[evolution/wip/tpopela/freeze-fixes] Move em_utils_prompt_user to e-util to remove duplication from composer



commit 0ce3d5bd4ac2c5e2dfac8bb6df415098e7a9be1d
Author: Tomas Popela <tpopela redhat com>
Date:   Thu Mar 19 09:08:12 2015 +0100

    Move em_utils_prompt_user to e-util to remove duplication from composer

 composer/e-composer-actions.c            |   57 +-----------------------
 e-util/e-misc-utils.c                    |   68 ++++++++++++++++++++++++++++
 e-util/e-misc-utils.h                    |    5 ++
 mail/e-mail-backend.c                    |    4 +-
 mail/e-mail-reader-utils.c               |   12 +++---
 mail/em-composer-utils.c                 |   16 ++++---
 mail/em-utils.c                          |   72 ++----------------------------
 mail/em-utils.h                          |    1 -
 modules/mail/e-mail-shell-view-actions.c |    3 +-
 9 files changed, 99 insertions(+), 139 deletions(-)
---
diff --git a/composer/e-composer-actions.c b/composer/e-composer-actions.c
index 4a072e3..e7c5524 100644
--- a/composer/e-composer-actions.c
+++ b/composer/e-composer-actions.c
@@ -27,59 +27,6 @@
 #include <errno.h>
 #include <fcntl.h>
 
-/* because 'composer' is compiled before 'mail' folder */
-static gboolean
-composer_copy_em_utils_prompt_user (GtkWindow *parent,
-                                   const gchar *promptkey,
-                                   const gchar *tag,
-                                   ...)
-{
-       GtkWidget *dialog;
-       GtkWidget *check = NULL;
-       GtkWidget *container;
-       va_list ap;
-       gint button;
-       GSettings *settings;
-       EAlert *alert = NULL;
-
-       settings = e_util_ref_settings ("org.gnome.evolution.mail");
-
-       if (promptkey && !g_settings_get_boolean (settings, promptkey)) {
-               g_object_unref (settings);
-               return TRUE;
-       }
-
-       va_start (ap, tag);
-       alert = e_alert_new_valist (tag, ap);
-       va_end (ap);
-
-       dialog = e_alert_dialog_new (parent, alert);
-       g_object_unref (alert);
-
-       container = e_alert_dialog_get_content_area (E_ALERT_DIALOG (dialog));
-
-       if (promptkey) {
-               check = gtk_check_button_new_with_mnemonic (
-                       _("_Do not show this message again"));
-               gtk_box_pack_start (
-                       GTK_BOX (container), check, FALSE, FALSE, 0);
-               gtk_widget_show (check);
-       }
-
-       button = gtk_dialog_run (GTK_DIALOG (dialog));
-       if (promptkey)
-               g_settings_set_boolean (
-                       settings, promptkey,
-                       !gtk_toggle_button_get_active (
-                               GTK_TOGGLE_BUTTON (check)));
-
-       gtk_widget_destroy (dialog);
-
-       g_object_unref (settings);
-
-       return button == GTK_RESPONSE_YES;
-}
-
 static void
 action_attach_cb (GtkAction *action,
                   EMsgComposer *composer)
@@ -366,8 +313,8 @@ composer_actions_accel_activate_cb (GtkAccelGroup *accel_group,
        EMsgComposer *composer = user_data;
 
        if (keyval == GDK_KEY_Return && (modifier & GDK_MODIFIER_MASK) == GDK_CONTROL_MASK &&
-           !composer_copy_em_utils_prompt_user (GTK_WINDOW (composer), "prompt-on-accel-send",
-               "mail-composer:prompt-accel-send", NULL)) {
+           !e_util_prompt_user (GTK_WINDOW (composer), "org.gnome.evolution.mail",
+               "prompt-on-accel-send", "mail-composer:prompt-accel-send", NULL)) {
                return TRUE;
        }
        return FALSE;
diff --git a/e-util/e-misc-utils.c b/e-util/e-misc-utils.c
index da035de..b488394 100644
--- a/e-util/e-misc-utils.c
+++ b/e-util/e-misc-utils.c
@@ -49,6 +49,7 @@
 #include <camel/camel.h>
 #include <libedataserver/libedataserver.h>
 
+#include "e-alert-dialog.h"
 #include "e-alert-sink.h"
 #include "e-client-cache.h"
 #include "e-filter-option.h"
@@ -3075,3 +3076,70 @@ e_util_cleanup_settings (void)
 
        g_mutex_unlock (&settings_hash_lock);
 }
