edit-dialog: implements GCAL_RESPONSE_SAVE_EVENT

This patch mainly implements GCAL_RESPONSE_SAVE_EVENT. It updates the event correctly, no matter in which source it is.

Signed-off-by: Georges Basile Stavracas Neto <georges.stavracas@gmail.com>
This commit is contained in:
Georges Basile Stavracas Neto
2014-12-04 17:10:49 -05:00
committed by Erick Pérez Castellanos
parent 5a1f12ad00
commit 56e69f7c88
5 changed files with 95 additions and 2 deletions
+20 -1
View File
@@ -220,7 +220,7 @@ gcal_edit_dialog_constructed (GObject* object)
object);
g_object_set_data (G_OBJECT (priv->done_button),
"response",
GINT_TO_POINTER (GTK_RESPONSE_ACCEPT));
GINT_TO_POINTER (GCAL_RESPONSE_SAVE_EVENT));
g_signal_connect (priv->done_button,
"clicked",
G_CALLBACK (gcal_edit_dialog_action_button_clicked),
@@ -765,6 +765,25 @@ gcal_edit_dialog_set_manager (GcalEditDialog *dialog,
priv->manager = manager;
}
ECalComponent*
gcal_edit_dialog_get_component (GcalEditDialog *dialog)
{
GcalEditDialogPrivate *priv;
priv = gcal_edit_dialog_get_instance_private (dialog);
g_object_ref (priv->component);
return priv->component;
}
ESource*
gcal_edit_dialog_get_source (GcalEditDialog *dialog)
{
GcalEditDialogPrivate *priv;
priv = gcal_edit_dialog_get_instance_private (dialog);
return priv->source;
}
const gchar*
gcal_edit_dialog_peek_source_uid (GcalEditDialog *dialog)
{
+5
View File
@@ -27,6 +27,7 @@
G_BEGIN_DECLS
#define GCAL_RESPONSE_DELETE_EVENT 2
#define GCAL_RESPONSE_SAVE_EVENT 4
#define GCAL_TYPE_EDIT_DIALOG (gcal_edit_dialog_get_type ())
@@ -60,6 +61,10 @@ void gcal_edit_dialog_set_event_data (GcalEditDialog *d
void gcal_edit_dialog_set_manager (GcalEditDialog *dialog,
GcalManager *manager);
ECalComponent* gcal_edit_dialog_get_component (GcalEditDialog *dialog);
ESource* gcal_edit_dialog_get_source (GcalEditDialog *dialog);
const gchar* gcal_edit_dialog_peek_source_uid (GcalEditDialog *dialog);
const gchar* gcal_edit_dialog_peek_event_uid (GcalEditDialog *dialog);
+51
View File
@@ -90,6 +90,10 @@ static void on_client_connected (GObject *sour
GAsyncResult *result,
gpointer user_data);
static void on_event_updated (GObject *source_object,
GAsyncResult *result,
gpointer user_data);
static void remove_source (GcalManager *manager,
ESource *source);
@@ -278,6 +282,34 @@ on_client_connected (GObject *source_object,
}
}
/**
* on_component_updated:
* @source_object: {@link ECalClient} source
* @result: result of the operation
* @user_data: manager instance
*
* Called when an component is modified. Currently, it only checks for
* error, but a more sophisticated implementation will come in no time.
*
**/
static void
on_event_updated (GObject *source_object,
GAsyncResult *result,
gpointer user_data)
{
GError *error;
error = NULL;
if (! e_cal_client_modify_object_finish (E_CAL_CLIENT (source_object),
result,
&error))
{
g_warning ("Error updating component: %s", error->message);
g_error_free (error);
}
g_object_unref (E_CAL_COMPONENT (user_data));
}
void
remove_source (GcalManager *manager,
ESource *source)
@@ -647,6 +679,25 @@ gcal_manager_create_event (GcalManager *manager,
g_object_unref (event);
}
void
gcal_manager_update_event (GcalManager *manager,
ESource *source,
ECalComponent *component)
{
GcalManagerPrivate *priv;
GcalManagerUnit *unit;
priv = gcal_manager_get_instance_private (manager);
unit = (GcalManagerUnit*) g_hash_table_lookup (priv->clients, source);
e_cal_client_modify_object (unit->client,
e_cal_component_get_icalcomponent (component),
E_CAL_OBJ_MOD_THIS,
NULL,
on_event_updated,
component);
}
void
gcal_manager_move_event_to_source (GcalManager *manager,
const gchar *source_uid,
+5
View File
@@ -92,6 +92,11 @@ void gcal_manager_create_event (GcalManager *manager
const icaltimetype *initial_date,
const icaltimetype *final_date);
/* Update method */
void gcal_manager_update_event (GcalManager *manager,
ESource *source,
ECalComponent *component);
/* Set methods */
void gcal_manager_move_event_to_source (GcalManager *manager,
const gchar *source_uid,
+14 -1
View File
@@ -757,6 +757,7 @@ edit_dialog_closed (GtkDialog *dialog,
GcalWindowPrivate *priv;
GcalEditDialog *edit_dialog;
ECalComponent *component;
GcalView *view;
priv = gcal_window_get_instance_private (GCAL_WINDOW (user_data));
@@ -766,9 +767,18 @@ edit_dialog_closed (GtkDialog *dialog,
view = GCAL_VIEW (priv->views[priv->active_view]);
edit_dialog = GCAL_EDIT_DIALOG (dialog);
/* FIXME: add back cancel and accept responses */
switch (response)
{
case GCAL_RESPONSE_SAVE_EVENT:
/* retrieve the component from the dialog*/
component = gcal_edit_dialog_get_component (edit_dialog);
gcal_manager_update_event (priv->manager,
gcal_edit_dialog_get_source (edit_dialog),
component);
break;
case GCAL_RESPONSE_DELETE_EVENT:
/* delete the event */
if (priv->notification != NULL)
@@ -786,6 +796,9 @@ edit_dialog_closed (GtkDialog *dialog,
break;
case GTK_RESPONSE_CANCEL:
break;
}
}