[gnome-calendar] edit-dialog: implements GCAL_RESPONSE_SAVE_EVENT



commit 56e69f7c883fcb801d82cdc4b98c473353f30989
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Fri Oct 31 00:14:20 2014 -0200

    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>

 src/gcal-edit-dialog.c |   21 ++++++++++++++++++-
 src/gcal-edit-dialog.h |    5 ++++
 src/gcal-manager.c     |   51 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/gcal-manager.h     |    5 ++++
 src/gcal-window.c      |   15 +++++++++++++-
 5 files changed, 95 insertions(+), 2 deletions(-)
---
diff --git a/src/gcal-edit-dialog.c b/src/gcal-edit-dialog.c
index 502f6c2..c8309c0 100644
--- a/src/gcal-edit-dialog.c
+++ b/src/gcal-edit-dialog.c
@@ -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)
 {
diff --git a/src/gcal-edit-dialog.h b/src/gcal-edit-dialog.h
index 39e0dcb..182b79c 100644
--- a/src/gcal-edit-dialog.h
+++ b/src/gcal-edit-dialog.h
@@ -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);
diff --git a/src/gcal-manager.c b/src/gcal-manager.c
index e3c8879..6cb665c 100644
--- a/src/gcal-manager.c
+++ b/src/gcal-manager.c
@@ -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)
@@ -648,6 +680,25 @@ gcal_manager_create_event (GcalManager        *manager,
 }
 
 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,
                                    const gchar *event_uid,
diff --git a/src/gcal-manager.h b/src/gcal-manager.h
index a3943d6..d38f307 100644
--- a/src/gcal-manager.h
+++ b/src/gcal-manager.h
@@ -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,
diff --git a/src/gcal-window.c b/src/gcal-window.c
index d299583..009e1fb 100644
--- a/src/gcal-window.c
+++ b/src/gcal-window.c
@@ -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;
+
     }
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]