[gnome-clocks/bilelmoussaoui/redesign-timer] Timer: using actions & remove unneded code



commit 9d1914524567b6b817635377a0bf6b5b67117a6c
Author: Bilal Elmoussaoui <bil elmoussaoui gmail com>
Date:   Tue Jan 28 16:37:17 2020 +0100

    Timer: using actions & remove unneded code

 data/ui/timer_setup.ui | 34 +++++++++++++++++++++--------
 src/timer.vala         | 59 ++++++++++++--------------------------------------
 2 files changed, 39 insertions(+), 54 deletions(-)
---
diff --git a/data/ui/timer_setup.ui b/data/ui/timer_setup.ui
index 700b916..213fb69 100644
--- a/data/ui/timer_setup.ui
+++ b/data/ui/timer_setup.ui
@@ -47,7 +47,7 @@
                 <property name="row_spacing">12</property>
                 <property name="column_spacing">12</property>
                 <child>
-                  <object class="GtkButton" id="predefined_1m">
+                  <object class="GtkButton">
                     <property name="label" translatable="yes">1 m</property>
                     <property name="width_request">70</property>
                     <property name="height_request">40</property>
@@ -56,6 +56,8 @@
                     <property name="receives_default">True</property>
                     <property name="halign">center</property>
                     <property name="valign">center</property>
+                    <property name="action_name">timer-setup.set-duration</property>
+                    <property name="action_target">1</property>
                   </object>
                   <packing>
                     <property name="left_attach">0</property>
@@ -63,7 +65,7 @@
                   </packing>
                 </child>
                 <child>
-                  <object class="GtkButton" id="predefined_2m">
+                  <object class="GtkButton">
                     <property name="label" translatable="yes">2 m</property>
                     <property name="width_request">70</property>
                     <property name="height_request">40</property>
@@ -72,6 +74,8 @@
                     <property name="receives_default">True</property>
                     <property name="halign">center</property>
                     <property name="valign">center</property>
+                    <property name="action_name">timer-setup.set-duration</property>
+                    <property name="action_target">2</property>
                   </object>
                   <packing>
                     <property name="left_attach">1</property>
@@ -79,7 +83,7 @@
                   </packing>
                 </child>
                 <child>
-                  <object class="GtkButton" id="predefined_3m">
+                  <object class="GtkButton">
                     <property name="label" translatable="yes">3 m</property>
                     <property name="width_request">70</property>
                     <property name="height_request">40</property>
@@ -88,6 +92,8 @@
                     <property name="receives_default">True</property>
                     <property name="halign">center</property>
                     <property name="valign">center</property>
+                    <property name="action_name">timer-setup.set-duration</property>
+                    <property name="action_target">3</property>
                   </object>
                   <packing>
                     <property name="left_attach">2</property>
@@ -95,7 +101,7 @@
                   </packing>
                 </child>
                 <child>
-                  <object class="GtkButton" id="predefined_5m">
+                  <object class="GtkButton">
                     <property name="label" translatable="yes">5 m</property>
                     <property name="width_request">70</property>
                     <property name="height_request">40</property>
@@ -104,6 +110,8 @@
                     <property name="receives_default">True</property>
                     <property name="halign">center</property>
                     <property name="valign">center</property>
+                    <property name="action_name">timer-setup.set-duration</property>
+                    <property name="action_target">5</property>
                   </object>
                   <packing>
                     <property name="left_attach">3</property>
@@ -111,7 +119,7 @@
                   </packing>
                 </child>
                 <child>
-                  <object class="GtkButton" id="predefined_30m">
+                  <object class="GtkButton">
                     <property name="label" translatable="yes">30 m</property>
                     <property name="width_request">70</property>
                     <property name="height_request">40</property>
@@ -120,6 +128,8 @@
                     <property name="receives_default">True</property>
                     <property name="halign">center</property>
                     <property name="valign">center</property>
+                    <property name="action_name">timer-setup.set-duration</property>
+                    <property name="action_target">30</property>
                   </object>
                   <packing>
                     <property name="left_attach">1</property>
@@ -127,7 +137,7 @@
                   </packing>
                 </child>
                 <child>
-                  <object class="GtkButton" id="predefined_15m">
+                  <object class="GtkButton">
                     <property name="label" translatable="yes">15 m</property>
                     <property name="width_request">70</property>
                     <property name="height_request">40</property>
@@ -136,6 +146,8 @@
                     <property name="receives_default">True</property>
                     <property name="halign">center</property>
                     <property name="valign">center</property>
+                    <property name="action_name">timer-setup.set-duration</property>
+                    <property name="action_target">15</property>
                   </object>
                   <packing>
                     <property name="left_attach">0</property>
@@ -143,7 +155,7 @@
                   </packing>
                 </child>
                 <child>
-                  <object class="GtkButton" id="predefined_45m">
+                  <object class="GtkButton">
                     <property name="label" translatable="yes">45 m</property>
                     <property name="width_request">70</property>
                     <property name="height_request">40</property>
@@ -152,6 +164,8 @@
                     <property name="receives_default">True</property>
                     <property name="halign">center</property>
                     <property name="valign">center</property>
