diff options
author | Georges Basile Stavracas Neto <georges.stavracas@gmail.com> | 2015-07-16 00:22:54 -0300 |
---|---|---|
committer | Georges Basile Stavracas Neto <georges.stavracas@gmail.com> | 2015-07-16 00:22:54 -0300 |
commit | 6080b62368f3300d178fec173d31b19eb7b21e0a (patch) | |
tree | f45351115ba38ce161b61e285219070cfcfbce28 | |
parent | d3a806a684a40ec0aa1baa75c67d79e3ce6edaa1 (diff) | |
download | gnome-calendar-6080b62368f3300d178fec173d31b19eb7b21e0a.tar.gz |
manager: implement ::move method
-rw-r--r-- | src/gcal-manager.c | 65 | ||||
-rw-r--r-- | src/gcal-manager.h | 6 |
2 files changed, 62 insertions, 9 deletions
diff --git a/src/gcal-manager.c b/src/gcal-manager.c index 77247c01..4ebaeb61 100644 --- a/src/gcal-manager.c +++ b/src/gcal-manager.c @@ -1528,13 +1528,66 @@ gcal_manager_remove_event (GcalManager *manager, } void -gcal_manager_move_event_to_source (GcalManager *manager, - const gchar *source_uid, - const gchar *event_uid, - const gchar *new_source_uid) +gcal_manager_move_event_to_source (GcalManager *manager, + ECalComponent *component, + ESource *source, + ESource *dest) { - /* FIXME: add code, fix stub method */ - ; + GcalManagerPrivate *priv; + ECalComponent *clone; + icalcomponent *comp; + GcalManagerUnit *unit; + ECalComponentId *id; + GError *error; + + g_return_if_fail (GCAL_IS_MANAGER (manager)); + + priv = gcal_manager_get_instance_private (manager); + error = NULL; + + /* First, try to create the component on the destination source */ + unit = g_hash_table_lookup (priv->clients, dest); + + clone = e_cal_component_clone (component); + comp = e_cal_component_get_icalcomponent (clone); + + e_cal_client_create_object_sync (unit->client, + comp, + NULL, + NULL, + &error); + + if (error) + { + g_warning ("Error moving source: %s", error->message); + g_clear_error (&error); + return; + } + + /* + * After we carefully confirm that a clone of the component was + * created, try to remove the old component. Data loss it the last + * thing we want to happen here. + */ + unit = g_hash_table_lookup (priv->clients, source); + + id = e_cal_component_get_id (component); + + e_cal_client_remove_object_sync (unit->client, + id->uid, + id->rid, + E_CAL_OBJ_MOD_THIS, + priv->async_ops, + &error); + + if (error) + { + g_warning ("Error moving source: %s", error->message); + g_clear_error (&error); + return; + } + + e_cal_component_free_id (id); } /** diff --git a/src/gcal-manager.h b/src/gcal-manager.h index 9eead908..67a48b2b 100644 --- a/src/gcal-manager.h +++ b/src/gcal-manager.h @@ -151,9 +151,9 @@ void gcal_manager_remove_event (GcalManager *manager /* Set methods */ void gcal_manager_move_event_to_source (GcalManager *manager, - const gchar *source_uid, - const gchar *event_uid, - const gchar *new_source_uid); + ECalComponent *component, + ESource *source, + ESource *dest); GList* gcal_manager_get_events (GcalManager *manager, icaltimetype *range_start, |