[evolution] Bug 241477 - Message color cannot be removed once applied to a message



commit 6b46f0e09436a688f6333642ed2bf584f9ae580a
Author: Milan Crha <mcrha redhat com>
Date:   Mon Jul 23 21:29:58 2018 +0200

    Bug 241477 - Message color cannot be removed once applied to a message
    
    Closes https://bugzilla.gnome.org/show_bug.cgi?id=241477

 data/ui/evolution-mail-reader.ui |  29 +++++-----
 data/ui/evolution-mail.ui        |   7 ++-
 src/mail/e-mail-reader.c         | 121 ++++++++++++++++++++++++++++++++++++---
 src/mail/e-mail-reader.h         |   3 +-
 4 files changed, 137 insertions(+), 23 deletions(-)
---
diff --git a/data/ui/evolution-mail-reader.ui b/data/ui/evolution-mail-reader.ui
index c051d745b0..eff05c2971 100644
--- a/data/ui/evolution-mail-reader.ui
+++ b/data/ui/evolution-mail-reader.ui
@@ -76,18 +76,21 @@
         <menuitem action='mail-archive'/>
         <separator/>
         <menu action='mail-mark-as-menu'>
-          <menuitem action="mail-mark-read"/>
-          <menuitem action="mail-mark-unread"/>
+          <menuitem action='mail-mark-read'/>
+          <menuitem action='mail-mark-unread'/>
           <separator/>
-          <menuitem action="mail-mark-important"/>
-          <menuitem action="mail-mark-unimportant"/>
+          <menuitem action='mail-mark-important'/>
+          <menuitem action='mail-mark-unimportant'/>
           <separator/>
-          <menuitem action="mail-mark-junk"/>
-          <menuitem action="mail-mark-notjunk"/>
+          <menuitem action='mail-mark-junk'/>
+          <menuitem action='mail-mark-notjunk'/>
           <separator/>
-          <menuitem action="mail-flag-for-followup"/>
-          <menuitem action="mail-flag-clear"/>
-          <menuitem action="mail-flag-completed"/>
+          <menuitem action='mail-flag-for-followup'/>
+          <menuitem action='mail-flag-clear'/>
+          <menuitem action='mail-flag-completed'/>
+          <separator/>
+          <menuitem action='mail-color-assign'/>
+          <menuitem action='mail-color-unset'/>
           <separator/>
           <menu action='mail-label-menu'>
             <menuitem action='mail-label-none'/>
@@ -97,10 +100,10 @@
             <menuitem action='mail-label-new'/>
           </menu>
           <separator/>
-          <menuitem action="mail-mark-ignore-thread-whole"/>
-          <menuitem action="mail-mark-ignore-thread-sub"/>
-          <menuitem action="mail-mark-unignore-thread-whole"/>
-          <menuitem action="mail-mark-unignore-thread-sub"/>
+          <menuitem action='mail-mark-ignore-thread-whole'/>
+          <menuitem action='mail-mark-ignore-thread-sub'/>
+          <menuitem action='mail-mark-unignore-thread-whole'/>
+          <menuitem action='mail-mark-unignore-thread-sub'/>
         </menu>
         <menuitem action='mail-filters-apply'/>
         <menuitem action='mail-check-for-junk'/>
diff --git a/data/ui/evolution-mail.ui b/data/ui/evolution-mail.ui
index c031026479..f2ff7aa391 100644
--- a/data/ui/evolution-mail.ui
+++ b/data/ui/evolution-mail.ui
@@ -121,8 +121,11 @@
     <menuitem action='mail-popup-mark-junk'/>
     <menuitem action='mail-popup-mark-notjunk'/>
     <menuitem action='mail-popup-flag-for-followup'/>
-    <menuitem action="mail-popup-flag-clear"/>
-    <menuitem action="mail-popup-flag-completed"/>
+    <menuitem action='mail-popup-flag-clear'/>
+    <menuitem action='mail-popup-flag-completed'/>
+    <separator/>
+    <menuitem action='mail-popup-color-assign'/>
+    <menuitem action='mail-popup-color-unset'/>
     <separator/>
     <menuitem action='mail-popup-add-note'/>
     <menuitem action='mail-popup-edit-note'/>
