[gnome-clocks] Store last used timer in gsettings



commit 6d93d6976e35bfa2d34480905bb9c94eedde0949
Author: Paolo Borelli <pborelli gnome org>
Date:   Mon Mar 4 21:02:46 2013 +0100

    Store last used timer in gsettings
    
    Also default to a 5 minute timer.

 data/org.gnome.clocks.gschema.xml.in |    7 +++++++
 src/alarm.vala                       |    2 +-
 src/timer.vala                       |   17 +++++++++++------
 src/world.vala                       |    2 +-
 4 files changed, 20 insertions(+), 8 deletions(-)
---
diff --git a/data/org.gnome.clocks.gschema.xml.in b/data/org.gnome.clocks.gschema.xml.in
index ec38d29..4f9eb25 100644
--- a/data/org.gnome.clocks.gschema.xml.in
+++ b/data/org.gnome.clocks.gschema.xml.in
@@ -14,5 +14,12 @@
         List of alarms set.
       </_description>
     </key>
+    <key name="timer" type="u">
+      <default>300</default>
+      <_summary>Timer</_summary>
+      <_description>
+        Configured timer duration in seconds.
+      </_description>
+    </key>
   </schema>
 </schemalist>
diff --git a/src/alarm.vala b/src/alarm.vala
index 28e95d8..86010f3 100644
--- a/src/alarm.vala
+++ b/src/alarm.vala
@@ -475,7 +475,7 @@ public class MainPanel : Gd.Stack, Clocks.Clock {
         Object (label: _("Alarm"), toolbar: toolbar);
 
         alarms = new List<Item> ();
-        settings = new GLib.Settings("org.gnome.clocks");
+        settings = new GLib.Settings ("org.gnome.clocks");
 
         var builder = Utils.load_ui ("alarm.ui");
         var empty_view = builder.get_object ("empty_panel") as Gtk.Widget;
diff --git a/src/timer.vala b/src/timer.vala
index d94e411..887582d 100644
--- a/src/timer.vala
+++ b/src/timer.vala
@@ -30,6 +30,7 @@ public class MainPanel : Gd.Stack, Clocks.Clock {
     public Toolbar toolbar { get; construct set; }
 
     private State state;
+    private GLib.Settings settings;
     private uint timeout_id;
     private Utils.Bell bell;
     private Gtk.Widget setup_panel;
@@ -47,6 +48,8 @@ public class MainPanel : Gd.Stack, Clocks.Clock {
     public MainPanel (Toolbar toolbar) {
         Object (label: _("Timer"), toolbar: toolbar, transition_type: Gd.StackTransitionType.CROSSFADE);
 
+        settings = new GLib.Settings ("org.gnome.clocks");
+
         bell = new Utils.Bell ("complete", _("Time is up!"), _("Timer countdown finished"));
 
         timeout_id = 0;
@@ -136,11 +139,11 @@ public class MainPanel : Gd.Stack, Clocks.Clock {
         state = State.STOPPED;
         timer.reset ();
         remove_timeout ();
-        span = 0;
-        h_spinbutton.value = 0;
-        m_spinbutton.value = 0;
-        s_spinbutton.value = 0;
-        start_button.set_sensitive (false);
+        span = settings.get_uint ("timer");
+        h_spinbutton.value = (int) span / 3600;
+        m_spinbutton.value = (int) span / 60;
+        s_spinbutton.value = span % 60;
+        start_button.set_sensitive (span > 0);
         visible_child = setup_panel;
     }
 
@@ -152,8 +155,10 @@ public class MainPanel : Gd.Stack, Clocks.Clock {
 
             state = State.RUNNING;
             span = h * 3600 + m * 60 + s;
-            timer.start ();
 
+            settings.set_uint ("timer", (uint) span);
+
+            timer.start ();
             visible_child = countdown_panel;
 
             update_countdown_label (h, m, s);
diff --git a/src/world.vala b/src/world.vala
index 07d3630..f0ea607 100644
--- a/src/world.vala
+++ b/src/world.vala
@@ -256,7 +256,7 @@ public class MainPanel : Gd.Stack, Clocks.Clock {
         Object (label: _("World"), toolbar: toolbar, transition_type: Gd.StackTransitionType.CROSSFADE);
 
         locations = new List<Item> ();
-        settings = new GLib.Settings("org.gnome.clocks");
+        settings = new GLib.Settings ("org.gnome.clocks");
 
         day_pixbuf = Utils.load_image ("day.png");
         night_pixbuf = Utils.load_image ("night.png");


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