[gnome-clocks] timer: Add ability to enter mins/secs > 59
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-clocks] timer: Add ability to enter mins/secs > 59
- Date: Sat, 21 Feb 2015 08:35:41 +0000 (UTC)
commit e58772de45dda1f6cec42e29c9c3cfe53740c4a6
Author: Ankit <ankitstarski gmail com>
Date: Fri Feb 20 22:12:25 2015 +0530
timer: Add ability to enter mins/secs > 59
Linked 'input' signal of minutes and seconds field to its handler.
Apparently, Gtk.Entry.get_text() returns the actual value entered in
the spinner as opposed to the Gtk.Entry.get_value_as_int() which
returns the value after evaluating the range of spinner.
Then used these values to find overflow and carry to the next field.
https://bugzilla.gnome.org/show_bug.cgi?id=727827
data/ui/timer.ui | 2 ++
src/timer.vala | 38 ++++++++++++++++++++++++++++++++++++++
2 files changed, 40 insertions(+), 0 deletions(-)
---
diff --git a/data/ui/timer.ui b/data/ui/timer.ui
index cfee59c..40ff931 100644
--- a/data/ui/timer.ui
+++ b/data/ui/timer.ui
@@ -112,6 +112,7 @@
<property name="wrap">True</property>
<signal name="output" handler="show_leading_zeros" swapped="no"/>
<signal name="changed" handler="update_start_button" swapped="no"/>
+ <signal name="input" handler="input_minutes" swapped="no"/>
<style>
<class name="clocks-spinbutton"/>
</style>
@@ -154,6 +155,7 @@
<property name="wrap">True</property>
<signal name="output" handler="show_leading_zeros" swapped="no"/>
<signal name="changed" handler="update_start_button" swapped="no"/>
+ <signal name="input" handler="input_seconds" swapped="no"/>
<style>
<class name="clocks-spinbutton"/>
</style>
diff --git a/src/timer.vala b/src/timer.vala
index 358e4aa..918ca06 100644
--- a/src/timer.vala
+++ b/src/timer.vala
@@ -145,6 +145,44 @@ public class Face : Gtk.Stack, Clocks.Clock {
}
[GtkCallback]
+ private int input_minutes (Gtk.SpinButton spin_button, out double new_value) {
+ int entered_value = int.parse (spin_button.get_text ());
+
+ // if input entered is not within bounds then it will carry the
+ // extra portion to hours field
+ if (entered_value > 59) {
+ int current_hours = h_spinbutton.get_value_as_int ();
+ if (current_hours < 99) {
+ h_spinbutton.set_value (current_hours + entered_value / 60);
+ m_spinbutton.set_value (entered_value % 60);
+ }
+ }
+ return 0;
+ }
+
+ [GtkCallback]
+ private int input_seconds (Gtk.SpinButton spin_button, out double new_value) {
+ int entered_value = int.parse (spin_button.get_text ());
+
+ // if input entered is not within bounds then it will carry the
+ // extra portion to minutes field and hours field accordingly
+ if (entered_value > 59) {
+ int current_minutes = m_spinbutton.get_value_as_int ();
+ int new_minutes = current_minutes + entered_value / 60;
+ if (new_minutes > 59) {
+ int current_hours = h_spinbutton.get_value_as_int ();
+ if (current_hours < 99) {
+ h_spinbutton.set_value (current_hours + new_minutes / 60);
+ new_minutes = new_minutes % 60;
+ }
+ }
+ m_spinbutton.set_value (new_minutes);
+ s_spinbutton.set_value (entered_value % 60);
+ }
+ return 0;
+ }
+
+ [GtkCallback]
private void update_start_button () {
var h = h_spinbutton.get_value_as_int ();
var m = m_spinbutton.get_value_as_int ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]