[gnome-calendar/wip/gbsneto/gcal-event: 6/6] manager: use GcalEvent on it's API
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar/wip/gbsneto/gcal-event: 6/6] manager: use GcalEvent on it's API
- Date: Fri, 12 Feb 2016 23:19:38 +0000 (UTC)
commit a49ea9fc9639c328c33ff7e923ed990e000b32b7
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Fri Feb 12 17:16:31 2016 -0200
manager: use GcalEvent on it's API
To make things consistend and clear, use the
GcalEvent class to handle events.
src/gcal-manager.c | 46 +++++++++++++++++++++++++---------------------
src/gcal-manager.h | 12 ++++--------
src/gcal-window.c | 39 +++++++++++++--------------------------
3 files changed, 42 insertions(+), 55 deletions(-)
---
diff --git a/src/gcal-manager.c b/src/gcal-manager.c
index 3e31b2c..61ad354 100644
--- a/src/gcal-manager.c
+++ b/src/gcal-manager.c
@@ -24,8 +24,7 @@
typedef struct
{
- ESource *source;
- ECalComponent *component;
+ GcalEvent *event;
GcalManager *manager;
} AsyncOpsData;
@@ -251,7 +250,7 @@ submit_thread_job (EThreadJobFunc func,
static void
free_async_ops_data (AsyncOpsData *data)
{
- g_object_unref (data->component);
+ g_object_unref (data->event);
g_free (data);
}
@@ -1380,20 +1379,22 @@ gcal_manager_is_client_writable (GcalManager *manager,
void
gcal_manager_create_event (GcalManager *manager,
- ESource *source,
- ECalComponent *component)
+ GcalEvent *event)
{
GcalManagerUnit *unit;
icalcomponent *new_event_icalcomp;
+ ECalComponent *component;
AsyncOpsData *data;
+ ESource *source;
+ source = gcal_event_get_source (event);
+ component = gcal_event_get_component (event);
unit = g_hash_table_lookup (manager->clients, source);
new_event_icalcomp = e_cal_component_get_icalcomponent (component);
data = g_new0 (AsyncOpsData, 1);
- data->source = source;
- data->component = component;
+ data->event = g_object_ref (event);
data->manager = manager;
e_cal_client_create_object (unit->client,
@@ -1404,13 +1405,14 @@ gcal_manager_create_event (GcalManager *manager,
}
void
-gcal_manager_update_event (GcalManager *manager,
- ESource *source,
- ECalComponent *component)
+gcal_manager_update_event (GcalManager *manager,
+ GcalEvent *event)
{
GcalManagerUnit *unit;
+ ECalComponent *component;
- unit = (GcalManagerUnit*) g_hash_table_lookup (manager->clients, source);
+ unit = g_hash_table_lookup (manager->clients, gcal_event_get_source (event));
+ component = gcal_event_get_component (event);
e_cal_client_modify_object (unit->client,
e_cal_component_get_icalcomponent (component),
@@ -1422,13 +1424,14 @@ gcal_manager_update_event (GcalManager *manager,
void
gcal_manager_remove_event (GcalManager *manager,
- ESource *source,
- ECalComponent *component)
+ GcalEvent *event)
{
GcalManagerUnit *unit;
ECalComponentId *id;
+ ECalComponent *component;
- unit = g_hash_table_lookup (manager->clients, source);
+ component = gcal_event_get_component (event);
+ unit = g_hash_table_lookup (manager->clients, gcal_event_get_source (event));
id = e_cal_component_get_id (component);
e_cal_client_remove_object (unit->client,
@@ -1443,11 +1446,11 @@ gcal_manager_remove_event (GcalManager *manager,
}
void
-gcal_manager_move_event_to_source (GcalManager *manager,
- ECalComponent *component,
- ESource *source,
- ESource *dest)
+gcal_manager_move_event_to_source (GcalManager *manager,
+ GcalEvent *event,
+ ESource *dest)
{
+ ECalComponent *ecomponent;
ECalComponent *clone;
icalcomponent *comp;
GcalManagerUnit *unit;
@@ -1461,7 +1464,8 @@ gcal_manager_move_event_to_source (GcalManager *manager,
/* First, try to create the component on the destination source */
unit = g_hash_table_lookup (manager->clients, dest);
- clone = e_cal_component_clone (component);
+ ecomponent = gcal_event_get_component (event);
+ clone = e_cal_component_clone (ecomponent);
comp = e_cal_component_get_icalcomponent (clone);
e_cal_client_create_object_sync (unit->client,
@@ -1482,9 +1486,9 @@ gcal_manager_move_event_to_source (GcalManager *manager,
* created, try to remove the old component. Data loss it the last
* thing we want to happen here.
*/
- unit = g_hash_table_lookup (manager->clients, source);
+ unit = g_hash_table_lookup (manager->clients, gcal_event_get_source (event));
- id = e_cal_component_get_id (component);
+ id = e_cal_component_get_id (ecomponent);
e_cal_client_remove_object_sync (unit->client,
id->uid,
diff --git a/src/gcal-manager.h b/src/gcal-manager.h
index 92f3f0e..891b392 100644
--- a/src/gcal-manager.h
+++ b/src/gcal-manager.h
@@ -104,23 +104,19 @@ gboolean gcal_manager_is_client_writable (GcalManager *manager
/* Create method */
void gcal_manager_create_event (GcalManager *manager,
- ESource *source,
- ECalComponent *component);
+ GcalEvent *event);
/* Update method */
void gcal_manager_update_event (GcalManager *manager,
- ESource *source,
- ECalComponent *component);
+ GcalEvent *event);
/* Remove method */
void gcal_manager_remove_event (GcalManager *manager,
- ESource *source,
- ECalComponent *component);
+ GcalEvent *event);
/* Set methods */
void gcal_manager_move_event_to_source (GcalManager *manager,
- ECalComponent *component,
- ESource *source,
+ GcalEvent *event,
ESource *dest);
GList* gcal_manager_get_events (GcalManager *manager,
diff --git a/src/gcal-window.c b/src/gcal-window.c
index ae3c808..5ee79a2 100644
--- a/src/gcal-window.c
+++ b/src/gcal-window.c
@@ -708,9 +708,8 @@ show_new_event_widget (GcalView *view,
g_debug ("[show_new_event] position (%f, %f)", x, y);
/* Setup new event widget data */
- prepare_new_event_widget (GCAL_WINDOW (user_data));
-
- place_new_event_widget (GCAL_WINDOW (user_data), x, y);
+ prepare_new_event_widget (window);
+ place_new_event_widget (window, x, y);
}
static void
@@ -1071,8 +1070,9 @@ create_event (gpointer user_data,
GtkWidget *widget)
{
GcalWindow *window = GCAL_WINDOW (user_data);
- ESource *source;
ECalComponent *comp;
+ GcalEvent *event;
+ ESource *source;
/* reset and hide */
set_new_event_mode (GCAL_WINDOW (user_data), FALSE);
@@ -1081,12 +1081,10 @@ create_event (gpointer user_data,
comp = build_component_from_details (gtk_entry_get_text (GTK_ENTRY (window->new_event_what_entry)),
window->event_creation_data->start_date,
window->event_creation_data->end_date);
+ event = gcal_event_new (source, comp);
+
if (widget == window->new_event_details_button)
{
- GcalEvent *event;
-
- event = gcal_event_new (source, comp);
-
gcal_edit_dialog_set_event_is_new (GCAL_EDIT_DIALOG (window->edit_dialog), TRUE);
gcal_edit_dialog_set_event (GCAL_EDIT_DIALOG (window->edit_dialog), event);
g_object_unref (comp);
@@ -1096,10 +1094,11 @@ create_event (gpointer user_data,
else
{
/* create the event */
- gcal_manager_create_event (window->manager, source, comp);
+ gcal_manager_create_event (window->manager, event);
}
- g_object_unref (source);
+ g_clear_object (&source);
+ g_clear_object (&event);
}
static void
@@ -1156,26 +1155,17 @@ edit_dialog_closed (GtkDialog *dialog,
switch (response)
{
case GCAL_RESPONSE_CREATE_EVENT:
- gcal_manager_create_event (window->manager,
- gcal_event_get_source (event),
- g_object_ref (gcal_event_get_component (event)));
-
+ gcal_manager_create_event (window->manager, event);
break;
case GCAL_RESPONSE_SAVE_EVENT:
- gcal_manager_update_event (window->manager,
- gcal_event_get_source (event),
- g_object_ref (gcal_event_get_component (event)));
-
+ gcal_manager_update_event (window->manager, event);
break;
case GCAL_RESPONSE_DELETE_EVENT:
if (window->event_to_delete != NULL)
{
- gcal_manager_remove_event (window->manager,
- gcal_event_get_source (window->event_to_delete),
- gcal_event_get_component (window->event_to_delete));
-
+ gcal_manager_remove_event (window->manager, window->event_to_delete);
g_clear_object (&window->event_to_delete);
create_notification (GCAL_WINDOW (user_data), _("Another event deleted"), _("Undo"));
@@ -1245,10 +1235,7 @@ remove_event (GtkWidget *notification,
if (window->event_to_delete != NULL)
{
- gcal_manager_remove_event (window->manager,
- gcal_event_get_source (window->event_to_delete),
- gcal_event_get_component (window->event_to_delete));
-
+ gcal_manager_remove_event (window->manager, window->event_to_delete);
g_clear_object (&window->event_to_delete);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]