[evolution/wip/gsettings] Adapt to new CamelSession background job API.
- From: Rodrigo Moya <rodrigo src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/wip/gsettings] Adapt to new CamelSession background job API.
- Date: Wed, 29 Jun 2011 17:28:12 +0000 (UTC)
commit 6154ca44a52803be56bc5c05ede52e304d07b7c2
Author: Matthew Barnes <mbarnes redhat com>
Date: Sat Apr 23 11:36:27 2011 -0400
Adapt to new CamelSession background job API.
mail/e-mail-backend.c | 117 +++++++++++++++++++++++++++++++++++++++++++++++--
mail/e-mail-session.c | 67 +++-------------------------
2 files changed, 119 insertions(+), 65 deletions(-)
---
diff --git a/mail/e-mail-backend.c b/mail/e-mail-backend.c
index b1eec7e..7665a64 100644
--- a/mail/e-mail-backend.c
+++ b/mail/e-mail-backend.c
@@ -49,10 +49,15 @@
#include "mail/mail-ops.h"
#include "mail/mail-vfolder.h"
+#define E_MAIL_BACKEND_GET_PRIVATE(obj) \
+ (G_TYPE_INSTANCE_GET_PRIVATE \
+ ((obj), E_TYPE_MAIL_BACKEND, EMailBackendPrivate))
+
#define QUIT_POLL_INTERVAL 1 /* seconds */
struct _EMailBackendPrivate {
EMailSession *session;
+ GHashTable *jobs;
};
enum {
@@ -395,6 +400,83 @@ mail_backend_folder_changed_cb (MailFolderCache *folder_cache,
}
static void
+mail_backend_job_started_cb (CamelSession *session,
+ GCancellable *cancellable,
+ EShellBackend *shell_backend)
+{
+ EMailBackendPrivate *priv;
+ EActivity *activity;
+
+ priv = E_MAIL_BACKEND_GET_PRIVATE (shell_backend);
+
+ activity = e_activity_new ();
+ e_activity_set_cancellable (activity, cancellable);
+ e_shell_backend_add_activity (shell_backend, activity);
+
+ /* The hash table takes ownership of the activity. */
+ g_hash_table_insert (priv->jobs, cancellable, activity);
+}
+
+static void
+mail_backend_job_finished_cb (CamelSession *session,
+ GCancellable *cancellable,
+ const GError *error,
+ EShellBackend *shell_backend)
+{
+ EMailBackendPrivate *priv;
+ EShellBackendClass *class;
+ EActivity *activity;
+ const gchar *description;
+
+ priv = E_MAIL_BACKEND_GET_PRIVATE (shell_backend);
+ class = E_SHELL_BACKEND_GET_CLASS (shell_backend);
+
+ activity = g_hash_table_lookup (priv->jobs, cancellable);
+ description = e_activity_get_text (activity);
+
+ if (error != NULL) {
+ EShell *shell;
+ GList *list, *iter;
+
+ shell = e_shell_backend_get_shell (shell_backend);
+ list = e_shell_get_watched_windows (shell);
+
+ /* Submit the error to an appropriate EAlertSink. */
+ for (iter = list; iter != NULL; iter = g_list_next (iter)) {
+ EShellView *shell_view;
+ EShellContent *shell_content;
+
+ if (!E_IS_SHELL_WINDOW (iter->data))
+ continue;
+
+ shell_view = e_shell_window_peek_shell_view (
+ E_SHELL_WINDOW (iter->data), class->name);
+
+ if (!E_IS_SHELL_VIEW (shell_view))
+ continue;
+
+ shell_content =
+ e_shell_view_get_shell_content (shell_view);
+
+ if (description != NULL && *description != '\0')
+ e_alert_submit (
+ E_ALERT_SINK (shell_content),
+ "mail:async-error", description,
+ error->message, NULL);
+ else
+ e_alert_submit (
+ E_ALERT_SINK (shell_content),
+ "mail:async-error-nodescribe",
+ error->message, NULL);
+
+ break;
+ }
+ }
+
+ g_hash_table_remove (priv->jobs, cancellable);
+}
+
+static void
mail_backend_get_property (GObject *object,
guint property_id,
GValue *value,
@@ -417,13 +499,19 @@ mail_backend_dispose (GObject *object)
{
EMailBackendPrivate *priv;
- priv = E_MAIL_BACKEND (object)->priv;
+ priv = E_MAIL_BACKEND_GET_PRIVATE (object);
if (priv->session != NULL) {
+ g_signal_handlers_disconnect_matched (
+ priv->session, G_SIGNAL_MATCH_DATA,
+ 0, 0, NULL, NULL, object);
g_object_unref (priv->session);
priv->session = NULL;
}
+ /* There should be no unfinished jobs left. */
+ g_warn_if_fail (g_hash_table_size (priv->jobs) == 0);
+
/* Chain up to parent's dispose() method. */
G_OBJECT_CLASS (e_mail_backend_parent_class)->dispose (object);
}
@@ -431,6 +519,12 @@ mail_backend_dispose (GObject *object)
static void
mail_backend_finalize (GObject *object)
{
+ EMailBackendPrivate *priv;
+
+ priv = E_MAIL_BACKEND_GET_PRIVATE (object);
+
+ g_hash_table_destroy (priv->jobs);
+
/* Chain up to parent's finalize() method. */
G_OBJECT_CLASS (e_mail_backend_parent_class)->finalize (object);
@@ -446,7 +540,7 @@ mail_backend_constructed (GObject *object)
EMFolderTreeModel *folder_tree_model;
MailFolderCache *folder_cache;
- priv = E_MAIL_BACKEND (object)->priv;
+ priv = E_MAIL_BACKEND_GET_PRIVATE (object);
shell_backend = E_SHELL_BACKEND (object);
shell = e_shell_backend_get_shell (shell_backend);
@@ -464,6 +558,16 @@ mail_backend_constructed (GObject *object)
priv->session, "online",
G_BINDING_SYNC_CREATE);
+ g_signal_connect (
+ priv->session, "job-started",
+ G_CALLBACK (mail_backend_job_started_cb),
+ shell_backend);
+
+ g_signal_connect (
+ priv->session, "job-finished",
+ G_CALLBACK (mail_backend_job_finished_cb),
+ shell_backend);
+
/* FIXME This is an evil hack that needs to die.
* Give EAccountComboBox a CamelSession property. */
e_account_combo_box_set_session (CAMEL_SESSION (priv->session));
@@ -546,8 +650,13 @@ e_mail_backend_class_init (EMailBackendClass *class)
static void
e_mail_backend_init (EMailBackend *backend)
{
- backend->priv = G_TYPE_INSTANCE_GET_PRIVATE (
- backend, E_TYPE_MAIL_BACKEND, EMailBackendPrivate);
+ backend->priv = E_MAIL_BACKEND_GET_PRIVATE (backend);
+
+ backend->priv->jobs = g_hash_table_new_full (
+ (GHashFunc) g_direct_hash,
+ (GEqualFunc) g_direct_equal,
+ (GDestroyNotify) NULL,
+ (GDestroyNotify) g_object_unref);
}
EMailSession *
diff --git a/mail/e-mail-session.c b/mail/e-mail-session.c
index f85c4ec..83e191f 100644
--- a/mail/e-mail-session.c
+++ b/mail/e-mail-session.c
@@ -64,6 +64,10 @@
#include "mail-send-recv.h"
#include "mail-tools.h"
+#define E_MAIL_SESSION_GET_PRIVATE(obj) \
+ (G_TYPE_INSTANCE_GET_PRIVATE \
+ ((obj), E_TYPE_MAIL_SESSION, EMailSessionPrivate))
+
static guint session_check_junk_notify_id;
static guint session_gconf_proxy_id;
@@ -553,7 +557,7 @@ mail_session_dispose (GObject *object)
{
EMailSessionPrivate *priv;
- priv = E_MAIL_SESSION (object)->priv;
+ priv = E_MAIL_SESSION_GET_PRIVATE (object);
if (priv->folder_cache != NULL) {
g_object_unref (priv->folder_cache);
@@ -796,61 +800,6 @@ mail_session_lookup_addressbook (CamelSession *session,
return ret;
}
-static gpointer
-mail_session_thread_msg_new (CamelSession *session,
- CamelSessionThreadOps *ops,
- guint size)
-{
- CamelSessionThreadMsg *msg;
- CamelSessionClass *session_class;
-
- /* TODO This is very temporary, until we have a better way to do
- * the progress reporting, we just borrow a dummy mail-mt
- * thread message and hook it onto out camel thread message. */
-
- /* Chain up to parent's thread_msg_new() method. */
- session_class = CAMEL_SESSION_CLASS (e_mail_session_parent_class);
- msg = session_class->thread_msg_new (session, ops, size);
-
-#if 0
- /* We create a dummy mail_msg, and then copy its cancellation
- * port over to ours, so we get cancellation and progress in
- * common with hte existing mail code, for free. */
- if (msg) {
- MailMsg *m = mail_msg_new (&ms_thread_info_dummy);
-
- msg->data = m;
- e_activity_set_cancellable (
- m->activity, msg->cancellable);
- }
-#endif
-
- return msg;
-}
-
-static void
-mail_session_thread_msg_free (CamelSession *session,
- CamelSessionThreadMsg *msg)
-{
- CamelSessionClass *session_class;
-
-#if 0
- mail_msg_unref (msg->data);
-#endif
-
- /* Chain up to parent's thread_msg_free() method. */
- session_class = CAMEL_SESSION_CLASS (e_mail_session_parent_class);
- session_class->thread_msg_free (session, msg);
-}
-
-static void
-mail_session_thread_status (CamelSession *session,
- CamelSessionThreadMsg *msg,
- const gchar *text,
- gint pc)
-{
-}
-
static gboolean
mail_session_forward_to (CamelSession *session,
CamelFolder *folder,
@@ -984,9 +933,6 @@ e_mail_session_class_init (EMailSessionClass *class)
session_class->alert_user = mail_session_alert_user;
session_class->get_filter_driver = mail_session_get_filter_driver;
session_class->lookup_addressbook = mail_session_lookup_addressbook;
- session_class->thread_msg_new = mail_session_thread_msg_new;
- session_class->thread_msg_free = mail_session_thread_msg_free;
- session_class->thread_status = mail_session_thread_status;
session_class->forward_to = mail_session_forward_to;
g_object_class_install_property (
@@ -1005,8 +951,7 @@ e_mail_session_init (EMailSession *session)
{
GConfClient *client;
- session->priv = G_TYPE_INSTANCE_GET_PRIVATE (
- session, E_TYPE_MAIL_SESSION, EMailSessionPrivate);
+ session->priv = E_MAIL_SESSION_GET_PRIVATE (session);
session->priv->folder_cache = mail_folder_cache_new ();
/* Initialize the EAccount setup. */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]