diff options
Diffstat (limited to 'composer')
-rw-r--r-- | composer/e-composer-actions.c | 18 | ||||
-rw-r--r-- | composer/e-msg-composer.c | 119 | ||||
-rw-r--r-- | composer/e-msg-composer.h | 8 | ||||
-rw-r--r-- | composer/mail-composer.error.xml | 14 |
4 files changed, 138 insertions, 21 deletions
diff --git a/composer/e-composer-actions.c b/composer/e-composer-actions.c index b47b60241a..5e57e6df2f 100644 --- a/composer/e-composer-actions.c +++ b/composer/e-composer-actions.c @@ -193,14 +193,28 @@ static void action_save_draft_cb (GtkAction *action, EMsgComposer *composer) { - e_msg_composer_save_draft (composer); + e_msg_composer_save_to_drafts (composer); } static void action_send_cb (GtkAction *action, EMsgComposer *composer) { - e_msg_composer_send (composer); + CamelSession *session; + + session = e_msg_composer_get_session (composer); + + /* If we're online, send the message now. + * Otherwise write the message to Outbox. */ + if (camel_session_get_online (session)) + e_msg_composer_send (composer); + else { + /* Inform the user. */ + e_alert_run_dialog_for_args ( + GTK_WINDOW (composer), + "mail-composer:saving-to-outbox", NULL); + e_msg_composer_save_to_outbox (composer); + } } static void diff --git a/composer/e-msg-composer.c b/composer/e-msg-composer.c index 34cf70597a..faa99acf1d 100644 --- a/composer/e-msg-composer.c +++ b/composer/e-msg-composer.c @@ -94,7 +94,8 @@ enum { enum { PRESEND, SEND, - SAVE_DRAFT, + SAVE_TO_DRAFTS, + SAVE_TO_OUTBOX, PRINT, LAST_SIGNAL }; @@ -2530,11 +2531,22 @@ e_msg_composer_class_init (EMsgComposerClass *class) CAMEL_TYPE_MIME_MESSAGE, E_TYPE_ACTIVITY); - signals[SAVE_DRAFT] = g_signal_new ( - "save-draft", + signals[SAVE_TO_DRAFTS] = g_signal_new ( + "save-to-drafts", G_OBJECT_CLASS_TYPE (class), G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (EMsgComposerClass, save_draft), + G_STRUCT_OFFSET (EMsgComposerClass, save_to_drafts), + NULL, NULL, + e_marshal_VOID__OBJECT_OBJECT, + G_TYPE_NONE, 2, + CAMEL_TYPE_MIME_MESSAGE, + E_TYPE_ACTIVITY); + + signals[SAVE_TO_OUTBOX] = g_signal_new ( + "save-to-outbox", + G_OBJECT_CLASS_TYPE (class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (EMsgComposerClass, save_to_outbox), NULL, NULL, e_marshal_VOID__OBJECT_OBJECT, G_TYPE_NONE, 2, @@ -3562,9 +3574,9 @@ e_msg_composer_send (EMsgComposer *composer) } static void -msg_composer_save_draft_cb (EMsgComposer *composer, - GAsyncResult *result, - AsyncContext *context) +msg_composer_save_to_drafts_cb (EMsgComposer *composer, + GAsyncResult *result, + AsyncContext *context) { CamelMimeMessage *message; GtkhtmlEditor *editor; @@ -3595,8 +3607,8 @@ msg_composer_save_draft_cb (EMsgComposer *composer, g_return_if_fail (CAMEL_IS_MIME_MESSAGE (message)); g_signal_emit ( - composer, signals[SAVE_DRAFT], 0, - message, context->activity); + composer, signals[SAVE_TO_DRAFTS], + 0, message, context->activity); g_object_unref (message); @@ -3608,13 +3620,13 @@ msg_composer_save_draft_cb (EMsgComposer *composer, } /** - * e_msg_composer_save_draft: + * e_msg_composer_save_to_drafts: * @composer: an #EMsgComposer * * Save the message in @composer to the selected account's Drafts folder. **/ void -e_msg_composer_save_draft (EMsgComposer *composer) +e_msg_composer_save_to_drafts (EMsgComposer *composer) { AsyncContext *context; EActivityBar *activity_bar; @@ -3634,7 +3646,90 @@ e_msg_composer_save_draft (EMsgComposer *composer) e_msg_composer_get_message_draft ( composer, G_PRIORITY_DEFAULT, cancellable, - (GAsyncReadyCallback) msg_composer_save_draft_cb, + (GAsyncReadyCallback) msg_composer_save_to_drafts_cb, + context); +} + +static void +msg_composer_save_to_outbox_cb (EMsgComposer *composer, + GAsyncResult *result, + AsyncContext *context) +{ + CamelMimeMessage *message; + GtkhtmlEditor *editor; + GError *error = NULL; + + message = e_msg_composer_get_message_finish (composer, result, &error); + + /* Ignore cancellations. */ + if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { + g_warn_if_fail (message == NULL); + async_context_free (context); + g_error_free (error); + return; + } + + if (error != NULL) { + g_warn_if_fail (message == NULL); + async_context_free (context); + e_alert_submit ( + GTK_WIDGET (composer), + "mail-composer:no-build-message", + error->message, NULL); + g_error_free (error); + return; + } + + g_return_if_fail (CAMEL_IS_MIME_MESSAGE (message)); + + g_signal_emit ( + composer, signals[SAVE_TO_OUTBOX], + 0, message, context->activity); + + g_object_unref (message); + + async_context_free (context); + + /* XXX This should be elsewhere. */ + editor = GTKHTML_EDITOR (composer); + gtkhtml_editor_set_changed (editor, FALSE); +} + +/** + * e_msg_composer_save_to_outbox: + * @composer: an #EMsgComposer + * + * Save the message in @composer to the local Outbox folder. + **/ +void +e_msg_composer_save_to_outbox (EMsgComposer *composer) +{ + AsyncContext *context; + EActivityBar *activity_bar; + GCancellable *cancellable; + gboolean proceed_with_save = TRUE; + + g_return_if_fail (E_IS_MSG_COMPOSER (composer)); + + /* This gives the user a chance to abort the save. */ + g_signal_emit (composer, signals[PRESEND], 0, &proceed_with_save); + + if (!proceed_with_save) + return; + + context = g_slice_new0 (AsyncContext); + context->activity = e_composer_activity_new (composer); + + cancellable = camel_operation_new (); + e_activity_set_cancellable (context->activity, cancellable); + g_object_unref (cancellable); + + activity_bar = E_ACTIVITY_BAR (composer->priv->activity_bar); + e_activity_bar_set_activity (activity_bar, context->activity); + + e_msg_composer_get_message ( + composer, G_PRIORITY_DEFAULT, cancellable, + (GAsyncReadyCallback) msg_composer_save_to_outbox_cb, context); } diff --git a/composer/e-msg-composer.h b/composer/e-msg-composer.h index 7b782c2c3a..2fe912d7a8 100644 --- a/composer/e-msg-composer.h +++ b/composer/e-msg-composer.h @@ -74,7 +74,10 @@ struct _EMsgComposerClass { GtkPrintOperationAction print_action, CamelMimeMessage *message, EActivity *activity); - void (*save_draft) (EMsgComposer *composer, + void (*save_to_drafts) (EMsgComposer *composer, + CamelMimeMessage *message, + EActivity *activity); + void (*save_to_outbox) (EMsgComposer *composer, CamelMimeMessage *message, EActivity *activity); void (*send) (EMsgComposer *composer, @@ -100,7 +103,8 @@ EShell * e_msg_composer_get_shell (EMsgComposer *composer); EWebView * e_msg_composer_get_web_view (EMsgComposer *composer); void e_msg_composer_send (EMsgComposer *composer); -void e_msg_composer_save_draft (EMsgComposer *composer); +void e_msg_composer_save_to_drafts (EMsgComposer *composer); +void e_msg_composer_save_to_outbox (EMsgComposer *composer); void e_msg_composer_print (EMsgComposer *composer, GtkPrintOperationAction print_action); diff --git a/composer/mail-composer.error.xml b/composer/mail-composer.error.xml index 90f0187b0e..e265aaad02 100644 --- a/composer/mail-composer.error.xml +++ b/composer/mail-composer.error.xml @@ -63,19 +63,23 @@ <_secondary>The reported error was "{0}". The message has not been sent.</_secondary> </error> - <error id="save-draft-error" type="error"> + <error id="save-to-drafts-error" type="error"> <_primary>An error occurred while saving to your Drafts folder.</_primary> <_secondary>The reported error was "{0}". The message has most likely not been saved.</_secondary> </error> <error id="send-error" type="error"> - <_primary>An error occurred while sending.</_primary> + <_primary>An error occurred while sending. How do you want to proceed?</_primary> <_secondary>The reported error was "{0}".</_secondary> + <!-- Response codes were chosen somewhat arbitrarily. --> + <button _label="_Continue Editing" response="GTK_RESPONSE_CLOSE"/> + <button _label="_Save to Outbox" response="GTK_RESPONSE_ACCEPT"/> + <button _label="_Try Again" response="GTK_RESPONSE_OK"/> </error> - <error id="saved-to-outbox" type="info"> - <_primary>Message saved to Outbox.</_primary> - <_secondary>Because you are working offline, the message has been saved to your local Outbox folder. When you are back online you can send the message by clicking the Send/Receive button in Evolution's toolbar.</_secondary> + <error id="saving-to-outbox" type="info"> + <_primary>Saving message to Outbox.</_primary> + <_secondary>Because you are working offline, the message will be saved to your local Outbox folder. When you are back online you can send the message by clicking the Send/Receive button in Evolution's toolbar.</_secondary> </error> </error-list> |