+
+/**
+ * e_util_prompt_user:
+ * @parent: parent window
+ * @settings_schema: name of the settings schema where @promptkey belongs.
+ * @promptkey: settings key to check if we should prompt the user or not.
+ * @tag: e_alert tag.
+ *
+ * Convenience function to query the user with a Yes/No dialog and a
+ * "Do not show this dialog again" checkbox. If the user checks that
+ * checkbox, then @promptkey is set to %FALSE, otherwise it is set to
+ * %TRUE.
+ *
+ * Returns %TRUE if the user clicks Yes or %FALSE otherwise.
+ **/
+gboolean
+e_util_prompt_user (GtkWindow *parent,
+                    const gchar *settings_schema,
+                    const gchar *promptkey,
+                    const gchar *tag,
+                    ...)
+{
+       GtkWidget *dialog;
+       GtkWidget *check = NULL;
+       GtkWidget *container;
+       va_list ap;
+       gint button;
+       GSettings *settings;
+       EAlert *alert = NULL;
+
+       settings = e_util_ref_settings (settings_schema);
+
+       if (promptkey && !g_settings_get_boolean (settings, promptkey)) {
+               g_object_unref (settings);
+               return TRUE;
+       }
+
+       va_start (ap, tag);
+       alert = e_alert_new_valist (tag, ap);
+       va_end (ap);
+
+       dialog = e_alert_dialog_new (parent, alert);
+       g_object_unref (alert);
+
+       container = e_alert_dialog_get_content_area (E_ALERT_DIALOG (dialog));
+
+       if (promptkey) {
+               check = gtk_check_button_new_with_mnemonic (
+                       _("_Do not show this message again"));
+               gtk_box_pack_start (
+                       GTK_BOX (container), check, FALSE, FALSE, 0);
+               gtk_widget_show (check);
+       }
+
+       button = gtk_dialog_run (GTK_DIALOG (dialog));
+       if (promptkey)
+               g_settings_set_boolean (
+                       settings, promptkey,
+                       !gtk_toggle_button_get_active (
+                               GTK_TOGGLE_BUTTON (check)));
+
+       gtk_widget_destroy (dialog);
+
+       g_object_unref (settings);
+
+       return button == GTK_RESPONSE_YES;
+}
diff --git a/e-util/e-misc-utils.h b/e-util/e-misc-utils.h
index 1d9d016..78146ce 100644
--- a/e-util/e-misc-utils.h
+++ b/e-util/e-misc-utils.h
@@ -272,6 +272,11 @@ void               e_signal_disconnect_notify_handler
 
 GSettings *    e_util_ref_settings             (const gchar *schema_id);
 void           e_util_cleanup_settings         (void);
+gboolean       e_util_prompt_user              (GtkWindow *parent,
+                                                const gchar *settings_schema,
+                                                const gchar *promptkey,
+                                                const gchar *tag,
+                                                ...);
 
 G_END_DECLS
 
