[gnome-control-center/gbsneto/fix-datetime-dialog: 1/3] datetime: Switch Month row to AdwComboRow




commit 65c53a4c578bcf93f877e46e30c7f7f13e0127f3
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Wed Jan 26 23:43:43 2022 -0300

    datetime: Switch Month row to AdwComboRow
    
    It fits it much better, and allows for a great cleanup.

 panels/datetime/cc-datetime-panel.c  |  56 ++++---------
 panels/datetime/cc-datetime-panel.ui | 154 +++++------------------------------
 2 files changed, 38 insertions(+), 172 deletions(-)
---
diff --git a/panels/datetime/cc-datetime-panel.c b/panels/datetime/cc-datetime-panel.c
index 7e1088533..65f5b8601 100644
--- a/panels/datetime/cc-datetime-panel.c
+++ b/panels/datetime/cc-datetime-panel.c
@@ -96,13 +96,10 @@ struct _CcDateTimePanel
   GtkWidget *timeformat_row;
   GtkWidget *h_spinbutton;
   GtkLockButton *lock_button;
-  GtkLabel  *month_label;
   GtkListBox *date_box;
   GtkListBoxRow *day_row;
-  GtkListBoxRow *month_row;
+  AdwComboRow *month_row;
   GtkListBoxRow *year_row;
-  GtkPopover *month_popover;
-  GtkFlowBox *month_flowbox;
   GtkWidget *network_time_switch;
   GtkWidget *time_editor;
   GtkWidget *timezone_button;
@@ -233,7 +230,6 @@ static void
 update_time (CcDateTimePanel *self)
 {
   g_autofree gchar *label = NULL;
-  GtkWidget *month_label;
   gboolean use_ampm;
 
   if (self->clock_format == G_DESKTOP_CLOCK_FORMAT_12H)
@@ -258,8 +254,7 @@ update_time (CcDateTimePanel *self)
     }
 
   self->month = g_date_time_get_month (self->date);
-  month_label = gtk_flow_box_get_child_at_index (self->month_flowbox, self->month - 1);
-  gtk_label_set_text (self->month_label, gtk_label_get_text (GTK_LABEL (month_label)));
+  adw_combo_row_set_selected (self->month_row, self->month - 1);
   gtk_label_set_text (GTK_LABEL (self->datetime_label), label);
 }
 
@@ -386,17 +381,6 @@ change_date (CcDateTimePanel *self)
   queue_set_datetime (self);
 }
 
-static void
-date_box_row_activated_cb (CcDateTimePanel *self,
-                           GtkListBoxRow   *row)
-{
-  g_assert (CC_IS_DATE_TIME_PANEL (self));
-  g_assert (GTK_IS_LIST_BOX_ROW (row));
-
-  if (row == self->month_row)
-    gtk_popover_popup (self->month_popover);
-}
-
 static gboolean
 city_changed_cb (CcDateTimePanel    *self,
                  GtkTreeModel       *model,
@@ -594,22 +578,20 @@ month_year_changed (CcDateTimePanel *self)
 }
 
 static void
-month_row_activated_cb (CcDateTimePanel *self,
-                        GtkFlowBoxChild *child,
-                        GtkFlowBox      *box)
+on_month_row_selected_changed_cb (AdwComboRow     *month_row,
+                                  GParamSpec      *pspec,
+                                  CcDateTimePanel *self)
 {
-  int i;
+  unsigned int i;
 
   g_assert (CC_IS_DATE_TIME_PANEL (self));
-  g_assert (GTK_IS_FLOW_BOX_CHILD (child));
-  g_assert (GTK_IS_FLOW_BOX (box));
+  g_assert (ADW_IS_COMBO_ROW (month_row));
 
-  i = gtk_flow_box_child_get_index (child);
+  i = adw_combo_row_get_selected (month_row);
   g_assert (i >= 0 && i < 12);
 
   self->month = i + 1;
   month_year_changed (self);
-  gtk_popover_popdown (self->month_popover);
 }
 
 static void
@@ -862,7 +844,6 @@ setup_datetime_dialog (CcDateTimePanel *self)
   GtkAdjustment *adjustment;
   GdkDisplay *display;
   g_autoptr(GtkCssProvider) provider = NULL;
-  GtkWidget *month_label;
   guint num_days;
 
   /* Big time buttons */
@@ -882,8 +863,7 @@ setup_datetime_dialog (CcDateTimePanel *self)
 
   /* Month */
   self->month = g_date_time_get_month (self->date);
