[evolution/wip/webkit2] Bug 769072 - Silently discards message when save to draft fails on quit



commit c443d1562caa19ea721a88d79707b6652e65d4e4
Author: Milan Crha <mcrha redhat com>
Date:   Thu Aug 4 20:19:20 2016 +0200

    Bug 769072 - Silently discards message when save to draft fails on quit

 composer/e-msg-composer.c |   45 +++++++++++++++++++++++++--------------------
 mail/em-composer-utils.c  |   33 +++++++++++++++++++++++++++++----
 mail/mail.error.xml       |    4 +++-
 3 files changed, 57 insertions(+), 25 deletions(-)
---
diff --git a/composer/e-msg-composer.c b/composer/e-msg-composer.c
index 323995e..ce453a8 100644
--- a/composer/e-msg-composer.c
+++ b/composer/e-msg-composer.c
@@ -2091,29 +2091,12 @@ msg_composer_notify_header_cb (EMsgComposer *composer)
 static gboolean
 msg_composer_delete_event_cb (EMsgComposer *composer)
 {
-       EShell *shell;
-       GtkApplication *application;
-       GList *windows;
-
-       shell = e_msg_composer_get_shell (composer);
-
        /* If the "async" action group is insensitive, it means an
         * asynchronous operation is in progress.  Block the event. */
        if (!gtk_action_group_get_sensitive (composer->priv->async_actions))
                return TRUE;
 
-       application = GTK_APPLICATION (shell);
-       windows = gtk_application_get_windows (application);
-
-       if (g_list_length (windows) == 1) {
-               /* This is the last watched window, use the quit
-                * mechanism to have a draft saved properly */
-               e_shell_quit (shell, E_SHELL_QUIT_ACTION);
-       } else {
-               /* There are more watched windows opened,
-                * invoke only a close action */
-               gtk_action_activate (ACTION (CLOSE));
-       }
+       gtk_action_activate (ACTION (CLOSE));
 
        return TRUE;
 }
@@ -4086,6 +4069,29 @@ e_msg_composer_send (EMsgComposer *composer)
 }
 
 static void
+msg_composer_save_to_drafts_done_cb (gpointer user_data,
+                                    GObject *gone_object)
+{
+       EMsgComposer *composer = user_data;
+       EHTMLEditor *editor;
+       EHTMLEditorView *view;
+
+       g_return_if_fail (E_IS_MSG_COMPOSER (composer));
+
+       editor = e_msg_composer_get_editor (composer);
+       view = e_html_editor_get_view (editor);
+
+       if (e_msg_composer_is_exiting (composer) &&
+           !e_html_editor_view_get_changed (view)) {
+               gtk_widget_destroy (GTK_WIDGET (composer));
+       } else if (e_msg_composer_is_exiting (composer)) {
+               gtk_widget_set_sensitive (GTK_WIDGET (composer), TRUE);
+               gtk_window_present (GTK_WINDOW (composer));
+               composer->priv->application_exiting = FALSE;
+       }
+}
+
+static void
 msg_composer_save_to_drafts_cb (EMsgComposer *composer,
                                 GAsyncResult *result,
                                 AsyncContext *context)
@@ -4147,7 +4153,7 @@ msg_composer_save_to_drafts_cb (EMsgComposer *composer,
        if (e_msg_composer_is_exiting (composer))
                g_object_weak_ref (
                        G_OBJECT (context->activity),
-                       (GWeakNotify) gtk_widget_destroy, composer);
+                       msg_composer_save_to_drafts_done_cb, composer);
 
        async_context_free (context);
 }
@@ -5413,7 +5419,6 @@ e_msg_composer_can_close (EMsgComposer *composer,
 
        switch (response) {
                case GTK_RESPONSE_YES:
-                       gtk_widget_hide (widget);
                        e_msg_composer_request_close (composer);
                        if (can_save_draft)
                                gtk_action_activate (ACTION (SAVE_DRAFT));
diff --git a/mail/em-composer-utils.c b/mail/em-composer-utils.c
index 3802d25..3088016 100644
--- a/mail/em-composer-utils.c
+++ b/mail/em-composer-utils.c
@@ -894,6 +894,10 @@ composer_save_to_drafts_complete (GObject *source_object,
 }
 
 static void
+composer_save_to_drafts_append_mail (AsyncContext *async_context,
+                                     CamelFolder *drafts_folder);
+
+static void
 composer_save_to_drafts_cleanup (GObject *source_object,
                                  GAsyncResult *result,
                                  gpointer user_data)
@@ -929,6 +933,27 @@ composer_save_to_drafts_cleanup (GObject *source_object,
 
        } else if (local_error != NULL) {
                g_warn_if_fail (async_context->message_uid == NULL);
+
+               if (e_msg_composer_is_exiting (async_context->composer)) {
+                       gint response;
+
+                       /* If we can't retrieve the Drafts folder for the
+                        * selected account, ask the user if he wants to
+                        * save to the local Drafts folder instead. */
+                       response = e_alert_run_dialog_for_args (
+                               GTK_WINDOW (async_context->composer),
+                               "mail:ask-default-drafts", local_error->message, NULL);
+                       if (response != GTK_RESPONSE_YES) {
+                               e_html_editor_view_set_changed (view, TRUE);
+                               async_context_free (async_context);
+                       } else {
+                               composer_save_to_drafts_append_mail (async_context, NULL);
+                       }
+
+                       g_error_free (local_error);
+                       return;
+               }
+
                e_alert_submit (
                        alert_sink,
                        "mail-composer:save-to-drafts-error",
@@ -1026,15 +1051,15 @@ composer_save_to_drafts_got_folder (GObject *source_object,
        } else if (local_error != NULL) {
                gint response;
 
-               /* XXX Not showing the error message in the dialog? */
-               g_error_free (local_error);
-
                /* If we can't retrieve the Drafts folder for the
                 * selected account, ask the user if he wants to
                 * save to the local Drafts folder instead. */
                response = e_alert_run_dialog_for_args (
                        GTK_WINDOW (async_context->composer),
-                       "mail:ask-default-drafts", NULL);
+                       "mail:ask-default-drafts", local_error->message, NULL);
+
+               g_error_free (local_error);
+
                if (response != GTK_RESPONSE_YES) {
                        e_content_editor_set_changed (cnt_editor, TRUE);
                        async_context_free (async_context);
diff --git a/mail/mail.error.xml b/mail/mail.error.xml
index 2293cf3..c4b6f9e 100644
--- a/mail/mail.error.xml
+++ b/mail/mail.error.xml
@@ -97,7 +97,9 @@ Many email systems add an Apparently-To header to messages that only have BCC re
 
   <error id="ask-default-drafts" type="question" default="GTK_RESPONSE_YES">
     <_primary>Use default drafts folder?</_primary>
-    <_secondary xml:space="preserve">Unable to open the drafts folder for this account. Use the system 
drafts folder instead?</_secondary>
+    <_secondary xml:space="preserve">Unable to open the drafts folder for this account. Use the system 
drafts folder instead?
+
+The reported error was &quot;{0}&quot;.</_secondary>
     <button stock="gtk-cancel" response="GTK_RESPONSE_CANCEL"/>
     <button _label="Use _Default" response="GTK_RESPONSE_YES"/>
   </error>


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