when changing sort_key by clicking column header, preserve sort_type
[claws.git] / src / summaryview.c
index df982dc425ffb52414f11140186451f2a75bad19..9bf442054fb200b51aa8f09fc40f0ec50abab383 100644 (file)
@@ -193,6 +193,8 @@ static void summary_mark_row_as_read        (SummaryView            *summaryview,
                                         GtkCMCTreeNode         *row);
 static void summary_mark_row_as_unread (SummaryView            *summaryview,
                                         GtkCMCTreeNode         *row);
+static gboolean summary_mark_all_read_confirm(gboolean ask_if_needed);
+static gboolean summary_mark_all_unread_confirm(gboolean ask_if_needed);
 static void summary_delete_row         (SummaryView            *summaryview,
                                         GtkCMCTreeNode         *row);
 static void summary_unmark_row         (SummaryView            *summaryview,
@@ -1766,7 +1768,11 @@ void summary_set_menu_sensitive(SummaryView *summaryview)
        gboolean sensitive;
        gint i;
 
+#ifndef GENERIC_UMPC
 #define N_ENTRIES 39
+#else
+#define N_ENTRIES 28
+#endif
        static struct {
                const gchar *entry;
                SensitiveCondMask cond;
@@ -4138,6 +4144,11 @@ void summary_mark_as_read(SummaryView *summaryview)
 
        if (summary_is_locked(summaryview))
                return;
+
+       if ((summaryview->folder_item->total_msgs == (gint)g_list_length(GTK_CMCLIST(ctree)->selection))
+                && !summary_mark_all_read_confirm(TRUE))
+               return;
+
        START_LONG_OPERATION(summaryview, FALSE);
        folder_item_set_batch(summaryview->folder_item, TRUE);
        for (cur = GTK_CMCLIST(ctree)->selection; cur != NULL && cur->data != NULL; cur = cur->next)
@@ -4157,6 +4168,11 @@ void summary_mark_as_unread(SummaryView *summaryview)
 
        if (summary_is_locked(summaryview))
                return;
+
+       if ((summaryview->folder_item->total_msgs == (gint)g_list_length(GTK_CMCLIST(ctree)->selection))
+                && !summary_mark_all_unread_confirm(TRUE))
+               return;
+
        START_LONG_OPERATION(summaryview, FALSE);
        folder_item_set_batch(summaryview->folder_item, TRUE);
        for (cur = GTK_CMCLIST(ctree)->selection; cur != NULL && cur->data != NULL; cur = cur->next)
@@ -4202,29 +4218,36 @@ void summary_msgs_unlock(SummaryView *summaryview)
        summary_status_show(summaryview);
 }
 
-void summary_mark_all_read(SummaryView *summaryview, gboolean ask_if_needed)
+static gboolean summary_mark_all_read_confirm(gboolean ask_if_needed)
 {
-       GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
-       GtkCMCTreeNode *node;
-       AlertValue val;
-       gboolean froze = FALSE;
-
        /* ask_if_needed is FALSE when user-asking is performed by caller,
           commonly when the caller is a mark-as-read-recursive func */
        if (ask_if_needed && prefs_common.ask_mark_all_read) {
-               val = alertpanel_full(_("Mark all as read"),
+               AlertValue val = alertpanel_full(_("Mark all as read"),
                          _("Do you really want to mark all mails in this folder as read?"),
                          GTK_STOCK_NO, GTK_STOCK_YES, NULL, ALERTFOCUS_FIRST,
                          TRUE, NULL, ALERT_QUESTION);
 
                if ((val & ~G_ALERTDISABLE) != G_ALERTALTERNATE)
-                       return;
+                       return FALSE;
                else if (val & G_ALERTDISABLE)
                        prefs_common.ask_mark_all_read = FALSE;
        }
+       return TRUE;
+}
+
+void summary_mark_all_read(SummaryView *summaryview, gboolean ask_if_needed)
+{
+       GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
+       GtkCMCTreeNode *node;
+       gboolean froze = FALSE;
        
        if (summary_is_locked(summaryview))
                return;
+
+       if (!summary_mark_all_read_confirm(ask_if_needed))
+               return;
+
        START_LONG_OPERATION(summaryview, TRUE);
        folder_item_set_batch(summaryview->folder_item, TRUE);
        for (node = GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list); node != NULL;
@@ -4241,29 +4264,36 @@ void summary_mark_all_read(SummaryView *summaryview, gboolean ask_if_needed)
        summary_status_show(summaryview);
 }
 
-void summary_mark_all_unread(SummaryView *summaryview, gboolean ask_if_needed)
+static gboolean summary_mark_all_unread_confirm(gboolean ask_if_needed)
 {
-       GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
-       GtkCMCTreeNode *node;
-       AlertValue val;
-       gboolean froze = FALSE;
-
        /* ask_if_needed is FALSE when user-asking is performed by caller,
           commonly when the caller is a mark-as-unread-recursive func */
        if (ask_if_needed && prefs_common.ask_mark_all_read) {
-               val = alertpanel_full(_("Mark all as unread"),
+               AlertValue val = alertpanel_full(_("Mark all as unread"),
                          _("Do you really want to mark all mails in this folder as unread?"),
                          GTK_STOCK_NO, GTK_STOCK_YES, NULL, ALERTFOCUS_FIRST,
                          TRUE, NULL, ALERT_QUESTION);
 
                if ((val & ~G_ALERTDISABLE) != G_ALERTALTERNATE)
-                       return;
+                       return FALSE;
                else if (val & G_ALERTDISABLE)
                        prefs_common.ask_mark_all_read = FALSE;
        }
+       return TRUE;
+}
+
+void summary_mark_all_unread(SummaryView *summaryview, gboolean ask_if_needed)
+{
+       GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
+       GtkCMCTreeNode *node;
+       gboolean froze = FALSE;
        
        if (summary_is_locked(summaryview))
                return;
+
+       if (!summary_mark_all_unread_confirm(ask_if_needed))
+               return;
+
        START_LONG_OPERATION(summaryview, TRUE);
        folder_item_set_batch(summaryview->folder_item, TRUE);
        for (node = GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list); node != NULL;
@@ -4386,7 +4416,7 @@ static gboolean check_permission(SummaryView *summaryview, MsgInfo * msginfo)
                }
 
                if (!found) {
-                       alertpanel_error(_("You're not the author of the article.\n"));
+                       alertpanel_error(_("You're not the author of the article."));
                }
                
                return found;
@@ -4474,7 +4504,7 @@ void summary_delete(SummaryView *summaryview)
 
        if (!prefs_common.live_dangerously) {
                gchar *buf = NULL;
-               int num = g_list_length(GTK_CMCLIST(summaryview->ctree)->selection);
+               guint num = g_list_length(GTK_CMCLIST(summaryview->ctree)->selection);
                buf = g_strdup_printf(ngettext(
                        "Do you really want to delete the selected message?",
                        "Do you really want to delete the %d selected messages?", num),
@@ -5882,7 +5912,7 @@ static void summary_colorlabel_menu_item_activate_cb(GtkWidget *widget,
 }
 
 /* summary_set_colorlabel_color() - labelcolor parameter is the color *flag*
- * for the messsage; not the color index */
+ * for the message; not the color index */
 void summary_set_colorlabel_color(GtkCMCTree *ctree, GtkCMCTreeNode *node,
                                  guint labelcolor)
 {
@@ -5943,6 +5973,54 @@ void summary_set_colorlabel(SummaryView *summaryview, guint labelcolor,
        GList *cur;
        gboolean froze = FALSE;
 
+       if (prefs_common.ask_override_colorlabel) {
+               GtkCMCTree *ctree = GTK_CMCTREE(summaryview->ctree);
+               gboolean ask = FALSE;
+               AlertValue val;
+               guint color;
+               gboolean already_this_color_everywhere = TRUE;
+
+               /* if clearing color labels (applying 'none', 0):
+                   - ask if at least one message has a non-0 color label set
+                  if applying a non-0 color label:
+                   - ask if at least one of the selected messages has a non-0 color label different
+                         from the one we want to apply.
+                   - don't ask if all messages have the same color label as the one we're applying
+               */
+               for (cur = GTK_CMCLIST(ctree)->selection;
+                        !ask && cur != NULL && cur->data != NULL;
+                        cur = cur->next) {
+                       MsgInfo *msginfo = gtk_cmctree_node_get_row_data(ctree, GTK_CMCTREE_NODE(cur->data));
+                       if (msginfo) {
+                               color = MSG_GET_COLORLABEL_VALUE(msginfo->flags);
+                               if (labelcolor == 0) {
+                                       /* clearing color labels */
+                                       ask = (color != 0);
+                               } else {
+                                       already_this_color_everywhere &= (color == labelcolor);
+                                       ask = ((color != 0) && (color != labelcolor)) && !already_this_color_everywhere;
+                               }
+                       }
+               }
+
+               if (ask) {
+                       gchar *msg;
+
+                       if (labelcolor == 0)
+                               msg = _("Do you really want to reset the color label of all selected messages?");
+                       else
+                               msg = _("Do you really want to apply this color label to all selected messages?");
+                       val = alertpanel_full(_("Set color label"), msg,
+                                 GTK_STOCK_NO, GTK_STOCK_YES, NULL, ALERTFOCUS_FIRST,
+                                 TRUE, NULL, ALERT_QUESTION);
+
+                       if ((val & ~G_ALERTDISABLE) != G_ALERTALTERNATE)
+                               return;
+                       else if (val & G_ALERTDISABLE)
+                               prefs_common.ask_override_colorlabel = FALSE;
+               }
+       }
+
        START_LONG_OPERATION(summaryview, FALSE);
        for (cur = GTK_CMCLIST(ctree)->selection; cur != NULL && cur->data != NULL; cur = cur->next)
                summary_set_row_colorlabel(summaryview,
@@ -7213,7 +7291,7 @@ static void summary_sort_by_column_click(SummaryView *summaryview,
                             summaryview->sort_type == SORT_ASCENDING
                             ? SORT_DESCENDING : SORT_ASCENDING);
        else
-               summary_sort(summaryview, sort_key, SORT_ASCENDING);
+               summary_sort(summaryview, sort_key, summaryview->sort_type);
 
        node = GTK_CMCTREE_NODE(GTK_CMCLIST(summaryview->ctree)->row_list);