aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libemail-engine/e-mail-session.c143
-rw-r--r--mail/e-mail-config-auth-check.c1
-rw-r--r--mail/e-mail-ui-session.c285
-rw-r--r--mail/e-mail-ui-session.h5
-rw-r--r--mail/mail.error.xml15
5 files changed, 56 insertions, 393 deletions
diff --git a/libemail-engine/e-mail-session.c b/libemail-engine/e-mail-session.c
index dc42b00aac..533e0385f0 100644
--- a/libemail-engine/e-mail-session.c
+++ b/libemail-engine/e-mail-session.c
@@ -146,112 +146,6 @@ G_DEFINE_TYPE_WITH_CODE (
CAMEL_TYPE_SESSION,
G_IMPLEMENT_INTERFACE (E_TYPE_EXTENSIBLE, NULL))
-/* Support for CamelSession.alert_user() *************************************/
-
-static GQueue user_message_queue = { NULL, NULL, 0 };
-
-struct _user_message_msg {
- MailMsg base;
-
- EUserPrompter *prompter;
- CamelSessionAlertType type;
- gchar *prompt;
- GList *button_captions;
- EFlag *done;
-
- gint result;
- guint ismain : 1;
-};
-
-static void
-user_message_exec (struct _user_message_msg *m,
- GCancellable *cancellable,
- GError **error);
-
-static void
-user_message_response_cb (GObject *source,
- GAsyncResult *result,
- gpointer user_data)
-{
- struct _user_message_msg *m = user_data;
- GError *local_error = NULL;
-
- m->result = e_user_prompter_prompt_finish (
- E_USER_PROMPTER (source), result, &local_error);
-
- if (local_error != NULL) {
- g_warning (
- "%s: Failed to prompt user: %s",
- G_STRFUNC, local_error->message);
- g_clear_error (&local_error);
- }
-
- /* waiting for a response? */
- if (m->button_captions)
- e_flag_set (m->done);
-
- /* check for pendings */
- if (!g_queue_is_empty (&user_message_queue)) {
- GCancellable *cancellable;
-
- m = g_queue_pop_head (&user_message_queue);
- cancellable = m->base.cancellable;
- user_message_exec (m, cancellable, &m->base.error);
- mail_msg_unref (m);
- }
-}
-
-static void
-user_message_exec (struct _user_message_msg *m,
- GCancellable *cancellable,
- GError **error)
-{
- if (m->ismain) {
- const gchar *type = "";
-
- switch (m->type) {
- case CAMEL_SESSION_ALERT_INFO:
- type = "info";
- break;
- case CAMEL_SESSION_ALERT_WARNING:
- type = "warning";
- break;
- case CAMEL_SESSION_ALERT_ERROR:
- type = "error";
- break;
- }
-
- if (!m->prompter)
- m->prompter = e_user_prompter_new ();
-
- e_user_prompter_prompt (
- m->prompter, type, "",
- m->prompt, NULL, FALSE, m->button_captions, cancellable,
- user_message_response_cb, m);
- } else
- g_queue_push_tail (&user_message_queue, mail_msg_ref (m));
-}
-
-static void
-user_message_free (struct _user_message_msg *m)
-{
- g_free (m->prompt);
- g_list_free_full (m->button_captions, g_free);
- e_flag_free (m->done);
-
- if (m->prompter)
- g_object_unref (m->prompter);
- m->prompter = NULL;
-}
-
-static MailMsgInfo user_message_info = {
- sizeof (struct _user_message_msg),
- (MailMsgDescFunc) NULL,
- (MailMsgExecFunc) user_message_exec,
- (MailMsgDoneFunc) NULL,
- (MailMsgFreeFunc) user_message_free
-};
-
static gboolean
session_forward_to_flush_outbox_cb (gpointer user_data)
{
@@ -1371,42 +1265,6 @@ mail_session_forget_password (CamelSession *session,
return TRUE;
}
-static gint
-mail_session_alert_user (CamelSession *session,
- CamelSessionAlertType type,
- const gchar *prompt,
- GList *button_captions,
- GCancellable *cancellable)
-{
- struct _user_message_msg *m;
- gint result = -1;
-
- m = mail_msg_new (&user_message_info);
- m->ismain = mail_in_main_thread ();
- m->type = type;
- m->prompt = g_strdup (prompt);
- m->done = e_flag_new ();
- m->button_captions = g_list_copy_deep (
- button_captions, (GCopyFunc) g_strdup, NULL);
-
- if (g_list_length (button_captions) > 1)
- mail_msg_ref (m);
-
- if (m->ismain)
- user_message_exec (m, cancellable, &m->base.error);
- else
- mail_msg_main_loop_push (m);
-
- if (g_list_length (button_captions) > 1) {
- e_flag_wait (m->done);
- result = m->result;
- mail_msg_unref (m);
- } else if (m->ismain)
- mail_msg_unref (m);
-
- return result;
-}
-
static CamelCertTrust
mail_session_trust_prompt (CamelSession *session,
CamelService *service,
@@ -1787,7 +1645,6 @@ e_mail_session_class_init (EMailSessionClass *class)
session_class->add_service = mail_session_add_service;
session_class->get_password = mail_session_get_password;
session_class->forget_password = mail_session_forget_password;
- session_class->alert_user = mail_session_alert_user;
session_class->trust_prompt = mail_session_trust_prompt;
session_class->authenticate_sync = mail_session_authenticate_sync;
session_class->forward_to_sync = mail_session_forward_to_sync;
diff --git a/mail/e-mail-config-auth-check.c b/mail/e-mail-config-auth-check.c
index d514872939..42a2db5797 100644
--- a/mail/e-mail-config-auth-check.c
+++ b/mail/e-mail-config-auth-check.c
@@ -147,7 +147,6 @@ mail_config_auth_check_update (EMailConfigAuthCheck *auth_check)
NULL);
/* to be able to answer for invalid/self-signed server certificates */
- CAMEL_SESSION_GET_CLASS (session)->alert_user = e_mail_ui_session_alert_user;
CAMEL_SESSION_GET_CLASS (session)->trust_prompt = e_mail_ui_session_trust_prompt;
service = camel_session_add_service (
diff --git a/mail/e-mail-ui-session.c b/mail/e-mail-ui-session.c
index 4bd2af5daf..7248842c01 100644
--- a/mail/e-mail-ui-session.c
+++ b/mail/e-mail-ui-session.c
@@ -103,210 +103,6 @@ struct _SourceContext {
CamelService *service;
};
-/* Support for CamelSession.alert_user() *************************************/
-
-static gpointer user_message_dialog;
-static GQueue user_message_queue = { NULL, NULL, 0 };
-
-struct _user_message_msg {
- MailMsg base;
-
- CamelSessionAlertType type;
- gchar *prompt;
- GList *button_captions;
- EFlag *done;
-
- gint result;
- guint ismain : 1;
-};
-
-static void user_message_exec (struct _user_message_msg *m,
- GCancellable *cancellable,
- GError **error);
-
-static void
-user_message_response_free (GtkDialog *dialog,
- gint button)
-{
- struct _user_message_msg *m = NULL;
-
- gtk_widget_destroy ((GtkWidget *) dialog);
-
- user_message_dialog = NULL;
-
- /* check for pendings */
- if (!g_queue_is_empty (&user_message_queue)) {
- GCancellable *cancellable;
-
- m = g_queue_pop_head (&user_message_queue);
- cancellable = m->base.cancellable;
- user_message_exec (m, cancellable, &m->base.error);
- mail_msg_unref (m);
- }
-}
-
-/* clicked, send back the reply */
-static void
-user_message_response (GtkDialog *dialog,
- gint button,
- struct _user_message_msg *m)
-{
- /* if !m or !button_captions, then we've already replied */
- if (m && m->button_captions) {
- m->result = button;
- e_flag_set (m->done);
- }
-
- user_message_response_free (dialog, button);
-}
-
-static void
-user_message_exec (struct _user_message_msg *m,
- GCancellable *cancellable,
- GError **error)
-{
- gboolean info_only;
- GtkWindow *parent;
- EShell *shell;
- const gchar *error_type;
- gint index;
- GList *iter;
-
- info_only = g_list_length (m->button_captions) <= 1;
-
- if (!m->ismain && user_message_dialog != NULL && !info_only) {
- g_queue_push_tail (&user_message_queue, mail_msg_ref (m));
- return;
- }
-
- switch (m->type) {
- case CAMEL_SESSION_ALERT_INFO:
- error_type = "system:simple-info";
- break;
- case CAMEL_SESSION_ALERT_WARNING:
- error_type = "system:simple-warning";
- break;
- case CAMEL_SESSION_ALERT_ERROR:
- error_type = "system:simple-error";
- break;
- default:
- error_type = NULL;
- g_return_if_reached ();
- }
-
- shell = e_shell_get_default ();
-
- /* try to find "mail" view to place the informational alert to */
- if (info_only) {
- GtkWindow *active_window;
- EShellWindow *shell_window;
- EShellView *shell_view;
- EShellContent *shell_content = NULL;
-
- /* check currently active window first, ... */
- active_window = e_shell_get_active_window (shell);
- if (active_window && E_IS_SHELL_WINDOW (active_window)) {
- if (E_IS_SHELL_WINDOW (active_window)) {
- shell_window = E_SHELL_WINDOW (active_window);
- shell_view = e_shell_window_peek_shell_view (shell_window, "mail");
- if (shell_view)
- shell_content = e_shell_view_get_shell_content (shell_view);
- }
- }
-
- if (!shell_content) {
- GList *list, *iter;
-
- list = gtk_application_get_windows (GTK_APPLICATION (shell));
-
- /* ...then iterate through all opened
- * windows and pick one which has it */
- for (iter = list; iter != NULL && !shell_content; iter = g_list_next (iter)) {
- if (E_IS_SHELL_WINDOW (iter->data)) {
- shell_window = iter->data;
- shell_view = e_shell_window_peek_shell_view (shell_window, "mail");
- if (shell_view)
- shell_content = e_shell_view_get_shell_content (shell_view);
- }
- }
- }
-
- /* When no shell-content found, which might not happen,
- * but just in case, process the information alert like
- * usual, through an EAlertDialog machinery. */
- if (shell_content) {
- e_alert_submit (
- E_ALERT_SINK (shell_content),
- error_type, m->prompt, NULL);
- return;
- } else if (!m->ismain && user_message_dialog != NULL) {
- g_queue_push_tail (&user_message_queue, mail_msg_ref (m));
- return;
- }
- }
-
- /* Pull in the active window from the shell to get a parent window */
- parent = e_shell_get_active_window (shell);
- user_message_dialog = e_alert_dialog_new_for_args (
- parent, error_type, m->prompt, NULL);
- g_object_set (user_message_dialog, "resizable", TRUE, NULL);
-
- if (m->button_captions) {
- GtkWidget *action_area;
- GList *children, *child;
-
- /* remove all default buttons and keep only those requested */
- action_area = gtk_dialog_get_action_area (GTK_DIALOG (user_message_dialog));
-
- children = gtk_container_get_children (GTK_CONTAINER (action_area));
- for (child = children; child != NULL; child = child->next) {
- gtk_container_remove (GTK_CONTAINER (action_area), child->data);
- }
-
- g_list_free (children);
- }
-
- for (index = 0, iter = m->button_captions; iter; index++, iter = iter->next) {
- gtk_dialog_add_button (GTK_DIALOG (user_message_dialog), iter->data, index);
- }
-
- /* XXX This is a case where we need to be able to construct
- * custom EAlerts without a predefined XML definition. */
- if (m->ismain) {
- gint response;
-
- response = gtk_dialog_run (user_message_dialog);
- user_message_response (
- user_message_dialog, response, m);
- } else {
- gpointer user_data = m;
-
- if (g_list_length (m->button_captions) <= 1)
- user_data = NULL;
-
- g_signal_connect (
- user_message_dialog, "response",
- G_CALLBACK (user_message_response), user_data);
- gtk_widget_show (user_message_dialog);
- }
-}
-
-static void
-user_message_free (struct _user_message_msg *m)
-{
- g_free (m->prompt);
- g_list_free_full (m->button_captions, g_free);
- e_flag_free (m->done);
-}
-
-static MailMsgInfo user_message_info = {
- sizeof (struct _user_message_msg),
- (MailMsgDescFunc) NULL,
- (MailMsgExecFunc) user_message_exec,
- (MailMsgDoneFunc) NULL,
- (MailMsgFreeFunc) user_message_free
-};
-
/* Support for CamelSession.get_filter_driver () *****************************/
static CamelFolder *
@@ -659,45 +455,6 @@ mail_ui_session_remove_service (CamelSession *session,
e_mail_account_store_remove_service (store, NULL, service);
}
-gint
-e_mail_ui_session_alert_user (CamelSession *session,
- CamelSessionAlertType type,
- const gchar *prompt,
- GList *button_captions,
- GCancellable *cancellable)
-{
- struct _user_message_msg *m;
- gint result = -1;
-
- m = mail_msg_new (&user_message_info);
- m->ismain = mail_in_main_thread ();
- m->type = type;
- m->prompt = g_strdup (prompt);
- m->done = e_flag_new ();
- m->button_captions = g_list_copy_deep (
- button_captions, (GCopyFunc) g_strdup, NULL);
-
- if (g_list_length (button_captions) > 1)
- mail_msg_ref (m);
-
- if (!cancellable)
- cancellable = m->base.cancellable;
-
- if (m->ismain)
- user_message_exec (m, cancellable, &m->base.error);
- else
- mail_msg_main_loop_push (m);
-
- if (g_list_length (button_captions) > 1) {
- e_flag_wait (m->done);
- result = m->result;
- mail_msg_unref (m);
- } else if (m->ismain)
- mail_msg_unref (m);
-
- return result;
-}
-
CamelCertTrust
e_mail_ui_session_trust_prompt (CamelSession *session,
CamelService *service,
@@ -759,6 +516,46 @@ mail_ui_session_lookup_addressbook (CamelSession *session,
}
static void
+mail_ui_session_user_alert (CamelSession *session,
+ CamelService *service,
+ CamelSessionAlertType type,
+ const gchar *alert_message)
+{
+ EAlert *alert;
+ EShell *shell;
+ const gchar *alert_tag;
+ gchar *display_name;
+
+ shell = e_shell_get_default ();
+
+ switch (type) {
+ case CAMEL_SESSION_ALERT_INFO:
+ alert_tag = "mail:user-alert-info";
+ break;
+ case CAMEL_SESSION_ALERT_WARNING:
+ alert_tag = "mail:user-alert-warning";
+ break;
+ case CAMEL_SESSION_ALERT_ERROR:
+ alert_tag = "mail:user-alert-error";
+ break;
+ default:
+ g_return_if_reached ();
+ }
+
+ display_name = camel_service_dup_display_name (service);
+
+ /* Just submit the alert to the EShell rather than hunting for
+ * a suitable window. This will post it to all shell windows in
+ * all views, but if it's coming from the server then it must be
+ * important... right? */
+ alert = e_alert_new (alert_tag, display_name, alert_message, NULL);
+ e_shell_submit_alert (shell, alert);
+ g_object_unref (alert);
+
+ g_free (display_name);
+}
+
+static void
mail_ui_session_refresh_service (EMailSession *session,
CamelService *service)
{
@@ -790,9 +587,9 @@ e_mail_ui_session_class_init (EMailUISessionClass *class)
session_class = CAMEL_SESSION_CLASS (class);
session_class->add_service = mail_ui_session_add_service;
session_class->remove_service = mail_ui_session_remove_service;
- session_class->alert_user = e_mail_ui_session_alert_user;
session_class->get_filter_driver = mail_ui_session_get_filter_driver;
session_class->lookup_addressbook = mail_ui_session_lookup_addressbook;
+ session_class->user_alert = mail_ui_session_user_alert;
mail_session_class = E_MAIL_SESSION_CLASS (class);
mail_session_class->create_vfolder_context = mail_ui_session_create_vfolder_context;
diff --git a/mail/e-mail-ui-session.h b/mail/e-mail-ui-session.h
index dc8a149ab9..6caad3faad 100644
--- a/mail/e-mail-ui-session.h
+++ b/mail/e-mail-ui-session.h
@@ -89,11 +89,6 @@ EPhotoCache * e_mail_ui_session_get_photo_cache
(EMailUISession *session);
void e_mail_ui_session_add_activity (EMailUISession *session,
EActivity *activity);
-gint e_mail_ui_session_alert_user (CamelSession *session,
- CamelSessionAlertType type,
- const gchar *prompt,
- GList *button_captions,
- GCancellable *cancellable);
CamelCertTrust e_mail_ui_session_trust_prompt (CamelSession *session,
CamelService *service,
GTlsCertificate *certificate,
diff --git a/mail/mail.error.xml b/mail/mail.error.xml
index f067ed3b9d..6ff80e929c 100644
--- a/mail/mail.error.xml
+++ b/mail/mail.error.xml
@@ -521,5 +521,20 @@ An mbox account will be created to preserve the old mbox folders. You can delete
<_secondary xml:space="preserve">You must be working online to complete this operation.</_secondary>
</error>
+ <error id="user-alert-info" type="info">
+ <_primary>Message from &quot;{0}&quot; account:</_primary>
+ <secondary>{1}</secondary>
+ </error>
+
+ <error id="user-alert-warning" type="warning">
+ <_primary>Message from &quot;{0}&quot; account:</_primary>
+ <secondary>{1}</secondary>
+ </error>
+
+ <error id="user-alert-error" type="error">
+ <_primary>Message from &quot;{0}&quot; account:</_primary>
+ <secondary>{1}</secondary>
+ </error>
+
</error-list>