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



commit 3156b4f814413e94b7405c480f5ab430b0e826b5
Author: Volker Sobek <reklov live com>
Date:   Wed Feb 13 14:31:48 2013 +0100

    (to be squashed) AlarmDialog: Make the day buttons functional

 src/alarm.vala |   34 ++++++++++++++++++++++++++--------
 src/utils.vala |    3 +++
 2 files changed, 29 insertions(+), 8 deletions(-)
---
diff --git a/src/alarm.vala b/src/alarm.vala
index 71be46f..317973a 100644
--- a/src/alarm.vala
+++ b/src/alarm.vala
@@ -238,14 +238,22 @@ private class SetupDialog : Gtk.Dialog {
             time_box.pack_start (am_pm_button);
         }
 
+        // Create an array with the weekday buttons with
+        // day_buttons[0] referencing the button for Monday, and so on.
         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);
+        }
+
+        // TODO: This is always returns 0 for now, the method is not implemented yet.
+        var first_weekday = Utils.LocalizedWeekdays.first_weekday;
+        // Pack the buttons, starting with the first day of the week
+        // depending on the locale.
+        for (int i = 0; i < 7; i++) {
+            var day_number = (first_weekday + i) % 7;
+            day_buttons_box.pack_start (day_buttons[day_number]);
         }
 
         get_content_area ().add (grid);
@@ -274,6 +282,7 @@ private class SetupDialog : Gtk.Dialog {
             days = alarm.days;
         }
 
+        // Set the time.
         if (format == Utils.WallClock.Format.TWELVE) {
             if (hour < 12) {
                 am_pm_button.choice = AmPmToggleButton.AmPm.AM;
@@ -286,12 +295,16 @@ private class SetupDialog : Gtk.Dialog {
                 hour = 12;
             }
         }
-
         h_spinbutton.set_value (hour);
         m_spinbutton.set_value (minute);
-        name_entry.set_text (name != null ? name : "");
 
-        // TODO: set day buttons
+        // Set the name.
+        name_entry.set_text (name);
+
+        // Set the toggle buttons for weekdays.
+        for (int i = 0; i < days.length; i++) {
+            day_buttons[days[i]].active = true;
+        }
     }
 
     public Item get_alarm_item () {
@@ -307,9 +320,14 @@ private class SetupDialog : Gtk.Dialog {
             }
         }
 
-        // TODO: get days from day buttons
+        int[] days = {};
+        for (int i = 0; i < 6; i++) {
+            if (day_buttons[i].active) {
+                days += i;
+            }
+        }
 
-        return new Item (name, true, hour, minute, null);
+        return new Item (name, true, hour, minute, days);
     }
 
     private bool show_leading_zeros (Gtk.SpinButton spin_button) {
diff --git a/src/utils.vala b/src/utils.vala
index 568f5d1..377f872 100644
--- a/src/utils.vala
+++ b/src/utils.vala
@@ -207,6 +207,9 @@ public class LocalizedWeekdays {
         get { return _abbrs; }
     }
 
+    // TODO: Implement
+    public static int first_weekday { get; private set; default = 0; }
+
 }
 
 } // namespace Utils


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