Factorize folderview_find_next_{unread,new,marked}
authorColin Leroy <colin@colino.net>
Thu, 15 May 2014 10:00:06 +0000 (12:00 +0200)
committerColin Leroy <colin@colino.net>
Thu, 15 May 2014 10:00:06 +0000 (12:00 +0200)
src/folderview.c
src/folderview.h
src/mainwindow.c
src/messageview.c
src/summaryview.c

index 94d708d..457affb 100644 (file)
@@ -867,8 +867,9 @@ void folderview_unselect(FolderView *folderview)
        folderview->selected = folderview->opened = NULL;
 }
 
-static GtkCMCTreeNode *folderview_find_next_marked(GtkCMCTree *ctree,
-                                                GtkCMCTreeNode *node)
+static GtkCMCTreeNode *folderview_find_next_with_flag(GtkCMCTree *ctree,
+                                                     GtkCMCTreeNode *node,
+                                                     MsgPermFlags flag)
 {
        FolderItem *item;
 
@@ -879,73 +880,51 @@ static GtkCMCTreeNode *folderview_find_next_marked(GtkCMCTree *ctree,
 
        for (; node != NULL; node = gtkut_ctree_node_next(ctree, node)) {
                item = gtk_cmctree_node_get_row_data(ctree, node);
-               if (item && item->marked_msgs > 0 && item->stype != F_TRASH)
-                       return node;
+               if (item->stype == F_TRASH)
+                       continue;
+               switch (flag) {
+               case MSG_UNREAD:
+                       if(item->unread_msgs > 0)
+                               return node;
+                       break;
+               case MSG_NEW:
+                       if(item->new_msgs > 0)
+                               return node;
+                       break;
+               case MSG_MARKED:
+                       if(item->marked_msgs > 0)
+                               return node;
+                       break;
+               }
        }
 
        return NULL;
 }
 
-void folderview_select_next_marked(FolderView *folderview)
+void folderview_select_next_with_flag(FolderView *folderview,
+                                     MsgPermFlags flag,
+                                     gboolean force_open)
 {
        GtkCMCTree *ctree = GTK_CMCTREE(folderview->ctree);
        GtkCMCTreeNode *node = NULL;
        EntryAction last_summary_select_prio = prefs_common.summary_select_prio[0];
        gboolean last_open = prefs_common.always_show_msg;
        
-       prefs_common.summary_select_prio[0] = ACTION_MARKED;
-       prefs_common.always_show_msg = OPENMSG_ALWAYS;
-
-       if ((node = folderview_find_next_marked(ctree, folderview->opened))
-           != NULL) {
-               folderview_select_node(folderview, node);
-               goto out;
-       }
-
-       if (!folderview->opened ||
-           folderview->opened == GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list)) {
-               goto out;
-       }
-       /* search again from the first node */
-       if ((node = folderview_find_next_marked(ctree, NULL)) != NULL)
-               folderview_select_node(folderview, node);
-
-out:
-       prefs_common.summary_select_prio[0] = last_summary_select_prio;
-       prefs_common.always_show_msg = last_open;
-}
-
-static GtkCMCTreeNode *folderview_find_next_unread(GtkCMCTree *ctree,
-                                                GtkCMCTreeNode *node)
-{
-       FolderItem *item;
-
-       if (node)
-               node = gtkut_ctree_node_next(ctree, node);
-       else
-               node = GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list);
-
-       for (; node != NULL; node = gtkut_ctree_node_next(ctree, node)) {
-               item = gtk_cmctree_node_get_row_data(ctree, node);
-               if (item && item->unread_msgs > 0 && item->stype != F_TRASH)
-                       return node;
+       switch (flag) {
+       case MSG_UNREAD:
+               prefs_common.summary_select_prio[0] = ACTION_UNREAD;
+               break;
+       case MSG_NEW:
+               prefs_common.summary_select_prio[0] = ACTION_NEW;
+               break;
+       case MSG_MARKED:
+               prefs_common.summary_select_prio[0] = ACTION_MARKED;
+               break;
        }
-
-       return NULL;
-}
-
-void folderview_select_next_unread(FolderView *folderview, gboolean force_open)
-{
-       GtkCMCTree *ctree = GTK_CMCTREE(folderview->ctree);
-       GtkCMCTreeNode *node = NULL;
-       EntryAction last_summary_select_prio = prefs_common.summary_select_prio[0];
-       gboolean last_open = prefs_common.always_show_msg;
-       
-       prefs_common.summary_select_prio[0] = ACTION_UNREAD;
        prefs_common.always_show_msg = force_open ? OPENMSG_ALWAYS : last_open;
 
-       if ((node = folderview_find_next_unread(ctree, folderview->opened))
-           != NULL) {
+       node = folderview_find_next_with_flag(ctree, folderview->opened, flag);
+       if (node != NULL) {
                folderview_select_node(folderview, node);
                goto out;
        }
@@ -954,56 +933,10 @@ void folderview_select_next_unread(FolderView *folderview, gboolean force_open)
            folderview->opened == GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list)) {
                goto out;
        }
-       /* search again from the first node */
-       if ((node = folderview_find_next_unread(ctree, NULL)) != NULL)
-               folderview_select_node(folderview, node);
-
-out:
-       prefs_common.summary_select_prio[0] = last_summary_select_prio;
-       prefs_common.always_show_msg = last_open;
-}
 
