Fix bug #1941 ‘recursive "mark read all"’
authorRicardo Mones <ricardo@mones.org>
Thu, 28 May 2015 19:07:30 +0000 (21:07 +0200)
committerRicardo Mones <ricardo@mones.org>
Thu, 28 May 2015 19:33:05 +0000 (21:33 +0200)
Based on the original patch from Robert David which unfortunately
didn't marked as read the folder currently open on summary view.

AUTHORS
src/folderutils.c
src/folderutils.h
src/folderview.c
src/gtk/authors.h

diff --git a/AUTHORS b/AUTHORS
index 4b83479..6803548 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -313,3 +313,4 @@ contributors (in addition to the above; based on Changelog)
        Daniel Zaoui
        Johan Vromans
        Charles Lehner
+       Robert David
index 8fea729..cd1735a 100644 (file)
@@ -158,3 +158,27 @@ void folderutils_mark_all_read(FolderItem *item)
        }
        folder_item_update_thaw();
 }
+
+void folderutils_mark_all_read_recursive(FolderItem *item)
+{
+       GNode *node;
+
+       cm_return_if_fail(item != NULL);
+
+       folderutils_mark_all_read(item);
+
+       cm_return_if_fail(item->folder != NULL);
+       cm_return_if_fail(item->folder->node != NULL);
+
+       node = item->folder->node;
+       node = g_node_find(node, G_PRE_ORDER, G_TRAVERSE_ALL, item);
+       node = node->children;
+
+       while (node != NULL) {
+               if (node->data != NULL) {
+                       FolderItem *sub_item = (FolderItem *) node->data;
+                       node = node->next;
+                       folderutils_mark_all_read_recursive(sub_item);
+               }
+       }
+}
index 08da0fa..ca404c5 100644 (file)
@@ -30,5 +30,6 @@ typedef enum {
 gint folderutils_delete_duplicates(FolderItem *item,
                                   DeleteDuplicatesMode mode);
 void folderutils_mark_all_read   (FolderItem *item);
+void folderutils_mark_all_read_recursive         (FolderItem *item);
 
 #endif /* FOLDERUTILS_H */
index c061c0c..0ddc249 100644 (file)
@@ -163,8 +163,14 @@ static void folderview_col_resized (GtkCMCList     *clist,
                                         gint            width,
                                         FolderView     *folderview);
 
+static void mark_all_read_handler      (GtkAction      *action,
+                                        gpointer        data,
+                                        gboolean        recursive);
+
 static void mark_all_read_cb            (GtkAction     *action,
                                         gpointer        data);
+static void mark_all_read_recursive_cb  (GtkAction     *action,
+                                        gpointer        data);
 
 static void folderview_empty_trash_cb  (GtkAction      *action,
                                         gpointer        data);
@@ -228,6 +234,7 @@ static GtkActionEntry folderview_common_popup_entries[] =
 {
        {"FolderViewPopup",                     NULL, "FolderViewPopup" },
        {"FolderViewPopup/MarkAllRead",         NULL, N_("Mark all re_ad"), NULL, NULL, G_CALLBACK(mark_all_read_cb) },
+       {"FolderViewPopup/MarkAllReadRec",      NULL, N_("Mark all read recursi_ve"), NULL, NULL, G_CALLBACK(mark_all_read_recursive_cb) },
        {"FolderViewPopup/---",                 NULL, "---" },
        {"FolderViewPopup/RunProcessing",       NULL, N_("R_un processing rules"), NULL, NULL, G_CALLBACK(folderview_run_processing_cb) },
        {"FolderViewPopup/SearchFolder",        NULL, N_("_Search folder..."), NULL, NULL, G_CALLBACK(folderview_search_cb) },
@@ -809,6 +816,16 @@ void folderview_select(FolderView *folderview, FolderItem *item)
 }
 
 static void mark_all_read_cb(GtkAction *action, gpointer data)
+{
+       mark_all_read_handler(action, data, FALSE);
+}
+
+static void mark_all_read_recursive_cb(GtkAction *action, gpointer data)
+{
+       mark_all_read_handler(action, data, TRUE);
+}
+
+static void mark_all_read_handler(GtkAction *action, gpointer data, gboolean recursive)
 {
        FolderView *folderview = (FolderView *)data;
        FolderItem *item;
@@ -833,14 +850,17 @@ static void mark_all_read_cb(GtkAction *action, gpointer data)
 
        
        folder_item_update_freeze();
-       if (folderview->summaryview->folder_item != item)
+       if (folderview->summaryview->folder_item != item && !recursive)
                summary_lock(folderview->summaryview);
        else
                summary_freeze(folderview->summaryview);
                
-       folderutils_mark_all_read(item);
+       if (recursive)
+               folderutils_mark_all_read_recursive(item);
+       else
+               folderutils_mark_all_read(item);
        
-       if (folderview->summaryview->folder_item != item)
+       if (folderview->summaryview->folder_item != item && !recursive)
                summary_unlock(folderview->summaryview);
        else
                summary_thaw(folderview->summaryview);
@@ -1820,6 +1840,7 @@ static void folderview_set_sens_and_popup_menu(FolderView *folderview, gint row,
                fpopup->add_menuitems(ui_manager, item);
 
        MENUITEM_ADDUI_MANAGER(ui_manager, "/Popup/FolderViewPopup", "MarkAllRead", "FolderViewPopup/MarkAllRead", GTK_UI_MANAGER_MENUITEM)
+       MENUITEM_ADDUI_MANAGER(ui_manager, "/Popup/FolderViewPopup", "MarkAllReadRec", "FolderViewPopup/MarkAllReadRec", GTK_UI_MANAGER_MENUITEM)
        MENUITEM_ADDUI_MANAGER(ui_manager, "/Popup/FolderViewPopup", "Separator1", "FolderViewPopup/---", GTK_UI_MANAGER_SEPARATOR)
        MENUITEM_ADDUI_MANAGER(ui_manager, "/Popup/FolderViewPopup", "RunProcessing", "FolderViewPopup/RunProcessing", GTK_UI_MANAGER_MENUITEM)
        MENUITEM_ADDUI_MANAGER(ui_manager, "/Popup/FolderViewPopup", "SearchFolder", "FolderViewPopup/SearchFolder", GTK_UI_MANAGER_MENUITEM)
@@ -1850,6 +1871,7 @@ static void folderview_set_sens_and_popup_menu(FolderView *folderview, gint row,
        cm_menu_set_sensitive_full(ui_manager, "Popup/"name, sens)
 
        SET_SENS("FolderViewPopup/MarkAllRead", item->unread_msgs >= 1);
+       SET_SENS("FolderViewPopup/MarkAllReadRec", folderview_have_unread_children(folderview,item));
        SET_SENS("FolderViewPopup/SearchFolder", item->total_msgs >= 1 && 
                 folderview->selected == folderview->opened);
        SET_SENS("FolderViewPopup/Properties", TRUE);
index ffb9fd6..8a77633 100644 (file)
@@ -111,6 +111,7 @@ static char *CONTRIBS_LIST[] = {
 "Christian Cornelssen",
 "Palmer Dabbelt",
 "George Danchev",
+"Robert David",
 "Kevin Day",
 "Matthieu Dazy",
 "Ben Deering",