changeset 70:74524f379440

trying simple search in insert_requested_icon() due to malfunction under linux environment.
author Yoshiki Yazawa <yaz@cc.rim.or.jp>
date Mon, 23 Jun 2008 17:06:04 +0900
parents d1f92d980f58
children 76fc004cd327
files pidgin-twitter.c
diffstat 1 files changed, 26 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/pidgin-twitter.c	Mon Jun 23 12:18:34 2008 +0900
+++ b/pidgin-twitter.c	Mon Jun 23 17:06:04 2008 +0900
@@ -700,6 +700,8 @@
     int icon_id;
     GList *entry_of_mark;
 
+    twitter_debug("called\n");
+
     /* find the conversation that contains the mark  */
     for(win_list = pidgin_conv_windows_get_list(); win_list;
             win_list = win_list->next) {
@@ -737,6 +739,7 @@
 
     message = gtk_text_buffer_get_text(target_buffer, &inserting_point, &next_line, FALSE);
 
+#if 0
     g_regex_match(regp[USER], message, 0, &match_info);
     if(!g_match_info_matches(match_info)) {
         g_match_info_free(match_info);
@@ -753,12 +756,25 @@
     g_match_info_free(match_info);
     g_free(message);
 
-    /* Return if the message is not by the user that has the icon. */
+    /* Return if the message is not from the user who has this icon. */
     if(!g_str_equal(user_name, user_name_in_message)) {
         g_free(user_name_in_message);
         return;
     }
     g_free(user_name_in_message);
+#endif
+
+
+    /* simple search works sufficiently */
+    gchar *needle = g_strdup_printf("%s:", user_name);
+    if(!g_strstr_len(message, 256, needle)){ // xxx 256 is just a guess.
+        g_free(message); message = NULL;
+        g_free(needle); needle = NULL;
+        return;
+    }
+    twitter_debug("got needle %s\n", needle);
+    g_free(message); message = NULL;
+    g_free(needle); needle = NULL;
 
     /* insert icon */
     icon_id = GPOINTER_TO_INT(g_hash_table_lookup(icon_id_by_user, user_name));
@@ -766,8 +782,6 @@
         return;
     }
 
-    /* xxx scale stored icon to adequate size here. --yaz */
-
     /* insert icon actually */
     gtk_imhtml_insert_image_at_iter(target_imhtml, icon_id, &inserting_point);
 
@@ -855,7 +869,6 @@
     /* if img has been registerd, just return */
     icon_id = GPOINTER_TO_INT(g_hash_table_lookup(icon_id_by_user, user_name));
     if(icon_id) {
-        g_free(user_name);
         return;
     }
 
@@ -884,22 +897,21 @@
 
         icon_id = purple_imgstore_add_with_id(data, len, path);
 
-        g_hash_table_insert(icon_id_by_user, user_name, GINT_TO_POINTER(icon_id));
-        //user_name must not be freed!! --yaz
+        g_hash_table_insert(icon_id_by_user, g_strdup(user_name), GINT_TO_POINTER(icon_id));
         g_free(filename);
         g_free(path);
 
+        g_list_foreach(requested_icon_marks, insert_requested_icon, user_name);
         return;
     }
 
     /* Return if user's icon has been requested already. */
     if(g_list_find_custom(requested_users, user_name, (GCompareFunc)strcmp)) {
-        g_free(user_name);
         return;
     }
 
     /* The string object are owned by the list. */
-    requested_users = g_list_append(requested_users, user_name);
+    requested_users = g_list_append(requested_users, g_strdup(user_name));
     /* Create the URL of the user's icon.
      * See http://twitter.g.hatena.ne.jp/ikko615/20080107/1199703400
      */
@@ -907,7 +919,7 @@
                           user_name);
 
     fetch_data = purple_util_fetch_url(url, TRUE, NULL, TRUE,
-                                       got_icon_cb, user_name);
+                                       got_icon_cb, g_strdup(user_name));
     g_free(url);
     requestings = g_list_append(requestings, fetch_data);
 
@@ -919,7 +931,7 @@
                 PurpleConversation *conv, PurpleMessageFlags flags)
 {
     GMatchInfo *match_info = NULL;
-    gchar *user_name;
+    gchar *user_name = NULL;
     GtkIMHtml *imhtml;
     GtkTextBuffer *text_buffer;
     GtkTextIter inserting_point;
@@ -958,16 +970,16 @@
                           gtk_text_buffer_create_mark(
                               text_buffer, NULL,
                               &inserting_point, FALSE));
-        twitter_debug("%s's icon has not been downloaded.", user_name);
+        twitter_debug("%s's icon has not been downloaded.\n", user_name);
         /* request to attach icon to the buffer
-         * user_name is owned by the function. */
+         * this function owns user_name string */
         request_icon(user_name);
-        /* user_name must not free */
+        g_free(user_name); user_name = NULL;
         return;
     }
 
     gtk_imhtml_insert_image_at_iter(imhtml, icon_id, &inserting_point);
-    g_free(user_name);
+    g_free(user_name); user_name = NULL;
 }
 
 static gboolean