[gnome-calendar/wip/igaldino/flowbox-year-view: 11/13] year-view: Fix showing selected day



commit a670c94a4ca3796fab8f9cc466459870f3195952
Author: Isaque Galdino <igaldino gmail com>
Date:   Fri Feb 10 12:07:14 2017 -0200

    year-view: Fix showing selected day
    
    In the new layout using GcalDateChooser widget, it was showing all
    first day's month selected.
    
    This commit fixes that, implementing a new API in GcalDateChooser widget
    to enable/disable showing the selected day.
    
    Year view was also changed to correctly set the date in the
    GcalDateChooser widget when it's in the same month of the current date.

 src/gcal-date-chooser.c    |   40 +++++++++++++++++++++++++++++++++++++++-
 src/gcal-date-chooser.h    |    5 +++++
 src/views/gcal-year-view.c |   15 +++++++++++++--
 3 files changed, 57 insertions(+), 3 deletions(-)
---
diff --git a/src/gcal-date-chooser.c b/src/gcal-date-chooser.c
index ebf6834..e9b212e 100644
--- a/src/gcal-date-chooser.c
+++ b/src/gcal-date-chooser.c
@@ -51,6 +51,7 @@ struct _GcalDateChooser
   gboolean            show_week_numbers;
   gboolean            no_month_change;
   gboolean            show_month_only;
+  gboolean            show_selected_day;
 
   GcalDateChooserDayOptionsCallback day_options_cb;
   gpointer            day_options_data;
@@ -75,6 +76,7 @@ enum
   PROP_SHOW_WEEK_NUMBERS,
   PROP_NO_MONTH_CHANGE,
   PROP_SHOW_MONTH_ONLY,
+  PROP_SHOW_SELECTED_DAY,
   NUM_PROPERTIES
 };
 
@@ -313,7 +315,10 @@ calendar_update_selected_day_display (GcalDateChooser *self)
       {
         d = GCAL_DATE_CHOOSER_DAY (self->days[row][col]);
         date = gcal_date_chooser_day_get_date (d);
-        gcal_date_chooser_day_set_selected (d, datetime_compare_date (date, self->date) == 0);
+        if (self->show_selected_day)
+          gcal_date_chooser_day_set_selected (d, datetime_compare_date (date, self->date) == 0);
+        else
+          gcal_date_chooser_day_set_selected (d, FALSE);
       }
     }
 }
@@ -382,6 +387,10 @@ calendar_set_property (GObject      *obj,
       gcal_date_chooser_set_show_month_only (self, g_value_get_boolean (value));
       break;
 
+    case PROP_SHOW_SELECTED_DAY:
+      gcal_date_chooser_set_show_selected_day (self, g_value_get_boolean (value));
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, property_id, pspec);
       break;
@@ -422,6 +431,10 @@ calendar_get_property (GObject    *obj,
       g_value_set_boolean (value, self->show_month_only);
       break;
 
+    case PROP_SHOW_SELECTED_DAY:
+      g_value_set_boolean (value, self->show_selected_day);
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, property_id, pspec);
       break;
@@ -556,6 +569,12 @@ gcal_date_chooser_class_init (GcalDateChooserClass *class)
                                                            FALSE,
                                                            G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
 
+  properties[PROP_SHOW_SELECTED_DAY] = g_param_spec_boolean ("show-selected-day",
+                                                           "Show Selected Day",
+                                                           "If TRUE, it will display the selected day",
+                                                           TRUE,
+                                                           G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
+
   g_object_class_install_properties (object_class, NUM_PROPERTIES, properties);
 
   signals[MONTH_CHANGED] = g_signal_new ("month-changed",
@@ -597,6 +616,7 @@ gcal_date_chooser_init (GcalDateChooser *self)
   self->show_week_numbers = TRUE;
   self->no_month_change = FALSE;
   self->show_month_only = FALSE;
+  self->show_selected_day = TRUE;
 
   self->date = g_date_time_new_now_local ();
   g_date_time_get_ymd (self->date, &self->this_year, NULL, NULL);
@@ -803,6 +823,24 @@ gcal_date_chooser_get_show_month_only (GcalDateChooser *self)
 }
 
 void
+gcal_date_chooser_set_show_selected_day (GcalDateChooser *self,
+                                         gboolean         setting)
+{
+  if (self->show_selected_day == setting)
+    return;
+
+  self->show_selected_day = setting;
+
+  g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SHOW_SELECTED_DAY]);
+}
+
+gboolean
+gcal_date_chooser_get_show_selected_day (GcalDateChooser *self)
+{
+  return self->show_selected_day;
+}
+
+void
 gcal_date_chooser_set_date (GcalDateChooser *self,
                             GDateTime       *date)
 {
diff --git a/src/gcal-date-chooser.h b/src/gcal-date-chooser.h
index 0d4e253..dc77cf4 100644
--- a/src/gcal-date-chooser.h
+++ b/src/gcal-date-chooser.h
@@ -77,6 +77,11 @@ gboolean             gcal_date_chooser_get_show_month_only       (GcalDateChoose
 void                 gcal_date_chooser_set_show_month_only       (GcalDateChooser    *self,
                                                                   gboolean            setting);
 
+gboolean             gcal_date_chooser_get_show_selected_day     (GcalDateChooser    *self);
+
+void                 gcal_date_chooser_set_show_selected_day     (GcalDateChooser    *self,
+                                                                  gboolean            setting);
+
 G_END_DECLS
 
 #endif /* __GCAL_DATE_CHOOSER_H__ */
diff --git a/src/views/gcal-year-view.c b/src/views/gcal-year-view.c
index 182f43f..0aeec1d 100644
--- a/src/views/gcal-year-view.c
+++ b/src/views/gcal-year-view.c
@@ -191,13 +191,24 @@ update_date (GcalYearView *year_view,
 
   for (int i = 0; i < 12; i++)
     {
-      date_for_month = g_date_time_new_local (year_view->date->year, i + 1, 1, 0, 0, 0);
       month_box = gtk_flow_box_get_child_at_index (GTK_FLOW_BOX (year_view->flowbox), i);
       if (month_box)
         {
           month = gtk_bin_get_child (GTK_BIN (month_box));
           if (month)
-            gcal_date_chooser_set_date (GCAL_DATE_CHOOSER (month), date_for_month);
+            {
+              if (year_view->date->month == (i + 1))
+                {
+                  date_for_month = g_date_time_new_local (year_view->date->year, year_view->date->month, 
year_view->date->day, 0, 0, 0);
+                  gcal_date_chooser_set_show_selected_day (GCAL_DATE_CHOOSER (month), TRUE);
+                }
+              else
+                {
+                  date_for_month = g_date_time_new_local (year_view->date->year, i + 1, 1, 0, 0, 0);
+                  gcal_date_chooser_set_show_selected_day (GCAL_DATE_CHOOSER (month), FALSE);
+                }
+              gcal_date_chooser_set_date (GCAL_DATE_CHOOSER (month), date_for_month);
+            }
         }
       g_clear_pointer (&date_for_month, g_date_time_unref);
     }


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