[gnome-clocks/wip/vala] (to be squashed) AlarmDialog: Add the day buttons



commit 4331b3275eb984382e4c80ec8c2e0accd3fdb9c6
Author: Volker Sobek <reklov live com>
Date:   Tue Feb 12 23:02:50 2013 +0100

    (to be squashed) AlarmDialog: Add the day buttons
    
    They are not yet functional and don't support locales.
    
    Some other cleanups as well.

 src/alarm.ui   |   66 ++++++++++++++++++++++++++++++-------------------------
 src/alarm.vala |   42 ++++++++++++++++++++++++-----------
 src/utils.vala |   32 +++++++++++++++++++++++++++
 3 files changed, 97 insertions(+), 43 deletions(-)
---
diff --git a/src/alarm.ui b/src/alarm.ui
index a11c7b1..61437f3 100644
--- a/src/alarm.ui
+++ b/src/alarm.ui
@@ -91,6 +91,10 @@
   <object class="GtkGrid" id="setup_dialog_content">
     <property name="visible">True</property>
     <property name="can_focus">False</property>
+    <property name="margin_left">5</property>
+    <property name="margin_right">5</property>
+    <property name="margin_top">5</property>
+    <property name="margin_bottom">5</property>
     <property name="hexpand">True</property>
     <property name="vexpand">True</property>
     <property name="row_spacing">9</property>
@@ -152,22 +156,50 @@
       </packing>
     </child>
     <child>
+      <object class="GtkBox" id="day_buttons_box">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="homogeneous">True</property>
+        <style>
+          <class name="linked"/>
+        </style>
+        <child>
+          <placeholder/>
+        </child>
+        <child>
+          <placeholder/>
+        </child>
+        <child>
+          <placeholder/>
+        </child>
+      </object>
+      <packing>
+        <property name="left_attach">1</property>
+        <property name="top_attach">2</property>
+        <property name="width">1</property>
+        <property name="height">1</property>
+      </packing>
+    </child>
+    <child>
       <object class="GtkBox" id="time_box">
         <property name="visible">True</property>
         <property name="can_focus">False</property>
+        <property name="hexpand">True</property>
         <property name="spacing">6</property>
         <child>
           <object class="GtkSpinButton" id="h_spinbutton">
             <property name="visible">True</property>
             <property name="can_focus">True</property>
+            <property name="hexpand">True</property>
             <property name="invisible_char">â</property>
+            <property name="invisible_char_set">True</property>
             <property name="input_purpose">number</property>
             <property name="adjustment">h_adjustment</property>
             <property name="numeric">True</property>
             <property name="wrap">True</property>
           </object>
           <packing>
-            <property name="expand">False</property>
+            <property name="expand">True</property>
             <property name="fill">True</property>
             <property name="position">0</property>
           </packing>
@@ -188,21 +220,20 @@
           <object class="GtkSpinButton" id="m_spinbutton">
             <property name="visible">True</property>
             <property name="can_focus">True</property>
+            <property name="hexpand">True</property>
             <property name="invisible_char">â</property>
+            <property name="invisible_char_set">True</property>
             <property name="input_purpose">number</property>
             <property name="adjustment">m_adjustment</property>
             <property name="numeric">True</property>
             <property name="wrap">True</property>
           </object>
           <packing>
-            <property name="expand">False</property>
+            <property name="expand">True</property>
             <property name="fill">True</property>
             <property name="position">2</property>
           </packing>
         </child>
-        <child>
-          <placeholder/>
-        </child>
       </object>
       <packing>
         <property name="left_attach">1</property>
@@ -211,30 +242,5 @@
         <property name="height">1</property>
       </packing>
     </child>
-    <child>
-      <object class="GtkBox" id="box1">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="homogeneous">True</property>
-        <style>
-          <class name="linked"/>
-        </style>
-        <child>
-          <placeholder/>
-        </child>
-        <child>
-          <placeholder/>
-        </child>
-        <child>
-          <placeholder/>
-        </child>
-      </object>
-      <packing>
-        <property name="left_attach">1</property>
-        <property name="top_attach">2</property>
-        <property name="width">1</property>
-        <property name="height">1</property>
-      </packing>
-    </child>
   </object>
 </interface>
