[gnome-calendar/ui-rewrite] manager: update GcalManager::remove_event API



commit 3661a49a6d674b0bf982a6fba818b256d712a999
Author: Erick Pérez Castellanos <erick red gmail com>
Date:   Tue Dec 2 16:30:58 2014 -0500

    manager: update GcalManager::remove_event API
    
    Move GcalManager::remove_event API to new style using ESource and
    ECalComponent instead of uuid
    Update GcalWindow uses of this API

 src/gcal-manager.c |  119 ++++++++++++++++++++++++++--------------------------
 src/gcal-manager.h |    9 ++--
 src/gcal-window.c  |   46 ++++++++++++--------
 3 files changed, 93 insertions(+), 81 deletions(-)
---
diff --git a/src/gcal-manager.c b/src/gcal-manager.c
index 03e8a52..3fe43ab 100644
--- a/src/gcal-manager.c
+++ b/src/gcal-manager.c
@@ -99,6 +99,10 @@ static void     on_event_updated                         (GObject          *sour
                                                           GAsyncResult     *result,
                                                           gpointer          user_data);
 
+static void     on_event_removed                          (GObject         *source_object,
+                                                           GAsyncResult    *result,
+                                                           gpointer         user_data);
+
 static void     remove_source                             (GcalManager     *manager,
                                                            ESource         *source);
 
@@ -106,10 +110,6 @@ static void     remove_source                             (GcalManager     *mana
 
 static void     gcal_manager_finalize                     (GObject         *object);
 
-static void     gcal_manager_on_event_removed             (GObject         *source_object,
-                                                           GAsyncResult    *result,
-                                                           gpointer         user_data);
-
 static void     gcal_manager_on_event_created             (GObject         *source_object,
                                                            GAsyncResult    *result,
                                                            gpointer         user_data);
@@ -337,6 +337,37 @@ on_event_updated (GObject      *source_object,
   g_object_unref (E_CAL_COMPONENT (user_data));
 }
 
+/**
+ * on_event_removed:
+ * @source_object: { link ECalClient} source
+ * @result: result of the operation
+ * @user_data: an { link ECalComponent}
+ *
+ * Called when an component is removed. Currently, it only checks for
+ * error, but a more sophisticated implementation will come in no time.*
+ *
+ **/
+static void
+on_event_removed (GObject      *source_object,
+                  GAsyncResult *result,
+                  gpointer      user_data)
+{
+  ECalClient *client;
+  GError *error;
+
+  client = E_CAL_CLIENT (source_object);
+
+  error = NULL;
+  if (!e_cal_client_remove_object_finish (client, result, &error))
+    {
+      /* FIXME: Notify the user somehow */
+      g_warning ("Error removing event: %s", error->message);
+      g_error_free (error);
+    }
+
+  g_object_unref (E_CAL_COMPONENT (user_data));
+}
+
 void
 remove_source (GcalManager  *manager,
                ESource      *source)
@@ -448,35 +479,6 @@ gcal_manager_finalize (GObject *object)
 }
 
 static void
-gcal_manager_on_event_removed (GObject      *source_object,
-                               GAsyncResult *result,
-                               gpointer      user_data)
-{
-  ECalClient *client;
-  DeleteEventData *data;
-  GError *error;
-
-  client = E_CAL_CLIENT (source_object);
-  data = (DeleteEventData*) user_data;
-
-  error = NULL;
-  if (e_cal_client_remove_object_finish (client, result, &error))
-    {
-      /* removing events from hash */
-      /* FIXME: add notification to UI */
-      g_debug ("Found and removed: %s", data->event_uid);
-    }
-  else
-    {
-      //FIXME: do something when there was some error
-      ;
-    }
-
-  g_free (data->event_uid);
-  g_free (data);
-}
-
-static void
 gcal_manager_on_event_created (GObject      *source_object,
                                GAsyncResult *result,
                                gpointer      user_data)
@@ -692,32 +694,6 @@ gcal_manager_is_client_writable (GcalManager *manager,
 }
 
 void
