[gnome-control-center] datetime: get month_label from GtkFlowBox widget



commit 7c91fc140035f398696f6ffeb9b7c3b81bdbbf6f
Author: Pablo Correa Gómez <ablocorrea hotmail com>
Date:   Wed Nov 3 12:12:56 2021 +0100

    datetime: get month_label from GtkFlowBox widget
    
    Using g_date_time_format to get the name of the month
    translates the name according to LC_TIME. This is inconsistent
    with all other labels displayed, which get translated according
    to LC_MESSAGES. By taking the label from the corresponding
    entry in the GtkFlowBox, we avoid the incosistency
    
    Fixes #1507

 panels/datetime/cc-datetime-panel.c  | 14 ++++++++------
 panels/datetime/cc-datetime-panel.ui |  3 +--
 2 files changed, 9 insertions(+), 8 deletions(-)
---
diff --git a/panels/datetime/cc-datetime-panel.c b/panels/datetime/cc-datetime-panel.c
index 68617d934..7e1088533 100644
--- a/panels/datetime/cc-datetime-panel.c
+++ b/panels/datetime/cc-datetime-panel.c
@@ -102,6 +102,7 @@ struct _CcDateTimePanel
   GtkListBoxRow *month_row;
   GtkListBoxRow *year_row;
   GtkPopover *month_popover;
+  GtkFlowBox *month_flowbox;
   GtkWidget *network_time_switch;
   GtkWidget *time_editor;
   GtkWidget *timezone_button;
@@ -232,7 +233,7 @@ static void
 update_time (CcDateTimePanel *self)
 {
   g_autofree gchar *label = NULL;
-  g_autofree gchar *month_label = NULL;
+  GtkWidget *month_label;
   gboolean use_ampm;
 
   if (self->clock_format == G_DESKTOP_CLOCK_FORMAT_12H)
@@ -257,8 +258,8 @@ update_time (CcDateTimePanel *self)
     }
 
   self->month = g_date_time_get_month (self->date);
-  month_label = g_date_time_format (self->date, "%B");
-  gtk_label_set_text (self->month_label, month_label);
+  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)));
   gtk_label_set_text (GTK_LABEL (self->datetime_label), label);
 }
 
@@ -861,7 +862,7 @@ setup_datetime_dialog (CcDateTimePanel *self)
   GtkAdjustment *adjustment;
   GdkDisplay *display;
   g_autoptr(GtkCssProvider) provider = NULL;
-  g_autofree char *month = NULL;
+  GtkWidget *month_label;
   guint num_days;
 
   /* Big time buttons */
@@ -881,8 +882,8 @@ setup_datetime_dialog (CcDateTimePanel *self)
 
   /* Month */
   self->month = g_date_time_get_month (self->date);
-  month = g_date_time_format (self->date, "%B");
-  gtk_label_set_text (self->month_label, month);
+  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)));
 
   /* Day */
   num_days = g_date_get_days_in_month (g_date_time_get_month (self->date),
@@ -973,6 +974,7 @@ cc_date_time_panel_class_init (CcDateTimePanelClass *klass)
   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);
diff --git a/panels/datetime/cc-datetime-panel.ui b/panels/datetime/cc-datetime-panel.ui
index fcb2fc534..0d97a21ec 100644
--- a/panels/datetime/cc-datetime-panel.ui
+++ b/panels/datetime/cc-datetime-panel.ui
@@ -14,7 +14,7 @@
   <object class="GtkPopover" id="month_popover">
     <property name="visible">False</property>
     <child>
-      <object class="GtkFlowBox">
+      <object class="GtkFlowBox" id="month_flowbox">
         <property name="margin-top">12</property>
         <property name="margin-bottom">12</property>
         <property name="margin-start">12</property>
@@ -402,4 +402,3 @@
     </child>
   </template>
 </interface>
-


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