[evolution/gnome-3-20] Bug 769072 - Silently discards message when save to draft fails on quit



commit d6b3450528bf4807586781a4101eb8fd6913ec72
Author: Milan Crha <mcrha redhat com>
Date:   Thu Aug 4 20:26:55 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  |   25 +++++++++++++++++++++++++
 2 files changed, 50 insertions(+), 20 deletions(-)
---
diff --git a/composer/e-msg-composer.c b/composer/e-msg-composer.c
index 4adbf4a..2d40100 100644
--- a/composer/e-msg-composer.c
+++ b/composer/e-msg-composer.c
@@ -2315,29 +2315,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;
 }
@@ -4333,6 +4316,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)
@@ -4394,7 +4400,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);
 }
@@ -5691,7 +5697,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 82cad5e..889eea1 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", 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",


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