[gnome-calendar/ui-rewrite] gcal-view: cleaned API



commit 16ed67919a098381fcf203d505e8567b3aa2695b
Author: Erick Pérez Castellanos <erick red gmail com>
Date:   Wed Jun 19 09:41:35 2013 -0400

    gcal-view: cleaned API
    
    Removed unneeded GcalView:reposition_child method.
    Reworked gcal_window_events_modified to use GcalView:get_by_uuid

 src/gcal-month-view.c |   67 +------------------------------------------------
 src/gcal-view.c       |   15 ++---------
 src/gcal-view.h       |    5 ---
 src/gcal-window.c     |   45 ++++++++++++++++++++++++++------
 src/gcal-year-view.c  |   66 +-----------------------------------------------
 5 files changed, 41 insertions(+), 157 deletions(-)
---
diff --git a/src/gcal-month-view.c b/src/gcal-month-view.c
index 12ecd3c..834258e 100644
--- a/src/gcal-month-view.c
+++ b/src/gcal-month-view.c
@@ -129,9 +129,6 @@ static GtkWidget*     gcal_month_view_get_by_uuid           (GcalView       *vie
                                                              const gchar    *uuid);
 
 /* Review API */
-static void           gcal_month_view_reposition_child      (GcalView       *view,
-                                                             const gchar    *uuid);
-
 static void           gcal_month_view_clear_selection       (GcalView       *view);
 
 static void           gcal_month_view_create_event_on_current_unit (GcalView *view);
@@ -168,7 +165,7 @@ gcal_month_view_class_init (GcalMonthViewClass *klass)
   widget_class->button_release_event = gcal_month_view_button_release;
 
   container_class = GTK_CONTAINER_CLASS (klass);
-  container_class->add   = gcal_month_view_add;
+  container_class->add = gcal_month_view_add;
   container_class->remove = gcal_month_view_remove;
   container_class->forall = gcal_month_view_forall;
 
