Track the mark-as-read timeout to be able to cancel it properly
authorColin Leroy <colin@colino.net>
Thu, 1 May 2014 08:54:47 +0000 (10:54 +0200)
committerColin Leroy <colin@colino.net>
Thu, 1 May 2014 08:54:47 +0000 (10:54 +0200)
when changing message or folder. Should fix bug #1644, "race condition
between message move and mark as read after timeout", bug #2145 "Claws
becomes unresponsive and gets Killed while moving messages between imap
folders", and bug #2643 "claws crash when accessing imap folder"

src/summaryview.c
src/summaryview.h

index fe37768..744e781 100644 (file)
@@ -1603,6 +1603,11 @@ void summary_clear_list(SummaryView *summaryview)
                summaryview->folder_item = NULL;
        }
 
+       if (summaryview->mark_as_read_timeout_tag != 0) {
+               g_source_remove(summaryview->mark_as_read_timeout_tag);
+               summaryview->mark_as_read_timeout_tag = 0;
+       }
+
        summaryview->display_msg = FALSE;
 
        summaryview->selected = NULL;
@@ -2249,6 +2254,10 @@ void summary_select_node(SummaryView *summaryview, GtkCMCTreeNode *node,
        if (!summaryview->folder_item)
                return;
        if (node) {
+               if (summaryview->mark_as_read_timeout_tag != 0) {
+                       g_source_remove(summaryview->mark_as_read_timeout_tag);
+                       summaryview->mark_as_read_timeout_tag = 0;
+               }
                gtkut_ctree_expand_parent_all(ctree, node);
                if (do_refresh) {
                        summary_lock(summaryview);
@@ -3542,8 +3551,10 @@ static int msginfo_mark_as_read_timeout(void *data)
                                     mdata->summaryview->selected);
        procmsg_msginfo_free(mdata->msginfo);
 
+       mdata->summaryview->mark_as_read_timeout_tag = 0;
+
        g_free(mdata);
-       return FALSE;   
+       return FALSE;
 }
 
 static void summary_display_msg_full(SummaryView *summaryview,
@@ -3620,12 +3631,17 @@ static void summary_display_msg_full(SummaryView *summaryview,
                        MarkAsReadData *data = g_new0(MarkAsReadData, 1);
                        data->summaryview = summaryview;
                        data->msginfo = procmsg_msginfo_new_ref(msginfo);
+                       if (summaryview->mark_as_read_timeout_tag != 0)
+                               g_source_remove(summaryview->mark_as_read_timeout_tag);
+
 #if GLIB_CHECK_VERSION(2,14,0)
-                       g_timeout_add_seconds(prefs_common.mark_as_read_delay,
-                               msginfo_mark_as_read_timeout, data);
+                       summaryview->mark_as_read_timeout_tag = 
+                               g_timeout_add_seconds(prefs_common.mark_as_read_delay,
+                                       msginfo_mark_as_read_timeout, data);
 #else
-                       g_timeout_add(prefs_common.mark_as_read_delay * 1000,
-                               msginfo_mark_as_read_timeout, data);
+                       summaryview->mark_as_read_timeout_tag = 
+                               g_timeout_add(prefs_common.mark_as_read_delay * 1000,
+                                       msginfo_mark_as_read_timeout, data);
 #endif
                } else if (new_window || !prefs_common.mark_as_read_on_new_window) {
                        msginfo_mark_as_read(summaryview, msginfo, row);
index 784e869..205e2a1 100644 (file)
@@ -170,7 +170,8 @@ private:
        // folders with matches for recursive quicksearch queries
        GSList *recursive_matched_folders;
        FolderItem *search_root_folder;
-       
+
+       guint mark_as_read_timeout_tag;
 #if !GTK_CHECK_VERSION(2,12,0)
        GtkTooltips *tooltips;
 #endif