aboutsummaryrefslogtreecommitdiffstats
path: root/mail
diff options
context:
space:
mode:
authorMilan Crha <mcrha@redhat.com>2012-09-05 21:41:16 +0800
committerMilan Crha <mcrha@redhat.com>2012-09-05 21:42:03 +0800
commit511acab89a83114aad35e9c6f76a8f284907dab9 (patch)
tree4455567f90a3708dc43b172491388daf0f8c590e /mail
parent86c5e71225cda76616a5a5d5cfba46b84351b863 (diff)
downloadgsoc2013-evolution-511acab89a83114aad35e9c6f76a8f284907dab9.tar
gsoc2013-evolution-511acab89a83114aad35e9c6f76a8f284907dab9.tar.gz
gsoc2013-evolution-511acab89a83114aad35e9c6f76a8f284907dab9.tar.bz2
gsoc2013-evolution-511acab89a83114aad35e9c6f76a8f284907dab9.tar.lz
gsoc2013-evolution-511acab89a83114aad35e9c6f76a8f284907dab9.tar.xz
gsoc2013-evolution-511acab89a83114aad35e9c6f76a8f284907dab9.tar.zst
gsoc2013-evolution-511acab89a83114aad35e9c6f76a8f284907dab9.zip
Bug #682425 - Can do network operations on disabled accounts
Diffstat (limited to 'mail')
-rw-r--r--mail/e-mail-account-store.c41
-rw-r--r--mail/e-mail-account-store.h3
-rw-r--r--mail/e-mail-backend.c91
-rw-r--r--mail/e-mail-reader.c21
4 files changed, 92 insertions, 64 deletions
diff --git a/mail/e-mail-account-store.c b/mail/e-mail-account-store.c
index a78034aee5..9c777b5c6b 100644
--- a/mail/e-mail-account-store.c
+++ b/mail/e-mail-account-store.c
@@ -1365,6 +1365,47 @@ e_mail_account_store_queue_enabled_services (EMailAccountStore *store,
}
}
+gboolean
+e_mail_account_store_have_enabled_service (EMailAccountStore *store,
+ GType service_type)
+{
+ GtkTreeModel *tree_model;
+ GtkTreeIter iter;
+ gboolean iter_set;
+ gint column;
+ gboolean found = FALSE;
+
+ g_return_val_if_fail (E_IS_MAIL_ACCOUNT_STORE (store), FALSE);
+
+ tree_model = GTK_TREE_MODEL (store);
+
+ iter_set = gtk_tree_model_get_iter_first (tree_model, &iter);
+
+ while (iter_set && !found) {
+ GValue value = G_VALUE_INIT;
+ gboolean enabled;
+
+ column = E_MAIL_ACCOUNT_STORE_COLUMN_ENABLED;
+ gtk_tree_model_get_value (tree_model, &iter, column, &value);
+ enabled = g_value_get_boolean (&value);
+ g_value_unset (&value);
+
+ if (enabled) {
+ CamelService *service;
+
+ column = E_MAIL_ACCOUNT_STORE_COLUMN_SERVICE;
+ gtk_tree_model_get_value (tree_model, &iter, column, &value);
+ service = g_value_get_object (&value);
+ found = service && G_TYPE_CHECK_INSTANCE_TYPE (service, service_type);
+ g_value_unset (&value);
+ }
+
+ iter_set = gtk_tree_model_iter_next (tree_model, &iter);
+ }
+
+ return found;
+}
+
void
e_mail_account_store_reorder_services (EMailAccountStore *store,
GQueue *ordered_services)
diff --git a/mail/e-mail-account-store.h b/mail/e-mail-account-store.h
index 063f6c07ad..5bd696e051 100644
--- a/mail/e-mail-account-store.h
+++ b/mail/e-mail-account-store.h
@@ -134,6 +134,9 @@ void e_mail_account_store_queue_services
void e_mail_account_store_queue_enabled_services
(EMailAccountStore *store,
GQueue *out_queue);
+gboolean e_mail_account_store_have_enabled_service
+ (EMailAccountStore *store,
+ GType service_type);
void e_mail_account_store_reorder_services
(EMailAccountStore *store,
GQueue *ordered_services);
diff --git a/mail/e-mail-backend.c b/mail/e-mail-backend.c
index 81a16ed745..251bce953a 100644
--- a/mail/e-mail-backend.c
+++ b/mail/e-mail-backend.c
@@ -137,14 +137,25 @@ mail_backend_prepare_for_offline_cb (EShell *shell,
{
GtkWindow *window;
EMailSession *session;
- ESourceRegistry *registry;
- GList *list, *link;
- const gchar *extension_name;
+ EMailAccountStore *account_store;
+ GQueue queue = G_QUEUE_INIT;
gboolean synchronize = FALSE;
+ if (e_shell_backend_is_started (E_SHELL_BACKEND (backend))) {
+ if (!e_activity_get_cancellable (activity)) {
+ GCancellable *cancellable;
+
+ cancellable = camel_operation_new ();
+ e_activity_set_cancellable (activity, cancellable);
+ g_object_unref (cancellable);
+ }
+
+ e_shell_backend_add_activity (E_SHELL_BACKEND (backend), activity);
+ }
+
window = e_shell_get_active_window (shell);
session = e_mail_backend_get_session (backend);
- registry = e_mail_session_get_registry (session);
+ account_store = e_mail_ui_session_get_account_store (E_MAIL_UI_SESSION (session));
if (e_shell_get_network_available (shell) &&
e_shell_backend_is_started (E_SHELL_BACKEND (backend)))
@@ -157,34 +168,21 @@ mail_backend_prepare_for_offline_cb (EShell *shell,
CAMEL_SESSION (session), FALSE);
}
- extension_name = E_SOURCE_EXTENSION_MAIL_ACCOUNT;
- list = e_source_registry_list_sources (registry, extension_name);
-
- for (link = list; link != NULL; link = g_list_next (link)) {
- ESource *source = E_SOURCE (link->data);
+ e_mail_account_store_queue_enabled_services (account_store, &queue);
+ while (!g_queue_is_empty (&queue)) {
CamelService *service;
- const gchar *uid;
-
- uid = e_source_get_uid (source);
- service = camel_session_ref_service (
- CAMEL_SESSION (session), uid);
+ service = g_queue_pop_head (&queue);
if (service == NULL)
continue;
- /* FIXME Not passing a GCancellable. */
if (CAMEL_IS_STORE (service))
e_mail_store_go_offline (
- CAMEL_STORE (service),
- G_PRIORITY_DEFAULT,
- NULL, (GAsyncReadyCallback)
- mail_backend_store_operation_done_cb,
+ CAMEL_STORE (service), G_PRIORITY_DEFAULT,
+ e_activity_get_cancellable (activity),
+ (GAsyncReadyCallback) mail_backend_store_operation_done_cb,
g_object_ref (activity));
-
- g_object_unref (service);
}
-
- g_list_free_full (list, (GDestroyNotify) g_object_unref);
}
static void
@@ -193,46 +191,41 @@ mail_backend_prepare_for_online_cb (EShell *shell,
EMailBackend *backend)
{
EMailSession *session;
- ESourceRegistry *registry;
- GList *list, *link;
- const gchar *extension_name;
+ EMailAccountStore *account_store;
+ GQueue queue = G_QUEUE_INIT;
- session = e_mail_backend_get_session (backend);
- registry = e_mail_session_get_registry (session);
+ if (e_shell_backend_is_started (E_SHELL_BACKEND (backend))) {
+ if (!e_activity_get_cancellable (activity)) {
+ GCancellable *cancellable;
- camel_session_set_online (CAMEL_SESSION (session), TRUE);
+ cancellable = camel_operation_new ();
+ e_activity_set_cancellable (activity, cancellable);
+ g_object_unref (cancellable);
+ }
- extension_name = E_SOURCE_EXTENSION_MAIL_ACCOUNT;
- list = e_source_registry_list_sources (registry, extension_name);
+ e_shell_backend_add_activity (E_SHELL_BACKEND (backend), activity);
+ }
- for (link = list; link != NULL; link = g_list_next (link)) {
- ESource *source = E_SOURCE (link->data);
- CamelService *service;
- const gchar *uid;
+ session = e_mail_backend_get_session (backend);
+ account_store = e_mail_ui_session_get_account_store (E_MAIL_UI_SESSION (session));
- if (!e_source_get_enabled (source))
- continue;
+ camel_session_set_online (CAMEL_SESSION (session), TRUE);
- uid = e_source_get_uid (source);
- service = camel_session_ref_service (
- CAMEL_SESSION (session), uid);
+ e_mail_account_store_queue_enabled_services (account_store, &queue);
+ while (!g_queue_is_empty (&queue)) {
+ CamelService *service;
+ service = g_queue_pop_head (&queue);
if (service == NULL)
continue;
- /* FIXME Not passing a GCancellable. */
if (CAMEL_IS_STORE (service))
e_mail_store_go_online (
- CAMEL_STORE (service),
- G_PRIORITY_DEFAULT,
- NULL, (GAsyncReadyCallback)
- mail_backend_store_operation_done_cb,
+ CAMEL_STORE (service), G_PRIORITY_DEFAULT,
+ e_activity_get_cancellable (activity),
+ (GAsyncReadyCallback) mail_backend_store_operation_done_cb,
g_object_ref (activity));
-
- g_object_unref (service);
}
-
- g_list_free_full (list, (GDestroyNotify) g_object_unref);
}
/* Helper for mail_backend_prepare_for_quit_cb() */
diff --git a/mail/e-mail-reader.c b/mail/e-mail-reader.c
index 659e5699a0..963b9e0f36 100644
--- a/mail/e-mail-reader.c
+++ b/mail/e-mail-reader.c
@@ -48,6 +48,7 @@
#include "mail/e-mail-backend.h"
#include "mail/e-mail-browser.h"
#include "mail/e-mail-reader-utils.h"
+#include "mail/e-mail-ui-session.h"
#include "mail/e-mail-view.h"
#include "mail/em-composer-utils.h"
#include "mail/em-event.h"
@@ -4118,8 +4119,8 @@ e_mail_reader_check_state (EMailReader *reader)
CamelStore *store = NULL;
EMailBackend *backend;
ESourceRegistry *registry;
- GList *list, *iter;
- const gchar *extension_name;
+ EMailSession *mail_session;
+ EMailAccountStore *account_store;
const gchar *tag;
gboolean can_clear_flags = FALSE;
gboolean can_flag_completed = FALSE;
@@ -4146,6 +4147,8 @@ e_mail_reader_check_state (EMailReader *reader)
backend = e_mail_reader_get_backend (reader);
shell = e_shell_backend_get_shell (E_SHELL_BACKEND (backend));
registry = e_shell_get_registry (shell);
+ mail_session = e_mail_backend_get_session (backend);
+ account_store = e_mail_ui_session_get_account_store (E_MAIL_UI_SESSION (mail_session));
folder = e_mail_reader_get_folder (reader);
uids = e_mail_reader_get_selected_uids (reader);
@@ -4242,19 +4245,7 @@ e_mail_reader_check_state (EMailReader *reader)
camel_folder_free_message_info (folder, info);
}
- extension_name = E_SOURCE_EXTENSION_MAIL_ACCOUNT;
- list = e_source_registry_list_sources (registry, extension_name);
-
- for (iter = list; iter != NULL; iter = g_list_next (iter)) {
- ESource *source = E_SOURCE (iter->data);
-
- if (e_source_get_enabled (source)) {
- have_enabled_account = TRUE;
- break;
- }
- }
-
- g_list_free_full (list, (GDestroyNotify) g_object_unref);
+ have_enabled_account = e_mail_account_store_have_enabled_service (account_store, CAMEL_TYPE_STORE);
if (have_enabled_account)
state |= E_MAIL_READER_HAVE_ENABLED_ACCOUNT;