-  month_label = gtk_flow_box_get_child_at_index (self->month_flowbox, self->month - 1);
-  gtk_label_set_text (self->month_label, gtk_label_get_text (GTK_LABEL (month_label)));
+  adw_combo_row_set_selected (self->month_row, self->month - 1);
 
   /* Day */
   num_days = g_date_get_days_in_month (g_date_time_get_month (self->date),
@@ -910,8 +890,12 @@ sort_date_box (GtkListBoxRow   *a,
                GtkListBoxRow   *b,
                CcDateTimePanel *self)
 {
+  GtkListBoxRow *month_row;
+
   g_assert (CC_IS_DATE_TIME_PANEL (self));
 
+  month_row = GTK_LIST_BOX_ROW (self->month_row);
+
   switch (date_endian_get_default (FALSE)) {
   case DATE_ENDIANESS_BIG:
     /* year, month, day */
@@ -929,16 +913,16 @@ sort_date_box (GtkListBoxRow   *a,
 
   case DATE_ENDIANESS_MIDDLE:
     /* month, day, year */
-    if (a == self->month_row || b == self->year_row)
+    if (a == month_row || b == self->year_row)
       return -1;
-    if (a == self->year_row || b == self->month_row)
+    if (a == self->year_row || b == month_row)
       return 1;
 
   case DATE_ENDIANESS_YDM:
     /* year, day, month */
-    if (a == self->year_row || b == self->month_row)
+    if (a == self->year_row || b == month_row)
       return -1;
-    if (a == self->month_row || b == self->year_row)
+    if (a == month_row || b == self->year_row)
       return 1;
   }
 
@@ -972,9 +956,6 @@ cc_date_time_panel_class_init (CcDateTimePanelClass *klass)
   gtk_widget_class_bind_template_child (widget_class, CcDateTimePanel, day_spinbutton);
   gtk_widget_class_bind_template_child (widget_class, CcDateTimePanel, timeformat_row);
   gtk_widget_class_bind_template_child (widget_class, CcDateTimePanel, lock_button);
-  gtk_widget_class_bind_template_child (widget_class, CcDateTimePanel, month_label);
-  gtk_widget_class_bind_template_child (widget_class, CcDateTimePanel, month_popover);
-  gtk_widget_class_bind_template_child (widget_class, CcDateTimePanel, month_flowbox);
   gtk_widget_class_bind_template_child (widget_class, CcDateTimePanel, month_row);
   gtk_widget_class_bind_template_child (widget_class, CcDateTimePanel, network_time_switch);
   gtk_widget_class_bind_template_child (widget_class, CcDateTimePanel, time_editor);
@@ -988,9 +969,8 @@ cc_date_time_panel_class_init (CcDateTimePanelClass *klass)
   gtk_widget_class_bind_template_callback (widget_class, list_box_row_activated);
   gtk_widget_class_bind_template_callback (widget_class, time_changed_cb);
   gtk_widget_class_bind_template_callback (widget_class, change_clock_settings);
-  gtk_widget_class_bind_template_callback (widget_class, month_row_activated_cb);
-  gtk_widget_class_bind_template_callback (widget_class, date_box_row_activated_cb);
   gtk_widget_class_bind_template_callback (widget_class, format_clock_name_cb);
+  gtk_widget_class_bind_template_callback (widget_class, on_month_row_selected_changed_cb);
 
   bind_textdomain_codeset (GETTEXT_PACKAGE_TIMEZONES, "UTF-8");
 
diff --git a/panels/datetime/cc-datetime-panel.ui b/panels/datetime/cc-datetime-panel.ui
index 0d97a21ec..9b30ce1b0 100644
--- a/panels/datetime/cc-datetime-panel.ui
+++ b/panels/datetime/cc-datetime-panel.ui
@@ -11,110 +11,6 @@
   <object class="GtkTreeModelSort" id="city_modelsort">
     <property name="model">city_liststore</property>
   </object>
-  <object class="GtkPopover" id="month_popover">
-    <property name="visible">False</property>
-    <child>
-      <object class="GtkFlowBox" id="month_flowbox">
-        <property name="margin-top">12</property>
-        <property name="margin-bottom">12</property>
-        <property name="margin-start">12</property>
-        <property name="margin-end">12</property>
-        <property name="orientation">vertical</property>
-        <property name="max-children-per-line">6</property>
-        <property name="min-children-per-line">4</property>
-        <property name="homogeneous">True</property>
-        <property name="row-spacing">12</property>
-        <property name="column-spacing">12</property>
-        <property name="selection-mode">none</property>
-        <signal name="child-activated" handler="month_row_activated_cb" swapped="yes"/>
-
-        <child>
-          <object class="GtkLabel">
-            <property name="label" translatable="yes">January</property>
-            <property name="xalign">0.0</property>
-          </object>
-        </child>
-
-        <child>
-          <object class="GtkLabel">
-            <property name="label" translatable="yes">February</property>
-            <property name="xalign">0.0</property>
-          </object>
-        </child>
-
-        <child>
-          <object class="GtkLabel">
-            <property name="label" translatable="yes">March</property>
-            <property name="xalign">0.0</property>
-          </object>
-        </child>
-
-        <child>
-          <object class="GtkLabel">
-            <property name="label" translatable="yes">April</property>
-            <property name="xalign">0.0</property>
-          </object>
-        </child>
-
-        <child>
-          <object class="GtkLabel">
-            <property name="label" translatable="yes">May</property>
-            <property name="xalign">0.0</property>
-          </object>
-        </child>
-
-        <child>
-          <object class="GtkLabel">
-            <property name="label" translatable="yes">June</property>
-            <property name="xalign">0.0</property>
-          </object>
-        </child>
-
-        <child>
-          <object class="GtkLabel">
-            <property name="label" translatable="yes">July</property>
-            <property name="xalign">0.0</property>
-          </object>
-        </child>
-
-        <child>
-          <object class="GtkLabel">
-            <property name="label" translatable="yes">August</property>
-            <property name="xalign">0.0</property>
-          </object>
-        </child>
-
-        <child>
-          <object class="GtkLabel">
-            <property name="label" translatable="yes">September</property>
-            <property name="xalign">0.0</property>
-          </object>
-        </child>
-
-        <child>
-          <object class="GtkLabel">
-            <property name="label" translatable="yes">October</property>
-            <property name="xalign">0.0</property>
-          </object>
-        </child>
-
-        <child>
-          <object class="GtkLabel">
-            <property name="label" translatable="yes">November</property>
-            <property name="xalign">0.0</property>
-          </object>
-        </child>
-
-        <child>
-          <object class="GtkLabel">
-            <property name="label" translatable="yes">December</property>
-            <property name="xalign">0.0</property>
-          </object>
-        </child>
-
-      </object>
-    </child>
-  </object>
   <object class="GtkDialog" id="datetime_dialog">
     <property name="title" translatable="yes">Date &amp; Time</property>
     <property name="modal">True</property>
@@ -144,7 +40,6 @@
               <object class="GtkListBox" id="date_box">
                 <property name="width-request">320</property>
                 <property name="selection-mode">none</property>
-                <signal name="row-activated" handler="date_box_row_activated_cb" swapped="yes"/>
                 <style>
                   <class name="boxed-list"/>
                 </style>
@@ -183,36 +78,27 @@
 
                 <!-- Month row -->
                 <child>
-                  <object class="GtkListBoxRow" id="month_row">
-                    <child>
-                      <object class="GtkBox">
-                        <property name="margin_top">12</property>
-                        <property name="margin_bottom">12</property>
-                        <property name="margin_start">12</property>
-                        <property name="margin_end">12</property>
-                        <property name="spacing">6</property>
-                        <child>
-                          <object class="GtkLabel">
-                            <property name="hexpand">True</property>
-                            <property name="halign">start</property>
-                            <property name="label" translatable="yes">Month</property>
-                            <style>
-                              <class name="dim-label"/>
-                            </style>
-                          </object>
-                        </child>
-                        <child>
-                          <object class="GtkLabel" id="month_label">
-                            <property name="halign">end</property>
-                          </object>
-                        </child>
-                        <child>
-                          <object class="GtkImage" id="month_icon">
-                            <property name="icon-name">pan-down-symbolic</property>
-                          </object>
-                        </child>
+                  <object class="AdwComboRow" id="month_row">
+                    <property name="title" translatable="yes">Month</property>
+                    <signal name="notify::selected" handler="on_month_row_selected_changed_cb" 
object="CcDateTimePanel" swapped="no" />
+                    <property name="model">
+                      <object class="GtkStringList">
+                        <items>
+                          <item translatable="yes">January</item>
+                          <item translatable="yes">February</item>
+                          <item translatable="yes">March</item>
+                          <item translatable="yes">April</item>
+                          <item translatable="yes">May</item>
+                          <item translatable="yes">June</item>
+                          <item translatable="yes">July</item>
+                          <item translatable="yes">August</item>
+                          <item translatable="yes">September</item>
+                          <item translatable="yes">October</item>
+                          <item translatable="yes">November</item>
+                          <item translatable="yes">December</item>
+                        </items>
                       </object>
-                    </child>
+                    </property>
                   </object>
                 </child>
 


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