changeset 30042:d98eee650379

Some fixes related to setting moods. * Avoid run-time warnings when setting a mood without a message. * Fix a typo to not try setting a mood on an account that doesn't support them. * Avoid unnecessary strdup and strequal calls.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Thu, 25 Mar 2010 15:24:42 +0000
parents 551109fcd61d
children 72fd8c6144a2
files pidgin/gtkblist.c
diffstat 1 files changed, 17 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/pidgin/gtkblist.c	Thu Mar 25 14:23:22 2010 +0000
+++ b/pidgin/gtkblist.c	Thu Mar 25 15:24:42 2010 +0000
@@ -118,7 +118,6 @@
 	PidginMiniDialog *signed_on_elsewhere;
 
 	PidginBlistTheme *current_theme;
-
 } PidginBuddyListPrivate;
 
 #define PIDGIN_BUDDY_LIST_GET_PRIVATE(list) \
@@ -3405,7 +3404,7 @@
 update_status_with_mood(PurpleAccount *account, const gchar *mood,
     const gchar *text)
 {
-	if (mood != NULL && !purple_strequal(mood, "")) {
+	if (mood && *mood) {
 		if (text) {
 			purple_account_set_status(account, "mood", TRUE,
 			                          PURPLE_MOOD_NAME, mood,
@@ -3424,20 +3423,27 @@
 static void
 edit_mood_cb(PurpleConnection *gc, PurpleRequestFields *fields)
 {
-	PurpleRequestField *mood_field, *text_field;
+	PurpleRequestField *mood_field;
 	GList *l;
 
 	mood_field = purple_request_fields_get_field(fields, "mood");
-	text_field = purple_request_fields_get_field(fields, "text");
 	l = purple_request_field_list_get_selected(mood_field);
 
 	if (l) {
 		const char *mood = purple_request_field_list_get_data(mood_field, l->data);
-		const char *text = purple_request_field_string_get_value(text_field);
 
 		if (gc) {
+			const char *text;
 			PurpleAccount *account = purple_connection_get_account(gc);
 
+			if (gc->flags & PURPLE_CONNECTION_SUPPORT_MOOD_MESSAGES) {
+				PurpleRequestField *text_field;
+				text_field = purple_request_fields_get_field(fields, "text");
+				text = purple_request_field_string_get_value(text_field);
+			} else {
+				text = NULL;
+			}
+
 			update_status_with_mood(account, mood, text);
 		} else {
 			GList *accounts = purple_accounts_get_all_active();
@@ -3446,8 +3452,8 @@
 				PurpleAccount *account = (PurpleAccount *) accounts->data;
 				PurpleConnection *gc = purple_account_get_connection(account);
 
-				if (gc->flags && PURPLE_CONNECTION_SUPPORT_MOODS) {
-					update_status_with_mood(account, mood, text);
+				if (gc->flags & PURPLE_CONNECTION_SUPPORT_MOODS) {
+					update_status_with_mood(account, mood, NULL);
 				}
 			}
 		}
@@ -3467,9 +3473,9 @@
 get_global_moods(void)
 {
 	GHashTable *global_moods =
-		g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
+		g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL);
 	GHashTable *mood_counts =
-		g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
+		g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL);
 	GList *accounts = purple_accounts_get_all_active();
 	PurpleMood *result = NULL;
 	GList *out_moods = NULL;
@@ -3491,9 +3497,9 @@
 						GPOINTER_TO_INT(g_hash_table_lookup(mood_counts, mood->mood));
 
 				if (!g_hash_table_lookup(global_moods, mood->mood)) {
-					g_hash_table_insert(global_moods, g_strdup(mood->mood), mood);
+					g_hash_table_insert(global_moods, (gpointer)mood->mood, mood);
 				}
-				g_hash_table_insert(mood_counts, g_strdup(mood->mood),
+				g_hash_table_insert(mood_counts, (gpointer)mood->mood,
 				    GINT_TO_POINTER(mood_count + 1));
 			}