[evolution] I#673 - Allow deselect of the Archive folder



commit 72ca126803ca931a3a443be5265e24814c3205bb
Author: Milan Crha <mcrha redhat com>
Date:   Wed Feb 19 10:56:58 2020 +0100

    I#673 - Allow deselect of the Archive folder
    
    Closes https://gitlab.gnome.org/GNOME/evolution/issues/673

 src/mail/e-mail-config-defaults-page.c |  1 +
 src/mail/em-folder-selection-button.c  | 59 +++++++++++++++++++++++++-
 src/mail/em-folder-selection-button.h  |  5 +++
 src/mail/em-folder-selector.c          | 76 ++++++++++++++++++++++++++++++++++
 src/mail/em-folder-selector.h          |  3 ++
 src/modules/mail/em-mailer-prefs.c     |  1 +
 6 files changed, 144 insertions(+), 1 deletion(-)
---
diff --git a/src/mail/e-mail-config-defaults-page.c b/src/mail/e-mail-config-defaults-page.c
index 286cf89191..46221cc3ed 100644
--- a/src/mail/e-mail-config-defaults-page.c
+++ b/src/mail/e-mail-config-defaults-page.c
@@ -784,6 +784,7 @@ mail_config_defaults_page_constructed (GObject *object)
 
        text = _("Choose a folder to archive messages to.");
        widget = em_folder_selection_button_new (session, "", text);
+       em_folder_selection_button_set_can_none (EM_FOLDER_SELECTION_BUTTON (widget), TRUE);
        gtk_widget_set_hexpand (widget, TRUE);
        gtk_label_set_mnemonic_widget (label, widget);
        gtk_grid_attach (GTK_GRID (container), widget, 1, 4, 1, 1);