+                    <property name="action_name">timer-setup.set-duration</property>
+                    <property name="action_target">45</property>
                   </object>
                   <packing>
                     <property name="left_attach">2</property>
@@ -159,8 +173,8 @@
                   </packing>
                 </child>
                 <child>
-                  <object class="GtkButton" id="predefined_1h">
-                    <property name="label" translatable="yes">1 h</property>
+                  <object class="GtkButton">
+                    <property name="label">1 h</property>
                     <property name="width_request">70</property>
                     <property name="height_request">40</property>
                     <property name="visible">True</property>
@@ -168,6 +182,8 @@
                     <property name="receives_default">True</property>
                     <property name="halign">center</property>
                     <property name="valign">center</property>
+                    <property name="action_name">timer-setup.set-duration</property>
+                    <property name="action_target">60</property>
                   </object>
                   <packing>
                     <property name="left_attach">3</property>
diff --git a/src/timer.vala b/src/timer.vala
index 4513bb9..7875839 100644
--- a/src/timer.vala
+++ b/src/timer.vala
@@ -107,23 +107,6 @@ public class NewTimerDialog: Hdy.Dialog {
 [GtkTemplate (ui = "/org/gnome/clocks/ui/timer_setup.ui")]
 public class Setup : Gtk.Box {
     public signal void duration_changed (Duration duration);
-
-    [GtkChild]
-    private Gtk.Button predefined_1m;
-    [GtkChild]
-    private Gtk.Button predefined_2m;
-    [GtkChild]
-    private Gtk.Button predefined_3m;
-    [GtkChild]
-    private Gtk.Button predefined_5m;
-    [GtkChild]
-    private Gtk.Button predefined_15m;
-    [GtkChild]
-    private Gtk.Button predefined_30m;
-    [GtkChild]
-    private Gtk.Button predefined_45m;
-    [GtkChild]
-    private Gtk.Button predefined_1h;
     [GtkChild]
     private Gtk.SpinButton h_spinbutton;
     [GtkChild]
@@ -132,14 +115,19 @@ public class Setup : Gtk.Box {
     private Gtk.SpinButton s_spinbutton;
 
     public Setup() {
-        predefined_1m.clicked.connect(() => this.update_timer(0, 1, 0));
-        predefined_2m.clicked.connect(() => this.update_timer(0, 2, 0));
-        predefined_3m.clicked.connect(() => this.update_timer(0, 3, 0));
-        predefined_5m.clicked.connect(() => this.update_timer(0, 5, 0));
-        predefined_15m.clicked.connect(() => this.update_timer(0, 15, 0));
-        predefined_30m.clicked.connect(() => this.update_timer(0, 30, 0));
-        predefined_45m.clicked.connect(() => this.update_timer(0, 45, 0));
-        predefined_1h.clicked.connect(() => this.update_timer(1, 0, 0));
+        var actions = new SimpleActionGroup ();
+        // The duration here represends a number of minutes
+        var duration_type = new GLib.VariantType ("i");
+        var set_duration_action = new SimpleAction ("set-duration", duration_type);
+        set_duration_action.activate.connect ((action, param) => {
+            var total_minutes = param.get_int32();
+            var hours = total_minutes / 60;
+            var minutes = total_minutes - hours * 60;
+            this.h_spinbutton.set_value(hours);
+            this.m_spinbutton.set_value(minutes);
+        });
+        actions.add_action (set_duration_action);
+        insert_action_group ("timer-setup", actions);
 
     }
 
@@ -156,12 +144,6 @@ public class Setup : Gtk.Box {
         return (new Item (get_duration (), ""));
     }
 
-    private void update_timer(int h, int m, int s) {
-        this.h_spinbutton.set_value(h);
-        this.m_spinbutton.set_value(m);
-        this.s_spinbutton.set_value(s);
-    }
-
     [GtkCallback]
     private void update_duration() {
         var duration = get_duration ();
@@ -214,7 +196,6 @@ public class Setup : Gtk.Box {
 
 [GtkTemplate (ui = "/org/gnome/clocks/ui/timer_row.ui")]
 public class Row : Gtk.ListBoxRow {
-    public signal void ringing ();
     public enum State {
         STOPPED,
         RUNNING,
@@ -265,12 +246,12 @@ public class Row : Gtk.ListBoxRow {
     private Gtk.Button pause_button;
     [GtkChild]
     private Gtk.Button start_button;
-
     [GtkChild]
     private Gtk.Entry title;
 
     public signal void deleted ();
     public signal void edited ();
+    public signal void ringing ();
 
 
     public Row (Item item) {
@@ -420,17 +401,6 @@ public class Row : Gtk.ListBoxRow {
             timer_name.label = _("%i minutes timer".printf(item.duration.minutes));
         }
     }
-
-    public override void grab_focus () {
-        /*if (timer_stack.visible_child == setup_frame) {
-            start_button.grab_focus ();
-        }*/
-    }
-
-    public bool escape_pressed () {
-
-        return true;
-    }
 }
 
 
@@ -547,7 +517,6 @@ public class Face : Gtk.Stack, Clocks.Clock {
         bell.ring_once ();
     }
 
-
     public override void grab_focus () {
         /*if (visible_child == setup_frame) {
             start_button.grab_focus ();


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