[gnome-clocks] Disabling multiple alarm for the same time
- From: Evgeny Bobkin <ebobkin src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-clocks] Disabling multiple alarm for the same time
- Date: Mon, 10 Feb 2014 19:10:12 +0000 (UTC)
commit 629cdb6c9e8e47ec0ad619c72785a53ea04b9d9d
Author: Saurabh_P <srp201201051 gmail com>
Date: Mon Feb 10 23:50:59 2014 +0530
Disabling multiple alarm for the same time
Connect signals for state(value) change of spinbuttons and active_switch in
alarmsetupdialog.ui file and for day-toggle buttons in SetupDialog class.
Add GtkRevealer in ui file and add one GtkLabel as its child and initialize
it not to reveal child. If any signal emits then store dialogbox information
in temporary alarm item and check it with all the alarms(passed as an argument
to SetupDialog class constructor) and check if there exists any alarm for
the same time and it is activated. If there is a duplicate alarm then reveal
the warning label and make done button insensitive otherwise make it sensitive.
https://bugzilla.gnome.org/show_bug.cgi?id=697659
data/ui/alarmsetupdialog.ui | 26 +++++++++++++++++++++++-
src/alarm.vala | 44 ++++++++++++++++++++++++++++++++++++++++--
2 files changed, 65 insertions(+), 5 deletions(-)
---
diff --git a/data/ui/alarmsetupdialog.ui b/data/ui/alarmsetupdialog.ui
index 9cc4d54..fd791fd 100644
--- a/data/ui/alarmsetupdialog.ui
+++ b/data/ui/alarmsetupdialog.ui
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.15.2 on Mon Jul 22 18:18:00 2013 -->
+<!-- Generated with glade 3.16.0 -->
<interface>
- <!-- interface-requires gtk+ 3.10 -->
+ <requires lib="gtk+" version="3.10"/>
<object class="GtkAdjustment" id="h_adjustment">
<property name="upper">100</property>
<property name="step_increment">1</property>
@@ -135,6 +135,7 @@
<property name="numeric">True</property>
<property name="wrap">True</property>
<signal name="output" handler="show_leading_zeros" object="ClocksAlarmSetupDialog"
swapped="no"/>
+ <signal name="value-changed" handler="avert_duplicate_alarm" swapped="no"/>
</object>
<packing>
<property name="left_attach">3</property>
@@ -180,6 +181,7 @@
<property name="numeric">True</property>
<property name="wrap">True</property>
<signal name="output" handler="show_leading_zeros" object="ClocksAlarmSetupDialog"
swapped="no"/>
+ <signal name="value-changed" handler="avert_duplicate_alarm" swapped="no"/>
</object>
<packing>
<property name="left_attach">1</property>
@@ -197,6 +199,25 @@
</packing>
</child>
<child>
+ <object class="GtkRevealer" id="label_revealer">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkLabel" id="warn_label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">You already have an alarm for this
time.</property>
+ </object>
+ </child>
+ </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="GtkGrid" id="grid2">
<property name="visible">True</property>
<property name="can_focus">False</property>
@@ -295,6 +316,7 @@
<property name="can_focus">True</property>
<property name="halign">start</property>
<property name="valign">center</property>
+ <signal name="state-flags-changed" handler="avert_duplicate_alarm" swapped="no"/>
</object>
<packing>
<property name="left_attach">1</property>
diff --git a/src/alarm.vala b/src/alarm.vala
index 22786fc..bcab3f5 100644
--- a/src/alarm.vala
+++ b/src/alarm.vala
@@ -180,6 +180,20 @@ private class Item : Object, ContentItem {
state = State.READY;
}
+ public bool compare_with_item (Item i) {
+ return (this.alarm_time.compare (i.alarm_time) == 0 && this.active && i.active);
+ }
+
+ public bool check_duplicate_alarm (List<Item> alarms_list) {
+ update_alarm_time ();
+ foreach (Item i in alarms_list) {
+ if (compare_with_item (i)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
// Update the state and ringing time. Ring or stop
// depending on the current time.
// Returns true if the state changed, false otherwise.
@@ -285,11 +299,16 @@ private class SetupDialog : Gtk.Dialog {
[GtkChild]
private Gtk.Alignment am_pm_alignment;
[GtkChild]
+ private Gtk.Revealer label_revealer;
+ [GtkChild]
private Gtk.SizeGroup am_pm_sizegroup;
+ private unowned List<Item> alarms_list;
- public SetupDialog (Gtk.Window parent, Item? alarm) {
+ public SetupDialog (Gtk.Window parent, Item? alarm, List<Item> alarms) {
Object (transient_for: parent, title: alarm != null ? _("Edit Alarm") : _("New Alarm"));
+ alarms_list = alarms;
+
// Force LTR since we do not want to reverse [hh] : [mm]
time_grid.set_direction (Gtk.TextDirection.LTR);
@@ -309,10 +328,15 @@ private class SetupDialog : Gtk.Dialog {
// Create an array with the weekday buttons with
// day_buttons[0] referencing the button for Monday, and so on.
+ // Also declare toogled signal connection.
day_buttons = new Gtk.ToggleButton[7];
for (int i = 0; i < 7; i++) {
var button = new Gtk.ToggleButton.with_label (Utils.Weekdays.abbreviation ((Utils.Weekdays.Day)
i));
day_buttons[i] = button;
+
+ day_buttons[i].toggled.connect (() => {
+ avert_duplicate_alarm ();
+ });
}
// Pack the buttons, starting with the first day of the week
@@ -326,6 +350,20 @@ private class SetupDialog : Gtk.Dialog {
set_from_alarm (alarm);
}
+ [GtkCallback]
+ private void avert_duplicate_alarm () {
+ var alarm = new Item ();
+ apply_to_alarm (alarm);
+
+ if (alarm.check_duplicate_alarm (alarms_list)) {
+ this.set_response_sensitive (1, false);
+ label_revealer.set_reveal_child (true);
+ } else {
+ this.set_response_sensitive (1, true);
+ label_revealer.set_reveal_child (false);
+ }
+ }
+
// Sets up the dialog to show the values of alarm.
public void set_from_alarm (Item? alarm) {
string name;
@@ -604,7 +642,7 @@ public class MainPanel : Gtk.Stack, Clocks.Clock {
}
private void edit (Item alarm) {
- var dialog = new SetupDialog ((Gtk.Window) get_toplevel (), alarm);
+ var dialog = new SetupDialog ((Gtk.Window) get_toplevel (), alarm, alarms);
// Disable alarm while editing it and remember the original active state.
var saved_active = alarm.active;
@@ -630,7 +668,7 @@ public class MainPanel : Gtk.Stack, Clocks.Clock {
}
public void activate_new () {
- var dialog = new SetupDialog ((Gtk.Window) get_toplevel (), null);
+ var dialog = new SetupDialog ((Gtk.Window) get_toplevel (), null, alarms);
dialog.response.connect ((dialog, response) => {
if (response == 1) {
var alarm = new Item ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]