diff --git a/mail/e-mail-backend.c b/mail/e-mail-backend.c
index beb5eef..cfe28a6 100644
--- a/mail/e-mail-backend.c
+++ b/mail/e-mail-backend.c
@@ -211,8 +211,8 @@ mail_backend_prepare_for_offline_cb (EShell *shell,
                        mail_backend_any_store_requires_downsync (account_store);
 
                if (ask_to_synchronize) {
-                       synchronize = em_utils_prompt_user (
-                               window, NULL, "mail:ask-quick-offline", NULL);
+                       synchronize = e_util_prompt_user (
+                               window, "org.gnome.evolution.mail", NULL, "mail:ask-quick-offline", NULL);
                }
 
                if (!synchronize) {
diff --git a/mail/e-mail-reader-utils.c b/mail/e-mail-reader-utils.c
index 42dcf4b..0df7af1 100644
--- a/mail/e-mail-reader-utils.c
+++ b/mail/e-mail-reader-utils.c
@@ -443,8 +443,8 @@ e_mail_reader_expunge_folder (EMailReader *reader,
        window = e_mail_reader_get_window (reader);
        display_name = camel_folder_get_display_name (folder);
 
-       proceed = em_utils_prompt_user (
-               window, "prompt-on-expunge",
+       proceed = e_util_prompt_user (
+               window, "org.gnome.evolution.mail", "prompt-on-expunge",
                "mail:ask-expunge", display_name, NULL);
 
        if (proceed) {
@@ -1511,8 +1511,8 @@ mail_reader_remove_duplicates_cb (GObject *source_object,
        n_duplicates = g_hash_table_size (duplicates);
 
        if (n_duplicates == 0) {
-               em_utils_prompt_user (
-                       parent_window, NULL,
+               e_util_prompt_user (
+                       parent_window, "org.gnome.evolution.mail", NULL,
                        "mail:info-no-remove-duplicates",
                        camel_folder_get_display_name (folder), NULL);
        } else {
@@ -1530,8 +1530,8 @@ mail_reader_remove_duplicates_cb (GObject *source_object,
                        camel_folder_get_display_name (folder),
                        n_duplicates);
 
-               proceed = em_utils_prompt_user (
-                       parent_window, NULL,
+               proceed = e_util_prompt_user (
+                       parent_window, "org.gnome.evolution.mail", NULL,
                        "mail:ask-remove-duplicates",
                        confirmation, NULL);
 
diff --git a/mail/em-composer-utils.c b/mail/em-composer-utils.c
index 8e5212b..4874995 100644
--- a/mail/em-composer-utils.c
+++ b/mail/em-composer-utils.c
@@ -129,9 +129,9 @@ ask_confirm_for_unwanted_html_mail (EMsgComposer *composer,
        }
 
        if (str->len)
-               res = em_utils_prompt_user (
+               res = e_util_prompt_user (
                        GTK_WINDOW (composer),
-                       "prompt-on-unwanted-html",
+                       "prompt-on-unwanted-html", "org.gnome.evolution.mail",
                        "mail:ask-send-html", str->str, NULL);
        else
                res = TRUE;
@@ -144,8 +144,9 @@ ask_confirm_for_unwanted_html_mail (EMsgComposer *composer,
 static gboolean
 ask_confirm_for_empty_subject (EMsgComposer *composer)
 {
-       return em_utils_prompt_user (
+       return e_util_prompt_user (
                GTK_WINDOW (composer),
+               "org.gnome.evolution.mail",
                "prompt-on-empty-subject",
                "mail:ask-send-no-subject", NULL);
 }
@@ -160,8 +161,9 @@ ask_confirm_for_only_bcc (EMsgComposer *composer,
         * this dialog to provide slightly different text in that case, to
         * better explain what the hell is going on. */
 
-       return em_utils_prompt_user (
+       return e_util_prompt_user (
                GTK_WINDOW (composer),
+               "org.gnome.evolution.mail",
                "prompt-on-only-bcc",
                hidden_list_case ?
                "mail:ask-send-only-bcc-contact" :
@@ -306,8 +308,9 @@ composer_presend_check_recipients (EMsgComposer *composer,
        }
 
        if (invalid_addrs) {
-               if (!em_utils_prompt_user (
+               if (!e_util_prompt_user (
                        GTK_WINDOW (composer),
+                       "org.gnome.evolution.mail",
                        "prompt-on-invalid-recip",
                        strstr (invalid_addrs->str, ", ") ?
                                "mail:ask-send-invalid-recip-multi" :
@@ -381,7 +384,8 @@ composer_presend_check_downloads (EMsgComposer *composer,
        store = e_attachment_view_get_store (view);
 
        if (e_attachment_store_get_num_loading (store) > 0) {
-               if (!em_utils_prompt_user (GTK_WINDOW (composer), NULL,
+               if (!e_util_prompt_user (GTK_WINDOW (composer),
+                   "org.gnome.evolution.mail", NULL,
                    "mail-composer:ask-send-message-pending-download", NULL))
                        check_passed = FALSE;
        }
diff --git a/mail/em-utils.c b/mail/em-utils.c
index b152359..88b845b 100644
--- a/mail/em-utils.c
+++ b/mail/em-utils.c
@@ -75,79 +75,14 @@ em_utils_ask_open_many (GtkWindow *parent,
                "Are you sure you want to open %d message at once?",
                "Are you sure you want to open %d messages at once?",
                how_many), how_many);
-       proceed = em_utils_prompt_user (
-               parent, "prompt-on-open-many",
+       proceed = e_util_prompt_user (
+               parent, "org.gnome.evolution.mail", "prompt-on-open-many",
                "mail:ask-open-many", string, NULL);
        g_free (string);
 
        return proceed;
 }
 
-/**
- * em_utils_prompt_user:
- * @parent: parent window
- * @promptkey: settings key to check if we should prompt the user or not.
- * @tag: e_alert tag.
- *
- * Convenience function to query the user with a Yes/No dialog and a
- * "Do not show this dialog again" checkbox. If the user checks that
- * checkbox, then @promptkey is set to %FALSE, otherwise it is set to
- * %TRUE.
- *
- * Returns %TRUE if the user clicks Yes or %FALSE otherwise.
- **/
-gboolean
-em_utils_prompt_user (GtkWindow *parent,
-                      const gchar *promptkey,
-                      const gchar *tag,
-                      ...)
-{
-       GtkWidget *dialog;
-       GtkWidget *check = NULL;
-       GtkWidget *container;
-       va_list ap;
-       gint button;
-       GSettings *settings;
-       EAlert *alert = NULL;
-
-       settings = e_util_ref_settings ("org.gnome.evolution.mail");
-
-       if (promptkey && !g_settings_get_boolean (settings, promptkey)) {
-               g_object_unref (settings);
-               return TRUE;
-       }
-
-       va_start (ap, tag);
-       alert = e_alert_new_valist (tag, ap);
-       va_end (ap);
-
-       dialog = e_alert_dialog_new (parent, alert);
-       g_object_unref (alert);
-
-       container = e_alert_dialog_get_content_area (E_ALERT_DIALOG (dialog));
-
-       if (promptkey) {
-               check = gtk_check_button_new_with_mnemonic (
-                       _("_Do not show this message again"));
-               gtk_box_pack_start (
-                       GTK_BOX (container), check, FALSE, FALSE, 0);
-               gtk_widget_show (check);
-       }
-
-       button = gtk_dialog_run (GTK_DIALOG (dialog));
-       if (promptkey)
-               g_settings_set_boolean (
-                       settings, promptkey,
-                       !gtk_toggle_button_get_active (
-                               GTK_TOGGLE_BUTTON (check)));
-
-       gtk_widget_destroy (dialog);
-
-       g_object_unref (settings);
-
-       return button == GTK_RESPONSE_YES;
-}
-
 /* Editing Filters/Search Folders... */
 
 static GtkWidget *filter_editor = NULL;
@@ -1332,7 +1267,8 @@ em_utils_empty_trash (GtkWidget *parent,
 
        registry = e_mail_session_get_registry (session);
 
-       if (!em_utils_prompt_user ((GtkWindow *) parent,
+       if (!e_util_prompt_user ((GtkWindow *) parent,
+               "org.gnome.evolution.mail",
                "prompt-on-empty-trash",
                "mail:ask-empty-trash", NULL))
                return;
diff --git a/mail/em-utils.h b/mail/em-utils.h
index ccd4f71..8911cd7 100644
--- a/mail/em-utils.h
+++ b/mail/em-utils.h
@@ -36,7 +36,6 @@ G_BEGIN_DECLS
 struct _EMailPartList;
 
 gboolean em_utils_ask_open_many (GtkWindow *parent, gint how_many);
-gboolean em_utils_prompt_user (GtkWindow *parent, const gchar *promptkey, const gchar *tag, ...);
 
 void           em_utils_edit_filters           (EMailSession *session,
                                                 EAlertSink *alert_sink,
diff --git a/modules/mail/e-mail-shell-view-actions.c b/modules/mail/e-mail-shell-view-actions.c
index 5852101..6c6540d 100644
--- a/modules/mail/e-mail-shell-view-actions.c
+++ b/modules/mail/e-mail-shell-view-actions.c
@@ -588,7 +588,8 @@ mark_all_read_prompt_user (EMailShellView *mail_shell_view,
                        default:
                                break;
                }
-       } else if (em_utils_prompt_user (parent,
+       } else if (e_util_prompt_user (parent,
+                       "org.gnome.evolution.mail",
                        "prompt-on-mark-all-read",
                        "mail:ask-mark-all-read", NULL))
                return MARK_ALL_READ_CURRENT_ONLY;


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