-gcal_manager_remove_event (GcalManager *manager,
-                           const gchar *source_uid,
-                           const gchar *event_uid)
-{
-  GcalManagerPrivate *priv;
-  GcalManagerUnit *unit;
-  DeleteEventData *data;
-
-  priv = gcal_manager_get_instance_private (manager);
-
-  unit = g_hash_table_lookup (priv->clients, source_uid);
-
-  data = g_new0 (DeleteEventData, 1);
-  data->event_uid = g_strdup (event_uid);
-  data->unit = unit;
-  data->manager = manager;
-  e_cal_client_remove_object (unit->client,
-                              event_uid,
-                              NULL,
-                              E_CAL_OBJ_MOD_ALL,
-                              priv->async_ops,
-                              gcal_manager_on_event_removed,
-                              data);
-}
-
-void
 gcal_manager_create_event (GcalManager        *manager,
                            const gchar        *source_uid,
                            const gchar        *summary,
@@ -797,6 +773,31 @@ gcal_manager_update_event (GcalManager   *manager,
 }
 
 void
+gcal_manager_remove_event (GcalManager   *manager,
+                           ESource       *source,
+                           ECalComponent *component)
+{
+  GcalManagerPrivate *priv;
+  GcalManagerUnit *unit;
+  ECalComponentId *id;
+
+  priv = gcal_manager_get_instance_private (manager);
+
+  unit = g_hash_table_lookup (priv->clients, source);
+  id = e_cal_component_get_id (component);
+
+  e_cal_client_remove_object (unit->client,
+                              id->uid,
+                              id->rid,
+                              E_CAL_OBJ_MOD_THIS,
+                              priv->async_ops,
+                              on_event_removed,
+                              component);
+
+  e_cal_component_free_id (id);
+}
+
+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 f89a462..bf0cf93 100644
--- a/src/gcal-manager.h
+++ b/src/gcal-manager.h
@@ -91,10 +91,6 @@ void           gcal_manager_refresh                 (GcalManager        *manager
 gboolean       gcal_manager_is_client_writable      (GcalManager        *manager,
                                                      ESource            *source);
 
-void           gcal_manager_remove_event            (GcalManager        *manager,
-                                                     const gchar        *source_uid,
-                                                     const gchar        *event_uid);
-
 /* Create method */
 void           gcal_manager_create_event            (GcalManager        *manager,
                                                      const gchar        *source_uid,
@@ -107,6 +103,11 @@ void           gcal_manager_update_event            (GcalManager        *manager
                                                      ESource            *source,
                                                      ECalComponent      *component);
 
+/* Remove method */
+void           gcal_manager_remove_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 43a2e6e..aee0ab2 100644
--- a/src/gcal-window.c
+++ b/src/gcal-window.c
@@ -92,9 +92,8 @@ typedef struct
   gboolean             leaving_search_mode;
 
   NewEventData        *event_creation_data;
-  /* FIXME: Review to see if this are needed */
-  /* temp to keep the will_delete event uuid */
-  gchar               *event_to_delete;
+
+  GcalEventData       *event_to_delete;
 
   /* temp to keep event_creation */
   gboolean             open_edit_dialog;
@@ -764,6 +763,8 @@ edit_dialog_closed (GtkDialog *dialog,
   ECalComponent *component;
   GcalView *view;
 
+  gchar *uuid;
+
   priv = gcal_window_get_instance_private (GCAL_WINDOW (user_data));
 
   gtk_widget_hide (GTK_WIDGET (dialog));
@@ -791,13 +792,20 @@ edit_dialog_closed (GtkDialog *dialog,
       gtk_revealer_set_reveal_child (GTK_REVEALER (priv->notification),
                                      TRUE);
 
-      priv->event_to_delete =
-        gcal_edit_dialog_get_event_uuid (edit_dialog);
+      /* FIXME: this will crash if the notification is still open */
+      if (priv->event_to_delete != NULL)
+        g_free (priv->event_to_delete);
 
-      /* hide widget of the event */
-      gtk_widget_hide (gcal_view_get_by_uuid (view,
-                                              priv->event_to_delete));
+      priv->event_to_delete = g_new0 (GcalEventData, 1);
+      priv->event_to_delete->source =
+        gcal_edit_dialog_get_source (edit_dialog);
+      priv->event_to_delete->event_component =
+        gcal_edit_dialog_get_component (edit_dialog);
 
+      uuid = gcal_edit_dialog_get_event_uuid (edit_dialog);
+      /* hide widget of the event */
+      gtk_widget_hide (gcal_view_get_by_uuid (view, uuid));
+      g_free (uuid);
       break;
 
     case GTK_RESPONSE_CANCEL:
@@ -896,7 +904,6 @@ remove_event (GtkWidget       *notification,
                           gpointer         user_data)
 {
   GcalWindowPrivate *priv;
-  gchar **tokens;
 
   priv = gcal_window_get_instance_private (GCAL_WINDOW (user_data));
 
@@ -905,13 +912,11 @@ remove_event (GtkWidget       *notification,
 
   if (priv->event_to_delete != NULL)
     {
-      tokens = g_strsplit (priv->event_to_delete, ":", 2);
-
-      gcal_manager_remove_event (priv->manager, tokens[0], tokens[1]);
+      gcal_manager_remove_event (priv->manager,
+                                 priv->event_to_delete->source,
+                                 priv->event_to_delete->event_component);
 
-      g_strfreev (tokens);
-      g_free (priv->event_to_delete);
-      priv->event_to_delete = NULL;
+      g_clear_pointer (&(priv->event_to_delete), g_free);
     }
 }
 
@@ -920,19 +925,24 @@ undo_remove_event (GtkButton *button,
                    gpointer   user_data)
 {
   GcalWindowPrivate *priv;
+  gchar *uuid;
   GtkWidget *event_widget;
 
   priv = gcal_window_get_instance_private (GCAL_WINDOW (user_data));
 
   if (priv->event_to_delete != NULL)
     {
+      uuid = get_uuid_from_component (
+                 priv->event_to_delete->source,
+                 priv->event_to_delete->event_component);
       event_widget = gcal_view_get_by_uuid (
           GCAL_VIEW (priv->views[priv->active_view]),
-          priv->event_to_delete);
+          uuid);
+
       gtk_widget_show (event_widget);
 
-      g_free (priv->event_to_delete);
-      priv->event_to_delete = NULL;
+      g_clear_pointer (&(priv->event_to_delete), g_free);
+      g_free (uuid);
 
       gtk_revealer_set_reveal_child (GTK_REVEALER (priv->notification),
                                      FALSE);


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