[gnome-clocks/wip/vala] Alarm: Set the repeat label



commit 4a0629e044e770d3ac3c6a48a1c3cb6f1a66b72e
Author: Volker Sobek <reklov live com>
Date:   Sat Feb 16 15:11:04 2013 +0100

    Alarm: Set the repeat label

 egg-list-box   |    2 +-
 src/alarm.vala |   57 +++++++++++++++++++++++++++++++++++++++++++------------
 2 files changed, 45 insertions(+), 14 deletions(-)
---
diff --git a/egg-list-box b/egg-list-box
index 491db4b..87a01fd 160000
--- a/egg-list-box
+++ b/egg-list-box
@@ -1 +1 @@
-Subproject commit 491db4b5eb181f1e13b909644dfd0ad971231099
+Subproject commit 87a01fd7134a6f257f17d5d2163f3f50fba973c4
diff --git a/src/alarm.vala b/src/alarm.vala
index cdfe8ac..24620c0 100644
--- a/src/alarm.vala
+++ b/src/alarm.vala
@@ -34,6 +34,7 @@ private class Item : Object {
         get {
             return _name;
         }
+
         set {
             _name = value;
             bell = new Utils.Bell ("alarm-clock-elapsed", _("Alarm"), value);
@@ -42,9 +43,39 @@ private class Item : Object {
     public int hour { get; set; }
     public int minute { get; set; }
 
-    // FIXME
+    // days[0] = Monday, ..., days[6] = Sunday
     public int[] days { get; set; }
 
+    public string repeat_label {
+        owned get {
+            string r = null;
+            var n_active_days = days.length;
+            int[] weekdays = {0, 1, 2, 3, 4};
+            if (n_active_days == 0) {
+                r = ""; // TODO: Should whe show something for no-repeat alarms?
+            } else if (n_active_days == 1) {
+                r = Utils.LocalizedWeekdays.plurals[_days[0]];
+            } else if (n_active_days == 7) {
+                r = _("Every Day");
+            } else if (days_equal (weekdays)) {
+                r = _("Weekdays");
+            } else {
+                string[] abbrs = {};
+                for (int i = 0; i < 7; i++) {
+                    var day_num = (Utils.LocalizedWeekdays.first_weekday + i) % 7;
+                    foreach (int d in days) {
+                        if (d == day_num) {
+                            abbrs += Utils.LocalizedWeekdays.abbrs[d];
+
+                        }
+                    }
+                }
+                r = string.joinv (", ", abbrs);
+            }
+            return r;
+        }
+    }
+
     public State state { get; private set; }
 
     public string time_label {
@@ -53,12 +84,6 @@ private class Item : Object {
          }
     }
 
-    public string repeat_label {
-         get {
-            return _("Every Day");
-         }
-    }
-
     public bool active {
         get {
             return _active;
@@ -82,8 +107,9 @@ private class Item : Object {
     private GLib.DateTime ring_end_time;
     private Utils.Bell bell;
 
-    public Item.with_data (string name, bool active, int hour, int minute, int[]? days) {
+    public Item.with_data (string name, bool active, int hour, int minute, int[] days) {
         Object (name: name, active: active, hour: hour, minute: minute);
+        this.days = days;
 
         bell = new Utils.Bell ("alarm-clock-elapsed", _("Alarm"), name);
 
@@ -95,12 +121,17 @@ private class Item : Object {
     }
 
     public bool equal (Item a) {
-        return a.name == name && a.hour == hour && a.minute == minute && compare_days ();
+        return a.name == name && a.hour == hour && a.minute == minute && days_equal (a.days);
     }
 
-    private bool compare_days () {
-        // FIXME
-        return true;
+    private bool days_equal (int[] days) {
+        if (_days.length == days.length) {
+            if (Memory.cmp (_days, days, _days.length * sizeof (int)) == 0) {
+                return true;
+            }
+        }
+
+        return false;
     }
 
     public void reset () {
@@ -207,7 +238,7 @@ private class Item : Object {
             } else if (key == "minute") {
                 minute = v.get_child_value (1).get_child_value (0).get_int32 ();
             } else if (key == "days") {
-                // TODO
+                days = {}; //TODO
             }
         }
         if (name != null && hour > 0 && minute > 0) {


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