[gnome-clocks/bilelmoussaoui/redesign-timer] Timer: bind the NewTimerDialog
- From: Bilal Elmoussaoui <bilelmoussaoui src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-clocks/bilelmoussaoui/redesign-timer] Timer: bind the NewTimerDialog
- Date: Tue, 28 Jan 2020 04:24:40 +0000 (UTC)
commit b766bc86ff01e5bc84e28d21ca9c341c9b82f85c
Author: Bilal Elmoussaoui <bil elmoussaoui gmail com>
Date: Tue Jan 28 05:24:15 2020 +0100
Timer: bind the NewTimerDialog
data/ui/timer_setup.ui | 6 ++--
src/timer.vala | 82 ++++++++++++++++++++------------------------------
2 files changed, 36 insertions(+), 52 deletions(-)
---
diff --git a/data/ui/timer_setup.ui b/data/ui/timer_setup.ui
index 713ac59..700b916 100644
--- a/data/ui/timer_setup.ui
+++ b/data/ui/timer_setup.ui
@@ -223,7 +223,7 @@
<property name="adjustment">adjustment_hours</property>
<property name="numeric">True</property>
<property name="wrap">True</property>
- <signal name="changed" handler="update_start_button" swapped="no"/>
+ <signal name="changed" handler="update_duration" swapped="no"/>
<signal name="output" handler="show_leading_zeros" swapped="no"/>
<style>
<class name="clocks-spinbutton"/>
@@ -263,7 +263,7 @@
<property name="adjustment">adjustment_minutes</property>
<property name="numeric">True</property>
<property name="wrap">True</property>
- <signal name="changed" handler="update_start_button" swapped="no"/>
+ <signal name="changed" handler="update_duration" swapped="no"/>
<signal name="input" handler="input_minutes" swapped="no"/>
<signal name="output" handler="show_leading_zeros" swapped="no"/>
<style>
@@ -304,7 +304,7 @@
<property name="adjustment">adjustment_seconds</property>
<property name="numeric">True</property>
<property name="wrap">True</property>
- <signal name="changed" handler="update_start_button" swapped="no"/>
+ <signal name="changed" handler="update_duration" swapped="no"/>
<signal name="input" handler="input_seconds" swapped="no"/>
<signal name="output" handler="show_leading_zeros" swapped="no"/>
<style>
diff --git a/src/timer.vala b/src/timer.vala
index e316f71..0c01440 100644
--- a/src/timer.vala
+++ b/src/timer.vala
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2013 Paolo Borelli <pborelli gnome org>
- *
+ * Copyright (C) 2020 Bilal Elmoussaoui <bilal elmoussaoui gnome org>
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
@@ -30,10 +30,8 @@ public class Duration: Object {
rest = s - hours * 3600;
minutes = rest / 60;
seconds = rest - minutes * 60;
-
}
-
public Duration (int h, int m, int s) {
hours = h;
minutes = m;
@@ -43,24 +41,14 @@ public class Duration: Object {
public int get_total_seconds () {
return hours * 3600 + minutes * 60 + seconds;
}
-
-
}
+
public class Item : Object, ContentItem {
public bool selectable { get; set; default = false; }
public bool selected { get; set; default = false; }
- public string name {
- get {
- return _name;
- }
- set {
- // ignored
- }
- }
-
- private string _name;
+ public string name { get ; set; }
public Duration duration { get; set; }
public void serialize (GLib.VariantBuilder builder) {
@@ -96,14 +84,14 @@ public class Item : Object, ContentItem {
}
}
-public class NewTimerDialog: Hdy.Dialog {
+public class NewTimerDialog: Hdy.Dialog {
private new Gtk.Button add_button;
private Gtk.Button cancel_button;
- private Setup timer_setup;
+ public Setup timer_setup;
- public NewTimerDialog (Gtk.Window parent, Item? timer) {
- Object (transient_for: parent, title: timer != null ? _("Edit Timer") : _("New Timer"),
use_header_bar: 1);
+ public NewTimerDialog (Gtk.Window parent) {
+ Object (transient_for: parent, title: _("New Timer"), use_header_bar: 1);
this.set_default_size (640, 360);
var headerbar = (Gtk.HeaderBar)this.get_header_bar ();
@@ -113,6 +101,7 @@ public class NewTimerDialog: Hdy.Dialog {
add_button.get_style_context ().add_class ("suggested-action");
add_button.set_sensitive (false);
add_button.show ();
+ add_button.clicked.connect( () => this.response (Gtk.ResponseType.ACCEPT));
headerbar.pack_end (add_button);
cancel_button = new Gtk.Button.with_label (_("Cancel"));
@@ -122,14 +111,16 @@ public class NewTimerDialog: Hdy.Dialog {
timer_setup = new Setup ();
this.get_content_area ().add (timer_setup);
-
-
+ timer_setup.duration_changed.connect ((duration) => {
+ add_button.set_sensitive (duration.get_total_seconds () != 0);
+ });
}
}
[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;
@@ -166,16 +157,18 @@ public class Setup : Gtk.Box {
}
- public Item get_timer() {
- var h = this.h_spinbutton.get_value();
- var m = this.m_spinbutton.get_value();
- var s = this.s_spinbutton.get_value();
- int total_seconds = (int)(h * 3600 + m * 60 + s);
+ public Duration get_duration () {
+ int h = (int)this.h_spinbutton.get_value();
+ int m = (int)this.m_spinbutton.get_value();
+ int s = (int)this.s_spinbutton.get_value();
- var duration = new Duration.from_seconds(total_seconds);
- return (new Item (duration, ""));
+ var duration = new Duration(h, m, s);
+ return duration;
}
+ public Item get_timer() {
+ return (new Item (get_duration (), ""));
+ }
private void update_timer(int h, int m, int s) {
this.h_spinbutton.set_value(h);
@@ -183,23 +176,17 @@ public class Setup : Gtk.Box {
this.s_spinbutton.set_value(s);
}
+ [GtkCallback]
+ private void update_duration() {
+ var duration = get_duration ();
+ duration_changed (duration);
+ }
+
[GtkCallback]
private bool show_leading_zeros (Gtk.SpinButton spin_button) {
spin_button.set_text ("%02i".printf(spin_button.get_value_as_int ()));
return true;
}
- [GtkCallback]
- private void update_start_button () {
- /* var h = h_spinbutton.get_value_as_int ();
- var m = m_spinbutton.get_value_as_int ();
- var s = s_spinbutton.get_value_as_int ();
-
- if (h != 0 || m != 0 || s != 0) {
- start_button.set_sensitive (true);
- } else {
- start_button.set_sensitive (false);
- }*/
- }
[GtkCallback]
private int input_minutes (Gtk.SpinButton spin_button, out double new_value) {
@@ -236,8 +223,6 @@ public class Setup : Gtk.Box {
new_value = entered_value % 60;
return 1;
}
-
-
}
@@ -289,7 +274,6 @@ public class Row : Gtk.Box {
reset ();
}
-
[GtkCallback]
private void on_start_button_clicked () {
switch (state) {
@@ -412,6 +396,7 @@ public class Row : Gtk.Box {
}
}
+
[GtkTemplate (ui = "/org/gnome/clocks/ui/timer.ui")]
public class Face : Gtk.Stack, Clocks.Clock {
public enum State {
@@ -486,13 +471,12 @@ public class Face : Gtk.Stack, Clocks.Clock {
public void activate_new () {
- var dialog = new NewTimerDialog ((Gtk.Window) get_toplevel (), null);
+ var dialog = new NewTimerDialog ((Gtk.Window) get_toplevel ());
dialog.response.connect ((dialog, response) => {
- if (response == 1) {
- /* var alarm = new Item ();
- ((SetupDialog) dialog).apply_to_alarm (alarm);
- alarms.add (alarm);
- save ();*/
+ if (response == Gtk.ResponseType.ACCEPT) {
+ var timer = ((NewTimerDialog) dialog).timer_setup.get_timer ();
+ timers.add (timer);
+ save ();
}
dialog.destroy ();
});
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]