aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/gui/e-task-list-selector.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 /calendar/gui/e-task-list-selector.c
parentfa4289a2f3c26112c907f283a1fd8ab3fb4f26d6 (diff)
downloadgsoc2013-evolution-84339b3be5a771406fcd5898bbd21dc1c5b98c82.tar.gz
gsoc2013-evolution-84339b3be5a771406fcd5898bbd21dc1c5b98c82.tar.zst
gsoc2013-evolution-84339b3be5a771406fcd5898bbd21dc1c5b98c82.zip
Do not use deprecated EBook/ECal API
Diffstat (limited to 'calendar/gui/e-task-list-selector.c')
-rw-r--r--calendar/gui/e-task-list-selector.c190
1 files changed, 126 insertions, 64 deletions
diff --git a/calendar/gui/e-task-list-selector.c b/calendar/gui/e-task-list-selector.c
index 6967648b1f..9d1fb5cb99 100644
--- a/calendar/gui/e-task-list-selector.c
+++ b/calendar/gui/e-task-list-selector.c
@@ -25,9 +25,9 @@
#include "e-task-list-selector.h"
#include <string.h>
-#include <libecal/e-cal.h>
+#include <libecal/e-cal-client.h>
+#include <libedataserverui/e-client-utils.h>
#include "e-util/e-selection.h"
-#include "calendar/common/authentication.h"
#include "calendar/gui/comp-util.h"
struct _ETaskListSelectorPrivate {
@@ -37,23 +37,31 @@ struct _ETaskListSelectorPrivate {
static gpointer parent_class;
static gboolean
-task_list_selector_update_single_object (ECal *client,
+task_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
-task_list_selector_update_objects (ECal *client,
+task_list_selector_update_objects (ECalClient *client,
icalcomponent *icalcomp)
{
icalcomponent *subcomp;
@@ -74,14 +82,19 @@ task_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_VTODO_COMPONENT ||
kind == ICAL_VEVENT_COMPONENT) {
success = task_list_selector_update_single_object (
@@ -97,9 +110,36 @@ task_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 task 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
task_list_selector_process_data (ESourceSelector *selector,
- ECal *client,
+ ECalClient *client,
const gchar *source_uid,
icalcomponent *icalcomp,
GdkDragAction action)
@@ -110,7 +150,6 @@ task_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. */
@@ -124,13 +163,13 @@ task_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);
@@ -138,6 +177,10 @@ task_list_selector_process_data (ESourceSelector *selector,
goto exit;
}
+ if (error)
+ g_error_free (error);
+ error = NULL;
+
success = task_list_selector_update_objects (client, icalcomp);
if (!success || action != GDK_ACTION_MOVE)
@@ -149,74 +192,93 @@ task_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_TODO);
- if (client == NULL) {
- g_message ("Cannot create source client to remove old task");
- 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 task");
+ 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
-task_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_TODO);
+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 task 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 = task_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;
+
+ task_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
+task_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_TASKS, TRUE, NULL,
+ e_client_utils_authenticate_handler, NULL,
+ client_opened_for_drop_cb, dd);
+
+ return TRUE;
}
static void