[gnome-calendar/gbsneto/event-editor: 12/16] time-selector: Make it a GtkBox directly



commit ce3ab2eab2ecfa3ca2b0a4f17505a6209c22675e
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Thu Nov 14 15:28:57 2019 -0300

    time-selector: Make it a GtkBox directly

 src/gui/gcal-time-selector.c  |  58 +--------------------
 src/gui/gcal-time-selector.h  |   3 +-
 src/gui/gcal-time-selector.ui | 116 +++++++++++++++++-------------------------
 3 files changed, 49 insertions(+), 128 deletions(-)
---
diff --git a/src/gui/gcal-time-selector.c b/src/gui/gcal-time-selector.c
index 1ce4bef4..d43a4910 100644
--- a/src/gui/gcal-time-selector.c
+++ b/src/gui/gcal-time-selector.c
@@ -25,16 +25,14 @@
 
 struct _GcalTimeSelector
 {
-  GtkMenuButton parent;
+  GtkBox         parent;
 
   GtkAdjustment *hour_adjustment;
   GtkAdjustment *minute_adjustment;
 
-  GtkWidget *time_label;
   GtkWidget *hour_spin;
   GtkWidget *minute_spin;
   GtkWidget *period_combo;
-  GtkWidget *grid;
 
   GDateTime *time;
 
@@ -54,43 +52,7 @@ enum
   PM
 };
 
-static void     gcal_time_selector_constructed                 (GObject              *object);
-
-G_DEFINE_TYPE (GcalTimeSelector, gcal_time_selector, GTK_TYPE_MENU_BUTTON);
-
-static void
-update_label (GcalTimeSelector *selector)
-{
-  gchar *new_label;
-
-  if (selector->time_format == GCAL_TIME_FORMAT_24H)
-    {
-      new_label = g_date_time_format (selector->time, "%H:%M");
-    }
-  else
-    {
-      gchar *time_str;
-      gint hour, minute, period;
-
-      hour = (gint) gtk_adjustment_get_value (selector->hour_adjustment);
-      minute = (gint) gtk_adjustment_get_value (selector->minute_adjustment);
-
-
-      period = gtk_combo_box_get_active (GTK_COMBO_BOX (selector->period_combo));
-      time_str = g_strdup_printf ("%.2d:%.2d", hour, minute);
-
-      if (period == AM)
-        new_label = g_strdup_printf (_("%s AM"), time_str);
-      else
-        new_label = g_strdup_printf (_("%s PM"), time_str);
-
-      g_free (time_str);
-    }
-
-  gtk_label_set_label (GTK_LABEL (selector->time_label), new_label);
-
-  g_clear_pointer (&new_label, g_free);
-}
+G_DEFINE_TYPE (GcalTimeSelector, gcal_time_selector, GTK_TYPE_BOX);
 
 static void
 update_time (GcalTimeSelector *selector)
@@ -228,7 +190,6 @@ gcal_time_selector_class_init (GcalTimeSelectorClass *klass)
   GObjectClass *object_class;
 
   object_class = G_OBJECT_CLASS (klass);
-  object_class->constructed = gcal_time_selector_constructed;
   object_class->dispose = gcal_time_selector_dispose;
   object_class->finalize = gcal_time_selector_finalize;
   object_class->get_property = gcal_time_selector_get_property;
@@ -249,13 +210,11 @@ gcal_time_selector_class_init (GcalTimeSelectorClass *klass)
 
   gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), 
"/org/gnome/calendar/ui/gui/gcal-time-selector.ui");
 
-  gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (klass), GcalTimeSelector, time_label);
   gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (klass), GcalTimeSelector, hour_adjustment);
   gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (klass), GcalTimeSelector, hour_spin);
   gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (klass), GcalTimeSelector, minute_adjustment);
   gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (klass), GcalTimeSelector, minute_spin);
   gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (klass), GcalTimeSelector, period_combo);
-  gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (klass), GcalTimeSelector, grid);
 
   gtk_widget_class_bind_template_callback (GTK_WIDGET_CLASS (klass), on_output);
   gtk_widget_class_bind_template_callback (GTK_WIDGET_CLASS (klass), update_time);
@@ -269,17 +228,6 @@ gcal_time_selector_init (GcalTimeSelector *self)
   gtk_widget_init_template (GTK_WIDGET (self));
 }
 
-static void
-gcal_time_selector_constructed (GObject *object)
-{
-  GcalTimeSelector *selector = GCAL_TIME_SELECTOR (object);
-
-  /* chaining up */
-  G_OBJECT_CLASS (gcal_time_selector_parent_class)->constructed (object);
-
-  gtk_widget_set_direction (selector->grid, GTK_TEXT_DIR_LTR);
-}
-
 /* Public API */
 GtkWidget*
 gcal_time_selector_new (void)