@@ -210,8 +207,6 @@ gcal_month_view_init (GcalMonthView *self)
 static void
 gcal_view_interface_init (GcalViewIface *iface)
 {
-  iface->reposition_child = gcal_month_view_reposition_child;
-
   iface->clear_selection = gcal_month_view_clear_selection;
 
   iface->create_event_on_current_unit = gcal_month_view_create_event_on_current_unit;
@@ -1285,66 +1280,6 @@ gcal_month_view_get_by_uuid (GcalView    *view,
 }
 
 static void
-gcal_month_view_reposition_child (GcalView    *view,
-                                  const gchar *uuid)
-{
-  GcalMonthViewPrivate *priv;
-  gint i;
-  GList *l;
-
-  g_return_if_fail (GCAL_IS_MONTH_VIEW (view));
-  priv = GCAL_MONTH_VIEW (view)->priv;
-
-  for (i = 0; i < 31; i++)
-    {
-      for (l = priv->days[i]; l != NULL; l = l->next)
-        {
-          GcalViewChild *child;
-          const gchar* widget_uuid;
-
-          child = (GcalViewChild*) l->data;
-          widget_uuid = gcal_event_widget_peek_uuid (GCAL_EVENT_WIDGET (child->widget));
-          if (g_strcmp0 (uuid, widget_uuid) == 0)
-            {
-              icaltimetype *date;
-
-              date =
-                gcal_event_widget_get_date (GCAL_EVENT_WIDGET (child->widget));
-
-              if (gcal_month_view_draw_event (view, date, NULL))
-                {
-                  if (date->day - 1 == i)
-                    {
-                      priv->days[date->day - 1] =
-                        g_list_sort (priv->days[date->day - 1],
-                                     gcal_compare_event_widget_by_date);
-                    }
-                  else
-                    {
-                      priv->days[i] = g_list_remove (priv->days[i], child);
-
-                      child->hidden = TRUE;
-                      priv->days[date->day - 1] =
-                        g_list_insert_sorted (priv->days[date->day - 1],
-                                              child,
-                                              gcal_compare_event_widget_by_date);
-                    }
-
-                  gtk_widget_queue_resize (GTK_WIDGET (view));
-                }
-              else
-                {
-                  gtk_widget_destroy (gcal_month_view_get_by_uuid (view, uuid));
-                }
-
-              g_free (date);
-              return;
-            }
-        }
-    }
-}
-
-static void
 gcal_month_view_clear_selection (GcalView *view)
 {
   GcalMonthViewPrivate *priv;
diff --git a/src/gcal-view.c b/src/gcal-view.c
index 664481e..1e7b66b 100644
--- a/src/gcal-view.c
+++ b/src/gcal-view.c
@@ -116,16 +116,6 @@ gcal_view_get_date (GcalView *view)
 }
 
 void
-gcal_view_reposition_child (GcalView    *view,
-                            const gchar *uuid)
-{
-  g_return_if_fail (GCAL_IS_VIEW (view));
-  g_return_if_fail (GCAL_VIEW_GET_INTERFACE (view)->reposition_child);
-
-  GCAL_VIEW_GET_INTERFACE (view)->reposition_child (view, uuid);
-}
-
-void
 gcal_view_clear_selection (GcalView *view)
 {
   g_return_if_fail (GCAL_IS_VIEW (view));
@@ -273,9 +263,10 @@ gcal_view_draw_event (GcalView     *view,
  * @uuid: the uuid of the event-widget
  *
  * The uuid is formed by source-uid:event-uid, and the widget with
- * this uuid is fetched by this method
+ * this uuid is fetched by this method. If there's no widget with this
+ * uuid in the view %NULL is returned.
  *
- * Returns: a #GcalEventWidget as #GtkWidget
+ * Returns: a #GcalEventWidget as #GtkWidget, %NULL otherwise
  **/
 GtkWidget*
 gcal_view_get_by_uuid (GcalView    *view,
diff --git a/src/gcal-view.h b/src/gcal-view.h
index 3dc72a0..a78b9c9 100644
--- a/src/gcal-view.h
+++ b/src/gcal-view.h
@@ -51,8 +51,6 @@ struct _GcalViewIface
   void            (*create_event)                       (GcalView *view, icaltimetype *start_span, 
icaltimetype *end_span, gdouble x, gdouble y);
   void            (*updated)                            (GcalView *view, icaltimetype *date);
 
-  void            (*reposition_child)                   (GcalView *view, const gchar *uuid);
-
 /* FIXME remove me in favor of the one below */
   void            (*clear_selection)                    (GcalView *view);
 
@@ -85,9 +83,6 @@ void          gcal_view_set_date                      (GcalView     *view,
 
 icaltimetype* gcal_view_get_date                      (GcalView     *view);
 
-void          gcal_view_reposition_child              (GcalView     *view,
-                                                      const gchar  *uuid);
-
 /* FIXME remove me in favor of the one below */
 void          gcal_view_clear_selection               (GcalView     *view);
 
diff --git a/src/gcal-window.c b/src/gcal-window.c
index beebec3..b14cf73 100644
--- a/src/gcal-window.c
+++ b/src/gcal-window.c
@@ -779,6 +779,8 @@ gcal_window_events_modified (GcalManager *manager,
   gchar *event_uid;
 
   GtkWidget *widget;
+  icaltimetype *start_date;
+  icaltimetype *end_date;
 
   priv = GCAL_WINDOW (user_data)->priv;
 
@@ -796,16 +798,41 @@ gcal_window_events_modified (GcalManager *manager,
 
       for (i = 0; i < 5; i++)
         {
-          if (priv->views[i] != NULL)
-            {
-              widget = gcal_view_get_by_uuid (GCAL_VIEW (priv->views[i]),
-                                              (gchar*) l->data);
-              gcal_window_update_event_widget (manager,
-                                               source_uid,
-                                               event_uid,
-                                               GCAL_EVENT_WIDGET (widget));
-              gcal_view_reposition_child (GCAL_VIEW (priv->views[i]),
+          if (priv->views[i] == NULL)
+            continue;
+
+          widget = gcal_view_get_by_uuid (GCAL_VIEW (priv->views[i]),
                                           (gchar*) l->data);
+
+          if (widget != NULL)
+            {
+              start_date = gcal_manager_get_event_start_date (manager,
+                                                              source_uid,
+                                                              event_uid);
+              end_date = gcal_manager_get_event_end_date (manager,
+                                                          source_uid,
+                                                          event_uid);
+
+              if (gcal_view_draw_event (priv->views[i], start_date, end_date))
+                {
+                  gcal_window_update_event_widget (manager,
+                                                   source_uid,
+                                                   event_uid,
+                                                   GCAL_EVENT_WIDGET (widget));
+                  g_object_ref (widget);
+                  gtk_container_remove (GTK_CONTAINER (priv->views[i]),
+                                        widget);
+                  gtk_container_add (GTK_CONTAINER (priv->views[i]),
+                                     widget);
+                  g_object_unref (widget);
+                }
+              else
+                {
+                  gtk_widget_destroy (widget);
+                }
+
+              g_free (start_date);
+              g_free (end_date);
             }
         }
 
diff --git a/src/gcal-year-view.c b/src/gcal-year-view.c
index 31e59b3..ffecda2 100644
--- a/src/gcal-year-view.c
+++ b/src/gcal-year-view.c
@@ -127,9 +127,6 @@ static GtkWidget*     gcal_year_view_get_by_uuid                  (GcalView
                                                                    const gchar    *uuid);
 
 /* Review API */
-static void           gcal_year_view_reposition_child             (GcalView       *view,
-                                                                   const gchar    *uuid);
-
 static void           gcal_year_view_clear_selection              (GcalView       *view);
 
 static void           gcal_year_view_create_event_on_current_unit (GcalView       *view);
@@ -149,7 +146,7 @@ gcal_year_view_class_init (GcalYearViewClass *klass)
   GObjectClass *object_class;
 
   container_class = GTK_CONTAINER_CLASS (klass);
-  container_class->add   = gcal_year_view_add;
+  container_class->add = gcal_year_view_add;
   container_class->remove = gcal_year_view_remove;
   container_class->forall = gcal_year_view_forall;
 
@@ -207,7 +204,6 @@ gcal_year_view_init (GcalYearView *self)
 static void
 gcal_view_interface_init (GcalViewIface *iface)
 {
-  iface->reposition_child = gcal_year_view_reposition_child;
   iface->clear_selection = gcal_year_view_clear_selection;
   iface->create_event_on_current_unit = gcal_year_view_create_event_on_current_unit;
 
@@ -1067,66 +1063,6 @@ gcal_year_view_get_by_uuid (GcalView    *view,
 }
 
 static void
-gcal_year_view_reposition_child (GcalView    *view,
-                                 const gchar *uuid)
-{
-  GcalYearViewPrivate *priv;
-  gint i;
-  GList *l;
-
-  g_return_if_fail (GCAL_IS_YEAR_VIEW (view));
-  priv = GCAL_YEAR_VIEW (view)->priv;
-
-  for (i = 0; i < 12; i++)
-    {
-      for (l = priv->months[i]; l != NULL; l = l->next)
-        {
-          GcalViewChild *child;
-          const gchar* widget_uuid;
-
-          child = (GcalViewChild*) l->data;
-          widget_uuid = gcal_event_widget_peek_uuid (GCAL_EVENT_WIDGET (child->widget));
-          if (g_strcmp0 (uuid, widget_uuid) == 0)
-            {
-              icaltimetype *date;
-
-              date =
-                gcal_event_widget_get_date (GCAL_EVENT_WIDGET (child->widget));
-
-              if (gcal_year_view_draw_event (view, date, NULL))
-                {
-                  if (date->month - 1 == i)
-                    {
-                      priv->months[i] =
-                        g_list_sort (priv->months[i],
-                                     gcal_compare_event_widget_by_date);
-                    }
-                  else
-                    {
-                      priv->months[i] = g_list_remove (priv->months[i], child);
-
-                      child->hidden = TRUE;
-                      priv->months[date->month - 1] =
-                        g_list_insert_sorted (priv->months[date->month - 1],
-                                              child,
-                                              gcal_compare_event_widget_by_date);
-                    }
-
-                  gtk_widget_queue_resize (GTK_WIDGET (view));
-                }
-              else
-                {
-                  gtk_widget_destroy (gcal_year_view_get_by_uuid (view, uuid));
-                }
-
-              g_free (date);
-              return;
-            }
-        }
-    }
-}
-
-static void
 gcal_year_view_clear_selection (GcalView *view)
 {
   GcalYearViewPrivate *priv;


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