diff --git a/src/mail/e-mail-reader.c b/src/mail/e-mail-reader.c
index e24ec5d905..eeda54709c 100644
--- a/src/mail/e-mail-reader.c
+++ b/src/mail/e-mail-reader.c
@@ -397,6 +397,78 @@ exit:
        g_ptr_array_unref (uids);
 }
 
+static void
+mail_reader_manage_color_flag_on_selection (EMailReader *reader,
+                                           const gchar *color)
+{
+       CamelFolder *folder;
+
+       g_return_if_fail (E_IS_MAIL_READER (reader));
+
+       folder = e_mail_reader_ref_folder (reader);
+
+       if (folder != NULL) {
+               GPtrArray *uids;
+               guint ii;
+
+               camel_folder_freeze (folder);
+
+               uids = e_mail_reader_get_selected_uids_with_collapsed_threads (reader);
+
+               for (ii = 0; ii < uids->len; ii++) {
+                       CamelMessageInfo *info;
+
+                       info = camel_folder_get_message_info (folder, uids->pdata[ii]);
+                       if (info) {
+                               camel_message_info_set_user_tag (info, "color", color);
+                               g_object_unref (info);
+                       }
+               }
+
+               g_ptr_array_unref (uids);
+
+               camel_folder_thaw (folder);
+
+               g_object_unref (folder);
+       }
+}
+
+static void
+action_mail_color_assign_cb (GtkAction *action,
+                            EMailReader *reader)
+{
+       GtkWidget *dialog;
+
+       dialog = gtk_color_chooser_dialog_new (NULL, e_mail_reader_get_window (reader));
+
+       if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK) {
+               GdkRGBA rgba;
+               gchar *color;
+
+               gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (dialog), &rgba);
+
+               color = g_strdup_printf ("#%02X%02X%02X",
+                       0xFF & ((gint) (255 * rgba.red)),
+                       0xFF & ((gint) (255 * rgba.green)),
+                       0xFF & ((gint) (255 * rgba.blue)));
+
+               if (color) {
+                       mail_reader_manage_color_flag_on_selection (reader, color);
+
+                       g_free (color);
+               }
+       }
+
+       gtk_widget_destroy (dialog);
+}
+
+static void
+action_mail_color_unset_cb (GtkAction *action,
+                           EMailReader *reader)
+{
+       mail_reader_manage_color_flag_on_selection (reader, NULL);
+}
+
 static void
 action_mail_copy_cb (GtkAction *action,
                      EMailReader *reader)
@@ -2182,6 +2254,20 @@ static GtkActionEntry mail_reader_entries[] = {
          N_("Filter the selected messages for junk status"),
          G_CALLBACK (action_mail_check_for_junk_cb) },
 
