[gnome-clocks/wip/vala] Alarm: Allow to edit/create alarms (in progress) Not completely working yet, more to follow here



commit 8adc51169f5652e7ec1843f1e17fd50f78058032
Author: Volker Sobek <reklov live com>
Date:   Wed Feb 13 22:59:58 2013 +0100

    Alarm: Allow to edit/create alarms (in progress)
    Not completely working yet, more to follow here
    
    NOTE: I added a switch to the alarm dialog for now, to allow testing
    of this functionality. It's not an implementation of any official
    design by the designers.

 egg-list-box   |    1 -
 src/alarm.ui   |  138 +++++++++++++++++++++++++++++++-------------------------
 src/alarm.vala |   82 +++++++++++++++++++++++++++------
 3 files changed, 144 insertions(+), 77 deletions(-)
---
diff --git a/src/alarm.ui b/src/alarm.ui
index 61437f3..2f21be6 100644
--- a/src/alarm.ui
+++ b/src/alarm.ui
@@ -114,29 +114,77 @@
       </packing>
     </child>
     <child>
-      <object class="GtkLabel" id="name_label">
+      <object class="GtkBox" id="time_box">
         <property name="visible">True</property>
         <property name="can_focus">False</property>
-        <property name="xalign">1</property>
-        <property name="label" translatable="yes">Name</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">True</property>
+            <property name="fill">True</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="label1">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="label" translatable="yes">:</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+        <child>
+          <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">True</property>
+            <property name="fill">True</property>
+            <property name="position">2</property>
+          </packing>
+        </child>
       </object>
       <packing>
-        <property name="left_attach">0</property>
-        <property name="top_attach">1</property>
+        <property name="left_attach">1</property>
+        <property name="top_attach">0</property>
         <property name="width">1</property>
         <property name="height">1</property>
       </packing>
     </child>
     <child>
-      <object class="GtkLabel" id="repeat_label">
+      <object class="GtkLabel" id="name_label">
         <property name="visible">True</property>
         <property name="can_focus">False</property>
         <property name="xalign">1</property>
-        <property name="label" translatable="yes">Repeat Every</property>
+        <property name="label" translatable="yes">Name</property>
       </object>
       <packing>
         <property name="left_attach">0</property>
-        <property name="top_attach">2</property>
+        <property name="top_attach">1</property>
         <property name="width">1</property>
         <property name="height">1</property>
       </packing>
@@ -156,6 +204,20 @@
       </packing>
     </child>
     <child>
+      <object class="GtkLabel" id="repeat_label">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="xalign">1</property>
+        <property name="label" translatable="yes">Repeat Every</property>
+      </object>
+      <packing>
+        <property name="left_attach">0</property>
+        <property name="top_attach">2</property>
+        <property name="width">1</property>
+        <property name="height">1</property>
+      </packing>
+    </child>
+    <child>
       <object class="GtkBox" id="day_buttons_box">
         <property name="visible">True</property>
         <property name="can_focus">False</property>
@@ -181,66 +243,20 @@
       </packing>
     </child>
     <child>
-      <object class="GtkBox" id="time_box">
+      <object class="GtkSwitch" id="active_switch">
         <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">True</property>
-            <property name="fill">True</property>
-            <property name="position">0</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkLabel" id="label1">
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="label" translatable="yes">:</property>
-          </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">True</property>
-            <property name="position">1</property>
-          </packing>
-        </child>
-        <child>
-          <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">True</property>
-            <property name="fill">True</property>
-            <property name="position">2</property>
-          </packing>
-        </child>
+        <property name="can_focus">True</property>
+        <property name="halign">end</property>
       </object>
       <packing>
         <property name="left_attach">1</property>
-        <property name="top_attach">0</property>
+        <property name="top_attach">3</property>
         <property name="width">1</property>
         <property name="height">1</property>
       </packing>
     </child>
+    <child>
+      <placeholder/>
+    </child>
   </object>
 </interface>
diff --git a/src/alarm.vala b/src/alarm.vala
index 3178c3c..40b26c5 100644
--- a/src/alarm.vala
+++ b/src/alarm.vala
@@ -29,9 +29,18 @@ private class Item : Object {
         SNOOZING
     }
 
-    public string name { get; construct; }
-    public int hour { get; construct; }
-    public int minute { get; construct; }
+    private string _name;
+    public string name {
+        get {
+            return _name;
+        }
+        set {
+            _name = value;
+            bell = new Utils.Bell ("alarm-clock-elapsed", _("Alarm"), value);
+        }
+    }
+    public int hour { get; set; }
+    public int minute { get; set; }
 
     // FIXME
     public int[] days { get; set; }
