[gnome-calendar/wip/igaldino/flowbox-year-view: 24/24] date-chooser: Option to don't show other months



commit 0e2efa043412e77fdcd753bf617561379d424b37
Author: Isaque Galdino <igaldino gmail com>
Date:   Tue Feb 21 22:48:30 2017 -0300

    date-chooser: Option to don't show other months
    
    Currently GcalDateChooser shows current month's days and the last days
    from previous month and first days from the next one with they are on
    the same week the current month start or end.
    
    This is fine we are showing only one month, but if you are showing the
    whole year, e.g. year-view, that is not so nice.
    
    Therefore, this change GcalDateChooser to have an option to hide other
    months' days.

 src/gcal-date-chooser.c    |   39 +++++++++++++++++++++++++++++++++++++++
 src/gcal-date-chooser.h    |    5 +++++
 src/views/gcal-year-view.c |    1 +
 3 files changed, 45 insertions(+), 0 deletions(-)
---
diff --git a/src/gcal-date-chooser.c b/src/gcal-date-chooser.c
index e9b212e..37e37d9 100644
--- a/src/gcal-date-chooser.c
+++ b/src/gcal-date-chooser.c
@@ -52,6 +52,7 @@ struct _GcalDateChooser
   gboolean            no_month_change;
   gboolean            show_month_only;
   gboolean            show_selected_day;
+  gboolean            show_other_months;
 
   GcalDateChooserDayOptionsCallback day_options_cb;
   gpointer            day_options_data;
@@ -77,6 +78,7 @@ enum
   PROP_NO_MONTH_CHANGE,
   PROP_SHOW_MONTH_ONLY,
   PROP_SHOW_SELECTED_DAY,
+  PROP_SHOW_OTHER_MONTHS,
   NUM_PROPERTIES
 };
 
@@ -141,6 +143,8 @@ calendar_compute_days (GcalDateChooser *self)
       date = g_date_time_new_local (other_year, other_month, day, 1, 1, 1);
       gcal_date_chooser_day_set_date (d, date);
       gcal_date_chooser_day_set_other_month (d, TRUE);
+      if (!self->show_other_months)
+        gtk_widget_hide (GTK_WIDGET (d));
       g_date_time_unref (date);
       day++;
     }
@@ -184,6 +188,8 @@ calendar_compute_days (GcalDateChooser *self)
           date = g_date_time_new_local (other_year, other_month, day, 1, 1, 1);
           gcal_date_chooser_day_set_date (d, date);
           gcal_date_chooser_day_set_other_month (d, TRUE);
+          if (!self->show_other_months)
+            gtk_widget_hide (GTK_WIDGET (d));
           g_date_time_unref (date);
           day++;
         }
@@ -391,6 +397,10 @@ calendar_set_property (GObject      *obj,
       gcal_date_chooser_set_show_selected_day (self, g_value_get_boolean (value));
       break;
 
+    case PROP_SHOW_OTHER_MONTHS:
+      gcal_date_chooser_set_show_other_months (self, g_value_get_boolean (value));
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, property_id, pspec);
       break;
@@ -435,6 +445,10 @@ calendar_get_property (GObject    *obj,
       g_value_set_boolean (value, self->show_selected_day);
       break;
 
+    case PROP_SHOW_OTHER_MONTHS:
+      g_value_set_boolean (value, self->show_other_months);
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, property_id, pspec);
       break;
@@ -575,6 +589,12 @@ gcal_date_chooser_class_init (GcalDateChooserClass *class)
                                                            TRUE,
                                                            G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
 
+  properties[PROP_SHOW_OTHER_MONTHS] = g_param_spec_boolean ("show-other-months",
+                                                             "Show Other Months' days",
+                                                             "If TRUE, it will display other months' days",
+                                                             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",
@@ -617,6 +637,7 @@ gcal_date_chooser_init (GcalDateChooser *self)
   self->no_month_change = FALSE;
   self->show_month_only = FALSE;
   self->show_selected_day = TRUE;
+  self->show_other_months = TRUE;
 
   self->date = g_date_time_new_now_local ();
   g_date_time_get_ymd (self->date, &self->this_year, NULL, NULL);
@@ -841,6 +862,24 @@ gcal_date_chooser_get_show_selected_day (GcalDateChooser *self)
 }
 
 void
+gcal_date_chooser_set_show_other_months (GcalDateChooser *self,
+                                         gboolean         setting)
+{
+  if (self->show_other_months == setting)
+    return;
+
+  self->show_other_months = setting;
+
+  g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SHOW_OTHER_MONTHS]);
+}
+
+gboolean
+gcal_date_chooser_get_show_other_months (GcalDateChooser *self)
+{
+  return self->show_other_months;
+}
+
+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 dc77cf4..415e729 100644
--- a/src/gcal-date-chooser.h
+++ b/src/gcal-date-chooser.h
@@ -82,6 +82,11 @@ gboolean             gcal_date_chooser_get_show_selected_day     (GcalDateChoose
 void                 gcal_date_chooser_set_show_selected_day     (GcalDateChooser    *self,
                                                                   gboolean            setting);
 
+gboolean             gcal_date_chooser_get_show_other_months     (GcalDateChooser    *self);
+
+void                 gcal_date_chooser_set_show_other_months     (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 0aeec1d..7c2a597 100644
--- a/src/views/gcal-year-view.c
+++ b/src/views/gcal-year-view.c
@@ -1974,6 +1974,7 @@ gcal_year_view_init (GcalYearView *self)
       gtk_widget_set_visible (month, TRUE);
       gcal_date_chooser_set_show_month_only (GCAL_DATE_CHOOSER (month), TRUE);
       gcal_date_chooser_set_show_day_names (GCAL_DATE_CHOOSER (month), FALSE);
+      gcal_date_chooser_set_show_other_months (GCAL_DATE_CHOOSER (month), FALSE);
 
       gtk_container_add (GTK_CONTAINER (self->flowbox), month);
     }


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