+       { "mail-color-assign",
+         NULL,
+         N_("Assign C_olor…"),
+         NULL,
+         N_("Assign color for the selected messages"),
+         G_CALLBACK (action_mail_color_assign_cb) },
+
+       { "mail-color-unset",
+         NULL,
+         N_("Unse_t Color"),
+         NULL,
+         N_("Unset color for the selected messages"),
+         G_CALLBACK (action_mail_color_unset_cb) },
+
        { "mail-copy",
          "mail-copy",
          N_("_Copy to Folder..."),
@@ -2691,6 +2777,14 @@ static EPopupActionEntry mail_reader_popup_entries[] = {
          NULL,
          "mail-archive" },
 
+       { "mail-popup-color-assign",
+         NULL,
+         "mail-color-assign" },
+
+       { "mail-popup-color-unset",
+         NULL,
+         "mail-color-unset" },
+
        { "mail-popup-copy",
          NULL,
          "mail-copy" },
@@ -3802,6 +3896,7 @@ mail_reader_update_actions (EMailReader *reader,
        gboolean selection_has_unimportant_messages;
        gboolean selection_has_unread_messages;
        gboolean selection_has_mail_note;
+       gboolean selection_has_color;
        gboolean selection_is_mailing_list;
        gboolean single_message_selected;
        gboolean first_message_selected = FALSE;
@@ -3844,6 +3939,8 @@ mail_reader_update_actions (EMailReader *reader,
                (state & E_MAIL_READER_SELECTION_HAS_UNREAD);
        selection_has_mail_note =
                (state & E_MAIL_READER_SELECTION_HAS_MAIL_NOTE);
+       selection_has_color =
+               (state & E_MAIL_READER_SELECTION_HAS_COLOR);
        selection_is_mailing_list =
                (state & E_MAIL_READER_SELECTION_IS_MAILING_LIST);
 
@@ -3889,6 +3986,16 @@ mail_reader_update_actions (EMailReader *reader,
        action = e_mail_reader_get_action (reader, action_name);
        gtk_action_set_sensitive (action, sensitive);
 
+       action_name = "mail-color-assign";
+       sensitive = any_messages_selected;
+       action = e_mail_reader_get_action (reader, action_name);
+       gtk_action_set_sensitive (action, sensitive);
+
+       action_name = "mail-color-unset";
+       sensitive = any_messages_selected && selection_has_color;
+       action = e_mail_reader_get_action (reader, action_name);
+       gtk_action_set_sensitive (action, sensitive);
+
        action_name = "mail-copy";
        sensitive = any_messages_selected;
        action = e_mail_reader_get_action (reader, action_name);
@@ -4762,6 +4869,7 @@ e_mail_reader_check_state (EMailReader *reader)
        gboolean has_unimportant = FALSE;
        gboolean has_unread = FALSE;
        gboolean has_mail_note = FALSE;
+       gboolean has_color = FALSE;
        gboolean have_enabled_account = FALSE;
        gboolean drafts_or_outbox = FALSE;
        gboolean is_mailing_list;
@@ -4816,9 +4924,6 @@ e_mail_reader_check_state (EMailReader *reader)
                if (info == NULL)
                        continue;
 
-               if (camel_message_info_get_user_flag (info, E_MAIL_NOTES_USER_FLAG))
-                       has_mail_note = TRUE;
-
                flags = camel_message_info_get_flags (info);
 
                if (flags & CAMEL_MESSAGE_SEEN)
@@ -4880,10 +4985,10 @@ e_mail_reader_check_state (EMailReader *reader)
                string = camel_message_info_get_mlist (info);
                is_mailing_list &= (string != NULL && *string != '\0');
 
-               has_ignore_thread = has_ignore_thread ||
-                       camel_message_info_get_user_flag (info, "ignore-thread");
-               has_notignore_thread = has_notignore_thread ||
-                       !camel_message_info_get_user_flag (info, "ignore-thread");
+               has_ignore_thread = has_ignore_thread || camel_message_info_get_user_flag (info, 
"ignore-thread");
+               has_notignore_thread = has_notignore_thread || !camel_message_info_get_user_flag (info, 
"ignore-thread");
+               has_mail_note = has_mail_note || camel_message_info_get_user_flag (info, 
E_MAIL_NOTES_USER_FLAG);
+               has_color = has_color || camel_message_info_get_user_tag (info, "color") != NULL;
 
                g_clear_object (&info);
        }
@@ -4938,6 +5043,8 @@ e_mail_reader_check_state (EMailReader *reader)
                state |= E_MAIL_READER_FOLDER_ARCHIVE_FOLDER_SET;
        if (has_mail_note)
                state |= E_MAIL_READER_SELECTION_HAS_MAIL_NOTE;
+       if (has_color)
+               state |= E_MAIL_READER_SELECTION_HAS_COLOR;
 
        g_clear_object (&folder);
        g_ptr_array_unref (uids);
diff --git a/src/mail/e-mail-reader.h b/src/mail/e-mail-reader.h
index 9934ac52c9..8d3ab2a922 100644
--- a/src/mail/e-mail-reader.h
+++ b/src/mail/e-mail-reader.h
@@ -91,7 +91,8 @@ enum {
        E_MAIL_READER_FOLDER_ARCHIVE_FOLDER_SET = 1 << 19,
        E_MAIL_READER_SELECTION_HAS_IGNORE_THREAD = 1 << 20,
        E_MAIL_READER_SELECTION_HAS_NOTIGNORE_THREAD = 1 << 21,
-       E_MAIL_READER_SELECTION_HAS_MAIL_NOTE = 1 << 22
+       E_MAIL_READER_SELECTION_HAS_MAIL_NOTE = 1 << 22,
+       E_MAIL_READER_SELECTION_HAS_COLOR = 1 << 23
 };
 
 struct _EMailReaderInterface {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]