@@ -73,7 +82,7 @@ private class Item : Object {
     private GLib.DateTime ring_end_time;
     private Utils.Bell bell;
 
-    public Item (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);
 
         bell = new Utils.Bell ("alarm-clock-elapsed", _("Alarm"), name);
@@ -81,6 +90,10 @@ private class Item : Object {
         reset ();
     }
 
+    public Item () {
+        bell = new Utils.Bell ("alarm-clock-elapsed", _("Alarm"), "");
+    }
+
     public bool equal (Item a) {
         return a.name == name && a.hour == hour && a.minute == minute && compare_days ();
     }
@@ -90,7 +103,7 @@ private class Item : Object {
         return true;
     }
 
-    private void reset () {
+    public void reset () {
         update_alarm_time ();
         update_snooze_time (alarm_time);
         state = State.READY;
@@ -192,7 +205,7 @@ private class Item : Object {
             }
         }
         if (name != null && hour > 0 && minute > 0) {
-            return new Item (name, active, hour, minute, days);
+            return new Item.with_data (name, active, hour, minute, days);
         }
         return null;
     }
@@ -205,6 +218,8 @@ private class SetupDialog : Gtk.Dialog {
     private Gtk.Entry name_entry;
     private AmPmToggleButton am_pm_button;
     private Gtk.ToggleButton[] day_buttons;
+    private Gtk.Switch active_switch;
+    private Item alarm;
 
     public SetupDialog (Gtk.Window parent, Item? alarm) {
         Object (transient_for: parent, modal: true, title: _("New Alarm"));
@@ -223,6 +238,7 @@ private class SetupDialog : Gtk.Dialog {
         h_spinbutton = builder.get_object ("h_spinbutton") as Gtk.SpinButton;
         m_spinbutton = builder.get_object ("m_spinbutton") as Gtk.SpinButton;
         name_entry = builder.get_object ("name_entry") as Gtk.Entry;
+        active_switch = builder.get_object ("active_switch") as Gtk.Switch;
         assert (builder != null && grid != null && time_box != null &&
                 day_buttons_box != null && h_spinbutton != null &&
                 m_spinbutton != null && name_entry != null);
@@ -257,28 +273,30 @@ private class SetupDialog : Gtk.Dialog {
         }
 
         get_content_area ().add (grid);
-        set_alarm_item (alarm);
-        show_all ();
+        set_from_alarm (alarm);
     }
 
-    public void set_alarm_item (Item? alarm) {
+    // Sets up the dialog to show the values of alarm.
+    public void set_from_alarm (Item? alarm) {
         string name;
         bool active;
         int hour;
         int minute;
         int[] days;
-        var wc = Utils.WallClock.get_default ();
 
+        var wc = Utils.WallClock.get_default ();
         if (alarm == null) {
             name = _("New Alarm");
             hour = wc.date_time.get_hour();
             minute = wc.date_time.get_minute();
-            days = null;
+            days = {};
+            active = true;
         } else {
             name = alarm.name;
             hour = alarm.hour;
             minute = alarm.minute;
             days = alarm.days;
+            active = alarm.active;
         }
 
         // Set the time.
@@ -304,10 +322,15 @@ private class SetupDialog : Gtk.Dialog {
         for (int i = 0; i < days.length; i++) {
             day_buttons[days[i]].active = true;
         }
+
+        // Set On/Off switch.
+        active_switch.active = active;
     }
 
-    public Item get_alarm_item () {
+    // Sets alarm according to the current dialog settings.
+    public void apply_to_alarm (Item alarm) {
         var name = name_entry.get_text();
+        var active = active_switch.active;
         var hour = h_spinbutton.get_value_as_int ();
         var minute = m_spinbutton.get_value_as_int ();
         if (format == Utils.WallClock.Format.TWELVE) {
@@ -326,7 +349,11 @@ private class SetupDialog : Gtk.Dialog {
             }
         }
 
-        return new Item (name, true, hour, minute, days);
+        alarm.name = name;
+        alarm.active = active;
+        alarm.hour = hour;
+        alarm.minute = minute;
+        alarm.days = days;
     }
 
     private bool show_leading_zeros (Gtk.SpinButton spin_button) {
@@ -339,6 +366,11 @@ private class StandalonePanel : Gtk.EventBox {
     public Item alarm { get; set; }
 
     public StandalonePanel () {
+        get_style_context ().add_class ("view");
+        get_style_context ().add_class ("content-view");
+
+        var builder = Utils.load_ui ("alarm.ui");
+        var grid = builder.get_object ("ringing_panel") as Gtk.Grid;
     }
 
     public void update () {
@@ -381,6 +413,24 @@ public class MainPanel : Gd.Stack, Clocks.Clock {
             renderer.css_class = alarm.active ? "active" : "inactive";
         });
 
+        icon_view.item_activated.connect ((path) => {
+                Gtk.TreeIter i;
+                if (list_store.get_iter (out i, path)) {
+                    Item alarm;
+                    list_store.get (i, Column.ITEM, out alarm);
+                    var dialog = new SetupDialog ((Gtk.Window) get_toplevel (), alarm);
+                    dialog.response.connect ((dialog, response) => {
+                            if (response == 1) {
+                                ((SetupDialog) dialog).apply_to_alarm (alarm);
+                                alarm.reset ();
+                            }
+                            dialog.destroy ();
+                        });
+                    dialog.show_all ();
+                }
+            });
+
+
         content_view = new ContentView (icon_view, "alarm-symbolic", _("Select <b>New</b> to add an alarm"));
         add (content_view);
 
@@ -441,12 +491,14 @@ public class MainPanel : Gd.Stack, Clocks.Clock {
         var dialog = new SetupDialog ((Gtk.Window) get_toplevel (), null);
         dialog.response.connect ((dialog, response) => {
             if (response == 1) {
-                var alarm = ((SetupDialog) dialog).get_alarm_item ();
+                var alarm = new Item ();
+                ((SetupDialog) dialog).apply_to_alarm (alarm);
                 add_alarm (alarm);
+                alarm.reset();
             }
             dialog.destroy ();
         });
-        dialog.show ();
+        dialog.show_all ();
     }
 
     public void update_toolbar () {


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