changeset 61:a44d15cfd8a2

trying to fix changeset 60:ddd164e74312: clash when a message received and this plugin loaded after unloaded
author mikanbako <maoutwo@gmail.com>
date Sat, 21 Jun 2008 12:40:03 +0900
parents ddd164e74312
children 6843c3e6477f
files pidgin-twitter.c
diffstat 1 files changed, 43 insertions(+), 51 deletions(-) [+]
line wrap: on
line diff
--- a/pidgin-twitter.c	Sat Jun 21 02:32:28 2008 +0900
+++ b/pidgin-twitter.c	Sat Jun 21 12:40:03 2008 +0900
@@ -560,9 +560,6 @@
 detach_from_gtkconv(PidginConversation *gtkconv, gpointer null)
 {
     GtkWidget *box, *counter = NULL, *sep = NULL;
-    GtkIMHtml *imhtml = GTK_IMHTML(gtkconv->imhtml);
-
-    twitter_debug("end : imhtml : %o\n", gtk_imhtml_get_format_functions(imhtml));
 
     g_signal_handlers_disconnect_by_func(G_OBJECT(gtkconv->entry_buffer),
                                          (GFunc) insert_text_cb, gtkconv);
@@ -740,12 +737,15 @@
     twitter_debug("called\n");
     twitter_debug("buffer = %s suppress_oops = %d\n", *buffer, suppress_oops);
 
-    /* Prevent notifications of incoming messages.
-     * Check that conv is not null to avoid a clash.
+    /* Check that conv is not null to avoid a clash.
      * conv is null when the conversation window has not opened yet.
      */
-    if(conv && is_twitter_conv(conv) &&
-       purple_prefs_get_bool(OPT_PREVENT_NOTIFICATION)) {
+    if(!(conv && is_twitter_conv(conv))) {
+        return FALSE;
+    }
+
+    /* Prevent notifications of incoming messages. */
+    if(purple_prefs_get_bool(OPT_PREVENT_NOTIFICATION)) {
         *flags |= PURPLE_MESSAGE_SYSTEM;
     }
 
@@ -778,6 +778,7 @@
     GMatchInfo *match_info = NULL;
     gchar *user_name_in_message;
     int icon_id;
+    GList *entry_of_mark;
 
     /* find the conversation that contains the mark  */
     for(win_list = pidgin_conv_windows_get_list(); win_list;
@@ -816,12 +817,11 @@
 
     message = gtk_text_buffer_get_text(target_buffer, &inserting_point, &next_line, FALSE);
 
-    if(gtk_text_iter_get_line(&inserting_point) == 0) {
+    g_regex_match(regp[USER], message, 0, &match_info);
+    if(!g_match_info_matches(match_info)) {
+        g_match_info_free(match_info);
         g_regex_match(regp[USER_FIRST_LINE], message, 0, &match_info);
     }
-    else {
-        g_regex_match(regp[USER], message, 0, &match_info);
-    }
     if(!g_match_info_matches(match_info)) {
         twitter_debug("user's name was not matched : %s\n", message);
         g_match_info_free(match_info);
@@ -848,8 +848,10 @@
 
     gtk_imhtml_insert_image_at_iter(target_imhtml, icon_id, &inserting_point);
 
-    /* To prevent that requested_mark will be freed. */
-    g_object_ref(requested_mark);
+    /* mark the entry contains the deleted mark with NULL */
+    entry_of_mark = g_list_find(requested_icon_marks, requested_mark);
+    entry_of_mark->data = NULL;
+
     gtk_text_buffer_delete_mark(target_buffer, requested_mark);
 }
 
@@ -859,7 +861,8 @@
 {
     gchar *user_name = (gchar *)user_data;
     int icon_id;
-    GList* mark_list;
+
+    requestings = g_list_remove(requestings, url_data);
 
     /* Return if user's icon had already been downloaded or
      * the download is failure. */
@@ -874,45 +877,29 @@
 
         requested_users = g_list_remove(requested_users, user_name);
         g_free(user_name);
-        requestings = g_list_remove(requestings, url_data);
         return;
     }
 
     icon_id = purple_imgstore_add_with_id(g_memdup(url_text, len), len,
                                           user_name);
     g_hash_table_insert(icon_id_by_user, user_name, GINT_TO_POINTER(icon_id));
-    requestings = g_list_remove(requestings, url_data);
 
     twitter_debug("Downloading %s's icon has been complete.(icon_id = %d)\n",
         user_name, icon_id);
 
     /* Insert the icon to messages that had been received. */
-
     g_list_foreach(requested_icon_marks, insert_requested_icon, user_name);
-
-    /* Remove marks that inserted the icon. */
-    mark_list = g_list_first(requested_icon_marks);
-    while(mark_list) {
-        GtkTextMark *mark = mark_list->data;
-        GList* next = g_list_next(mark_list);
-
-        if(gtk_text_mark_get_deleted(mark)) {
-            g_object_unref(mark);
-            requested_icon_marks = g_list_delete_link(
-                                       requested_icon_marks, mark_list);
-        }
-
-        mark_list = next;
-    }
+    /* Remove the entries of the mark that inserted the icon. */
+    requested_icon_marks = g_list_remove_all(requested_icon_marks, NULL);
 }
 
 static void
 request_icon(const char *buffer)
 {
     GMatchInfo *match_info = NULL;
-    gchar* user_name = NULL;
-    gchar* message = NULL;
-    PurpleUtilFetchUrlData* fetch_data = NULL;
+    gchar *user_name = NULL;
+    gchar *message = NULL;
+    PurpleUtilFetchUrlData *fetch_data = NULL;
 
     /* get user's name */
 
@@ -963,7 +950,7 @@
                 PurpleConversation *conv, PurpleMessageFlags flags)
 {
     GMatchInfo *match_info = NULL;
-    gchar *user;
+    gchar *user_name;
     GtkIMHtml *imhtml;
     GtkTextBuffer *text_buffer;
     GtkTextIter inserting_point;
@@ -984,7 +971,7 @@
         return;
     }
 
-    user = g_match_info_fetch(match_info, 1);
+    user_name = g_match_info_fetch(match_info, 1);
     g_match_info_free(match_info);
 
     /* insert icon */
@@ -996,7 +983,7 @@
     gtk_text_buffer_get_iter_at_line(text_buffer, &inserting_point,
         gtk_text_buffer_get_line_count(text_buffer) - 1);
 
-    icon_id = GPOINTER_TO_INT(g_hash_table_lookup(icon_id_by_user, user));
+    icon_id = GPOINTER_TO_INT(g_hash_table_lookup(icon_id_by_user, user_name));
 
     /* If the user's icon has not been downloaded, mark the message */
     if(!icon_id) {
@@ -1004,13 +991,13 @@
                                    gtk_text_buffer_create_mark(
                                        text_buffer, NULL,
                                        &inserting_point, FALSE));
-        twitter_debug("%s's icon has not been downloaded.", user);
-        g_free(user);
+        twitter_debug("%s's icon has not been downloaded.", user_name);
+        g_free(user_name);
         return;
     }
 
     gtk_imhtml_insert_image_at_iter(imhtml, icon_id, &inserting_point);
-    g_free(user);
+    g_free(user_name);
 }
 
 static gboolean
@@ -1024,13 +1011,13 @@
     purple_signal_connect(purple_conversations_get_handle(),
                           "conversation-created",
                           plugin, PURPLE_CALLBACK(conv_created_cb), NULL);
-    purple_signal_connect(purple_conversations_get_handle(),
-                          "deleting-conversation",
-                           plugin, PURPLE_CALLBACK(deleting_conv_cb), NULL);
     purple_signal_connect(purple_conversations_get_handle(), "receiving-im-msg",
                           plugin, PURPLE_CALLBACK(receiving_im_cb), NULL);
     purple_signal_connect(pidgin_conversations_get_handle(), "displayed-im-msg",
                           plugin, PURPLE_CALLBACK(displayed_im_cb), NULL);
+    purple_signal_connect(purple_conversations_get_handle(),
+                          "deleting-conversation",
+                           plugin, PURPLE_CALLBACK(deleting_conv_cb), NULL);
 
     /* compile regex */
     regp[RECIPIENT] = g_regex_new(P_RECIPIENT, 0, 0, NULL);
@@ -1071,15 +1058,15 @@
     purple_signal_disconnect(purple_conversations_get_handle(),
                              "conversation-created",
                              plugin, PURPLE_CALLBACK(conv_created_cb));
+    purple_signal_disconnect(pidgin_conversations_get_handle(),
+                             "displayed-im-msg",
+                             plugin, PURPLE_CALLBACK(displayed_im_cb));
+    purple_signal_disconnect(purple_conversations_get_handle(),
+                             "receiving-im-msg",
+                             plugin, PURPLE_CALLBACK(receiving_im_cb));
     purple_signal_disconnect(purple_conversations_get_handle(),
                              "deleting-conversation",
                              plugin, PURPLE_CALLBACK(deleting_conv_cb));
-    purple_signal_disconnect(purple_conversations_get_handle(),
-                             "receiving-im-msg",
-                             plugin, PURPLE_CALLBACK(receiving_im_cb));
-    purple_signal_disconnect(pidgin_conversations_get_handle(),
-                             "displayed-im-msg",
-                             plugin, PURPLE_CALLBACK(displayed_im_cb));
 
     /* unreference regp */
     g_regex_unref(regp[RECIPIENT]);
@@ -1091,18 +1078,23 @@
     g_regex_unref(regp[USER_FIRST_LINE]);
     g_regex_unref(regp[USER_FORMATTED]);
 
+    g_list_free(requested_icon_marks);
+    requested_icon_marks = NULL;
+
     /* cancel request that has not been finished yet */
     for(list = g_list_first(requestings); list; list = g_list_next(list)) {
         purple_util_fetch_url_cancel(list->data);
     }
     g_list_free(requestings);
+    requestings = NULL;
 
     /* destroy hash table for icons */
+    g_hash_table_destroy(icon_id_by_user);
     for(list = g_list_first(requested_users); list; list = g_list_next(list)) {
         g_free(list->data);
     }
     g_list_free(requested_users);
-    g_hash_table_destroy(icon_id_by_user);
+    requested_users = NULL;
 
     /* detach from twitter window */
     detach_from_window();