diff --git a/src/mail/em-folder-selection-button.c b/src/mail/em-folder-selection-button.c
index 4119f24459..6f3bdaa608 100644
--- a/src/mail/em-folder-selection-button.c
+++ b/src/mail/em-folder-selection-button.c
@@ -46,10 +46,13 @@ struct _EMFolderSelectionButtonPrivate {
        gchar *title;
        gchar *caption;
        gchar *folder_uri;
+
+       gboolean can_none;
 };
 
 enum {
        PROP_0,
+       PROP_CAN_NONE,
        PROP_CAPTION,
        PROP_FOLDER_URI,
        PROP_SESSION,
@@ -127,6 +130,12 @@ folder_selection_button_set_property (GObject *object,
                                       GParamSpec *pspec)
 {
        switch (property_id) {
+               case PROP_CAN_NONE:
+                       em_folder_selection_button_set_can_none (
+                               EM_FOLDER_SELECTION_BUTTON (object),
+                               g_value_get_boolean (value));
+                       return;
+
                case PROP_CAPTION:
                        em_folder_selection_button_set_caption (
                                EM_FOLDER_SELECTION_BUTTON (object),
@@ -168,6 +177,13 @@ folder_selection_button_get_property (GObject *object,
                                       GParamSpec *pspec)
 {
        switch (property_id) {
+               case PROP_CAN_NONE:
+                       g_value_set_boolean (
+                               value,
+                               em_folder_selection_button_get_can_none (
+                               EM_FOLDER_SELECTION_BUTTON (object)));
+                       return;
+
                case PROP_CAPTION:
                        g_value_set_string (
                                value,
@@ -255,6 +271,7 @@ folder_selection_button_clicked (GtkButton *button)
        GtkWidget *dialog;
        GtkTreeSelection *selection;
        gpointer parent;
+       gint response;
 
        priv = EM_FOLDER_SELECTION_BUTTON_GET_PRIVATE (button);
 
@@ -278,6 +295,7 @@ folder_selection_button_clicked (GtkButton *button)
 
        selector = EM_FOLDER_SELECTOR (dialog);
        em_folder_selector_set_can_create (selector, TRUE);
+       em_folder_selector_set_can_none (selector, priv->can_none);
        em_folder_selector_set_caption (selector, priv->caption);
 
        folder_tree = em_folder_selector_get_folder_tree (selector);
@@ -293,7 +311,9 @@ folder_selection_button_clicked (GtkButton *button)
 
        em_folder_tree_set_selected (folder_tree, priv->folder_uri, FALSE);
 
-       if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK) {
+       response = gtk_dialog_run (GTK_DIALOG (dialog));
+
+       if (response == GTK_RESPONSE_OK) {
                const gchar *uri;
 
                uri = em_folder_selector_get_selected_uri (selector);
@@ -301,6 +321,9 @@ folder_selection_button_clicked (GtkButton *button)
                        EM_FOLDER_SELECTION_BUTTON (button), uri);
 
                g_signal_emit (button, signals[SELECTED], 0);
+       } else if (response == GTK_RESPONSE_NO) {
+               em_folder_selection_button_set_folder_uri (EM_FOLDER_SELECTION_BUTTON (button), NULL);
+               g_signal_emit (button, signals[SELECTED], 0);
        }
 
        gtk_widget_destroy (dialog);
@@ -323,6 +346,18 @@ em_folder_selection_button_class_init (EMFolderSelectionButtonClass *class)
        button_class = GTK_BUTTON_CLASS (class);
        button_class->clicked = folder_selection_button_clicked;
 
+       g_object_class_install_property (
+               object_class,
+               PROP_CAN_NONE,
+               g_param_spec_boolean (
+                       "can-none",
+                       "Can None",
+                       "Whether can show 'None' button, to be able to unselect folder",
+                       FALSE,
+                       G_PARAM_READWRITE |
+                       G_PARAM_CONSTRUCT |
+                       G_PARAM_STATIC_STRINGS));
+
        g_object_class_install_property (
                object_class,
                PROP_CAPTION,
@@ -454,6 +489,28 @@ em_folder_selection_button_set_session (EMFolderSelectionButton *button,
        g_object_notify (G_OBJECT (button), "session");
 }
 
+gboolean
+em_folder_selection_button_get_can_none (EMFolderSelectionButton *button)
+{
+       g_return_val_if_fail (EM_IS_FOLDER_SELECTION_BUTTON (button), FALSE);
+
+       return button->priv->can_none;
+}
+
+void
+em_folder_selection_button_set_can_none (EMFolderSelectionButton *button,
+                                        gboolean can_none)
+{
+       g_return_if_fail (EM_IS_FOLDER_SELECTION_BUTTON (button));
+
+       if (button->priv->can_none == can_none)
+               return;
+
+       button->priv->can_none = can_none;
+
+       g_object_notify (G_OBJECT (button), "can-none");
+}
+
 const gchar *
 em_folder_selection_button_get_caption (EMFolderSelectionButton *button)
 {
diff --git a/src/mail/em-folder-selection-button.h b/src/mail/em-folder-selection-button.h
index 2c6f743b3b..997dcd2904 100644
--- a/src/mail/em-folder-selection-button.h
+++ b/src/mail/em-folder-selection-button.h
@@ -74,6 +74,11 @@ EMailSession *       em_folder_selection_button_get_session
 void           em_folder_selection_button_set_session
                                        (EMFolderSelectionButton *button,
                                         EMailSession *session);
+gboolean       em_folder_selection_button_get_can_none
+                                       (EMFolderSelectionButton *button);
+void           em_folder_selection_button_set_can_none
+                                       (EMFolderSelectionButton *button,
+                                        gboolean can_none);
 const gchar *  em_folder_selection_button_get_caption
                                        (EMFolderSelectionButton *button);
 void           em_folder_selection_button_set_caption
diff --git a/src/mail/em-folder-selector.c b/src/mail/em-folder-selector.c
index edd439921a..c7f4640258 100644
--- a/src/mail/em-folder-selector.c
+++ b/src/mail/em-folder-selector.c
@@ -54,6 +54,7 @@ struct _EMFolderSelectorPrivate {
        gchar *selected_uri;
 
        gboolean can_create;
+       gboolean can_none;
        gchar *caption;
        gchar *default_button_label;
 };
@@ -61,6 +62,7 @@ struct _EMFolderSelectorPrivate {
 enum {
        PROP_0,
        PROP_CAN_CREATE,
+       PROP_CAN_NONE,
        PROP_CAPTION,
        PROP_DEFAULT_BUTTON_LABEL,
        PROP_MODEL
@@ -185,6 +187,12 @@ folder_selector_set_property (GObject *object,
                                g_value_get_boolean (value));
                        return;
 
+               case PROP_CAN_NONE:
+                       em_folder_selector_set_can_none (
+                               EM_FOLDER_SELECTOR (object),
+                               g_value_get_boolean (value));
+                       return;
+
                case PROP_CAPTION:
                        em_folder_selector_set_caption (
                                EM_FOLDER_SELECTOR (object),
@@ -221,6 +229,13 @@ folder_selector_get_property (GObject *object,
                                EM_FOLDER_SELECTOR (object)));
                        return;
 
+               case PROP_CAN_NONE:
+                       g_value_set_boolean (
+                               value,
+                               em_folder_selector_get_can_none (
+                               EM_FOLDER_SELECTOR (object)));
+                       return;
+
                case PROP_CAPTION:
                        g_value_set_string (
                                value,
@@ -316,6 +331,7 @@ folder_selector_constructed (GObject *object)
        gtk_dialog_add_buttons (
                GTK_DIALOG (selector),
                _("_Cancel"), GTK_RESPONSE_CANCEL,
+               _("_None"), GTK_RESPONSE_NO,
                selector->priv->default_button_label, GTK_RESPONSE_OK, NULL);
 
        gtk_dialog_set_response_sensitive (
@@ -323,6 +339,13 @@ folder_selector_constructed (GObject *object)
        gtk_dialog_set_default_response (
                GTK_DIALOG (selector), GTK_RESPONSE_OK);
 
+       widget = gtk_dialog_get_widget_for_response (GTK_DIALOG (selector), GTK_RESPONSE_NO);
+
+       e_binding_bind_property (
+               selector, "can-none",
+               widget, "visible",
+               G_BINDING_SYNC_CREATE);
+
        widget = gtk_dialog_get_widget_for_response (
                GTK_DIALOG (selector), GTK_RESPONSE_OK);
 
@@ -454,6 +477,18 @@ em_folder_selector_class_init (EMFolderSelectorClass *class)
                        G_PARAM_CONSTRUCT |
                        G_PARAM_STATIC_STRINGS));
 
+       g_object_class_install_property (
+               object_class,
+               PROP_CAN_NONE,
+               g_param_spec_boolean (
+                       "can-none",
+                       "Can None",
+                       "Whether can show 'None' button, to be able to unselect folder",
+                       FALSE,
+                       G_PARAM_READWRITE |
+                       G_PARAM_CONSTRUCT |
+                       G_PARAM_STATIC_STRINGS));
+
        g_object_class_install_property (
                object_class,
                PROP_CAPTION,
@@ -567,6 +602,47 @@ em_folder_selector_set_can_create (EMFolderSelector *selector,
        g_object_notify (G_OBJECT (selector), "can-create");
 }
 
+/**
+ * em_folder_selector_get_can_none:
+ * @selector: an #EMFolderSelector
+ *
+ * Returns whether the user can unselect folder by using a 'None' button.
+ *
+ * Returns: whether can unselect folder
+ *
+ * Since: 3.36
+ **/
+gboolean
+em_folder_selector_get_can_none (EMFolderSelector *selector)
+{
+       g_return_val_if_fail (EM_IS_FOLDER_SELECTOR (selector), FALSE);
+
+       return selector->priv->can_none;
+}
+
+/**
+ * em_folder_selector_set_can_none:
+ * @selector: an #EMFolderSelector
+ * @can_none: whether can unselect folder
+ *
+ * Sets whether the user can unselect folder using a 'None' button.
+ *
+ * Since: 3.36
+ **/
+void
+em_folder_selector_set_can_none (EMFolderSelector *selector,
+                                gboolean can_none)
+{
+       g_return_if_fail (EM_IS_FOLDER_SELECTOR (selector));
+
+       if (can_none == selector->priv->can_none)
+               return;
+
+       selector->priv->can_none = can_none;
+
+       g_object_notify (G_OBJECT (selector), "can-none");
+}
+
 /**
  * em_folder_selector_get_caption:
  * @selector: an #EMFolderSelector
diff --git a/src/mail/em-folder-selector.h b/src/mail/em-folder-selector.h
index 6a5787fe76..3a7b9a52da 100644
--- a/src/mail/em-folder-selector.h
+++ b/src/mail/em-folder-selector.h
@@ -73,6 +73,9 @@ gboolean      em_folder_selector_get_can_create
 void           em_folder_selector_set_can_create
                                                (EMFolderSelector *selector,
                                                 gboolean can_create);
+gboolean       em_folder_selector_get_can_none (EMFolderSelector *selector);
+void           em_folder_selector_set_can_none (EMFolderSelector *selector,
+                                                gboolean can_none);
 const gchar *  em_folder_selector_get_caption  (EMFolderSelector *selector);
 void           em_folder_selector_set_caption  (EMFolderSelector *selector,
                                                 const gchar *caption);
diff --git a/src/modules/mail/em-mailer-prefs.c b/src/modules/mail/em-mailer-prefs.c
index 35e2d42722..2c9bac40a1 100644
--- a/src/modules/mail/em-mailer-prefs.c
+++ b/src/modules/mail/em-mailer-prefs.c
@@ -1515,6 +1515,7 @@ em_mailer_prefs_construct (EMMailerPrefs *prefs,
 
        container = e_builder_get_widget (prefs->priv->builder, "archive-mail-hbox");
        widget = em_folder_selection_button_new (session, "", _("Choose a folder to archive messages to."));
+       em_folder_selection_button_set_can_none (EM_FOLDER_SELECTION_BUTTON (widget), TRUE);
        gtk_widget_set_hexpand (widget, FALSE);
        gtk_label_set_mnemonic_widget (GTK_LABEL (e_builder_get_widget (prefs->priv->builder, 
"lblArchiveMailFolder")), widget);
        gtk_container_add (GTK_CONTAINER (container), widget);


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