manager: use GcalEvent on it's API
To make things consistend and clear, use the GcalEvent class to handle events.
This commit is contained in:
+44
-24
@@ -24,8 +24,7 @@
|
|||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
ESource *source;
|
GcalEvent *event;
|
||||||
ECalComponent *component;
|
|
||||||
GcalManager *manager;
|
GcalManager *manager;
|
||||||
} AsyncOpsData;
|
} AsyncOpsData;
|
||||||
|
|
||||||
@@ -251,7 +250,7 @@ submit_thread_job (EThreadJobFunc func,
|
|||||||
static void
|
static void
|
||||||
free_async_ops_data (AsyncOpsData *data)
|
free_async_ops_data (AsyncOpsData *data)
|
||||||
{
|
{
|
||||||
g_object_unref (data->component);
|
g_object_unref (data->event);
|
||||||
g_free (data);
|
g_free (data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -500,16 +499,18 @@ on_event_removed (GObject *source_object,
|
|||||||
GError *error;
|
GError *error;
|
||||||
|
|
||||||
client = E_CAL_CLIENT (source_object);
|
client = E_CAL_CLIENT (source_object);
|
||||||
|
|
||||||
error = NULL;
|
error = NULL;
|
||||||
if (!e_cal_client_remove_object_finish (client, result, &error))
|
|
||||||
|
e_cal_client_remove_object_finish (client, result, &error);
|
||||||
|
|
||||||
|
if (error)
|
||||||
{
|
{
|
||||||
/* FIXME: Notify the user somehow */
|
/* FIXME: Notify the user somehow */
|
||||||
g_warning ("Error removing event: %s", error->message);
|
g_warning ("Error removing event: %s", error->message);
|
||||||
g_error_free (error);
|
g_error_free (error);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_object_unref (E_CAL_COMPONENT (user_data));
|
g_object_unref (user_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -1380,20 +1381,22 @@ gcal_manager_is_client_writable (GcalManager *manager,
|
|||||||
|
|
||||||
void
|
void
|
||||||
gcal_manager_create_event (GcalManager *manager,
|
gcal_manager_create_event (GcalManager *manager,
|
||||||
ESource *source,
|
GcalEvent *event)
|
||||||
ECalComponent *component)
|
|
||||||
{
|
{
|
||||||
GcalManagerUnit *unit;
|
GcalManagerUnit *unit;
|
||||||
icalcomponent *new_event_icalcomp;
|
icalcomponent *new_event_icalcomp;
|
||||||
|
ECalComponent *component;
|
||||||
AsyncOpsData *data;
|
AsyncOpsData *data;
|
||||||
|
ESource *source;
|
||||||
|
|
||||||
|
source = gcal_event_get_source (event);
|
||||||
|
component = gcal_event_get_component (event);
|
||||||
unit = g_hash_table_lookup (manager->clients, source);
|
unit = g_hash_table_lookup (manager->clients, source);
|
||||||
|
|
||||||
new_event_icalcomp = e_cal_component_get_icalcomponent (component);
|
new_event_icalcomp = e_cal_component_get_icalcomponent (component);
|
||||||
|
|
||||||
data = g_new0 (AsyncOpsData, 1);
|
data = g_new0 (AsyncOpsData, 1);
|
||||||
data->source = source;
|
data->event = g_object_ref (event);
|
||||||
data->component = component;
|
|
||||||
data->manager = manager;
|
data->manager = manager;
|
||||||
|
|
||||||
e_cal_client_create_object (unit->client,
|
e_cal_client_create_object (unit->client,
|
||||||
@@ -1404,13 +1407,21 @@ gcal_manager_create_event (GcalManager *manager,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
gcal_manager_update_event (GcalManager *manager,
|
gcal_manager_update_event (GcalManager *manager,
|
||||||
ESource *source,
|
GcalEvent *event)
|
||||||
ECalComponent *component)
|
|
||||||
{
|
{
|
||||||
GcalManagerUnit *unit;
|
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);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* While we're updating the event, we don't want the component
|
||||||
|
* to be destroyed, so take a reference of the component while
|
||||||
|
* we're performing the update on it.
|
||||||
|
*/
|
||||||
|
g_object_ref (component);
|
||||||
|
|
||||||
e_cal_client_modify_object (unit->client,
|
e_cal_client_modify_object (unit->client,
|
||||||
e_cal_component_get_icalcomponent (component),
|
e_cal_component_get_icalcomponent (component),
|
||||||
@@ -1422,15 +1433,23 @@ gcal_manager_update_event (GcalManager *manager,
|
|||||||
|
|
||||||
void
|
void
|
||||||
gcal_manager_remove_event (GcalManager *manager,
|
gcal_manager_remove_event (GcalManager *manager,
|
||||||
ESource *source,
|
GcalEvent *event)
|
||||||
ECalComponent *component)
|
|
||||||
{
|
{
|
||||||
GcalManagerUnit *unit;
|
GcalManagerUnit *unit;
|
||||||
ECalComponentId *id;
|
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);
|
id = e_cal_component_get_id (component);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* While we're removing the event, we don't want the component
|
||||||
|
* to be destroyed, so take a reference of the component while
|
||||||
|
* we're deleting it.
|
||||||
|
*/
|
||||||
|
g_object_ref (component);
|
||||||
|
|
||||||
e_cal_client_remove_object (unit->client,
|
e_cal_client_remove_object (unit->client,
|
||||||
id->uid,
|
id->uid,
|
||||||
id->rid,
|
id->rid,
|
||||||
@@ -1443,11 +1462,11 @@ gcal_manager_remove_event (GcalManager *manager,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
gcal_manager_move_event_to_source (GcalManager *manager,
|
gcal_manager_move_event_to_source (GcalManager *manager,
|
||||||
ECalComponent *component,
|
GcalEvent *event,
|
||||||
ESource *source,
|
ESource *dest)
|
||||||
ESource *dest)
|
|
||||||
{
|
{
|
||||||
|
ECalComponent *ecomponent;
|
||||||
ECalComponent *clone;
|
ECalComponent *clone;
|
||||||
icalcomponent *comp;
|
icalcomponent *comp;
|
||||||
GcalManagerUnit *unit;
|
GcalManagerUnit *unit;
|
||||||
@@ -1461,7 +1480,8 @@ gcal_manager_move_event_to_source (GcalManager *manager,
|
|||||||
/* First, try to create the component on the destination source */
|
/* First, try to create the component on the destination source */
|
||||||
unit = g_hash_table_lookup (manager->clients, dest);
|
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);
|
comp = e_cal_component_get_icalcomponent (clone);
|
||||||
|
|
||||||
e_cal_client_create_object_sync (unit->client,
|
e_cal_client_create_object_sync (unit->client,
|
||||||
@@ -1482,9 +1502,9 @@ gcal_manager_move_event_to_source (GcalManager *manager,
|
|||||||
* created, try to remove the old component. Data loss it the last
|
* created, try to remove the old component. Data loss it the last
|
||||||
* thing we want to happen here.
|
* 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,
|
e_cal_client_remove_object_sync (unit->client,
|
||||||
id->uid,
|
id->uid,
|
||||||
|
|||||||
+4
-8
@@ -104,23 +104,19 @@ gboolean gcal_manager_is_client_writable (GcalManager *manager
|
|||||||
|
|
||||||
/* Create method */
|
/* Create method */
|
||||||
void gcal_manager_create_event (GcalManager *manager,
|
void gcal_manager_create_event (GcalManager *manager,
|
||||||
ESource *source,
|
GcalEvent *event);
|
||||||
ECalComponent *component);
|
|
||||||
|
|
||||||
/* Update method */
|
/* Update method */
|
||||||
void gcal_manager_update_event (GcalManager *manager,
|
void gcal_manager_update_event (GcalManager *manager,
|
||||||
ESource *source,
|
GcalEvent *event);
|
||||||
ECalComponent *component);
|
|
||||||
|
|
||||||
/* Remove method */
|
/* Remove method */
|
||||||
void gcal_manager_remove_event (GcalManager *manager,
|
void gcal_manager_remove_event (GcalManager *manager,
|
||||||
ESource *source,
|
GcalEvent *event);
|
||||||
ECalComponent *component);
|
|
||||||
|
|
||||||
/* Set methods */
|
/* Set methods */
|
||||||
void gcal_manager_move_event_to_source (GcalManager *manager,
|
void gcal_manager_move_event_to_source (GcalManager *manager,
|
||||||
ECalComponent *component,
|
GcalEvent *event,
|
||||||
ESource *source,
|
|
||||||
ESource *dest);
|
ESource *dest);
|
||||||
|
|
||||||
GList* gcal_manager_get_events (GcalManager *manager,
|
GList* gcal_manager_get_events (GcalManager *manager,
|
||||||
|
|||||||
+11
-26
@@ -708,9 +708,8 @@ show_new_event_widget (GcalView *view,
|
|||||||
g_debug ("[show_new_event] position (%f, %f)", x, y);
|
g_debug ("[show_new_event] position (%f, %f)", x, y);
|
||||||
|
|
||||||
/* Setup new event widget data */
|
/* Setup new event widget data */
|
||||||
prepare_new_event_widget (GCAL_WINDOW (user_data));
|
prepare_new_event_widget (window);
|
||||||
|
place_new_event_widget (window, x, y);
|
||||||
place_new_event_widget (GCAL_WINDOW (user_data), x, y);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -1071,8 +1070,9 @@ create_event (gpointer user_data,
|
|||||||
GtkWidget *widget)
|
GtkWidget *widget)
|
||||||
{
|
{
|
||||||
GcalWindow *window = GCAL_WINDOW (user_data);
|
GcalWindow *window = GCAL_WINDOW (user_data);
|
||||||
ESource *source;
|
|
||||||
ECalComponent *comp;
|
ECalComponent *comp;
|
||||||
|
GcalEvent *event;
|
||||||
|
ESource *source;
|
||||||
|
|
||||||
/* reset and hide */
|
/* reset and hide */
|
||||||
set_new_event_mode (GCAL_WINDOW (user_data), FALSE);
|
set_new_event_mode (GCAL_WINDOW (user_data), FALSE);
|
||||||
@@ -1081,22 +1081,19 @@ create_event (gpointer user_data,
|
|||||||
comp = build_component_from_details (gtk_entry_get_text (GTK_ENTRY (window->new_event_what_entry)),
|
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->start_date,
|
||||||
window->event_creation_data->end_date);
|
window->event_creation_data->end_date);
|
||||||
|
event = gcal_event_new (source, comp);
|
||||||
|
|
||||||
if (widget == window->new_event_details_button)
|
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_is_new (GCAL_EDIT_DIALOG (window->edit_dialog), TRUE);
|
||||||
gcal_edit_dialog_set_event (GCAL_EDIT_DIALOG (window->edit_dialog), event);
|
gcal_edit_dialog_set_event (GCAL_EDIT_DIALOG (window->edit_dialog), event);
|
||||||
g_object_unref (comp);
|
|
||||||
|
|
||||||
gtk_dialog_run (GTK_DIALOG (window->edit_dialog));
|
gtk_dialog_run (GTK_DIALOG (window->edit_dialog));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* create the event */
|
/* create the event */
|
||||||
gcal_manager_create_event (window->manager, source, comp);
|
gcal_manager_create_event (window->manager, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_clear_object (&source);
|
g_clear_object (&source);
|
||||||
@@ -1161,26 +1158,17 @@ edit_dialog_closed (GtkDialog *dialog,
|
|||||||
switch (response)
|
switch (response)
|
||||||
{
|
{
|
||||||
case GCAL_RESPONSE_CREATE_EVENT:
|
case GCAL_RESPONSE_CREATE_EVENT:
|
||||||
gcal_manager_create_event (window->manager,
|
gcal_manager_create_event (window->manager, event);
|
||||||
gcal_event_get_source (event),
|
|
||||||
g_object_ref (gcal_event_get_component (event)));
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GCAL_RESPONSE_SAVE_EVENT:
|
case GCAL_RESPONSE_SAVE_EVENT:
|
||||||
gcal_manager_update_event (window->manager,
|
gcal_manager_update_event (window->manager, event);
|
||||||
gcal_event_get_source (event),
|
|
||||||
g_object_ref (gcal_event_get_component (event)));
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GCAL_RESPONSE_DELETE_EVENT:
|
case GCAL_RESPONSE_DELETE_EVENT:
|
||||||
if (window->event_to_delete != NULL)
|
if (window->event_to_delete != NULL)
|
||||||
{
|
{
|
||||||
gcal_manager_remove_event (window->manager,
|
gcal_manager_remove_event (window->manager, window->event_to_delete);
|
||||||
gcal_event_get_source (window->event_to_delete),
|
|
||||||
gcal_event_get_component (window->event_to_delete));
|
|
||||||
|
|
||||||
g_clear_object (&window->event_to_delete);
|
g_clear_object (&window->event_to_delete);
|
||||||
|
|
||||||
create_notification (GCAL_WINDOW (user_data), _("Another event deleted"), _("Undo"));
|
create_notification (GCAL_WINDOW (user_data), _("Another event deleted"), _("Undo"));
|
||||||
@@ -1250,10 +1238,7 @@ remove_event (GtkWidget *notification,
|
|||||||
|
|
||||||
if (window->event_to_delete != NULL)
|
if (window->event_to_delete != NULL)
|
||||||
{
|
{
|
||||||
gcal_manager_remove_event (window->manager,
|
gcal_manager_remove_event (window->manager, window->event_to_delete);
|
||||||
gcal_event_get_source (window->event_to_delete),
|
|
||||||
gcal_event_get_component (window->event_to_delete));
|
|
||||||
|
|
||||||
g_clear_object (&window->event_to_delete);
|
g_clear_object (&window->event_to_delete);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user