From 38790d8478e906a5c59d0c4a5216f297f305bfeb Mon Sep 17 00:00:00 2001 From: Milan Crha Date: Tue, 14 Jun 2011 08:54:20 +0200 Subject: Do not use deprecated EBook/ECal API --- calendar/gui/e-memo-list-selector.c | 189 ++++++++++++++++++++++++------------ 1 file changed, 125 insertions(+), 64 deletions(-) (limited to 'calendar/gui/e-memo-list-selector.c') diff --git a/calendar/gui/e-memo-list-selector.c b/calendar/gui/e-memo-list-selector.c index bb41412417..abc4bf9bf3 100644 --- a/calendar/gui/e-memo-list-selector.c +++ b/calendar/gui/e-memo-list-selector.c @@ -25,9 +25,9 @@ #include "e-memo-list-selector.h" #include -#include +#include +#include #include "e-util/e-selection.h" -#include "calendar/common/authentication.h" #include "calendar/gui/comp-util.h" struct _EMemoListSelectorPrivate { @@ -37,23 +37,31 @@ struct _EMemoListSelectorPrivate { static gpointer parent_class; static gboolean -memo_list_selector_update_single_object (ECal *client, +memo_list_selector_update_single_object (ECalClient *client, icalcomponent *icalcomp) { - gchar *uid; + gchar *uid = NULL; icalcomponent *tmp_icalcomp; uid = (gchar *) icalcomponent_get_uid (icalcomp); - if (e_cal_get_object (client, uid, NULL, &tmp_icalcomp, NULL)) - return e_cal_modify_object ( - client, icalcomp, CALOBJ_MOD_ALL, NULL); + if (e_cal_client_get_object_sync (client, uid, NULL, &tmp_icalcomp, NULL, NULL)) + return e_cal_client_modify_object_sync ( + client, icalcomp, CALOBJ_MOD_ALL, NULL, NULL); - return e_cal_create_object (client, icalcomp, &uid, NULL); + if (!e_cal_client_create_object_sync (client, icalcomp, &uid, NULL, NULL)) + return FALSE; + + if (uid) + icalcomponent_set_uid (icalcomp, uid); + + g_free (uid); + + return TRUE; } static gboolean -memo_list_selector_update_objects (ECal *client, +memo_list_selector_update_objects (ECalClient *client, icalcomponent *icalcomp) { icalcomponent *subcomp; @@ -74,14 +82,19 @@ memo_list_selector_update_objects (ECal *client, kind = icalcomponent_isa (subcomp); if (kind == ICAL_VTIMEZONE_COMPONENT) { icaltimezone *zone; + GError *error = NULL; zone = icaltimezone_new (); icaltimezone_set_component (zone, subcomp); - success = e_cal_add_timezone (client, zone, NULL); + success = e_cal_client_add_timezone_sync (client, zone, NULL, &error); icaltimezone_free (zone, 1); - if (!success) + if (!success) { + g_debug ("%s: Failed to add timezone: %s", G_STRFUNC, error ? error->message : "Unknown error"); + if (error) + g_error_free (error); return FALSE; + } } else if (kind == ICAL_VJOURNAL_COMPONENT) { success = memo_list_selector_update_single_object ( client, subcomp); @@ -96,9 +109,36 @@ memo_list_selector_update_objects (ECal *client, return TRUE; } +static void +client_opened_cb (GObject *source_object, GAsyncResult *result, gpointer user_data) +{ + gchar *uid = user_data; + EClient *client = NULL; + GError *error = NULL; + + g_return_if_fail (uid != NULL); + + if (!e_client_utils_open_new_finish (E_SOURCE (source_object), result, &client, &error)) + client = NULL; + + if (error) { + g_debug ("%s: Failed to open memo list: %s", G_STRFUNC, error->message); + g_error_free (error); + } + + if (client) { + if (!e_client_is_readonly (client)) + e_cal_client_remove_object_sync (E_CAL_CLIENT (client), uid, NULL, CALOBJ_MOD_THIS, NULL, NULL); + + g_object_unref (client); + } + + g_free (uid); +} + static gboolean memo_list_selector_process_data (ESourceSelector *selector, - ECal *client, + ECalClient *client, const gchar *source_uid, icalcomponent *icalcomp, GdkDragAction action) @@ -109,7 +149,6 @@ memo_list_selector_process_data (ESourceSelector *selector, const gchar *uid; gchar *old_uid = NULL; gboolean success = FALSE; - gboolean read_only = TRUE; GError *error = NULL; /* FIXME Deal with GDK_ACTION_ASK. */ @@ -123,13 +162,13 @@ memo_list_selector_process_data (ESourceSelector *selector, if (old_uid == NULL) old_uid = g_strdup (uid); - if (e_cal_get_object (client, uid, NULL, &tmp_icalcomp, &error)) { + if (e_cal_client_get_object_sync (client, uid, NULL, &tmp_icalcomp, NULL, &error)) { icalcomponent_free (tmp_icalcomp); success = TRUE; goto exit; } - if (error != NULL && error->code != E_CALENDAR_STATUS_OBJECT_NOT_FOUND) { + if (error != NULL && !g_error_matches (error, E_CAL_CLIENT_ERROR, E_CAL_CLIENT_ERROR_OBJECT_NOT_FOUND)) { g_message ( "Failed to search the object in destination " "task list: %s", error->message); @@ -137,6 +176,9 @@ memo_list_selector_process_data (ESourceSelector *selector, goto exit; } + if (error) + g_error_free (error); + success = memo_list_selector_update_objects (client, icalcomp); if (!success || action != GDK_ACTION_MOVE) @@ -148,74 +190,93 @@ memo_list_selector_process_data (ESourceSelector *selector, if (!E_IS_SOURCE (source) || e_source_get_readonly (source)) goto exit; - client = e_auth_new_cal_from_source (source, E_CAL_SOURCE_TYPE_JOURNAL); - if (client == NULL) { - g_message ("Cannot create source client to remove old memo"); - goto exit; - } - - e_cal_is_read_only (client, &read_only, NULL); - if (!read_only && e_cal_open (client, TRUE, NULL)) - e_cal_remove_object (client, old_uid, NULL); - else if (!read_only) - g_message ("Cannot open source client to remove old memo"); + e_client_utils_open_new (source, E_CLIENT_SOURCE_TYPE_MEMOS, TRUE, NULL, + e_client_utils_authenticate_handler, NULL, + client_opened_cb, g_strdup (old_uid)); - g_object_unref (client); - -exit: + exit: g_free (old_uid); return success; } -static gboolean -memo_list_selector_data_dropped (ESourceSelector *selector, - GtkSelectionData *selection_data, - ESource *destination, - GdkDragAction action, - guint info) +struct DropData { - ECal *client; - GSList *list, *iter; - gboolean success = FALSE; + ESourceSelector *selector; + GdkDragAction action; + GSList *list; +}; - client = e_auth_new_cal_from_source ( - destination, E_CAL_SOURCE_TYPE_JOURNAL); +static void +client_opened_for_drop_cb (GObject *source_object, GAsyncResult *result, gpointer user_data) +{ + struct DropData *dd = user_data; + EClient *client = NULL; + GError *error = NULL; - if (client == NULL || !e_cal_open (client, TRUE, NULL)) - goto exit; + g_return_if_fail (dd != NULL); - list = cal_comp_selection_get_string_list (selection_data); + if (!e_client_utils_open_new_finish (E_SOURCE (source_object), result, &client, &error)) + client = NULL; - for (iter = list; iter != NULL; iter = iter->next) { - gchar *source_uid = iter->data; - icalcomponent *icalcomp; - gchar *component_string; + if (error) { + g_debug ("%s: Failed to open memo list: %s", G_STRFUNC, error->message); + g_error_free (error); + } - /* Each string is "source_uid\ncomponent_string". */ - component_string = strchr (source_uid, '\n'); - if (component_string == NULL) - continue; + if (client) { + ECalClient *cal_client = E_CAL_CLIENT (client); + GSList *iter; - *component_string++ = '\0'; - icalcomp = icalparser_parse_string (component_string); - if (icalcomp == NULL) - continue; + for (iter = dd->list; iter != NULL; iter = iter->next) { + gchar *source_uid = iter->data; + icalcomponent *icalcomp; + gchar *component_string; - success = memo_list_selector_process_data ( - selector, client, source_uid, icalcomp, action); + /* Each string is "source_uid\ncomponent_string". */ + component_string = strchr (source_uid, '\n'); + if (component_string == NULL) + continue; - icalcomponent_free (icalcomp); - } + *component_string++ = '\0'; + icalcomp = icalparser_parse_string (component_string); + if (icalcomp == NULL) + continue; + + memo_list_selector_process_data ( + dd->selector, cal_client, source_uid, icalcomp, dd->action); - g_slist_foreach (list, (GFunc) g_free, NULL); - g_slist_free (list); + icalcomponent_free (icalcomp); + } -exit: - if (client != NULL) g_object_unref (client); + } - return success; + g_slist_foreach (dd->list, (GFunc) g_free, NULL); + g_slist_free (dd->list); + g_object_unref (dd->selector); + g_free (dd); +} + +static gboolean +memo_list_selector_data_dropped (ESourceSelector *selector, + GtkSelectionData *selection_data, + ESource *destination, + GdkDragAction action, + guint info) +{ + struct DropData *dd; + + dd = g_new0 (struct DropData, 1); + dd->selector = g_object_ref (selector); + dd->action = action; + dd->list = cal_comp_selection_get_string_list (selection_data); + + e_client_utils_open_new (destination, E_CLIENT_SOURCE_TYPE_MEMOS, TRUE, NULL, + e_client_utils_authenticate_handler, NULL, + client_opened_for_drop_cb, dd); + + return TRUE; } static void -- cgit v1.2.3