[gnome-calendar] gcal-view: reworked a little more the API



commit c22792e65e70091a0d894e7b1e68e239facb6efb
Author: Erick Pérez Castellanos <erick red gmail com>
Date:   Thu Jun 6 11:51:10 2013 -0400

    gcal-view: reworked a little more the API
    
    Added API to get the headers for update GcalNavBar
    Updated GcalMonthView, GcalWeekView and GcalYearView implementations
    Updated calls in GcalWindow

 src/gcal-month-view.c |   14 +++---
 src/gcal-view.c       |  134 ++++++++++++++++++++++++++++++++++---------------
 src/gcal-view.h       |   46 ++++++++---------
 src/gcal-week-view.c  |   12 ++--
 src/gcal-window.c     |    4 +-
 src/gcal-year-view.c  |   14 +++---
 6 files changed, 136 insertions(+), 88 deletions(-)
---
diff --git a/src/gcal-month-view.c b/src/gcal-month-view.c
index a7aa878..bdee211 100644
--- a/src/gcal-month-view.c
+++ b/src/gcal-month-view.c
@@ -117,7 +117,7 @@ static icaltimetype*  gcal_month_view_get_initial_date      (GcalView       *vie
 
 static icaltimetype*  gcal_month_view_get_final_date        (GcalView       *view);
 
-static gboolean       gcal_month_view_contains              (GcalView       *view,
+static gboolean       gcal_month_view_contains_date         (GcalView       *view,
                                                              icaltimetype   *date);
 
 static void           gcal_month_view_remove_by_uuid        (GcalView       *view,
@@ -209,7 +209,7 @@ gcal_view_interface_init (GcalViewIface *iface)
   iface->get_initial_date = gcal_month_view_get_initial_date;
   iface->get_final_date = gcal_month_view_get_final_date;
 
-  iface->contains = gcal_month_view_contains;
+  iface->contains_date = gcal_month_view_contains_date;
   iface->remove_by_uuid = gcal_month_view_remove_by_uuid;
   iface->get_by_uuid = gcal_month_view_get_by_uuid;
   iface->reposition_child = gcal_month_view_reposition_child;
@@ -1092,7 +1092,7 @@ gcal_month_view_set_date (GcalMonthView *view,
   will_resize = FALSE;
 
   /* if span_updated: queue_resize */
-  will_resize = ! gcal_view_contains (GCAL_VIEW (view), date);
+  will_resize = ! gcal_month_view_contains_date (GCAL_VIEW (view), date);
 
   if (priv->date != NULL)
     g_free (priv->date);
@@ -1118,7 +1118,7 @@ gcal_month_view_set_date (GcalMonthView *view,
               child = (GcalViewChild*) l->data;
               child_date =
                 gcal_event_widget_get_date (GCAL_EVENT_WIDGET (child->widget));
-              if (! gcal_view_contains (GCAL_VIEW (view), child_date))
+              if (! gcal_month_view_contains_date (GCAL_VIEW (view), child_date))
                 to_remove = g_list_append (to_remove, child->widget);
             }
         }
@@ -1206,8 +1206,8 @@ gcal_month_view_get_final_date (GcalView *view)
 }
 
 static gboolean
-gcal_month_view_contains (GcalView     *view,
-                          icaltimetype *date)
+gcal_month_view_contains_date (GcalView     *view,
+                               icaltimetype *date)
 {
   GcalMonthViewPrivate *priv;
 
@@ -1304,7 +1304,7 @@ gcal_month_view_reposition_child (GcalView    *view,
               date =
                 gcal_event_widget_get_date (GCAL_EVENT_WIDGET (child->widget));
 
-              if (gcal_month_view_contains (view, date))
+              if (gcal_month_view_contains_date (view, date))
                 {
                   if (date->day - 1 == i)
                     {
diff --git a/src/gcal-view.c b/src/gcal-view.c
index 58855aa..20f760a 100644
--- a/src/gcal-view.c
+++ b/src/gcal-view.c
@@ -115,34 +115,6 @@ gcal_view_get_date (GcalView *view)
   return date;
 }
 
-icaltimetype*
-gcal_view_get_initial_date (GcalView *view)
-{
-  g_return_val_if_fail (GCAL_IS_VIEW (view), NULL);
-  g_return_if_fail (GCAL_VIEW_GET_INTERFACE (view)->get_initial_date);
-
-  return GCAL_VIEW_GET_INTERFACE (view)->get_initial_date (view);
-}
-
-icaltimetype*
-gcal_view_get_final_date (GcalView *view)
-{
-  g_return_val_if_fail (GCAL_IS_VIEW (view), NULL);
-  g_return_if_fail (GCAL_VIEW_GET_INTERFACE (view)->get_final_date);
-
-  return GCAL_VIEW_GET_INTERFACE (view)->get_final_date (view);
-}
-
-gboolean
-gcal_view_contains (GcalView     *view,
-                       icaltimetype *date)
-{
-  g_return_val_if_fail (GCAL_IS_VIEW (view), FALSE);
-  g_return_if_fail (GCAL_VIEW_GET_INTERFACE (view)->contains);
-
-  return GCAL_VIEW_GET_INTERFACE (view)->contains (view, date);
-}
-
 void
 gcal_view_remove_by_uuid (GcalView    *view,
                           const gchar *uuid)
@@ -191,6 +163,66 @@ gcal_view_create_event_on_current_unit (GcalView *view)
   GCAL_VIEW_GET_INTERFACE (view)->create_event_on_current_unit (view);
 }
 
+/* New API */
+/**
+ * gcal_view_get_initial_date:
+ * @view: a #GcalView
+ *
+ * Return the initial date represented by the view.
+ *
+ * Returns: (transfer full): An #icaltimetype object
+ **/
+icaltimetype*
+gcal_view_get_initial_date (GcalView *view)
+{
+  g_return_val_if_fail (GCAL_IS_VIEW (view), NULL);
+  g_return_if_fail (GCAL_VIEW_GET_INTERFACE (view)->get_initial_date);
+
+  return GCAL_VIEW_GET_INTERFACE (view)->get_initial_date (view);
+}
+
+/**
+ * gcal_view_get_final_date:
+ * @view: a #GcalView
+ *
+ * Return the final date represented by the view.
+ *
+ * Returns: (transfer full): An #icaltimetype object
+ **/
+icaltimetype*
+gcal_view_get_final_date (GcalView *view)
+{
+  g_return_val_if_fail (GCAL_IS_VIEW (view), NULL);
+  g_return_if_fail (GCAL_VIEW_GET_INTERFACE (view)->get_final_date);
+
+  return GCAL_VIEW_GET_INTERFACE (view)->get_final_date (view);
+}
+
+/**
+ * gcal_view_contains_date:
+ * @view: a #GcalView
+ * @date: an #icaltimetype object
+ *
+ * Whether @date is contained in the time-range represented by @view
+ *
+ * Returns: %TRUE if it is, %FALSE otherwise
+ **/
+gboolean
+gcal_view_contains_date (GcalView     *view,
+                         icaltimetype *date)
+{
+  g_return_val_if_fail (GCAL_IS_VIEW (view), FALSE);
+  g_return_if_fail (GCAL_VIEW_GET_INTERFACE (view)->contains_date);
+
+  return GCAL_VIEW_GET_INTERFACE (view)->contains_date (view, date);
+}
+
+/**
+ * gcal_view_mark_current_unit:
+ * @view: a #GcalView
+ *
+ * Mark the current unit in the view as marked for event creation
+ **/
 void
 gcal_view_mark_current_unit (GcalView *view)
 {
@@ -200,6 +232,12 @@ gcal_view_mark_current_unit (GcalView *view)
   GCAL_VIEW_GET_INTERFACE (view)->mark_current_unit (view);
 }
 
+/**
+ * gcal_view_clear_mark:
+ * @view: a #GcalView
+ *
+ * Clear any marking the view had drawn
+ **/
 void
 gcal_view_clear_mark (GcalView *view)
 {
@@ -209,22 +247,38 @@ gcal_view_clear_mark (GcalView *view)
   GCAL_VIEW_GET_INTERFACE (view)->clear_mark (view);
 }
 
-void
-gcal_view_move_back (GcalView *view,
-                     gint      steps)
+/**
+ * gcal_view_get_left_header:
+ * @view: a #GcalView
+ *
+ * Returns the string representing for the left header of the unit.
+ * e.g.: for #GcalMonthView returns the month name
+ *
+ * Returns: (transfer full): a string.
+ **/
+gchar*
+gcal_view_get_left_header (GcalView *view)
 {
-  g_return_if_fail (GCAL_IS_VIEW (view));
-  g_return_if_fail (GCAL_VIEW_GET_INTERFACE (view)->move_back);
+  g_return_val_if_fail (GCAL_IS_VIEW (view), NULL);
+  g_return_val_if_fail (GCAL_VIEW_GET_INTERFACE (view)->get_left_header, NULL);
 
-  GCAL_VIEW_GET_INTERFACE (view)->move_back (view, steps);
+  return GCAL_VIEW_GET_INTERFACE (view)->get_left_header (view);
 }
 
-void
-gcal_view_move_forward (GcalView *view,
-                        gint      steps)
+/**
+ * gcal_view_get_right_header:
+ * @view: a #GcalView
+ *
+ * Returns the string representing for the right header of the unit.
+ * e.g.: for #GcalMonthView returns the year
+ *
+ * Returns: (transfer full): a string.
+ **/
+gchar*
+gcal_view_get_right_header (GcalView *view)
 {
-  g_return_if_fail (GCAL_IS_VIEW (view));
-  g_return_if_fail (GCAL_VIEW_GET_INTERFACE (view)->move_forward);
+  g_return_val_if_fail (GCAL_IS_VIEW (view), NULL);
+  g_return_val_if_fail (GCAL_VIEW_GET_INTERFACE (view)->get_right_header, NULL);
 
-  GCAL_VIEW_GET_INTERFACE (view)->move_forward (view, steps);
+  return GCAL_VIEW_GET_INTERFACE (view)->get_right_header (view);
 }
diff --git a/src/gcal-view.h b/src/gcal-view.h
index b88c969..871522b 100644
--- a/src/gcal-view.h
+++ b/src/gcal-view.h
@@ -51,11 +51,7 @@ struct _GcalViewIface
   void            (*create_event)                       (GcalView *view, icaltimetype *start_span, 
icaltimetype *end_span, gdouble x, gdouble y);
   void            (*updated)                            (GcalView *view, icaltimetype *date);
 
-  /* pure virtual methods */
-  icaltimetype*   (*get_initial_date)                   (GcalView *view);
-  icaltimetype*   (*get_final_date)                     (GcalView *view);
-
-  gboolean        (*contains)                           (GcalView *view, icaltimetype *date);
+  /* Container functions related API */
   void            (*remove_by_uuid)                     (GcalView *view, const gchar *uuid);
   GtkWidget*      (*get_by_uuid)                        (GcalView *view, const gchar *uuid);
   void            (*reposition_child)                   (GcalView *view, const gchar *uuid);
@@ -66,17 +62,19 @@ struct _GcalViewIface
 /* FIXME remove me in favor of the one below */
   void            (*create_event_on_current_unit)       (GcalView *view);
 
-/* New API */
-  /* Marks related API */
-  void       (*mark_current_unit)             (GcalView     *view);
-  void       (*clear_mark)                    (GcalView     *view);
+  /* New API */
+  /* Time handling related API */
+  icaltimetype*   (*get_initial_date)                   (GcalView *view);
+  icaltimetype*   (*get_final_date)                     (GcalView *view);
+  gboolean        (*contains_date)                      (GcalView *view, icaltimetype *date);
 
-  /* Navigation related API */
-  void       (*move_back)                     (GcalView     *view,
-                                              gint          steps);
-  void       (*move_forward)                  (GcalView     *view,
-                                              gint          steps);
+  /* Marks related API */
+  void            (*mark_current_unit)                  (GcalView     *view);
+  void            (*clear_mark)                         (GcalView     *view);
 
+  /* Update NavBar headings */
+  gchar*          (*get_left_header)                    (GcalView     *view);
+  gchar*          (*get_right_header)                   (GcalView     *view);
 };
 
 GType         gcal_view_get_type                      (void);
@@ -87,13 +85,6 @@ void          gcal_view_set_date                      (GcalView     *view,
 
 icaltimetype* gcal_view_get_date                      (GcalView     *view);
 
-icaltimetype* gcal_view_get_initial_date              (GcalView     *view);
-
-icaltimetype* gcal_view_get_final_date                (GcalView     *view);
-
-gboolean      gcal_view_contains                      (GcalView     *view,
-                                                      icaltimetype *date);
-
 void          gcal_view_remove_by_uuid                (GcalView     *view,
                                                       const gchar  *uuid);
 
@@ -110,15 +101,20 @@ void          gcal_view_clear_selection               (GcalView     *view);
 void          gcal_view_create_event_on_current_unit  (GcalView     *view);
 
 /* New API */
+icaltimetype* gcal_view_get_initial_date              (GcalView     *view);
+
+icaltimetype* gcal_view_get_final_date                (GcalView     *view);
+
+gboolean      gcal_view_contains_date                 (GcalView     *view,
+                                                      icaltimetype *date);
+
 void          gcal_view_mark_current_unit             (GcalView     *view);
 
 void          gcal_view_clear_mark                    (GcalView     *view);
 
-void          gcal_view_move_back                     (GcalView     *view,
-                                                      gint          steps);
+gchar*        gcal_view_get_left_header               (GcalView     *view);
 
-void          gcal_view_move_forward                  (GcalView     *view,
-                                                      gint          steps);
+gchar*        gcal_view_get_right_header              (GcalView     *view);
 
 G_END_DECLS
 
diff --git a/src/gcal-week-view.c b/src/gcal-week-view.c
index 075200a..e388bc6 100644
--- a/src/gcal-week-view.c
+++ b/src/gcal-week-view.c
@@ -149,7 +149,7 @@ static icaltimetype*  gcal_week_view_get_initial_date      (GcalView       *view
 
 static icaltimetype*  gcal_week_view_get_final_date        (GcalView       *view);
 
-static gboolean       gcal_week_view_contains              (GcalView       *view,
+static gboolean       gcal_week_view_contains_date         (GcalView       *view,
                                                             icaltimetype   *date);
 
 static void           gcal_week_view_remove_by_uuid        (GcalView       *view,
@@ -237,7 +237,7 @@ gcal_view_interface_init (GcalViewIface *iface)
   iface->get_initial_date = gcal_week_view_get_initial_date;
   iface->get_final_date = gcal_week_view_get_final_date;
 
-  iface->contains = gcal_week_view_contains;
+  iface->contains_date = gcal_week_view_contains_date;
   iface->remove_by_uuid = gcal_week_view_remove_by_uuid;
   iface->get_by_uuid = gcal_week_view_get_by_uuid;
 }
@@ -979,7 +979,7 @@ gcal_week_view_set_date (GcalWeekView *view,
   will_resize = FALSE;
 
   /* if span_updated: queue_resize */
-  will_resize = ! gcal_view_contains (GCAL_VIEW (view), date);
+  will_resize = ! gcal_week_view_contains_date (GCAL_VIEW (view), date);
 
   if (priv->date != NULL)
     g_free (priv->date);
@@ -999,7 +999,7 @@ gcal_week_view_set_date (GcalWeekView *view,
 
               child = (GcalWeekViewChild*) l->data;
               child_date = gcal_event_widget_get_date (GCAL_EVENT_WIDGET (child->widget));
-              if (! gcal_view_contains (GCAL_VIEW (view), child_date))
+              if (! gcal_week_view_contains_date (GCAL_VIEW (view), child_date))
                 to_remove = g_list_append (to_remove, child->widget);
             }
         }
@@ -1502,8 +1502,8 @@ gcal_week_view_get_final_date (GcalView *view)
 }
 
 static gboolean
-gcal_week_view_contains (GcalView     *view,
-                         icaltimetype *date)
+gcal_week_view_contains_date (GcalView     *view,
+                              icaltimetype *date)
 {
   GcalWeekViewPrivate *priv;
 
diff --git a/src/gcal-window.c b/src/gcal-window.c
index 21ced28..e0ade5c 100644
--- a/src/gcal-window.c
+++ b/src/gcal-window.c
@@ -626,8 +626,6 @@ gcal_window_set_active_view (GcalWindow         *window,
 
   g_object_notify (G_OBJECT (window), "active-view");
 
-  update_range = ! gcal_view_contains (GCAL_VIEW (priv->views[priv->active_view]),
-                                       priv->active_date);
 
   gcal_view_set_date (GCAL_VIEW (priv->views[priv->active_view]),
                       priv->active_date);
@@ -799,7 +797,7 @@ gcal_window_events_added (GcalManager *manager,
       starting_date = gcal_manager_get_event_start_date (manager,
                                                          source_uid,
                                                          event_uid);
-      if (gcal_view_contains (
+      if (gcal_view_contains_date (
             GCAL_VIEW (priv->views[priv->active_view]),
             starting_date) &&
           gcal_view_get_by_uuid (
diff --git a/src/gcal-year-view.c b/src/gcal-year-view.c
index 323e2c5..93af545 100644
--- a/src/gcal-year-view.c
+++ b/src/gcal-year-view.c
@@ -115,7 +115,7 @@ static icaltimetype*  gcal_year_view_get_initial_date             (GcalView
 
 static icaltimetype*  gcal_year_view_get_final_date               (GcalView       *view);
 
-static gboolean       gcal_year_view_contains                     (GcalView       *view,
+static gboolean       gcal_year_view_contains_date                (GcalView       *view,
                                                                    icaltimetype   *date);
 
 static void           gcal_year_view_remove_by_uuid               (GcalView       *view,
@@ -207,7 +207,7 @@ gcal_view_interface_init (GcalViewIface *iface)
   iface->get_initial_date = gcal_year_view_get_initial_date;
   iface->get_final_date = gcal_year_view_get_final_date;
 
-  iface->contains = gcal_year_view_contains;
+  iface->contains_date = gcal_year_view_contains_date;
   iface->remove_by_uuid = gcal_year_view_remove_by_uuid;
   iface->get_by_uuid = gcal_year_view_get_by_uuid;
   iface->reposition_child = gcal_year_view_reposition_child;
@@ -754,7 +754,7 @@ gcal_year_view_set_date (GcalYearView *view,
   will_resize = FALSE;
 
   /* if span_updated: queue_resize */
-  will_resize = ! gcal_view_contains (GCAL_VIEW (view), date);
+  will_resize = ! gcal_year_view_contains_date (GCAL_VIEW (view), date);
 
   if (priv->date != NULL)
     g_free (priv->date);
@@ -775,7 +775,7 @@ gcal_year_view_set_date (GcalYearView *view,
               child = (GcalViewChild*) l->data;
               child_date =
                 gcal_event_widget_get_date (GCAL_EVENT_WIDGET (child->widget));
-              if (! gcal_view_contains (GCAL_VIEW (view), child_date))
+              if (! gcal_year_view_contains_date (GCAL_VIEW (view), child_date))
                 to_remove = g_list_append (to_remove, child->widget);
             }
         }
@@ -1019,8 +1019,8 @@ gcal_year_view_get_final_date (GcalView *view)
 }
 
 static gboolean
-gcal_year_view_contains (GcalView     *view,
-                         icaltimetype *date)
+gcal_year_view_contains_date (GcalView     *view,
+                              icaltimetype *date)
 {
   GcalYearViewPrivate *priv;
 
@@ -1116,7 +1116,7 @@ gcal_year_view_reposition_child (GcalView    *view,
               date =
                 gcal_event_widget_get_date (GCAL_EVENT_WIDGET (child->widget));
 
-              if (gcal_year_view_contains (view, date))
+              if (gcal_year_view_contains_date (view, date))
                 {
                   if (date->month - 1 == i)
                     {


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