diff --git a/src/alarm.vala b/src/alarm.vala
index 6da2609..71be46f 100644
--- a/src/alarm.vala
+++ b/src/alarm.vala
@@ -199,11 +199,12 @@ private class Item : Object {
 
 private class SetupDialog : Gtk.Dialog {
 
+    private Utils.WallClock.Format format;
     private Gtk.SpinButton h_spinbutton;
     private Gtk.SpinButton m_spinbutton;
-    private AmPmToggleButton am_pm_button;
     private Gtk.Entry name_entry;
-    private Utils.WallClock.Format format;
+    private AmPmToggleButton am_pm_button;
+    private Gtk.ToggleButton[] day_buttons;
 
     public SetupDialog (Gtk.Window parent, Item? alarm) {
         Object (transient_for: parent, modal: true, title: _("New Alarm"));
@@ -211,30 +212,45 @@ private class SetupDialog : Gtk.Dialog {
         add_buttons (Gtk.Stock.CANCEL, 0, Gtk.Stock.SAVE, 1);
         set_default_response (1);
 
+        format  = Utils.WallClock.get_default ().format;
+        am_pm_button = new AmPmToggleButton ();
+
+        // Get objects from the ui file
         var builder = Utils.load_ui ("alarm.ui");
         var grid = builder.get_object ("setup_dialog_content") as Gtk.Grid;
         var time_box = builder.get_object ("time_box") as Gtk.Box;
-        var wc = Utils.WallClock.get_default ();
-
+        var day_buttons_box = builder.get_object ("day_buttons_box") as Gtk.Box;
         h_spinbutton = builder.get_object ("h_spinbutton") as Gtk.SpinButton;
         m_spinbutton = builder.get_object ("m_spinbutton") as Gtk.SpinButton;
-        h_spinbutton.output.connect (show_leading_zeros);
-        m_spinbutton.output.connect (show_leading_zeros);
         name_entry = builder.get_object ("name_entry") as Gtk.Entry;
-        am_pm_button = new AmPmToggleButton ();
-        format = wc.format;
+        assert (builder != null && grid != null && time_box != null &&
+                day_buttons_box != null && h_spinbutton != null &&
+                m_spinbutton != null && name_entry != null);
 
+        h_spinbutton.output.connect (show_leading_zeros);
+        m_spinbutton.output.connect (show_leading_zeros);
         if (format == Utils.WallClock.Format.TWENTYFOUR)
-            // 12h format
+            // 24h format
             h_spinbutton.set_range (0, 23);
         else {
-            // 24h format
+            // 12h format
             h_spinbutton.set_range (1, 12);
-            time_box.pack_end (am_pm_button);
+            time_box.pack_start (am_pm_button);
+        }
+
+        day_buttons = new Gtk.ToggleButton[7];
+        for (int i = 0; i < 7; i++) {
+            // TODO: start with button for the first day of the week
+            // depending on the locale
+            var abbr = Utils.LocalizedWeekdays.abbrs[i];
+            var button = new Gtk.ToggleButton.with_label (abbr);
+            day_buttons[i] = button;
+            day_buttons_box.pack_start (button);
         }
 
         get_content_area ().add (grid);
         set_alarm_item (alarm);
+        show_all ();
 
     }
 
@@ -271,8 +287,8 @@ private class SetupDialog : Gtk.Dialog {
             }
         }
 
-        h_spinbutton.set_value(hour);
-        m_spinbutton.set_value(minute);
+        h_spinbutton.set_value (hour);
+        m_spinbutton.set_value (minute);
         name_entry.set_text (name != null ? name : "");
 
         // TODO: set day buttons
diff --git a/src/utils.vala b/src/utils.vala
index 7ce44e5..568f5d1 100644
--- a/src/utils.vala
+++ b/src/utils.vala
@@ -177,5 +177,37 @@ public class Bell : Object {
     }
 }
 
+public class LocalizedWeekdays {
+    private static const string[] _plurals = {
+        N_("Mondays"),
+        N_("Tuesdays"),
+        N_("Wednesdays"),
+        N_("Thursdays"),
+        N_("Fridays"),
+        N_("Saturdays"),
+        N_("Sundays")
+    };
+
+    public static string[] plurals {
+        get { return _plurals; }
+    }
+
+    private const string[] _abbrs = {
+        // TODO: fetch localized abbreviations from glib/libc
+        "Mon",
+        "Tue",
+        "Wed",
+        "Thu",
+        "Fri",
+        "Sat",
+        "Sun"
+    };
+
+    public static string[] abbrs {
+        get { return _abbrs; }
+    }
+
+}
+
 } // namespace Utils
 } // namespace Clocks


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