[evolution] I#479 - Call mail account refresh also after going online
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution] I#479 - Call mail account refresh also after going online
- Date: Fri, 14 Jun 2019 06:52:36 +0000 (UTC)
commit a20db2de0d28bb71304139b21b7ab310be20a41d
Author: Milan Crha <mcrha redhat com>
Date: Fri Jun 14 08:54:23 2019 +0200
I#479 - Call mail account refresh also after going online
Closes https://gitlab.gnome.org/GNOME/evolution/issues/479
src/libemail-engine/e-mail-session.c | 41 ++++++++++++++
src/libemail-engine/e-mail-session.h | 8 ++-
src/libemail-engine/mail-folder-cache.c | 12 ++++-
src/mail/e-mail-backend.c | 94 ++++++++++++++++++++++++++++++++-
4 files changed, 152 insertions(+), 3 deletions(-)
---
diff --git a/src/libemail-engine/e-mail-session.c b/src/libemail-engine/e-mail-session.c
index 40e53395ce..308e4bb20f 100644
--- a/src/libemail-engine/e-mail-session.c
+++ b/src/libemail-engine/e-mail-session.c
@@ -133,6 +133,7 @@ enum {
ALLOW_AUTH_PROMPT,
GET_RECIPIENT_CERTIFICATE,
ARCHIVE_FOLDER_CHANGED,
+ CONNECT_STORE,
LAST_SIGNAL
};
@@ -2137,6 +2138,26 @@ e_mail_session_class_init (EMailSessionClass *class)
G_TYPE_STRING,
G_TYPE_STRING,
G_TYPE_STRING);
+
+ /**
+ * EMailSession::connect-store
+ * @session: the #EMailSession that emitted the signal
+ * @store: a #CamelStore
+ *
+ * This signal is emitted with e_mail_session_emit_connect_store() to let
+ * any listeners know to connect the given @store.
+ *
+ * Since: 3.34
+ **/
+ signals[CONNECT_STORE] = g_signal_new (
+ "connect-store",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (EMailSessionClass, connect_store),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__OBJECT,
+ G_TYPE_NONE, 1,
+ CAMEL_TYPE_STORE);
}
static void
@@ -2992,3 +3013,23 @@ e_mail_session_is_archive_folder (EMailSession *session,
return is_archive_folder;
}
+
+/**
+ * e_mail_session_emit_connect_store:
+ * @session: an #EMailSession
+ * @store: a #CamelStore
+ *
+ * Emits 'connect-store' on @session for @store. This lets
+ * any listeners know to connect the @store.
+ *
+ * Since: 3.34
+ **/
+void
+e_mail_session_emit_connect_store (EMailSession *session,
+ CamelStore *store)
+{
+ g_return_if_fail (E_IS_MAIL_SESSION (session));
+ g_return_if_fail (CAMEL_IS_STORE (store));
+
+ g_signal_emit (session, signals[CONNECT_STORE], 0, store);
+}
diff --git a/src/libemail-engine/e-mail-session.h b/src/libemail-engine/e-mail-session.h
index 0e4f20d871..8b91e36e49 100644
--- a/src/libemail-engine/e-mail-session.h
+++ b/src/libemail-engine/e-mail-session.h
@@ -93,8 +93,11 @@ struct _EMailSessionClass {
const gchar *service_uid,
const gchar *old_folder_uri,
const gchar *new_folder_uri);
+ void (*connect_store) (EMailSession *session,
+ CamelStore *store);
+
/* Padding for future expansion */
- gpointer reserved[9];
+ gpointer reserved[8];
};
GType e_mail_session_get_type (void);
@@ -183,6 +186,9 @@ void e_mail_session_emit_allow_auth_prompt
gboolean e_mail_session_is_archive_folder
(EMailSession *session,
const gchar *folder_uri);
+void e_mail_session_emit_connect_store
+ (EMailSession *session,
+ CamelStore *store);
/* Useful GBinding transform functions */
gboolean e_binding_transform_service_to_source
diff --git a/src/libemail-engine/mail-folder-cache.c b/src/libemail-engine/mail-folder-cache.c
index a9bb31a40f..a06d7409c6 100644
--- a/src/libemail-engine/mail-folder-cache.c
+++ b/src/libemail-engine/mail-folder-cache.c
@@ -679,8 +679,18 @@ mail_folder_cache_check_connection_status_cb (CamelStore *store,
provider = camel_service_get_provider (CAMEL_SERVICE (store));
if (provider && (provider->flags & CAMEL_PROVIDER_IS_STORAGE) != 0) {
+ CamelSession *session;
+
+ session = camel_service_ref_session (CAMEL_SERVICE (store));
+
/* Connect it, when the host is reachable */
- camel_service_connect (CAMEL_SERVICE (store), G_PRIORITY_DEFAULT, NULL, NULL, NULL);
+ if (E_IS_MAIL_SESSION (session)) {
+ e_mail_session_emit_connect_store (E_MAIL_SESSION (session), store);
+ } else {
+ e_mail_store_go_online (store, G_PRIORITY_DEFAULT, NULL, NULL, NULL);
+ }
+
+ g_clear_object (&session);
}
}
diff --git a/src/mail/e-mail-backend.c b/src/mail/e-mail-backend.c
index 73da7f5e40..6e70bf94c4 100644
--- a/src/mail/e-mail-backend.c
+++ b/src/mail/e-mail-backend.c
@@ -148,6 +148,48 @@ mail_backend_store_operation_done_cb (CamelStore *store,
g_object_unref (activity);
}
+static void
+mail_backend_store_go_online_done_cb (CamelStore *store,
+ GAsyncResult *result,
+ EActivity *activity)
+{
+ CamelService *service;
+
+ service = CAMEL_SERVICE (store);
+
+ if (e_mail_store_go_online_finish (store, result, NULL) &&
+ camel_service_get_connection_status (service) == CAMEL_SERVICE_CONNECTED) {
+ CamelSession *session;
+
+ session = camel_service_ref_session (service);
+
+ if (E_IS_MAIL_SESSION (session) && camel_session_get_online (session)) {
+ ESourceRegistry *registry;
+ ESource *source;
+ GSettings *settings;
+ gboolean all_on_start;
+
+ settings = e_util_ref_settings ("org.gnome.evolution.mail");
+ all_on_start = g_settings_get_boolean (settings, "send-recv-all-on-start");
+ g_object_unref (settings);
+
+ registry = e_mail_session_get_registry (E_MAIL_SESSION (session));
+ source = e_source_registry_ref_source (registry, camel_service_get_uid (service));
+
+ if (source && e_source_has_extension (source, E_SOURCE_EXTENSION_REFRESH) &&
+ (all_on_start || e_source_refresh_get_enabled (e_source_get_extension (source,
E_SOURCE_EXTENSION_REFRESH)))) {
+ e_source_refresh_force_timeout (source);
+ }
+
+ g_clear_object (&source);
+ }
+
+ g_clear_object (&session);
+ }
+
+ g_object_unref (activity);
+}
+
static void
mail_backend_local_trash_expunge_done_cb (GObject *source_object,
GAsyncResult *result,
@@ -267,6 +309,8 @@ mail_backend_prepare_for_online_cb (EShell *shell,
EMailSession *session;
EMailAccountStore *account_store;
GQueue queue = G_QUEUE_INIT;
+ GSettings *settings;
+ gboolean with_send_recv;
if (e_shell_backend_is_started (E_SHELL_BACKEND (backend))) {
if (!e_activity_get_cancellable (activity)) {
@@ -280,6 +324,10 @@ mail_backend_prepare_for_online_cb (EShell *shell,
e_shell_backend_add_activity (E_SHELL_BACKEND (backend), activity);
}
+ settings = e_util_ref_settings ("org.gnome.evolution.mail");
+ with_send_recv = g_settings_get_boolean (settings, "send-recv-on-start");
+ g_object_unref (settings);
+
session = e_mail_backend_get_session (backend);
account_store = e_mail_ui_session_get_account_store (E_MAIL_UI_SESSION (session));
@@ -297,7 +345,7 @@ mail_backend_prepare_for_online_cb (EShell *shell,
e_mail_store_go_online (
CAMEL_STORE (service), G_PRIORITY_DEFAULT,
e_activity_get_cancellable (activity),
- (GAsyncReadyCallback) mail_backend_store_operation_done_cb,
+ (GAsyncReadyCallback) (with_send_recv ? mail_backend_store_go_online_done_cb
: mail_backend_store_operation_done_cb),
g_object_ref (activity));
}
}
@@ -976,6 +1024,46 @@ mail_backend_allow_auth_prompt_cb (EMailSession *session,
e_shell_allow_auth_prompt_for (shell, source);
}
+static void
+mail_backend_connect_store_cb (EMailSession *session,
+ CamelStore *store,
+ gpointer user_data)
+{
+ EMailBackend *mail_backend = user_data;
+ GCancellable *cancellable;
+ EActivity *activity;
+ GSettings *settings;
+ gboolean with_send_recv;
+ gchar *description;
+
+ g_return_if_fail (E_IS_MAIL_SESSION (session));
+ g_return_if_fail (E_IS_MAIL_BACKEND (mail_backend));
+ g_return_if_fail (CAMEL_IS_STORE (store));
+
+ settings = e_util_ref_settings ("org.gnome.evolution.mail");
+ with_send_recv = g_settings_get_boolean (settings, "send-recv-on-start");
+ g_object_unref (settings);
+
+ cancellable = camel_operation_new ();
+ description = g_strdup_printf (_("Reconnecting to ā%sā"), camel_service_get_display_name
(CAMEL_SERVICE (store)));
+
+ activity = e_activity_new ();
+ e_activity_set_cancellable (activity, cancellable);
+ e_activity_set_text (activity, description);
+
+ if (E_IS_MAIL_UI_SESSION (session))
+ e_mail_ui_session_add_activity (E_MAIL_UI_SESSION (session), activity);
+
+ e_mail_store_go_online (
+ store, G_PRIORITY_DEFAULT,
+ e_activity_get_cancellable (activity),
+ (GAsyncReadyCallback) (with_send_recv ? mail_backend_store_go_online_done_cb :
mail_backend_store_operation_done_cb),
+ activity); /* Takes ownership of 'activity' */
+
+ g_object_unref (cancellable);
+ g_free (description);
+}
+
static void
mail_backend_get_property (GObject *object,
guint property_id,
@@ -1236,6 +1324,10 @@ mail_backend_constructed (GObject *object)
priv->session, "flush-outbox",
G_CALLBACK (mail_send), priv->session);
+ g_signal_connect (
+ priv->session, "connect-store",
+ G_CALLBACK (mail_backend_connect_store_cb), object);
+
/* Propagate "activity-added" signals from
* the mail session to the shell backend. */
g_signal_connect_swapped (
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]