[gnome-calendar] app: move view subscription to GcalWindow



commit fa2f300362693392ecd1ca150e86d6895351ee5c
Author: Erick Pérez Castellanos <erick red gmail com>
Date:   Tue Jan 27 22:37:44 2015 -0500

    app: move view subscription to GcalWindow
    
    Initialize :manager property first and :active-date later. Allocate
    ::active_date instance on instance init vfunc.

 src/gcal-month-view.c |   32 -------------
 src/gcal-month-view.h |    2 -
 src/gcal-window.c     |  120 +++++++++++++++++++++++++++++++++++++------------
 src/gcal-year-view.c  |   30 +-----------
 4 files changed, 93 insertions(+), 91 deletions(-)
---
diff --git a/src/gcal-month-view.c b/src/gcal-month-view.c
index 5abd128..5a919c9 100644
--- a/src/gcal-month-view.c
+++ b/src/gcal-month-view.c
@@ -75,7 +75,6 @@ typedef struct
 
   /* property */
   icaltimetype   *date;
-  GcalManager    *manager; /* weak reference */
 } GcalMonthViewPrivate;
 
 enum
@@ -639,32 +638,10 @@ gcal_month_view_set_property (GObject       *object,
     {
     case PROP_DATE:
       {
-        time_t range_start, range_end;
-        icaltimetype *date;
-        icaltimezone* default_zone;
-
         if (priv->date != NULL)
           g_free (priv->date);
 
         priv->date = g_value_dup_boxed (value);
-
-        date = gcal_view_get_initial_date (GCAL_VIEW (object));
-        priv->days_delay = (icaltime_day_of_week (*date) - priv->first_weekday + 6) % 7;
-
-        default_zone =
-          gcal_manager_get_system_timezone (priv->manager);
-        range_start = icaltime_as_timet_with_zone (*date,
-                                                   default_zone);
-        g_free (date);
-        date = gcal_view_get_final_date (GCAL_VIEW (object));
-        range_end = icaltime_as_timet_with_zone (*date,
-                                                 default_zone);
-        g_free (date);
-
-        gcal_manager_set_subscriber (priv->manager,
-                                     E_CAL_DATA_MODEL_SUBSCRIBER (object),
-                                     range_start,
-                                     range_end);
         gtk_widget_queue_draw (GTK_WIDGET (object));
         break;
       }
@@ -1729,15 +1706,6 @@ gcal_month_view_new (void)
   return g_object_new (GCAL_TYPE_MONTH_VIEW, NULL);
 }
 
-void
-gcal_month_view_set_manager (GcalMonthView *month_view,
-                             GcalManager   *manager)
-{
-  GcalMonthViewPrivate *priv = gcal_month_view_get_instance_private (month_view);
-
-  priv->manager = manager;
-}
-
 /**
  * gcal_month_view_set_first_weekday:
  * @view: A #GcalMonthView instance
diff --git a/src/gcal-month-view.h b/src/gcal-month-view.h
index 2784415..2903d5f 100644
--- a/src/gcal-month-view.h
+++ b/src/gcal-month-view.h
@@ -47,8 +47,6 @@ struct _GcalMonthViewClass
 
 GType          gcal_month_view_get_type           (void);
 GtkWidget*     gcal_month_view_new                (void);
-void           gcal_month_view_set_manager        (GcalMonthView *month_view,
-                                                   GcalManager   *manager);
 void           gcal_month_view_set_first_weekday  (GcalMonthView *view,
                                                    gint           day_nr);
 void           gcal_month_view_set_use_24h_format (GcalMonthView *view,
diff --git a/src/gcal-window.c b/src/gcal-window.c
index b8c2549..32024ad 100644
--- a/src/gcal-window.c
+++ b/src/gcal-window.c
@@ -112,9 +112,9 @@ enum
 {
   PROP_0,
   PROP_ACTIVE_VIEW,
+  PROP_MANAGER,
   PROP_ACTIVE_DATE,
-  PROP_NEW_EVENT_MODE,
-  PROP_MANAGER
+  PROP_NEW_EVENT_MODE
 };
 
 #define SAVE_GEOMETRY_ID_TIMEOUT 100 /* ms */
@@ -261,11 +261,73 @@ key_pressed (GtkWidget *widget,
 }
 
 static void
+update_active_date (GcalWindow   *window,
+                    icaltimetype *new_date)
+{
+  GcalWindowPrivate *priv;
+
+  time_t range_start, range_end;
+  icaltimetype date;
+  icaltimezone* default_zone;
+
+  priv = gcal_window_get_instance_private (window);
+  default_zone = gcal_manager_get_system_timezone (priv->manager);
+
+  /* year_view */
+  if (priv->active_date->year != new_date->year)
+    {
+      date = *new_date;
+      date.day = 1;
+      date.month = 1;
+      date.hour = 0;
+      date.minute = 0;
+      date.second = 0;
+      date.is_date = 0;
+      range_start = icaltime_as_timet_with_zone (date, default_zone);
+
+      date.day = 31;
+      date.month = 12;
+      date.hour = 23;
+      date.minute = 59;
+      range_end = icaltime_as_timet_with_zone (date, default_zone);
+
+      gcal_manager_set_subscriber (priv->manager,
+                                   E_CAL_DATA_MODEL_SUBSCRIBER (priv->views[GCAL_WINDOW_VIEW_YEAR]),
+                                   range_start, range_end);
+    }
+
+  /* month_view */
+  if (priv->active_date->month != new_date->month || priv->active_date->year != new_date->year)
+    {
+      date = *new_date;
+      date.day = 1;
+      date.hour = 0;
+      date.minute = 0;
+      date.second = 0;
+      date.is_date = 0;
+      range_start = icaltime_as_timet_with_zone (date, default_zone);
+
+      date.day = time_days_in_month (new_date->year, new_date->month - 1);
+      date.hour = 23;
+      date.minute = 59;
+      range_end = icaltime_as_timet_with_zone (date, default_zone);
+
+      gcal_manager_set_subscriber (priv->manager,
+                                   E_CAL_DATA_MODEL_SUBSCRIBER (priv->views[GCAL_WINDOW_VIEW_MONTH]),
+                                   range_start, range_end);
+    }
+
+    g_free (priv->active_date);
+    priv->active_date = new_date;
+}
+
+static void
 date_updated (GtkButton  *button,
               gpointer    user_data)
 {
   GcalWindowPrivate *priv;
 
+  icaltimetype *new_date;
   gboolean move_back, move_today;
 
   priv = gcal_window_get_instance_private (GCAL_WINDOW (user_data));
@@ -273,38 +335,37 @@ date_updated (GtkButton  *button,
   move_today = priv->today_button == (GtkWidget*) button;
   move_back = priv->back_button == (GtkWidget*) button;
 
+  new_date = gcal_dup_icaltime (priv->active_date);
+
+  /* FIXME: use current_date */
   if (move_today)
     {
-      *(priv->active_date) =
-        icaltime_current_time_with_zone (
-            gcal_manager_get_system_timezone (priv->manager));
-      *(priv->active_date) =
-        icaltime_set_timezone (
-            priv->active_date,
-            gcal_manager_get_system_timezone (priv->manager));
+      *new_date = icaltime_current_time_with_zone (gcal_manager_get_system_timezone (priv->manager));
+      *new_date = icaltime_set_timezone (new_date, gcal_manager_get_system_timezone (priv->manager));
     }
   else
     {
       switch (priv->active_view)
         {
         case GCAL_WINDOW_VIEW_DAY:
-          priv->active_date->day += 1 * (move_back ? -1 : 1);
+          new_date->day += 1 * (move_back ? -1 : 1);
           break;
         case GCAL_WINDOW_VIEW_WEEK:
-          priv->active_date->day += 7 * (move_back ? -1 : 1);
+          new_date->day += 7 * (move_back ? -1 : 1);
           break;
         case GCAL_WINDOW_VIEW_MONTH:
-          priv->active_date->month += 1 * (move_back ? -1 : 1);
+          new_date->month += 1 * (move_back ? -1 : 1);
           break;
         case GCAL_WINDOW_VIEW_YEAR:
-          priv->active_date->year += 1 * (move_back ? -1 : 1);
+          new_date->year += 1 * (move_back ? -1 : 1);
           break;
         case GCAL_WINDOW_VIEW_LIST:
         case GCAL_WINDOW_VIEW_SEARCH:
           break;
         }
     }
-  *(priv->active_date) = icaltime_normalize (*(priv->active_date));
+  *new_date = icaltime_normalize (*new_date);
+  update_active_date (user_data, new_date);
   g_object_notify (user_data, "active-date");
 }
 
@@ -1101,6 +1162,15 @@ gcal_window_class_init(GcalWindowClass *klass)
 
   g_object_class_install_property (
       object_class,
+      PROP_MANAGER,
+      g_param_spec_pointer ("manager",
+                            "The manager object",
+                            "A weak reference to the app manager object",
+                            G_PARAM_CONSTRUCT_ONLY |
+                            G_PARAM_READWRITE));
+
+  g_object_class_install_property (
+      object_class,
       PROP_ACTIVE_DATE,
       g_param_spec_boxed ("active-date",
                           "Date",
@@ -1118,15 +1188,6 @@ gcal_window_class_init(GcalWindowClass *klass)
                             FALSE,
                             G_PARAM_READWRITE));
 
-  g_object_class_install_property (
-      object_class,
-      PROP_MANAGER,
-      g_param_spec_pointer ("manager",
-                            "The manager object",
-                            "A weak reference to the app manager object",
-                            G_PARAM_CONSTRUCT_ONLY |
-                            G_PARAM_READWRITE));
-
   /* widgets */
   gtk_widget_class_bind_template_child_private (widget_class, GcalWindow, header_bar);
   gtk_widget_class_bind_template_child_private (widget_class, GcalWindow, main_box);
@@ -1180,6 +1241,10 @@ gcal_window_class_init(GcalWindowClass *klass)
 static void
 gcal_window_init (GcalWindow *self)
 {
+  GcalWindowPrivate *priv = gcal_window_get_instance_private (self);
+
+  priv->active_date = g_new0 (icaltimetype, 1);
+
   gtk_widget_init_template (GTK_WIDGET (self));
 }
 
@@ -1291,8 +1356,7 @@ gcal_window_finalize (GObject *object)
 
   priv = gcal_window_get_instance_private (GCAL_WINDOW (object));
 
-  if (priv->active_date != NULL)
-    g_free (priv->active_date);
+  g_free (priv->active_date);
 
   if (priv->views_switcher != NULL)
     g_object_unref (priv->views_switcher);
@@ -1319,9 +1383,7 @@ gcal_window_set_property (GObject      *object,
                                    priv->views[priv->active_view]);
       return;
     case PROP_ACTIVE_DATE:
-      if (priv->active_date != NULL)
-        g_free (priv->active_date);
-      priv->active_date = g_value_dup_boxed (value);
+      update_active_date (GCAL_WINDOW (object), g_value_dup_boxed (value));
       return;
     case PROP_NEW_EVENT_MODE:
       set_new_event_mode (GCAL_WINDOW (object), g_value_get_boolean (value));
@@ -1427,7 +1489,7 @@ gcal_window_new_with_view_and_date (GcalApplication   *app,
 
   manager = gcal_application_get_manager (GCAL_APPLICATION (app));
 
-  win  =  g_object_new (GCAL_TYPE_WINDOW, "application", GTK_APPLICATION (app), "active-date", date, 
"manager", manager,
+  win  =  g_object_new (GCAL_TYPE_WINDOW, "application", GTK_APPLICATION (app), "manager", manager, 
"active-date", date,
                         NULL);
 
   /* loading size */
diff --git a/src/gcal-year-view.c b/src/gcal-year-view.c
index f85a644..c540ee0 100644
--- a/src/gcal-year-view.c
+++ b/src/gcal-year-view.c
@@ -120,34 +120,8 @@ update_date (GcalYearView *year_view,
 {
   GcalYearViewPrivate *priv = year_view->priv;
 
-  if (priv->date == NULL || priv->date->year != new_date->year)
-    {
-      time_t range_start, range_end;
-      icaltimetype date;
-      icaltimezone* default_zone = gcal_manager_get_system_timezone (priv->manager);
-
-      date = *new_date;
-      date.day = 1;
-      date.month = 1;
-      date.hour = 0;
-      date.minute = 0;
-      date.second = 0;
-      date.is_date = 0;
-      range_start = icaltime_as_timet_with_zone (date, default_zone);
-
-      date.day = 31;
-      date.month = 12;
-      date.hour = 23;
-      date.minute = 59;
-      date.second = 0;
-      range_end = icaltime_as_timet_with_zone (date, default_zone);
-
-      gcal_manager_set_subscriber (priv->manager, E_CAL_DATA_MODEL_SUBSCRIBER (year_view), range_start, 
range_end);
-      gtk_widget_queue_draw (GTK_WIDGET (year_view));
-
-      if (priv->start_selected_date->day != 0)
-        reset_sidebar (year_view);
-    }
+  if (priv->date != NULL && priv->date->year != new_date->year && priv->start_selected_date->day != 0)
+    reset_sidebar (year_view);
 
   if (priv->date != NULL)
     g_free (priv->date);


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