aboutsummaryrefslogtreecommitdiffstats
path: root/modules/calendar/e-cal-shell-sidebar.c
diff options
context:
space:
mode:
authorMilan Crha <mcrha@redhat.com>2011-06-14 14:54:20 +0800
committerRodrigo Moya <rodrigo@gnome-db.org>2011-06-30 00:42:27 +0800
commit84339b3be5a771406fcd5898bbd21dc1c5b98c82 (patch)
tree15a9cfd61451b56d6b35541b1b1e966a34b17faf /modules/calendar/e-cal-shell-sidebar.c
parentfa4289a2f3c26112c907f283a1fd8ab3fb4f26d6 (diff)
downloadgsoc2013-evolution-84339b3be5a771406fcd5898bbd21dc1c5b98c82.tar
gsoc2013-evolution-84339b3be5a771406fcd5898bbd21dc1c5b98c82.tar.gz
gsoc2013-evolution-84339b3be5a771406fcd5898bbd21dc1c5b98c82.tar.bz2
gsoc2013-evolution-84339b3be5a771406fcd5898bbd21dc1c5b98c82.tar.lz
gsoc2013-evolution-84339b3be5a771406fcd5898bbd21dc1c5b98c82.tar.xz
gsoc2013-evolution-84339b3be5a771406fcd5898bbd21dc1c5b98c82.tar.zst
gsoc2013-evolution-84339b3be5a771406fcd5898bbd21dc1c5b98c82.zip
Do not use deprecated EBook/ECal API
Diffstat (limited to 'modules/calendar/e-cal-shell-sidebar.c')
-rw-r--r--modules/calendar/e-cal-shell-sidebar.c159
1 files changed, 76 insertions, 83 deletions
diff --git a/modules/calendar/e-cal-shell-sidebar.c b/modules/calendar/e-cal-shell-sidebar.c
index d49b143eef..8e3010ddb7 100644
--- a/modules/calendar/e-cal-shell-sidebar.c
+++ b/modules/calendar/e-cal-shell-sidebar.c
@@ -27,12 +27,12 @@
#include <string.h>
#include <glib/gi18n.h>
+#include <libedataserverui/e-client-utils.h>
#include "e-util/e-alert-dialog.h"
#include "e-util/gconf-bridge.h"
#include "widgets/misc/e-paned.h"
-#include "calendar/common/authentication.h"
#include "calendar/gui/e-calendar-selector.h"
#include "calendar/gui/misc.h"
#include "calendar/gui/dialogs/calendar-setup.h"
@@ -56,7 +56,7 @@ 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. */
- ECal *default_client;
+ ECalClient *default_client;
GCancellable *loading_default_client;
};
@@ -81,7 +81,7 @@ static GType cal_shell_sidebar_type;
static void
cal_shell_sidebar_emit_client_added (ECalShellSidebar *cal_shell_sidebar,
- ECal *client)
+ ECalClient *client)
{
guint signal_id = signals[CLIENT_ADDED];
@@ -90,7 +90,7 @@ cal_shell_sidebar_emit_client_added (ECalShellSidebar *cal_shell_sidebar,
static void
cal_shell_sidebar_emit_client_removed (ECalShellSidebar *cal_shell_sidebar,
- ECal *client)
+ ECalClient *client)
{
guint signal_id = signals[CLIENT_REMOVED];
@@ -108,7 +108,7 @@ cal_shell_sidebar_emit_status_message (ECalShellSidebar *cal_shell_sidebar,
static void
cal_shell_sidebar_backend_died_cb (ECalShellSidebar *cal_shell_sidebar,
- ECal *client)
+ ECalClient *client)
{
EShellView *shell_view;
EShellContent *shell_content;
@@ -123,7 +123,7 @@ cal_shell_sidebar_backend_died_cb (ECalShellSidebar *cal_shell_sidebar,
shell_view = e_shell_sidebar_get_shell_view (shell_sidebar);
shell_content = e_shell_view_get_shell_content (shell_view);
- source = e_cal_get_source (client);
+ source = e_client_get_source (E_CLIENT (client));
uid = e_source_peek_uid (source);
g_object_ref (source);
@@ -141,7 +141,7 @@ cal_shell_sidebar_backend_died_cb (ECalShellSidebar *cal_shell_sidebar,
static void
cal_shell_sidebar_backend_error_cb (ECalShellSidebar *cal_shell_sidebar,
const gchar *message,
- ECal *client)
+ ECalClient *client)
{
EShellView *shell_view;
EShellContent *shell_content;
@@ -153,7 +153,7 @@ cal_shell_sidebar_backend_error_cb (ECalShellSidebar *cal_shell_sidebar,
shell_view = e_shell_sidebar_get_shell_view (shell_sidebar);
shell_content = e_shell_view_get_shell_content (shell_view);
- source = e_cal_get_source (client);
+ source = e_client_get_source (E_CLIENT (client));
source_group = e_source_peek_group (source);
e_alert_submit (
@@ -164,38 +164,43 @@ cal_shell_sidebar_backend_error_cb (ECalShellSidebar *cal_shell_sidebar,
}
static void
-cal_shell_sidebar_client_opened_cb (ECalShellSidebar *cal_shell_sidebar,
- const GError *error,
- ECal *client)
+cal_shell_sidebar_client_opened_cb (GObject *source_object, GAsyncResult *result, gpointer user_data)
{
+ ECalClient *client = E_CAL_CLIENT (source_object);
+ ECalShellSidebar *cal_shell_sidebar = user_data;
EShellView *shell_view;
EShellContent *shell_content;
EShellSidebar *shell_sidebar;
const gchar *message;
+ GError *error = 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);
- if (g_error_matches (error, E_CALENDAR_ERROR,
- E_CALENDAR_STATUS_AUTHENTICATION_FAILED) ||
- g_error_matches (error, E_CALENDAR_ERROR,
- E_CALENDAR_STATUS_AUTHENTICATION_REQUIRED))
- e_auth_cal_forget_password (client);
+ e_client_open_finish (E_CLIENT (client), result, &error);
+
+ if (g_error_matches (error, E_CLIENT_ERROR, E_CLIENT_ERROR_AUTHENTICATION_FAILED) ||
+ g_error_matches (error, E_CLIENT_ERROR, E_CLIENT_ERROR_AUTHENTICATION_REQUIRED))
+ e_client_utils_forget_password (E_CLIENT (client));
+
+ if (g_error_matches (error, E_CLIENT_ERROR, E_CLIENT_ERROR_AUTHENTICATION_FAILED)) {
+ e_client_open (E_CLIENT (client), FALSE, NULL, cal_shell_sidebar_client_opened_cb, user_data);
+ g_clear_error (&error);
+ return;
+ }
/* Handle errors. */
- switch (error ? error->code : E_CALENDAR_STATUS_OK) {
- case E_CALENDAR_STATUS_OK:
+ switch ((error && error->domain == E_CLIENT_ERROR) ? error->code : -1) {
+ case -1:
break;
- case E_CALENDAR_STATUS_AUTHENTICATION_FAILED:
- e_cal_open_async (client, FALSE);
- return;
-
- case E_CALENDAR_STATUS_BUSY:
+ case E_CLIENT_ERROR_BUSY:
+ g_debug ("%s: Cannot open '%s', it's busy (%s)", G_STRFUNC, e_source_peek_name (e_client_get_source (E_CLIENT (client))), error->message);
+ g_clear_error (&error);
return;
- case E_CALENDAR_STATUS_REPOSITORY_OFFLINE:
+ case E_CLIENT_ERROR_REPOSITORY_OFFLINE:
e_alert_submit (
E_ALERT_SINK (shell_content),
"calendar:prompt-no-contents-offline-calendar",
@@ -203,7 +208,7 @@ cal_shell_sidebar_client_opened_cb (ECalShellSidebar *cal_shell_sidebar,
/* fall through */
default:
- if (error->code != E_CALENDAR_STATUS_REPOSITORY_OFFLINE) {
+ if (error->code != E_CLIENT_ERROR_REPOSITORY_OFFLINE) {
e_alert_submit (
E_ALERT_SINK (shell_content),
"calendar:failed-open-calendar",
@@ -212,15 +217,12 @@ cal_shell_sidebar_client_opened_cb (ECalShellSidebar *cal_shell_sidebar,
e_cal_shell_sidebar_remove_source (
cal_shell_sidebar,
- e_cal_get_source (client));
+ e_client_get_source (E_CLIENT (client)));
+ g_clear_error (&error);
return;
}
- g_assert (error == NULL);
-
- g_signal_handlers_disconnect_matched (
- client, G_SIGNAL_MATCH_FUNC, 0, 0, NULL,
- cal_shell_sidebar_client_opened_cb, NULL);
+ g_clear_error (&error);
message = _("Loading calendars");
cal_shell_sidebar_emit_status_message (cal_shell_sidebar, message);
@@ -229,27 +231,31 @@ cal_shell_sidebar_client_opened_cb (ECalShellSidebar *cal_shell_sidebar,
}
static void
-cal_shell_sidebar_default_loaded_cb (ESource *source,
- GAsyncResult *result,
- EShellSidebar *shell_sidebar)
+cal_shell_sidebar_default_loaded_cb (GObject *source_object, GAsyncResult *result, gpointer user_data)
{
+ EShellSidebar *shell_sidebar = user_data;
ECalShellSidebarPrivate *priv;
EShellContent *shell_content;
EShellView *shell_view;
- ECal *client;
+ ECalShellContent *cal_shell_content;
+ ECalModel *model;
+ EClient *client = NULL;
GError *error = NULL;
priv = E_CAL_SHELL_SIDEBAR (shell_sidebar)->priv;
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_load_cal_source_finish (source, result, &error);
+ if (!e_client_utils_open_new_finish (E_SOURCE (source_object), result, &client, &error))
+ client = NULL;
- if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
+ if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED) ||
+ g_error_matches (error, E_CLIENT_ERROR, E_CLIENT_ERROR_CANCELLED)) {
g_error_free (error);
goto exit;
-
} else if (error != NULL) {
e_alert_submit (
E_ALERT_SINK (shell_content),
@@ -259,16 +265,18 @@ cal_shell_sidebar_default_loaded_cb (ESource *source,
goto exit;
}
- g_return_if_fail (E_IS_CAL (client));
+ g_return_if_fail (E_IS_CAL_CLIENT (client));
if (priv->default_client != NULL)
g_object_unref (priv->default_client);
- priv->default_client = client;
+ priv->default_client = E_CAL_CLIENT (client);
+
+ e_cal_client_set_default_timezone (priv->default_client, e_cal_model_get_timezone (model));
g_object_notify (G_OBJECT (shell_sidebar), "default-client");
-exit:
+ exit:
g_object_unref (shell_sidebar);
}
@@ -279,29 +287,18 @@ cal_shell_sidebar_set_default (ECalShellSidebar *cal_shell_sidebar,
ECalShellSidebarPrivate *priv;
EShellView *shell_view;
EShellWindow *shell_window;
- EShellContent *shell_content;
EShellSidebar *shell_sidebar;
- ECalShellContent *cal_shell_content;
- ECalSourceType source_type;
- ECalModel *model;
- ECal *client;
- icaltimezone *timezone;
+ ECalClient *client;
const gchar *uid;
priv = cal_shell_sidebar->priv;
- source_type = E_CAL_SOURCE_TYPE_EVENT;
/* 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);
shell_window = e_shell_view_get_shell_window (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);
-
/* Cancel any unfinished previous request. */
if (priv->loading_default_client != NULL) {
g_cancellable_cancel (priv->loading_default_client);
@@ -324,11 +321,9 @@ cal_shell_sidebar_set_default (ECalShellSidebar *cal_shell_sidebar,
priv->loading_default_client = g_cancellable_new ();
- e_load_cal_source_async (
- source, source_type, timezone,
- GTK_WINDOW (shell_window), priv->loading_default_client,
- (GAsyncReadyCallback) cal_shell_sidebar_default_loaded_cb,
- g_object_ref (shell_sidebar));
+ e_client_utils_open_new (source, E_CLIENT_SOURCE_TYPE_EVENTS, FALSE, priv->loading_default_client,
+ e_client_utils_authenticate_handler, GTK_WINDOW (shell_window),
+ cal_shell_sidebar_default_loaded_cb, g_object_ref (shell_sidebar));
}
static void
@@ -702,7 +697,7 @@ cal_shell_sidebar_check_state (EShellSidebar *shell_sidebar)
source = e_source_selector_get_primary_selection (selector);
if (source != NULL) {
- ECal *client;
+ ECalClient *client;
const gchar *uri;
const gchar *delete;
@@ -717,7 +712,7 @@ cal_shell_sidebar_check_state (EShellSidebar *shell_sidebar)
cal_shell_sidebar->priv->client_table,
e_source_peek_uid (source));
refresh_supported =
- client && e_cal_get_refresh_supported (client);
+ client && e_client_check_refresh_supported (E_CLIENT (client));
}
if (source != NULL)
@@ -734,7 +729,7 @@ cal_shell_sidebar_check_state (EShellSidebar *shell_sidebar)
static void
cal_shell_sidebar_client_removed (ECalShellSidebar *cal_shell_sidebar,
- ECal *client)
+ ECalClient *client)
{
ESourceSelector *selector;
GHashTable *client_table;
@@ -748,7 +743,7 @@ cal_shell_sidebar_client_removed (ECalShellSidebar *cal_shell_sidebar,
client, G_SIGNAL_MATCH_DATA, 0, 0,
NULL, NULL, cal_shell_sidebar);
- source = e_cal_get_source (client);
+ source = e_client_get_source (E_CLIENT (client));
uid = e_source_peek_uid (source);
g_return_if_fail (uid != NULL);
@@ -793,9 +788,9 @@ cal_shell_sidebar_class_init (ECalShellSidebarClass *class)
PROP_DEFAULT_CLIENT,
g_param_spec_object (
"default-client",
- "Default Calendar Client",
+ "Default Calendar ECalClient",
"Default client for calendar operations",
- E_TYPE_CAL,
+ E_TYPE_CAL_CLIENT,
G_PARAM_READABLE));
g_object_class_install_property (
@@ -816,7 +811,7 @@ cal_shell_sidebar_class_init (ECalShellSidebarClass *class)
NULL, NULL,
g_cclosure_marshal_VOID__OBJECT,
G_TYPE_NONE, 1,
- E_TYPE_CAL);
+ E_TYPE_CAL_CLIENT);
signals[CLIENT_REMOVED] = g_signal_new (
"client-removed",
@@ -826,7 +821,7 @@ cal_shell_sidebar_class_init (ECalShellSidebarClass *class)
NULL, NULL,
g_cclosure_marshal_VOID__OBJECT,
G_TYPE_NONE, 1,
- E_TYPE_CAL);
+ E_TYPE_CAL_CLIENT);
signals[STATUS_MESSAGE] = g_signal_new (
"status-message",
@@ -917,7 +912,7 @@ e_cal_shell_sidebar_get_date_navigator (ECalShellSidebar *cal_shell_sidebar)
return E_CALENDAR (cal_shell_sidebar->priv->date_navigator);
}
-ECal *
+ECalClient *
e_cal_shell_sidebar_get_default_client (ECalShellSidebar *cal_shell_sidebar)
{
g_return_val_if_fail (
@@ -943,12 +938,12 @@ e_cal_shell_sidebar_add_source (ECalShellSidebar *cal_shell_sidebar,
EShellContent *shell_content;
EShellSidebar *shell_sidebar;
ECalShellContent *cal_shell_content;
- ECalSourceType source_type;
+ ECalClientSourceType source_type;
ESourceSelector *selector;
GHashTable *client_table;
ECalModel *model;
- ECal *default_client;
- ECal *client;
+ ECalClient *default_client;
+ ECalClient *client;
icaltimezone *timezone;
const gchar *uid;
const gchar *uri;
@@ -957,7 +952,7 @@ e_cal_shell_sidebar_add_source (ECalShellSidebar *cal_shell_sidebar,
g_return_if_fail (E_IS_CAL_SHELL_SIDEBAR (cal_shell_sidebar));
g_return_if_fail (E_IS_SOURCE (source));
- source_type = E_CAL_SOURCE_TYPE_EVENT;
+ source_type = E_CAL_CLIENT_SOURCE_TYPE_EVENTS;
client_table = cal_shell_sidebar->priv->client_table;
default_client = cal_shell_sidebar->priv->default_client;
selector = e_cal_shell_sidebar_get_selector (cal_shell_sidebar);
@@ -972,15 +967,18 @@ e_cal_shell_sidebar_add_source (ECalShellSidebar *cal_shell_sidebar,
ESource *default_source;
const gchar *default_uid;
- default_source = e_cal_get_source (default_client);
+ default_source = e_client_get_source (E_CLIENT (default_client));
default_uid = e_source_peek_uid (default_source);
if (g_strcmp0 (uid, default_uid) == 0)
client = g_object_ref (default_client);
}
- if (client == NULL)
- client = e_auth_new_cal_from_source (source, source_type);
+ if (client == NULL) {
+ client = e_cal_client_new (source, source_type, NULL);
+ if (client)
+ g_signal_connect (client, "authenticate", G_CALLBACK (e_client_utils_authenticate_handler), NULL);
+ }
g_return_if_fail (client != NULL);
@@ -997,17 +995,12 @@ e_cal_shell_sidebar_add_source (ECalShellSidebar *cal_shell_sidebar,
g_hash_table_insert (client_table, g_strdup (uid), client);
e_source_selector_select_source (selector, source);
- uri = e_cal_get_uri (client);
+ uri = e_client_get_uri (E_CLIENT (client));
/* Translators: The string field is a URI. */
message = g_strdup_printf (_("Opening calendar at %s"), uri);
cal_shell_sidebar_emit_status_message (cal_shell_sidebar, message);
g_free (message);
- g_signal_connect_swapped (
- client, "cal-opened-ex",
- G_CALLBACK (cal_shell_sidebar_client_opened_cb),
- cal_shell_sidebar);
-
/* FIXME Sidebar should not be accessing the EShellContent.
* This probably needs to be moved to ECalShellView. */
shell_sidebar = E_SHELL_SIDEBAR (cal_shell_sidebar);
@@ -1018,8 +1011,8 @@ e_cal_shell_sidebar_add_source (ECalShellSidebar *cal_shell_sidebar,
model = e_cal_shell_content_get_model (cal_shell_content);
timezone = e_cal_model_get_timezone (model);
- e_cal_set_default_timezone (client, timezone, NULL);
- e_cal_open_async (client, FALSE);
+ e_cal_client_set_default_timezone (client, timezone);
+ e_client_open (E_CLIENT (client), FALSE, NULL, cal_shell_sidebar_client_opened_cb, cal_shell_sidebar);
}
void
@@ -1027,7 +1020,7 @@ e_cal_shell_sidebar_remove_source (ECalShellSidebar *cal_shell_sidebar,
ESource *source)
{
GHashTable *client_table;
- ECal *client;
+ ECalClient *client;
const gchar *uid;
g_return_if_fail (E_IS_CAL_SHELL_SIDEBAR (cal_shell_sidebar));