Make Claws Mail conservative about color labels: ask for confirmation
authorwwp <wwp@free.fr>
Sun, 6 May 2018 14:02:43 +0000 (16:02 +0200)
committerwwp <wwp@free.fr>
Sun, 6 May 2018 14:02:43 +0000 (16:02 +0200)
when user clears or override existing color labels to messages.
Confirmation dialog is discardable.

src/prefs_common.c
src/prefs_common.h
src/prefs_summaries.c
src/summaryview.c

index d28153b..5b646a4 100644 (file)
@@ -876,6 +876,8 @@ static PrefParam param[] = {
 
        {"ask_mark_all_read", "TRUE", &prefs_common.ask_mark_all_read, P_BOOL,
         NULL, NULL, NULL},
+       {"ask_override_colorlabel", "TRUE", &prefs_common.ask_override_colorlabel, P_BOOL,
+        NULL, NULL, NULL},
 
        {"ask_apply_per_account_filtering_rules", "TRUE", &prefs_common.ask_apply_per_account_filtering_rules, P_BOOL,
         NULL, NULL, NULL},
index 10c21b7..82e1b54 100644 (file)
@@ -413,6 +413,7 @@ struct _PrefsCommon
 #endif
        int hover_timeout; /* msecs mouse hover timeout */
        gboolean ask_mark_all_read;
+       gboolean ask_override_colorlabel;
        gboolean ask_apply_per_account_filtering_rules;
        gint apply_per_account_filtering_rules;
 
index 304fcfe..500137f 100644 (file)
@@ -74,6 +74,7 @@ typedef struct _SummariesPage
        GtkWidget *spinbtn_mark_as_read_delay;
        GtkWidget *checkbtn_immedexec;
        GtkWidget *checkbtn_ask_mark_all_read;
+       GtkWidget *checkbtn_ask_override_colorlabel;
        GtkWidget *optmenu_sort_key;
        GtkWidget *optmenu_sort_type;
        GtkWidget *optmenu_nextunreadmsgdialog;
@@ -344,6 +345,7 @@ static void prefs_summaries_create_widget(PrefsPage *_page, GtkWindow *window,
        GtkAdjustment *spinbtn_mark_as_read_delay_adj;
        GtkWidget *checkbtn_immedexec;
        GtkWidget *checkbtn_ask_mark_all_read;
+       GtkWidget *checkbtn_ask_override_colorlabel;
        GtkWidget *label, *label_fill;
        GtkListStore *menu;
        GtkTreeIter iter;
@@ -598,6 +600,9 @@ static void prefs_summaries_create_widget(PrefsPage *_page, GtkWindow *window,
        PACK_CHECK_BUTTON
                (vbox1, checkbtn_ask_mark_all_read,
                 _("Confirm before marking all messages in a folder as read or unread"));
+       PACK_CHECK_BUTTON
+               (vbox1, checkbtn_ask_override_colorlabel,
+                _("Confirm before overriding color label of messages"));
        PACK_CHECK_BUTTON
                (vbox1, checkbtn_transhdr,
                 _("Translate header names"));
@@ -625,10 +630,11 @@ static void prefs_summaries_create_widget(PrefsPage *_page, GtkWindow *window,
        prefs_summaries->checkbtn_show_on_deletemove = checkbtn_show_on_deletemove;
        prefs_summaries->checkbtn_show_on_directional = checkbtn_show_on_directional;
 
-               prefs_summaries->checkbtn_mark_as_read_on_newwin = radio_mark_as_read_on_new_win;
+       prefs_summaries->checkbtn_mark_as_read_on_newwin = radio_mark_as_read_on_new_win;
        prefs_summaries->spinbtn_mark_as_read_delay = spinbtn_mark_as_read_delay;
        prefs_summaries->checkbtn_immedexec = checkbtn_immedexec;
        prefs_summaries->checkbtn_ask_mark_all_read = checkbtn_ask_mark_all_read;
+       prefs_summaries->checkbtn_ask_override_colorlabel = checkbtn_ask_override_colorlabel;
        prefs_summaries->optmenu_sort_key = optmenu_sort_key;
        prefs_summaries->optmenu_sort_type = optmenu_sort_type;
        prefs_summaries->optmenu_nextunreadmsgdialog = optmenu_nextunreadmsgdialog;
@@ -681,6 +687,8 @@ static void prefs_summaries_create_widget(PrefsPage *_page, GtkWindow *window,
                        prefs_common.immediate_exec);
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_ask_mark_all_read),
                        prefs_common.ask_mark_all_read);
+       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_ask_override_colorlabel),
+                       prefs_common.ask_override_colorlabel);
 
        combobox_select_by_data(GTK_COMBO_BOX(optmenu_sort_key),
                        prefs_common.default_sort_key);
@@ -737,6 +745,8 @@ static void prefs_summaries_save(PrefsPage *_page)
                GTK_TOGGLE_BUTTON(page->checkbtn_immedexec));
        prefs_common.ask_mark_all_read = gtk_toggle_button_get_active(
                GTK_TOGGLE_BUTTON(page->checkbtn_ask_mark_all_read));
+       prefs_common.ask_override_colorlabel = gtk_toggle_button_get_active(
+               GTK_TOGGLE_BUTTON(page->checkbtn_ask_override_colorlabel));
        prefs_common.mark_as_read_delay = gtk_spin_button_get_value_as_int(
                        GTK_SPIN_BUTTON(page->spinbtn_mark_as_read_delay));
 
index 66a0526..f4298a9 100644 (file)
@@ -4220,12 +4220,10 @@ void summary_msgs_unlock(SummaryView *summaryview)
 
 static gboolean summary_mark_all_read_confirm(gboolean ask_if_needed)
 {
-       AlertValue val;
-
        /* 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);
@@ -4268,12 +4266,10 @@ void summary_mark_all_read(SummaryView *summaryview, gboolean ask_if_needed)
 
 static gboolean summary_mark_all_unread_confirm(gboolean ask_if_needed)
 {
-       AlertValue val;
-
        /* 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);
@@ -4420,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;
@@ -5916,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)
 {
@@ -5977,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,