@@ -326,8 +274,6 @@ gcal_time_selector_set_time (GcalTimeSelector *selector,
       gtk_adjustment_set_value (selector->hour_adjustment, hour);
       gtk_adjustment_set_value (selector->minute_adjustment, minute);
 
-      update_label (selector);
-
       g_signal_handlers_unblock_by_func (selector->hour_adjustment, update_time, selector);
       g_signal_handlers_unblock_by_func (selector->minute_adjustment, update_time, selector);
 
diff --git a/src/gui/gcal-time-selector.h b/src/gui/gcal-time-selector.h
index b276dcc6..a469fbcb 100644
--- a/src/gui/gcal-time-selector.h
+++ b/src/gui/gcal-time-selector.h
@@ -26,8 +26,7 @@
 G_BEGIN_DECLS
 
 #define GCAL_TYPE_TIME_SELECTOR             (gcal_time_selector_get_type ())
-
-G_DECLARE_FINAL_TYPE (GcalTimeSelector, gcal_time_selector, GCAL, TIME_SELECTOR, GtkMenuButton)
+G_DECLARE_FINAL_TYPE (GcalTimeSelector, gcal_time_selector, GCAL, TIME_SELECTOR, GtkBox)
 
 GtkWidget*       gcal_time_selector_new          (void);
 
diff --git a/src/gui/gcal-time-selector.ui b/src/gui/gcal-time-selector.ui
index f595d0c9..45d4e4d2 100644
--- a/src/gui/gcal-time-selector.ui
+++ b/src/gui/gcal-time-selector.ui
@@ -1,15 +1,56 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
-  <template class="GcalTimeSelector" parent="GtkMenuButton">
-    <property name="use_popover">True</property>
-    <property name="popover">time_selector_popover</property>
+  <template class="GcalTimeSelector" parent="GtkBox">
+    <property name="spacing">6</property>
+
+    <!-- Hour -->
     <child>
-      <object class="GtkLabel" id="time_label">
+      <object class="GtkSpinButton" id="hour_spin">
         <property name="visible">True</property>
-        <property name="label" translatable="yes">00:00</property>
+        <property name="can_focus">True</property>
+        <property name="xalign">0.5</property>
+        <property name="input_purpose">number</property>
+        <property name="orientation">vertical</property>
+        <property name="adjustment">hour_adjustment</property>
+        <signal name="output" handler="on_output" object="GcalTimeSelector" swapped="no"/>
+      </object>
+    </child>
+
+    <child>
+      <object class="GtkLabel" id="label1">
+        <property name="visible">True</property>
+        <property name="label" translatable="yes">:</property>
+      </object>
+    </child>
+
+    <!-- Minute -->
+    <child>
+      <object class="GtkSpinButton" id="minute_spin">
+        <property name="visible">True</property>
+        <property name="can_focus">True</property>
+        <property name="xalign">0.5</property>
+        <property name="input_purpose">number</property>
+        <property name="orientation">vertical</property>
+        <property name="adjustment">minute_adjustment</property>
+        <signal name="output" handler="on_output" object="GcalTimeSelector" swapped="no"/>
+      </object>
+    </child>
+
+
+    <!-- AM/PM -->
+    <child>
+      <object class="GtkComboBoxText" id="period_combo">
+        <property name="valign">center</property>
+        <property name="active">0</property>
+        <signal name="changed" handler="update_time" object="GcalTimeSelector" swapped="yes"/>
+        <items>
+          <item translatable="yes">AM</item>
+          <item translatable="yes">PM</item>
+        </items>
       </object>
     </child>
   </template>
+
   <object class="GtkAdjustment" id="hour_adjustment">
     <property name="upper">23</property>
     <property name="step_increment">1</property>
@@ -22,69 +63,4 @@
     <property name="page_increment">10</property>
     <signal name="value-changed" handler="update_time" object="GcalTimeSelector" swapped="yes"/>
   </object>
-  <object class="GtkPopover" id="time_selector_popover">
-    <property name="position">bottom</property>
-    <child>
-      <object class="GtkGrid" id="grid">
-        <property name="visible">True</property>
-        <property name="border_width">12</property>
-        <property name="column_spacing">6</property>
-        <child>
-          <object class="GtkSpinButton" id="hour_spin">
-            <property name="visible">True</property>
-            <property name="can_focus">True</property>
-            <property name="xalign">0.5</property>
-            <property name="input_purpose">number</property>
-            <property name="orientation">vertical</property>
-            <property name="adjustment">hour_adjustment</property>
-            <signal name="output" handler="on_output" object="GcalTimeSelector" swapped="no"/>
-          </object>
-          <packing>
-            <property name="left_attach">0</property>
-            <property name="top_attach">0</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkSpinButton" id="minute_spin">
-            <property name="visible">True</property>
-            <property name="can_focus">True</property>
-            <property name="xalign">0.5</property>
-            <property name="input_purpose">number</property>
-            <property name="orientation">vertical</property>
-            <property name="adjustment">minute_adjustment</property>
-            <signal name="output" handler="on_output" object="GcalTimeSelector" swapped="no"/>
-          </object>
-          <packing>
-            <property name="left_attach">2</property>
-            <property name="top_attach">0</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkLabel" id="label1">
-            <property name="visible">True</property>
-            <property name="label" translatable="yes">:</property>
-          </object>
-          <packing>
-            <property name="left_attach">1</property>
-            <property name="top_attach">0</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkComboBoxText" id="period_combo">
-            <property name="valign">center</property>
-            <property name="active">0</property>
-            <signal name="changed" handler="update_time" object="GcalTimeSelector" swapped="yes"/>
-            <items>
-              <item translatable="yes">AM</item>
-              <item translatable="yes">PM</item>
-            </items>
-          </object>
-          <packing>
-            <property name="left_attach">3</property>
-            <property name="top_attach">0</property>
-          </packing>
-        </child>
-      </object>
-    </child>
-  </object>
 </interface>


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