-static GtkCMCTreeNode *folderview_find_next_new(GtkCMCTree *ctree,
-                                                GtkCMCTreeNode *node)
-{
-       FolderItem *item;
-
-       if (node)
-               node = gtkut_ctree_node_next(ctree, node);
-       else
-               node = GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list);
-
-       for (; node != NULL; node = gtkut_ctree_node_next(ctree, node)) {
-               item = gtk_cmctree_node_get_row_data(ctree, node);
-               if (item && item->new_msgs > 0 && item->stype != F_TRASH)
-                       return node;
-       }
-
-       return NULL;
-}
-
-void folderview_select_next_new(FolderView *folderview)
-{
-       GtkCMCTree *ctree = GTK_CMCTREE(folderview->ctree);
-       GtkCMCTreeNode *node = NULL;
-       EntryAction last_summary_select_prio = prefs_common.summary_select_prio[0];
-       gboolean last_open = prefs_common.always_show_msg;
-       
-       prefs_common.summary_select_prio[0] = ACTION_NEW;
-       prefs_common.always_show_msg = OPENMSG_ALWAYS;
-
-       if ((node = folderview_find_next_new(ctree, folderview->opened))
-           != NULL) {
-               folderview_select_node(folderview, node);
-               goto out;
-       }
-
-       if (!folderview->opened ||
-           folderview->opened == GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list)) {
-               goto out;
-       }
        /* search again from the first node */
-       if ((node = folderview_find_next_new(ctree, NULL)) != NULL)
+       node = folderview_find_next_with_flag(ctree, NULL, flag);
+       if (node != NULL)
                folderview_select_node(folderview, node);
 
 out:
@@ -2011,7 +1944,7 @@ static gboolean folderview_key_pressed(GtkWidget *widget, GdkEventKey *event,
                        if (folderview->opened == folderview->selected &&
                            (!folderview->summaryview->folder_item ||
                             folderview->summaryview->folder_item->total_msgs == 0))
-                               folderview_select_next_unread(folderview, TRUE);
+                               folderview_select_next_with_flag(folderview, MSG_UNREAD, TRUE);
                        else
                                folderview_select_node(folderview,
                                                       folderview->selected);
index 95093ff..cc36427 100644 (file)
@@ -113,10 +113,9 @@ void folderview_set_all                    (void);
 void folderview_select                 (FolderView     *folderview,
                                         FolderItem     *item);
 void folderview_unselect               (FolderView     *folderview);
-void folderview_select_next_unread     (FolderView     *folderview, 
+void folderview_select_next_with_flag  (FolderView     *folderview,
+                                        MsgPermFlags    flag,
                                         gboolean        force_open);
-void folderview_select_next_new                (FolderView     *folderview);
-void folderview_select_next_marked     (FolderView     *folderview);
 
 FolderItem *folderview_get_selected_item(FolderView    *folderview);
 
index dd560e8..517db91 100644 (file)
@@ -1393,7 +1393,7 @@ static gboolean mainwindow_key_pressed (GtkWidget *widget, GdkEventKey *event,
                                    && mainwin->summaryview->folder_item->total_msgs == 0))) {
                                g_signal_stop_emission_by_name(G_OBJECT(widget), 
                                               "key_press_event");
-                               folderview_select_next_unread(mainwin->folderview, TRUE);
+                               folderview_select_next_with_flag(mainwin->folderview, MSG_UNREAD, TRUE);
                        }
                }
                break;
@@ -4833,7 +4833,7 @@ static void goto_folder_cb(GtkAction *action, gpointer data)
 static void goto_unread_folder_cb(GtkAction *action, gpointer data)
 {
        MainWindow *mainwin = (MainWindow *)data;
-       folderview_select_next_unread(mainwin->folderview, FALSE);
+       folderview_select_next_with_flag(mainwin->folderview, MSG_UNREAD, FALSE);
 }
 
 static void scroll_prev_line_cb(GtkAction *action, gpointer data)
index 30cd460..b3b815b 100644 (file)
@@ -2584,8 +2584,9 @@ static void parent_cb(GtkAction *action, gpointer data)
 static void goto_unread_folder_cb(GtkAction *action, gpointer data)
 {
        MessageView *messageview = (MessageView *)data;
+
        messageview->updating = TRUE;
-       folderview_select_next_unread(messageview->mainwin->folderview, FALSE);
+       folderview_select_next_with_flag(messageview->mainwin->folderview, MSG_UNREAD, FALSE);
        messageview->updating = FALSE;
 
        if (messageview->deferred_destroy) {
index f874bc6..13ad155 100644 (file)
@@ -1903,7 +1903,7 @@ void summary_select_next_unread(SummaryView *summaryview)
                        }
 
                        if (val == G_ALERTALTERNATE)
-                               folderview_select_next_unread(summaryview->folderview, TRUE);
+                               folderview_select_next_with_flag(summaryview->folderview, MSG_UNREAD, TRUE);
                } else {
                        summary_select_node(summaryview, node, TRUE, FALSE);
                }
@@ -1998,7 +1998,7 @@ void summary_select_next_new(SummaryView *summaryview)
                        }
 
                        if (val == G_ALERTALTERNATE) {
-                               folderview_select_next_new(summaryview->folderview);
+                               folderview_select_next_with_flag(summaryview->folderview, MSG_NEW, TRUE);
                                return;
                        } 
                        else
@@ -2077,7 +2077,7 @@ void summary_select_next_marked(SummaryView *summaryview)
                        }
 
                        if (val == G_ALERTALTERNATE) {
-                               folderview_select_next_marked(summaryview->folderview);
+                               folderview_select_next_with_flag(summaryview->folderview, MSG_MARKED, TRUE);
                                return;
                        } 
                        else