aboutsummaryrefslogtreecommitdiffstats
path: root/modules/calendar
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2013-01-24 05:05:08 +0800
committerMatthew Barnes <mbarnes@redhat.com>2013-01-30 22:35:27 +0800
commitf19241d136043d5cfffbfbaf5b2d6d1affc70682 (patch)
tree6abc10286b092dfc9b046bde599f24767ad0c177 /modules/calendar
parente583928e0401a4baea4432c5b7e12a1b1eff8c2e (diff)
downloadgsoc2013-evolution-f19241d136043d5cfffbfbaf5b2d6d1affc70682.tar.gz
gsoc2013-evolution-f19241d136043d5cfffbfbaf5b2d6d1affc70682.tar.zst
gsoc2013-evolution-f19241d136043d5cfffbfbaf5b2d6d1affc70682.zip
Use e_cal_client_connect().
Instead of e_client_utils_open_new() or e_cal_client_new().
Diffstat (limited to 'modules/calendar')
-rw-r--r--modules/calendar/e-cal-attachment-handler.c36
-rw-r--r--modules/calendar/e-cal-shell-backend.c51
-rw-r--r--modules/calendar/e-cal-shell-sidebar.c424
-rw-r--r--modules/calendar/e-cal-shell-sidebar.h3
-rw-r--r--modules/calendar/e-cal-shell-view-actions.c30
-rw-r--r--modules/calendar/e-memo-shell-backend.c43
-rw-r--r--modules/calendar/e-memo-shell-sidebar.c424
-rw-r--r--modules/calendar/e-memo-shell-sidebar.h3
-rw-r--r--modules/calendar/e-task-shell-backend.c43
-rw-r--r--modules/calendar/e-task-shell-sidebar.c424
-rw-r--r--modules/calendar/e-task-shell-sidebar.h3
11 files changed, 836 insertions, 648 deletions
diff --git a/modules/calendar/e-cal-attachment-handler.c b/modules/calendar/e-cal-attachment-handler.c
index 372b826e51..d16f4a6bfc 100644
--- a/modules/calendar/e-cal-attachment-handler.c
+++ b/modules/calendar/e-cal-attachment-handler.c
@@ -171,16 +171,20 @@ attachment_handler_import_event (GObject *source_object,
{
ESource *source = E_SOURCE (source_object);
EAttachment *attachment = user_data;
- EClient *client = NULL;
- GError *error = NULL;
+ EClient *client;
icalcomponent *component;
icalcomponent *subcomponent;
icalcompiter iter;
+ GError *error = NULL;
- e_client_utils_open_new_finish (source, result, &client, &error);
+ client = e_cal_client_connect_finish (result, &error);
+
+ /* Sanity check. */
+ g_return_if_fail (
+ ((client != NULL) && (error == NULL)) ||
+ ((client == NULL) && (error != NULL)));
if (error != NULL) {
- g_warn_if_fail (client == NULL);
g_warning (
"%s: Failed to open '%s': %s",
G_STRFUNC, e_source_get_display_name (source),
@@ -190,8 +194,6 @@ attachment_handler_import_event (GObject *source_object,
return;
}
- g_return_if_fail (E_IS_CLIENT (client));
-
component = attachment_handler_get_component (attachment);
g_return_if_fail (component != NULL);
@@ -227,16 +229,20 @@ attachment_handler_import_todo (GObject *source_object,
{
ESource *source = E_SOURCE (source_object);
EAttachment *attachment = user_data;
- EClient *client = NULL;
- GError *error = NULL;
+ EClient *client;
icalcomponent *component;
icalcomponent *subcomponent;
icalcompiter iter;
+ GError *error = NULL;
- e_client_utils_open_new_finish (source, result, &client, &error);
+ client = e_cal_client_connect_finish (result, &error);
+
+ /* Sanity check. */
+ g_return_if_fail (
+ ((client != NULL) && (error == NULL)) ||
+ ((client == NULL) && (error != NULL)));
if (error != NULL) {
- g_warn_if_fail (client == NULL);
g_warning (
"%s: Failed to open '%s': %s",
G_STRFUNC, e_source_get_display_name (source),
@@ -246,8 +252,6 @@ attachment_handler_import_todo (GObject *source_object,
return;
}
- g_return_if_fail (E_IS_CLIENT (client));
-
component = attachment_handler_get_component (attachment);
g_return_if_fail (component != NULL);
@@ -363,14 +367,14 @@ attachment_handler_run_dialog (GtkWindow *parent,
switch (source_type) {
case E_CAL_CLIENT_SOURCE_TYPE_EVENTS:
- e_client_utils_open_new (
- source, E_CLIENT_SOURCE_TYPE_EVENTS, FALSE, NULL,
+ e_cal_client_connect (
+ source, source_type, NULL,
attachment_handler_import_event,
g_object_ref (attachment));
break;
case E_CAL_CLIENT_SOURCE_TYPE_TASKS:
- e_client_utils_open_new (
- source, E_CLIENT_SOURCE_TYPE_TASKS, FALSE, NULL,
+ e_cal_client_connect (
+ source, source_type, NULL,
attachment_handler_import_todo,
g_object_ref (attachment));
break;
diff --git a/modules/calendar/e-cal-shell-backend.c b/modules/calendar/e-cal-shell-backend.c
index 476831987a..4d9eee63c4 100644
--- a/modules/calendar/e-cal-shell-backend.c
+++ b/modules/calendar/e-cal-shell-backend.c
@@ -67,18 +67,22 @@ cal_shell_backend_new_event (ESource *source,
CompEditorFlags flags,
gboolean all_day)
{
- EClient *client = NULL;
+ EClient *client;
ECalClient *cal_client;
ECalComponent *comp;
EShellSettings *shell_settings;
CompEditor *editor;
GError *error = NULL;
- /* XXX Handle errors better. */
- e_client_utils_open_new_finish (source, result, &client, &error);
+ client = e_cal_client_connect_finish (result, &error);
+
+ /* Sanity check. */
+ g_return_if_fail (
+ ((client != NULL) && (error == NULL)) ||
+ ((client == NULL) && (error != NULL)));
+ /* XXX Handle errors better. */
if (error != NULL) {
- g_warn_if_fail (client == NULL);
g_warning (
"%s: Failed to open '%s': %s",
G_STRFUNC, e_source_get_display_name (source),
@@ -87,8 +91,6 @@ cal_shell_backend_new_event (ESource *source,
return;
}
- g_return_if_fail (E_IS_CAL_CLIENT (client));
-
cal_client = E_CAL_CLIENT (client);
shell_settings = e_shell_get_shell_settings (shell);
@@ -173,7 +175,7 @@ action_event_new_cb (GtkAction *action,
EShellBackend *shell_backend;
ESource *source;
ESourceRegistry *registry;
- EClientSourceType source_type;
+ ECalClientSourceType source_type;
const gchar *action_name;
shell = e_shell_window_get_shell (shell_window);
@@ -216,7 +218,7 @@ action_event_new_cb (GtkAction *action,
/* This callback is used for both appointments and meetings. */
- source_type = E_CLIENT_SOURCE_TYPE_EVENTS;
+ source_type = E_CAL_CLIENT_SOURCE_TYPE_EVENTS;
registry = e_shell_get_registry (shell);
source = e_source_registry_ref_default_calendar (registry);
@@ -227,18 +229,18 @@ action_event_new_cb (GtkAction *action,
/* Use a callback function appropriate for the action.
* FIXME Need to obtain a better default time zone. */
if (strcmp (action_name, "event-all-day-new") == 0)
- e_client_utils_open_new (
- source, source_type, FALSE, NULL,
+ e_cal_client_connect (
+ source, source_type, NULL,
cal_shell_backend_event_all_day_new_cb,
g_object_ref (shell));
else if (strcmp (action_name, "event-meeting-new") == 0)
- e_client_utils_open_new (
- source, source_type, FALSE, NULL,
+ e_cal_client_connect (
+ source, source_type, NULL,
cal_shell_backend_event_meeting_new_cb,
g_object_ref (shell));
else
- e_client_utils_open_new (
- source, source_type, FALSE, NULL,
+ e_cal_client_connect (
+ source, source_type, NULL,
cal_shell_backend_event_new_cb,
g_object_ref (shell));
@@ -346,7 +348,7 @@ cal_shell_backend_handle_uri_cb (EShellBackend *shell_backend,
EShellSettings *shell_settings;
CompEditor *editor;
CompEditorFlags flags = 0;
- ECalClient *client;
+ EClient *client;
ECalComponent *comp;
ESource *source;
ESourceRegistry *registry;
@@ -457,18 +459,18 @@ cal_shell_backend_handle_uri_cb (EShellBackend *shell_backend,
goto exit;
}
- client = e_cal_client_new (source, source_type, &error);
+ client = e_cal_client_connect_sync (source, source_type, NULL, &error);
- if (client != NULL)
- e_client_open_sync (E_CLIENT (client), TRUE, NULL, &error);
+ /* Sanity check. */
+ g_return_val_if_fail (
+ ((client != NULL) && (error == NULL)) ||
+ ((client == NULL) && (error != NULL)), FALSE);
if (error != NULL) {
g_warning (
"%s: Failed to create/open client '%s': %s",
G_STRFUNC, e_source_get_display_name (source),
error->message);
- if (client != NULL)
- g_object_unref (client);
g_object_unref (source);
g_error_free (error);
goto exit;
@@ -486,7 +488,8 @@ cal_shell_backend_handle_uri_cb (EShellBackend *shell_backend,
goto present;
e_cal_client_get_object_sync (
- client, comp_uid, comp_rid, &icalcomp, NULL, &error);
+ E_CAL_CLIENT (client),comp_uid,
+ comp_rid, &icalcomp, NULL, &error);
if (error != NULL) {
g_warning (
@@ -509,16 +512,16 @@ cal_shell_backend_handle_uri_cb (EShellBackend *shell_backend,
if (icalprop != NULL)
flags |= COMP_EDITOR_MEETING;
- if (itip_organizer_is_user (registry, comp, client))
+ if (itip_organizer_is_user (registry, comp, E_CAL_CLIENT (client)))
flags |= COMP_EDITOR_USER_ORG;
- if (itip_sentby_is_user (registry, comp, client))
+ if (itip_sentby_is_user (registry, comp, E_CAL_CLIENT (client)))
flags |= COMP_EDITOR_USER_ORG;
if (!e_cal_component_has_attendees (comp))
flags |= COMP_EDITOR_USER_ORG;
- editor = event_editor_new (client, shell, flags);
+ editor = event_editor_new (E_CAL_CLIENT (client), shell, flags);
comp_editor_edit_comp (editor, comp);
g_object_unref (comp);
diff --git a/modules/calendar/e-cal-shell-sidebar.c b/modules/calendar/e-cal-shell-sidebar.c
index 5f736b088c..aafae792e1 100644
--- a/modules/calendar/e-cal-shell-sidebar.c
+++ b/modules/calendar/e-cal-shell-sidebar.c
@@ -39,6 +39,8 @@
(G_TYPE_INSTANCE_GET_PRIVATE \
((obj), E_TYPE_CAL_SHELL_SIDEBAR, ECalShellSidebarPrivate))
+typedef struct _ConnectClosure ConnectClosure;
+
struct _ECalShellSidebarPrivate {
GtkWidget *paned;
GtkWidget *selector;
@@ -55,14 +57,23 @@ struct _ECalShellSidebarPrivate {
* opened. So the user first highlights a source, then
* sometime later we update our default-client property
* which is bound by an EBinding to ECalModel. */
- ECalClient *default_client;
+ EClient *default_client;
- ESource *loading_default_source_instance; /* not-reffed, only for comparison */
+ /* Not referenced, only for pointer comparison. */
+ ESource *connecting_default_source_instance;
- GCancellable *loading_default_client;
+ GCancellable *connecting_default_client;
GCancellable *loading_clients;
};
+struct _ConnectClosure {
+ ECalShellSidebar *cal_shell_sidebar;
+
+ /* For error messages. */
+ gchar *source_display_name;
+ gchar *parent_display_name;
+};
+
enum {
PROP_0,
PROP_DATE_NAVIGATOR,
@@ -84,9 +95,45 @@ G_DEFINE_DYNAMIC_TYPE (
e_cal_shell_sidebar,
E_TYPE_SHELL_SIDEBAR)
+static ConnectClosure *
+connect_closure_new (ECalShellSidebar *cal_shell_sidebar,
+ ESource *source)
+{
+ ConnectClosure *closure;
+ ESourceRegistry *registry;
+ ESourceSelector *selector;
+ ESource *parent;
+ const gchar *parent_uid;
+
+ selector = e_cal_shell_sidebar_get_selector (cal_shell_sidebar);
+ registry = e_source_selector_get_registry (selector);
+ parent_uid = e_source_get_parent (source);
+ parent = e_source_registry_ref_source (registry, parent_uid);
+
+ closure = g_slice_new0 (ConnectClosure);
+ closure->cal_shell_sidebar = g_object_ref (cal_shell_sidebar);
+ closure->source_display_name = e_source_dup_display_name (source);
+ closure->parent_display_name = e_source_dup_display_name (parent);
+
+ g_object_unref (parent);
+
+ return closure;
+}
+
+static void
+connect_closure_free (ConnectClosure *closure)
+{
+ g_object_unref (closure->cal_shell_sidebar);
+
+ g_free (closure->source_display_name);
+ g_free (closure->parent_display_name);
+
+ g_slice_free (ConnectClosure, closure);
+}
+
static void
cal_shell_sidebar_emit_client_added (ECalShellSidebar *cal_shell_sidebar,
- ECalClient *client)
+ EClient *client)
{
guint signal_id = signals[CLIENT_ADDED];
@@ -188,170 +235,170 @@ cal_shell_sidebar_backend_error_cb (ECalShellSidebar *cal_shell_sidebar,
}
static void
-cal_shell_sidebar_retrieve_capabilies_cb (GObject *source_object,
- GAsyncResult *result,
- gpointer user_data)
+cal_shell_sidebar_handle_connect_error (ECalShellSidebar *cal_shell_sidebar,
+ const gchar *parent_display_name,
+ const gchar *source_display_name,
+ const GError *error)
{
- ECalClient *client = E_CAL_CLIENT (source_object);
- ECalShellSidebar *cal_shell_sidebar = user_data;
- gchar *capabilities = NULL;
+ EShellView *shell_view;
+ EShellContent *shell_content;
+ EShellSidebar *shell_sidebar;
+ gboolean cancelled = FALSE;
+ gboolean offline_error;
- g_return_if_fail (client != NULL);
- g_return_if_fail (cal_shell_sidebar != NULL);
+ shell_sidebar = E_SHELL_SIDEBAR (cal_shell_sidebar);
+ shell_view = e_shell_sidebar_get_shell_view (shell_sidebar);
+ shell_content = e_shell_view_get_shell_content (shell_view);
- e_client_retrieve_capabilities_finish (
- E_CLIENT (client), result, &capabilities, NULL);
- g_free (capabilities);
+ cancelled |= g_error_matches (
+ error, G_IO_ERROR, G_IO_ERROR_CANCELLED);
+ cancelled |= g_error_matches (
+ error, E_CLIENT_ERROR, E_CLIENT_ERROR_CANCELLED);
- cal_shell_sidebar_emit_status_message (
- cal_shell_sidebar, _("Loading calendars"));
- cal_shell_sidebar_emit_client_added (cal_shell_sidebar, client);
- cal_shell_sidebar_emit_status_message (cal_shell_sidebar, NULL);
+ offline_error = g_error_matches (
+ error, E_CLIENT_ERROR, E_CLIENT_ERROR_REPOSITORY_OFFLINE);
+
+ if (cancelled) {
+ /* do nothing */
+ } else if (offline_error) {
+ e_alert_submit (
+ E_ALERT_SINK (shell_content),
+ "calendar:prompt-no-contents-offline-calendar",
+ parent_display_name,
+ source_display_name,
+ NULL);
+ } else {
+ e_alert_submit (
+ E_ALERT_SINK (shell_content),
+ "calendar:failed-open-calendar",
+ parent_display_name,
+ source_display_name,
+ error->message,
+ NULL);
+ }
}
static void
-cal_shell_sidebar_client_opened_cb (GObject *source_object,
- GAsyncResult *result,
- gpointer user_data)
+cal_shell_sidebar_client_connect_cb (GObject *source_object,
+ GAsyncResult *result,
+ gpointer user_data)
{
- ECalClient *client = E_CAL_CLIENT (source_object);
- ECalShellSidebar *cal_shell_sidebar = user_data;
- ESource *source, *parent;
- EShellView *shell_view;
+ EClient *client;
+ ConnectClosure *closure = user_data;
+ ECalShellContent *cal_shell_content;
EShellContent *shell_content;
EShellSidebar *shell_sidebar;
- ESourceRegistry *registry;
+ EShellView *shell_view;
+ ECalModel *model;
+ icaltimezone *timezone;
GError *error = NULL;
- source = e_client_get_source (E_CLIENT (client));
+ client = e_cal_client_connect_finish (result, &error);
- e_client_open_finish (E_CLIENT (client), result, &error);
+ /* Sanity check. */
+ g_return_if_fail (
+ ((client != NULL) && (error == NULL)) ||
+ ((client == NULL) && (error != NULL)));
- if (g_error_matches (error, E_CLIENT_ERROR, E_CLIENT_ERROR_CANCELLED) ||
- g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
- g_clear_error (&error);
- return;
+ if (error != NULL) {
+ cal_shell_sidebar_handle_connect_error (
+ closure->cal_shell_sidebar,
+ closure->parent_display_name,
+ closure->source_display_name,
+ error);
+ g_error_free (error);
+ goto exit;
}
- shell_sidebar = E_SHELL_SIDEBAR (cal_shell_sidebar);
+ /* FIXME Sidebar should not be accessing the EShellContent.
+ * This probably needs to be moved to ECalShellView. */
+ shell_sidebar = E_SHELL_SIDEBAR (closure->cal_shell_sidebar);
shell_view = e_shell_sidebar_get_shell_view (shell_sidebar);
shell_content = e_shell_view_get_shell_content (shell_view);
- registry = e_shell_get_registry (e_shell_backend_get_shell (e_shell_view_get_shell_backend (shell_view)));
- parent = e_source_registry_ref_source (registry, e_source_get_parent (source));
-
- /* Handle errors. */
- switch ((error && error->domain == E_CLIENT_ERROR) ? error->code : -1) {
- case -1:
- break;
-
- case E_CLIENT_ERROR_REPOSITORY_OFFLINE:
- e_alert_submit (
- E_ALERT_SINK (shell_content),
- "calendar:prompt-no-contents-offline-calendar",
- e_source_get_display_name (parent),
- e_source_get_display_name (source), NULL);
- /* fall through */
-
- default:
- if (error->code != E_CLIENT_ERROR_REPOSITORY_OFFLINE) {
- e_alert_submit (
- E_ALERT_SINK (shell_content),
- "calendar:failed-open-calendar",
- e_source_get_display_name (parent),
- e_source_get_display_name (source),
- error->message, NULL);
- }
-
- e_cal_shell_sidebar_remove_source (
- cal_shell_sidebar,
- e_client_get_source (E_CLIENT (client)));
- g_clear_error (&error);
- g_object_unref (parent);
- return;
- }
- g_clear_error (&error);
- g_object_unref (parent);
+ cal_shell_content = E_CAL_SHELL_CONTENT (shell_content);
+ model = e_cal_shell_content_get_model (cal_shell_content);
+ timezone = e_cal_model_get_timezone (model);
- /* to have them ready for later use */
- e_client_retrieve_capabilities (
- E_CLIENT (client), NULL,
- cal_shell_sidebar_retrieve_capabilies_cb,
- cal_shell_sidebar);
+ e_cal_client_set_default_timezone (E_CAL_CLIENT (client), timezone);
+
+ e_cal_shell_sidebar_add_client (closure->cal_shell_sidebar, client);
+
+ g_object_unref (client);
+
+exit:
+ connect_closure_free (closure);
}
static void
-cal_shell_sidebar_default_loaded_cb (GObject *source_object,
- GAsyncResult *result,
- gpointer user_data)
+cal_shell_sidebar_default_connect_cb (GObject *source_object,
+ GAsyncResult *result,
+ gpointer user_data)
{
- ESource *source = E_SOURCE (source_object);
- EShellSidebar *shell_sidebar = user_data;
+ EClient *client;
+ ESource *source;
+ ConnectClosure *closure = user_data;
ECalShellSidebarPrivate *priv;
EShellContent *shell_content;
+ EShellSidebar *shell_sidebar;
EShellView *shell_view;
ECalShellContent *cal_shell_content;
ECalModel *model;
- EClient *client = NULL;
+ icaltimezone *timezone;
GError *error = NULL;
- priv = E_CAL_SHELL_SIDEBAR_GET_PRIVATE (shell_sidebar);
+ priv = E_CAL_SHELL_SIDEBAR_GET_PRIVATE (closure->cal_shell_sidebar);
- shell_view = e_shell_sidebar_get_shell_view (shell_sidebar);
- shell_content = e_shell_view_get_shell_content (shell_view);
- cal_shell_content = E_CAL_SHELL_CONTENT (shell_content);
- model = e_cal_shell_content_get_model (cal_shell_content);
+ client = e_cal_client_connect_finish (result, &error);
- e_client_utils_open_new_finish (source, result, &client, &error);
+ /* Sanity check. */
+ g_return_if_fail (
+ ((client != NULL) && (error == NULL)) ||
+ ((client == NULL) && (error != NULL)));
- if (priv->loading_default_client) {
- g_object_unref (priv->loading_default_client);
- priv->loading_default_client = NULL;
+ if (priv->connecting_default_client != NULL) {
+ g_object_unref (priv->connecting_default_client);
+ priv->connecting_default_client = NULL;
}
- if (source == priv->loading_default_source_instance)
- priv->loading_default_source_instance = NULL;
-
- /* Ignore cancellations. */
- if (g_error_matches (error, E_CLIENT_ERROR, E_CLIENT_ERROR_CANCELLED) ||
- g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
- g_warn_if_fail (client == NULL);
+ if (error != NULL) {
+ cal_shell_sidebar_handle_connect_error (
+ closure->cal_shell_sidebar,
+ closure->parent_display_name,
+ closure->source_display_name,
+ error);
g_error_free (error);
goto exit;
-
- } else if (error != NULL) {
- ESourceRegistry *registry;
- ESource *parent;
-
- registry = e_shell_get_registry (e_shell_backend_get_shell (e_shell_view_get_shell_backend (shell_view)));
- parent = e_source_registry_ref_source (registry, e_source_get_parent (source));
-
- g_warn_if_fail (client == NULL);
- e_alert_submit (
- E_ALERT_SINK (shell_content),
- "calendar:failed-open-calendar",
- e_source_get_display_name (parent),
- e_source_get_display_name (source),
- error->message, NULL);
- g_error_free (error);
- g_object_unref (parent);
- goto exit;
}
- g_return_if_fail (E_IS_CAL_CLIENT (client));
+ source = e_client_get_source (client);
+
+ if (source == priv->connecting_default_source_instance)
+ priv->connecting_default_source_instance = NULL;
if (priv->default_client != NULL)
g_object_unref (priv->default_client);
- priv->default_client = E_CAL_CLIENT (client);
+ priv->default_client = g_object_ref (client);
- e_cal_client_set_default_timezone (
- priv->default_client, e_cal_model_get_timezone (model));
+ /* FIXME Sidebar should not be accessing the EShellContent.
+ * This probably needs to be moved to ECalShellView. */
+ shell_sidebar = E_SHELL_SIDEBAR (closure->cal_shell_sidebar);
+ shell_view = e_shell_sidebar_get_shell_view (shell_sidebar);
+ shell_content = e_shell_view_get_shell_content (shell_view);
+
+ cal_shell_content = E_CAL_SHELL_CONTENT (shell_content);
+ model = e_cal_shell_content_get_model (cal_shell_content);
+ timezone = e_cal_model_get_timezone (model);
+
+ e_cal_client_set_default_timezone (E_CAL_CLIENT (client), timezone);
g_object_notify (G_OBJECT (shell_sidebar), "default-client");
- exit:
- g_object_unref (shell_sidebar);
+ g_object_unref (client);
+
+exit:
+ connect_closure_free (closure);
}
static void
@@ -366,7 +413,7 @@ cal_shell_sidebar_set_default (ECalShellSidebar *cal_shell_sidebar,
priv = cal_shell_sidebar->priv;
/* already loading that source as default source */
- if (source == priv->loading_default_source_instance)
+ if (source == priv->connecting_default_source_instance)
return;
/* FIXME Sidebar should not be accessing the EShellContent.
@@ -374,10 +421,10 @@ cal_shell_sidebar_set_default (ECalShellSidebar *cal_shell_sidebar,
shell_sidebar = E_SHELL_SIDEBAR (cal_shell_sidebar);
/* Cancel any unfinished previous request. */
- if (priv->loading_default_client != NULL) {
- g_cancellable_cancel (priv->loading_default_client);
- g_object_unref (priv->loading_default_client);
- priv->loading_default_client = NULL;
+ if (priv->connecting_default_client != NULL) {
+ g_cancellable_cancel (priv->connecting_default_client);
+ g_object_unref (priv->connecting_default_client);
+ priv->connecting_default_client = NULL;
}
uid = e_source_get_uid (source);
@@ -394,14 +441,14 @@ cal_shell_sidebar_set_default (ECalShellSidebar *cal_shell_sidebar,
}
/* it's only for pointer comparison, no need to ref it */
- priv->loading_default_source_instance = source;
- priv->loading_default_client = g_cancellable_new ();
-
- e_client_utils_open_new (
- source, E_CLIENT_SOURCE_TYPE_EVENTS,
- FALSE, priv->loading_default_client,
- cal_shell_sidebar_default_loaded_cb,
- g_object_ref (shell_sidebar));
+ priv->connecting_default_source_instance = source;
+ priv->connecting_default_client = g_cancellable_new ();
+
+ e_cal_client_connect (
+ source, E_CAL_CLIENT_SOURCE_TYPE_EVENTS,
+ priv->connecting_default_client,
+ cal_shell_sidebar_default_connect_cb,
+ connect_closure_new (cal_shell_sidebar, source));
}
static void
@@ -569,10 +616,10 @@ cal_shell_sidebar_dispose (GObject *object)
priv->default_client = NULL;
}
- if (priv->loading_default_client != NULL) {
- g_cancellable_cancel (priv->loading_default_client);
- g_object_unref (priv->loading_default_client);
- priv->loading_default_client = NULL;
+ if (priv->connecting_default_client != NULL) {
+ g_cancellable_cancel (priv->connecting_default_client);
+ g_object_unref (priv->connecting_default_client);
+ priv->connecting_default_client = NULL;
}
if (priv->loading_clients != NULL) {
@@ -946,7 +993,7 @@ e_cal_shell_sidebar_get_default_client (ECalShellSidebar *cal_shell_sidebar)
g_return_val_if_fail (
E_IS_CAL_SHELL_SIDEBAR (cal_shell_sidebar), NULL);
- return cal_shell_sidebar->priv->default_client;
+ return (ECalClient *) cal_shell_sidebar->priv->default_client;
}
GtkWidget *
@@ -968,20 +1015,56 @@ e_cal_shell_sidebar_get_selector (ECalShellSidebar *cal_shell_sidebar)
}
void
+e_cal_shell_sidebar_add_client (ECalShellSidebar *cal_shell_sidebar,
+ EClient *client)
+{
+ ESource *source;
+ ESourceSelector *selector;
+ GHashTable *client_table;
+ const gchar *message;
+ const gchar *uid;
+
+ g_return_if_fail (E_IS_CAL_SHELL_SIDEBAR (cal_shell_sidebar));
+ g_return_if_fail (E_IS_CAL_CLIENT (client));
+
+ client_table = cal_shell_sidebar->priv->client_table;
+
+ source = e_client_get_source (client);
+ uid = e_source_get_uid (source);
+
+ if (g_hash_table_contains (client_table, uid))
+ return;
+
+ g_hash_table_insert (
+ client_table, g_strdup (uid), g_object_ref (client));
+
+ g_signal_connect_swapped (
+ client, "backend-died",
+ G_CALLBACK (cal_shell_sidebar_backend_died_cb),
+ cal_shell_sidebar);
+
+ g_signal_connect_swapped (
+ client, "backend-error",
+ G_CALLBACK (cal_shell_sidebar_backend_error_cb),
+ cal_shell_sidebar);
+
+ selector = e_cal_shell_sidebar_get_selector (cal_shell_sidebar);
+ e_source_selector_select_source (selector, source);
+
+ message = _("Loading calendars");
+ cal_shell_sidebar_emit_status_message (cal_shell_sidebar, message);
+ cal_shell_sidebar_emit_client_added (cal_shell_sidebar, client);
+ cal_shell_sidebar_emit_status_message (cal_shell_sidebar, NULL);
+}
+
+void
e_cal_shell_sidebar_add_source (ECalShellSidebar *cal_shell_sidebar,
ESource *source)
{
- EShellView *shell_view;
- EShellContent *shell_content;
- EShellSidebar *shell_sidebar;
- ECalShellContent *cal_shell_content;
ECalClientSourceType source_type;
ESourceSelector *selector;
GHashTable *client_table;
- ECalModel *model;
- ECalClient *default_client;
- ECalClient *client;
- icaltimezone *timezone;
+ EClient *default_client;
const gchar *display_name;
const gchar *uid;
gchar *message;
@@ -995,38 +1078,22 @@ e_cal_shell_sidebar_add_source (ECalShellSidebar *cal_shell_sidebar,
selector = e_cal_shell_sidebar_get_selector (cal_shell_sidebar);
uid = e_source_get_uid (source);
- client = g_hash_table_lookup (client_table, uid);
- if (client != NULL)
+ if (g_hash_table_contains (client_table, uid))
return;
if (default_client != NULL) {
ESource *default_source;
- const gchar *default_uid;
- default_source = e_client_get_source (E_CLIENT (default_client));
- default_uid = e_source_get_uid (default_source);
+ default_source = e_client_get_source (default_client);
- if (g_strcmp0 (uid, default_uid) == 0)
- client = g_object_ref (default_client);
+ if (e_source_equal (source, default_source)) {
+ e_cal_shell_sidebar_add_client (
+ cal_shell_sidebar, default_client);
+ return;
+ }
}
- if (client == NULL)
- client = e_cal_client_new (source, source_type, NULL);
-
- g_return_if_fail (client != NULL);
-
- g_signal_connect_swapped (
- client, "backend-died",
- G_CALLBACK (cal_shell_sidebar_backend_died_cb),
- cal_shell_sidebar);
-
- g_signal_connect_swapped (
- client, "backend-error",
- G_CALLBACK (cal_shell_sidebar_backend_error_cb),
- cal_shell_sidebar);
-
- g_hash_table_insert (client_table, g_strdup (uid), client);
e_source_selector_select_source (selector, source);
display_name = e_source_get_display_name (source);
@@ -1034,22 +1101,11 @@ e_cal_shell_sidebar_add_source (ECalShellSidebar *cal_shell_sidebar,
cal_shell_sidebar_emit_status_message (cal_shell_sidebar, message);
g_free (message);
- /* FIXME Sidebar should not be accessing the EShellContent.
- * This probably needs to be moved to ECalShellView. */
- shell_sidebar = E_SHELL_SIDEBAR (cal_shell_sidebar);
- shell_view = e_shell_sidebar_get_shell_view (shell_sidebar);
- shell_content = e_shell_view_get_shell_content (shell_view);
-
- cal_shell_content = E_CAL_SHELL_CONTENT (shell_content);
- model = e_cal_shell_content_get_model (cal_shell_content);
- timezone = e_cal_model_get_timezone (model);
-
- e_cal_client_set_default_timezone (client, timezone);
-
- e_client_open (
- E_CLIENT (client), FALSE,
+ e_cal_client_connect (
+ source, source_type,
cal_shell_sidebar->priv->loading_clients,
- cal_shell_sidebar_client_opened_cb, cal_shell_sidebar);
+ cal_shell_sidebar_client_connect_cb,
+ connect_closure_new (cal_shell_sidebar, source));
}
void
diff --git a/modules/calendar/e-cal-shell-sidebar.h b/modules/calendar/e-cal-shell-sidebar.h
index 6daabe25ca..6296b44b6a 100644
--- a/modules/calendar/e-cal-shell-sidebar.h
+++ b/modules/calendar/e-cal-shell-sidebar.h
@@ -96,6 +96,9 @@ GtkWidget * e_cal_shell_sidebar_get_new_calendar_button
ESourceSelector *
e_cal_shell_sidebar_get_selector
(ECalShellSidebar *cal_shell_sidebar);
+void e_cal_shell_sidebar_add_client
+ (ECalShellSidebar *cal_shell_sidebar,
+ EClient *client);
void e_cal_shell_sidebar_add_source
(ECalShellSidebar *cal_shell_sidebar,
ESource *source);
diff --git a/modules/calendar/e-cal-shell-view-actions.c b/modules/calendar/e-cal-shell-view-actions.c
index 8c66a68ed7..f9fdf1caf1 100644
--- a/modules/calendar/e-cal-shell-view-actions.c
+++ b/modules/calendar/e-cal-shell-view-actions.c
@@ -538,7 +538,7 @@ action_event_copy_cb (GtkAction *action,
ESource *source_source = NULL;
ESource *destination_source = NULL;
ESourceRegistry *registry;
- ECalClient *destination_client = NULL;
+ EClient *destination_client = NULL;
GList *selected, *iter;
GError *error = NULL;
@@ -571,12 +571,10 @@ action_event_copy_cb (GtkAction *action,
return;
/* Open the destination calendar. */
- destination_client = e_cal_client_new (
- destination_source, E_CAL_CLIENT_SOURCE_TYPE_EVENTS, NULL);
- if (destination_client == NULL)
- goto exit;
-
- e_client_open_sync (E_CLIENT (destination_client), FALSE, NULL, &error);
+ destination_client = e_cal_client_connect_sync (
+ destination_source,
+ E_CAL_CLIENT_SOURCE_TYPE_EVENTS,
+ NULL, &error);
if (error != NULL) {
g_warning (
@@ -594,7 +592,8 @@ action_event_copy_cb (GtkAction *action,
gboolean remove = FALSE;
e_cal_shell_view_transfer_item_to (
- cal_shell_view, event, destination_client, remove);
+ cal_shell_view, event,
+ E_CAL_CLIENT (destination_client), remove);
}
e_cal_shell_view_set_status_message (cal_shell_view, NULL, -1.0);
@@ -832,7 +831,7 @@ action_event_move_cb (GtkAction *action,
ESource *source_source = NULL;
ESource *destination_source = NULL;
ESourceRegistry *registry;
- ECalClient *destination_client = NULL;
+ EClient *destination_client = NULL;
GList *selected, *iter;
GError *error = NULL;
@@ -865,12 +864,10 @@ action_event_move_cb (GtkAction *action,
return;
/* Open the destination calendar. */
- destination_client = e_cal_client_new (
- destination_source, E_CAL_CLIENT_SOURCE_TYPE_EVENTS, NULL);
- if (destination_client == NULL)
- goto exit;
-
- e_client_open_sync (E_CLIENT (destination_client), FALSE, NULL, &error);
+ destination_client = e_cal_client_connect_sync (
+ destination_source,
+ E_CAL_CLIENT_SOURCE_TYPE_EVENTS,
+ NULL, &error);
if (error != NULL) {
g_warning (
@@ -888,7 +885,8 @@ action_event_move_cb (GtkAction *action,
gboolean remove = TRUE;
e_cal_shell_view_transfer_item_to (
- cal_shell_view, event, destination_client, remove);
+ cal_shell_view, event,
+ E_CAL_CLIENT (destination_client), remove);
}
e_cal_shell_view_set_status_message (cal_shell_view, NULL, -1.0);
diff --git a/modules/calendar/e-memo-shell-backend.c b/modules/calendar/e-memo-shell-backend.c
index 75fabd6d83..6f3d481d95 100644
--- a/modules/calendar/e-memo-shell-backend.c
+++ b/modules/calendar/e-memo-shell-backend.c
@@ -62,17 +62,21 @@ memo_shell_backend_new_memo (ESource *source,
EShell *shell,
CompEditorFlags flags)
{
- EClient *client = NULL;
+ EClient *client;
ECalClient *cal_client;
ECalComponent *comp;
CompEditor *editor;
GError *error = NULL;
- e_client_utils_open_new_finish (source, result, &client, &error);
+ client = e_cal_client_connect_finish (result, &error);
+
+ /* Sanity check. */
+ g_return_if_fail (
+ ((client != NULL) && (error == NULL)) ||
+ ((client == NULL) && (error != NULL)));
/* XXX Handle errors better. */
if (error != NULL) {
- g_warn_if_fail (client == NULL);
g_warning (
"%s: Failed to open '%s': %s",
G_STRFUNC, e_source_get_display_name (source),
@@ -81,8 +85,6 @@ memo_shell_backend_new_memo (ESource *source,
return;
}
- g_return_if_fail (E_IS_CAL_CLIENT (client));
-
cal_client = E_CAL_CLIENT (client);
comp = cal_comp_memo_new_with_defaults (cal_client);
cal_comp_update_time_by_active_window (comp, shell);
@@ -134,7 +136,7 @@ action_memo_new_cb (GtkAction *action,
EShell *shell;
ESource *source;
ESourceRegistry *registry;
- EClientSourceType source_type;
+ ECalClientSourceType source_type;
const gchar *action_name;
/* This callback is used for both memos and shared memos. */
@@ -142,20 +144,20 @@ action_memo_new_cb (GtkAction *action,
shell = e_shell_window_get_shell (shell_window);
registry = e_shell_get_registry (shell);
- source_type = E_CLIENT_SOURCE_TYPE_MEMOS;
+ source_type = E_CAL_CLIENT_SOURCE_TYPE_MEMOS;
source = e_source_registry_ref_default_memo_list (registry);
/* Use a callback function appropriate for the action.
* FIXME Need to obtain a better default time zone. */
action_name = gtk_action_get_name (action);
if (g_strcmp0 (action_name, "memo-shared-new") == 0)
- e_client_utils_open_new (
- source, source_type, FALSE, NULL,
+ e_cal_client_connect (
+ source, source_type, NULL,
memo_shell_backend_memo_shared_new_cb,
g_object_ref (shell));
else
- e_client_utils_open_new (
- source, source_type, FALSE, NULL,
+ e_cal_client_connect (
+ source, source_type, NULL,
memo_shell_backend_memo_new_cb,
g_object_ref (shell));
@@ -226,7 +228,7 @@ memo_shell_backend_handle_uri_cb (EShellBackend *shell_backend,
EShell *shell;
CompEditor *editor;
CompEditorFlags flags = 0;
- ECalClient *client;
+ EClient *client;
ECalComponent *comp;
ESource *source;
ESourceRegistry *registry;
@@ -304,17 +306,17 @@ memo_shell_backend_handle_uri_cb (EShellBackend *shell_backend,
goto exit;
}
- client = e_cal_client_new (source, source_type, &error);
+ client = e_cal_client_connect_sync (source, source_type, NULL, &error);
- if (client != NULL)
- e_client_open_sync (E_CLIENT (client), TRUE, NULL, &error);
+ /* Sanity check. */
+ g_return_val_if_fail (
+ ((client != NULL) && (error == NULL)) ||
+ ((client == NULL) && (error != NULL)), FALSE);
if (error != NULL) {
g_warning (
"%s: Failed to create/open client: %s",
G_STRFUNC, error->message);
- if (client != NULL)
- g_object_unref (client);
g_object_unref (source);
g_error_free (error);
goto exit;
@@ -332,7 +334,8 @@ memo_shell_backend_handle_uri_cb (EShellBackend *shell_backend,
goto present;
e_cal_client_get_object_sync (
- client, comp_uid, comp_rid, &icalcomp, NULL, &error);
+ E_CAL_CLIENT (client), comp_uid,
+ comp_rid, &icalcomp, NULL, &error);
if (error != NULL) {
g_warning (
@@ -353,10 +356,10 @@ memo_shell_backend_handle_uri_cb (EShellBackend *shell_backend,
if (e_cal_component_has_organizer (comp))
flags |= COMP_EDITOR_IS_SHARED;
- if (itip_organizer_is_user (registry, comp, client))
+ if (itip_organizer_is_user (registry, comp, E_CAL_CLIENT (client)))
flags |= COMP_EDITOR_USER_ORG;
- editor = memo_editor_new (client, shell, flags);
+ editor = memo_editor_new (E_CAL_CLIENT (client), shell, flags);
comp_editor_edit_comp (editor, comp);
g_object_unref (comp);
diff --git a/modules/calendar/e-memo-shell-sidebar.c b/modules/calendar/e-memo-shell-sidebar.c
index 5251763944..24e6f841d1 100644
--- a/modules/calendar/e-memo-shell-sidebar.c
+++ b/modules/calendar/e-memo-shell-sidebar.c
@@ -40,6 +40,8 @@
(G_TYPE_INSTANCE_GET_PRIVATE \
((obj), E_TYPE_MEMO_SHELL_SIDEBAR, EMemoShellSidebarPrivate))
+typedef struct _ConnectClosure ConnectClosure;
+
struct _EMemoShellSidebarPrivate {
GtkWidget *selector;
@@ -53,14 +55,23 @@ struct _EMemoShellSidebarPrivate {
* opened. So the user first highlights a source, then
* sometime later we update our default-client property
* which is bound by an EBinding to ECalModel. */
- ECalClient *default_client;
+ EClient *default_client;
- ESource *loading_default_source_instance; /* not-reffed, only for comparison */
+ /* Not referenced, only for pointer comparison. */
+ ESource *connecting_default_source_instance;
- GCancellable *loading_default_client;
+ GCancellable *connecting_default_client;
GCancellable *loading_clients;
};
+struct _ConnectClosure {
+ EMemoShellSidebar *memo_shell_sidebar;
+
+ /* For error messages. */
+ gchar *source_display_name;
+ gchar *parent_display_name;
+};
+
enum {
PROP_0,
PROP_DEFAULT_CLIENT,
@@ -81,9 +92,45 @@ G_DEFINE_DYNAMIC_TYPE (
e_memo_shell_sidebar,
E_TYPE_SHELL_SIDEBAR)
+static ConnectClosure *
+connect_closure_new (EMemoShellSidebar *memo_shell_sidebar,
+ ESource *source)
+{
+ ConnectClosure *closure;
+ ESourceRegistry *registry;
+ ESourceSelector *selector;
+ ESource *parent;
+ const gchar *parent_uid;
+
+ selector = e_memo_shell_sidebar_get_selector (memo_shell_sidebar);
+ registry = e_source_selector_get_registry (selector);
+ parent_uid = e_source_get_parent (source);
+ parent = e_source_registry_ref_source (registry, parent_uid);
+
+ closure = g_slice_new0 (ConnectClosure);
+ closure->memo_shell_sidebar = g_object_ref (memo_shell_sidebar);
+ closure->source_display_name = e_source_dup_display_name (source);
+ closure->parent_display_name = e_source_dup_display_name (parent);
+
+ g_object_unref (parent);
+
+ return closure;
+}
+
+static void
+connect_closure_free (ConnectClosure *closure)
+{
+ g_object_unref (closure->memo_shell_sidebar);
+
+ g_free (closure->source_display_name);
+ g_free (closure->parent_display_name);
+
+ g_slice_free (ConnectClosure, closure);
+}
+
static void
memo_shell_sidebar_emit_client_added (EMemoShellSidebar *memo_shell_sidebar,
- ECalClient *client)
+ EClient *client)
{
guint signal_id = signals[CLIENT_ADDED];
@@ -185,170 +232,170 @@ memo_shell_sidebar_backend_error_cb (EMemoShellSidebar *memo_shell_sidebar,
}
static void
-memo_shell_sidebar_retrieve_capabilies_cb (GObject *source_object,
- GAsyncResult *result,
- gpointer user_data)
+memo_shell_sidebar_handle_connect_error (EMemoShellSidebar *memo_shell_sidebar,
+ const gchar *parent_display_name,
+ const gchar *source_display_name,
+ const GError *error)
{
- ECalClient *client = E_CAL_CLIENT (source_object);
- EMemoShellSidebar *memo_shell_sidebar = user_data;
- gchar *capabilities = NULL;
+ EShellView *shell_view;
+ EShellContent *shell_content;
+ EShellSidebar *shell_sidebar;
+ gboolean cancelled = FALSE;
+ gboolean offline_error;
- g_return_if_fail (client != NULL);
- g_return_if_fail (memo_shell_sidebar != NULL);
+ shell_sidebar = E_SHELL_SIDEBAR (memo_shell_sidebar);
+ shell_view = e_shell_sidebar_get_shell_view (shell_sidebar);
+ shell_content = e_shell_view_get_shell_content (shell_view);
- e_client_retrieve_capabilities_finish (
- E_CLIENT (client), result, &capabilities, NULL);
- g_free (capabilities);
+ cancelled |= g_error_matches (
+ error, G_IO_ERROR, G_IO_ERROR_CANCELLED);
+ cancelled |= g_error_matches (
+ error, E_CLIENT_ERROR, E_CLIENT_ERROR_CANCELLED);
- memo_shell_sidebar_emit_status_message (
- memo_shell_sidebar, _("Loading memos"));
- memo_shell_sidebar_emit_client_added (memo_shell_sidebar, client);
- memo_shell_sidebar_emit_status_message (memo_shell_sidebar, NULL);
+ offline_error = g_error_matches (
+ error, E_CLIENT_ERROR, E_CLIENT_ERROR_REPOSITORY_OFFLINE);
+
+ if (cancelled) {
+ /* do nothing */
+ } else if (offline_error) {
+ e_alert_submit (
+ E_ALERT_SINK (shell_content),
+ "calendar:prompt-no-contents-offline-calendar",
+ parent_display_name,
+ source_display_name,
+ NULL);
+ } else {
+ e_alert_submit (
+ E_ALERT_SINK (shell_content),
+ "calendar:failed-open-calendar",
+ parent_display_name,
+ source_display_name,
+ error->message,
+ NULL);
+ }
}
static void
-memo_shell_sidebar_client_opened_cb (GObject *source_object,
- GAsyncResult *result,
- gpointer user_data)
+memo_shell_sidebar_client_connect_cb (GObject *source_object,
+ GAsyncResult *result,
+ gpointer user_data)
{
- ECalClient *client = E_CAL_CLIENT (source_object);
- EMemoShellSidebar *memo_shell_sidebar = user_data;
- ESource *source, *parent;
- EShellView *shell_view;
+ EClient *client;
+ ConnectClosure *closure = user_data;
+ EMemoShellContent *memo_shell_content;
EShellContent *shell_content;
EShellSidebar *shell_sidebar;
- ESourceRegistry *registry;
+ EShellView *shell_view;
+ ECalModel *model;
+ icaltimezone *timezone;
GError *error = NULL;
- source = e_client_get_source (E_CLIENT (client));
+ client = e_cal_client_connect_finish (result, &error);
- e_client_open_finish (E_CLIENT (client), result, &error);
+ /* Sanity check. */
+ g_return_if_fail (
+ ((client != NULL) && (error == NULL)) ||
+ ((client == NULL) && (error != NULL)));
- if (g_error_matches (error, E_CLIENT_ERROR, E_CLIENT_ERROR_CANCELLED) ||
- g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
- g_clear_error (&error);
- return;
+ if (error != NULL) {
+ memo_shell_sidebar_handle_connect_error (
+ closure->memo_shell_sidebar,
+ closure->parent_display_name,
+ closure->source_display_name,
+ error);
+ g_error_free (error);
+ goto exit;
}
- shell_sidebar = E_SHELL_SIDEBAR (memo_shell_sidebar);
+ /* FIXME Sidebar should not be accessing the EShellContent.
+ * This probably needs to be moved to EMemoShellView. */
+ shell_sidebar = E_SHELL_SIDEBAR (closure->memo_shell_sidebar);
shell_view = e_shell_sidebar_get_shell_view (shell_sidebar);
shell_content = e_shell_view_get_shell_content (shell_view);
- registry = e_shell_get_registry (e_shell_backend_get_shell (e_shell_view_get_shell_backend (shell_view)));
- parent = e_source_registry_ref_source (registry, e_source_get_parent (source));
-
- /* Handle errors. */
- switch ((error && error->domain == E_CLIENT_ERROR) ? error->code : -1) {
- case -1:
- break;
-
- case E_CLIENT_ERROR_REPOSITORY_OFFLINE:
- e_alert_submit (
- E_ALERT_SINK (shell_content),
- "calendar:prompt-no-contents-offline-memos",
- e_source_get_display_name (parent),
- e_source_get_display_name (source), NULL);
- /* fall through */
-
- default:
- if (error->code != E_CLIENT_ERROR_REPOSITORY_OFFLINE) {
- e_alert_submit (
- E_ALERT_SINK (shell_content),
- "calendar:failed-open-memos",
- e_source_get_display_name (parent),
- e_source_get_display_name (source),
- error->message, NULL);
- }
-
- e_memo_shell_sidebar_remove_source (
- memo_shell_sidebar,
- e_client_get_source (E_CLIENT (client)));
- g_clear_error (&error);
- g_object_unref (parent);
- return;
- }
- g_clear_error (&error);
- g_object_unref (parent);
+ memo_shell_content = E_MEMO_SHELL_CONTENT (shell_content);
+ model = e_memo_shell_content_get_memo_model (memo_shell_content);
+ timezone = e_cal_model_get_timezone (model);
- /* to have them ready for later use */
- e_client_retrieve_capabilities (
- E_CLIENT (client), NULL,
- memo_shell_sidebar_retrieve_capabilies_cb,
- memo_shell_sidebar);
+ e_cal_client_set_default_timezone (E_CAL_CLIENT (client), timezone);
+
+ e_memo_shell_sidebar_add_client (closure->memo_shell_sidebar, client);
+
+ g_object_unref (client);
+
+exit:
+ connect_closure_free (closure);
}
static void
-memo_shell_sidebar_default_loaded_cb (GObject *source_object,
- GAsyncResult *result,
- gpointer user_data)
+memo_shell_sidebar_default_connect_cb (GObject *source_object,
+ GAsyncResult *result,
+ gpointer user_data)
{
- ESource *source = E_SOURCE (source_object);
- EShellSidebar *shell_sidebar = user_data;
+ EClient *client;
+ ESource *source;
+ ConnectClosure *closure = user_data;
EMemoShellSidebarPrivate *priv;
EShellContent *shell_content;
+ EShellSidebar *shell_sidebar;
EShellView *shell_view;
EMemoShellContent *memo_shell_content;
ECalModel *model;
- EClient *client = NULL;
+ icaltimezone *timezone;
GError *error = NULL;
- priv = E_MEMO_SHELL_SIDEBAR_GET_PRIVATE (shell_sidebar);
+ priv = E_MEMO_SHELL_SIDEBAR_GET_PRIVATE (closure->memo_shell_sidebar);
- shell_view = e_shell_sidebar_get_shell_view (shell_sidebar);
- shell_content = e_shell_view_get_shell_content (shell_view);
- memo_shell_content = E_MEMO_SHELL_CONTENT (shell_content);
- model = e_memo_shell_content_get_memo_model (memo_shell_content);
+ client = e_cal_client_connect_finish (result, &error);
- e_client_utils_open_new_finish (source, result, &client, &error);
+ /* Sanity check. */
+ g_return_if_fail (
+ ((client != NULL) && (error == NULL)) ||
+ ((client == NULL) && (error != NULL)));
- if (priv->loading_default_client) {
- g_object_unref (priv->loading_default_client);
- priv->loading_default_client = NULL;
+ if (priv->connecting_default_client) {
+ g_object_unref (priv->connecting_default_client);
+ priv->connecting_default_client = NULL;
}
- if (source == priv->loading_default_source_instance)
- priv->loading_default_source_instance = NULL;
-
- /* Ignore cancellations. */
- if (g_error_matches (error, E_CLIENT_ERROR, E_CLIENT_ERROR_CANCELLED) ||
- g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
- g_warn_if_fail (client == NULL);
+ if (error != NULL) {
+ memo_shell_sidebar_handle_connect_error (
+ closure->memo_shell_sidebar,
+ closure->parent_display_name,
+ closure->source_display_name,
+ error);
g_error_free (error);
goto exit;
-
- } else if (error != NULL) {
- ESourceRegistry *registry;
- ESource *parent;
-
- registry = e_shell_get_registry (e_shell_backend_get_shell (e_shell_view_get_shell_backend (shell_view)));
- parent = e_source_registry_ref_source (registry, e_source_get_parent (source));
-
- g_warn_if_fail (client == NULL);
- e_alert_submit (
- E_ALERT_SINK (shell_content),
- "calendar:failed-open-memos",
- e_source_get_display_name (parent),
- e_source_get_display_name (source),
- error->message, NULL);
- g_error_free (error);
- g_object_unref (parent);
- goto exit;
}
- g_return_if_fail (E_IS_CAL_CLIENT (client));
+ source = e_client_get_source (client);
+
+ if (source == priv->connecting_default_source_instance)
+ priv->connecting_default_source_instance = NULL;
if (priv->default_client != NULL)
g_object_unref (priv->default_client);
- priv->default_client = E_CAL_CLIENT (client);
+ priv->default_client = g_object_ref (client);
- e_cal_client_set_default_timezone (
- priv->default_client, e_cal_model_get_timezone (model));
+ /* FIXME Sidebar should not be accessing the EShellContent.
+ * This probably needs to be moved to EMemoShellView. */
+ shell_sidebar = E_SHELL_SIDEBAR (closure->memo_shell_sidebar);
+ shell_view = e_shell_sidebar_get_shell_view (shell_sidebar);
+ shell_content = e_shell_view_get_shell_content (shell_view);
+
+ memo_shell_content = E_MEMO_SHELL_CONTENT (shell_content);
+ model = e_memo_shell_content_get_memo_model (memo_shell_content);
+ timezone = e_cal_model_get_timezone (model);
+
+ e_cal_client_set_default_timezone (E_CAL_CLIENT (client), timezone);
g_object_notify (G_OBJECT (shell_sidebar), "default-client");
- exit:
- g_object_unref (shell_sidebar);
+ g_object_unref (client);
+
+exit:
+ connect_closure_free (closure);
}
static void
@@ -363,7 +410,7 @@ memo_shell_sidebar_set_default (EMemoShellSidebar *memo_shell_sidebar,
priv = memo_shell_sidebar->priv;
/* already loading that source as default source */
- if (source == priv->loading_default_source_instance)
+ if (source == priv->connecting_default_source_instance)
return;
/* FIXME Sidebar should not be accessing the EShellContent.
@@ -371,10 +418,10 @@ memo_shell_sidebar_set_default (EMemoShellSidebar *memo_shell_sidebar,
shell_sidebar = E_SHELL_SIDEBAR (memo_shell_sidebar);
/* Cancel any unfinished previous request. */
- if (priv->loading_default_client != NULL) {
- g_cancellable_cancel (priv->loading_default_client);
- g_object_unref (priv->loading_default_client);
- priv->loading_default_client = NULL;
+ if (priv->connecting_default_client != NULL) {
+ g_cancellable_cancel (priv->connecting_default_client);
+ g_object_unref (priv->connecting_default_client);
+ priv->connecting_default_client = NULL;
}
uid = e_source_get_uid (source);
@@ -391,14 +438,14 @@ memo_shell_sidebar_set_default (EMemoShellSidebar *memo_shell_sidebar,
}
/* it's only for pointer comparison, no need to ref it */
- priv->loading_default_source_instance = source;
- priv->loading_default_client = g_cancellable_new ();
-
- e_client_utils_open_new (
- source, E_CLIENT_SOURCE_TYPE_MEMOS,
- FALSE, priv->loading_default_client,
- memo_shell_sidebar_default_loaded_cb,
- g_object_ref (shell_sidebar));
+ priv->connecting_default_source_instance = source;
+ priv->connecting_default_client = g_cancellable_new ();
+
+ e_cal_client_connect (
+ source, E_CAL_CLIENT_SOURCE_TYPE_MEMOS,
+ priv->connecting_default_client,
+ memo_shell_sidebar_default_connect_cb,
+ connect_closure_new (memo_shell_sidebar, source));
}
static void
@@ -533,10 +580,10 @@ memo_shell_sidebar_dispose (GObject *object)
priv->default_client = NULL;
}
- if (priv->loading_default_client != NULL) {
- g_cancellable_cancel (priv->loading_default_client);
- g_object_unref (priv->loading_default_client);
- priv->loading_default_client = NULL;
+ if (priv->connecting_default_client != NULL) {
+ g_cancellable_cancel (priv->connecting_default_client);
+ g_object_unref (priv->connecting_default_client);
+ priv->connecting_default_client = NULL;
}
if (priv->loading_clients != NULL) {
@@ -842,7 +889,7 @@ e_memo_shell_sidebar_get_default_client (EMemoShellSidebar *memo_shell_sidebar)
g_return_val_if_fail (
E_IS_MEMO_SHELL_SIDEBAR (memo_shell_sidebar), NULL);
- return memo_shell_sidebar->priv->default_client;
+ return (ECalClient *) memo_shell_sidebar->priv->default_client;
}
ESourceSelector *
@@ -855,20 +902,56 @@ e_memo_shell_sidebar_get_selector (EMemoShellSidebar *memo_shell_sidebar)
}
void
+e_memo_shell_sidebar_add_client (EMemoShellSidebar *memo_shell_sidebar,
+ EClient *client)
+{
+ ESource *source;
+ ESourceSelector *selector;
+ GHashTable *client_table;
+ const gchar *message;
+ const gchar *uid;
+
+ g_return_if_fail (E_IS_MEMO_SHELL_SIDEBAR (memo_shell_sidebar));
+ g_return_if_fail (E_IS_CAL_CLIENT (client));
+
+ client_table = memo_shell_sidebar->priv->client_table;
+
+ source = e_client_get_source (client);
+ uid = e_source_get_uid (source);
+
+ if (g_hash_table_contains (client_table, uid))
+ return;
+
+ g_hash_table_insert (
+ client_table, g_strdup (uid), g_object_ref (client));
+
+ g_signal_connect_swapped (
+ client, "backend-died",
+ G_CALLBACK (memo_shell_sidebar_backend_died_cb),
+ memo_shell_sidebar);
+
+ g_signal_connect_swapped (
+ client, "backend-error",
+ G_CALLBACK (memo_shell_sidebar_backend_error_cb),
+ memo_shell_sidebar);
+
+ selector = e_memo_shell_sidebar_get_selector (memo_shell_sidebar);
+ e_source_selector_select_source (selector, source);
+
+ message = _("Loading memo list");
+ memo_shell_sidebar_emit_status_message (memo_shell_sidebar, message);
+ memo_shell_sidebar_emit_client_added (memo_shell_sidebar, client);
+ memo_shell_sidebar_emit_status_message (memo_shell_sidebar, NULL);
+}
+
+void
e_memo_shell_sidebar_add_source (EMemoShellSidebar *memo_shell_sidebar,
ESource *source)
{
- EShellView *shell_view;
- EShellContent *shell_content;
- EShellSidebar *shell_sidebar;
- EMemoShellContent *memo_shell_content;
ECalClientSourceType source_type;
ESourceSelector *selector;
GHashTable *client_table;
- ECalModel *model;
- ECalClient *default_client;
- ECalClient *client;
- icaltimezone *timezone;
+ EClient *default_client;
const gchar *display_name;
const gchar *uid;
gchar *message;
@@ -882,38 +965,22 @@ e_memo_shell_sidebar_add_source (EMemoShellSidebar *memo_shell_sidebar,
selector = e_memo_shell_sidebar_get_selector (memo_shell_sidebar);
uid = e_source_get_uid (source);
- client = g_hash_table_lookup (client_table, uid);
- if (client != NULL)
+ if (g_hash_table_contains (client_table, uid))
return;
if (default_client != NULL) {
ESource *default_source;
- const gchar *default_uid;
- default_source = e_client_get_source (E_CLIENT (default_client));
- default_uid = e_source_get_uid (default_source);
+ default_source = e_client_get_source (default_client);
- if (g_strcmp0 (uid, default_uid) == 0)
- client = g_object_ref (default_client);
+ if (e_source_equal (source, default_source)) {
+ e_memo_shell_sidebar_add_client (
+ memo_shell_sidebar, default_client);
+ return;
+ }
}
- if (client == NULL)
- client = e_cal_client_new (source, source_type, NULL);
-
- g_return_if_fail (client != NULL);
-
- g_signal_connect_swapped (
- client, "backend-died",
- G_CALLBACK (memo_shell_sidebar_backend_died_cb),
- memo_shell_sidebar);
-
- g_signal_connect_swapped (
- client, "backend-error",
- G_CALLBACK (memo_shell_sidebar_backend_error_cb),
- memo_shell_sidebar);
-
- g_hash_table_insert (client_table, g_strdup (uid), client);
e_source_selector_select_source (selector, source);
display_name = e_source_get_display_name (source);
@@ -921,22 +988,11 @@ e_memo_shell_sidebar_add_source (EMemoShellSidebar *memo_shell_sidebar,
memo_shell_sidebar_emit_status_message (memo_shell_sidebar, message);
g_free (message);
- /* FIXME Sidebar should not be accessing the EShellContent.
- * This probably needs to be moved to EMemoShellView. */
- shell_sidebar = E_SHELL_SIDEBAR (memo_shell_sidebar);
- shell_view = e_shell_sidebar_get_shell_view (shell_sidebar);
- shell_content = e_shell_view_get_shell_content (shell_view);
-
- memo_shell_content = E_MEMO_SHELL_CONTENT (shell_content);
- model = e_memo_shell_content_get_memo_model (memo_shell_content);
- timezone = e_cal_model_get_timezone (model);
-
- e_cal_client_set_default_timezone (client, timezone);
-
- e_client_open (
- E_CLIENT (client), FALSE,
+ e_cal_client_connect (
+ source, source_type,
memo_shell_sidebar->priv->loading_clients,
- memo_shell_sidebar_client_opened_cb, memo_shell_sidebar);
+ memo_shell_sidebar_client_connect_cb,
+ connect_closure_new (memo_shell_sidebar, source));
}
void
diff --git a/modules/calendar/e-memo-shell-sidebar.h b/modules/calendar/e-memo-shell-sidebar.h
index 17814ebaea..31fc25c649 100644
--- a/modules/calendar/e-memo-shell-sidebar.h
+++ b/modules/calendar/e-memo-shell-sidebar.h
@@ -94,6 +94,9 @@ ECalClient * e_memo_shell_sidebar_get_default_client
ESourceSelector *
e_memo_shell_sidebar_get_selector
(EMemoShellSidebar *memo_shell_sidebar);
+void e_memo_shell_sidebar_add_client
+ (EMemoShellSidebar *memo_shell_sidebar,
+ EClient *client);
void e_memo_shell_sidebar_add_source
(EMemoShellSidebar *memo_shell_sidebar,
ESource *source);
diff --git a/modules/calendar/e-task-shell-backend.c b/modules/calendar/e-task-shell-backend.c
index 90ffb3cc6e..831e35de18 100644
--- a/modules/calendar/e-task-shell-backend.c
+++ b/modules/calendar/e-task-shell-backend.c
@@ -60,17 +60,21 @@ task_shell_backend_new_task (ESource *source,
EShell *shell,
CompEditorFlags flags)
{
- EClient *client = NULL;
+ EClient *client;
ECalClient *cal_client;
ECalComponent *comp;
CompEditor *editor;
GError *error = NULL;
- e_client_utils_open_new_finish (source, result, &client, &error);
+ client = e_cal_client_connect_finish (result, &error);
+
+ /* Sanity check. */
+ g_return_if_fail (
+ ((client != NULL) && (error == NULL)) ||
+ ((client == NULL) && (error != NULL)));
/* XXX Handle errors better. */
if (error != NULL) {
- g_warn_if_fail (client == NULL);
g_warning (
"%s: Failed to open '%s': %s",
G_STRFUNC, e_source_get_display_name (source),
@@ -79,8 +83,6 @@ task_shell_backend_new_task (ESource *source,
return;
}
- g_return_if_fail (E_IS_CAL_CLIENT (client));
-
cal_client = E_CAL_CLIENT (client);
editor = task_editor_new (cal_client, shell, flags);
comp = cal_comp_task_new_with_defaults (cal_client);
@@ -131,7 +133,7 @@ action_task_new_cb (GtkAction *action,
EShell *shell;
ESource *source;
ESourceRegistry *registry;
- EClientSourceType source_type;
+ ECalClientSourceType source_type;
const gchar *action_name;
/* This callback is used for both tasks and assigned tasks. */
@@ -139,20 +141,20 @@ action_task_new_cb (GtkAction *action,
shell = e_shell_window_get_shell (shell_window);
registry = e_shell_get_registry (shell);
- source_type = E_CLIENT_SOURCE_TYPE_TASKS;
+ source_type = E_CAL_CLIENT_SOURCE_TYPE_TASKS;
source = e_source_registry_ref_default_task_list (registry);
/* Use a callback function appropriate for the action.
* FIXME Need to obtain a better default time zone. */
action_name = gtk_action_get_name (action);
if (strcmp (action_name, "task-assigned-new") == 0)
- e_client_utils_open_new (
- source, source_type, FALSE, NULL,
+ e_cal_client_connect (
+ source, source_type, NULL,
task_shell_backend_task_assigned_new_cb,
g_object_ref (shell));
else
- e_client_utils_open_new (
- source, source_type, FALSE, NULL,
+ e_cal_client_connect (
+ source, source_type, NULL,
task_shell_backend_task_new_cb,
g_object_ref (shell));
@@ -223,7 +225,7 @@ task_shell_backend_handle_uri_cb (EShellBackend *shell_backend,
EShell *shell;
CompEditor *editor;
CompEditorFlags flags = 0;
- ECalClient *client;
+ EClient *client;
ECalComponent *comp;
ESource *source;
ESourceRegistry *registry;
@@ -302,17 +304,17 @@ task_shell_backend_handle_uri_cb (EShellBackend *shell_backend,
goto exit;
}
- client = e_cal_client_new (source, source_type, &error);
+ client = e_cal_client_connect_sync (source, source_type, NULL, &error);
- if (client != NULL)
- e_client_open_sync (E_CLIENT (client), TRUE, NULL, &error);
+ /* Sanity check. */
+ g_return_val_if_fail (
+ ((client != NULL) && (error == NULL)) ||
+ ((client == NULL) && (error != NULL)), FALSE);
if (error != NULL) {
g_warning (
"%s: Failed to create/open client: %s",
G_STRFUNC, error->message);
- if (client != NULL)
- g_object_unref (client);
g_object_unref (source);
g_error_free (error);
goto exit;
@@ -330,7 +332,8 @@ task_shell_backend_handle_uri_cb (EShellBackend *shell_backend,
goto present;
e_cal_client_get_object_sync (
- client, comp_uid, comp_rid, &icalcomp, NULL, &error);
+ E_CAL_CLIENT (client), comp_uid,
+ comp_rid, &icalcomp, NULL, &error);
if (error != NULL) {
g_warning (
@@ -353,13 +356,13 @@ task_shell_backend_handle_uri_cb (EShellBackend *shell_backend,
if (icalprop != NULL)
flags |= COMP_EDITOR_IS_ASSIGNED;
- if (itip_organizer_is_user (registry, comp, client))
+ if (itip_organizer_is_user (registry, comp, E_CAL_CLIENT (client)))
flags |= COMP_EDITOR_USER_ORG;
if (!e_cal_component_has_attendees (comp))
flags |= COMP_EDITOR_USER_ORG;
- editor = task_editor_new (client, shell, flags);
+ editor = task_editor_new (E_CAL_CLIENT (client), shell, flags);
comp_editor_edit_comp (editor, comp);
g_object_unref (comp);
diff --git a/modules/calendar/e-task-shell-sidebar.c b/modules/calendar/e-task-shell-sidebar.c
index 7c7742e295..dc25f3921a 100644
--- a/modules/calendar/e-task-shell-sidebar.c
+++ b/modules/calendar/e-task-shell-sidebar.c
@@ -40,6 +40,8 @@
(G_TYPE_INSTANCE_GET_PRIVATE \
((obj), E_TYPE_TASK_SHELL_SIDEBAR, ETaskShellSidebarPrivate))
+typedef struct _ConnectClosure ConnectClosure;
+
struct _ETaskShellSidebarPrivate {
GtkWidget *selector;
@@ -53,14 +55,23 @@ struct _ETaskShellSidebarPrivate {
* opened. So the user first highlights a source, then
* sometime later we update our default-client property
* which is bound by an EBinding to ECalModel. */
- ECalClient *default_client;
+ EClient *default_client;
- ESource *loading_default_source_instance; /* not-reffed, only for comparison */
+ /* Not referenced, only for pointer comparison. */
+ ESource *connecting_default_source_instance;
- GCancellable *loading_default_client;
+ GCancellable *connecting_default_client;
GCancellable *loading_clients;
};
+struct _ConnectClosure {
+ ETaskShellSidebar *task_shell_sidebar;
+
+ /* For error messages. */
+ gchar *source_display_name;
+ gchar *parent_display_name;
+};
+
enum {
PROP_0,
PROP_DEFAULT_CLIENT,
@@ -81,9 +92,45 @@ G_DEFINE_DYNAMIC_TYPE (
e_task_shell_sidebar,
E_TYPE_SHELL_SIDEBAR)
+static ConnectClosure *
+connect_closure_new (ETaskShellSidebar *task_shell_sidebar,
+ ESource *source)
+{
+ ConnectClosure *closure;
+ ESourceRegistry *registry;
+ ESourceSelector *selector;
+ ESource *parent;
+ const gchar *parent_uid;
+
+ selector = e_task_shell_sidebar_get_selector (task_shell_sidebar);
+ registry = e_source_selector_get_registry (selector);
+ parent_uid = e_source_get_parent (source);
+ parent = e_source_registry_ref_source (registry, parent_uid);
+
+ closure = g_slice_new0 (ConnectClosure);
+ closure->task_shell_sidebar = g_object_ref (task_shell_sidebar);
+ closure->source_display_name = e_source_dup_display_name (source);
+ closure->parent_display_name = e_source_dup_display_name (parent);
+
+ g_object_unref (parent);
+
+ return closure;
+}
+
+static void
+connect_closure_free (ConnectClosure *closure)
+{
+ g_object_unref (closure->task_shell_sidebar);
+
+ g_free (closure->source_display_name);
+ g_free (closure->parent_display_name);
+
+ g_slice_free (ConnectClosure, closure);
+}
+
static void
task_shell_sidebar_emit_client_added (ETaskShellSidebar *task_shell_sidebar,
- ECalClient *client)
+ EClient *client)
{
guint signal_id = signals[CLIENT_ADDED];
@@ -185,170 +232,170 @@ task_shell_sidebar_backend_error_cb (ETaskShellSidebar *task_shell_sidebar,
}
static void
-task_shell_sidebar_retrieve_capabilies_cb (GObject *source_object,
- GAsyncResult *result,
- gpointer user_data)
+task_shell_sidebar_handle_connect_error (ETaskShellSidebar *task_shell_sidebar,
+ const gchar *parent_display_name,
+ const gchar *source_display_name,
+ const GError *error)
{
- ECalClient *client = E_CAL_CLIENT (source_object);
- ETaskShellSidebar *task_shell_sidebar = user_data;
- gchar *capabilities = NULL;
+ EShellView *shell_view;
+ EShellContent *shell_content;
+ EShellSidebar *shell_sidebar;
+ gboolean cancelled = FALSE;
+ gboolean offline_error;
- g_return_if_fail (client != NULL);
- g_return_if_fail (task_shell_sidebar != NULL);
+ shell_sidebar = E_SHELL_SIDEBAR (task_shell_sidebar);
+ shell_view = e_shell_sidebar_get_shell_view (shell_sidebar);
+ shell_content = e_shell_view_get_shell_content (shell_view);
- e_client_retrieve_capabilities_finish (
- E_CLIENT (client), result, &capabilities, NULL);
- g_free (capabilities);
+ cancelled |= g_error_matches (
+ error, G_IO_ERROR, G_IO_ERROR_CANCELLED);
+ cancelled |= g_error_matches (
+ error, E_CLIENT_ERROR, E_CLIENT_ERROR_CANCELLED);
- task_shell_sidebar_emit_status_message (
- task_shell_sidebar, _("Loading tasks"));
- task_shell_sidebar_emit_client_added (task_shell_sidebar, client);
- task_shell_sidebar_emit_status_message (task_shell_sidebar, NULL);
+ offline_error = g_error_matches (
+ error, E_CLIENT_ERROR, E_CLIENT_ERROR_REPOSITORY_OFFLINE);
+
+ if (cancelled) {
+ /* do nothing */
+ } else if (offline_error) {
+ e_alert_submit (
+ E_ALERT_SINK (shell_content),
+ "calendar:prompt-no-contents-offline-calendar",
+ parent_display_name,
+ source_display_name,
+ NULL);
+ } else {
+ e_alert_submit (
+ E_ALERT_SINK (shell_content),
+ "calendar:failed-open-calendar",
+ parent_display_name,
+ source_display_name,
+ error->message,
+ NULL);
+ }
}
static void
-task_shell_sidebar_client_opened_cb (GObject *source_object,
- GAsyncResult *result,
- gpointer user_data)
+task_shell_sidebar_client_connect_cb (GObject *source_object,
+ GAsyncResult *result,
+ gpointer user_data)
{
- ECalClient *client = E_CAL_CLIENT (source_object);
- ETaskShellSidebar *task_shell_sidebar = user_data;
- ESource *source, *parent;
- EShellView *shell_view;
+ EClient *client;
+ ConnectClosure *closure = user_data;
+ ETaskShellContent *task_shell_content;
EShellContent *shell_content;
EShellSidebar *shell_sidebar;
- ESourceRegistry *registry;
+ EShellView *shell_view;
+ ECalModel *model;
+ icaltimezone *timezone;
GError *error = NULL;
- source = e_client_get_source (E_CLIENT (client));
+ client = e_cal_client_connect_finish (result, &error);
- e_client_open_finish (E_CLIENT (client), result, &error);
+ /* Sanity check. */
+ g_return_if_fail (
+ ((client != NULL) && (error == NULL)) ||
+ ((client == NULL) && (error != NULL)));
- if (g_error_matches (error, E_CLIENT_ERROR, E_CLIENT_ERROR_CANCELLED) ||
- g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
- g_clear_error (&error);
- return;
+ if (error != NULL) {
+ task_shell_sidebar_handle_connect_error (
+ closure->task_shell_sidebar,
+ closure->parent_display_name,
+ closure->source_display_name,
+ error);
+ g_error_free (error);
+ goto exit;
}
- shell_sidebar = E_SHELL_SIDEBAR (task_shell_sidebar);
+ /* FIXME Sidebar should not be accessing the EShellContent.
+ * This probably needs to be moved to ETaskShellView. */
+ shell_sidebar = E_SHELL_SIDEBAR (closure->task_shell_sidebar);
shell_view = e_shell_sidebar_get_shell_view (shell_sidebar);
shell_content = e_shell_view_get_shell_content (shell_view);
- registry = e_shell_get_registry (e_shell_backend_get_shell (e_shell_view_get_shell_backend (shell_view)));
- parent = e_source_registry_ref_source (registry, e_source_get_parent (source));
-
- /* Handle errors. */
- switch ((error && error->domain == E_CLIENT_ERROR) ? error->code : -1) {
- case -1:
- break;
-
- case E_CLIENT_ERROR_REPOSITORY_OFFLINE:
- e_alert_submit (
- E_ALERT_SINK (shell_content),
- "calendar:prompt-no-contents-offline-tasks",
- e_source_get_display_name (parent),
- e_source_get_display_name (source), NULL);
- /* fall through */
-
- default:
- if (error->code != E_CLIENT_ERROR_REPOSITORY_OFFLINE) {
- e_alert_submit (
- E_ALERT_SINK (shell_content),
- "calendar:failed-open-tasks",
- e_source_get_display_name (parent),
- e_source_get_display_name (source),
- error->message, NULL);
- }
-
- e_task_shell_sidebar_remove_source (
- task_shell_sidebar,
- e_client_get_source (E_CLIENT (client)));
- g_clear_error (&error);
- g_object_unref (parent);
- return;
- }
- g_clear_error (&error);
- g_object_unref (parent);
+ task_shell_content = E_TASK_SHELL_CONTENT (shell_content);
+ model = e_task_shell_content_get_task_model (task_shell_content);
+ timezone = e_cal_model_get_timezone (model);
- /* to have them ready for later use */
- e_client_retrieve_capabilities (
- E_CLIENT (client), NULL,
- task_shell_sidebar_retrieve_capabilies_cb,
- task_shell_sidebar);
+ e_cal_client_set_default_timezone (E_CAL_CLIENT (client), timezone);
+
+ e_task_shell_sidebar_add_client (closure->task_shell_sidebar, client);
+
+ g_object_unref (client);
+
+exit:
+ connect_closure_free (closure);
}
static void
-task_shell_sidebar_default_loaded_cb (GObject *source_object,
- GAsyncResult *result,
- gpointer user_data)
+task_shell_sidebar_default_connect_cb (GObject *source_object,
+ GAsyncResult *result,
+ gpointer user_data)
{
- ESource *source = E_SOURCE (source_object);
- EShellSidebar *shell_sidebar = user_data;
+ EClient *client;
+ ESource *source;
+ ConnectClosure *closure = user_data;
ETaskShellSidebarPrivate *priv;
EShellContent *shell_content;
+ EShellSidebar *shell_sidebar;
EShellView *shell_view;
ETaskShellContent *task_shell_content;
ECalModel *model;
- EClient *client = NULL;
+ icaltimezone *timezone;
GError *error = NULL;
- priv = E_TASK_SHELL_SIDEBAR_GET_PRIVATE (shell_sidebar);
+ priv = E_TASK_SHELL_SIDEBAR_GET_PRIVATE (closure->task_shell_sidebar);
- shell_view = e_shell_sidebar_get_shell_view (shell_sidebar);
- shell_content = e_shell_view_get_shell_content (shell_view);
- task_shell_content = E_TASK_SHELL_CONTENT (shell_content);
- model = e_task_shell_content_get_task_model (task_shell_content);
+ client = e_cal_client_connect_finish (result, &error);
- e_client_utils_open_new_finish (source, result, &client, &error);
+ /* Sanity check. */
+ g_return_if_fail (
+ ((client != NULL) && (error == NULL)) ||
+ ((client == NULL) && (error != NULL)));
- if (priv->loading_default_client) {
- g_object_unref (priv->loading_default_client);
- priv->loading_default_client = NULL;
+ if (priv->connecting_default_client) {
+ g_object_unref (priv->connecting_default_client);
+ priv->connecting_default_client = NULL;
}
- if (source == priv->loading_default_source_instance)
- priv->loading_default_source_instance = NULL;
-
- /* Ignore cancellations. */
- if (g_error_matches (error, E_CLIENT_ERROR, E_CLIENT_ERROR_CANCELLED) ||
- g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
- g_warn_if_fail (client == NULL);
+ if (error != NULL) {
+ task_shell_sidebar_handle_connect_error (
+ closure->task_shell_sidebar,
+ closure->parent_display_name,
+ closure->source_display_name,
+ error);
g_error_free (error);
goto exit;
-
- } else if (error != NULL) {
- ESourceRegistry *registry;
- ESource *parent;
-
- registry = e_shell_get_registry (e_shell_backend_get_shell (e_shell_view_get_shell_backend (shell_view)));
- parent = e_source_registry_ref_source (registry, e_source_get_parent (source));
-
- g_warn_if_fail (client == NULL);
- e_alert_submit (
- E_ALERT_SINK (shell_content),
- "calendar:failed-open-tasks",
- e_source_get_display_name (parent),
- e_source_get_display_name (source),
- error->message, NULL);
- g_error_free (error);
- g_object_unref (parent);
- goto exit;
}
- g_return_if_fail (E_IS_CAL_CLIENT (client));
+ source = e_client_get_source (client);
+
+ if (source == priv->connecting_default_source_instance)
+ priv->connecting_default_source_instance = NULL;
if (priv->default_client != NULL)
g_object_unref (priv->default_client);
- priv->default_client = E_CAL_CLIENT (client);
+ priv->default_client = g_object_ref (client);
- e_cal_client_set_default_timezone (
- priv->default_client, e_cal_model_get_timezone (model));
+ /* FIXME Sidebar should not be accessing the EShellContent.
+ * This probably needs to be moved to ETaskShellView. */
+ shell_sidebar = E_SHELL_SIDEBAR (closure->task_shell_sidebar);
+ shell_view = e_shell_sidebar_get_shell_view (shell_sidebar);
+ shell_content = e_shell_view_get_shell_content (shell_view);
+
+ task_shell_content = E_TASK_SHELL_CONTENT (shell_content);
+ model = e_task_shell_content_get_task_model (task_shell_content);
+ timezone = e_cal_model_get_timezone (model);
+
+ e_cal_client_set_default_timezone (E_CAL_CLIENT (client), timezone);
g_object_notify (G_OBJECT (shell_sidebar), "default-client");
- exit:
- g_object_unref (shell_sidebar);
+ g_object_unref (client);
+
+exit:
+ connect_closure_free (closure);
}
static void
@@ -363,7 +410,7 @@ task_shell_sidebar_set_default (ETaskShellSidebar *task_shell_sidebar,
priv = task_shell_sidebar->priv;
/* already loading that source as default source */
- if (source == priv->loading_default_source_instance)
+ if (source == priv->connecting_default_source_instance)
return;
/* FIXME Sidebar should not be accessing the EShellContent.
@@ -371,10 +418,10 @@ task_shell_sidebar_set_default (ETaskShellSidebar *task_shell_sidebar,
shell_sidebar = E_SHELL_SIDEBAR (task_shell_sidebar);
/* Cancel any unfinished previous request. */
- if (priv->loading_default_client != NULL) {
- g_cancellable_cancel (priv->loading_default_client);
- g_object_unref (priv->loading_default_client);
- priv->loading_default_client = NULL;
+ if (priv->connecting_default_client != NULL) {
+ g_cancellable_cancel (priv->connecting_default_client);
+ g_object_unref (priv->connecting_default_client);
+ priv->connecting_default_client = NULL;
}
uid = e_source_get_uid (source);
@@ -391,14 +438,14 @@ task_shell_sidebar_set_default (ETaskShellSidebar *task_shell_sidebar,
}
/* it's only for pointer comparison, no need to ref it */
- priv->loading_default_source_instance = source;
- priv->loading_default_client = g_cancellable_new ();
-
- e_client_utils_open_new (
- source, E_CLIENT_SOURCE_TYPE_TASKS,
- FALSE, priv->loading_default_client,
- task_shell_sidebar_default_loaded_cb,
- g_object_ref (shell_sidebar));
+ priv->connecting_default_source_instance = source;
+ priv->connecting_default_client = g_cancellable_new ();
+
+ e_cal_client_connect (
+ source, E_CAL_CLIENT_SOURCE_TYPE_TASKS,
+ priv->connecting_default_client,
+ task_shell_sidebar_default_connect_cb,
+ connect_closure_new (task_shell_sidebar, source));
}
static void
@@ -533,10 +580,10 @@ task_shell_sidebar_dispose (GObject *object)
priv->default_client = NULL;
}
- if (priv->loading_default_client != NULL) {
- g_cancellable_cancel (priv->loading_default_client);
- g_object_unref (priv->loading_default_client);
- priv->loading_default_client = NULL;
+ if (priv->connecting_default_client != NULL) {
+ g_cancellable_cancel (priv->connecting_default_client);
+ g_object_unref (priv->connecting_default_client);
+ priv->connecting_default_client = NULL;
}
if (priv->loading_clients != NULL) {
@@ -842,7 +889,7 @@ e_task_shell_sidebar_get_default_client (ETaskShellSidebar *task_shell_sidebar)
g_return_val_if_fail (
E_IS_TASK_SHELL_SIDEBAR (task_shell_sidebar), NULL);
- return task_shell_sidebar->priv->default_client;
+ return (ECalClient *) task_shell_sidebar->priv->default_client;
}
ESourceSelector *
@@ -855,20 +902,56 @@ e_task_shell_sidebar_get_selector (ETaskShellSidebar *task_shell_sidebar)
}
void
+e_task_shell_sidebar_add_client (ETaskShellSidebar *task_shell_sidebar,
+ EClient *client)
+{
+ ESource *source;
+ ESourceSelector *selector;
+ GHashTable *client_table;
+ const gchar *message;
+ const gchar *uid;
+
+ g_return_if_fail (E_IS_TASK_SHELL_SIDEBAR (task_shell_sidebar));
+ g_return_if_fail (E_IS_CAL_CLIENT (client));
+
+ client_table = task_shell_sidebar->priv->client_table;
+
+ source = e_client_get_source (client);
+ uid = e_source_get_uid (source);
+
+ if (g_hash_table_contains (client_table, uid))
+ return;
+
+ g_hash_table_insert (
+ client_table, g_strdup (uid), g_object_ref (client));
+
+ g_signal_connect_swapped (
+ client, "backend-died",
+ G_CALLBACK (task_shell_sidebar_backend_died_cb),
+ task_shell_sidebar);
+
+ g_signal_connect_swapped (
+ client, "backend-error",
+ G_CALLBACK (task_shell_sidebar_backend_error_cb),
+ task_shell_sidebar);
+
+ selector = e_task_shell_sidebar_get_selector (task_shell_sidebar);
+ e_source_selector_select_source (selector, source);
+
+ message = _("Loading task list");
+ task_shell_sidebar_emit_status_message (task_shell_sidebar, message);
+ task_shell_sidebar_emit_client_added (task_shell_sidebar, client);
+ task_shell_sidebar_emit_status_message (task_shell_sidebar, NULL);
+}
+
+void
e_task_shell_sidebar_add_source (ETaskShellSidebar *task_shell_sidebar,
ESource *source)
{
- EShellView *shell_view;
- EShellContent *shell_content;
- EShellSidebar *shell_sidebar;
- ETaskShellContent *task_shell_content;
ECalClientSourceType source_type;
ESourceSelector *selector;
GHashTable *client_table;
- ECalModel *model;
- ECalClient *default_client;
- ECalClient *client;
- icaltimezone *timezone;
+ EClient *default_client;
const gchar *display_name;
const gchar *uid;
gchar *message;
@@ -882,38 +965,22 @@ e_task_shell_sidebar_add_source (ETaskShellSidebar *task_shell_sidebar,
selector = e_task_shell_sidebar_get_selector (task_shell_sidebar);
uid = e_source_get_uid (source);
- client = g_hash_table_lookup (client_table, uid);
- if (client != NULL)
+ if (g_hash_table_contains (client_table, uid))
return;
if (default_client != NULL) {
ESource *default_source;
- const gchar *default_uid;
- default_source = e_client_get_source (E_CLIENT (default_client));
- default_uid = e_source_get_uid (default_source);
+ default_source = e_client_get_source (default_client);
- if (g_strcmp0 (uid, default_uid) == 0)
- client = g_object_ref (default_client);
+ if (e_source_equal (source, default_source)) {
+ e_task_shell_sidebar_add_client (
+ task_shell_sidebar, default_client);
+ return;
+ }
}
- if (client == NULL)
- client = e_cal_client_new (source, source_type, NULL);
-
- g_return_if_fail (client != NULL);
-
- g_signal_connect_swapped (
- client, "backend-died",
- G_CALLBACK (task_shell_sidebar_backend_died_cb),
- task_shell_sidebar);
-
- g_signal_connect_swapped (
- client, "backend-error",
- G_CALLBACK (task_shell_sidebar_backend_error_cb),
- task_shell_sidebar);
-
- g_hash_table_insert (client_table, g_strdup (uid), client);
e_source_selector_select_source (selector, source);
display_name = e_source_get_display_name (source);
@@ -921,22 +988,11 @@ e_task_shell_sidebar_add_source (ETaskShellSidebar *task_shell_sidebar,
task_shell_sidebar_emit_status_message (task_shell_sidebar, message);
g_free (message);
- /* FIXME Sidebar should not be accessing the EShellContent.
- * This probably needs to be moved to ETaskShellView. */
- shell_sidebar = E_SHELL_SIDEBAR (task_shell_sidebar);
- shell_view = e_shell_sidebar_get_shell_view (shell_sidebar);
- shell_content = e_shell_view_get_shell_content (shell_view);
-
- task_shell_content = E_TASK_SHELL_CONTENT (shell_content);
- model = e_task_shell_content_get_task_model (task_shell_content);
- timezone = e_cal_model_get_timezone (model);
-
- e_cal_client_set_default_timezone (client, timezone);
-
- e_client_open (
- E_CLIENT (client), FALSE,
+ e_cal_client_connect (
+ source, source_type,
task_shell_sidebar->priv->loading_clients,
- task_shell_sidebar_client_opened_cb, task_shell_sidebar);
+ task_shell_sidebar_client_connect_cb,
+ connect_closure_new (task_shell_sidebar, source));
}
void
diff --git a/modules/calendar/e-task-shell-sidebar.h b/modules/calendar/e-task-shell-sidebar.h
index d9a143e278..736b273486 100644
--- a/modules/calendar/e-task-shell-sidebar.h
+++ b/modules/calendar/e-task-shell-sidebar.h
@@ -94,6 +94,9 @@ ECalClient * e_task_shell_sidebar_get_default_client
ESourceSelector *
e_task_shell_sidebar_get_selector
(ETaskShellSidebar *task_shell_sidebar);
+void e_task_shell_sidebar_add_client
+ (ETaskShellSidebar *task_shell_sidebar,
+ EClient *client);
void e_task_shell_sidebar_add_source
(ETaskShellSidebar *task_shell_sidebar,
ESource *source);