[gnome-clocks/zbrown/timer/store-name] timers: store timer name in gsettings
- From: Zander <zbrown src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-clocks/zbrown/timer/store-name] timers: store timer name in gsettings
- Date: Tue, 28 Jan 2020 12:59:16 +0000 (UTC)
commit 3c1ee7d12b87890419df9dec30304c4d8a14bd57
Author: Zander Brown <zbrown gnome org>
Date: Tue Jan 28 12:58:12 2020 +0000
timers: store timer name in gsettings
data/ui/timer_row.ui | 243 ++++++++++++++++++++++++++-------------------------
src/timer.vala | 59 ++++++++-----
2 files changed, 159 insertions(+), 143 deletions(-)
---
diff --git a/data/ui/timer_row.ui b/data/ui/timer_row.ui
index ed4b462..5fb1b8e 100644
--- a/data/ui/timer_row.ui
+++ b/data/ui/timer_row.ui
@@ -1,127 +1,95 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1 -->
<interface>
- <requires lib="gtk+" version="3.12"/>
- <template class="ClocksTimerRow" parent="GtkBox">
+ <requires lib="gtk+" version="3.20"/>
+ <template class="ClocksTimerRow" parent="GtkListBoxRow">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="valign">start</property>
- <property name="margin_top">12</property>
- <property name="margin_bottom">12</property>
- <property name="orientation">vertical</property>
- <property name="spacing">18</property>
<child>
- <object class="GtkLabel" id="countdown_label">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="label">00:00:00</property>
- <attributes>
- <attribute name="font-features" value="tnum=1"/>
- </attributes>
- <style>
- <class name="timer-countdown"/>
- </style>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">True</property>
- <property name="position">0</property>
- </packing>
- </child>
- <child>
- <object class="GtkStack">
- <property name="visible">True</property>
+ <object class="GtkBox">
<property name="can_focus">False</property>
+ <property name="valign">start</property>
+ <property name="margin_top">12</property>
+ <property name="margin_bottom">12</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">18</property>
<child>
- <object class="GtkEntry">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="halign">center</property>
- <property name="width_chars">26</property>
- <property name="placeholder_text" translatable="yes">Title...</property>
- </object>
- <packing>
- <property name="name">page0</property>
- <property name="title" translatable="yes">page0</property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel" id="timer_name">
+ <object class="GtkLabel" id="countdown_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="halign">center</property>
+ <property name="label">00:00:00</property>
+ <attributes>
+ <attribute name="font-features" value="tnum=1"/>
+ </attributes>
<style>
- <class name="dim-label"/>
+ <class name="timer-countdown"/>
</style>
</object>
<packing>
- <property name="name">page1</property>
- <property name="title" translatable="yes">page1</property>
- <property name="position">1</property>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
</packing>
</child>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">True</property>
- <property name="position">1</property>
- </packing>
- </child>
- <child>
- <object class="GtkGrid">
- <property name="width_request">300</property>
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="halign">center</property>
- <property name="row_homogeneous">True</property>
- <property name="column_homogeneous">True</property>
<child>
- <object class="GtkButton" id="reset_button">
+ <object class="GtkStack">
<property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
- <property name="halign">center</property>
- <property name="valign">center</property>
- <property name="relief">none</property>
- <signal name="clicked" handler="on_reset_button_clicked" swapped="no"/>
+ <property name="can_focus">False</property>
<child>
- <object class="GtkImage">
+ <object class="GtkEntry" id="title">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="halign">center</property>
+ <property name="width_chars">26</property>
+ <property name="placeholder_text" translatable="yes">Title...</property>
+ </object>
+ <packing>
+ <property name="name">page0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="timer_name">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="icon_name">view-refresh-symbolic</property>
+ <property name="halign">center</property>
+ <style>
+ <class name="dim-label"/>
+ </style>
</object>
+ <packing>
+ <property name="name">page1</property>
+ <property name="position">1</property>
+ </packing>
</child>
- <style>
- <class name="round-button"/>
- </style>
</object>
<packing>
- <property name="left_attach">0</property>
- <property name="top_attach">0</property>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
</packing>
</child>
<child>
- <object class="GtkStack" id="start_stack">
+ <object class="GtkGrid">
+ <property name="width_request">300</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
- <property name="valign">center</property>
- <property name="hhomogeneous">False</property>
- <property name="vhomogeneous">False</property>
+ <property name="row_homogeneous">True</property>
+ <property name="column_homogeneous">True</property>
<child>
- <object class="GtkButton" id="pause_button">
+ <object class="GtkButton" id="reset_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="halign">center</property>
<property name="valign">center</property>
<property name="relief">none</property>
- <signal name="clicked" handler="on_pause_button_clicked" swapped="no"/>
+ <signal name="clicked" handler="on_reset_button_clicked" swapped="no"/>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="icon_name">media-playback-pause-symbolic</property>
+ <property name="icon_name">view-refresh-symbolic</property>
</object>
</child>
<style>
@@ -129,71 +97,106 @@
</style>
</object>
<packing>
- <property name="name">pause</property>
+ <property name="left_attach">0</property>
+ <property name="top_attach">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkStack" id="start_stack">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="halign">center</property>
+ <property name="valign">center</property>
+ <property name="hhomogeneous">False</property>
+ <property name="vhomogeneous">False</property>
+ <child>
+ <object class="GtkButton" id="pause_button">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="halign">center</property>
+ <property name="valign">center</property>
+ <property name="relief">none</property>
+ <signal name="clicked" handler="on_pause_button_clicked" swapped="no"/>
+ <child>
+ <object class="GtkImage">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="icon_name">media-playback-pause-symbolic</property>
+ </object>
+ </child>
+ <style>
+ <class name="round-button"/>
+ </style>
+ </object>
+ <packing>
+ <property name="name">pause</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="start_button">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="halign">center</property>
+ <property name="valign">center</property>
+ <property name="relief">none</property>
+ <signal name="clicked" handler="on_start_button_clicked" swapped="no"/>
+ <child>
+ <object class="GtkImage">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="icon_name">media-playback-start-symbolic</property>
+ </object>
+ </child>
+ <style>
+ <class name="round-button"/>
+ <class name="suggested-action"/>
+ </style>
+ </object>
+ <packing>
+ <property name="name">start</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">0</property>
</packing>
</child>
<child>
- <object class="GtkButton" id="start_button">
+ <object class="GtkButton" id="delete_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="halign">center</property>
<property name="valign">center</property>
<property name="relief">none</property>
- <signal name="clicked" handler="on_start_button_clicked" swapped="no"/>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="icon_name">media-playback-start-symbolic</property>
+ <property name="icon_name">edit-delete-symbolic</property>
</object>
</child>
<style>
<class name="round-button"/>
- <class name="suggested-action"/>
</style>
</object>
<packing>
- <property name="name">start</property>
- <property name="position">1</property>
+ <property name="left_attach">2</property>
+ <property name="top_attach">0</property>
</packing>
</child>
</object>
<packing>
- <property name="left_attach">1</property>
- <property name="top_attach">0</property>
- </packing>
- </child>
- <child>
- <object class="GtkButton" id="delete_button">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
- <property name="halign">center</property>
- <property name="valign">center</property>
- <property name="relief">none</property>
- <child>
- <object class="GtkImage">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="icon_name">edit-delete-symbolic</property>
- </object>
- </child>
- <style>
- <class name="round-button"/>
- </style>
- </object>
- <packing>
- <property name="left_attach">2</property>
- <property name="top_attach">0</property>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">3</property>
</packing>
</child>
</object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">True</property>
- <property name="position">3</property>
- </packing>
</child>
</template>
</interface>
diff --git a/src/timer.vala b/src/timer.vala
index 5440107..7e44a2c 100644
--- a/src/timer.vala
+++ b/src/timer.vala
@@ -79,8 +79,7 @@ public class Item : Object, ContentItem {
}
public Item (Duration duration, string? name) {
- Object (name: name);
- this.duration = duration;
+ Object (name: name, duration: duration);
}
}
@@ -214,8 +213,7 @@ public class Setup : Gtk.Box {
[GtkTemplate (ui = "/org/gnome/clocks/ui/timer_row.ui")]
-public class Row : Gtk.Box {
- public signal void deleted (Item item);
+public class Row : Gtk.ListBoxRow {
public enum State {
STOPPED,
RUNNING,
@@ -223,7 +221,21 @@ public class Row : Gtk.Box {
}
public State state { get; private set; default = State.STOPPED; }
- public Item item { get; construct set; }
+ public Item item {
+ get {
+ return _item;
+ }
+
+ construct set {
+ _item = value;
+
+ title.text = _item.name;
+ title.bind_property ("text", _item, "name");
+
+ _item.notify["name"].connect (() => edited ());
+ }
+ }
+ private Item _item = null;
private double span;
private GLib.Timer timer;
@@ -238,21 +250,26 @@ public class Row : Gtk.Box {
[GtkChild]
private Gtk.Button delete_button;
+ [GtkChild]
+ private Gtk.Entry title;
+
+ public signal void deleted ();
+ public signal void edited ();
+
+
public Row (Item item) {
Object(item: item);
span = item.duration.get_total_seconds ();
timer = new GLib.Timer ();
timeout_id = 0;
- destroy.connect(() => {
+ destroy.connect (() => {
if (timeout_id != 0) {
- GLib.Source.remove(timeout_id);
+ GLib.Source.remove (timeout_id);
timeout_id = 0;
}
});
- delete_button.clicked.connect(() => {
- this.deleted (this.item);
- });
+ delete_button.clicked.connect (() => deleted ());
reset ();
}
@@ -311,7 +328,7 @@ public class Row : Gtk.Box {
state = State.RUNNING;
timer.start ();
timeout_id = GLib.Timeout.add(40, () => {
- if (state != State.RUNNING) {
+ if (state != State.RUNNING) {
timeout_id = 0;
return false;
}
@@ -411,24 +428,23 @@ public class Face : Gtk.Stack, Clocks.Clock {
settings = new GLib.Settings ("org.gnome.clocks");
timers = new ContentStore();
-
timers_list.set_header_func ((Gtk.ListBoxUpdateHeaderFunc) Hdy.list_box_separator_header);
timers_list.bind_model (timers, (timer) => {
- var timer_row = new Row ((Item)timer);
- timer_row.deleted.connect((item) => {
- this.remove_timer(item);
- });
- return timer_row;
+ var row = new Row ((Item) timer);
+ row.deleted.connect (() => remove_timer ((Item) timer));
+ row.edited.connect (() => save ());
+ return row;
});
- timers.items_changed.connect(() => {
+ timers.items_changed.connect (() => {
if (this.timers.get_n_items () > 0) {
- this.set_visible_child_name ("timers");
+ this.visible_child_name = "timers";
this.button_mode = NEW;
} else {
- this.set_visible_child_name ("empty");
+ this.visible_child_name = "empty";
this.button_mode = NONE;
}
+ save ();
});
bell = new Utils.Bell ("complete");
@@ -452,7 +468,6 @@ public class Face : Gtk.Stack, Clocks.Clock {
private void remove_timer (Item item) {
timers.remove (item);
- save ();
}
@@ -462,7 +477,6 @@ public class Face : Gtk.Stack, Clocks.Clock {
if (response == Gtk.ResponseType.ACCEPT) {
var timer = ((NewTimerDialog) dialog).timer_setup.get_timer ();
timers.add (timer);
- save ();
}
dialog.destroy ();
});
@@ -472,7 +486,6 @@ public class Face : Gtk.Stack, Clocks.Clock {
private void add_timer (Item timer) {
timers.add (timer);
- save ();
}
private void load () {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]