changeset 197:be4ef598d120 multiaccounts

a crash after a user switched using API was fixed.
author mikanbako <maoutwo@gmail.com>
date Sun, 10 Aug 2008 16:01:22 +0900
parents 0b0b4cab7c0e
children
files pidgin-twitter.c pidgin-twitter.h
diffstat 2 files changed, 40 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/pidgin-twitter.c	Tue Aug 05 23:19:09 2008 +0900
+++ b/pidgin-twitter.c	Sun Aug 10 16:01:22 2008 +0900
@@ -29,13 +29,14 @@
 static gboolean suppress_oops = FALSE;
 static GHashTable *icon_hash[3]; /* twitter, wassr, identica. */
 static GHashTable *conv_hash = NULL;
+static GHashTable *source_hash = NULL;
 static GHashTable *last_id_hash = NULL;
 static GList *statuseslist = NULL;
 static GList *postedlist = NULL;
 static gchar *wassr_post = NULL;
 static gchar *identica_post = NULL;
 
-static struct _source {
+typedef struct _source {
     guint id;
     PurpleConversation *conv;
 } source;
@@ -1542,23 +1543,36 @@
 conv_created_cb(PurpleConversation *conv, gpointer null)
 {
     PidginConversation *gtkconv = PIDGIN_CONVERSATION(conv);
+    PurpleAccount *account = purple_conversation_get_account(conv);
+    source *src;
 
     twitter_debug("called\n");
 
     g_return_if_fail(gtkconv != NULL);
 
+    if(!g_hash_table_lookup(source_hash,
+                            purple_account_get_username(account))) {
+        src = g_new0(source, 1);
+        g_hash_table_insert(source_hash,
+                            g_strdup(purple_account_get_username(account)),
+                            src);
+    }
+    else
+        src = g_hash_table_lookup(source_hash,
+                                  purple_account_get_username(account));
+
     gint service = get_service_type(conv);
     /* only attach to twitter conversation window */
     switch(service) {
     case twitter_service:
         get_status_with_api((gpointer)conv);
-        source.id = g_timeout_add_seconds(
+        src->id = g_timeout_add_seconds(
             service_account_get_int(purple_conversation_get_account(conv),
                                     purple_conversation_get_name(conv),
                                     OPT_API_BASE_GET_INTERVAL,
                                     TWITTER_DEFAULT_INTERVAL),
             get_status_with_api, (gpointer)conv);
-        source.conv = conv;
+        src->conv = conv;
         attach_to_conv(conv, NULL);
         break;
     case wassr_service:
@@ -1577,6 +1591,7 @@
     PidginConversation *gtkconv = PIDGIN_CONVERSATION(conv);
     PurpleAccount *account = purple_conversation_get_account(conv);
     const char *conv_name = purple_conversation_get_name(conv);
+    source* source;
 
     twitter_debug("called\n");
 
@@ -1585,6 +1600,8 @@
     gint service = get_service_type(conv);
     GHashTable *hash = NULL;
 
+    source = g_hash_table_lookup(source_hash, purple_account_get_username(account));
+
     /* only attach to twitter conversation window */
     switch(service) {
     case twitter_service:
@@ -1593,8 +1610,8 @@
                                     OPT_API_BASE_POST,
                                     FALSE)) {
             g_source_remove_by_user_data((gpointer)conv);
-            source.id = 0;
-            source.conv = NULL;
+            source->id = 0;
+            source->conv = NULL;
         }
         hash = icon_hash[twitter_service];
         break;
@@ -2417,10 +2434,10 @@
 
     twitter_debug("called\n");
 
-    if(gc && !service_account_get_bool(purple_connection_get_account(gc),
-                                       CONV_NAME_TWITTER,
-                                       OPT_API_BASE_POST,
-                                       FALSE))
+    if(!service_account_get_bool(purple_connection_get_account(gc),
+                                 CONV_NAME_TWITTER,
+                                 OPT_API_BASE_POST,
+                                 FALSE))
         return;
 
     if (!list)
@@ -2510,6 +2527,8 @@
     conv_hash = g_hash_table_new_full(g_direct_hash, g_direct_equal,
                                               NULL, NULL);
     last_id_hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
+    source_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
+                                              g_free, g_free);
 
     /* attach counter to the existing twitter window */
     if(purple_prefs_get_bool(OPT_COUNTER)) {
@@ -2600,6 +2619,7 @@
 
     g_hash_table_destroy(conv_hash);
     g_hash_table_destroy(last_id_hash);
+    g_hash_table_destroy(source_hash);
 
     /* detach from twitter window */
     detach_from_window();
@@ -3175,10 +3195,10 @@
 }
 
 static void
-account_preference_api_base_post_changed(void)
+account_preference_api_base_post_changed(PurpleConversation* conv)
 {
-    signed_on_cb(NULL);
-    get_status_with_api((gpointer)(source.conv));
+    signed_on_cb(purple_conversation_get_gc(conv));
+    get_status_with_api((gpointer)conv);
 }
 
 static void
@@ -3195,24 +3215,27 @@
     service_account_set_bool(account, conv_name, key, value);
 
     if(!strcmp(OPT_API_BASE_POST, key))
-        account_preference_api_base_post_changed();
+        account_preference_api_base_post_changed(conv);
 }
 
 static void
 account_preference_interval_changed(PurpleAccount *account,
                                     const char *conv_name)
 {
+    source *source = g_hash_table_lookup(source_hash,
+                                         purple_account_get_username(account));
+
     /* remove idle func */
-    g_source_remove_by_user_data((gpointer)(source.conv));
+    g_source_remove_by_user_data((gpointer)(source->conv));
 
     /* add idle func */
     if(service_account_get_bool(account, conv_name, OPT_API_BASE_POST, FALSE)) {
-        source.id = g_timeout_add_seconds(
+        source->id = g_timeout_add_seconds(
             service_account_get_int(account,
                                     conv_name,
                                     OPT_API_BASE_GET_INTERVAL,
                                     TWITTER_DEFAULT_INTERVAL),
-            get_status_with_api, (gpointer)(source.conv));
+            get_status_with_api, (gpointer)(source->conv));
     }
 }
 
--- a/pidgin-twitter.h	Tue Aug 05 23:19:09 2008 +0900
+++ b/pidgin-twitter.h	Sun Aug 10 16:01:22 2008 +0900
@@ -225,7 +225,7 @@
 static void destroyed_pref_button_cb(GtkWidget *pref_button, gpointer dialog);
 static void closed_account_preference_window_cb(GtkDialog *dialog, gint response_id, gpointer pref_button);
 static void account_preference_text_changed_cb(GtkEditable *editable, gpointer conv_ptr);
-static void account_preference_api_base_post_changed(void);
+static void account_preference_api_base_post_changed(PurpleConversation *conv);
 static void account_preference_bool_toggled_cb(GtkToggleButton *togglebutton, gpointer conv_ptr);
 static void account_preference_interval_changed(PurpleAccount *account, const char *conv_name);
 static void account_preference_spin_changed_cb(GtkSpinButton *spinbutton, gpointer conv_ptr);