[gnome-break-timer/dylanmccall/meson-build: 15/25] Change all *.vala files to indent with spaces
- From: Dylan McCall <dylanmccall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-break-timer/dylanmccall/meson-build: 15/25] Change all *.vala files to indent with spaces
- Date: Wed, 23 Jan 2019 04:04:15 +0000 (UTC)
commit 21cc0756bf9645114d070eb34a50f499cdcf011d
Author: Dylan McCall <dylan dylanmccall com>
Date: Wed Jan 9 23:30:15 2019 -0800
Change all *.vala files to indent with spaces
(╯°□°)╯︵ ┻━┻
.editorconfig | 19 +
.gitignore | 1 -
AUTHORS | 2 +-
common/IBreakHelper.vala | 50 +-
common/ISessionStatus.vala | 12 +-
common/NaturalTime.vala | 252 ++++----
gnome-break-timer.in => gnome-break-timer.sh.in | 0
helper/BreakManager.vala | 242 ++++----
helper/HelperApplication.vala | 338 +++++------
helper/ScreenOverlay.vala | 412 ++++++-------
helper/SessionStatus.vala | 138 ++---
helper/UIManager.vala | 504 ++++++++--------
helper/activity-monitor/ActivityMonitor.vala | 416 ++++++-------
.../MutterActivityMonitorBackend.vala | 142 ++---
helper/break/BreakController.vala | 296 ++++-----
helper/break/BreakType.vala | 30 +-
helper/break/BreakView.vala | 230 +++----
helper/break/TimerBreakController.vala | 444 +++++++-------
helper/break/TimerBreakStatusWidget.vala | 124 ++--
helper/break/TimerBreakType.vala | 90 +--
helper/break/TimerBreakView.vala | 66 +-
helper/main.vala | 18 +-
helper/microbreak/MicroBreakController.vala | 16 +-
helper/microbreak/MicroBreakType.vala | 34 +-
helper/microbreak/MicroBreakView.vala | 218 +++----
helper/restbreak/RestBreakController.vala | 92 +--
helper/restbreak/RestBreakType.vala | 34 +-
helper/restbreak/RestBreakView.vala | 380 ++++++------
helper/util/Countdown.vala | 468 +++++++--------
helper/util/PausableTimeout.vala | 128 ++--
helper/util/SimpleFocusManager.vala | 158 ++---
helper/util/StatefulTimer.vala | 198 +++---
helper/util/Util.vala | 62 +-
meson.build | 2 +-
settings/BreakManager.vala | 254 ++++----
settings/BreakSettingsDialog.vala | 382 ++++++------
settings/BreakType.vala | 272 ++++-----
settings/CircleCounter.vala | 196 +++---
settings/MainWindow.vala | 664 ++++++++++-----------
settings/MicroBreakType.vala | 134 ++---
settings/OverlayArrow.vala | 196 +++---
settings/RestBreakType.vala | 136 ++---
settings/SettingsApplication.vala | 216 +++----
settings/TimeChooser.vala | 204 +++----
settings/TimerBreakType.vala | 338 +++++------
settings/main.vala | 6 +-
.../activity-monitor/activity-monitor_runner.vala | 6 +-
tests/activity-monitor/test_ActivityMonitor.vala | 264 ++++----
tests/breaks/breaks_runner.vala | 6 +-
tests/breaks/test_TimerBreakController.vala | 602 +++++++++----------
tests/common/common_runner.vala | 6 +-
tests/common/test_NaturalTime.vala | 186 +++---
tests/helper-util/helper_util_runner.vala | 8 +-
tests/helper-util/test_Countdown.vala | 576 +++++++++---------
tests/helper-util/test_StatefulTimer.vala | 170 +++---
tests/tests.vala | 492 +++++++--------
56 files changed, 5474 insertions(+), 5456 deletions(-)
---
diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..d0ad051
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,19 @@
+[*.vala, *.c]
+indent_style = spaces
+indent_size = 4
+
+[*.py, *.sh, *.sh.in]
+indent_style = spaces
+indent_size = 4
+
+[*.json]
+indent_style = spaces
+indent_size = 4
+
+[*.xml, *.xml.in, *.xml.in.in, *.doap]
+indent_style = spaces
+indent_size = 2
+
+[meson.build]
+indent_style = spaces
+indent_size = 4
diff --git a/.gitignore b/.gitignore
index a34bad6..774a17e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,4 +5,3 @@
.libs
.flatpak-builder
/build
-
diff --git a/AUTHORS b/AUTHORS
index 7a3cbbc..0eccdf2 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -1,6 +1,6 @@
GNOME Break Timer was designed and implemented by
-Dylan McCall <www.dylanmccall.com>
+Dylan McCall <https://www.dylanmc.ca//->
Allan Day
The gnome-break-timer icon is based on the gnome-clocks icon, from
<https://git.gnome.org/browse/gnome-clocks>.
diff --git a/common/IBreakHelper.vala b/common/IBreakHelper.vala
index bce0856..e664cdb 100644
--- a/common/IBreakHelper.vala
+++ b/common/IBreakHelper.vala
@@ -19,46 +19,46 @@ namespace BreakTimer {
[DBus (name = "org.gnome.BreakTimer")]
public interface IBreakHelper : Object {
- /** Returns the ID of the break that is currently focused and activated, if any. */
- public abstract string? get_current_active_break () throws DBusError, IOError;
+ /** Returns the ID of the break that is currently focused and activated, if any. */
+ public abstract string? get_current_active_break () throws DBusError, IOError;
- /** Returns a list of breaks that are currently known to the break helper. */
- public abstract string[] get_break_ids () throws DBusError, IOError;
+ /** Returns a list of breaks that are currently known to the break helper. */
+ public abstract string[] get_break_ids () throws DBusError, IOError;
- /** Returns a list of helpful status messages for each break, for debugging. */
- public abstract string[] get_status_messages () throws DBusError, IOError;
+ /** Returns a list of helpful status messages for each break, for debugging. */
+ public abstract string[] get_status_messages () throws DBusError, IOError;
- /** Activate the specified break immediately, regardless of the usual activation conditions. */
- public abstract void activate_break (string break_id) throws DBusError, IOError;
+ /** Activate the specified break immediately, regardless of the usual activation conditions. */
+ public abstract void activate_break (string break_id) throws DBusError, IOError;
- // TODO: It might make sense to communicate when the active break changes,
- // using a signal. The only reason we don't at the moment is it adds
- // complexity in the break helper, and the settings app already polls the
- // dbus service regularly for updates.
+ // TODO: It might make sense to communicate when the active break changes,
+ // using a signal. The only reason we don't at the moment is it adds
+ // complexity in the break helper, and the settings app already polls the
+ // dbus service regularly for updates.
}
[DBus (name = "org.gnome.BreakTimer.TimerBreak")]
public interface IBreakHelper_TimerBreak : Object {
- /** Get the break's current status, such as time remaining, or time until the break starts */
- public abstract TimerBreakStatus get_status () throws DBusError, IOError;
+ /** Get the break's current status, such as time remaining, or time until the break starts */
+ public abstract TimerBreakStatus get_status () throws DBusError, IOError;
- /** Activate the break */
- public abstract void activate () throws DBusError, IOError;
+ /** Activate the break */
+ public abstract void activate () throws DBusError, IOError;
}
public struct BreakStatus {
- bool is_enabled;
- bool is_focused;
- bool is_active;
+ bool is_enabled;
+ bool is_focused;
+ bool is_active;
}
public struct TimerBreakStatus {
- bool is_enabled;
- bool is_focused;
- bool is_active;
- int starts_in;
- int time_remaining;
- int current_duration;
+ bool is_enabled;
+ bool is_focused;
+ bool is_active;
+ int starts_in;
+ int time_remaining;
+ int current_duration;
}
}
diff --git a/common/ISessionStatus.vala b/common/ISessionStatus.vala
index 037a5fa..76de8e4 100644
--- a/common/ISessionStatus.vala
+++ b/common/ISessionStatus.vala
@@ -18,13 +18,13 @@
namespace BreakTimer {
public interface ISessionStatus : Object {
- public signal void locked ();
- public signal void unlocked ();
+ public signal void locked ();
+ public signal void unlocked ();
- public abstract bool is_locked ();
- public abstract void lock_screen ();
- public abstract void blank_screen ();
- public abstract void unblank_screen ();
+ public abstract bool is_locked ();
+ public abstract void lock_screen ();
+ public abstract void blank_screen ();
+ public abstract void unblank_screen ();
}
}
diff --git a/common/NaturalTime.vala b/common/NaturalTime.vala
index 31ca9c2..1e47c89 100644
--- a/common/NaturalTime.vala
+++ b/common/NaturalTime.vala
@@ -18,135 +18,135 @@
namespace BreakTimer {
public class NaturalTime : Object {
- public delegate string FormatTimeCb (int seconds);
+ public delegate string FormatTimeCb (int seconds);
- private struct TimeUnit {
- public int seconds;
- public FormatTimeCb format_time;
-
- public TimeUnit (int seconds, FormatTimeCb format_time) {
- this.seconds = seconds;
- this.format_time = format_time;
- }
-
- public string format_seconds (int seconds, out int output_value) {
- output_value = seconds / this.seconds;
- return this.format_time(output_value);
- }
- }
-
- private TimeUnit[] units { get; private set; }
-
- private NaturalTime () {
- this.units = {
- TimeUnit (1, (time) => {
- return ngettext ("%d second", "%d seconds", time).printf(time);
- }),
- TimeUnit (60, (time) => {
- return ngettext ("%d minute", "%d minutes", time).printf(time);
- }),
- TimeUnit (3600, (time) => {
- return ngettext ("%d hour", "%d hours", time).printf(time);
- })
- };
- }
+ private struct TimeUnit {
+ public int seconds;
+ public FormatTimeCb format_time;
+
+ public TimeUnit (int seconds, FormatTimeCb format_time) {
+ this.seconds = seconds;
+ this.format_time = format_time;
+ }
+
+ public string format_seconds (int seconds, out int output_value) {
+ output_value = seconds / this.seconds;
+ return this.format_time(output_value);
+ }
+ }
+
+ private TimeUnit[] units { get; private set; }
+
+ private NaturalTime () {
+ this.units = {
+ TimeUnit (1, (time) => {
+ return ngettext ("%d second", "%d seconds", time).printf(time);
+ }),
+ TimeUnit (60, (time) => {
+ return ngettext ("%d minute", "%d minutes", time).printf(time);
+ }),
+ TimeUnit (3600, (time) => {
+ return ngettext ("%d hour", "%d hours", time).printf(time);
+ })
+ };
+ }
- private static NaturalTime _instance;
- public static NaturalTime instance {
- get {
- if (_instance == null) {
- _instance = new NaturalTime ();
- }
- return _instance;
- }
- }
-
- /**
- * Get a natural label for the given time in seconds. Converts seconds
- * to a unit that will represent the time as accurately as possible,
- * favouring precision over unit selection.
- * So, an input of 60 will return "1 minute", but 61 will return
- * "61 seconds".
- * @param seconds time in seconds.
- * @param output_value set to the numerical value of the output.
- * @return a string with a natural and accurate representation of the time.
- */
- public string get_label_for_seconds (int seconds, out int output_value = null) {
- TimeUnit label_unit = units[0];
- foreach (TimeUnit unit in units) {
- if (seconds % unit.seconds == 0) {
- label_unit = unit;
- // assumes smallest unit is first in the list
- if (seconds == 0) break;
- }
- }
- return label_unit.format_seconds (seconds, out output_value);
- }
-
- /**
- * Get a natural label for the given time in seconds. Converts seconds
- * to a unit that will represent the time as cleanly as possible,
- * favouring the simplest possible unit over precision.
- * So, an input of 60 will return "1 minute", and 61 will return the
- * same.
- * @param seconds time in seconds.
- * @param output_value set to the numerical value of the output.
- * @return a string with a natural and accurate representation of the time.
- */
- public string get_simplest_label_for_seconds (int seconds, out int output_value = null) {
- TimeUnit label_unit = units[0];
- foreach (TimeUnit unit in units) {
- if (seconds >= unit.seconds) {
- label_unit = unit;
- }
- }
- return label_unit.format_seconds (seconds, out output_value);
- }
-
- /**
- * Get a natural label for the given time in seconds, in an imprecise
- * format intented for a countdown. Precision is unimportant, so this
- * function softens the time by a gradually smaller interval as seconds
- * reaches 0.
- * @param seconds number of seconds remaining in the countdown.
- * @param output_value set to the numerical value of the output.
- * @return a string representing the time remaining.
- */
- public string get_countdown_for_seconds (int seconds, out int output_value = null) {
- int seconds_softened = soften_seconds_for_countdown (seconds);
- return get_simplest_label_for_seconds (seconds_softened, out output_value);
- }
-
- /**
- * Get a natural label for the given time in seconds, in an imprecise
- * format intented for a countdown. Precision is unimportant, so this
- * function softens the time by a gradually smaller interval as seconds
- * reaches 0.
- * When the remaining time is near the given start time, the start time
- * is shown instead, without being softened.
- * @param seconds number of seconds remaining in the countdown.
- * @param start countdown start time, in seconds, which will be shown exactly.
- * @param output_value set to the numerical value of the output.
- * @return a string representing the time remaining.
- */
- public string get_countdown_for_seconds_with_start (int seconds, int start, out int output_value =
null) {
- int seconds_softened = soften_seconds_for_countdown (seconds);
- if (seconds_softened > start) seconds_softened = start;
- return get_simplest_label_for_seconds (seconds_softened, out output_value);
- }
+ private static NaturalTime _instance;
+ public static NaturalTime instance {
+ get {
+ if (_instance == null) {
+ _instance = new NaturalTime ();
+ }
+ return _instance;
+ }
+ }
+
+ /**
+ * Get a natural label for the given time in seconds. Converts seconds
+ * to a unit that will represent the time as accurately as possible,
+ * favouring precision over unit selection.
+ * So, an input of 60 will return "1 minute", but 61 will return
+ * "61 seconds".
+ * @param seconds time in seconds.
+ * @param output_value set to the numerical value of the output.
+ * @return a string with a natural and accurate representation of the time.
+ */
+ public string get_label_for_seconds (int seconds, out int output_value = null) {
+ TimeUnit label_unit = units[0];
+ foreach (TimeUnit unit in units) {
+ if (seconds % unit.seconds == 0) {
+ label_unit = unit;
+ // assumes smallest unit is first in the list
+ if (seconds == 0) break;
+ }
+ }
+ return label_unit.format_seconds (seconds, out output_value);
+ }
+
+ /**
+ * Get a natural label for the given time in seconds. Converts seconds
+ * to a unit that will represent the time as cleanly as possible,
+ * favouring the simplest possible unit over precision.
+ * So, an input of 60 will return "1 minute", and 61 will return the
+ * same.
+ * @param seconds time in seconds.
+ * @param output_value set to the numerical value of the output.
+ * @return a string with a natural and accurate representation of the time.
+ */
+ public string get_simplest_label_for_seconds (int seconds, out int output_value = null) {
+ TimeUnit label_unit = units[0];
+ foreach (TimeUnit unit in units) {
+ if (seconds >= unit.seconds) {
+ label_unit = unit;
+ }
+ }
+ return label_unit.format_seconds (seconds, out output_value);
+ }
+
+ /**
+ * Get a natural label for the given time in seconds, in an imprecise
+ * format intented for a countdown. Precision is unimportant, so this
+ * function softens the time by a gradually smaller interval as seconds
+ * reaches 0.
+ * @param seconds number of seconds remaining in the countdown.
+ * @param output_value set to the numerical value of the output.
+ * @return a string representing the time remaining.
+ */
+ public string get_countdown_for_seconds (int seconds, out int output_value = null) {
+ int seconds_softened = soften_seconds_for_countdown (seconds);
+ return get_simplest_label_for_seconds (seconds_softened, out output_value);
+ }
+
+ /**
+ * Get a natural label for the given time in seconds, in an imprecise
+ * format intented for a countdown. Precision is unimportant, so this
+ * function softens the time by a gradually smaller interval as seconds
+ * reaches 0.
+ * When the remaining time is near the given start time, the start time
+ * is shown instead, without being softened.
+ * @param seconds number of seconds remaining in the countdown.
+ * @param start countdown start time, in seconds, which will be shown exactly.
+ * @param output_value set to the numerical value of the output.
+ * @return a string representing the time remaining.
+ */
+ public string get_countdown_for_seconds_with_start (int seconds, int start, out int output_value = null)
{
+ int seconds_softened = soften_seconds_for_countdown (seconds);
+ if (seconds_softened > start) seconds_softened = start;
+ return get_simplest_label_for_seconds (seconds_softened, out output_value);
+ }
- private int soften_seconds_for_countdown (int seconds) {
- int interval = 1;
- if (seconds <= 10) {
- interval = 1;
- } else if (seconds <= 60) {
- interval = 10;
- } else {
- interval = 60;
- }
- int time_softened = ( (seconds-1) / interval) + 1;
- return time_softened * interval;
- }
+ private int soften_seconds_for_countdown (int seconds) {
+ int interval = 1;
+ if (seconds <= 10) {
+ interval = 1;
+ } else if (seconds <= 60) {
+ interval = 10;
+ } else {
+ interval = 60;
+ }
+ int time_softened = ( (seconds-1) / interval) + 1;
+ return time_softened * interval;
+ }
}
}
diff --git a/gnome-break-timer.in b/gnome-break-timer.sh.in
similarity index 100%
rename from gnome-break-timer.in
rename to gnome-break-timer.sh.in
diff --git a/helper/BreakManager.vala b/helper/BreakManager.vala
index ec18719..37fef35 100644
--- a/helper/BreakManager.vala
+++ b/helper/BreakManager.vala
@@ -18,131 +18,131 @@
namespace BreakTimer.Helper {
public class BreakManager : Object {
- private UIManager ui_manager;
-
- private Gee.Map<string, BreakType> breaks;
- private BreakHelperServer break_helper_server;
-
- private Settings settings;
- public bool master_enabled { get; set; }
- public string[] selected_break_ids { get; set; }
-
- public BreakManager (UIManager ui_manager) {
- this.ui_manager = ui_manager;
-
- this.breaks = new Gee.HashMap<string, BreakType> ();
- this.settings = new Settings ("org.gnome.BreakTimer");
-
- this.settings.bind ("enabled", this, "master-enabled", SettingsBindFlags.DEFAULT);
- this.settings.bind ("selected-breaks", this, "selected-break-ids", SettingsBindFlags.DEFAULT);
- this.notify["master-enabled"].connect (this.update_enabled_breaks);
- this.notify["selected-break-ids"].connect (this.update_enabled_breaks);
-
- this.break_helper_server = new BreakHelperServer (this);
- try {
- DBusConnection connection = Bus.get_sync (BusType.SESSION, null);
- connection.register_object (
- Config.HELPER_OBJECT_PATH,
- this.break_helper_server
- );
- } catch (IOError error) {
- GLib.error ("Error registering helper on the session bus: %s", error.message);
- }
- }
-
- public Json.Object serialize () {
- Json.Object json_root = new Json.Object ();
- foreach (BreakType break_type in this.all_breaks ()) {
- Json.Object break_json = break_type.break_controller.serialize ();
- json_root.set_object_member (break_type.id, break_json);
- }
- return json_root;
- }
-
- public void deserialize (ref Json.Object json_root) {
- foreach (BreakType break_type in this.all_breaks ()) {
- Json.Object break_json = json_root.get_object_member (break_type.id);
- if (break_json != null) {
- break_type.break_controller.deserialize (ref break_json);
- }
- }
- }
-
- public void load_breaks (ActivityMonitor activity_monitor) {
- this.add_break (new MicroBreakType (activity_monitor));
- this.add_break (new RestBreakType (activity_monitor));
-
- this.update_enabled_breaks ();
- }
-
- public Gee.Set<string> all_break_ids () {
- return this.breaks.keys;
- }
-
- public Gee.Collection<BreakType> all_breaks () {
- return this.breaks.values;
- }
-
- public BreakType? get_break_type_for_name (string name) {
- return this.breaks.get (name);
- }
-
- private void add_break (BreakType break_type) {
- this.breaks.set (break_type.id, break_type);
- break_type.initialize (this.ui_manager);
- }
-
- private void update_enabled_breaks () {
- foreach (BreakType break_type in this.all_breaks ()) {
- bool is_enabled = this.master_enabled && break_type.id in this.selected_break_ids;
- break_type.break_controller.set_enabled (is_enabled);
- }
- }
+ private UIManager ui_manager;
+
+ private Gee.Map<string, BreakType> breaks;
+ private BreakHelperServer break_helper_server;
+
+ private Settings settings;
+ public bool master_enabled { get; set; }
+ public string[] selected_break_ids { get; set; }
+
+ public BreakManager (UIManager ui_manager) {
+ this.ui_manager = ui_manager;
+
+ this.breaks = new Gee.HashMap<string, BreakType> ();
+ this.settings = new Settings ("org.gnome.BreakTimer");
+
+ this.settings.bind ("enabled", this, "master-enabled", SettingsBindFlags.DEFAULT);
+ this.settings.bind ("selected-breaks", this, "selected-break-ids", SettingsBindFlags.DEFAULT);
+ this.notify["master-enabled"].connect (this.update_enabled_breaks);
+ this.notify["selected-break-ids"].connect (this.update_enabled_breaks);
+
+ this.break_helper_server = new BreakHelperServer (this);
+ try {
+ DBusConnection connection = Bus.get_sync (BusType.SESSION, null);
+ connection.register_object (
+ Config.HELPER_OBJECT_PATH,
+ this.break_helper_server
+ );
+ } catch (IOError error) {
+ GLib.error ("Error registering helper on the session bus: %s", error.message);
+ }
+ }
+
+ public Json.Object serialize () {
+ Json.Object json_root = new Json.Object ();
+ foreach (BreakType break_type in this.all_breaks ()) {
+ Json.Object break_json = break_type.break_controller.serialize ();
+ json_root.set_object_member (break_type.id, break_json);
+ }
+ return json_root;
+ }
+
+ public void deserialize (ref Json.Object json_root) {
+ foreach (BreakType break_type in this.all_breaks ()) {
+ Json.Object break_json = json_root.get_object_member (break_type.id);
+ if (break_json != null) {
+ break_type.break_controller.deserialize (ref break_json);
+ }
+ }
+ }
+
+ public void load_breaks (ActivityMonitor activity_monitor) {
+ this.add_break (new MicroBreakType (activity_monitor));
+ this.add_break (new RestBreakType (activity_monitor));
+
+ this.update_enabled_breaks ();
+ }
+
+ public Gee.Set<string> all_break_ids () {
+ return this.breaks.keys;
+ }
+
+ public Gee.Collection<BreakType> all_breaks () {
+ return this.breaks.values;
+ }
+
+ public BreakType? get_break_type_for_name (string name) {
+ return this.breaks.get (name);
+ }
+
+ private void add_break (BreakType break_type) {
+ this.breaks.set (break_type.id, break_type);
+ break_type.initialize (this.ui_manager);
+ }
+
+ private void update_enabled_breaks () {
+ foreach (BreakType break_type in this.all_breaks ()) {
+ bool is_enabled = this.master_enabled && break_type.id in this.selected_break_ids;
+ break_type.break_controller.set_enabled (is_enabled);
+ }
+ }
}
[DBus (name = "org.gnome.BreakTimer")]
public class BreakHelperServer : Object, IBreakHelper {
- private weak BreakManager break_manager;
-
- public BreakHelperServer (BreakManager break_manager) {
- this.break_manager = break_manager;
- }
-
- public string? get_current_active_break () {
- /* Ask for focused break */
- foreach (BreakType break_type in this.break_manager.all_breaks ()) {
- bool is_active = break_type.break_view.has_ui_focus () &&
- break_type.break_controller.is_active ();
- if (is_active) return break_type.id;
- }
- return null;
- }
-
- public bool is_active () {
- bool active = false;
- foreach (BreakType break_type in this.break_manager.all_breaks ()) {
- active = active || break_type.break_controller.is_active ();
- }
- return active;
- }
-
- public string[] get_break_ids () {
- return this.break_manager.all_break_ids ().to_array ();
- }
-
- public string[] get_status_messages () {
- var messages = new Gee.ArrayList<string> ();
- foreach (BreakType break_type in break_manager.all_breaks ()) {
- string status_message = break_type.break_view.get_status_message ();
- messages.add ("%s:\t%s".printf (break_type.id, status_message));
- }
- return messages.to_array ();
- }
-
- public void activate_break (string break_name) {
- BreakType? break_type = this.break_manager.get_break_type_for_name (break_name);
- if (break_type != null) break_type.break_controller.activate ();
- }
+ private weak BreakManager break_manager;
+
+ public BreakHelperServer (BreakManager break_manager) {
+ this.break_manager = break_manager;
+ }
+
+ public string? get_current_active_break () {
+ /* Ask for focused break */
+ foreach (BreakType break_type in this.break_manager.all_breaks ()) {
+ bool is_active = break_type.break_view.has_ui_focus () &&
+ break_type.break_controller.is_active ();
+ if (is_active) return break_type.id;
+ }
+ return null;
+ }
+
+ public bool is_active () {
+ bool active = false;
+ foreach (BreakType break_type in this.break_manager.all_breaks ()) {
+ active = active || break_type.break_controller.is_active ();
+ }
+ return active;
+ }
+
+ public string[] get_break_ids () {
+ return this.break_manager.all_break_ids ().to_array ();
+ }
+
+ public string[] get_status_messages () {
+ var messages = new Gee.ArrayList<string> ();
+ foreach (BreakType break_type in break_manager.all_breaks ()) {
+ string status_message = break_type.break_view.get_status_message ();
+ messages.add ("%s:\t%s".printf (break_type.id, status_message));
+ }
+ return messages.to_array ();
+ }
+
+ public void activate_break (string break_name) {
+ BreakType? break_type = this.break_manager.get_break_type_for_name (break_name);
+ if (break_type != null) break_type.break_controller.activate ();
+ }
}
}
diff --git a/helper/HelperApplication.vala b/helper/HelperApplication.vala
index 0c32553..4c53b7e 100644
--- a/helper/HelperApplication.vala
+++ b/helper/HelperApplication.vala
@@ -18,175 +18,175 @@
namespace BreakTimer.Helper {
public class HelperApplication : Gtk.Application {
- const string app_id = Config.HELPER_DESKTOP_ID;
- const string app_name = _("GNOME Break Timer");
- const int DATA_VERSION = 0;
-
- private static const string STYLE_DATA =
- """
- @define-color bg_top rgba(218, 236, 237, 0.80);
- @define-color bg_middle rgba(226, 237, 236, 0.87);
- @define-color bg_bottom rgba(179, 209, 183, 0.89);
-
- GtkWindow._screen-overlay {
- background-color: @bg_inner;
- background-image:-gtk-gradient (linear,
- center top,
- center bottom,
- color-stop (0, @bg_top),
- color-stop (0.08, @bg_middle),
- color-stop (0.92, @bg_middle),
- color-stop (1, @bg_bottom));
- font-size: 18px;
- color: #999;
- }
-
- GtkLabel._timer-label {
- font-weight: bold;
- font-size: 36px;
- color: #333;
- text-shadow: 1px 1px 5px rgba (0, 0, 0, 0.5);
- }
- """;
-
- private BreakManager break_manager;
- private ISessionStatus session_status;
- private ActivityMonitorBackend activity_monitor_backend;
- private ActivityMonitor activity_monitor;
- private UIManager ui_manager;
-
- private string cache_path;
-
- public HelperApplication () {
- Object (
- application_id: app_id,
- register_session: true,
- flags: ApplicationFlags.FLAGS_NONE
- );
- Environment.set_application_name (app_name);
-
- // Keep running for one minute after the last break is disabled
- this.set_inactivity_timeout (60 * 1000);
-
- string user_cache_path = Environment.get_user_cache_dir ();
- this.cache_path = Path.build_filename (user_cache_path, "gnome-break-timer");
- }
-
- public override void activate () {
- base.activate ();
- }
-
- public override void startup () {
- base.startup ();
-
- Notify.init (app_name);
-
- /* set up custom gtk style for application */
- Gdk.Screen screen = Gdk.Screen.get_default ();
- Gtk.CssProvider style_provider = new Gtk.CssProvider ();
-
- try {
- style_provider.load_from_data (STYLE_DATA, -1);
- } catch (Error error) {
- GLib.warning ("Error loading style data: %s", error.message);
- }
-
- Gtk.StyleContext.add_provider_for_screen (
- screen,
- style_provider,
- Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
- );
-
- this.session_status = new SessionStatus (this);
-
- try {
- this.activity_monitor_backend = new MutterActivityMonitorBackend ();
- } catch {
- GLib.error ("Failed to initialize activity monitor backend");
- }
- this.activity_monitor = new ActivityMonitor (session_status, activity_monitor_backend);
-
- this.ui_manager = new UIManager (this, session_status, false);
- this.break_manager = new BreakManager (ui_manager);
- this.break_manager.load_breaks (activity_monitor);
-
- this.restore_state ();
-
- this.activity_monitor.start ();
-
- var connection = this.get_dbus_connection ();
- if (connection != null) {
- Bus.own_name_on_connection (connection, Config.HELPER_BUS_NAME,
BusNameOwnerFlags.REPLACE, null, null);
- }
- }
-
- public override void shutdown () {
- base.shutdown ();
-
- this.save_state ();
- }
-
- private File get_state_file () {
- File cache_dir = File.new_for_path (this.cache_path);
- try {
- if (! cache_dir.query_exists ()) cache_dir.make_directory_with_parents ();
- } catch (Error e) {
- GLib.warning ("Error creating cache directory: %s", e.message);
- }
- string state_file_name = "last-state-%d".printf (DATA_VERSION);
- return cache_dir.get_child (state_file_name);
- }
-
- private void save_state () {
- File state_file = this.get_state_file ();
-
- Json.Generator generator = new Json.Generator ();
- Json.Node root = new Json.Node (Json.NodeType.OBJECT);
- Json.Object root_object = new Json.Object ();
- root.set_object (root_object);
- generator.set_root (root);
-
- root_object.set_object_member ("break_manager", this.break_manager.serialize ());
- root_object.set_object_member ("activity_monitor_backend",
this.activity_monitor_backend.serialize ());
- root_object.set_object_member ("activity_monitor", this.activity_monitor.serialize ());
-
- try {
- OutputStream state_stream = state_file.replace (null, false, FileCreateFlags.NONE);
- generator.to_stream (state_stream);
- } catch (Error e) {
- GLib.warning ("Error writing to state file: %s", e.message);
- }
- }
-
- private void restore_state () {
- File state_file = this.get_state_file ();
- if (state_file.query_exists ()) {
- Json.Parser parser = new Json.Parser ();
-
- try {
- InputStream state_stream = state_file.read ();
- parser.load_from_stream (state_stream);
- } catch (Error e) {
- GLib.warning ("Error reading state file: %s", e.message);
- }
-
- Json.Node? root = parser.get_root ();
- if (root != null) {
- Json.Object root_object = root.get_object ();
-
- Json.Object break_manager_json = root_object.get_object_member
("break_manager");
- this.break_manager.deserialize (ref break_manager_json);
-
- Json.Object activity_monitor_backend_json = root_object.get_object_member
("activity_monitor_backend");
- this.activity_monitor_backend.deserialize (ref activity_monitor_backend_json);
-
- Json.Object activity_monitor_json = root_object.get_object_member
("activity_monitor");
- this.activity_monitor.deserialize (ref activity_monitor_json);
-
- this.activity_monitor.poll_activity ();
- }
- }
- }
+ const string app_id = Config.HELPER_DESKTOP_ID;
+ const string app_name = _("GNOME Break Timer");
+ const int DATA_VERSION = 0;
+
+ private static const string STYLE_DATA =
+ """
+ @define-color bg_top rgba(218, 236, 237, 0.80);
+ @define-color bg_middle rgba(226, 237, 236, 0.87);
+ @define-color bg_bottom rgba(179, 209, 183, 0.89);
+
+ GtkWindow._screen-overlay {
+ background-color: @bg_inner;
+ background-image:-gtk-gradient (linear,
+ center top,
+ center bottom,
+ color-stop (0, @bg_top),
+ color-stop (0.08, @bg_middle),
+ color-stop (0.92, @bg_middle),
+ color-stop (1, @bg_bottom));
+ font-size: 18px;
+ color: #999;
+ }
+
+ GtkLabel._timer-label {
+ font-weight: bold;
+ font-size: 36px;
+ color: #333;
+ text-shadow: 1px 1px 5px rgba (0, 0, 0, 0.5);
+ }
+ """;
+
+ private BreakManager break_manager;
+ private ISessionStatus session_status;
+ private ActivityMonitorBackend activity_monitor_backend;
+ private ActivityMonitor activity_monitor;
+ private UIManager ui_manager;
+
+ private string cache_path;
+
+ public HelperApplication () {
+ Object (
+ application_id: app_id,
+ register_session: true,
+ flags: ApplicationFlags.FLAGS_NONE
+ );
+ Environment.set_application_name (app_name);
+
+ // Keep running for one minute after the last break is disabled
+ this.set_inactivity_timeout (60 * 1000);
+
+ string user_cache_path = Environment.get_user_cache_dir ();
+ this.cache_path = Path.build_filename (user_cache_path, "gnome-break-timer");
+ }
+
+ public override void activate () {
+ base.activate ();
+ }
+
+ public override void startup () {
+ base.startup ();
+
+ Notify.init (app_name);
+
+ /* set up custom gtk style for application */
+ Gdk.Screen screen = Gdk.Screen.get_default ();
+ Gtk.CssProvider style_provider = new Gtk.CssProvider ();
+
+ try {
+ style_provider.load_from_data (STYLE_DATA, -1);
+ } catch (Error error) {
+ GLib.warning ("Error loading style data: %s", error.message);
+ }
+
+ Gtk.StyleContext.add_provider_for_screen (
+ screen,
+ style_provider,
+ Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
+ );
+
+ this.session_status = new SessionStatus (this);
+
+ try {
+ this.activity_monitor_backend = new MutterActivityMonitorBackend ();
+ } catch {
+ GLib.error ("Failed to initialize activity monitor backend");
+ }
+ this.activity_monitor = new ActivityMonitor (session_status, activity_monitor_backend);
+
+ this.ui_manager = new UIManager (this, session_status, false);
+ this.break_manager = new BreakManager (ui_manager);
+ this.break_manager.load_breaks (activity_monitor);
+
+ this.restore_state ();
+
+ this.activity_monitor.start ();
+
+ var connection = this.get_dbus_connection ();
+ if (connection != null) {
+ Bus.own_name_on_connection (connection, Config.HELPER_BUS_NAME, BusNameOwnerFlags.REPLACE, null,
null);
+ }
+ }
+
+ public override void shutdown () {
+ base.shutdown ();
+
+ this.save_state ();
+ }
+
+ private File get_state_file () {
+ File cache_dir = File.new_for_path (this.cache_path);
+ try {
+ if (! cache_dir.query_exists ()) cache_dir.make_directory_with_parents ();
+ } catch (Error e) {
+ GLib.warning ("Error creating cache directory: %s", e.message);
+ }
+ string state_file_name = "last-state-%d".printf (DATA_VERSION);
+ return cache_dir.get_child (state_file_name);
+ }
+
+ private void save_state () {
+ File state_file = this.get_state_file ();
+
+ Json.Generator generator = new Json.Generator ();
+ Json.Node root = new Json.Node (Json.NodeType.OBJECT);
+ Json.Object root_object = new Json.Object ();
+ root.set_object (root_object);
+ generator.set_root (root);
+
+ root_object.set_object_member ("break_manager", this.break_manager.serialize ());
+ root_object.set_object_member ("activity_monitor_backend", this.activity_monitor_backend.serialize
());
+ root_object.set_object_member ("activity_monitor", this.activity_monitor.serialize ());
+
+ try {
+ OutputStream state_stream = state_file.replace (null, false, FileCreateFlags.NONE);
+ generator.to_stream (state_stream);
+ } catch (Error e) {
+ GLib.warning ("Error writing to state file: %s", e.message);
+ }
+ }
+
+ private void restore_state () {
+ File state_file = this.get_state_file ();
+ if (state_file.query_exists ()) {
+ Json.Parser parser = new Json.Parser ();
+
+ try {
+ InputStream state_stream = state_file.read ();
+ parser.load_from_stream (state_stream);
+ } catch (Error e) {
+ GLib.warning ("Error reading state file: %s", e.message);
+ }
+
+ Json.Node? root = parser.get_root ();
+ if (root != null) {
+ Json.Object root_object = root.get_object ();
+
+ Json.Object break_manager_json = root_object.get_object_member ("break_manager");
+ this.break_manager.deserialize (ref break_manager_json);
+
+ Json.Object activity_monitor_backend_json = root_object.get_object_member
("activity_monitor_backend");
+ this.activity_monitor_backend.deserialize (ref activity_monitor_backend_json);
+
+ Json.Object activity_monitor_json = root_object.get_object_member ("activity_monitor");
+ this.activity_monitor.deserialize (ref activity_monitor_json);
+
+ this.activity_monitor.poll_activity ();
+ }
+ }
+ }
}
}
diff --git a/helper/ScreenOverlay.vala b/helper/ScreenOverlay.vala
index 9c90305..415a78c 100644
--- a/helper/ScreenOverlay.vala
+++ b/helper/ScreenOverlay.vala
@@ -20,241 +20,241 @@ namespace BreakTimer.Helper {
/* FIXME: Do another overlay widget and kill the set_format junk :) */
public interface IScreenOverlayContent : Gtk.Widget {
- public abstract void added_to_overlay ();
- public abstract void removed_from_overlay ();
- public abstract void before_fade_in ();
- public abstract void before_fade_out ();
+ public abstract void added_to_overlay ();
+ public abstract void removed_from_overlay ();
+ public abstract void before_fade_in ();
+ public abstract void before_fade_out ();
}
public class ScreenOverlay : Gtk.Window {
- public enum Format {
- SILENT,
- MINI,
- FULL
- }
+ public enum Format {
+ SILENT,
+ MINI,
+ FULL
+ }
- private Format format;
- private Gtk.Grid wrapper_grid;
- private IScreenOverlayContent? custom_content;
- private uint fade_timeout;
+ private Format format;
+ private Gtk.Grid wrapper_grid;
+ private IScreenOverlayContent? custom_content;
+ private uint fade_timeout;
- private delegate void FadeCompleteCb ();
-
- public ScreenOverlay () {
- Object (type: Gtk.WindowType.POPUP);
-
- this.format = Format.FULL;
+ private delegate void FadeCompleteCb ();
+
+ public ScreenOverlay () {
+ Object (type: Gtk.WindowType.POPUP);
+
+ this.format = Format.FULL;
- this.wrapper_grid = new Gtk.Grid ();
- this.add (this.wrapper_grid);
- this.wrapper_grid.show ();
- this.wrapper_grid.set_halign (Gtk.Align.CENTER);
- this.wrapper_grid.set_valign (Gtk.Align.CENTER);
-
- Gdk.Screen screen = this.get_screen ();
- screen.composited_changed.connect (this.on_screen_composited_changed);
- this.on_screen_composited_changed (screen);
-
- Gtk.StyleContext style = this.get_style_context ();
- style.add_class ("_screen-overlay");
+ this.wrapper_grid = new Gtk.Grid ();
+ this.add (this.wrapper_grid);
+ this.wrapper_grid.show ();
+ this.wrapper_grid.set_halign (Gtk.Align.CENTER);
+ this.wrapper_grid.set_valign (Gtk.Align.CENTER);
+
+ Gdk.Screen screen = this.get_screen ();
+ screen.composited_changed.connect (this.on_screen_composited_changed);
+ this.on_screen_composited_changed (screen);
+
+ Gtk.StyleContext style = this.get_style_context ();
+ style.add_class ("_screen-overlay");
- this.realize.connect (this.on_realize);
- this.realize ();
- }
+ this.realize.connect (this.on_realize);
+ this.realize ();
+ }
- private void on_screen_composited_changed (Gdk.Screen screen) {
- Gdk.Visual? screen_visual = null;
- if (screen.is_composited ()) {
- screen_visual = screen.get_rgba_visual ();
- }
- if (screen_visual == null) {
- screen_visual = screen.get_system_visual ();
- }
- this.set_visual (screen_visual);
- }
-
- private void on_realize () {
- this.apply_format (this.format);
- }
+ private void on_screen_composited_changed (Gdk.Screen screen) {
+ Gdk.Visual? screen_visual = null;
+ if (screen.is_composited ()) {
+ screen_visual = screen.get_rgba_visual ();
+ }
+ if (screen_visual == null) {
+ screen_visual = screen.get_system_visual ();
+ }
+ this.set_visual (screen_visual);
+ }
+
+ private void on_realize () {
+ this.apply_format (this.format);
+ }
- private void apply_format (Format format) {
- switch (format) {
- case Format.SILENT:
- this.fade_out ();
- break;
+ private void apply_format (Format format) {
+ switch (format) {
+ case Format.SILENT:
+ this.fade_out ();
+ break;
- case Format.MINI:
- this.input_shape_combine_region ( (Cairo.Region)null);
-
- this.set_size_request (-1, -1);
- this.resize (1, 1);
+ case Format.MINI:
+ this.input_shape_combine_region ( (Cairo.Region)null);
+
+ this.set_size_request (-1, -1);
+ this.resize (1, 1);
- this.fade_in ();
+ this.fade_in ();
- break;
+ break;
- case Format.FULL:
- /* empty input region to ignore any input */
- this.input_shape_combine_region (new Cairo.Region ());
-
- Gdk.Screen screen = this.get_screen ();
- int monitor = screen.get_monitor_at_window (this.get_window ());
- Gdk.Rectangle geom;
- screen.get_monitor_geometry (monitor, out geom);
-
- string? session = Environment.get_variable ("DESKTOP_SESSION");
-
- if (session == "gnome-shell") {
- /* make sure the overlay doesn't cause the top panel to hide */
- // FIXME: position _properly_ around panel, using _NET_WORKAREA or a
maximized toplevel window
- this.set_size_request (geom.width, geom.height-1);
- this.move (0, 1);
- } else {
- this.set_size_request (geom.width, geom.height);
- }
+ case Format.FULL:
+ /* empty input region to ignore any input */
+ this.input_shape_combine_region (new Cairo.Region ());
+
+ Gdk.Screen screen = this.get_screen ();
+ int monitor = screen.get_monitor_at_window (this.get_window ());
+ Gdk.Rectangle geom;
+ screen.get_monitor_geometry (monitor, out geom);
+
+ string? session = Environment.get_variable ("DESKTOP_SESSION");
+
+ if (session == "gnome-shell") {
+ /* make sure the overlay doesn't cause the top panel to hide */
+ // FIXME: position _properly_ around panel, using _NET_WORKAREA or a maximized toplevel
window
+ this.set_size_request (geom.width, geom.height-1);
+ this.move (0, 1);
+ } else {
+ this.set_size_request (geom.width, geom.height);
+ }
- this.fade_in ();
-
- break;
- }
- }
-
- public void set_format (Format format) {
- this.format = format;
- if (this.get_realized ()) this.apply_format (format);
- }
+ this.fade_in ();
+
+ break;
+ }
+ }
+
+ public void set_format (Format format) {
+ this.format = format;
+ if (this.get_realized ()) this.apply_format (format);
+ }
- private static double ease_swing (double p) {
- return 0.5 - Math.cos (p*Math.PI) / 2.0;
- }
+ private static double ease_swing (double p) {
+ return 0.5 - Math.cos (p*Math.PI) / 2.0;
+ }
- private void fade_opacity (double duration_ms, double to, FadeCompleteCb? complete_cb = null) {
- double from;
- if (this.get_visible ()) {
- from = this.get_opacity ();
- } else {
- from = 0.0;
- this.set_opacity (from);
- this.show ();
- }
+ private void fade_opacity (double duration_ms, double to, FadeCompleteCb? complete_cb = null) {
+ double from;
+ if (this.get_visible ()) {
+ from = this.get_opacity ();
+ } else {
+ from = 0.0;
+ this.set_opacity (from);
+ this.show ();
+ }
- double fade_direction = (double) (to - from);
- Timer fade_timer = new Timer ();
+ double fade_direction = (double) (to - from);
+ Timer fade_timer = new Timer ();
- if (this.fade_timeout > 0) Source.remove (this.fade_timeout);
- this.fade_timeout = Timeout.add (20, () => {
- double elapsed_ms = fade_timer.elapsed () * 1000.0;
- double percent = elapsed_ms / duration_ms;
- percent = percent.clamp (0, 1);
- double opacity = from + (fade_direction * ease_swing (percent));
- this.set_opacity (opacity);
+ if (this.fade_timeout > 0) Source.remove (this.fade_timeout);
+ this.fade_timeout = Timeout.add (20, () => {
+ double elapsed_ms = fade_timer.elapsed () * 1000.0;
+ double percent = elapsed_ms / duration_ms;
+ percent = percent.clamp (0, 1);
+ double opacity = from + (fade_direction * ease_swing (percent));
+ this.set_opacity (opacity);
- bool do_continue = percent < 1.0;
- if (! do_continue) {
- if (complete_cb != null) complete_cb ();
- }
- return do_continue;
- });
- }
+ bool do_continue = percent < 1.0;
+ if (! do_continue) {
+ if (complete_cb != null) complete_cb ();
+ }
+ return do_continue;
+ });
+ }
- public void fade_in () {
- if (this.format != Format.SILENT) {
- if (this.custom_content != null) {
- this.custom_content.before_fade_in ();
- this.fade_opacity (2000, 1);
- }
- }
- }
+ public void fade_in () {
+ if (this.format != Format.SILENT) {
+ if (this.custom_content != null) {
+ this.custom_content.before_fade_in ();
+ this.fade_opacity (2000, 1);
+ }
+ }
+ }
- public void fade_out () {
- if (this.get_visible ()) {
- if (this.custom_content != null) {
- this.custom_content.before_fade_out ();
- }
- this.fade_opacity (1500, 0, () => {
- this.hide ();
- });
- }
- }
+ public void fade_out () {
+ if (this.get_visible ()) {
+ if (this.custom_content != null) {
+ this.custom_content.before_fade_out ();
+ }
+ this.fade_opacity (1500, 0, () => {
+ this.hide ();
+ });
+ }
+ }
- private void fade_out_and_remove () {
- if (this.get_visible ()) {
- if (this.custom_content != null) this.custom_content.before_fade_out ();
- this.fade_opacity (1500, 0, () => {
- this.hide ();
- this.set_content (null);
- });
- } else {
- this.set_content (null);
- }
- }
+ private void fade_out_and_remove () {
+ if (this.get_visible ()) {
+ if (this.custom_content != null) this.custom_content.before_fade_out ();
+ this.fade_opacity (1500, 0, () => {
+ this.hide ();
+ this.set_content (null);
+ });
+ } else {
+ this.set_content (null);
+ }
+ }
- public void shake () {
- int start_x;
- int start_y;
- this.get_position (out start_x, out start_y);
-
- int shake_count = 0;
- double velocity_x = 1.5;
- double velocity_y = 0;
-
- double move_x = start_x;
- double move_y = start_y;
-
- Timeout.add (15, () => {
- if (shake_count < 42) {
- if (move_x - start_x > 6 || move_x - start_x < -6) {
- velocity_x = -velocity_x;
- }
- move_x = move_x + velocity_x;
- move_y = move_y + velocity_y;
- this.move ( (int)move_x, (int)move_y);
- shake_count += 1;
- return true;
- } else {
- this.move (start_x, start_y);
- return false;
- }
- });
- }
+ public void shake () {
+ int start_x;
+ int start_y;
+ this.get_position (out start_x, out start_y);
+
+ int shake_count = 0;
+ double velocity_x = 1.5;
+ double velocity_y = 0;
+
+ double move_x = start_x;
+ double move_y = start_y;
+
+ Timeout.add (15, () => {
+ if (shake_count < 42) {
+ if (move_x - start_x > 6 || move_x - start_x < -6) {
+ velocity_x = -velocity_x;
+ }
+ move_x = move_x + velocity_x;
+ move_y = move_y + velocity_y;
+ this.move ( (int)move_x, (int)move_y);
+ shake_count += 1;
+ return true;
+ } else {
+ this.move (start_x, start_y);
+ return false;
+ }
+ });
+ }
- public void request_attention () {
- this.shake ();
- Gdk.Window gdk_window = this.get_window ();
- gdk_window.beep ();
- }
+ public void request_attention () {
+ this.shake ();
+ Gdk.Window gdk_window = this.get_window ();
+ gdk_window.beep ();
+ }
- public void set_content (IScreenOverlayContent? widget) {
- if (this.custom_content != null) {
- this.custom_content.removed_from_overlay ();
- this.wrapper_grid.remove (this.custom_content);
- }
- if (widget != null) {
- widget.added_to_overlay ();
- this.wrapper_grid.add (widget);
- }
- this.custom_content = widget;
- }
+ public void set_content (IScreenOverlayContent? widget) {
+ if (this.custom_content != null) {
+ this.custom_content.removed_from_overlay ();
+ this.wrapper_grid.remove (this.custom_content);
+ }
+ if (widget != null) {
+ widget.added_to_overlay ();
+ this.wrapper_grid.add (widget);
+ }
+ this.custom_content = widget;
+ }
- public void reveal_content (IScreenOverlayContent? widget) {
- this.set_content (widget);
- this.fade_in ();
- }
+ public void reveal_content (IScreenOverlayContent? widget) {
+ this.set_content (widget);
+ this.fade_in ();
+ }
- public void disappear_content (IScreenOverlayContent? widget) {
- if (this.custom_content == widget) {
- this.fade_out_and_remove ();
- }
- }
+ public void disappear_content (IScreenOverlayContent? widget) {
+ if (this.custom_content == widget) {
+ this.fade_out_and_remove ();
+ }
+ }
- public bool is_showing_content (IScreenOverlayContent? widget) {
- if (widget == null) {
- return false;
- } else {
- return this.get_visible () && this.custom_content == widget;
- }
- }
+ public bool is_showing_content (IScreenOverlayContent? widget) {
+ if (widget == null) {
+ return false;
+ } else {
+ return this.get_visible () && this.custom_content == widget;
+ }
+ }
}
}
diff --git a/helper/SessionStatus.vala b/helper/SessionStatus.vala
index 02c99c6..d1cc5db 100644
--- a/helper/SessionStatus.vala
+++ b/helper/SessionStatus.vala
@@ -33,83 +33,83 @@ public interface IScreenSaver : Object {
* case we are unable to connect.
*/
public class SessionStatus : ISessionStatus, Object {
- private Gtk.Application application;
- private IScreenSaver? screensaver;
- private bool screensaver_is_active = false;
+ private Gtk.Application application;
+ private IScreenSaver? screensaver;
+ private bool screensaver_is_active = false;
- public SessionStatus (Gtk.Application application) {
- this.application = application;
+ public SessionStatus (Gtk.Application application) {
+ this.application = application;
- Bus.watch_name (BusType.SESSION, "org.gnome.ScreenSaver", BusNameWatcherFlags.NONE,
- this.screensaver_appeared, this.screensaver_disappeared);
- }
+ Bus.watch_name (BusType.SESSION, "org.gnome.ScreenSaver", BusNameWatcherFlags.NONE,
+ this.screensaver_appeared, this.screensaver_disappeared);
+ }
- private void screensaver_appeared () {
- try {
- this.screensaver = Bus.get_proxy_sync (
- BusType.SESSION,
- "org.gnome.ScreenSaver",
- "/org/gnome/ScreenSaver"
- );
- this.screensaver.active_changed.connect (this.screensaver_active_changed_cb);
- this.screensaver_is_active = this.screensaver.get_active ();
- } catch (IOError error) {
- this.screensaver = null;
- GLib.warning ("Error connecting to screensaver service: %s", error.message);
- }
- }
-
- private void screensaver_disappeared () {
- this.screensaver.active_changed.disconnect (this.screensaver_active_changed_cb);
- this.screensaver = null;
- }
+ private void screensaver_appeared () {
+ try {
+ this.screensaver = Bus.get_proxy_sync (
+ BusType.SESSION,
+ "org.gnome.ScreenSaver",
+ "/org/gnome/ScreenSaver"
+ );
+ this.screensaver.active_changed.connect (this.screensaver_active_changed_cb);
+ this.screensaver_is_active = this.screensaver.get_active ();
+ } catch (IOError error) {
+ this.screensaver = null;
+ GLib.warning ("Error connecting to screensaver service: %s", error.message);
+ }
+ }
+
+ private void screensaver_disappeared () {
+ this.screensaver.active_changed.disconnect (this.screensaver_active_changed_cb);
+ this.screensaver = null;
+ }
- private void screensaver_active_changed_cb (bool active) {
- this.screensaver_is_active = active;
- if (active) {
- this.locked ();
- } else {
- this.unlocked ();
- }
- }
+ private void screensaver_active_changed_cb (bool active) {
+ this.screensaver_is_active = active;
+ if (active) {
+ this.locked ();
+ } else {
+ this.unlocked ();
+ }
+ }
- public bool is_locked () {
- if (this.screensaver != null) {
- return this.screensaver_is_active;
- } else {
- return false;
- }
- }
+ public bool is_locked () {
+ if (this.screensaver != null) {
+ return this.screensaver_is_active;
+ } else {
+ return false;
+ }
+ }
- public void lock_screen () {
- if (this.screensaver != null) {
- try {
- this.screensaver.lock ();
- } catch (IOError error) {
- GLib.warning ("Error locking screen: %s", error.message);
- }
- }
- }
+ public void lock_screen () {
+ if (this.screensaver != null) {
+ try {
+ this.screensaver.lock ();
+ } catch (IOError error) {
+ GLib.warning ("Error locking screen: %s", error.message);
+ }
+ }
+ }
- public void blank_screen () {
- if (this.screensaver != null) {
- try {
- this.screensaver.set_active (true);
- } catch (IOError error) {
- GLib.warning ("Error blanking screeen: %s", error.message);
- }
- }
- }
+ public void blank_screen () {
+ if (this.screensaver != null) {
+ try {
+ this.screensaver.set_active (true);
+ } catch (IOError error) {
+ GLib.warning ("Error blanking screeen: %s", error.message);
+ }
+ }
+ }
- public void unblank_screen () {
- if (this.screensaver != null) {
- try {
- this.screensaver.set_active (false);
- } catch (IOError error) {
- GLib.warning ("Error unblanking screeen: %s", error.message);
- }
- }
- }
+ public void unblank_screen () {
+ if (this.screensaver != null) {
+ try {
+ this.screensaver.set_active (false);
+ } catch (IOError error) {
+ GLib.warning ("Error unblanking screeen: %s", error.message);
+ }
+ }
+ }
}
}
diff --git a/helper/UIManager.vala b/helper/UIManager.vala
index fe350a3..a45d38b 100644
--- a/helper/UIManager.vala
+++ b/helper/UIManager.vala
@@ -26,258 +26,258 @@ namespace BreakTimer.Helper {
* interface to create notifications and overlays.
*/
public class UIManager : SimpleFocusManager {
- public abstract class UIFragment : Object, IFocusable {
- protected UIManager ui_manager;
-
- protected IScreenOverlayContent? overlay_content;
- protected Notify.Notification? notification;
-
- protected FocusPriority focus_priority = FocusPriority.LOW;
-
- public bool has_ui_focus () {
- return this.ui_manager.is_focusing (this);
- }
-
- protected void request_ui_focus () {
- if (this.has_ui_focus ()) {
- // If we already have focus, UIManager will not call
- // focus_started again. We need to call it ourselves.
- this.focus_started ();
- } else {
- this.ui_manager.request_focus (this, this.focus_priority);
- }
- }
-
- protected void release_ui_focus () {
- this.ui_manager.release_focus (this);
- }
-
- protected void play_sound_from_id (string event_id) {
- /* FIXME: Replace this with a modern equivalent? */
- /*
- if (this.has_ui_focus ()) {
- unowned Canberra.Context canberra = CanberraGtk.context_get ();
- canberra.play (0,
- Canberra.PROP_EVENT_ID, event_id
- );
- }
- */
- }
-
- protected bool can_lock_screen () {
- return ! this.ui_manager.application.is_inhibited (Gtk.ApplicationInhibitFlags.IDLE);
- }
-
- protected void lock_screen () {
- if (this.has_ui_focus ()) {
- if (! this.ui_manager.session_status.is_locked ()) {
- this.ui_manager.session_status.lock_screen ();
- }
- }
- }
-
- protected bool notifications_can_do (string capability) {
- // For whatever reason notify_capabilities.index () isn't matching
- // our capability strings, so we'll search the list ourselves
- foreach (string server_capability in this.ui_manager.notify_capabilities) {
- if (server_capability == capability) return true;
- }
- return false;
- }
-
- protected void show_notification (Notify.Notification notification) {
- if (this.has_ui_focus ()) {
- this.ui_manager.show_notification (notification);
- this.notification = notification;
- }
- }
-
- protected void show_lock_notification (Notify.Notification notification) {
- if (this.has_ui_focus ()) {
- this.ui_manager.show_lock_notification (notification);
- this.notification = notification;
- }
- }
-
- protected void hide_notification () {
- this.ui_manager.hide_notification (this.notification);
- }
-
- protected void set_overlay (IScreenOverlayContent overlay_content) {
- if (this.ui_manager.screen_overlay == null) return;
-
- this.overlay_content = overlay_content;
-
- if (this.has_ui_focus ()) {
- this.ui_manager.screen_overlay.set_content (this.overlay_content);
- }
- }
-
- protected void reveal_overlay () {
- if (this.ui_manager.screen_overlay == null) return;
-
- if (this.has_ui_focus ()) {
- this.ui_manager.screen_overlay.reveal_content (this.overlay_content);
- }
- }
-
- protected void shake_overlay () {
- if (this.ui_manager.screen_overlay == null) return;
-
- if (this.overlay_is_visible ()) {
- this.ui_manager.screen_overlay.request_attention ();
- }
- }
-
- protected bool overlay_is_visible () {
- if (this.ui_manager.screen_overlay == null) {
- return false;
- } else {
- return this.ui_manager.screen_overlay.is_showing_content
(this.overlay_content);
- }
- }
-
- protected void hide_overlay () {
- if (this.ui_manager.screen_overlay == null) return;
-
- this.ui_manager.screen_overlay.disappear_content (this.overlay_content);
- }
-
- /* IFocusable interface */
-
- protected abstract void focus_started ();
- protected abstract void focus_stopped ();
- }
-
- private weak Gtk.Application application;
- private ISessionStatus session_status;
-
- public bool quiet_mode { get; set; default=false; }
- public int64 quiet_mode_expire_time { get; set; }
-
- private PausableTimeout quiet_mode_timeout;
-
- protected ScreenOverlay? screen_overlay;
- protected Notify.Notification? notification;
-
- protected List<string> notify_capabilities;
-
- // The desktop-entry notification hint wants our desktop ID without the
- // ".desktop" part, so we need to trim it accordingly
- private static string DESKTOP_ENTRY_BASENAME = Config.HELPER_DESKTOP_ID.slice (
- 0, Config.HELPER_DESKTOP_ID.last_index_of (".desktop")
- );
-
- public UIManager (Gtk.Application application, ISessionStatus session_status, bool with_overlay) {
- this.application = application;
- this.session_status = session_status;
-
- if (with_overlay) {
- this.screen_overlay = new ScreenOverlay ();
- }
-
- Settings settings = new Settings ("org.gnome.BreakTimer");
- settings.bind ("quiet-mode", this, "quiet-mode", SettingsBindFlags.DEFAULT);
- settings.bind ("quiet-mode-expire-time", this, "quiet-mode-expire-time",
SettingsBindFlags.DEFAULT);
-
- this.quiet_mode_timeout = new PausableTimeout (this.quiet_mode_timeout_cb, 30);
- this.notify["quiet-mode"].connect ( (s, p) => {
- this.update_overlay_format ();
- });
- this.update_overlay_format ();
-
- this.session_status.unlocked.connect (this.hide_lock_notification_cb);
- this.notify_capabilities = Notify.get_server_caps ();
- }
-
- private void quiet_mode_timeout_cb (PausableTimeout timeout, int delta_millisecs) {
- int64 now = Util.get_real_time_seconds ();
- if (this.quiet_mode && now > this.quiet_mode_expire_time) {
- this.quiet_mode = false;
- this.quiet_mode_expire_time = 0;
- GLib.debug ("Automatically expiring quiet mode");
- }
- }
-
- private void update_overlay_format () {
- if (this.screen_overlay == null) return;
-
- if (this.quiet_mode) {
- this.screen_overlay.set_format (ScreenOverlay.Format.SILENT);
- this.quiet_mode_timeout.start ();
- this.quiet_mode_timeout.run_once ();
- GLib.debug ("Quiet mode enabled");
- } else {
- this.screen_overlay.set_format (ScreenOverlay.Format.FULL);
- this.quiet_mode_timeout.stop ();
- GLib.debug ("Quiet mode disabled");
- }
- }
-
- /**
- * Show a notification, ensuring that the application is only showing one
- * notification at any time.
- */
- protected void show_notification (Notify.Notification notification) {
- if (notification != this.notification) {
- this.hide_notification (this.notification);
- }
- notification.set_hint ("desktop-entry", DESKTOP_ENTRY_BASENAME);
- try {
- notification.show ();
- } catch (Error error) {
- GLib.warning ("Error showing notification: %s", error.message);
- }
- this.notification = notification;
- }
-
- private Notify.Notification? lock_notification;
- /**
- * Show a notification that will only appear in the lock screen. The
- * notification automatically hides when the screen is unlocked.
- */
- protected void show_lock_notification (Notify.Notification notification) {
- if (this.session_status.is_locked ()) {
- this.lock_notification = notification;
- } else {
- notification.set_hint ("transient", true);
- }
- this.show_notification (notification);
- }
-
- private void hide_lock_notification_cb () {
- this.hide_notification (this.lock_notification, true);
- this.lock_notification = null;
- }
-
- /**
- * Close a notification proactively, if it is still open.
- */
- protected void hide_notification (Notify.Notification? notification, bool immediate=true) {
- if (notification != null && this.notification == notification) {
- try {
- if (immediate) {
- this.notification.close ();
- } else {
- this.notification.set_hint ("transient", true);
- this.notification.show ();
- }
- } catch (Error error) {
- // We ignore this error, because it's usually just noise
- // GLib.warning ("Error closing notification: %s", error.message);
- }
- }
- this.notification = null;
- }
-
- public void add_break (BreakView break_view) {
- this.application.hold ();
- }
-
- public void remove_break (BreakView break_view) {
- this.release_focus (break_view);
- this.application.release ();
- }
+ public abstract class UIFragment : Object, IFocusable {
+ protected UIManager ui_manager;
+
+ protected IScreenOverlayContent? overlay_content;
+ protected Notify.Notification? notification;
+
+ protected FocusPriority focus_priority = FocusPriority.LOW;
+
+ public bool has_ui_focus () {
+ return this.ui_manager.is_focusing (this);
+ }
+
+ protected void request_ui_focus () {
+ if (this.has_ui_focus ()) {
+ // If we already have focus, UIManager will not call
+ // focus_started again. We need to call it ourselves.
+ this.focus_started ();
+ } else {
+ this.ui_manager.request_focus (this, this.focus_priority);
+ }
+ }
+
+ protected void release_ui_focus () {
+ this.ui_manager.release_focus (this);
+ }
+
+ protected void play_sound_from_id (string event_id) {
+ /* FIXME: Replace this with a modern equivalent? */
+ /*
+ if (this.has_ui_focus ()) {
+ unowned Canberra.Context canberra = CanberraGtk.context_get ();
+ canberra.play (0,
+ Canberra.PROP_EVENT_ID, event_id
+ );
+ }
+ */
+ }
+
+ protected bool can_lock_screen () {
+ return ! this.ui_manager.application.is_inhibited (Gtk.ApplicationInhibitFlags.IDLE);
+ }
+
+ protected void lock_screen () {
+ if (this.has_ui_focus ()) {
+ if (! this.ui_manager.session_status.is_locked ()) {
+ this.ui_manager.session_status.lock_screen ();
+ }
+ }
+ }
+
+ protected bool notifications_can_do (string capability) {
+ // For whatever reason notify_capabilities.index () isn't matching
+ // our capability strings, so we'll search the list ourselves
+ foreach (string server_capability in this.ui_manager.notify_capabilities) {
+ if (server_capability == capability) return true;
+ }
+ return false;
+ }
+
+ protected void show_notification (Notify.Notification notification) {
+ if (this.has_ui_focus ()) {
+ this.ui_manager.show_notification (notification);
+ this.notification = notification;
+ }
+ }
+
+ protected void show_lock_notification (Notify.Notification notification) {
+ if (this.has_ui_focus ()) {
+ this.ui_manager.show_lock_notification (notification);
+ this.notification = notification;
+ }
+ }
+
+ protected void hide_notification () {
+ this.ui_manager.hide_notification (this.notification);
+ }
+
+ protected void set_overlay (IScreenOverlayContent overlay_content) {
+ if (this.ui_manager.screen_overlay == null) return;
+
+ this.overlay_content = overlay_content;
+
+ if (this.has_ui_focus ()) {
+ this.ui_manager.screen_overlay.set_content (this.overlay_content);
+ }
+ }
+
+ protected void reveal_overlay () {
+ if (this.ui_manager.screen_overlay == null) return;
+
+ if (this.has_ui_focus ()) {
+ this.ui_manager.screen_overlay.reveal_content (this.overlay_content);
+ }
+ }
+
+ protected void shake_overlay () {
+ if (this.ui_manager.screen_overlay == null) return;
+
+ if (this.overlay_is_visible ()) {
+ this.ui_manager.screen_overlay.request_attention ();
+ }
+ }
+
+ protected bool overlay_is_visible () {
+ if (this.ui_manager.screen_overlay == null) {
+ return false;
+ } else {
+ return this.ui_manager.screen_overlay.is_showing_content (this.overlay_content);
+ }
+ }
+
+ protected void hide_overlay () {
+ if (this.ui_manager.screen_overlay == null) return;
+
+ this.ui_manager.screen_overlay.disappear_content (this.overlay_content);
+ }
+
+ /* IFocusable interface */
+
+ protected abstract void focus_started ();
+ protected abstract void focus_stopped ();
+ }
+
+ private weak Gtk.Application application;
+ private ISessionStatus session_status;
+
+ public bool quiet_mode { get; set; default=false; }
+ public int64 quiet_mode_expire_time { get; set; }
+
+ private PausableTimeout quiet_mode_timeout;
+
+ protected ScreenOverlay? screen_overlay;
+ protected Notify.Notification? notification;
+
+ protected List<string> notify_capabilities;
+
+ // The desktop-entry notification hint wants our desktop ID without the
+ // ".desktop" part, so we need to trim it accordingly
+ private static string DESKTOP_ENTRY_BASENAME = Config.HELPER_DESKTOP_ID.slice (
+ 0, Config.HELPER_DESKTOP_ID.last_index_of (".desktop")
+ );
+
+ public UIManager (Gtk.Application application, ISessionStatus session_status, bool with_overlay) {
+ this.application = application;
+ this.session_status = session_status;
+
+ if (with_overlay) {
+ this.screen_overlay = new ScreenOverlay ();
+ }
+
+ Settings settings = new Settings ("org.gnome.BreakTimer");
+ settings.bind ("quiet-mode", this, "quiet-mode", SettingsBindFlags.DEFAULT);
+ settings.bind ("quiet-mode-expire-time", this, "quiet-mode-expire-time", SettingsBindFlags.DEFAULT);
+
+ this.quiet_mode_timeout = new PausableTimeout (this.quiet_mode_timeout_cb, 30);
+ this.notify["quiet-mode"].connect ( (s, p) => {
+ this.update_overlay_format ();
+ });
+ this.update_overlay_format ();
+
+ this.session_status.unlocked.connect (this.hide_lock_notification_cb);
+ this.notify_capabilities = Notify.get_server_caps ();
+ }
+
+ private void quiet_mode_timeout_cb (PausableTimeout timeout, int delta_millisecs) {
+ int64 now = Util.get_real_time_seconds ();
+ if (this.quiet_mode && now > this.quiet_mode_expire_time) {
+ this.quiet_mode = false;
+ this.quiet_mode_expire_time = 0;
+ GLib.debug ("Automatically expiring quiet mode");
+ }
+ }
+
+ private void update_overlay_format () {
+ if (this.screen_overlay == null) return;
+
+ if (this.quiet_mode) {
+ this.screen_overlay.set_format (ScreenOverlay.Format.SILENT);
+ this.quiet_mode_timeout.start ();
+ this.quiet_mode_timeout.run_once ();
+ GLib.debug ("Quiet mode enabled");
+ } else {
+ this.screen_overlay.set_format (ScreenOverlay.Format.FULL);
+ this.quiet_mode_timeout.stop ();
+ GLib.debug ("Quiet mode disabled");
+ }
+ }
+
+ /**
+ * Show a notification, ensuring that the application is only showing one
+ * notification at any time.
+ */
+ protected void show_notification (Notify.Notification notification) {
+ if (notification != this.notification) {
+ this.hide_notification (this.notification);
+ }
+ notification.set_hint ("desktop-entry", DESKTOP_ENTRY_BASENAME);
+ try {
+ notification.show ();
+ } catch (Error error) {
+ GLib.warning ("Error showing notification: %s", error.message);
+ }
+ this.notification = notification;
+ }
+
+ private Notify.Notification? lock_notification;
+ /**
+ * Show a notification that will only appear in the lock screen. The
+ * notification automatically hides when the screen is unlocked.
+ */
+ protected void show_lock_notification (Notify.Notification notification) {
+ if (this.session_status.is_locked ()) {
+ this.lock_notification = notification;
+ } else {
+ notification.set_hint ("transient", true);
+ }
+ this.show_notification (notification);
+ }
+
+ private void hide_lock_notification_cb () {
+ this.hide_notification (this.lock_notification, true);
+ this.lock_notification = null;
+ }
+
+ /**
+ * Close a notification proactively, if it is still open.
+ */
+ protected void hide_notification (Notify.Notification? notification, bool immediate=true) {
+ if (notification != null && this.notification == notification) {
+ try {
+ if (immediate) {
+ this.notification.close ();
+ } else {
+ this.notification.set_hint ("transient", true);
+ this.notification.show ();
+ }
+ } catch (Error error) {
+ // We ignore this error, because it's usually just noise
+ // GLib.warning ("Error closing notification: %s", error.message);
+ }
+ }
+ this.notification = null;
+ }
+
+ public void add_break (BreakView break_view) {
+ this.application.hold ();
+ }
+
+ public void remove_break (BreakView break_view) {
+ this.release_focus (break_view);
+ this.application.release ();
+ }
}
}
diff --git a/helper/activity-monitor/ActivityMonitor.vala b/helper/activity-monitor/ActivityMonitor.vala
index 41ff270..3c38327 100644
--- a/helper/activity-monitor/ActivityMonitor.vala
+++ b/helper/activity-monitor/ActivityMonitor.vala
@@ -18,217 +18,217 @@
namespace BreakTimer.Helper {
public class ActivityMonitor : Object {
- public enum ActivityType {
- SLEEP,
- LOCKED,
- NONE,
- INPUT,
- UNLOCK
- }
-
- public struct UserActivity {
- public ActivityType type;
- public int64 idle_time;
- public int64 time_since_active;
- public int64 time_correction;
-
- public Json.Object serialize () {
- Json.Object json_root = new Json.Object ();
- json_root.set_int_member ("type", (int) this.type);
- json_root.set_int_member ("idle_time", this.idle_time);
- json_root.set_int_member ("time_since_active", this.time_since_active);
- json_root.set_int_member ("time_correction", this.time_correction);
- return json_root;
- }
-
- public static UserActivity deserialize (ref Json.Object json_root) {
- return UserActivity () {
- type = (ActivityType) json_root.get_int_member ("type"),
- idle_time = json_root.get_int_member ("idle_time"),
- time_since_active = json_root.get_int_member ("time_since_active"),
- time_correction = json_root.get_int_member ("time_correction")
- };
- }
-
- public bool is_active () {
- return this.type > ActivityType.NONE;
- }
- }
-
- public signal void detected_idle (UserActivity activity);
- public signal void detected_activity (UserActivity activity);
-
- private PausableTimeout poll_activity_timeout;
- private UserActivity last_activity;
- private int64 last_active_timestamp;
-
- private ISessionStatus session_status;
- private ActivityMonitorBackend backend;
-
- public ActivityMonitor (ISessionStatus session_status, ActivityMonitorBackend backend) {
- this.session_status = session_status;
- this.backend = backend;
-
- this.poll_activity_timeout = new PausableTimeout (this.poll_activity_cb, 1);
- session_status.unlocked.connect (this.unlocked_cb);
-
- this.last_activity = UserActivity ();
- }
-
- public Json.Object serialize () {
- Json.Object json_root = new Json.Object ();
- json_root.set_int_member ("last_active_timestamp", this.last_active_timestamp);
- json_root.set_object_member ("last_activity", this.last_activity.serialize ());
- return json_root;
- }
-
- public void deserialize (ref Json.Object json_root) {
- this.last_active_timestamp = json_root.get_int_member ("last_active_timestamp");
- Json.Object? last_activity_json = json_root.get_object_member ("last_activity");
- this.last_activity = UserActivity.deserialize (ref last_activity_json);
- }
-
- public void start () {
- this.poll_activity_timeout.start ();
- }
-
- public void stop () {
- this.poll_activity_timeout.stop ();
- }
-
- public void poll_activity () {
- UserActivity activity = this.collect_activity ();
- this.add_activity (activity);
- }
-
- private void poll_activity_cb (PausableTimeout timeout, int delta_millisecs) {
- this.poll_activity ();
- }
-
- private void unlocked_cb () {
- UserActivity activity = UserActivity () {
- type = ActivityType.UNLOCK,
- idle_time = 0,
- time_correction = 0
- };
- this.add_activity (activity);
- }
-
- private void add_activity (UserActivity activity) {
- this.last_activity = activity;
- if (activity.is_active ()) {
- this.last_active_timestamp = Util.get_real_time_seconds ();
- this.detected_activity (activity);
- } else {
- this.detected_idle (activity);
- }
- }
-
- /**
- * Determines user activity level since the last call to this function.
- * This function is ugly and stateful, so it shouldn't be called from
- * more than one place.
- * @returns a struct with information about the user's current activity
- */
- private UserActivity collect_activity () {
- UserActivity activity;
-
- int64 sleep_time = backend.pop_sleep_time ();
- int64 idle_time = backend.get_idle_seconds ();
- int64 time_since_active = (int64) (Util.get_real_time_seconds () -
this.last_active_timestamp);
-
- // Order is important here: some types of activity (or inactivity)
- // happen at the same time, and are only reported once.
-
- if (sleep_time > idle_time + 5) {
- // Detected sleep time exceeds reported idle time by a healthy
- // margin. We use a magic number to filter out strange cases
- activity = UserActivity () {
- type = ActivityType.SLEEP,
- idle_time = 0,
- time_correction = sleep_time
- };
- GLib.debug ("Detected system sleep for " + int64.FORMAT + " seconds", sleep_time);
- } else if (this.session_status.is_locked ()) {
- activity = UserActivity () {
- type = ActivityType.LOCKED,
- idle_time = idle_time,
- time_correction = 0
- };
- } else if (idle_time == 0 || idle_time < this.last_activity.idle_time) {
- activity = UserActivity () {
- type = ActivityType.INPUT,
- idle_time = idle_time,
- time_correction = 0
- };
- } else {
- activity = UserActivity () {
- type = ActivityType.NONE,
- idle_time = idle_time,
- time_correction = 0
- };
- }
-
- activity.time_since_active = time_since_active;
-
- /*
- // Catch up idle time missed due to infrequent updates.
- // Should be unnecessary now that we just update every second.
- if (activity.idle_time > this.fuzzy_seconds && this.fuzzy_seconds > 0) {
- activity.time_correction = activity.idle_time - this.fuzzy_seconds;
- }
- */
-
- return activity;
- }
+ public enum ActivityType {
+ SLEEP,
+ LOCKED,
+ NONE,
+ INPUT,
+ UNLOCK
+ }
+
+ public struct UserActivity {
+ public ActivityType type;
+ public int64 idle_time;
+ public int64 time_since_active;
+ public int64 time_correction;
+
+ public Json.Object serialize () {
+ Json.Object json_root = new Json.Object ();
+ json_root.set_int_member ("type", (int) this.type);
+ json_root.set_int_member ("idle_time", this.idle_time);
+ json_root.set_int_member ("time_since_active", this.time_since_active);
+ json_root.set_int_member ("time_correction", this.time_correction);
+ return json_root;
+ }
+
+ public static UserActivity deserialize (ref Json.Object json_root) {
+ return UserActivity () {
+ type = (ActivityType) json_root.get_int_member ("type"),
+ idle_time = json_root.get_int_member ("idle_time"),
+ time_since_active = json_root.get_int_member ("time_since_active"),
+ time_correction = json_root.get_int_member ("time_correction")
+ };
+ }
+
+ public bool is_active () {
+ return this.type > ActivityType.NONE;
+ }
+ }
+
+ public signal void detected_idle (UserActivity activity);
+ public signal void detected_activity (UserActivity activity);
+
+ private PausableTimeout poll_activity_timeout;
+ private UserActivity last_activity;
+ private int64 last_active_timestamp;
+
+ private ISessionStatus session_status;
+ private ActivityMonitorBackend backend;
+
+ public ActivityMonitor (ISessionStatus session_status, ActivityMonitorBackend backend) {
+ this.session_status = session_status;
+ this.backend = backend;
+
+ this.poll_activity_timeout = new PausableTimeout (this.poll_activity_cb, 1);
+ session_status.unlocked.connect (this.unlocked_cb);
+
+ this.last_activity = UserActivity ();
+ }
+
+ public Json.Object serialize () {
+ Json.Object json_root = new Json.Object ();
+ json_root.set_int_member ("last_active_timestamp", this.last_active_timestamp);
+ json_root.set_object_member ("last_activity", this.last_activity.serialize ());
+ return json_root;
+ }
+
+ public void deserialize (ref Json.Object json_root) {
+ this.last_active_timestamp = json_root.get_int_member ("last_active_timestamp");
+ Json.Object? last_activity_json = json_root.get_object_member ("last_activity");
+ this.last_activity = UserActivity.deserialize (ref last_activity_json);
+ }
+
+ public void start () {
+ this.poll_activity_timeout.start ();
+ }
+
+ public void stop () {
+ this.poll_activity_timeout.stop ();
+ }
+
+ public void poll_activity () {
+ UserActivity activity = this.collect_activity ();
+ this.add_activity (activity);
+ }
+
+ private void poll_activity_cb (PausableTimeout timeout, int delta_millisecs) {
+ this.poll_activity ();
+ }
+
+ private void unlocked_cb () {
+ UserActivity activity = UserActivity () {
+ type = ActivityType.UNLOCK,
+ idle_time = 0,
+ time_correction = 0
+ };
+ this.add_activity (activity);
+ }
+
+ private void add_activity (UserActivity activity) {
+ this.last_activity = activity;
+ if (activity.is_active ()) {
+ this.last_active_timestamp = Util.get_real_time_seconds ();
+ this.detected_activity (activity);
+ } else {
+ this.detected_idle (activity);
+ }
+ }
+
+ /**
+ * Determines user activity level since the last call to this function.
+ * This function is ugly and stateful, so it shouldn't be called from
+ * more than one place.
+ * @returns a struct with information about the user's current activity
+ */
+ private UserActivity collect_activity () {
+ UserActivity activity;
+
+ int64 sleep_time = backend.pop_sleep_time ();
+ int64 idle_time = backend.get_idle_seconds ();
+ int64 time_since_active = (int64) (Util.get_real_time_seconds () - this.last_active_timestamp);
+
+ // Order is important here: some types of activity (or inactivity)
+ // happen at the same time, and are only reported once.
+
+ if (sleep_time > idle_time + 5) {
+ // Detected sleep time exceeds reported idle time by a healthy
+ // margin. We use a magic number to filter out strange cases
+ activity = UserActivity () {
+ type = ActivityType.SLEEP,
+ idle_time = 0,
+ time_correction = sleep_time
+ };
+ GLib.debug ("Detected system sleep for " + int64.FORMAT + " seconds", sleep_time);
+ } else if (this.session_status.is_locked ()) {
+ activity = UserActivity () {
+ type = ActivityType.LOCKED,
+ idle_time = idle_time,
+ time_correction = 0
+ };
+ } else if (idle_time == 0 || idle_time < this.last_activity.idle_time) {
+ activity = UserActivity () {
+ type = ActivityType.INPUT,
+ idle_time = idle_time,
+ time_correction = 0
+ };
+ } else {
+ activity = UserActivity () {
+ type = ActivityType.NONE,
+ idle_time = idle_time,
+ time_correction = 0
+ };
+ }
+
+ activity.time_since_active = time_since_active;
+
+ /*
+ // Catch up idle time missed due to infrequent updates.
+ // Should be unnecessary now that we just update every second.
+ if (activity.idle_time > this.fuzzy_seconds && this.fuzzy_seconds > 0) {
+ activity.time_correction = activity.idle_time - this.fuzzy_seconds;
+ }
+ */
+
+ return activity;
+ }
}
public abstract class ActivityMonitorBackend : Object {
- private int64 last_real_time = 0;
- private int64 last_monotonic_time = 0;
-
- public virtual Json.Object serialize () {
- Json.Object json_root = new Json.Object ();
- json_root.set_int_member ("last_real_time", this.last_real_time);
- json_root.set_int_member ("last_monotonic_time", this.last_monotonic_time);
- return json_root;
- }
-
- public virtual void deserialize (ref Json.Object json_root) {
- this.last_real_time = json_root.get_int_member ("last_real_time");
- this.last_monotonic_time = json_root.get_int_member ("last_monotonic_time");
- }
-
- protected abstract uint64 time_since_last_event_ms ();
-
- public int64 get_idle_seconds () {
- uint64 idle_ms = this.time_since_last_event_ms ();
- return (int64) idle_ms / Util.MILLISECONDS_IN_SECONDS;
- }
-
- /** Detect if the device has been asleep using the difference between monotonic time and real time */
- public int64 pop_sleep_time () {
- int64 sleep_time;
- int64 now_real = Util.get_real_time_seconds ();
- int64 now_monotonic = Util.get_monotonic_time_seconds ();
- int64 real_time_delta = (int64) (now_real - this.last_real_time);
- int64 monotonic_time_delta = (int64) (now_monotonic - this.last_monotonic_time).abs ();
-
- if (this.last_real_time > 0 && this.last_monotonic_time > 0) {
- if (real_time_delta > monotonic_time_delta) {
- sleep_time = (int64) (real_time_delta - monotonic_time_delta);
- } else {
- sleep_time = real_time_delta;
- }
- } else {
- sleep_time = 0;
- }
-
- this.last_real_time = now_real;
- this.last_monotonic_time = now_monotonic;
-
- return sleep_time;
- }
+ private int64 last_real_time = 0;
+ private int64 last_monotonic_time = 0;
+
+ public virtual Json.Object serialize () {
+ Json.Object json_root = new Json.Object ();
+ json_root.set_int_member ("last_real_time", this.last_real_time);
+ json_root.set_int_member ("last_monotonic_time", this.last_monotonic_time);
+ return json_root;
+ }
+
+ public virtual void deserialize (ref Json.Object json_root) {
+ this.last_real_time = json_root.get_int_member ("last_real_time");
+ this.last_monotonic_time = json_root.get_int_member ("last_monotonic_time");
+ }
+
+ protected abstract uint64 time_since_last_event_ms ();
+
+ public int64 get_idle_seconds () {
+ uint64 idle_ms = this.time_since_last_event_ms ();
+ return (int64) idle_ms / Util.MILLISECONDS_IN_SECONDS;
+ }
+
+ /** Detect if the device has been asleep using the difference between monotonic time and real time */
+ public int64 pop_sleep_time () {
+ int64 sleep_time;
+ int64 now_real = Util.get_real_time_seconds ();
+ int64 now_monotonic = Util.get_monotonic_time_seconds ();
+ int64 real_time_delta = (int64) (now_real - this.last_real_time);
+ int64 monotonic_time_delta = (int64) (now_monotonic - this.last_monotonic_time).abs ();
+
+ if (this.last_real_time > 0 && this.last_monotonic_time > 0) {
+ if (real_time_delta > monotonic_time_delta) {
+ sleep_time = (int64) (real_time_delta - monotonic_time_delta);
+ } else {
+ sleep_time = real_time_delta;
+ }
+ } else {
+ sleep_time = 0;
+ }
+
+ this.last_real_time = now_real;
+ this.last_monotonic_time = now_monotonic;
+
+ return sleep_time;
+ }
}
}
diff --git a/helper/activity-monitor/MutterActivityMonitorBackend.vala
b/helper/activity-monitor/MutterActivityMonitorBackend.vala
index 699174c..0593990 100644
--- a/helper/activity-monitor/MutterActivityMonitorBackend.vala
+++ b/helper/activity-monitor/MutterActivityMonitorBackend.vala
@@ -19,90 +19,90 @@ namespace BreakTimer.Helper {
[DBus (name = "org.gnome.Mutter.IdleMonitor")]
public interface IMutterIdleMonitor : Object {
- public abstract uint32 add_idle_watch(uint64 interval_ms) throws GLib.DBusError, GLib.IOError;
- public abstract uint32 add_user_active_watch() throws GLib.DBusError, GLib.IOError;
- public abstract uint64 get_idletime() throws GLib.DBusError, GLib.IOError;
- public abstract void remove_watch(uint32 id) throws GLib.DBusError, GLib.IOError;
- public abstract void reset_idletime() throws GLib.DBusError, GLib.IOError;
+ public abstract uint32 add_idle_watch(uint64 interval_ms) throws GLib.DBusError, GLib.IOError;
+ public abstract uint32 add_user_active_watch() throws GLib.DBusError, GLib.IOError;
+ public abstract uint64 get_idletime() throws GLib.DBusError, GLib.IOError;
+ public abstract void remove_watch(uint32 id) throws GLib.DBusError, GLib.IOError;
+ public abstract void reset_idletime() throws GLib.DBusError, GLib.IOError;
- public signal void watch_fired (uint32 id);
+ public signal void watch_fired (uint32 id);
}
public class MutterActivityMonitorBackend : ActivityMonitorBackend {
- private IMutterIdleMonitor? mutter_idle_monitor;
- private uint32 idle_watch_id;
- private uint32 user_active_watch_id;
+ private IMutterIdleMonitor? mutter_idle_monitor;
+ private uint32 idle_watch_id;
+ private uint32 user_active_watch_id;
- private uint64 last_idle_time_ms;
- private int64 last_idle_time_update_time_ms;
- private bool user_is_active;
+ private uint64 last_idle_time_ms;
+ private int64 last_idle_time_update_time_ms;
+ private bool user_is_active;
- private static uint64 IDLE_WATCH_INTERVAL_MS = 1000;
+ private static uint64 IDLE_WATCH_INTERVAL_MS = 1000;
- public MutterActivityMonitorBackend () {
- this.user_is_active = false;
- Bus.watch_name (
- BusType.SESSION,
- "org.gnome.Mutter.IdleMonitor",
- BusNameWatcherFlags.NONE,
- this.mutter_idle_monitor_appeared,
- this.mutter_idle_monitor_disappeared
- );
- }
+ public MutterActivityMonitorBackend () {
+ this.user_is_active = false;
+ Bus.watch_name (
+ BusType.SESSION,
+ "org.gnome.Mutter.IdleMonitor",
+ BusNameWatcherFlags.NONE,
+ this.mutter_idle_monitor_appeared,
+ this.mutter_idle_monitor_disappeared
+ );
+ }
- ~MutterActivityMonitorBackend() {
- if (this.mutter_idle_monitor != null && this.idle_watch_id > 0) {
- this.mutter_idle_monitor.remove_watch (this.idle_watch_id);
- }
- }
+ ~MutterActivityMonitorBackend() {
+ if (this.mutter_idle_monitor != null && this.idle_watch_id > 0) {
+ this.mutter_idle_monitor.remove_watch (this.idle_watch_id);
+ }
+ }
- private void mutter_idle_monitor_appeared () {
- try {
- this.mutter_idle_monitor = Bus.get_proxy_sync (
- BusType.SESSION,
- "org.gnome.Mutter.IdleMonitor",
- "/org/gnome/Mutter/IdleMonitor/Core"
- );
- this.mutter_idle_monitor.watch_fired.connect
(this.mutter_idle_monitor_watch_fired_cb);
- this.idle_watch_id = this.mutter_idle_monitor.add_idle_watch (IDLE_WATCH_INTERVAL_MS);
- this.update_last_idle_time();
- } catch (IOError error) {
- this.mutter_idle_monitor = null;
- GLib.warning ("Error connecting to mutter idle monitor service: %s", error.message);
- }
- }
+ private void mutter_idle_monitor_appeared () {
+ try {
+ this.mutter_idle_monitor = Bus.get_proxy_sync (
+ BusType.SESSION,
+ "org.gnome.Mutter.IdleMonitor",
+ "/org/gnome/Mutter/IdleMonitor/Core"
+ );
+ this.mutter_idle_monitor.watch_fired.connect (this.mutter_idle_monitor_watch_fired_cb);
+ this.idle_watch_id = this.mutter_idle_monitor.add_idle_watch (IDLE_WATCH_INTERVAL_MS);
+ this.update_last_idle_time();
+ } catch (IOError error) {
+ this.mutter_idle_monitor = null;
+ GLib.warning ("Error connecting to mutter idle monitor service: %s", error.message);
+ }
+ }
- private void mutter_idle_monitor_disappeared () {
- this.mutter_idle_monitor = null;
- this.idle_watch_id = 0;
- }
+ private void mutter_idle_monitor_disappeared () {
+ this.mutter_idle_monitor = null;
+ this.idle_watch_id = 0;
+ }
- private void mutter_idle_monitor_watch_fired_cb (uint32 id) {
- if (id == this.idle_watch_id) {
- this.user_is_active = false;
- this.update_last_idle_time();
- this.user_active_watch_id = this.mutter_idle_monitor.add_user_active_watch ();
- } else if (id == this.user_active_watch_id) {
- this.user_is_active = true;
- this.user_active_watch_id = 0;
- }
- }
+ private void mutter_idle_monitor_watch_fired_cb (uint32 id) {
+ if (id == this.idle_watch_id) {
+ this.user_is_active = false;
+ this.update_last_idle_time();
+ this.user_active_watch_id = this.mutter_idle_monitor.add_user_active_watch ();
+ } else if (id == this.user_active_watch_id) {
+ this.user_is_active = true;
+ this.user_active_watch_id = 0;
+ }
+ }
- private void update_last_idle_time() {
- this.last_idle_time_ms = this.mutter_idle_monitor.get_idletime ();
- this.last_idle_time_update_time_ms = Util.get_monotonic_time_ms ();
- }
+ private void update_last_idle_time() {
+ this.last_idle_time_ms = this.mutter_idle_monitor.get_idletime ();
+ this.last_idle_time_update_time_ms = Util.get_monotonic_time_ms ();
+ }
- protected override uint64 time_since_last_event_ms () {
- if (this.user_is_active) {
- return 0;
- } else {
- int64 now = Util.get_monotonic_time_ms ();
- int64 time_since = now - this.last_idle_time_update_time_ms;
- uint64 idle_time_ms = this.last_idle_time_ms + time_since;
- return idle_time_ms;
- }
- }
+ protected override uint64 time_since_last_event_ms () {
+ if (this.user_is_active) {
+ return 0;
+ } else {
+ int64 now = Util.get_monotonic_time_ms ();
+ int64 time_since = now - this.last_idle_time_update_time_ms;
+ uint64 idle_time_ms = this.last_idle_time_ms + time_since;
+ return idle_time_ms;
+ }
+ }
}
}
diff --git a/helper/break/BreakController.vala b/helper/break/BreakController.vala
index 9cca7e4..3f41e0d 100644
--- a/helper/break/BreakController.vala
+++ b/helper/break/BreakController.vala
@@ -27,163 +27,163 @@ namespace BreakTimer.Helper {
* break's state, which can be either WAITING, ACTIVE, or DISABLED.
*/
public abstract class BreakController : Object {
- /**
- * ''WAITING'': The break has not started yet. For example, it may be
- * monitoring user activity in the background, waiting
- * until the user has been working for a particular
- * time.
- * ''ACTIVE'': The break has started. For example, when a break
- * becomes active, it might show a "Take a break"
- * screen. Once the break has been satisfied, it should
- * return to the WAITING state.
- * ''DISABLED'': The break is not in use, and should not be monitoring
- * activity. This state is usually set explicitly by
- * BreakManager.
- */
- public enum State {
- WAITING,
- ACTIVE,
- DISABLED
- }
- public State state { get; private set; }
+ /**
+ * ''WAITING'': The break has not started yet. For example, it may be
+ * monitoring user activity in the background, waiting
+ * until the user has been working for a particular
+ * time.
+ * ''ACTIVE'': The break has started. For example, when a break
+ * becomes active, it might show a "Take a break"
+ * screen. Once the break has been satisfied, it should
+ * return to the WAITING state.
+ * ''DISABLED'': The break is not in use, and should not be monitoring
+ * activity. This state is usually set explicitly by
+ * BreakManager.
+ */
+ public enum State {
+ WAITING,
+ ACTIVE,
+ DISABLED
+ }
+ public State state { get; private set; }
- public enum FinishedReason {
- DISABLED,
- SKIPPED,
- SATISFIED
- }
-
- /** The break has been enabled. It will monitor user activity and emit activated () or finished ()
signals until it is disabled. */
- public signal void enabled ();
- /** The break has been disabled. Its timers have been stopped and it will not do anything until it is
enabled again. */
- public signal void disabled ();
+ public enum FinishedReason {
+ DISABLED,
+ SKIPPED,
+ SATISFIED
+ }
+
+ /** The break has been enabled. It will monitor user activity and emit activated () or finished ()
signals until it is disabled. */
+ public signal void enabled ();
+ /** The break has been disabled. Its timers have been stopped and it will not do anything until it is
enabled again. */
+ public signal void disabled ();
- /** The break is going to happen soon */
- public signal void warned ();
- /** The break is no longer going to start soon */
- public signal void unwarned ();
-
- /** The break has been activated and is now counting down aggressively until it is satisfied. */
- public signal void activated ();
- /** The break has been satisfied. This can happen at any time, including while the break is waiting
or after it has been activiated. */
- public signal void finished (BreakController.FinishedReason reason, bool was_active);
+ /** The break is going to happen soon */
+ public signal void warned ();
+ /** The break is no longer going to start soon */
+ public signal void unwarned ();
+
+ /** The break has been activated and is now counting down aggressively until it is satisfied. */
+ public signal void activated ();
+ /** The break has been satisfied. This can happen at any time, including while the break is waiting or
after it has been activiated. */
+ public signal void finished (BreakController.FinishedReason reason, bool was_active);
- /** The break is active and it has progressed in some fashion (for example, remaining time has
changed). */
- public signal void active_changed ();
+ /** The break is active and it has progressed in some fashion (for example, remaining time has changed).
*/
+ public signal void active_changed ();
- private int64? activate_timestamp { get; set; }
-
- public BreakController () {
- this.state = State.DISABLED;
- this.activate_timestamp = null;
- }
+ private int64? activate_timestamp { get; set; }
+
+ public BreakController () {
+ this.state = State.DISABLED;
+ this.activate_timestamp = null;
+ }
- public virtual Json.Object serialize () {
- Json.Object json_root = new Json.Object ();
- json_root.set_int_member ("state", (int)this.state);
- if (this.activate_timestamp == null) {
- json_root.set_null_member ("activate_timestamp");
- } else {
- json_root.set_int_member ("activate_timestamp", this.activate_timestamp);
- }
- return json_root;
- }
+ public virtual Json.Object serialize () {
+ Json.Object json_root = new Json.Object ();
+ json_root.set_int_member ("state", (int)this.state);
+ if (this.activate_timestamp == null) {
+ json_root.set_null_member ("activate_timestamp");
+ } else {
+ json_root.set_int_member ("activate_timestamp", this.activate_timestamp);
+ }
+ return json_root;
+ }
- public virtual void deserialize (ref Json.Object json_root) {
- // State serialized_state = (State)json_root.get_int_member ("state");
- // We won't restore the original state directly. A BreakController
- // implementation should decide whether to activate at this stage.
+ public virtual void deserialize (ref Json.Object json_root) {
+ // State serialized_state = (State)json_root.get_int_member ("state");
+ // We won't restore the original state directly. A BreakController
+ // implementation should decide whether to activate at this stage.
- if (json_root.get_null_member ("activate_timestamp")) {
- this.activate_timestamp = null;
- } else {
- this.activate_timestamp = json_root.get_int_member ("activate_timestamp");
- }
- }
-
- /**
- * Set whether the break is enabled or disabled. If it is enabled,
- * it will periodically update in the background, and if it is
- * disabled it will do nothing (and consume fewer resources).
- * This will also emit the enabled () or disabled () signal.
- * @param enable True to enable the break, false to disable it
- */
- public void set_enabled (bool enable) {
- if (enable && !this.is_enabled ()) {
- this.state = State.WAITING;
- this.enabled ();
- } else if (!enable && this.is_enabled ()) {
- bool was_active = this.state == State.ACTIVE;
- this.state = State.DISABLED;
- this.finished (BreakController.FinishedReason.DISABLED, was_active);
- this.disabled ();
- }
- }
-
- /**
- * @return True if the break is enabled and waiting to start automatically
- */
- public bool is_enabled () {
- return this.state != State.DISABLED;
- }
-
- /**
- * @return True if the break has been activated, is in focus, and expects to be satisfied
- */
- public bool is_active () {
- return this.state == State.ACTIVE;
- }
+ if (json_root.get_null_member ("activate_timestamp")) {
+ this.activate_timestamp = null;
+ } else {
+ this.activate_timestamp = json_root.get_int_member ("activate_timestamp");
+ }
+ }
+
+ /**
+ * Set whether the break is enabled or disabled. If it is enabled,
+ * it will periodically update in the background, and if it is
+ * disabled it will do nothing (and consume fewer resources).
+ * This will also emit the enabled () or disabled () signal.
+ * @param enable True to enable the break, false to disable it
+ */
+ public void set_enabled (bool enable) {
+ if (enable && !this.is_enabled ()) {
+ this.state = State.WAITING;
+ this.enabled ();
+ } else if (!enable && this.is_enabled ()) {
+ bool was_active = this.state == State.ACTIVE;
+ this.state = State.DISABLED;
+ this.finished (BreakController.FinishedReason.DISABLED, was_active);
+ this.disabled ();
+ }
+ }
+
+ /**
+ * @return True if the break is enabled and waiting to start automatically
+ */
+ public bool is_enabled () {
+ return this.state != State.DISABLED;
+ }
+
+ /**
+ * @return True if the break has been activated, is in focus, and expects to be satisfied
+ */
+ public bool is_active () {
+ return this.state == State.ACTIVE;
+ }
- /**
- * @return The real time, in seconds, since the break was activated.
- */
- public int get_seconds_since_start () {
- if (this.activate_timestamp != null) {
- return (int) (Util.get_real_time_seconds () - this.activate_timestamp);
- } else {
- return 0;
- }
- }
-
- /**
- * Start a break. This is usually triggered automatically by the break
- * controller itself, but it may be triggered externally as well.
- */
- public void activate () {
- if (this.state < State.ACTIVE) {
- if (this.activate_timestamp == null) {
- this.activate_timestamp = Util.get_real_time_seconds ();
- }
- this.state = State.ACTIVE;
- this.activated ();
- }
- }
-
- /**
- * The break's requirements have been satisfied. Start counting from
- * the beginning again.
- */
- public void finish () {
- bool was_active = this.is_active ();
- this.state = State.WAITING;
- this.activate_timestamp = null;
- this.finished (BreakController.FinishedReason.SATISFIED, was_active);
- }
+ /**
+ * @return The real time, in seconds, since the break was activated.
+ */
+ public int get_seconds_since_start () {
+ if (this.activate_timestamp != null) {
+ return (int) (Util.get_real_time_seconds () - this.activate_timestamp);
+ } else {
+ return 0;
+ }
+ }
+
+ /**
+ * Start a break. This is usually triggered automatically by the break
+ * controller itself, but it may be triggered externally as well.
+ */
+ public void activate () {
+ if (this.state < State.ACTIVE) {
+ if (this.activate_timestamp == null) {
+ this.activate_timestamp = Util.get_real_time_seconds ();
+ }
+ this.state = State.ACTIVE;
+ this.activated ();
+ }
+ }
+
+ /**
+ * The break's requirements have been satisfied. Start counting from
+ * the beginning again.
+ */
+ public void finish () {
+ bool was_active = this.is_active ();
+ this.state = State.WAITING;
+ this.activate_timestamp = null;
+ this.finished (BreakController.FinishedReason.SATISFIED, was_active);
+ }
- /**
- * We're skipping this break. The BreakController should act as if the
- * break has finished as usual, but we will send a different
- * FinishedReason to the "finished" signal. This way, its BreakView will
- * know to present this differently than if the break has actually been
- * satisfied.
- * @param forget_start true to reset the value returned by get_seconds_since_start
- */
- public void skip (bool forget_start = false) {
- bool was_active = this.is_active ();
- this.state = State.WAITING;
- if (forget_start) this.activate_timestamp = null;
- this.finished (BreakController.FinishedReason.SKIPPED, was_active);
- }
+ /**
+ * We're skipping this break. The BreakController should act as if the
+ * break has finished as usual, but we will send a different
+ * FinishedReason to the "finished" signal. This way, its BreakView will
+ * know to present this differently than if the break has actually been
+ * satisfied.
+ * @param forget_start true to reset the value returned by get_seconds_since_start
+ */
+ public void skip (bool forget_start = false) {
+ bool was_active = this.is_active ();
+ this.state = State.WAITING;
+ if (forget_start) this.activate_timestamp = null;
+ this.finished (BreakController.FinishedReason.SKIPPED, was_active);
+ }
}
}
diff --git a/helper/break/BreakType.vala b/helper/break/BreakType.vala
index aff3505..66d6d6f 100644
--- a/helper/break/BreakType.vala
+++ b/helper/break/BreakType.vala
@@ -18,24 +18,24 @@
namespace BreakTimer.Helper {
public abstract class BreakType : Object {
- public string id;
- public BreakController break_controller;
- public BreakView break_view;
+ public string id;
+ public BreakController break_controller;
+ public BreakView break_view;
- protected Settings settings;
-
- public BreakType (string id, Settings settings) {
- this.id = id;
- this.settings = settings;
- }
+ protected Settings settings;
+
+ public BreakType (string id, Settings settings) {
+ this.id = id;
+ this.settings = settings;
+ }
- public virtual void initialize (UIManager ui_manager) {
- this.break_controller = this.get_break_controller ();
- this.break_view = this.get_break_view (this.break_controller, ui_manager);
- }
+ public virtual void initialize (UIManager ui_manager) {
+ this.break_controller = this.get_break_controller ();
+ this.break_view = this.get_break_view (this.break_controller, ui_manager);
+ }
- protected abstract BreakController get_break_controller ();
- protected abstract BreakView get_break_view (BreakController controller, UIManager ui_manager);
+ protected abstract BreakController get_break_controller ();
+ protected abstract BreakView get_break_view (BreakController controller, UIManager ui_manager);
}
}
diff --git a/helper/break/BreakView.vala b/helper/break/BreakView.vala
index e86fcee..3f2323e 100644
--- a/helper/break/BreakView.vala
+++ b/helper/break/BreakView.vala
@@ -18,121 +18,121 @@
namespace BreakTimer.Helper {
public abstract class BreakView : UIManager.UIFragment {
- protected weak BreakController break_controller;
-
- private int64 last_break_notification_time = 0;
-
- public BreakView (BreakController break_controller, UIManager ui_manager) {
- this.ui_manager = ui_manager;
- this.break_controller = break_controller;
-
- break_controller.enabled.connect ( () => { this.ui_manager.add_break (this); });
- break_controller.disabled.connect ( () => { this.ui_manager.remove_break (this); });
-
- break_controller.warned.connect ( () => { this.request_ui_focus (); });
- break_controller.unwarned.connect ( () => { this.release_ui_focus (); });
- break_controller.activated.connect ( () => { this.request_ui_focus (); });
- break_controller.finished.connect_after ( () => { this.release_ui_focus (); });
- }
-
- /** The break is active and has been given UI focus. This is the point where we start caring about
it. */
- public signal void focused_and_activated ();
- /** The break has lost UI focus. We don't need to display anything at this point. */
- public signal void lost_ui_focus ();
-
- public abstract string get_status_message ();
-
- /**
- * Each BreakView should use a single resident notification, which we
- * update as the break's status changes. Removing the notification, at any
- * point, should skip the break. This function is guaranteed to return a
- * notification matching that description. Initially, it will create a
- * new notification, and once that notification is shown it will continue
- * to return a reference to that same notification until it is removed by
- * the application.
- * @see show_break_notification
- * @see hide_notification
- */
- protected Notify.Notification build_common_notification (string summary, string? body, string? icon) {
- Notify.Notification notification;
- if (this.notification != null) {
- notification = this.notification;
- notification.clear_actions ();
- notification.clear_hints ();
- notification.update (summary, body, icon);
- } else {
- notification = new Notify.Notification (summary, body, icon);
- notification.closed.connect (this.notification_closed_cb);
- }
- notification.set_hint ("resident", true);
- return notification;
- }
-
- protected void show_break_notification (Notify.Notification notification) {
- if (this.overlay_is_visible ()) return;
-
- if (this.notifications_can_do ("actions")) {
- /* Label for a notification action that shows information about the current break */
- notification.add_action ("info", _("What should I do?"),
this.notification_action_info_cb);
- }
- this.show_notification (notification);
- this.last_break_notification_time = Util.get_real_time_seconds ();
- }
-
- protected int seconds_since_last_break_notification () {
- int64 now = Util.get_real_time_seconds ();
- if (this.last_break_notification_time > 0) {
- return (int) (now - this.last_break_notification_time);
- } else {
- return 0;
- }
- }
-
- protected void show_break_info () {
- // TODO: Use dbus activation once we can depend on GLib >= 2.37
- AppInfo settings_app_info = new DesktopAppInfo (Config.SETTINGS_DESKTOP_ID);
- AppLaunchContext app_launch_context = new AppLaunchContext ();
- try {
- settings_app_info.launch (null, app_launch_context);
- } catch (Error error) {
- stderr.printf ("Error launching settings application: %s\n", error.message);
- }
- }
-
- protected virtual void dismiss_break () {
- this.break_controller.skip ();
- }
-
- private void notification_action_info_cb () {
- this.show_break_info ();
- }
-
- private void notification_closed_cb () {
- // If the notification is dismissed in a particularly forceful way, we assume the
- // user is cutting the break short. When we're using persistent notifications,
- // this requires the user to explicitly remove the notification with its context
- // menu in the message tray.
- if (this.notification.get_closed_reason () == 2 && this.notifications_can_do ("persistence"))
{
- // Notification closed reason code 2: dismissed by the user
- this.dismiss_break ();
- }
- }
-
- /* UIFragment interface */
-
- protected override void focus_started () {
- if (this.break_controller.is_active ()) {
- this.focused_and_activated ();
- }
- // else the break may have been given focus early. (See the BreakController.warned signal).
- }
-
- protected override void focus_stopped () {
- this.hide_overlay ();
- this.lost_ui_focus ();
- // We don't hide the current notification, because we might have a
- // "Finished" notification that outlasts the UIFragment
- }
+ protected weak BreakController break_controller;
+
+ private int64 last_break_notification_time = 0;
+
+ public BreakView (BreakController break_controller, UIManager ui_manager) {
+ this.ui_manager = ui_manager;
+ this.break_controller = break_controller;
+
+ break_controller.enabled.connect ( () => { this.ui_manager.add_break (this); });
+ break_controller.disabled.connect ( () => { this.ui_manager.remove_break (this); });
+
+ break_controller.warned.connect ( () => { this.request_ui_focus (); });
+ break_controller.unwarned.connect ( () => { this.release_ui_focus (); });
+ break_controller.activated.connect ( () => { this.request_ui_focus (); });
+ break_controller.finished.connect_after ( () => { this.release_ui_focus (); });
+ }
+
+ /** The break is active and has been given UI focus. This is the point where we start caring about it. */
+ public signal void focused_and_activated ();
+ /** The break has lost UI focus. We don't need to display anything at this point. */
+ public signal void lost_ui_focus ();
+
+ public abstract string get_status_message ();
+
+ /**
+ * Each BreakView should use a single resident notification, which we
+ * update as the break's status changes. Removing the notification, at any
+ * point, should skip the break. This function is guaranteed to return a
+ * notification matching that description. Initially, it will create a
+ * new notification, and once that notification is shown it will continue
+ * to return a reference to that same notification until it is removed by
+ * the application.
+ * @see show_break_notification
+ * @see hide_notification
+ */
+ protected Notify.Notification build_common_notification (string summary, string? body, string? icon) {
+ Notify.Notification notification;
+ if (this.notification != null) {
+ notification = this.notification;
+ notification.clear_actions ();
+ notification.clear_hints ();
+ notification.update (summary, body, icon);
+ } else {
+ notification = new Notify.Notification (summary, body, icon);
+ notification.closed.connect (this.notification_closed_cb);
+ }
+ notification.set_hint ("resident", true);
+ return notification;
+ }
+
+ protected void show_break_notification (Notify.Notification notification) {
+ if (this.overlay_is_visible ()) return;
+
+ if (this.notifications_can_do ("actions")) {
+ /* Label for a notification action that shows information about the current break */
+ notification.add_action ("info", _("What should I do?"), this.notification_action_info_cb);
+ }
+ this.show_notification (notification);
+ this.last_break_notification_time = Util.get_real_time_seconds ();
+ }
+
+ protected int seconds_since_last_break_notification () {
+ int64 now = Util.get_real_time_seconds ();
+ if (this.last_break_notification_time > 0) {
+ return (int) (now - this.last_break_notification_time);
+ } else {
+ return 0;
+ }
+ }
+
+ protected void show_break_info () {
+ // TODO: Use dbus activation once we can depend on GLib >= 2.37
+ AppInfo settings_app_info = new DesktopAppInfo (Config.SETTINGS_DESKTOP_ID);
+ AppLaunchContext app_launch_context = new AppLaunchContext ();
+ try {
+ settings_app_info.launch (null, app_launch_context);
+ } catch (Error error) {
+ stderr.printf ("Error launching settings application: %s\n", error.message);
+ }
+ }
+
+ protected virtual void dismiss_break () {
+ this.break_controller.skip ();
+ }
+
+ private void notification_action_info_cb () {
+ this.show_break_info ();
+ }
+
+ private void notification_closed_cb () {
+ // If the notification is dismissed in a particularly forceful way, we assume the
+ // user is cutting the break short. When we're using persistent notifications,
+ // this requires the user to explicitly remove the notification with its context
+ // menu in the message tray.
+ if (this.notification.get_closed_reason () == 2 && this.notifications_can_do ("persistence")) {
+ // Notification closed reason code 2: dismissed by the user
+ this.dismiss_break ();
+ }
+ }
+
+ /* UIFragment interface */
+
+ protected override void focus_started () {
+ if (this.break_controller.is_active ()) {
+ this.focused_and_activated ();
+ }
+ // else the break may have been given focus early. (See the BreakController.warned signal).
+ }
+
+ protected override void focus_stopped () {
+ this.hide_overlay ();
+ this.lost_ui_focus ();
+ // We don't hide the current notification, because we might have a
+ // "Finished" notification that outlasts the UIFragment
+ }
}
}
diff --git a/helper/break/TimerBreakController.vala b/helper/break/TimerBreakController.vala
index faaab02..7723b8f 100644
--- a/helper/break/TimerBreakController.vala
+++ b/helper/break/TimerBreakController.vala
@@ -26,228 +26,228 @@ namespace BreakTimer.Helper {
* activates and counts down for its duration.
*/
public abstract class TimerBreakController : BreakController {
- public int interval { get; set; }
- public int duration { get; set; }
-
- protected Countdown interval_countdown;
- protected Countdown duration_countdown;
- protected PausableTimeout countdowns_timeout;
-
- protected int fuzzy_seconds;
-
- private StatefulTimer counting_timer = new StatefulTimer ();
- private StatefulTimer delayed_timer = new StatefulTimer ();
-
- public TimerBreakController (ActivityMonitor activity_monitor, int fuzzy_seconds = 0) {
- base ();
- this.fuzzy_seconds = fuzzy_seconds;
-
- this.interval_countdown = new Countdown (this.interval);
- this.duration_countdown = new Countdown (this.duration);
- this.countdowns_timeout = new PausableTimeout (this.update_countdowns, 1);
-
- this.notify["interval"].connect ( (s, p) => {
- this.interval_countdown.set_base_duration (this.interval);
- });
- this.notify["duration"].connect ( (s, p) => {
- this.duration_countdown.set_base_duration (this.duration);
- // Unwarn (for now) in case the new duration is shorter than the old one
- if (this.state == State.WAITING) this.unwarn ();
- });
-
- activity_monitor.detected_activity.connect (this.detected_activity_cb);
- activity_monitor.detected_idle.connect (this.detected_idle_cb);
-
- this.enabled.connect (this.enabled_cb);
- this.disabled.connect (this.disabled_cb);
-
- this.activated.connect (this.activated_cb);
- this.finished.connect (this.finished_cb);
- }
-
- /** Fires continually, as long as the break is active and counting down. */
- public signal void counting (int lap_time, int total_time);
- /** Fires as long as the break is active but is not counting down. */
- public signal void delayed (int lap_time, int total_time);
-
- public override Json.Object serialize () {
- Json.Object json_root = base.serialize ();
- json_root.set_string_member ("interval_countdown", this.interval_countdown.serialize ());
- json_root.set_string_member ("duration_countdown", this.duration_countdown.serialize ());
- json_root.set_string_member ("countdowns_timeout", this.countdowns_timeout.serialize ());
- json_root.set_string_member ("counting_timer", this.counting_timer.serialize ());
- json_root.set_string_member ("delayed_timer", this.delayed_timer.serialize ());
- return json_root;
- }
-
- public override void deserialize (ref Json.Object json_root) {
- base.deserialize (ref json_root);
- this.interval_countdown.deserialize (json_root.get_string_member ("interval_countdown"));
- this.duration_countdown.deserialize (json_root.get_string_member ("duration_countdown"));
- this.countdowns_timeout.deserialize (json_root.get_string_member ("countdowns_timeout"));
- this.counting_timer.deserialize (json_root.get_string_member ("counting_timer"));
- this.delayed_timer.deserialize (json_root.get_string_member ("delayed_timer"));
- }
-
- private void enabled_cb () {
- this.interval_countdown.continue ();
- this.duration_countdown.pause ();
- this.countdowns_timeout.start ();
- }
-
- private void disabled_cb () {
- this.interval_countdown.pause ();
- this.duration_countdown.pause ();
- this.countdowns_timeout.stop ();
- }
-
- private void activated_cb () {
- this.interval_countdown.pause ();
- this.duration_countdown.continue ();
- this.counting_timer.reset ();
- this.delayed_timer.reset ();
- }
-
- private void finished_cb (BreakController.FinishedReason reason) {
- if (reason > BreakController.FinishedReason.DISABLED) {
- this.interval_countdown.reset ();
- this.duration_countdown.reset ();
- this.counting_timer.reset ();
- this.delayed_timer.reset ();
- }
- }
-
- bool is_warned;
- private void warn () {
- if (! is_warned) {
- is_warned = true;
- this.warned ();
- }
- }
- private void unwarn () {
- if (is_warned) {
- is_warned = false;
- this.unwarned ();
- }
- }
-
- /**
- * @return Time until the next scheduled break, in seconds.
- */
- public int starts_in () {
- return this.interval_countdown.get_time_remaining ();
- }
-
- /**
- * @return Idle time remaining until the break is satisfied.
- */
- public int get_time_remaining () {
- return this.duration_countdown.get_time_remaining ();
- }
-
- /**
- * Stops the break and starts it again at some point in the future.
- * @param resume_after the amount of time to postpone for
- */
- public void postpone (int resume_after) {
- this.skip ();
- this.interval_countdown.continue_from (resume_after - this.interval);
- }
-
- /**
- * @return Total length of the break, taking into account extra time that
- * may have been added outside of the break's settings.
- */
- public int get_current_duration () {
- return this.duration_countdown.get_duration ();
- }
-
- private void detected_idle_cb (ActivityMonitor.UserActivity activity) {
- if (! this.is_enabled ()) return;
-
- if (activity.time_since_active < this.fuzzy_seconds) {
- this.detected_activity_cb (activity);
- return;
- }
-
- if (activity.time_correction > 0) {
- // FIXME: Casting int64 to int
- this.duration_countdown.advance_time ((int) activity.time_correction);
- }
-
- if (this.state == State.WAITING) {
- if (this.interval_countdown.get_time_elapsed () > 0) {
- this.duration_countdown.continue ();
- }
- this.interval_countdown.pause ();
- } else {
- this.duration_countdown.continue ();
- }
-
- int lap_time;
-
- this.delayed_timer.freeze ();
- if (this.counting_timer.is_stopped ()) {
- this.counting_timer.start_lap ();
- lap_time = (int) activity.idle_time;
- } else {
- lap_time = (int) this.counting_timer.lap_time ();
- }
-
- this.counting (
- lap_time,
- (int)this.counting_timer.elapsed ()
- );
- this.countdowns_timeout.run_once ();
- }
-
- private void detected_activity_cb (ActivityMonitor.UserActivity activity) {
- if (! this.is_enabled ()) return;
-
- int lap_time;
-
- this.counting_timer.freeze ();
- if (this.delayed_timer.is_stopped ()) {
- this.delayed_timer.start_lap ();
- lap_time = 0;
- } else {
- lap_time = (int)this.delayed_timer.lap_time ();
- }
-
- this.duration_countdown.pause ();
- if (this.state == State.WAITING) {
- this.interval_countdown.continue ();
- }
-
- this.delayed (
- lap_time,
- (int)this.delayed_timer.elapsed ()
- );
- this.countdowns_timeout.run_once ();
- }
-
- /**
- * Checks if it is time to activate the break. The break will activate as
- * soon as soon as interval_countdown reaches 0. The break's "warned"
- * signal is fired when the break is close (within its set duration) to
- * starting.
- */
- private void update_countdowns (PausableTimeout timeout, int delta_millisecs) {
- if (this.duration_countdown.is_finished ()) {
- this.duration_countdown.reset ();
- this.finish ();
- } else if (this.state == State.WAITING) {
- if (this.starts_in () == 0) {
- this.activate ();
- } else if (this.starts_in () <= this.duration) {
- this.warn ();
- } else {
- this.unwarn ();
- }
- } else if (this.state == State.ACTIVE) {
- this.active_changed ();
- }
- }
+ public int interval { get; set; }
+ public int duration { get; set; }
+
+ protected Countdown interval_countdown;
+ protected Countdown duration_countdown;
+ protected PausableTimeout countdowns_timeout;
+
+ protected int fuzzy_seconds;
+
+ private StatefulTimer counting_timer = new StatefulTimer ();
+ private StatefulTimer delayed_timer = new StatefulTimer ();
+
+ public TimerBreakController (ActivityMonitor activity_monitor, int fuzzy_seconds = 0) {
+ base ();
+ this.fuzzy_seconds = fuzzy_seconds;
+
+ this.interval_countdown = new Countdown (this.interval);
+ this.duration_countdown = new Countdown (this.duration);
+ this.countdowns_timeout = new PausableTimeout (this.update_countdowns, 1);
+
+ this.notify["interval"].connect ( (s, p) => {
+ this.interval_countdown.set_base_duration (this.interval);
+ });
+ this.notify["duration"].connect ( (s, p) => {
+ this.duration_countdown.set_base_duration (this.duration);
+ // Unwarn (for now) in case the new duration is shorter than the old one
+ if (this.state == State.WAITING) this.unwarn ();
+ });
+
+ activity_monitor.detected_activity.connect (this.detected_activity_cb);
+ activity_monitor.detected_idle.connect (this.detected_idle_cb);
+
+ this.enabled.connect (this.enabled_cb);
+ this.disabled.connect (this.disabled_cb);
+
+ this.activated.connect (this.activated_cb);
+ this.finished.connect (this.finished_cb);
+ }
+
+ /** Fires continually, as long as the break is active and counting down. */
+ public signal void counting (int lap_time, int total_time);
+ /** Fires as long as the break is active but is not counting down. */
+ public signal void delayed (int lap_time, int total_time);
+
+ public override Json.Object serialize () {
+ Json.Object json_root = base.serialize ();
+ json_root.set_string_member ("interval_countdown", this.interval_countdown.serialize ());
+ json_root.set_string_member ("duration_countdown", this.duration_countdown.serialize ());
+ json_root.set_string_member ("countdowns_timeout", this.countdowns_timeout.serialize ());
+ json_root.set_string_member ("counting_timer", this.counting_timer.serialize ());
+ json_root.set_string_member ("delayed_timer", this.delayed_timer.serialize ());
+ return json_root;
+ }
+
+ public override void deserialize (ref Json.Object json_root) {
+ base.deserialize (ref json_root);
+ this.interval_countdown.deserialize (json_root.get_string_member ("interval_countdown"));
+ this.duration_countdown.deserialize (json_root.get_string_member ("duration_countdown"));
+ this.countdowns_timeout.deserialize (json_root.get_string_member ("countdowns_timeout"));
+ this.counting_timer.deserialize (json_root.get_string_member ("counting_timer"));
+ this.delayed_timer.deserialize (json_root.get_string_member ("delayed_timer"));
+ }
+
+ private void enabled_cb () {
+ this.interval_countdown.continue ();
+ this.duration_countdown.pause ();
+ this.countdowns_timeout.start ();
+ }
+
+ private void disabled_cb () {
+ this.interval_countdown.pause ();
+ this.duration_countdown.pause ();
+ this.countdowns_timeout.stop ();
+ }
+
+ private void activated_cb () {
+ this.interval_countdown.pause ();
+ this.duration_countdown.continue ();
+ this.counting_timer.reset ();
+ this.delayed_timer.reset ();
+ }
+
+ private void finished_cb (BreakController.FinishedReason reason) {
+ if (reason > BreakController.FinishedReason.DISABLED) {
+ this.interval_countdown.reset ();
+ this.duration_countdown.reset ();
+ this.counting_timer.reset ();
+ this.delayed_timer.reset ();
+ }
+ }
+
+ bool is_warned;
+ private void warn () {
+ if (! is_warned) {
+ is_warned = true;
+ this.warned ();
+ }
+ }
+ private void unwarn () {
+ if (is_warned) {
+ is_warned = false;
+ this.unwarned ();
+ }
+ }
+
+ /**
+ * @return Time until the next scheduled break, in seconds.
+ */
+ public int starts_in () {
+ return this.interval_countdown.get_time_remaining ();
+ }
+
+ /**
+ * @return Idle time remaining until the break is satisfied.
+ */
+ public int get_time_remaining () {
+ return this.duration_countdown.get_time_remaining ();
+ }
+
+ /**
+ * Stops the break and starts it again at some point in the future.
+ * @param resume_after the amount of time to postpone for
+ */
+ public void postpone (int resume_after) {
+ this.skip ();
+ this.interval_countdown.continue_from (resume_after - this.interval);
+ }
+
+ /**
+ * @return Total length of the break, taking into account extra time that
+ * may have been added outside of the break's settings.
+ */
+ public int get_current_duration () {
+ return this.duration_countdown.get_duration ();
+ }
+
+ private void detected_idle_cb (ActivityMonitor.UserActivity activity) {
+ if (! this.is_enabled ()) return;
+
+ if (activity.time_since_active < this.fuzzy_seconds) {
+ this.detected_activity_cb (activity);
+ return;
+ }
+
+ if (activity.time_correction > 0) {
+ // FIXME: Casting int64 to int
+ this.duration_countdown.advance_time ((int) activity.time_correction);
+ }
+
+ if (this.state == State.WAITING) {
+ if (this.interval_countdown.get_time_elapsed () > 0) {
+ this.duration_countdown.continue ();
+ }
+ this.interval_countdown.pause ();
+ } else {
+ this.duration_countdown.continue ();
+ }
+
+ int lap_time;
+
+ this.delayed_timer.freeze ();
+ if (this.counting_timer.is_stopped ()) {
+ this.counting_timer.start_lap ();
+ lap_time = (int) activity.idle_time;
+ } else {
+ lap_time = (int) this.counting_timer.lap_time ();
+ }
+
+ this.counting (
+ lap_time,
+ (int)this.counting_timer.elapsed ()
+ );
+ this.countdowns_timeout.run_once ();
+ }
+
+ private void detected_activity_cb (ActivityMonitor.UserActivity activity) {
+ if (! this.is_enabled ()) return;
+
+ int lap_time;
+
+ this.counting_timer.freeze ();
+ if (this.delayed_timer.is_stopped ()) {
+ this.delayed_timer.start_lap ();
+ lap_time = 0;
+ } else {
+ lap_time = (int)this.delayed_timer.lap_time ();
+ }
+
+ this.duration_countdown.pause ();
+ if (this.state == State.WAITING) {
+ this.interval_countdown.continue ();
+ }
+
+ this.delayed (
+ lap_time,
+ (int)this.delayed_timer.elapsed ()
+ );
+ this.countdowns_timeout.run_once ();
+ }
+
+ /**
+ * Checks if it is time to activate the break. The break will activate as
+ * soon as soon as interval_countdown reaches 0. The break's "warned"
+ * signal is fired when the break is close (within its set duration) to
+ * starting.
+ */
+ private void update_countdowns (PausableTimeout timeout, int delta_millisecs) {
+ if (this.duration_countdown.is_finished ()) {
+ this.duration_countdown.reset ();
+ this.finish ();
+ } else if (this.state == State.WAITING) {
+ if (this.starts_in () == 0) {
+ this.activate ();
+ } else if (this.starts_in () <= this.duration) {
+ this.warn ();
+ } else {
+ this.unwarn ();
+ }
+ } else if (this.state == State.ACTIVE) {
+ this.active_changed ();
+ }
+ }
}
}
diff --git a/helper/break/TimerBreakStatusWidget.vala b/helper/break/TimerBreakStatusWidget.vala
index 585fd37..333682b 100644
--- a/helper/break/TimerBreakStatusWidget.vala
+++ b/helper/break/TimerBreakStatusWidget.vala
@@ -18,78 +18,78 @@
namespace BreakTimer.Helper {
public class TimerBreakStatusWidget : Gtk.Grid, IScreenOverlayContent {
- private TimerBreakController timer_break;
+ private TimerBreakController timer_break;
- private Gtk.Label timer_label;
- private Gtk.Label message_label;
-
- public TimerBreakStatusWidget (TimerBreakController timer_break) {
- Object ();
- this.timer_break = timer_break;
-
- this.set_column_spacing (12);
- this.set_row_spacing (12);
-
- this.timer_label = new Gtk.Label (null);
- this.attach (this.timer_label, 0, 0, 1, 1);
- Gtk.StyleContext timer_style = this.timer_label.get_style_context ();
- timer_style.add_class ("_timer-label");
-
- this.message_label = new Gtk.Label (null);
- this.attach (this.message_label, 0, 1, 1, 1);
- this.message_label.set_line_wrap (true);
+ private Gtk.Label timer_label;
+ private Gtk.Label message_label;
+
+ public TimerBreakStatusWidget (TimerBreakController timer_break) {
+ Object ();
+ this.timer_break = timer_break;
+
+ this.set_column_spacing (12);
+ this.set_row_spacing (12);
+
+ this.timer_label = new Gtk.Label (null);
+ this.attach (this.timer_label, 0, 0, 1, 1);
+ Gtk.StyleContext timer_style = this.timer_label.get_style_context ();
+ timer_style.add_class ("_timer-label");
+
+ this.message_label = new Gtk.Label (null);
+ this.attach (this.message_label, 0, 1, 1, 1);
+ this.message_label.set_line_wrap (true);
- this.show_all ();
- }
+ this.show_all ();
+ }
- private void active_changed_cb () {
- int time_remaining = this.timer_break.get_time_remaining ();
- if (this.timer_break.is_active ()) {
- int start_time = this.timer_break.get_current_duration ();
- string countdown = NaturalTime.instance.get_countdown_for_seconds_with_start (
- time_remaining, start_time);
- this.timer_label.set_text (countdown);
- }
- }
+ private void active_changed_cb () {
+ int time_remaining = this.timer_break.get_time_remaining ();
+ if (this.timer_break.is_active ()) {
+ int start_time = this.timer_break.get_current_duration ();
+ string countdown = NaturalTime.instance.get_countdown_for_seconds_with_start (
+ time_remaining, start_time);
+ this.timer_label.set_text (countdown);
+ }
+ }
- private void finished_cb (BreakController.FinishedReason reason) {
- if (reason == BreakController.FinishedReason.SATISFIED) {
- /* Break overlay label when a break has been finished */
- this.timer_label.set_text ( _("Thank you"));
- }
- }
+ private void finished_cb (BreakController.FinishedReason reason) {
+ if (reason == BreakController.FinishedReason.SATISFIED) {
+ /* Break overlay label when a break has been finished */
+ this.timer_label.set_text ( _("Thank you"));
+ }
+ }
- private void update_content () {
- // Make sure the content being displayed is up to date. This is
- // usually called when the widget is about to appear.
- this.active_changed_cb ();
- }
-
- /** Set a reassuring message to accompany the break timer */
- public void set_message (string message) {
- this.message_label.set_text (message);
- }
+ private void update_content () {
+ // Make sure the content being displayed is up to date. This is
+ // usually called when the widget is about to appear.
+ this.active_changed_cb ();
+ }
+
+ /** Set a reassuring message to accompany the break timer */
+ public void set_message (string message) {
+ this.message_label.set_text (message);
+ }
- /* IScreenOverlayContent interface */
+ /* IScreenOverlayContent interface */
- public void added_to_overlay () {
- this.timer_break.active_changed.connect (this.active_changed_cb);
- this.timer_break.finished.connect (this.finished_cb);
- this.update_content ();
- }
+ public void added_to_overlay () {
+ this.timer_break.active_changed.connect (this.active_changed_cb);
+ this.timer_break.finished.connect (this.finished_cb);
+ this.update_content ();
+ }
- public void removed_from_overlay () {
- this.timer_break.active_changed.disconnect (this.active_changed_cb);
- this.timer_break.finished.disconnect (this.finished_cb);
- }
+ public void removed_from_overlay () {
+ this.timer_break.active_changed.disconnect (this.active_changed_cb);
+ this.timer_break.finished.disconnect (this.finished_cb);
+ }
- public void before_fade_in () {
- this.update_content ();
- }
+ public void before_fade_in () {
+ this.update_content ();
+ }
- public void before_fade_out () {
- this.update_content ();
- }
+ public void before_fade_out () {
+ this.update_content ();
+ }
}
}
diff --git a/helper/break/TimerBreakType.vala b/helper/break/TimerBreakType.vala
index 4669d03..01cff86 100644
--- a/helper/break/TimerBreakType.vala
+++ b/helper/break/TimerBreakType.vala
@@ -18,61 +18,61 @@
namespace BreakTimer.Helper {
public abstract class TimerBreakType : BreakType {
- private BreakHelper_TimerBreakServer break_type_server;
+ private BreakHelper_TimerBreakServer break_type_server;
- public TimerBreakType (string id, Settings settings) {
- base (id, settings);
- }
+ public TimerBreakType (string id, Settings settings) {
+ base (id, settings);
+ }
- protected override void initialize (UIManager ui_manager) {
- base.initialize (ui_manager);
+ protected override void initialize (UIManager ui_manager) {
+ base.initialize (ui_manager);
- var timer_break_controller = (TimerBreakController)this.break_controller;
- var timer_break_view = (TimerBreakView)this.break_view;
+ var timer_break_controller = (TimerBreakController)this.break_controller;
+ var timer_break_view = (TimerBreakView)this.break_view;
- this.settings.bind ("interval-seconds", timer_break_controller, "interval",
SettingsBindFlags.GET);
- this.settings.bind ("duration-seconds", timer_break_controller, "duration",
SettingsBindFlags.GET);
+ this.settings.bind ("interval-seconds", timer_break_controller, "interval", SettingsBindFlags.GET);
+ this.settings.bind ("duration-seconds", timer_break_controller, "duration", SettingsBindFlags.GET);
- this.break_type_server = new BreakHelper_TimerBreakServer (
- timer_break_controller,
- timer_break_view
- );
- try {
- DBusConnection connection = Bus.get_sync (BusType.SESSION, null);
- connection.register_object (
- Config.HELPER_BREAK_OBJECT_BASE_PATH+this.id,
- this.break_type_server
- );
- } catch (IOError error) {
- GLib.error ("Error registering break type on the session bus: %s", error.message);
- }
- }
+ this.break_type_server = new BreakHelper_TimerBreakServer (
+ timer_break_controller,
+ timer_break_view
+ );
+ try {
+ DBusConnection connection = Bus.get_sync (BusType.SESSION, null);
+ connection.register_object (
+ Config.HELPER_BREAK_OBJECT_BASE_PATH+this.id,
+ this.break_type_server
+ );
+ } catch (IOError error) {
+ GLib.error ("Error registering break type on the session bus: %s", error.message);
+ }
+ }
}
[DBus (name = "org.gnome.BreakTimer.TimerBreak")]
private class BreakHelper_TimerBreakServer : Object, IBreakHelper_TimerBreak {
- private weak TimerBreakController break_controller;
- private weak TimerBreakView break_view;
-
- public BreakHelper_TimerBreakServer (TimerBreakController break_controller, TimerBreakView
break_view) {
- this.break_controller = break_controller;
- this.break_view = break_view;
- }
-
- public TimerBreakStatus get_status () {
- return TimerBreakStatus () {
- is_enabled = this.break_controller.is_enabled (),
- is_focused = this.break_view.has_ui_focus (),
- is_active = this.break_controller.is_active (),
- starts_in = this.break_controller.starts_in (),
- time_remaining = this.break_controller.get_time_remaining (),
- current_duration = this.break_controller.get_current_duration ()
- };
- }
+ private weak TimerBreakController break_controller;
+ private weak TimerBreakView break_view;
+
+ public BreakHelper_TimerBreakServer (TimerBreakController break_controller, TimerBreakView break_view) {
+ this.break_controller = break_controller;
+ this.break_view = break_view;
+ }
+
+ public TimerBreakStatus get_status () {
+ return TimerBreakStatus () {
+ is_enabled = this.break_controller.is_enabled (),
+ is_focused = this.break_view.has_ui_focus (),
+ is_active = this.break_controller.is_active (),
+ starts_in = this.break_controller.starts_in (),
+ time_remaining = this.break_controller.get_time_remaining (),
+ current_duration = this.break_controller.get_current_duration ()
+ };
+ }
- public void activate () {
- this.break_controller.activate ();
- }
+ public void activate () {
+ this.break_controller.activate ();
+ }
}
}
diff --git a/helper/break/TimerBreakView.vala b/helper/break/TimerBreakView.vala
index f7b1eb0..198c4f6 100644
--- a/helper/break/TimerBreakView.vala
+++ b/helper/break/TimerBreakView.vala
@@ -18,40 +18,40 @@
namespace BreakTimer.Helper {
public abstract class TimerBreakView : BreakView {
- protected TimerBreakController timer_break {
- get { return (TimerBreakController)this.break_controller; }
- }
-
- public TimerBreakView (TimerBreakController timer_break, UIManager ui_manager) {
- base (timer_break, ui_manager);
- }
-
- public override string get_status_message () {
- string message;
-
- int starts_in = this.timer_break.starts_in ();
- int time_remaining = this.timer_break.get_time_remaining ();
- string state_label = this.timer_break.state.to_string ();
-
- message = "%s%s, I:%d, D:%d".printf (
- this.has_ui_focus () ? ">" : "",
- state_label,
- starts_in,
- time_remaining
- );
-
- return message;
- }
+ protected TimerBreakController timer_break {
+ get { return (TimerBreakController)this.break_controller; }
+ }
+
+ public TimerBreakView (TimerBreakController timer_break, UIManager ui_manager) {
+ base (timer_break, ui_manager);
+ }
+
+ public override string get_status_message () {
+ string message;
+
+ int starts_in = this.timer_break.starts_in ();
+ int time_remaining = this.timer_break.get_time_remaining ();
+ string state_label = this.timer_break.state.to_string ();
+
+ message = "%s%s, I:%d, D:%d".printf (
+ this.has_ui_focus () ? ">" : "",
+ state_label,
+ starts_in,
+ time_remaining
+ );
+
+ return message;
+ }
- protected int get_lead_in_seconds () {
- int lead_in = this.timer_break.duration+3;
- if (lead_in > 40) {
- lead_in = 40;
- } else if (lead_in < 15) {
- lead_in = 15;
- }
- return lead_in;
- }
+ protected int get_lead_in_seconds () {
+ int lead_in = this.timer_break.duration+3;
+ if (lead_in > 40) {
+ lead_in = 40;
+ } else if (lead_in < 15) {
+ lead_in = 15;
+ }
+ return lead_in;
+ }
}
}
diff --git a/helper/main.vala b/helper/main.vala
index f2975f6..d41719a 100644
--- a/helper/main.vala
+++ b/helper/main.vala
@@ -20,18 +20,18 @@ namespace BreakTimer.Helper {
static HelperApplication application;
public int main (string[] args) {
- application = new HelperApplication ();
- /*
- Posix.signal (Posix.SIGINT, sigint_cb);
- Posix.signal (Posix.SIGTERM, sigint_cb);
- Posix.signal (Posix.SIGHUP, sigint_cb);
- */
- int status = application.run (args);
- return status;
+ application = new HelperApplication ();
+ /*
+ Posix.signal (Posix.SIGINT, sigint_cb);
+ Posix.signal (Posix.SIGTERM, sigint_cb);
+ Posix.signal (Posix.SIGHUP, sigint_cb);
+ */
+ int status = application.run (args);
+ return status;
}
void sigint_cb (int signal_number) {
- application.quit ();
+ application.quit ();
}
}
diff --git a/helper/microbreak/MicroBreakController.vala b/helper/microbreak/MicroBreakController.vala
index 8cb38c2..e8b9b37 100644
--- a/helper/microbreak/MicroBreakController.vala
+++ b/helper/microbreak/MicroBreakController.vala
@@ -24,15 +24,15 @@ namespace BreakTimer.Helper {
* or moves the mouse.
*/
public class MicroBreakController : TimerBreakController {
- public MicroBreakController (ActivityMonitor activity_monitor) {
- base (activity_monitor, 0);
+ public MicroBreakController (ActivityMonitor activity_monitor) {
+ base (activity_monitor, 0);
- this.delayed.connect (this.delayed_cb);
- }
-
- private void delayed_cb (int lap_time, int total_time) {
- this.duration_countdown.reset ();
- }
+ this.delayed.connect (this.delayed_cb);
+ }
+
+ private void delayed_cb (int lap_time, int total_time) {
+ this.duration_countdown.reset ();
+ }
}
}
diff --git a/helper/microbreak/MicroBreakType.vala b/helper/microbreak/MicroBreakType.vala
index 938d2ee..e490c66 100644
--- a/helper/microbreak/MicroBreakType.vala
+++ b/helper/microbreak/MicroBreakType.vala
@@ -18,26 +18,26 @@
namespace BreakTimer.Helper {
public class MicroBreakType : TimerBreakType {
- private ActivityMonitor activity_monitor;
+ private ActivityMonitor activity_monitor;
- public MicroBreakType (ActivityMonitor activity_monitor) {
- Settings settings = new Settings ("org.gnome.BreakTimer.microbreak");
- base ("microbreak", settings);
- this.activity_monitor = activity_monitor;
- }
+ public MicroBreakType (ActivityMonitor activity_monitor) {
+ Settings settings = new Settings ("org.gnome.BreakTimer.microbreak");
+ base ("microbreak", settings);
+ this.activity_monitor = activity_monitor;
+ }
- protected override BreakController get_break_controller () {
- return new MicroBreakController (
- this.activity_monitor
- );
- }
+ protected override BreakController get_break_controller () {
+ return new MicroBreakController (
+ this.activity_monitor
+ );
+ }
- protected override BreakView get_break_view (BreakController controller, UIManager ui_manager) {
- return new MicroBreakView (
- (MicroBreakController)controller,
- ui_manager
- );
- }
+ protected override BreakView get_break_view (BreakController controller, UIManager ui_manager) {
+ return new MicroBreakView (
+ (MicroBreakController)controller,
+ ui_manager
+ );
+ }
}
}
diff --git a/helper/microbreak/MicroBreakView.vala b/helper/microbreak/MicroBreakView.vala
index daca421..5db9a67 100644
--- a/helper/microbreak/MicroBreakView.vala
+++ b/helper/microbreak/MicroBreakView.vala
@@ -21,115 +21,115 @@ namespace BreakTimer.Helper {
/* TODO: replace pause break if appropriate */
public class MicroBreakView : TimerBreakView {
- protected MicroBreakController micro_break {
- get { return (MicroBreakController)this.break_controller; }
- }
-
- private int delay_time_notified = 0;
-
- public MicroBreakView (MicroBreakController micro_break, UIManager ui_manager) {
- base (micro_break, ui_manager);
- this.focus_priority = FocusPriority.LOW;
-
- this.focused_and_activated.connect (this.focused_and_activated_cb);
- this.lost_ui_focus.connect (this.lost_ui_focus_cb);
- this.micro_break.finished.connect (this.finished_cb);
- }
-
- protected new void show_break_notification (Notify.Notification notification) {
- if (this.notifications_can_do ("actions")) {
- /* Label for a notification action that will skip the current microbreak */
- notification.add_action ("skip", _("Skip this one"),
this.notification_action_skip_cb);
- }
- base.show_break_notification (notification);
- }
-
- private void show_start_notification () {
- var notification = this.build_common_notification (
- _("It’s time for a micro break"),
- _("Take a break from typing and look away from the screen"),
- "alarm-symbolic"
- );
- notification.set_urgency (Notify.Urgency.NORMAL);
- notification.set_hint ("sound-name", "message");
- this.show_break_notification (notification);
- }
-
- private void show_overdue_notification () {
- int delay_value;
- int time_since_start = this.micro_break.get_seconds_since_start ();
- string delay_text = NaturalTime.instance.get_simplest_label_for_seconds (
- time_since_start, out delay_value);
-
- string body_text = ngettext (
- /* %s will be replaced with a string that describes a time interval, such as "2
minutes", "40 seconds" or "1 hour" */
- "You were due to take a micro break %s ago",
- "You were due to take a micro break %s ago",
- delay_value
- ).printf (delay_text);
-
- var notification = this.build_common_notification (
- _("Overdue micro break"),
- body_text,
- "alarm-symbolic"
- );
- notification.set_urgency (Notify.Urgency.NORMAL);
- this.show_break_notification (notification);
- }
-
- private void show_finished_notification () {
- var notification = this.build_common_notification (
- _("Break is over"),
- _("Your micro break has ended"),
- "alarm-symbolic"
- );
- notification.set_urgency (Notify.Urgency.NORMAL);
- this.show_lock_notification (notification);
-
- this.play_sound_from_id ("complete");
- }
-
- private void focused_and_activated_cb () {
- this.delay_time_notified = 0;
-
- var status_widget = new TimerBreakStatusWidget (this.micro_break);
- status_widget.set_message ( _("Take a moment to rest your eyes"));
- this.set_overlay (status_widget);
-
- if (! this.overlay_is_visible ()) {
- this.show_start_notification ();
- Timeout.add_seconds (this.get_lead_in_seconds (), () => {
- this.reveal_overlay ();
- return false;
- });
- }
-
- this.micro_break.delayed.connect (this.delayed_cb);
- }
-
- private void lost_ui_focus_cb () {
- this.micro_break.delayed.disconnect (this.delayed_cb);
- }
-
- private void finished_cb (BreakController.FinishedReason reason, bool was_active) {
- if (reason == BreakController.FinishedReason.SATISFIED && was_active) {
- this.show_finished_notification ();
- } else {
- this.hide_notification ();
- }
- }
-
- private void delayed_cb (int lap_time, int total_time) {
- int time_since_notified = total_time - this.delay_time_notified;
- if (time_since_notified > this.micro_break.interval) {
- this.show_overdue_notification ();
- this.delay_time_notified = total_time;
- }
- }
-
- private void notification_action_skip_cb () {
- this.break_controller.skip (true);
- }
+ protected MicroBreakController micro_break {
+ get { return (MicroBreakController)this.break_controller; }
+ }
+
+ private int delay_time_notified = 0;
+
+ public MicroBreakView (MicroBreakController micro_break, UIManager ui_manager) {
+ base (micro_break, ui_manager);
+ this.focus_priority = FocusPriority.LOW;
+
+ this.focused_and_activated.connect (this.focused_and_activated_cb);
+ this.lost_ui_focus.connect (this.lost_ui_focus_cb);
+ this.micro_break.finished.connect (this.finished_cb);
+ }
+
+ protected new void show_break_notification (Notify.Notification notification) {
+ if (this.notifications_can_do ("actions")) {
+ /* Label for a notification action that will skip the current microbreak */
+ notification.add_action ("skip", _("Skip this one"), this.notification_action_skip_cb);
+ }
+ base.show_break_notification (notification);
+ }
+
+ private void show_start_notification () {
+ var notification = this.build_common_notification (
+ _("It’s time for a micro break"),
+ _("Take a break from typing and look away from the screen"),
+ "alarm-symbolic"
+ );
+ notification.set_urgency (Notify.Urgency.NORMAL);
+ notification.set_hint ("sound-name", "message");
+ this.show_break_notification (notification);
+ }
+
+ private void show_overdue_notification () {
+ int delay_value;
+ int time_since_start = this.micro_break.get_seconds_since_start ();
+ string delay_text = NaturalTime.instance.get_simplest_label_for_seconds (
+ time_since_start, out delay_value);
+
+ string body_text = ngettext (
+ /* %s will be replaced with a string that describes a time interval, such as "2 minutes", "40
seconds" or "1 hour" */
+ "You were due to take a micro break %s ago",
+ "You were due to take a micro break %s ago",
+ delay_value
+ ).printf (delay_text);
+
+ var notification = this.build_common_notification (
+ _("Overdue micro break"),
+ body_text,
+ "alarm-symbolic"
+ );
+ notification.set_urgency (Notify.Urgency.NORMAL);
+ this.show_break_notification (notification);
+ }
+
+ private void show_finished_notification () {
+ var notification = this.build_common_notification (
+ _("Break is over"),
+ _("Your micro break has ended"),
+ "alarm-symbolic"
+ );
+ notification.set_urgency (Notify.Urgency.NORMAL);
+ this.show_lock_notification (notification);
+
+ this.play_sound_from_id ("complete");
+ }
+
+ private void focused_and_activated_cb () {
+ this.delay_time_notified = 0;
+
+ var status_widget = new TimerBreakStatusWidget (this.micro_break);
+ status_widget.set_message ( _("Take a moment to rest your eyes"));
+ this.set_overlay (status_widget);
+
+ if (! this.overlay_is_visible ()) {
+ this.show_start_notification ();
+ Timeout.add_seconds (this.get_lead_in_seconds (), () => {
+ this.reveal_overlay ();
+ return false;
+ });
+ }
+
+ this.micro_break.delayed.connect (this.delayed_cb);
+ }
+
+ private void lost_ui_focus_cb () {
+ this.micro_break.delayed.disconnect (this.delayed_cb);
+ }
+
+ private void finished_cb (BreakController.FinishedReason reason, bool was_active) {
+ if (reason == BreakController.FinishedReason.SATISFIED && was_active) {
+ this.show_finished_notification ();
+ } else {
+ this.hide_notification ();
+ }
+ }
+
+ private void delayed_cb (int lap_time, int total_time) {
+ int time_since_notified = total_time - this.delay_time_notified;
+ if (time_since_notified > this.micro_break.interval) {
+ this.show_overdue_notification ();
+ this.delay_time_notified = total_time;
+ }
+ }
+
+ private void notification_action_skip_cb () {
+ this.break_controller.skip (true);
+ }
}
}
diff --git a/helper/restbreak/RestBreakController.vala b/helper/restbreak/RestBreakController.vala
index d5dc0c7..25953e5 100644
--- a/helper/restbreak/RestBreakController.vala
+++ b/helper/restbreak/RestBreakController.vala
@@ -24,61 +24,61 @@ namespace BreakTimer.Helper {
* finished using the computer, and then it will start to count down again.
*/
public class RestBreakController : TimerBreakController {
- private Countdown reminder_countdown;
+ private Countdown reminder_countdown;
- public signal void current_duration_changed ();
+ public signal void current_duration_changed ();
- public RestBreakController (ActivityMonitor activity_monitor) {
- base (activity_monitor, 5);
+ public RestBreakController (ActivityMonitor activity_monitor) {
+ base (activity_monitor, 5);
- // Countdown for an extra reminder that a break is ongoing, if the
- // user is ignoring it
- this.reminder_countdown = new Countdown (this.interval / 4);
- this.notify["interval"].connect ( (s, p) => {
- this.reminder_countdown.set_base_duration (this.interval / 4);
- });
- this.activated.connect ( () => {
- this.reminder_countdown.reset ();
- });
+ // Countdown for an extra reminder that a break is ongoing, if the
+ // user is ignoring it
+ this.reminder_countdown = new Countdown (this.interval / 4);
+ this.notify["interval"].connect ( (s, p) => {
+ this.reminder_countdown.set_base_duration (this.interval / 4);
+ });
+ this.activated.connect ( () => {
+ this.reminder_countdown.reset ();
+ });
- this.counting.connect (this.counting_cb);
- this.delayed.connect (this.delayed_cb);
- }
+ this.counting.connect (this.counting_cb);
+ this.delayed.connect (this.delayed_cb);
+ }
- public override Json.Object serialize () {
- Json.Object json_root = base.serialize ();
- json_root.set_string_member ("reminder_countdown", this.reminder_countdown.serialize ());
- return json_root;
- }
+ public override Json.Object serialize () {
+ Json.Object json_root = base.serialize ();
+ json_root.set_string_member ("reminder_countdown", this.reminder_countdown.serialize ());
+ return json_root;
+ }
- public override void deserialize (ref Json.Object json_root) {
- base.deserialize (ref json_root);
- this.reminder_countdown.deserialize (json_root.get_string_member ("reminder_countdown"));
- }
+ public override void deserialize (ref Json.Object json_root) {
+ base.deserialize (ref json_root);
+ this.reminder_countdown.deserialize (json_root.get_string_member ("reminder_countdown"));
+ }
- private void counting_cb (int lap_time, int total_time) {
- this.reminder_countdown.pause ();
- if (lap_time > 60) {
- this.reminder_countdown.reset ();
- }
- }
+ private void counting_cb (int lap_time, int total_time) {
+ this.reminder_countdown.pause ();
+ if (lap_time > 60) {
+ this.reminder_countdown.reset ();
+ }
+ }
- private void delayed_cb (int lap_time, int total_time) {
- if (this.state == State.WAITING && lap_time > 10) {
- this.duration_countdown.reset ();
- }
- this.reminder_countdown.continue ();
+ private void delayed_cb (int lap_time, int total_time) {
+ if (this.state == State.WAITING && lap_time > 10) {
+ this.duration_countdown.reset ();
+ }
+ this.reminder_countdown.continue ();
- if (this.reminder_countdown.is_finished ()) {
- // Demand attention if the break is delayed for a long time
- int new_penalty = this.duration_countdown.get_penalty () + (this.duration/4);
- new_penalty = int.min (new_penalty, this.duration/2);
- this.duration_countdown.reset ();
- this.duration_countdown.set_penalty (new_penalty);
- this.current_duration_changed ();
- this.reminder_countdown.start ();
- }
- }
+ if (this.reminder_countdown.is_finished ()) {
+ // Demand attention if the break is delayed for a long time
+ int new_penalty = this.duration_countdown.get_penalty () + (this.duration/4);
+ new_penalty = int.min (new_penalty, this.duration/2);
+ this.duration_countdown.reset ();
+ this.duration_countdown.set_penalty (new_penalty);
+ this.current_duration_changed ();
+ this.reminder_countdown.start ();
+ }
+ }
}
}
diff --git a/helper/restbreak/RestBreakType.vala b/helper/restbreak/RestBreakType.vala
index 0c52b66..6d7caed 100644
--- a/helper/restbreak/RestBreakType.vala
+++ b/helper/restbreak/RestBreakType.vala
@@ -18,26 +18,26 @@
namespace BreakTimer.Helper {
public class RestBreakType : TimerBreakType {
- private ActivityMonitor activity_monitor;
+ private ActivityMonitor activity_monitor;
- public RestBreakType (ActivityMonitor activity_monitor) {
- Settings settings = new Settings ("org.gnome.BreakTimer.restbreak");
- base ("restbreak", settings);
- this.activity_monitor = activity_monitor;
- }
+ public RestBreakType (ActivityMonitor activity_monitor) {
+ Settings settings = new Settings ("org.gnome.BreakTimer.restbreak");
+ base ("restbreak", settings);
+ this.activity_monitor = activity_monitor;
+ }
- protected override BreakController get_break_controller () {
- return new RestBreakController (
- this.activity_monitor
- );
- }
+ protected override BreakController get_break_controller () {
+ return new RestBreakController (
+ this.activity_monitor
+ );
+ }
- protected override BreakView get_break_view (BreakController controller, UIManager ui_manager) {
- return new RestBreakView (
- (RestBreakController)controller,
- ui_manager
- );
- }
+ protected override BreakView get_break_view (BreakController controller, UIManager ui_manager) {
+ return new RestBreakView (
+ (RestBreakController)controller,
+ ui_manager
+ );
+ }
}
}
diff --git a/helper/restbreak/RestBreakView.vala b/helper/restbreak/RestBreakView.vala
index 8ce1a9d..3bcf6e6 100644
--- a/helper/restbreak/RestBreakView.vala
+++ b/helper/restbreak/RestBreakView.vala
@@ -20,196 +20,196 @@ namespace BreakTimer.Helper {
/* TODO: Use a single persistent notification throughout a given break */
public class RestBreakView : TimerBreakView {
- protected RestBreakController rest_break {
- get { return (RestBreakController)this.break_controller; }
- }
-
- private string[] rest_quotes = {
- /*
- _("The quieter you become, the more you can hear."),
- _("Knock on the sky and listen to the sound."),
- _("So little time, so little to do."),
- _("Sometimes the questions are complicated and the answers are simple."),
- _("You cannot step into the same river twice."),
- _("The obstacle is the path."),
- _("No snowflake ever falls in the wrong place."),
- _("The energy of the mind is the essence of life.")
- */
- };
-
- private int64 original_start_time = 0;
- private bool was_skipped = false;
- private bool proceeding_happily = false;
-
- public RestBreakView (RestBreakController rest_break, UIManager ui_manager) {
- base (rest_break, ui_manager);
- this.focus_priority = FocusPriority.HIGH;
-
- this.focused_and_activated.connect (this.focused_and_activated_cb);
- this.lost_ui_focus.connect (this.lost_ui_focus_cb);
- this.rest_break.finished.connect (this.finished_cb);
- }
-
- protected new void show_break_notification (Notify.Notification notification, bool allow_postpone) {
- if (allow_postpone && this.notifications_can_do ("actions")) {
- /* Label for a notification action that will delay the current break for a few
minutes */
- notification.add_action ("postpone", _("Remind me later"),
this.notification_action_postpone_cb);
- }
- base.show_break_notification (notification);
- }
-
- protected override void dismiss_break () {
- // Instead of skipping the break, we postpone for a little while.
- // Enough time to think about what you've done. You monster.
- this.rest_break.postpone (this.rest_break.interval / 4);
- }
-
- private void show_start_notification () {
- // FIXME: Should say how long the break is?
- var notification = this.build_common_notification (
- _("Time for a break"),
- _("It’s time to take a break. Get away from the computer for a little while!"),
- "alarm-symbolic"
- );
- notification.set_urgency (Notify.Urgency.NORMAL);
- notification.set_hint ("sound-name", "message");
- this.show_break_notification (notification, true);
- }
-
- private void show_interrupted_notification () {
- int countdown_value;
- int time_remaining = this.rest_break.get_time_remaining ();
- int start_time = this.rest_break.get_current_duration ();
- string countdown_text = NaturalTime.instance.get_countdown_for_seconds_with_start (
- time_remaining, start_time, out countdown_value);
-
- string body_text = ngettext (
- /* %s will be replaced with a string that describes a time interval, such as "2
minutes", "40 seconds" or "1 hour" */
- "There is %s remaining in your break",
- "There are %s remaining in your break",
- countdown_value
- ).printf (countdown_text);
-
- var notification = this.build_common_notification (
- _("Break interrupted"),
- body_text,
- "alarm-symbolic"
- );
- notification.set_urgency (Notify.Urgency.NORMAL);
- this.show_break_notification (notification, false);
- }
-
- private void show_overdue_notification () {
- int delay_value;
- int64 now = Util.get_real_time_seconds ();
- int time_since_start = (int) (now - this.original_start_time);
- string delay_text = NaturalTime.instance.get_simplest_label_for_seconds (
- time_since_start, out delay_value);
-
- string body_text = ngettext (
- /* %s will be replaced with a string that describes a time interval, such as "2
minutes", "40 seconds" or "1 hour" */
- "You were due to take a break %s ago",
- "You were due to take a break %s ago",
- delay_value
- ).printf (delay_text);
-
- var notification = this.build_common_notification (
- _("Overdue break"),
- body_text,
- "alarm-symbolic"
- );
- notification.set_urgency (Notify.Urgency.NORMAL);
- this.show_break_notification (notification, false);
- }
-
- private void show_finished_notification () {
- var notification = this.build_common_notification (
- _("Break is over"),
- _("Your break time has ended"),
- "alarm-symbolic"
- );
- notification.set_urgency (Notify.Urgency.NORMAL);
- this.show_lock_notification (notification);
-
- this.play_sound_from_id ("complete");
- }
-
- private void focused_and_activated_cb () {
- this.proceeding_happily = false;
-
- var status_widget = new TimerBreakStatusWidget (this.rest_break);
- int quote_number = Random.int_range (0, this.rest_quotes.length);
- string random_quote = this.rest_quotes[quote_number];
- status_widget.set_message (random_quote);
- this.set_overlay (status_widget);
-
- if (! this.overlay_is_visible ()) {
- // We only show notifications if the break overlay is not visible
- if (! this.was_skipped) {
- this.original_start_time = Util.get_real_time_seconds ();
- this.show_start_notification ();
- } else {
- this.show_overdue_notification ();
- }
-
- // And we escalate to showing the overlay a little later
- Timeout.add_seconds (this.get_lead_in_seconds (), () => {
- this.reveal_overlay ();
- return false;
- });
- }
-
- this.rest_break.counting.connect (this.counting_cb);
- this.rest_break.delayed.connect (this.delayed_cb);
- this.rest_break.current_duration_changed.connect (this.current_duration_changed_cb);
- }
-
- private void lost_ui_focus_cb () {
- this.rest_break.counting.disconnect (this.counting_cb);
- this.rest_break.delayed.disconnect (this.delayed_cb);
- this.rest_break.current_duration_changed.disconnect (this.current_duration_changed_cb);
- }
-
- private void finished_cb (BreakController.FinishedReason reason, bool was_active) {
- this.was_skipped = (reason == BreakController.FinishedReason.SKIPPED);
-
- if (was_active && reason == BreakController.FinishedReason.SATISFIED) {
- this.show_finished_notification ();
- } else {
- this.hide_notification ();
- }
- }
-
- private void counting_cb (int lap_time, int total_time) {
- this.proceeding_happily = lap_time > 20;
-
- if (this.proceeding_happily) {
- // TODO: Make a sound slightly before locking?
- if (this.can_lock_screen ()) this.lock_screen ();
- }
- }
-
- private void delayed_cb (int lap_time, int total_time) {
- if (this.proceeding_happily) {
- // Show a "Break interrupted" notification if the break has
- // been counting down happily until now
- this.show_interrupted_notification ();
- } else if (this.seconds_since_last_break_notification () > 60) {
- // Show an "Overdue break" notification every minute if the
- // break is being delayed.
- this.show_overdue_notification ();
- }
-
- this.proceeding_happily = false;
- }
-
- private void current_duration_changed_cb () {
- this.shake_overlay ();
- }
-
- private void notification_action_postpone_cb () {
- this.rest_break.postpone (60);
- }
+ protected RestBreakController rest_break {
+ get { return (RestBreakController)this.break_controller; }
+ }
+
+ private string[] rest_quotes = {
+ /*
+ _("The quieter you become, the more you can hear."),
+ _("Knock on the sky and listen to the sound."),
+ _("So little time, so little to do."),
+ _("Sometimes the questions are complicated and the answers are simple."),
+ _("You cannot step into the same river twice."),
+ _("The obstacle is the path."),
+ _("No snowflake ever falls in the wrong place."),
+ _("The energy of the mind is the essence of life.")
+ */
+ };
+
+ private int64 original_start_time = 0;
+ private bool was_skipped = false;
+ private bool proceeding_happily = false;
+
+ public RestBreakView (RestBreakController rest_break, UIManager ui_manager) {
+ base (rest_break, ui_manager);
+ this.focus_priority = FocusPriority.HIGH;
+
+ this.focused_and_activated.connect (this.focused_and_activated_cb);
+ this.lost_ui_focus.connect (this.lost_ui_focus_cb);
+ this.rest_break.finished.connect (this.finished_cb);
+ }
+
+ protected new void show_break_notification (Notify.Notification notification, bool allow_postpone) {
+ if (allow_postpone && this.notifications_can_do ("actions")) {
+ /* Label for a notification action that will delay the current break for a few minutes */
+ notification.add_action ("postpone", _("Remind me later"), this.notification_action_postpone_cb);
+ }
+ base.show_break_notification (notification);
+ }
+
+ protected override void dismiss_break () {
+ // Instead of skipping the break, we postpone for a little while.
+ // Enough time to think about what you've done. You monster.
+ this.rest_break.postpone (this.rest_break.interval / 4);
+ }
+
+ private void show_start_notification () {
+ // FIXME: Should say how long the break is?
+ var notification = this.build_common_notification (
+ _("Time for a break"),
+ _("It’s time to take a break. Get away from the computer for a little while!"),
+ "alarm-symbolic"
+ );
+ notification.set_urgency (Notify.Urgency.NORMAL);
+ notification.set_hint ("sound-name", "message");
+ this.show_break_notification (notification, true);
+ }
+
+ private void show_interrupted_notification () {
+ int countdown_value;
+ int time_remaining = this.rest_break.get_time_remaining ();
+ int start_time = this.rest_break.get_current_duration ();
+ string countdown_text = NaturalTime.instance.get_countdown_for_seconds_with_start (
+ time_remaining, start_time, out countdown_value);
+
+ string body_text = ngettext (
+ /* %s will be replaced with a string that describes a time interval, such as "2 minutes", "40
seconds" or "1 hour" */
+ "There is %s remaining in your break",
+ "There are %s remaining in your break",
+ countdown_value
+ ).printf (countdown_text);
+
+ var notification = this.build_common_notification (
+ _("Break interrupted"),
+ body_text,
+ "alarm-symbolic"
+ );
+ notification.set_urgency (Notify.Urgency.NORMAL);
+ this.show_break_notification (notification, false);
+ }
+
+ private void show_overdue_notification () {
+ int delay_value;
+ int64 now = Util.get_real_time_seconds ();
+ int time_since_start = (int) (now - this.original_start_time);
+ string delay_text = NaturalTime.instance.get_simplest_label_for_seconds (
+ time_since_start, out delay_value);
+
+ string body_text = ngettext (
+ /* %s will be replaced with a string that describes a time interval, such as "2 minutes", "40
seconds" or "1 hour" */
+ "You were due to take a break %s ago",
+ "You were due to take a break %s ago",
+ delay_value
+ ).printf (delay_text);
+
+ var notification = this.build_common_notification (
+ _("Overdue break"),
+ body_text,
+ "alarm-symbolic"
+ );
+ notification.set_urgency (Notify.Urgency.NORMAL);
+ this.show_break_notification (notification, false);
+ }
+
+ private void show_finished_notification () {
+ var notification = this.build_common_notification (
+ _("Break is over"),
+ _("Your break time has ended"),
+ "alarm-symbolic"
+ );
+ notification.set_urgency (Notify.Urgency.NORMAL);
+ this.show_lock_notification (notification);
+
+ this.play_sound_from_id ("complete");
+ }
+
+ private void focused_and_activated_cb () {
+ this.proceeding_happily = false;
+
+ var status_widget = new TimerBreakStatusWidget (this.rest_break);
+ int quote_number = Random.int_range (0, this.rest_quotes.length);
+ string random_quote = this.rest_quotes[quote_number];
+ status_widget.set_message (random_quote);
+ this.set_overlay (status_widget);
+
+ if (! this.overlay_is_visible ()) {
+ // We only show notifications if the break overlay is not visible
+ if (! this.was_skipped) {
+ this.original_start_time = Util.get_real_time_seconds ();
+ this.show_start_notification ();
+ } else {
+ this.show_overdue_notification ();
+ }
+
+ // And we escalate to showing the overlay a little later
+ Timeout.add_seconds (this.get_lead_in_seconds (), () => {
+ this.reveal_overlay ();
+ return false;
+ });
+ }
+
+ this.rest_break.counting.connect (this.counting_cb);
+ this.rest_break.delayed.connect (this.delayed_cb);
+ this.rest_break.current_duration_changed.connect (this.current_duration_changed_cb);
+ }
+
+ private void lost_ui_focus_cb () {
+ this.rest_break.counting.disconnect (this.counting_cb);
+ this.rest_break.delayed.disconnect (this.delayed_cb);
+ this.rest_break.current_duration_changed.disconnect (this.current_duration_changed_cb);
+ }
+
+ private void finished_cb (BreakController.FinishedReason reason, bool was_active) {
+ this.was_skipped = (reason == BreakController.FinishedReason.SKIPPED);
+
+ if (was_active && reason == BreakController.FinishedReason.SATISFIED) {
+ this.show_finished_notification ();
+ } else {
+ this.hide_notification ();
+ }
+ }
+
+ private void counting_cb (int lap_time, int total_time) {
+ this.proceeding_happily = lap_time > 20;
+
+ if (this.proceeding_happily) {
+ // TODO: Make a sound slightly before locking?
+ if (this.can_lock_screen ()) this.lock_screen ();
+ }
+ }
+
+ private void delayed_cb (int lap_time, int total_time) {
+ if (this.proceeding_happily) {
+ // Show a "Break interrupted" notification if the break has
+ // been counting down happily until now
+ this.show_interrupted_notification ();
+ } else if (this.seconds_since_last_break_notification () > 60) {
+ // Show an "Overdue break" notification every minute if the
+ // break is being delayed.
+ this.show_overdue_notification ();
+ }
+
+ this.proceeding_happily = false;
+ }
+
+ private void current_duration_changed_cb () {
+ this.shake_overlay ();
+ }
+
+ private void notification_action_postpone_cb () {
+ this.rest_break.postpone (60);
+ }
}
}
diff --git a/helper/util/Countdown.vala b/helper/util/Countdown.vala
index e4d1894..1545ae7 100644
--- a/helper/util/Countdown.vala
+++ b/helper/util/Countdown.vala
@@ -24,251 +24,251 @@ namespace BreakTimer.Helper {
* adjusted at any time using penalty and bonus time.
*/
public class Countdown : Object {
- private enum State {
- STOPPED,
- PAUSED,
- COUNTING
- }
- private State state;
-
- private int base_duration;
-
- private int64 start_time;
- private int stop_time_elapsed;
- private int penalty;
-
- public Countdown (int base_duration) {
- this.base_duration = base_duration;
- this.reset ();
- }
+ private enum State {
+ STOPPED,
+ PAUSED,
+ COUNTING
+ }
+ private State state;
+
+ private int base_duration;
+
+ private int64 start_time;
+ private int stop_time_elapsed;
+ private int penalty;
+
+ public Countdown (int base_duration) {
+ this.base_duration = base_duration;
+ this.reset ();
+ }
- public string serialize () {
- int serialized_time_counted = (int) (Util.get_real_time_seconds () - this.start_time);
- serialized_time_counted = int.max (0, serialized_time_counted);
+ public string serialize () {
+ int serialized_time_counted = (int) (Util.get_real_time_seconds () - this.start_time);
+ serialized_time_counted = int.max (0, serialized_time_counted);
- return string.joinv (",", {
- ( (int)this.state).to_string (),
- this.start_time.to_string (),
- this.stop_time_elapsed.to_string (),
- this.penalty.to_string (),
- serialized_time_counted.to_string ()
- });
- }
+ return string.joinv (",", {
+ ( (int)this.state).to_string (),
+ this.start_time.to_string (),
+ this.stop_time_elapsed.to_string (),
+ this.penalty.to_string (),
+ serialized_time_counted.to_string ()
+ });
+ }
- public void deserialize (string data, bool persistent = false) {
- string[] data_parts = data.split (",");
+ public void deserialize (string data, bool persistent = false) {
+ string[] data_parts = data.split (",");
- State serialized_state = (State)int.parse (data_parts[0]);
+ State serialized_state = (State)int.parse (data_parts[0]);
- switch (serialized_state) {
- case State.STOPPED:
- this.reset ();
- break;
- case State.PAUSED:
- this.pause ();
- break;
- case State.COUNTING:
- this.start ();
- break;
- }
+ switch (serialized_state) {
+ case State.STOPPED:
+ this.reset ();
+ break;
+ case State.PAUSED:
+ this.pause ();
+ break;
+ case State.COUNTING:
+ this.start ();
+ break;
+ }
- this.stop_time_elapsed = int.parse (data_parts[2]);
- this.penalty = int.parse (data_parts[3]);
+ this.stop_time_elapsed = int.parse (data_parts[2]);
+ this.penalty = int.parse (data_parts[3]);
- if (persistent) {
- // Pretend the countdown has been running since it was serialized
- this.start_time = int64.parse (data_parts[1]);
- } else {
- // Resume where the timer left off
- if (serialized_state == State.COUNTING) {
- int serialized_time_counted = int.parse (data_parts[4]);
- this.advance_time (serialized_time_counted);
- }
- }
- }
-
- /**
- * Stop the countdown and forget its current position.
- * This is the same as calling Countdown.start (), except the countdown
- * will not advance.
- */
- public void reset () {
- this.penalty = 0;
- this.stop_time_elapsed = 0;
- this.state = State.STOPPED;
- }
-
- /**
- * Start counting down from the time set with set_base_duration.
- * This is the same as calling Countdown.stop () followed by
- * Countdown.continue ().
- */
- public void start () {
- this.start_from (0);
- }
-
- /**
- * Start counting with the time offset by the given number of seconds.
- * Useful if the countdown should have started in the past.
- * @param start_offset the number of seconds to offset the start time,
- * where a negative value brings the countdown closer
- * to being finished.
- */
- public void start_from (int start_offset) {
- this.reset ();
- this.continue_from (start_offset);
- }
-
- /**
- * Pause the countdown, keeping its current position.
- */
- public void pause () {
- this.stop_time_elapsed = this.get_time_elapsed ();
- this.state = State.PAUSED;
- }
-
- /**
- * Start the countdown, continuing from the current position if
- * possible.
- */
- public void continue () {
- if (this.state < State.COUNTING) {
- this.continue_from (0);
- }
- }
-
- /**
- * If not already counting, start counting with the time offset by the
- * given number of seconds. This is like start_from, but it never resets
- * the countdown.
- * @param start_offset the number of seconds to offset the start time,
- * where a negative value brings the countdown closer
- * to being finished.
- */
- public void continue_from (int start_offset) {
- if (this.state < State.COUNTING) {
- int64 now = Util.get_real_time_seconds ();
- this.start_time = now + start_offset;
- this.state = State.COUNTING;
- }
- }
+ if (persistent) {
+ // Pretend the countdown has been running since it was serialized
+ this.start_time = int64.parse (data_parts[1]);
+ } else {
+ // Resume where the timer left off
+ if (serialized_state == State.COUNTING) {
+ int serialized_time_counted = int.parse (data_parts[4]);
+ this.advance_time (serialized_time_counted);
+ }
+ }
+ }
+
+ /**
+ * Stop the countdown and forget its current position.
+ * This is the same as calling Countdown.start (), except the countdown
+ * will not advance.
+ */
+ public void reset () {
+ this.penalty = 0;
+ this.stop_time_elapsed = 0;
+ this.state = State.STOPPED;
+ }
+
+ /**
+ * Start counting down from the time set with set_base_duration.
+ * This is the same as calling Countdown.stop () followed by
+ * Countdown.continue ().
+ */
+ public void start () {
+ this.start_from (0);
+ }
+
+ /**
+ * Start counting with the time offset by the given number of seconds.
+ * Useful if the countdown should have started in the past.
+ * @param start_offset the number of seconds to offset the start time,
+ * where a negative value brings the countdown closer
+ * to being finished.
+ */
+ public void start_from (int start_offset) {
+ this.reset ();
+ this.continue_from (start_offset);
+ }
+
+ /**
+ * Pause the countdown, keeping its current position.
+ */
+ public void pause () {
+ this.stop_time_elapsed = this.get_time_elapsed ();
+ this.state = State.PAUSED;
+ }
+
+ /**
+ * Start the countdown, continuing from the current position if
+ * possible.
+ */
+ public void continue () {
+ if (this.state < State.COUNTING) {
+ this.continue_from (0);
+ }
+ }
+
+ /**
+ * If not already counting, start counting with the time offset by the
+ * given number of seconds. This is like start_from, but it never resets
+ * the countdown.
+ * @param start_offset the number of seconds to offset the start time,
+ * where a negative value brings the countdown closer
+ * to being finished.
+ */
+ public void continue_from (int start_offset) {
+ if (this.state < State.COUNTING) {
+ int64 now = Util.get_real_time_seconds ();
+ this.start_time = now + start_offset;
+ this.state = State.COUNTING;
+ }
+ }
- /**
- * If the countdown is paused, continue as if that never happened. This
- * has the effect of the countdown advancing by the time for which it was
- * paused.
- */
- public void cancel_pause () {
- if (this.state == State.PAUSED) {
- this.stop_time_elapsed = 0;
- this.state = State.COUNTING;
- }
- }
+ /**
+ * If the countdown is paused, continue as if that never happened. This
+ * has the effect of the countdown advancing by the time for which it was
+ * paused.
+ */
+ public void cancel_pause () {
+ if (this.state == State.PAUSED) {
+ this.stop_time_elapsed = 0;
+ this.state = State.COUNTING;
+ }
+ }
- /**
- * Advance the countdown by the number of seconds, regardless of its
- * present state. If the countdown is currently paused, calling continue
- * will take into account the given offset.
- * @param seconds_off the number of seconds to advance the countdown,
- * where a positive value brings it closer to being
- * finished.
- */
- public void advance_time (int seconds_off) {
- int64 now = Util.get_real_time_seconds ();
- if (this.state == State.COUNTING) {
- this.start_time = now - seconds_off;
- } else {
- this.stop_time_elapsed += seconds_off;
- }
- }
+ /**
+ * Advance the countdown by the number of seconds, regardless of its
+ * present state. If the countdown is currently paused, calling continue
+ * will take into account the given offset.
+ * @param seconds_off the number of seconds to advance the countdown,
+ * where a positive value brings it closer to being
+ * finished.
+ */
+ public void advance_time (int seconds_off) {
+ int64 now = Util.get_real_time_seconds ();
+ if (this.state == State.COUNTING) {
+ this.start_time = now - seconds_off;
+ } else {
+ this.stop_time_elapsed += seconds_off;
+ }
+ }
- /**
- * Sets a temporary time penalty. This increases the countdown's duration
- * until it is reset.
- * @param penalty the number of seconds extra the countdown will last.
- */
- public void set_penalty (int penalty) {
- this.penalty = penalty;
- }
-
- /**
- * @return the current time penalty for the countdown.
- * @see set_penalty
- */
- public int get_penalty () {
- return this.penalty;
- }
-
- /**
- * @return true if the countdown is currently counting, or false if it is
- * either stopped or paused.
- */
- public bool is_counting () {
- return this.state == State.COUNTING;
- }
-
- /**
- * Sets the base duration for the countdown. This is how long the
- * countdown will last from when it is freshly started.
- *
- * The base duration can be changed while the countdown is counting. The
- * elapsed time will not change, while the remaining time will increase or
- * decrease based on that elapsed time, the new base duration, and the
- * current penalty.
- *
- * @param base_duration the new base duration for the countdown
- */
- public void set_base_duration (int base_duration) {
- this.base_duration = base_duration;
- }
-
- /**
- * Returns the current duration for the countdown. This is not the same as
- * the base duration: it takes into account the penalty, as well. The
- * return value will change as the time penalty changes.
- * @return the countdown's duration
- */
- public int get_duration () {
- return int.max (0, this.base_duration + this.penalty);
- }
-
- /**
- * Returns the amount of time that the countdown has been counting, if at
- * all. If the countdown is paused, this will return the elapsed time from
- * the point when it was paused.
- * @return the countdown's current elapsed time, or 0
- */
- public int get_time_elapsed () {
- int time_elapsed = this.stop_time_elapsed;
-
- if (this.state == State.COUNTING) {
- int64 now = Util.get_real_time_seconds ();
- time_elapsed += (int) (now - this.start_time);
- }
-
- return int.max (0, time_elapsed);
- }
-
- /**
- * Returns the time remaining until the countdown will be finished, or 0
- * if the countdown is already finished. If the countdown is not counting,
- * this will return its current duration.
- * @return the time the countdown needs to count until it is finished
- */
- public int get_time_remaining () {
- int time_remaining = this.get_duration () - this.get_time_elapsed ();
- return int.max (0, time_remaining);
- }
+ /**
+ * Sets a temporary time penalty. This increases the countdown's duration
+ * until it is reset.
+ * @param penalty the number of seconds extra the countdown will last.
+ */
+ public void set_penalty (int penalty) {
+ this.penalty = penalty;
+ }
+
+ /**
+ * @return the current time penalty for the countdown.
+ * @see set_penalty
+ */
+ public int get_penalty () {
+ return this.penalty;
+ }
+
+ /**
+ * @return true if the countdown is currently counting, or false if it is
+ * either stopped or paused.
+ */
+ public bool is_counting () {
+ return this.state == State.COUNTING;
+ }
+
+ /**
+ * Sets the base duration for the countdown. This is how long the
+ * countdown will last from when it is freshly started.
+ *
+ * The base duration can be changed while the countdown is counting. The
+ * elapsed time will not change, while the remaining time will increase or
+ * decrease based on that elapsed time, the new base duration, and the
+ * current penalty.
+ *
+ * @param base_duration the new base duration for the countdown
+ */
+ public void set_base_duration (int base_duration) {
+ this.base_duration = base_duration;
+ }
+
+ /**
+ * Returns the current duration for the countdown. This is not the same as
+ * the base duration: it takes into account the penalty, as well. The
+ * return value will change as the time penalty changes.
+ * @return the countdown's duration
+ */
+ public int get_duration () {
+ return int.max (0, this.base_duration + this.penalty);
+ }
+
+ /**
+ * Returns the amount of time that the countdown has been counting, if at
+ * all. If the countdown is paused, this will return the elapsed time from
+ * the point when it was paused.
+ * @return the countdown's current elapsed time, or 0
+ */
+ public int get_time_elapsed () {
+ int time_elapsed = this.stop_time_elapsed;
+
+ if (this.state == State.COUNTING) {
+ int64 now = Util.get_real_time_seconds ();
+ time_elapsed += (int) (now - this.start_time);
+ }
+
+ return int.max (0, time_elapsed);
+ }
+
+ /**
+ * Returns the time remaining until the countdown will be finished, or 0
+ * if the countdown is already finished. If the countdown is not counting,
+ * this will return its current duration.
+ * @return the time the countdown needs to count until it is finished
+ */
+ public int get_time_remaining () {
+ int time_remaining = this.get_duration () - this.get_time_elapsed ();
+ return int.max (0, time_remaining);
+ }
- /**
- * Returns true if the countdown is finished; if its elapsed time meets or
- * exceeds its duration. This is equivalent to checking if the remaining
- * time is 0.
- * @return true if the countdown is finished.
- */
- public bool is_finished () {
- return this.get_time_remaining () == 0;
- }
+ /**
+ * Returns true if the countdown is finished; if its elapsed time meets or
+ * exceeds its duration. This is equivalent to checking if the remaining
+ * time is 0.
+ * @return true if the countdown is finished.
+ */
+ public bool is_finished () {
+ return this.get_time_remaining () == 0;
+ }
}
}
diff --git a/helper/util/PausableTimeout.vala b/helper/util/PausableTimeout.vala
index 983c6bd..ecdc361 100644
--- a/helper/util/PausableTimeout.vala
+++ b/helper/util/PausableTimeout.vala
@@ -24,73 +24,73 @@ namespace BreakTimer.Helper {
* start methods, respectively.
*/
public class PausableTimeout : Object {
- public delegate void TimeoutCB (PausableTimeout timeout, int delta_millisecs);
-
- private unowned TimeoutCB timeout_cb;
- private uint source_id;
- private int frequency;
- private int64 last_time;
-
- public PausableTimeout (TimeoutCB callback, int frequency) {
- this.timeout_cb = callback;
- this.frequency = frequency;
- }
+ public delegate void TimeoutCB (PausableTimeout timeout, int delta_millisecs);
+
+ private unowned TimeoutCB timeout_cb;
+ private uint source_id;
+ private int frequency;
+ private int64 last_time;
+
+ public PausableTimeout (TimeoutCB callback, int frequency) {
+ this.timeout_cb = callback;
+ this.frequency = frequency;
+ }
- public string serialize () {
- return string.joinv (",", {
- this.frequency.to_string (),
- this.last_time.to_string ()
- });
- }
+ public string serialize () {
+ return string.joinv (",", {
+ this.frequency.to_string (),
+ this.last_time.to_string ()
+ });
+ }
- public void deserialize (string data) {
- string[] data_parts = data.split (",");
- this.frequency = int.parse (data_parts[0]);
- this.last_time = int64.parse (data_parts[1]);
- }
-
- private bool timeout_wrapper () {
- int64 now = Util.get_monotonic_time ();
- int64 time_delta = now - this.last_time;
- this.last_time = now;
-
- int delta_millisecs = (int) (time_delta / 1000);
- this.timeout_cb (this, delta_millisecs);
-
- return true;
- }
+ public void deserialize (string data) {
+ string[] data_parts = data.split (",");
+ this.frequency = int.parse (data_parts[0]);
+ this.last_time = int64.parse (data_parts[1]);
+ }
+
+ private bool timeout_wrapper () {
+ int64 now = Util.get_monotonic_time ();
+ int64 time_delta = now - this.last_time;
+ this.last_time = now;
+
+ int delta_millisecs = (int) (time_delta / 1000);
+ this.timeout_cb (this, delta_millisecs);
+
+ return true;
+ }
- public void run_once () {
- this.timeout_wrapper ();
- }
-
- public void start () {
- if (this.is_running ()) {
- Source.remove (this.source_id);
- }
-
- this.last_time = Util.get_monotonic_time ();
-
- this.source_id = Timeout.add_seconds (this.frequency, this.timeout_wrapper);
- }
-
- public void set_frequency (int frequency) {
- this.frequency = frequency;
- if (this.is_running ()) {
- this.start ();
- }
- }
-
- public void stop () {
- if (this.is_running ()) {
- Source.remove (this.source_id);
- this.source_id = 0;
- }
- }
-
- public bool is_running () {
- return this.source_id > 0;
- }
+ public void run_once () {
+ this.timeout_wrapper ();
+ }
+
+ public void start () {
+ if (this.is_running ()) {
+ Source.remove (this.source_id);
+ }
+
+ this.last_time = Util.get_monotonic_time ();
+
+ this.source_id = Timeout.add_seconds (this.frequency, this.timeout_wrapper);
+ }
+
+ public void set_frequency (int frequency) {
+ this.frequency = frequency;
+ if (this.is_running ()) {
+ this.start ();
+ }
+ }
+
+ public void stop () {
+ if (this.is_running ()) {
+ Source.remove (this.source_id);
+ this.source_id = 0;
+ }
+ }
+
+ public bool is_running () {
+ return this.source_id > 0;
+ }
}
}
diff --git a/helper/util/SimpleFocusManager.vala b/helper/util/SimpleFocusManager.vala
index e057176..1693f18 100644
--- a/helper/util/SimpleFocusManager.vala
+++ b/helper/util/SimpleFocusManager.vala
@@ -18,14 +18,14 @@
namespace BreakTimer.Helper {
public interface IFocusable : Object {
- public abstract void focus_started ();
- public abstract void focus_stopped ();
+ public abstract void focus_started ();
+ public abstract void focus_stopped ();
}
public enum FocusPriority {
- NONE,
- LOW,
- HIGH
+ NONE,
+ LOW,
+ HIGH
}
/**
@@ -36,80 +36,80 @@ public enum FocusPriority {
* request or release focus.
*/
public class SimpleFocusManager : Object {
- private class Request : Object {
- public IFocusable owner;
- public FocusPriority priority;
-
- public static int priority_compare_func (Request a, Request b) {
- if (a.priority < b.priority) {
- return -1;
- } else if (a.priority == b.priority) {
- return 0;
- } else {
- return 1;
- }
- }
- }
-
- private SList<Request> focus_requests;
- private Request? current_focus;
-
- public SimpleFocusManager () {
- this.focus_requests = new SList<Request> ();
- this.current_focus = null;
- }
-
- private void set_focus (Request? new_focus) {
- Request? old_focus = this.current_focus;
-
- if (new_focus != old_focus) {
- this.current_focus = new_focus;
- // the order is important so new_focus can gracefully replace old_focus
- if (new_focus != null) {
- new_focus.owner.focus_started ();
- }
- if (old_focus != null) {
- old_focus.owner.focus_stopped ();
- }
- }
- }
-
- private void update_focus () {
- Request? new_focus = null;
- if (this.focus_requests.length () > 0) {
- new_focus = this.focus_requests.last ().data;
- }
- this.set_focus (new_focus);
- }
-
- private bool focus_requested (IFocusable focusable) {
- foreach (Request request in this.focus_requests) {
- if (request.owner == focusable) return true;
- }
- return false;
- }
-
- public void request_focus (IFocusable focusable, FocusPriority priority) {
- if (! this.focus_requested (focusable)) {
- Request request = new Request ();
- request.owner = focusable;
- request.priority = priority;
-
- this.focus_requests.insert_sorted (request, Request.priority_compare_func);
- this.update_focus ();
- }
- }
-
- public void release_focus (IFocusable focusable) {
- foreach (Request request in this.focus_requests) {
- if (request.owner == focusable) this.focus_requests.remove (request);
- }
- this.update_focus ();
- }
-
- public bool is_focusing (IFocusable focusable) {
- return this.current_focus != null && this.current_focus.owner == focusable;
- }
+ private class Request : Object {
+ public IFocusable owner;
+ public FocusPriority priority;
+
+ public static int priority_compare_func (Request a, Request b) {
+ if (a.priority < b.priority) {
+ return -1;
+ } else if (a.priority == b.priority) {
+ return 0;
+ } else {
+ return 1;
+ }
+ }
+ }
+
+ private SList<Request> focus_requests;
+ private Request? current_focus;
+
+ public SimpleFocusManager () {
+ this.focus_requests = new SList<Request> ();
+ this.current_focus = null;
+ }
+
+ private void set_focus (Request? new_focus) {
+ Request? old_focus = this.current_focus;
+
+ if (new_focus != old_focus) {
+ this.current_focus = new_focus;
+ // the order is important so new_focus can gracefully replace old_focus
+ if (new_focus != null) {
+ new_focus.owner.focus_started ();
+ }
+ if (old_focus != null) {
+ old_focus.owner.focus_stopped ();
+ }
+ }
+ }
+
+ private void update_focus () {
+ Request? new_focus = null;
+ if (this.focus_requests.length () > 0) {
+ new_focus = this.focus_requests.last ().data;
+ }
+ this.set_focus (new_focus);
+ }
+
+ private bool focus_requested (IFocusable focusable) {
+ foreach (Request request in this.focus_requests) {
+ if (request.owner == focusable) return true;
+ }
+ return false;
+ }
+
+ public void request_focus (IFocusable focusable, FocusPriority priority) {
+ if (! this.focus_requested (focusable)) {
+ Request request = new Request ();
+ request.owner = focusable;
+ request.priority = priority;
+
+ this.focus_requests.insert_sorted (request, Request.priority_compare_func);
+ this.update_focus ();
+ }
+ }
+
+ public void release_focus (IFocusable focusable) {
+ foreach (Request request in this.focus_requests) {
+ if (request.owner == focusable) this.focus_requests.remove (request);
+ }
+ this.update_focus ();
+ }
+
+ public bool is_focusing (IFocusable focusable) {
+ return this.current_focus != null && this.current_focus.owner == focusable;
+ }
}
}
diff --git a/helper/util/StatefulTimer.vala b/helper/util/StatefulTimer.vala
index 995c9d9..7da0306 100644
--- a/helper/util/StatefulTimer.vala
+++ b/helper/util/StatefulTimer.vala
@@ -25,105 +25,105 @@ namespace BreakTimer.Helper {
* - a "lap" feature (start_lap, lap_time) to measure smaller time intervals
*/
public class StatefulTimer : Object {
- public enum State {
- STOPPED,
- COUNTING
- }
- public State state { public get; private set; }
-
- private Timer timer;
- private double timer_error;
- private double lap_start;
-
- public StatefulTimer () {
- this.timer = new Timer ();
- this.state = State.COUNTING;
- }
-
- public string serialize () {
- return string.joinv (",", {
- ( (int)this.state).to_string (),
- this.elapsed ().to_string (),
- this.lap_start.to_string ()
- });
- }
-
- public void deserialize (string data) {
- string[] data_parts = data.split (",");
- State old_state = (State)int.parse (data_parts[0]);
- double old_elapsed = double.parse (data_parts[1]);
- double old_lap_start = double.parse (data_parts[2]);
-
- // We need to update the timer (which was not serialized) according to the State variable
- if (old_state == State.STOPPED) {
- this.stop ();
- } else if (old_state == State.COUNTING) {
- this.start ();
- }
- this.timer_error = this.elapsed () - old_elapsed;
- this.lap_start = old_lap_start;
- }
-
- public inline bool is_stopped () {
- return ! this.is_counting ();
- }
-
- public bool is_counting () {
- return this.state == State.COUNTING;
- }
-
- public void start () {
- this.timer.start ();
- this.state = State.COUNTING;
- this.timer_error = 0;
- this.lap_start = 0;
- }
-
- public void stop () {
- this.timer.stop ();
- this.state = State.STOPPED;
- }
-
- public void continue () {
- this.timer.continue ();
- this.state = State.COUNTING;
- }
-
- public double elapsed () {
- return this.timer.elapsed () - this.timer_error;
- }
-
- public void reset () {
- this.start ();
- }
-
- /**
- * Starts counting a new lap, and continues the timer if it is not
- * already counting.
- */
- public void start_lap () {
- if (this.is_stopped ()) this.continue ();
- this.lap_start = this.elapsed ();
- }
-
- /**
- * Returns the time since the last lap was created, or the elapsed time if
- * no laps have been created.
- * @see start_lap
- */
- public double lap_time () {
- return this.elapsed () - this.lap_start;
- }
-
- /**
- * Stops the timer, but does not advance the end time if if is already
- * stopped.
- */
- public void freeze () {
- if (this.state > State.STOPPED) {
- this.stop ();
- }
- }
+ public enum State {
+ STOPPED,
+ COUNTING
+ }
+ public State state { public get; private set; }
+
+ private Timer timer;
+ private double timer_error;
+ private double lap_start;
+
+ public StatefulTimer () {
+ this.timer = new Timer ();
+ this.state = State.COUNTING;
+ }
+
+ public string serialize () {
+ return string.joinv (",", {
+ ( (int)this.state).to_string (),
+ this.elapsed ().to_string (),
+ this.lap_start.to_string ()
+ });
+ }
+
+ public void deserialize (string data) {
+ string[] data_parts = data.split (",");
+ State old_state = (State)int.parse (data_parts[0]);
+ double old_elapsed = double.parse (data_parts[1]);
+ double old_lap_start = double.parse (data_parts[2]);
+
+ // We need to update the timer (which was not serialized) according to the State variable
+ if (old_state == State.STOPPED) {
+ this.stop ();
+ } else if (old_state == State.COUNTING) {
+ this.start ();
+ }
+ this.timer_error = this.elapsed () - old_elapsed;
+ this.lap_start = old_lap_start;
+ }
+
+ public inline bool is_stopped () {
+ return ! this.is_counting ();
+ }
+
+ public bool is_counting () {
+ return this.state == State.COUNTING;
+ }
+
+ public void start () {
+ this.timer.start ();
+ this.state = State.COUNTING;
+ this.timer_error = 0;
+ this.lap_start = 0;
+ }
+
+ public void stop () {
+ this.timer.stop ();
+ this.state = State.STOPPED;
+ }
+
+ public void continue () {
+ this.timer.continue ();
+ this.state = State.COUNTING;
+ }
+
+ public double elapsed () {
+ return this.timer.elapsed () - this.timer_error;
+ }
+
+ public void reset () {
+ this.start ();
+ }
+
+ /**
+ * Starts counting a new lap, and continues the timer if it is not
+ * already counting.
+ */
+ public void start_lap () {
+ if (this.is_stopped ()) this.continue ();
+ this.lap_start = this.elapsed ();
+ }
+
+ /**
+ * Returns the time since the last lap was created, or the elapsed time if
+ * no laps have been created.
+ * @see start_lap
+ */
+ public double lap_time () {
+ return this.elapsed () - this.lap_start;
+ }
+
+ /**
+ * Stops the timer, but does not advance the end time if if is already
+ * stopped.
+ */
+ public void freeze () {
+ if (this.state > State.STOPPED) {
+ this.stop ();
+ }
+ }
}
}
diff --git a/helper/util/Util.vala b/helper/util/Util.vala
index d9b38b3..1901761 100644
--- a/helper/util/Util.vala
+++ b/helper/util/Util.vala
@@ -22,44 +22,44 @@ namespace BreakTimer.Helper {
* but end up being used throughout this application.
*/
public class Util {
- public const int MILLISECONDS_IN_SECONDS = 1000;
- public const int MICROSECONDS_IN_SECONDS = 1000 * 1000;
+ public const int MILLISECONDS_IN_SECONDS = 1000;
+ public const int MICROSECONDS_IN_SECONDS = 1000 * 1000;
- public static bool _do_override_time = false;
- public static int64 _override_real_time = 0;
- public static int64 _override_monotonic_time = 0;
+ public static bool _do_override_time = false;
+ public static int64 _override_real_time = 0;
+ public static int64 _override_monotonic_time = 0;
- public inline static int64 get_real_time () {
- if (_do_override_time) {
- return _override_real_time;
- } else {
- return GLib.get_real_time ();
- }
- }
+ public inline static int64 get_real_time () {
+ if (_do_override_time) {
+ return _override_real_time;
+ } else {
+ return GLib.get_real_time ();
+ }
+ }
- public inline static int64 get_real_time_ms () {
- return get_real_time () / MILLISECONDS_IN_SECONDS;
- }
+ public inline static int64 get_real_time_ms () {
+ return get_real_time () / MILLISECONDS_IN_SECONDS;
+ }
- public inline static int64 get_real_time_seconds () {
- return get_real_time () / MICROSECONDS_IN_SECONDS;
- }
+ public inline static int64 get_real_time_seconds () {
+ return get_real_time () / MICROSECONDS_IN_SECONDS;
+ }
- public inline static int64 get_monotonic_time () {
- if (_do_override_time) {
- return _override_monotonic_time;
- } else {
- return GLib.get_monotonic_time ();
- }
- }
+ public inline static int64 get_monotonic_time () {
+ if (_do_override_time) {
+ return _override_monotonic_time;
+ } else {
+ return GLib.get_monotonic_time ();
+ }
+ }
- public inline static int64 get_monotonic_time_ms () {
- return get_monotonic_time () / MILLISECONDS_IN_SECONDS;
- }
+ public inline static int64 get_monotonic_time_ms () {
+ return get_monotonic_time () / MILLISECONDS_IN_SECONDS;
+ }
- public inline static int64 get_monotonic_time_seconds () {
- return get_monotonic_time () / MICROSECONDS_IN_SECONDS;
- }
+ public inline static int64 get_monotonic_time_seconds () {
+ return get_monotonic_time () / MICROSECONDS_IN_SECONDS;
+ }
}
}
diff --git a/meson.build b/meson.build
index fb9659f..040ea6d 100644
--- a/meson.build
+++ b/meson.build
@@ -79,7 +79,7 @@ config_lib_dep = declare_dependency(
)
configure_file(
- input: 'gnome-break-timer.in',
+ input: 'gnome-break-timer.sh.in',
output: 'gnome-break-timer',
configuration: build_conf,
install: true,
diff --git a/settings/BreakManager.vala b/settings/BreakManager.vala
index c029156..3093883 100644
--- a/settings/BreakManager.vala
+++ b/settings/BreakManager.vala
@@ -24,133 +24,133 @@ using GLib;
namespace BreakTimer.Settings {
public class BreakManager : Object {
- private SettingsApplication application;
-
- private IBreakHelper break_helper;
-
- private Gee.Map<string, BreakType> breaks;
- private GLib.List<BreakType> breaks_ordered;
-
- private GLib.Settings settings;
- public bool master_enabled { get; set; }
- public string[] selected_break_ids { get; set; }
- public BreakType? foreground_break { get; private set; }
-
- public BreakManager (SettingsApplication application) {
- this.application = application;
- this.breaks = new Gee.HashMap<string, BreakType> ();
- this.breaks_ordered = new GLib.List<BreakType> ();
-
- this.settings = new GLib.Settings ("org.gnome.BreakTimer");
- this.settings.bind ("enabled", this, "master-enabled", SettingsBindFlags.DEFAULT);
- this.settings.bind ("selected-breaks", this, "selected-break-ids", SettingsBindFlags.DEFAULT);
-
- // We choose not too send a signal when master_enabled changes because
- // we might be starting the break helper at the same time, so the
- // value of is_working () could fluctuate unpleasantly.
- //this.notify["master-enabled"].connect ( () => { this.status_changed (); });
- this.notify["master-enabled"].connect ( () => {
- // Launch the break timer service if the break manager is enabled
- // TODO: this is redundant, because gnome-session autostarts the
- // service. However, it is unclear if we should rely on it.
- if (this.master_enabled) this.launch_break_timer_service ();
- });
- }
-
- public signal void break_status_available ();
- public signal void break_added (BreakType break_type);
- public signal void status_changed ();
-
- public void load_breaks () {
- this.add_break (new MicroBreakType ());
- this.add_break (new RestBreakType ());
-
- this.status_changed ();
-
- Bus.watch_name (BusType.SESSION, Config.HELPER_BUS_NAME, BusNameWatcherFlags.NONE,
- this.break_helper_appeared, this.break_helper_disappeared);
- }
-
- public Gee.Set<string> all_break_ids () {
- return this.breaks.keys;
- }
-
- public unowned GLib.List<BreakType> all_breaks () {
- return this.breaks_ordered;
- }
-
- /**
- * @returns true if the break helper is working correctly.
- */
- public bool is_working () {
- return (this.master_enabled == false || this.breaks.size == 0 || this.break_helper != null);
- }
-
- public BreakType? get_break_type_for_name (string name) {
- return this.breaks.get (name);
- }
-
- private void add_break (BreakType break_type) {
- break_type.initialize ();
- this.breaks.set (break_type.id, break_type);
- this.breaks_ordered.append (break_type);
- break_type.status_changed.connect (this.break_status_changed);
- this.break_added (break_type);
- }
-
- private void break_status_changed (BreakType break_type, BreakStatus? break_status) {
- BreakType? new_foreground_break = this.foreground_break;
-
- if (break_status != null && break_status.is_focused && break_status.is_active) {
- new_foreground_break = break_type;
- } else if (this.foreground_break == break_type) {
- new_foreground_break = null;
- }
-
- if (this.foreground_break != new_foreground_break) {
- this.foreground_break = new_foreground_break;
- }
-
- this.status_changed ();
- }
-
- private void break_helper_appeared () {
- try {
- this.break_helper = Bus.get_proxy_sync (
- BusType.SESSION,
- Config.HELPER_BUS_NAME,
- Config.HELPER_OBJECT_PATH,
- DBusProxyFlags.DO_NOT_AUTO_START
- );
- this.break_status_available ();
- } catch (IOError error) {
- this.break_helper = null;
- GLib.warning ("Error connecting to break helper service: %s", error.message);
- }
- }
-
- private void break_helper_disappeared () {
- if (this.break_helper == null && this.master_enabled) {
- // Try to start break_helper automatically if it should be
- // running. Only do this once, if it was not running previously.
- this.launch_break_timer_service ();
- }
-
- this.break_helper = null;
-
- this.status_changed ();
- }
-
- private void launch_break_timer_service () {
- // TODO: Use dbus activation once we can depend on GLib >= 2.37
- AppInfo helper_app_info = new DesktopAppInfo (Config.HELPER_DESKTOP_ID);
- AppLaunchContext app_launch_context = new AppLaunchContext ();
- try {
- helper_app_info.launch (null, app_launch_context);
- } catch (Error error) {
- GLib.warning ("Error launching helper application: %s", error.message);
- }
- }
+ private SettingsApplication application;
+
+ private IBreakHelper break_helper;
+
+ private Gee.Map<string, BreakType> breaks;
+ private GLib.List<BreakType> breaks_ordered;
+
+ private GLib.Settings settings;
+ public bool master_enabled { get; set; }
+ public string[] selected_break_ids { get; set; }
+ public BreakType? foreground_break { get; private set; }
+
+ public BreakManager (SettingsApplication application) {
+ this.application = application;
+ this.breaks = new Gee.HashMap<string, BreakType> ();
+ this.breaks_ordered = new GLib.List<BreakType> ();
+
+ this.settings = new GLib.Settings ("org.gnome.BreakTimer");
+ this.settings.bind ("enabled", this, "master-enabled", SettingsBindFlags.DEFAULT);
+ this.settings.bind ("selected-breaks", this, "selected-break-ids", SettingsBindFlags.DEFAULT);
+
+ // We choose not too send a signal when master_enabled changes because
+ // we might be starting the break helper at the same time, so the
+ // value of is_working () could fluctuate unpleasantly.
+ //this.notify["master-enabled"].connect ( () => { this.status_changed (); });
+ this.notify["master-enabled"].connect ( () => {
+ // Launch the break timer service if the break manager is enabled
+ // TODO: this is redundant, because gnome-session autostarts the
+ // service. However, it is unclear if we should rely on it.
+ if (this.master_enabled) this.launch_break_timer_service ();
+ });
+ }
+
+ public signal void break_status_available ();
+ public signal void break_added (BreakType break_type);
+ public signal void status_changed ();
+
+ public void load_breaks () {
+ this.add_break (new MicroBreakType ());
+ this.add_break (new RestBreakType ());
+
+ this.status_changed ();
+
+ Bus.watch_name (BusType.SESSION, Config.HELPER_BUS_NAME, BusNameWatcherFlags.NONE,
+ this.break_helper_appeared, this.break_helper_disappeared);
+ }
+
+ public Gee.Set<string> all_break_ids () {
+ return this.breaks.keys;
+ }
+
+ public unowned GLib.List<BreakType> all_breaks () {
+ return this.breaks_ordered;
+ }
+
+ /**
+ * @returns true if the break helper is working correctly.
+ */
+ public bool is_working () {
+ return (this.master_enabled == false || this.breaks.size == 0 || this.break_helper != null);
+ }
+
+ public BreakType? get_break_type_for_name (string name) {
+ return this.breaks.get (name);
+ }
+
+ private void add_break (BreakType break_type) {
+ break_type.initialize ();
+ this.breaks.set (break_type.id, break_type);
+ this.breaks_ordered.append (break_type);
+ break_type.status_changed.connect (this.break_status_changed);
+ this.break_added (break_type);
+ }
+
+ private void break_status_changed (BreakType break_type, BreakStatus? break_status) {
+ BreakType? new_foreground_break = this.foreground_break;
+
+ if (break_status != null && break_status.is_focused && break_status.is_active) {
+ new_foreground_break = break_type;
+ } else if (this.foreground_break == break_type) {
+ new_foreground_break = null;
+ }
+
+ if (this.foreground_break != new_foreground_break) {
+ this.foreground_break = new_foreground_break;
+ }
+
+ this.status_changed ();
+ }
+
+ private void break_helper_appeared () {
+ try {
+ this.break_helper = Bus.get_proxy_sync (
+ BusType.SESSION,
+ Config.HELPER_BUS_NAME,
+ Config.HELPER_OBJECT_PATH,
+ DBusProxyFlags.DO_NOT_AUTO_START
+ );
+ this.break_status_available ();
+ } catch (IOError error) {
+ this.break_helper = null;
+ GLib.warning ("Error connecting to break helper service: %s", error.message);
+ }
+ }
+
+ private void break_helper_disappeared () {
+ if (this.break_helper == null && this.master_enabled) {
+ // Try to start break_helper automatically if it should be
+ // running. Only do this once, if it was not running previously.
+ this.launch_break_timer_service ();
+ }
+
+ this.break_helper = null;
+
+ this.status_changed ();
+ }
+
+ private void launch_break_timer_service () {
+ // TODO: Use dbus activation once we can depend on GLib >= 2.37
+ AppInfo helper_app_info = new DesktopAppInfo (Config.HELPER_DESKTOP_ID);
+ AppLaunchContext app_launch_context = new AppLaunchContext ();
+ try {
+ helper_app_info.launch (null, app_launch_context);
+ } catch (Error error) {
+ GLib.warning ("Error launching helper application: %s", error.message);
+ }
+ }
}
}
diff --git a/settings/BreakSettingsDialog.vala b/settings/BreakSettingsDialog.vala
index c84eb30..ec8c51a 100644
--- a/settings/BreakSettingsDialog.vala
+++ b/settings/BreakSettingsDialog.vala
@@ -21,205 +21,205 @@ using GLib;
namespace BreakTimer.Settings {
public class BreakSettingsDialog : Gtk.Dialog {
- private BreakManager break_manager;
-
- private BreakConfigurationChooser configuration_chooser;
- private Gtk.Grid breaks_grid;
-
- private const int ABOUT_BUTTON_RESPONSE = 5;
-
- public BreakSettingsDialog (BreakManager break_manager) {
- Object (use_header_bar: 1);
- this.break_manager = break_manager;
-
- GLib.Settings settings = new GLib.Settings ("org.gnome.BreakTimer");
-
- this.set_title ( _("Choose Your Break Schedule"));
- this.set_resizable (false);
-
- this.delete_event.connect (this.hide_on_delete);
-
- this.add_button (_("_Close"), Gtk.ResponseType.CLOSE);
- this.response.connect (this.response_cb);
-
- Gtk.Container content_area = (Gtk.Container)this.get_content_area ();
-
- Gtk.Grid content = new Gtk.Grid ();
- content_area.add (content);
- content.set_orientation (Gtk.Orientation.VERTICAL);
- content.set_margin_top (10);
- content.set_margin_right (10);
- content.set_margin_bottom (10);
- content.set_margin_left (10);
-
- this.configuration_chooser = new BreakConfigurationChooser ();
- content.add (this.configuration_chooser);
- this.configuration_chooser.add_configuration (
- { "microbreak", "restbreak" },
- _("A mix of short breaks and long breaks")
- );
- this.configuration_chooser.add_configuration (
- { "restbreak" },
- _("Occasional long breaks")
- );
- this.configuration_chooser.add_configuration (
- { "microbreak" },
- _("Frequent short breaks")
- );
- settings.bind ("selected-breaks", this.configuration_chooser, "selected-break-ids",
SettingsBindFlags.DEFAULT);
-
- this.breaks_grid = new FixedSizeGrid ();
- content.add (this.breaks_grid);
- this.breaks_grid.set_orientation (Gtk.Orientation.VERTICAL);
-
- content.show_all ();
-
- break_manager.break_added.connect (this.break_added_cb);
- this.configuration_chooser.notify["selected-break-ids"].connect
(this.update_break_configuration);
- }
-
- private void update_break_configuration () {
- foreach (BreakType break_type in this.break_manager.all_breaks ()) {
- if (break_type.id in this.configuration_chooser.selected_break_ids) {
- break_type.settings_panel.show ();
- } else {
- break_type.settings_panel.hide ();
- }
- }
- }
-
- private void break_added_cb (BreakType break_type) {
- var settings_panel = break_type.settings_panel;
- breaks_grid.add (settings_panel);
- settings_panel.realize ();
- settings_panel.set_valign (Gtk.Align.CENTER);
- settings_panel.set_vexpand (true);
- settings_panel.set_margin_top (10);
- settings_panel.set_margin_bottom (10);
- this.update_break_configuration ();
- }
-
- private void response_cb (int response_id) {
- if (response_id == Gtk.ResponseType.CLOSE) {
- this.hide ();
- }
- }
+ private BreakManager break_manager;
+
+ private BreakConfigurationChooser configuration_chooser;
+ private Gtk.Grid breaks_grid;
+
+ private const int ABOUT_BUTTON_RESPONSE = 5;
+
+ public BreakSettingsDialog (BreakManager break_manager) {
+ Object (use_header_bar: 1);
+ this.break_manager = break_manager;
+
+ GLib.Settings settings = new GLib.Settings ("org.gnome.BreakTimer");
+
+ this.set_title ( _("Choose Your Break Schedule"));
+ this.set_resizable (false);
+
+ this.delete_event.connect (this.hide_on_delete);
+
+ this.add_button (_("_Close"), Gtk.ResponseType.CLOSE);
+ this.response.connect (this.response_cb);
+
+ Gtk.Container content_area = (Gtk.Container)this.get_content_area ();
+
+ Gtk.Grid content = new Gtk.Grid ();
+ content_area.add (content);
+ content.set_orientation (Gtk.Orientation.VERTICAL);
+ content.set_margin_top (10);
+ content.set_margin_right (10);
+ content.set_margin_bottom (10);
+ content.set_margin_left (10);
+
+ this.configuration_chooser = new BreakConfigurationChooser ();
+ content.add (this.configuration_chooser);
+ this.configuration_chooser.add_configuration (
+ { "microbreak", "restbreak" },
+ _("A mix of short breaks and long breaks")
+ );
+ this.configuration_chooser.add_configuration (
+ { "restbreak" },
+ _("Occasional long breaks")
+ );
+ this.configuration_chooser.add_configuration (
+ { "microbreak" },
+ _("Frequent short breaks")
+ );
+ settings.bind ("selected-breaks", this.configuration_chooser, "selected-break-ids",
SettingsBindFlags.DEFAULT);
+
+ this.breaks_grid = new FixedSizeGrid ();
+ content.add (this.breaks_grid);
+ this.breaks_grid.set_orientation (Gtk.Orientation.VERTICAL);
+
+ content.show_all ();
+
+ break_manager.break_added.connect (this.break_added_cb);
+ this.configuration_chooser.notify["selected-break-ids"].connect (this.update_break_configuration);
+ }
+
+ private void update_break_configuration () {
+ foreach (BreakType break_type in this.break_manager.all_breaks ()) {
+ if (break_type.id in this.configuration_chooser.selected_break_ids) {
+ break_type.settings_panel.show ();
+ } else {
+ break_type.settings_panel.hide ();
+ }
+ }
+ }
+
+ private void break_added_cb (BreakType break_type) {
+ var settings_panel = break_type.settings_panel;
+ breaks_grid.add (settings_panel);
+ settings_panel.realize ();
+ settings_panel.set_valign (Gtk.Align.CENTER);
+ settings_panel.set_vexpand (true);
+ settings_panel.set_margin_top (10);
+ settings_panel.set_margin_bottom (10);
+ this.update_break_configuration ();
+ }
+
+ private void response_cb (int response_id) {
+ if (response_id == Gtk.ResponseType.CLOSE) {
+ this.hide ();
+ }
+ }
}
class BreakConfigurationChooser : Gtk.ComboBox {
- public class Configuration : Object {
- public Gtk.TreeIter iter;
- public string[] break_ids;
- public string label;
-
- public Configuration (string[] break_ids, string label) {
- this.break_ids = break_ids;
- this.label = label;
- }
-
- public bool matches_breaks (string[] test_break_ids) {
- if (test_break_ids.length == this.break_ids.length) {
- foreach (string test_break_id in test_break_ids) {
- if (! (test_break_id in this.break_ids)) return false;
- }
- return true;
- } else {
- return false;
- }
- }
- }
-
- private Gtk.ListStore list_store;
- private List<Configuration> configurations;
-
- public string[] selected_break_ids { public get; public set; }
-
- public BreakConfigurationChooser () {
- Object ();
- this.configurations = new List<Configuration> ();
-
- this.list_store = new Gtk.ListStore (2, typeof (Configuration), typeof (string));
- this.set_model (this.list_store);
-
- var label_renderer = new Gtk.CellRendererText ();
- this.pack_start (label_renderer, true);
- this.add_attribute (label_renderer, "text", 1);
-
- this.notify["active"].connect (this.send_selected_break);
- this.notify["selected-break-ids"].connect (this.receive_selected_break);
- }
-
- public void add_configuration (string[] break_ids, string label) {
- var configuration = new Configuration (break_ids, label);
- this.configurations.append (configuration);
- Gtk.TreeIter iter;
- this.list_store.append (out iter);
- this.list_store.set (iter, 0, configuration, 1, configuration.label);
- configuration.iter = iter;
- }
-
- private void send_selected_break () {
- Gtk.TreeIter iter;
- if (this.get_active_iter (out iter)) {
- Value value;
- this.list_store.get_value (iter, 0, out value);
- Configuration configuration = (Configuration)value;
- this.selected_break_ids = configuration.break_ids;
- }
- }
-
- private void receive_selected_break () {
- var configuration = this.get_configuration_for_break_ids (this.selected_break_ids);
- if (configuration != null) {
- this.set_active_iter (configuration.iter);
- } else {
- this.set_active (-1);
- }
- }
-
- private Configuration? get_configuration_for_break_ids (string[] selected_breaks) {
- foreach (Configuration configuration in this.configurations) {
- if (configuration.matches_breaks (selected_breaks)) {
- return configuration;
- }
- }
- return null;
- }
+ public class Configuration : Object {
+ public Gtk.TreeIter iter;
+ public string[] break_ids;
+ public string label;
+
+ public Configuration (string[] break_ids, string label) {
+ this.break_ids = break_ids;
+ this.label = label;
+ }
+
+ public bool matches_breaks (string[] test_break_ids) {
+ if (test_break_ids.length == this.break_ids.length) {
+ foreach (string test_break_id in test_break_ids) {
+ if (! (test_break_id in this.break_ids)) return false;
+ }
+ return true;
+ } else {
+ return false;
+ }
+ }
+ }
+
+ private Gtk.ListStore list_store;
+ private List<Configuration> configurations;
+
+ public string[] selected_break_ids { public get; public set; }
+
+ public BreakConfigurationChooser () {
+ Object ();
+ this.configurations = new List<Configuration> ();
+
+ this.list_store = new Gtk.ListStore (2, typeof (Configuration), typeof (string));
+ this.set_model (this.list_store);
+
+ var label_renderer = new Gtk.CellRendererText ();
+ this.pack_start (label_renderer, true);
+ this.add_attribute (label_renderer, "text", 1);
+
+ this.notify["active"].connect (this.send_selected_break);
+ this.notify["selected-break-ids"].connect (this.receive_selected_break);
+ }
+
+ public void add_configuration (string[] break_ids, string label) {
+ var configuration = new Configuration (break_ids, label);
+ this.configurations.append (configuration);
+ Gtk.TreeIter iter;
+ this.list_store.append (out iter);
+ this.list_store.set (iter, 0, configuration, 1, configuration.label);
+ configuration.iter = iter;
+ }
+
+ private void send_selected_break () {
+ Gtk.TreeIter iter;
+ if (this.get_active_iter (out iter)) {
+ Value value;
+ this.list_store.get_value (iter, 0, out value);
+ Configuration configuration = (Configuration)value;
+ this.selected_break_ids = configuration.break_ids;
+ }
+ }
+
+ private void receive_selected_break () {
+ var configuration = this.get_configuration_for_break_ids (this.selected_break_ids);
+ if (configuration != null) {
+ this.set_active_iter (configuration.iter);
+ } else {
+ this.set_active (-1);
+ }
+ }
+
+ private Configuration? get_configuration_for_break_ids (string[] selected_breaks) {
+ foreach (Configuration configuration in this.configurations) {
+ if (configuration.matches_breaks (selected_breaks)) {
+ return configuration;
+ }
+ }
+ return null;
+ }
}
class FixedSizeGrid : Gtk.Grid {
- public FixedSizeGrid () {
- Object ();
- }
-
- public override void adjust_size_request (Gtk.Orientation orientation, ref int minimum_size, ref int
natural_size) {
- foreach (Gtk.Widget widget in this.get_hidden_children ()) {
- int widget_allocated_size = 0;
-
- if (orientation == Gtk.Orientation.VERTICAL && this.orientation ==
Gtk.Orientation.VERTICAL) {
- widget_allocated_size = widget.get_allocated_height ();
- } else if (orientation == Gtk.Orientation.HORIZONTAL && this.orientation ==
Gtk.Orientation.HORIZONTAL) {
- widget_allocated_size = widget.get_allocated_width ();
- }
-
- minimum_size += widget_allocated_size;
- natural_size += widget_allocated_size;
-
- widget.adjust_size_request (orientation, ref minimum_size, ref natural_size);
- }
-
- base.adjust_size_request (orientation, ref minimum_size, ref natural_size);
- }
-
- private List<weak Gtk.Widget> get_hidden_children () {
- var hidden_children = new List<weak Gtk.Widget> ();
- foreach (Gtk.Widget widget in this.get_children ()) {
- if (! widget.is_visible ()) hidden_children.append (widget);
- }
- return hidden_children;
- }
+ public FixedSizeGrid () {
+ Object ();
+ }
+
+ public override void adjust_size_request (Gtk.Orientation orientation, ref int minimum_size, ref int
natural_size) {
+ foreach (Gtk.Widget widget in this.get_hidden_children ()) {
+ int widget_allocated_size = 0;
+
+ if (orientation == Gtk.Orientation.VERTICAL && this.orientation == Gtk.Orientation.VERTICAL) {
+ widget_allocated_size = widget.get_allocated_height ();
+ } else if (orientation == Gtk.Orientation.HORIZONTAL && this.orientation ==
Gtk.Orientation.HORIZONTAL) {
+ widget_allocated_size = widget.get_allocated_width ();
+ }
+
+ minimum_size += widget_allocated_size;
+ natural_size += widget_allocated_size;
+
+ widget.adjust_size_request (orientation, ref minimum_size, ref natural_size);
+ }
+
+ base.adjust_size_request (orientation, ref minimum_size, ref natural_size);
+ }
+
+ private List<weak Gtk.Widget> get_hidden_children () {
+ var hidden_children = new List<weak Gtk.Widget> ();
+ foreach (Gtk.Widget widget in this.get_children ()) {
+ if (! widget.is_visible ()) hidden_children.append (widget);
+ }
+ return hidden_children;
+ }
}
}
diff --git a/settings/BreakType.vala b/settings/BreakType.vala
index de255c9..894d6b4 100644
--- a/settings/BreakType.vala
+++ b/settings/BreakType.vala
@@ -21,153 +21,153 @@ using GLib;
namespace BreakTimer.Settings {
public abstract class BreakType : Object {
- public string id { get; private set; }
- public BreakStatus? status;
-
- public BreakInfoPanel info_panel;
- public BreakStatusPanel status_panel;
- public BreakSettingsPanel settings_panel;
-
- public GLib.Settings settings;
-
- public BreakType (string id, GLib.Settings settings) {
- this.id = id;
- this.settings = settings;
- }
-
- public signal void status_changed (BreakStatus? status);
-
- public virtual void initialize () {
- this.info_panel = this.get_info_panel ();
- this.status_panel = this.get_status_panel ();
- this.settings_panel = this.get_settings_panel ();
- }
-
- protected void update_status (BreakStatus? status) {
- this.status = status;
- this.status_changed (status);
- }
-
- protected abstract BreakInfoPanel get_info_panel ();
- protected abstract BreakStatusPanel get_status_panel ();
- protected abstract BreakSettingsPanel get_settings_panel ();
+ public string id { get; private set; }
+ public BreakStatus? status;
+
+ public BreakInfoPanel info_panel;
+ public BreakStatusPanel status_panel;
+ public BreakSettingsPanel settings_panel;
+
+ public GLib.Settings settings;
+
+ public BreakType (string id, GLib.Settings settings) {
+ this.id = id;
+ this.settings = settings;
+ }
+
+ public signal void status_changed (BreakStatus? status);
+
+ public virtual void initialize () {
+ this.info_panel = this.get_info_panel ();
+ this.status_panel = this.get_status_panel ();
+ this.settings_panel = this.get_settings_panel ();
+ }
+
+ protected void update_status (BreakStatus? status) {
+ this.status = status;
+ this.status_changed (status);
+ }
+
+ protected abstract BreakInfoPanel get_info_panel ();
+ protected abstract BreakStatusPanel get_status_panel ();
+ protected abstract BreakSettingsPanel get_settings_panel ();
}
public abstract class BreakInfoPanel : Gtk.Grid {
- public BreakType break_type { public get; private set; }
- public string title { public get; private set; }
-
- private Gtk.Label heading_label;
- private Gtk.Label description_label;
- private Gtk.Label detail_label;
-
- public BreakInfoPanel (BreakType break_type, string title) {
- Object ();
- this.break_type = break_type;
- this.title = title;
-
- this.set_orientation (Gtk.Orientation.VERTICAL);
- this.set_hexpand (true);
- this.set_row_spacing (24);
- this.get_style_context ().add_class ("_break-info");
-
- this.heading_label = new Gtk.Label (null);
- this.add (this.heading_label);
- this.heading_label.get_style_context ().add_class ("_break-info-heading");
-
- this.description_label = new Gtk.Label (null);
- this.add (this.description_label);
- this.description_label.set_line_wrap (true);
- this.description_label.set_justify (Gtk.Justification.CENTER);
- this.description_label.set_max_width_chars (60);
-
- this.detail_label = new Gtk.Label (null);
- this.add (this.detail_label);
-
- this.show_all ();
- }
-
- protected void set_heading (string heading) {
- this.heading_label.set_label (heading);
- }
-
- protected void set_description (string description) {
- this.description_label.set_label (description);
- }
-
- protected void set_detail (string detail) {
- this.detail_label.set_label (detail);
- }
+ public BreakType break_type { public get; private set; }
+ public string title { public get; private set; }
+
+ private Gtk.Label heading_label;
+ private Gtk.Label description_label;
+ private Gtk.Label detail_label;
+
+ public BreakInfoPanel (BreakType break_type, string title) {
+ Object ();
+ this.break_type = break_type;
+ this.title = title;
+
+ this.set_orientation (Gtk.Orientation.VERTICAL);
+ this.set_hexpand (true);
+ this.set_row_spacing (24);
+ this.get_style_context ().add_class ("_break-info");
+
+ this.heading_label = new Gtk.Label (null);
+ this.add (this.heading_label);
+ this.heading_label.get_style_context ().add_class ("_break-info-heading");
+
+ this.description_label = new Gtk.Label (null);
+ this.add (this.description_label);
+ this.description_label.set_line_wrap (true);
+ this.description_label.set_justify (Gtk.Justification.CENTER);
+ this.description_label.set_max_width_chars (60);
+
+ this.detail_label = new Gtk.Label (null);
+ this.add (this.detail_label);
+
+ this.show_all ();
+ }
+
+ protected void set_heading (string heading) {
+ this.heading_label.set_label (heading);
+ }
+
+ protected void set_description (string description) {
+ this.description_label.set_label (description);
+ }
+
+ protected void set_detail (string detail) {
+ this.detail_label.set_label (detail);
+ }
}
public abstract class BreakStatusPanel : Gtk.Grid {
- public BreakType break_type { public get; private set; }
- public bool is_enabled { get; set; default=false; }
+ public BreakType break_type { public get; private set; }
+ public bool is_enabled { get; set; default=false; }
- public BreakStatusPanel (BreakType break_type) {
- Object ();
- this.break_type = break_type;
+ public BreakStatusPanel (BreakType break_type) {
+ Object ();
+ this.break_type = break_type;
- this.get_style_context ().add_class ("_break-status");
- }
+ this.get_style_context ().add_class ("_break-status");
+ }
}
public abstract class BreakSettingsPanel : Gtk.Grid {
- private Gtk.Grid header;
- private Gtk.Grid details;
-
- public BreakSettingsPanel (BreakType break_type, string title, string? description) {
- Object ();
-
- this.set_orientation (Gtk.Orientation.VERTICAL);
- this.set_row_spacing (10);
-
- this.header = new Gtk.Grid ();
- this.add (this.header);
- this.header.set_column_spacing (12);
-
- var title_grid = new Gtk.Grid ();
- this.set_header (title_grid);
- title_grid.set_orientation (Gtk.Orientation.VERTICAL);
- title_grid.set_row_spacing (4);
-
- var title_label = new Gtk.Label (title);
- title_grid.add (title_label);
- title_label.get_style_context ().add_class ("_settings-title");
- title_label.set_halign (Gtk.Align.FILL);
- title_label.set_hexpand (true);
- title_label.set_justify (Gtk.Justification.CENTER);
-
- // var description_label = new Gtk.Label ("<small>%s</small>".printf (description));
- // title_grid.add (description_label);
- // description_label.get_style_context ().add_class ("_settings-description");
- // description_label.set_use_markup (true);
- // description_label.set_halign (Gtk.Align.FILL);
- // description_label.set_hexpand (true);
- // description_label.set_justify (Gtk.Justification.CENTER);
-
- this.details = new Gtk.Grid ();
- this.add (this.details);
- this.details.set_margin_left (12);
- this.details.set_halign (Gtk.Align.CENTER);
- this.details.set_hexpand (true);
-
- this.show_all ();
- }
-
- protected void set_header (Gtk.Widget content) {
- this.header.attach (content, 0, 0, 1, 1);
- }
-
- protected void set_header_action (Gtk.Widget content) {
- this.header.attach (content, 1, 0, 1, 1);
- content.set_halign (Gtk.Align.END);
- content.set_valign (Gtk.Align.CENTER);
- }
-
- protected void set_details (Gtk.Widget content) {
- this.details.add (content);
- }
+ private Gtk.Grid header;
+ private Gtk.Grid details;
+
+ public BreakSettingsPanel (BreakType break_type, string title, string? description) {
+ Object ();
+
+ this.set_orientation (Gtk.Orientation.VERTICAL);
+ this.set_row_spacing (10);
+
+ this.header = new Gtk.Grid ();
+ this.add (this.header);
+ this.header.set_column_spacing (12);
+
+ var title_grid = new Gtk.Grid ();
+ this.set_header (title_grid);
+ title_grid.set_orientation (Gtk.Orientation.VERTICAL);
+ title_grid.set_row_spacing (4);
+
+ var title_label = new Gtk.Label (title);
+ title_grid.add (title_label);
+ title_label.get_style_context ().add_class ("_settings-title");
+ title_label.set_halign (Gtk.Align.FILL);
+ title_label.set_hexpand (true);
+ title_label.set_justify (Gtk.Justification.CENTER);
+
+ // var description_label = new Gtk.Label ("<small>%s</small>".printf (description));
+ // title_grid.add (description_label);
+ // description_label.get_style_context ().add_class ("_settings-description");
+ // description_label.set_use_markup (true);
+ // description_label.set_halign (Gtk.Align.FILL);
+ // description_label.set_hexpand (true);
+ // description_label.set_justify (Gtk.Justification.CENTER);
+
+ this.details = new Gtk.Grid ();
+ this.add (this.details);
+ this.details.set_margin_left (12);
+ this.details.set_halign (Gtk.Align.CENTER);
+ this.details.set_hexpand (true);
+
+ this.show_all ();
+ }
+
+ protected void set_header (Gtk.Widget content) {
+ this.header.attach (content, 0, 0, 1, 1);
+ }
+
+ protected void set_header_action (Gtk.Widget content) {
+ this.header.attach (content, 1, 0, 1, 1);
+ content.set_halign (Gtk.Align.END);
+ content.set_valign (Gtk.Align.CENTER);
+ }
+
+ protected void set_details (Gtk.Widget content) {
+ this.details.add (content);
+ }
}
}
diff --git a/settings/CircleCounter.vala b/settings/CircleCounter.vala
index 016e219..6939eba 100644
--- a/settings/CircleCounter.vala
+++ b/settings/CircleCounter.vala
@@ -26,104 +26,104 @@ namespace BreakTimer.Settings {
* direction at any time.
*/
public class CircleCounter : Gtk.Widget {
- protected const double LINE_WIDTH = 5.0;
- protected const int DEFAULT_RADIUS = 48;
-
- private const double SNAP_INCREMENT = (Math.PI * 2) / 60.0;
-
- public enum Direction {
- COUNT_DOWN,
- COUNT_UP
- }
-
- /**
- * The direction of the countdown.
- * COUNT_DOWN: a full circle that disappears as progress increases
- * COUNT_UP: a circle gradually appears as progress increases
- */
- public Direction direction {get; set;}
- /**
- * A value from 0.0 to 1.0, where 1.0 means the count is finished. The
- * circle will be filled by this amount according to the direction
- * property.
- */
- public double progress {get; set;}
-
- public CircleCounter () {
- Object ();
- this.set_has_window (false);
-
- this.get_style_context ().add_class ("_circle-counter");
-
- this.notify["progress"].connect((s, p) => {
- this.queue_draw ();
- });
- }
-
- public override bool draw (Cairo.Context cr) {
- Gtk.StyleContext style_context = this.get_style_context ();
- Gtk.StateFlags state = this.get_state_flags ();
- Gtk.Allocation allocation;
- this.get_allocation (out allocation);
-
- int center_x = allocation.width / 2;
- int center_y = allocation.height / 2;
- int radius = int.min(center_x, center_y);
- double arc_radius = radius - LINE_WIDTH / 2;
-
- Gdk.RGBA trough_color = style_context.get_background_color (state);
- Gdk.RGBA base_color = style_context.get_color (state);
-
- Gdk.cairo_set_source_rgba (cr, trough_color);
- cr.arc (center_x, center_y, arc_radius, 0, Math.PI * 2.0);
- cr.set_line_width (LINE_WIDTH);
- cr.stroke ();
-
- double start_angle = 1.5 * Math.PI;
- double progress_angle = this.progress * Math.PI * 2.0;
- progress_angle = (int)(progress_angle / SNAP_INCREMENT) * SNAP_INCREMENT;
-
- if (this.direction == Direction.COUNT_DOWN) {
- if (progress_angle > 0) {
- cr.arc (center_x, center_y, arc_radius, start_angle, start_angle -
progress_angle);
- } else {
- // No progress: Draw a full circle (to be gradually emptied)
- cr.arc (center_x, center_y, arc_radius, start_angle, start_angle + Math.PI *
2.0);
- }
- } else {
- if (progress_angle > 0) {
- cr.arc_negative (center_x, center_y, arc_radius, start_angle, start_angle -
progress_angle);
- }
- // No progress: Draw nothing (arc will gradually appear)
- }
-
- Gdk.cairo_set_source_rgba (cr, base_color);
- cr.set_line_width (LINE_WIDTH);
- cr.set_line_cap (Cairo.LineCap.ROUND);
- cr.stroke ();
-
- return true;
- }
-
- public override void get_preferred_width (out int minimum_width, out int natural_width) {
- var diameter = calculate_diameter ();
- minimum_width = diameter;
- natural_width = diameter;
- }
-
- public override void get_preferred_height (out int minimum_height, out int natural_height) {
- var diameter = calculate_diameter ();
- minimum_height = diameter;
- natural_height = diameter;
- }
-
- public override void size_allocate (Gtk.Allocation allocation) {
- base.size_allocate (allocation);
- }
-
- private int calculate_diameter () {
- return 2 * DEFAULT_RADIUS;
- }
+ protected const double LINE_WIDTH = 5.0;
+ protected const int DEFAULT_RADIUS = 48;
+
+ private const double SNAP_INCREMENT = (Math.PI * 2) / 60.0;
+
+ public enum Direction {
+ COUNT_DOWN,
+ COUNT_UP
+ }
+
+ /**
+ * The direction of the countdown.
+ * COUNT_DOWN: a full circle that disappears as progress increases
+ * COUNT_UP: a circle gradually appears as progress increases
+ */
+ public Direction direction {get; set;}
+ /**
+ * A value from 0.0 to 1.0, where 1.0 means the count is finished. The
+ * circle will be filled by this amount according to the direction
+ * property.
+ */
+ public double progress {get; set;}
+
+ public CircleCounter () {
+ Object ();
+ this.set_has_window (false);
+
+ this.get_style_context ().add_class ("_circle-counter");
+
+ this.notify["progress"].connect((s, p) => {
+ this.queue_draw ();
+ });
+ }
+
+ public override bool draw (Cairo.Context cr) {
+ Gtk.StyleContext style_context = this.get_style_context ();
+ Gtk.StateFlags state = this.get_state_flags ();
+ Gtk.Allocation allocation;
+ this.get_allocation (out allocation);
+
+ int center_x = allocation.width / 2;
+ int center_y = allocation.height / 2;
+ int radius = int.min(center_x, center_y);
+ double arc_radius = radius - LINE_WIDTH / 2;
+
+ Gdk.RGBA trough_color = style_context.get_background_color (state);
+ Gdk.RGBA base_color = style_context.get_color (state);
+
+ Gdk.cairo_set_source_rgba (cr, trough_color);
+ cr.arc (center_x, center_y, arc_radius, 0, Math.PI * 2.0);
+ cr.set_line_width (LINE_WIDTH);
+ cr.stroke ();
+
+ double start_angle = 1.5 * Math.PI;
+ double progress_angle = this.progress * Math.PI * 2.0;
+ progress_angle = (int)(progress_angle / SNAP_INCREMENT) * SNAP_INCREMENT;
+
+ if (this.direction == Direction.COUNT_DOWN) {
+ if (progress_angle > 0) {
+ cr.arc (center_x, center_y, arc_radius, start_angle, start_angle - progress_angle);
+ } else {
+ // No progress: Draw a full circle (to be gradually emptied)
+ cr.arc (center_x, center_y, arc_radius, start_angle, start_angle + Math.PI * 2.0);
+ }
+ } else {
+ if (progress_angle > 0) {
+ cr.arc_negative (center_x, center_y, arc_radius, start_angle, start_angle - progress_angle);
+ }
+ // No progress: Draw nothing (arc will gradually appear)
+ }
+
+ Gdk.cairo_set_source_rgba (cr, base_color);
+ cr.set_line_width (LINE_WIDTH);
+ cr.set_line_cap (Cairo.LineCap.ROUND);
+ cr.stroke ();
+
+ return true;
+ }
+
+ public override void get_preferred_width (out int minimum_width, out int natural_width) {
+ var diameter = calculate_diameter ();
+ minimum_width = diameter;
+ natural_width = diameter;
+ }
+
+ public override void get_preferred_height (out int minimum_height, out int natural_height) {
+ var diameter = calculate_diameter ();
+ minimum_height = diameter;
+ natural_height = diameter;
+ }
+
+ public override void size_allocate (Gtk.Allocation allocation) {
+ base.size_allocate (allocation);
+ }
+
+ private int calculate_diameter () {
+ return 2 * DEFAULT_RADIUS;
+ }
}
}
diff --git a/settings/MainWindow.vala b/settings/MainWindow.vala
index 30c247d..862ebfa 100644
--- a/settings/MainWindow.vala
+++ b/settings/MainWindow.vala
@@ -21,346 +21,346 @@ using GLib;
namespace BreakTimer.Settings {
public class MainWindow : Gtk.ApplicationWindow {
- private BreakManager break_manager;
-
- private Gtk.HeaderBar header;
- private Gtk.Stack main_stack;
-
- private Gtk.Button settings_button;
- private Gtk.Switch master_switch;
-
- private BreakSettingsDialog break_settings_dialog;
-
- private WelcomePanel welcome_panel;
- private StatusPanel status_panel;
-
- public MainWindow (SettingsApplication application, BreakManager break_manager) {
- Object (application: application);
- this.break_manager = break_manager;
-
- this.set_title ( _("Break Timer"));
-
- Gtk.Builder builder = new Gtk.Builder ();
- try {
- builder.add_from_resource ("/org/gnome/BreakTimer/settings/settings-panels.ui");
- } catch (Error e) {
- GLib.error ("Error loading UI: %s", e.message);
- }
-
- this.break_settings_dialog = new BreakSettingsDialog (break_manager);
- this.break_settings_dialog.set_modal (true);
- this.break_settings_dialog.set_transient_for (this);
-
- Gtk.Grid content = new Gtk.Grid ();
- this.add (content);
- content.set_orientation (Gtk.Orientation.VERTICAL);
- content.set_vexpand (true);
-
- this.header = new Gtk.HeaderBar ();
- this.set_titlebar (this.header);
- this.header.set_show_close_button (true);
- this.header.set_hexpand (true);
-
- this.master_switch = new Gtk.Switch ();
- header.pack_start (this.master_switch);
- master_switch.set_valign (Gtk.Align.CENTER);
- break_manager.bind_property ("master-enabled", this.master_switch, "active",
BindingFlags.BIDIRECTIONAL | BindingFlags.SYNC_CREATE);
-
- this.settings_button = new Gtk.Button ();
- header.pack_end (this.settings_button);
- settings_button.clicked.connect (this.settings_clicked_cb);
- // FIXME: This icon is not semantically correct. (Wrong category, especially).
- settings_button.set_image (new Gtk.Image.from_icon_name (
- "preferences-system-symbolic",
- Gtk.IconSize.MENU)
- );
- settings_button.valign = Gtk.Align.CENTER;
- settings_button.set_always_show_image (true);
-
- this.main_stack = new Gtk.Stack ();
- content.add (this.main_stack);
- main_stack.set_margin_top (6);
- main_stack.set_margin_bottom (6);
- main_stack.set_transition_duration (250);
-
- this.status_panel = new StatusPanel (break_manager, builder);
- this.main_stack.add_named (this.status_panel, "status_panel");
-
- this.welcome_panel = new WelcomePanel (break_manager, builder, this);
- this.main_stack.add_named (this.welcome_panel, "welcome_panel");
- this.welcome_panel.tour_finished.connect (this.on_tour_finished);
-
- this.header.show_all ();
- content.show_all ();
-
- break_manager.break_added.connect (this.break_added_cb);
- break_manager.notify["foreground-break"].connect (this.update_visible_panel);
- this.update_visible_panel ();
- }
-
- public Gtk.Widget get_master_switch () {
- return this.master_switch;
- }
-
- public Gtk.Widget get_settings_button () {
- return this.settings_button;
- }
-
- public Gtk.Widget? get_close_button () {
- // TODO: We need some way to get the close button position from this.header
- return null;
- }
-
- private void break_added_cb (BreakType break_type) {
- var info_panel = break_type.info_panel;
- this.main_stack.add_named (info_panel, break_type.id);
- info_panel.set_margin_left (20);
- info_panel.set_margin_right (20);
- info_panel.set_halign (Gtk.Align.CENTER);
- info_panel.set_valign (Gtk.Align.CENTER);
- }
-
- private void update_visible_panel () {
- // Use a transition when switching from the welcome panel
- Gtk.StackTransitionType transition;
- if (this.main_stack.get_visible_child () == this.welcome_panel) {
- transition = Gtk.StackTransitionType.SLIDE_LEFT;
- } else {
- transition = Gtk.StackTransitionType.NONE;
- }
-
- BreakType? foreground_break = this.break_manager.foreground_break;
- if (this.welcome_panel.is_active ()) {
- this.main_stack.set_visible_child_full ("welcome_panel", transition);
- this.header.set_title ( _("Welcome Tour"));
- } else if (foreground_break != null) {
- this.main_stack.set_visible_child_full (foreground_break.id, transition);
- this.header.set_title (foreground_break.info_panel.title);
- } else {
- this.main_stack.set_visible_child_full ("status_panel", transition);
- this.header.set_title ( _("Break Timer"));
- }
- }
-
- private void on_tour_finished () {
- this.update_visible_panel ();
- }
-
- public void show_about_dialog () {
- const string copyright = "Copyright © 2011-2013 Dylan McCall";
-
- Gtk.show_about_dialog (this,
- "program-name", _("GNOME Break Timer"),
- "logo-icon-name", "org.gnome.BreakTimer",
- "version", Config.VERSION,
- "comments", _("Computer break reminders for active minds"),
- "website", Config.PACKAGE_URL,
- "website-label", _("GNOME Break Timer Website"),
- "copyright", copyright,
- "license-type", Gtk.License.GPL_3_0,
- "wrap-license", false,
- "translator-credits", _("translator-credits")
- );
- }
-
- private void settings_clicked_cb () {
- this.break_settings_dialog.show ();
- this.welcome_panel.settings_button_clicked ();
- }
+ private BreakManager break_manager;
+
+ private Gtk.HeaderBar header;
+ private Gtk.Stack main_stack;
+
+ private Gtk.Button settings_button;
+ private Gtk.Switch master_switch;
+
+ private BreakSettingsDialog break_settings_dialog;
+
+ private WelcomePanel welcome_panel;
+ private StatusPanel status_panel;
+
+ public MainWindow (SettingsApplication application, BreakManager break_manager) {
+ Object (application: application);
+ this.break_manager = break_manager;
+
+ this.set_title ( _("Break Timer"));
+
+ Gtk.Builder builder = new Gtk.Builder ();
+ try {
+ builder.add_from_resource ("/org/gnome/BreakTimer/settings/settings-panels.ui");
+ } catch (Error e) {
+ GLib.error ("Error loading UI: %s", e.message);
+ }
+
+ this.break_settings_dialog = new BreakSettingsDialog (break_manager);
+ this.break_settings_dialog.set_modal (true);
+ this.break_settings_dialog.set_transient_for (this);
+
+ Gtk.Grid content = new Gtk.Grid ();
+ this.add (content);
+ content.set_orientation (Gtk.Orientation.VERTICAL);
+ content.set_vexpand (true);
+
+ this.header = new Gtk.HeaderBar ();
+ this.set_titlebar (this.header);
+ this.header.set_show_close_button (true);
+ this.header.set_hexpand (true);
+
+ this.master_switch = new Gtk.Switch ();
+ header.pack_start (this.master_switch);
+ master_switch.set_valign (Gtk.Align.CENTER);
+ break_manager.bind_property ("master-enabled", this.master_switch, "active",
BindingFlags.BIDIRECTIONAL | BindingFlags.SYNC_CREATE);
+
+ this.settings_button = new Gtk.Button ();
+ header.pack_end (this.settings_button);
+ settings_button.clicked.connect (this.settings_clicked_cb);
+ // FIXME: This icon is not semantically correct. (Wrong category, especially).
+ settings_button.set_image (new Gtk.Image.from_icon_name (
+ "preferences-system-symbolic",
+ Gtk.IconSize.MENU)
+ );
+ settings_button.valign = Gtk.Align.CENTER;
+ settings_button.set_always_show_image (true);
+
+ this.main_stack = new Gtk.Stack ();
+ content.add (this.main_stack);
+ main_stack.set_margin_top (6);
+ main_stack.set_margin_bottom (6);
+ main_stack.set_transition_duration (250);
+
+ this.status_panel = new StatusPanel (break_manager, builder);
+ this.main_stack.add_named (this.status_panel, "status_panel");
+
+ this.welcome_panel = new WelcomePanel (break_manager, builder, this);
+ this.main_stack.add_named (this.welcome_panel, "welcome_panel");
+ this.welcome_panel.tour_finished.connect (this.on_tour_finished);
+
+ this.header.show_all ();
+ content.show_all ();
+
+ break_manager.break_added.connect (this.break_added_cb);
+ break_manager.notify["foreground-break"].connect (this.update_visible_panel);
+ this.update_visible_panel ();
+ }
+
+ public Gtk.Widget get_master_switch () {
+ return this.master_switch;
+ }
+
+ public Gtk.Widget get_settings_button () {
+ return this.settings_button;
+ }
+
+ public Gtk.Widget? get_close_button () {
+ // TODO: We need some way to get the close button position from this.header
+ return null;
+ }
+
+ private void break_added_cb (BreakType break_type) {
+ var info_panel = break_type.info_panel;
+ this.main_stack.add_named (info_panel, break_type.id);
+ info_panel.set_margin_left (20);
+ info_panel.set_margin_right (20);
+ info_panel.set_halign (Gtk.Align.CENTER);
+ info_panel.set_valign (Gtk.Align.CENTER);
+ }
+
+ private void update_visible_panel () {
+ // Use a transition when switching from the welcome panel
+ Gtk.StackTransitionType transition;
+ if (this.main_stack.get_visible_child () == this.welcome_panel) {
+ transition = Gtk.StackTransitionType.SLIDE_LEFT;
+ } else {
+ transition = Gtk.StackTransitionType.NONE;
+ }
+
+ BreakType? foreground_break = this.break_manager.foreground_break;
+ if (this.welcome_panel.is_active ()) {
+ this.main_stack.set_visible_child_full ("welcome_panel", transition);
+ this.header.set_title ( _("Welcome Tour"));
+ } else if (foreground_break != null) {
+ this.main_stack.set_visible_child_full (foreground_break.id, transition);
+ this.header.set_title (foreground_break.info_panel.title);
+ } else {
+ this.main_stack.set_visible_child_full ("status_panel", transition);
+ this.header.set_title ( _("Break Timer"));
+ }
+ }
+
+ private void on_tour_finished () {
+ this.update_visible_panel ();
+ }
+
+ public void show_about_dialog () {
+ const string copyright = "Copyright © 2011-2013 Dylan McCall";
+
+ Gtk.show_about_dialog (this,
+ "program-name", _("GNOME Break Timer"),
+ "logo-icon-name", "org.gnome.BreakTimer",
+ "version", Config.VERSION,
+ "comments", _("Computer break reminders for active minds"),
+ "website", Config.PACKAGE_URL,
+ "website-label", _("GNOME Break Timer Website"),
+ "copyright", copyright,
+ "license-type", Gtk.License.GPL_3_0,
+ "wrap-license", false,
+ "translator-credits", _("translator-credits")
+ );
+ }
+
+ private void settings_clicked_cb () {
+ this.break_settings_dialog.show ();
+ this.welcome_panel.settings_button_clicked ();
+ }
}
/* TODO: It would be nice to move some of this code to a UI file built with
* Glade. Especially anything involving long strings. */
private class WelcomePanel : Gtk.Stack {
- private BreakManager break_manager;
- private MainWindow main_window;
-
- private enum Step {
- WELCOME,
- BREAKS,
- READY
- }
- private Step current_step;
-
- private Gtk.Container start_page;
- private Gtk.Container breaks_page;
- private Gtk.Container ready_page;
-
- public WelcomePanel (BreakManager break_manager, Gtk.Builder builder, MainWindow main_window) {
- Object ();
- this.break_manager = break_manager;
- this.main_window = main_window;
-
- if (this.break_manager.master_enabled) {
- this.current_step = Step.READY;
- } else {
- this.current_step = Step.WELCOME;
- }
-
- this.set_transition_type (Gtk.StackTransitionType.SLIDE_LEFT);
- this.set_transition_duration (250);
-
- this.start_page = this.build_page_with_arrow (
- builder, "welcome_start", "switch_on_label", main_window.get_master_switch ());
- this.add (this.start_page);
-
- this.breaks_page = this.build_page_with_arrow (
- builder, "welcome_breaks", "settings_label", main_window.get_settings_button ());
- this.add (this.breaks_page);
-
- this.ready_page = this.build_page_with_arrow (
- builder, "welcome_ready", "keeps_running_label", main_window.get_close_button ());
- this.add (this.ready_page);
-
- var breaks_ok_button = new Gtk.Button.with_label (_("OK, got it!"));
- breaks_ok_button.get_style_context ().add_class ("suggested-action");
- breaks_ok_button.set_halign (Gtk.Align.CENTER);
- this.breaks_page.add (breaks_ok_button);
- breaks_ok_button.clicked.connect (this.on_breaks_confirmed);
-
- var ready_ok_button = new Gtk.Button.with_label (_("Ready to go"));
- ready_ok_button.get_style_context ().add_class ("suggested-action");
- ready_ok_button.set_halign (Gtk.Align.CENTER);
- this.ready_page.add (ready_ok_button);
- ready_ok_button.clicked.connect (this.on_ready_confirmed);
-
- break_manager.notify["master-enabled"].connect (this.on_master_switch_toggled);
- }
-
- public signal void tour_finished ();
-
- public bool is_active () {
- return this.current_step < Step.READY;
- }
-
- internal void settings_button_clicked () {
- if (this.current_step == Step.BREAKS) {
- this.on_breaks_confirmed ();
- }
- }
-
- private void on_master_switch_toggled () {
- if (this.break_manager.master_enabled) {
- this.advance_current_step (Step.BREAKS);
- } else {
- // TODO: Should we jump back to the first step, or keep going?
- }
- }
-
- private Gtk.Container build_page_with_arrow (Gtk.Builder builder, string page_name, string?
arrow_source_name, Gtk.Widget? arrow_target) {
- Gtk.Grid page_wrapper = new Gtk.Grid ();
- page_wrapper.set_orientation (Gtk.Orientation.VERTICAL);
- page_wrapper.set_row_spacing (16);
- page_wrapper.set_margin_bottom (30);
-
- Gtk.Overlay page_overlay = new Gtk.Overlay ();
- page_wrapper.add (page_overlay);
-
- page_overlay.add (builder.get_object (page_name) as Gtk.Widget);
- Gtk.Widget arrow_source = builder.get_object (arrow_source_name) as Gtk.Widget;
- if (arrow_source != null && arrow_target != null) {
- var arrow = new OverlayArrow (arrow_source, arrow_target);
- page_overlay.add_overlay (arrow);
- }
-
- return page_wrapper;
- }
-
- private void on_breaks_confirmed () {
- this.advance_current_step (Step.READY);
- }
-
- private void on_ready_confirmed () {
- this.tour_finished ();
- }
-
- private void advance_current_step (Step next_step) {
- if (next_step > this.current_step) this.current_step = next_step;
-
- if (this.current_step == Step.WELCOME) {
- this.set_visible_child (this.start_page);
- } else if (this.current_step == Step.BREAKS) {
- this.set_visible_child (this.breaks_page);
- } else {
- this.set_visible_child (this.ready_page);
- }
- }
+ private BreakManager break_manager;
+ private MainWindow main_window;
+
+ private enum Step {
+ WELCOME,
+ BREAKS,
+ READY
+ }
+ private Step current_step;
+
+ private Gtk.Container start_page;
+ private Gtk.Container breaks_page;
+ private Gtk.Container ready_page;
+
+ public WelcomePanel (BreakManager break_manager, Gtk.Builder builder, MainWindow main_window) {
+ Object ();
+ this.break_manager = break_manager;
+ this.main_window = main_window;
+
+ if (this.break_manager.master_enabled) {
+ this.current_step = Step.READY;
+ } else {
+ this.current_step = Step.WELCOME;
+ }
+
+ this.set_transition_type (Gtk.StackTransitionType.SLIDE_LEFT);
+ this.set_transition_duration (250);
+
+ this.start_page = this.build_page_with_arrow (
+ builder, "welcome_start", "switch_on_label", main_window.get_master_switch ());
+ this.add (this.start_page);
+
+ this.breaks_page = this.build_page_with_arrow (
+ builder, "welcome_breaks", "settings_label", main_window.get_settings_button ());
+ this.add (this.breaks_page);
+
+ this.ready_page = this.build_page_with_arrow (
+ builder, "welcome_ready", "keeps_running_label", main_window.get_close_button ());
+ this.add (this.ready_page);
+
+ var breaks_ok_button = new Gtk.Button.with_label (_("OK, got it!"));
+ breaks_ok_button.get_style_context ().add_class ("suggested-action");
+ breaks_ok_button.set_halign (Gtk.Align.CENTER);
+ this.breaks_page.add (breaks_ok_button);
+ breaks_ok_button.clicked.connect (this.on_breaks_confirmed);
+
+ var ready_ok_button = new Gtk.Button.with_label (_("Ready to go"));
+ ready_ok_button.get_style_context ().add_class ("suggested-action");
+ ready_ok_button.set_halign (Gtk.Align.CENTER);
+ this.ready_page.add (ready_ok_button);
+ ready_ok_button.clicked.connect (this.on_ready_confirmed);
+
+ break_manager.notify["master-enabled"].connect (this.on_master_switch_toggled);
+ }
+
+ public signal void tour_finished ();
+
+ public bool is_active () {
+ return this.current_step < Step.READY;
+ }
+
+ internal void settings_button_clicked () {
+ if (this.current_step == Step.BREAKS) {
+ this.on_breaks_confirmed ();
+ }
+ }
+
+ private void on_master_switch_toggled () {
+ if (this.break_manager.master_enabled) {
+ this.advance_current_step (Step.BREAKS);
+ } else {
+ // TODO: Should we jump back to the first step, or keep going?
+ }
+ }
+
+ private Gtk.Container build_page_with_arrow (Gtk.Builder builder, string page_name, string?
arrow_source_name, Gtk.Widget? arrow_target) {
+ Gtk.Grid page_wrapper = new Gtk.Grid ();
+ page_wrapper.set_orientation (Gtk.Orientation.VERTICAL);
+ page_wrapper.set_row_spacing (16);
+ page_wrapper.set_margin_bottom (30);
+
+ Gtk.Overlay page_overlay = new Gtk.Overlay ();
+ page_wrapper.add (page_overlay);
+
+ page_overlay.add (builder.get_object (page_name) as Gtk.Widget);
+ Gtk.Widget arrow_source = builder.get_object (arrow_source_name) as Gtk.Widget;
+ if (arrow_source != null && arrow_target != null) {
+ var arrow = new OverlayArrow (arrow_source, arrow_target);
+ page_overlay.add_overlay (arrow);
+ }
+
+ return page_wrapper;
+ }
+
+ private void on_breaks_confirmed () {
+ this.advance_current_step (Step.READY);
+ }
+
+ private void on_ready_confirmed () {
+ this.tour_finished ();
+ }
+
+ private void advance_current_step (Step next_step) {
+ if (next_step > this.current_step) this.current_step = next_step;
+
+ if (this.current_step == Step.WELCOME) {
+ this.set_visible_child (this.start_page);
+ } else if (this.current_step == Step.BREAKS) {
+ this.set_visible_child (this.breaks_page);
+ } else {
+ this.set_visible_child (this.ready_page);
+ }
+ }
}
private class StatusPanel : Gtk.Stack {
- private BreakManager break_manager;
-
- private Gtk.Grid breaks_list;
- private Gtk.Widget no_breaks_message;
- private Gtk.Widget error_message;
-
- public StatusPanel (BreakManager break_manager, Gtk.Builder builder) {
- Object ();
-
- this.break_manager = break_manager;
-
- this.set_margin_top (20);
- this.set_margin_right (20);
- this.set_margin_bottom (20);
- this.set_margin_left (20);
- this.set_hexpand (true);
- this.set_vexpand (true);
-
- this.breaks_list = this.build_breaks_list (break_manager);
- this.add (this.breaks_list);
-
- this.no_breaks_message = builder.get_object ("status_stopped") as Gtk.Widget;
- this.add (this.no_breaks_message);
-
- this.error_message = builder.get_object ("status_error") as Gtk.Widget;
- this.add (this.error_message);
-
- break_manager.break_added.connect (this.break_added_cb);
- break_manager.status_changed.connect (this.status_changed_cb);
- }
-
- private Gtk.Grid build_breaks_list (BreakManager break_manager) {
- var breaks_list = new Gtk.Grid ();
- breaks_list.set_orientation (Gtk.Orientation.VERTICAL);
- breaks_list.set_halign (Gtk.Align.CENTER);
- breaks_list.set_valign (Gtk.Align.CENTER);
-
- return breaks_list;
- }
-
- private void break_added_cb (BreakType break_type) {
- var status_panel = break_type.status_panel;
- this.breaks_list.add (status_panel);
- status_panel.set_margin_top (18);
- status_panel.set_margin_right (20);
- status_panel.set_margin_bottom (18);
- status_panel.set_margin_left (20);
- }
-
- private void status_changed_cb () {
- bool any_breaks_enabled = false;
-
- unowned List<BreakType> all_breaks = this.break_manager.all_breaks ();
- foreach (BreakType break_type in all_breaks) {
- var status = break_type.status;
- if (status != null) {
- if (status.is_enabled) {
- break_type.status_panel.show ();
- any_breaks_enabled = true;
- } else {
- break_type.status_panel.hide ();
- }
- }
- }
-
- if (any_breaks_enabled) {
- this.set_visible_child (this.breaks_list);
- } else if (this.break_manager.is_working ()) {
- this.set_visible_child (this.no_breaks_message);
- } else {
- this.set_visible_child (this.error_message);
- }
- }
+ private BreakManager break_manager;
+
+ private Gtk.Grid breaks_list;
+ private Gtk.Widget no_breaks_message;
+ private Gtk.Widget error_message;
+
+ public StatusPanel (BreakManager break_manager, Gtk.Builder builder) {
+ Object ();
+
+ this.break_manager = break_manager;
+
+ this.set_margin_top (20);
+ this.set_margin_right (20);
+ this.set_margin_bottom (20);
+ this.set_margin_left (20);
+ this.set_hexpand (true);
+ this.set_vexpand (true);
+
+ this.breaks_list = this.build_breaks_list (break_manager);
+ this.add (this.breaks_list);
+
+ this.no_breaks_message = builder.get_object ("status_stopped") as Gtk.Widget;
+ this.add (this.no_breaks_message);
+
+ this.error_message = builder.get_object ("status_error") as Gtk.Widget;
+ this.add (this.error_message);
+
+ break_manager.break_added.connect (this.break_added_cb);
+ break_manager.status_changed.connect (this.status_changed_cb);
+ }
+
+ private Gtk.Grid build_breaks_list (BreakManager break_manager) {
+ var breaks_list = new Gtk.Grid ();
+ breaks_list.set_orientation (Gtk.Orientation.VERTICAL);
+ breaks_list.set_halign (Gtk.Align.CENTER);
+ breaks_list.set_valign (Gtk.Align.CENTER);
+
+ return breaks_list;
+ }
+
+ private void break_added_cb (BreakType break_type) {
+ var status_panel = break_type.status_panel;
+ this.breaks_list.add (status_panel);
+ status_panel.set_margin_top (18);
+ status_panel.set_margin_right (20);
+ status_panel.set_margin_bottom (18);
+ status_panel.set_margin_left (20);
+ }
+
+ private void status_changed_cb () {
+ bool any_breaks_enabled = false;
+
+ unowned List<BreakType> all_breaks = this.break_manager.all_breaks ();
+ foreach (BreakType break_type in all_breaks) {
+ var status = break_type.status;
+ if (status != null) {
+ if (status.is_enabled) {
+ break_type.status_panel.show ();
+ any_breaks_enabled = true;
+ } else {
+ break_type.status_panel.hide ();
+ }
+ }
+ }
+
+ if (any_breaks_enabled) {
+ this.set_visible_child (this.breaks_list);
+ } else if (this.break_manager.is_working ()) {
+ this.set_visible_child (this.no_breaks_message);
+ } else {
+ this.set_visible_child (this.error_message);
+ }
+ }
}
}
diff --git a/settings/MicroBreakType.vala b/settings/MicroBreakType.vala
index c6656e7..c8ec49c 100644
--- a/settings/MicroBreakType.vala
+++ b/settings/MicroBreakType.vala
@@ -21,82 +21,82 @@ using GLib;
namespace BreakTimer.Settings {
public class MicroBreakType : TimerBreakType {
- public MicroBreakType () {
- GLib.Settings settings = new GLib.Settings ("org.gnome.BreakTimer.microbreak");
- base ("microbreak", settings);
-
- this.interval_options = { 240, 300, 360, 480, 600 };
- this.duration_options = { 15, 30, 45, 60 };
- }
-
- protected override BreakInfoPanel get_info_panel () {
- return new MicroBreakInfoPanel (this);
- }
-
- protected override BreakStatusPanel get_status_panel () {
- return new MicroBreakStatusPanel (this);
- }
-
- protected override BreakSettingsPanel get_settings_panel () {
- return new MicroBreakSettingsPanel (this);
- }
+ public MicroBreakType () {
+ GLib.Settings settings = new GLib.Settings ("org.gnome.BreakTimer.microbreak");
+ base ("microbreak", settings);
+
+ this.interval_options = { 240, 300, 360, 480, 600 };
+ this.duration_options = { 15, 30, 45, 60 };
+ }
+
+ protected override BreakInfoPanel get_info_panel () {
+ return new MicroBreakInfoPanel (this);
+ }
+
+ protected override BreakStatusPanel get_status_panel () {
+ return new MicroBreakStatusPanel (this);
+ }
+
+ protected override BreakSettingsPanel get_settings_panel () {
+ return new MicroBreakSettingsPanel (this);
+ }
}
class MicroBreakInfoPanel : BreakInfoPanel {
- private TimerBreakStatus? status;
-
- public MicroBreakInfoPanel (MicroBreakType break_type) {
- base (
- break_type,
- _("Microbreak")
- );
-
- break_type.timer_status_changed.connect (this.timer_status_changed_cb);
- }
-
- private void timer_status_changed_cb (TimerBreakStatus? status) {
- this.status = status;
- this.update_description ();
- }
-
- private void update_description () {
- if (this.status == null) return;
-
- int time_remaining_value;
- string time_remaining_text = NaturalTime.instance.get_countdown_for_seconds_with_start (
- this.status.time_remaining, this.status.current_duration, out time_remaining_value);
- string description_text = ngettext (
- /* %s will be replaced with a string that describes a time interval, such as "2
minutes", "40 seconds" or "1 hour" */
- "Take a break from typing and look away from the screen for %s.",
- "Take a break from typing and look away from the screen for %s.",
- time_remaining_value
- ).printf (time_remaining_text);
-
- this.set_heading ( _("It’s microbreak time"));
- this.set_description (description_text);
- this.set_detail (_("I'll chime when it’s time to use the computer again."));
- }
+ private TimerBreakStatus? status;
+
+ public MicroBreakInfoPanel (MicroBreakType break_type) {
+ base (
+ break_type,
+ _("Microbreak")
+ );
+
+ break_type.timer_status_changed.connect (this.timer_status_changed_cb);
+ }
+
+ private void timer_status_changed_cb (TimerBreakStatus? status) {
+ this.status = status;
+ this.update_description ();
+ }
+
+ private void update_description () {
+ if (this.status == null) return;
+
+ int time_remaining_value;
+ string time_remaining_text = NaturalTime.instance.get_countdown_for_seconds_with_start (
+ this.status.time_remaining, this.status.current_duration, out time_remaining_value);
+ string description_text = ngettext (
+ /* %s will be replaced with a string that describes a time interval, such as "2 minutes", "40
seconds" or "1 hour" */
+ "Take a break from typing and look away from the screen for %s.",
+ "Take a break from typing and look away from the screen for %s.",
+ time_remaining_value
+ ).printf (time_remaining_text);
+
+ this.set_heading ( _("It’s microbreak time"));
+ this.set_description (description_text);
+ this.set_detail (_("I'll chime when it’s time to use the computer again."));
+ }
}
class MicroBreakStatusPanel : TimerBreakStatusPanel {
- public MicroBreakStatusPanel (MicroBreakType break_type) {
- base (
- break_type,
- /* Label that explains a countdown timer, which shows a string such as "5 minutes" */
- _("Your next microbreak is in"),
- _("It's time for a microbreak")
- );
- }
+ public MicroBreakStatusPanel (MicroBreakType break_type) {
+ base (
+ break_type,
+ /* Label that explains a countdown timer, which shows a string such as "5 minutes" */
+ _("Your next microbreak is in"),
+ _("It's time for a microbreak")
+ );
+ }
}
class MicroBreakSettingsPanel : TimerBreakSettingsPanel {
- public MicroBreakSettingsPanel (MicroBreakType break_type) {
- base (
- break_type,
- _("Microbreak"),
- _("Pause frequently to relax your eyes")
- );
- }
+ public MicroBreakSettingsPanel (MicroBreakType break_type) {
+ base (
+ break_type,
+ _("Microbreak"),
+ _("Pause frequently to relax your eyes")
+ );
+ }
}
}
diff --git a/settings/OverlayArrow.vala b/settings/OverlayArrow.vala
index 1b7e162..8bb59b8 100644
--- a/settings/OverlayArrow.vala
+++ b/settings/OverlayArrow.vala
@@ -22,104 +22,104 @@ namespace BreakTimer.Settings {
/* FIXME: This widget is stealing clicks when it is used in an overlay */
public class OverlayArrow : Gtk.Widget {
- private Gtk.Widget from_widget;
- private Gtk.Widget to_widget;
-
- public OverlayArrow (Gtk.Widget from_widget, Gtk.Widget to_widget) {
- Object ();
- this.set_has_window (false);
-
- this.set_halign (Gtk.Align.FILL);
- this.set_valign (Gtk.Align.FILL);
-
- this.from_widget = from_widget;
- this.to_widget = to_widget;
- }
-
- public override bool draw (Cairo.Context cr) {
- int max_width = this.get_allocated_width ();
- int max_height = this.get_allocated_height ();
-
- int from_x, from_y;
- this.get_from_coordinates (out from_x, out from_y);
- from_x = from_x.clamp (0, max_width);
- from_y = from_y.clamp (0, max_height);
-
- int to_x, to_y;
- this.get_to_coordinates (out to_x, out to_y);
- to_x = to_x.clamp (0, max_width);
- to_y = to_y.clamp (0, max_height);
-
- Gtk.StateFlags state = this.get_state_flags ();
- Gtk.StyleContext style_context = this.get_style_context ();
- Gdk.RGBA color = style_context.get_color (state);
- Gdk.cairo_set_source_rgba (cr, color);
- cr.set_line_width (1.0);
-
- cr.move_to (from_x, from_y);
- double curve_x = to_x - from_x;
- double curve_y = (to_y+8) - from_y;
- cr.rel_curve_to (curve_x / 3.0, 0, curve_x, curve_y / 3.0, curve_x, curve_y);
- cr.stroke ();
-
- cr.move_to (to_x, to_y+8);
- cr.rel_line_to (-4, 0);
- cr.rel_line_to (4, -6);
- cr.rel_line_to (4, 6);
- cr.close_path ();
- cr.fill_preserve ();
- cr.stroke ();
-
- return true;
- }
-
- public override void size_allocate (Gtk.Allocation allocation) {
- base.size_allocate (allocation);
- }
-
- private void get_points_offset (out int offset_x, out int offset_y) {
- Gtk.Allocation to_allocation;
- this.to_widget.get_allocation (out to_allocation);
- this.from_widget.translate_coordinates (this.to_widget, to_allocation.width/2,
to_allocation.width/2, out offset_x, out offset_y);
- }
-
- private void get_from_coordinates (out int from_x, out int from_y) {
- // Is to_widget to the right or to the left?
- Gtk.Allocation from_allocation;
- this.from_widget.get_allocation (out from_allocation);
-
- int offset_x, offset_y;
- this.get_points_offset (out offset_x, out offset_y);
-
- int from_local_x, from_local_y;
- if (offset_x > 0) {
- from_local_x = 0;
- from_local_y = from_allocation.height / 2;
- } else {
- from_local_x = from_allocation.width;
- from_local_y = from_allocation.height / 2;
- }
- this.from_widget.translate_coordinates (this, from_local_x, from_local_y, out from_x, out
from_y);
- }
-
- private void get_to_coordinates (out int to_x, out int to_y) {
- // Is to_widget to the right or to the left?
- Gtk.Allocation to_allocation;
- this.to_widget.get_allocation (out to_allocation);
-
- int offset_x, offset_y;
- this.get_points_offset (out offset_x, out offset_y);
-
- int to_local_x, to_local_y;
- if (offset_y > 0) {
- to_local_x = to_allocation.width / 2;
- to_local_y = to_allocation.height;
- } else {
- to_local_x = to_allocation.width / 2;
- to_local_y = 0;
- }
- this.to_widget.translate_coordinates (this, to_local_x, to_local_y, out to_x, out to_y);
- }
+ private Gtk.Widget from_widget;
+ private Gtk.Widget to_widget;
+
+ public OverlayArrow (Gtk.Widget from_widget, Gtk.Widget to_widget) {
+ Object ();
+ this.set_has_window (false);
+
+ this.set_halign (Gtk.Align.FILL);
+ this.set_valign (Gtk.Align.FILL);
+
+ this.from_widget = from_widget;
+ this.to_widget = to_widget;
+ }
+
+ public override bool draw (Cairo.Context cr) {
+ int max_width = this.get_allocated_width ();
+ int max_height = this.get_allocated_height ();
+
+ int from_x, from_y;
+ this.get_from_coordinates (out from_x, out from_y);
+ from_x = from_x.clamp (0, max_width);
+ from_y = from_y.clamp (0, max_height);
+
+ int to_x, to_y;
+ this.get_to_coordinates (out to_x, out to_y);
+ to_x = to_x.clamp (0, max_width);
+ to_y = to_y.clamp (0, max_height);
+
+ Gtk.StateFlags state = this.get_state_flags ();
+ Gtk.StyleContext style_context = this.get_style_context ();
+ Gdk.RGBA color = style_context.get_color (state);
+ Gdk.cairo_set_source_rgba (cr, color);
+ cr.set_line_width (1.0);
+
+ cr.move_to (from_x, from_y);
+ double curve_x = to_x - from_x;
+ double curve_y = (to_y+8) - from_y;
+ cr.rel_curve_to (curve_x / 3.0, 0, curve_x, curve_y / 3.0, curve_x, curve_y);
+ cr.stroke ();
+
+ cr.move_to (to_x, to_y+8);
+ cr.rel_line_to (-4, 0);
+ cr.rel_line_to (4, -6);
+ cr.rel_line_to (4, 6);
+ cr.close_path ();
+ cr.fill_preserve ();
+ cr.stroke ();
+
+ return true;
+ }
+
+ public override void size_allocate (Gtk.Allocation allocation) {
+ base.size_allocate (allocation);
+ }
+
+ private void get_points_offset (out int offset_x, out int offset_y) {
+ Gtk.Allocation to_allocation;
+ this.to_widget.get_allocation (out to_allocation);
+ this.from_widget.translate_coordinates (this.to_widget, to_allocation.width/2,
to_allocation.width/2, out offset_x, out offset_y);
+ }
+
+ private void get_from_coordinates (out int from_x, out int from_y) {
+ // Is to_widget to the right or to the left?
+ Gtk.Allocation from_allocation;
+ this.from_widget.get_allocation (out from_allocation);
+
+ int offset_x, offset_y;
+ this.get_points_offset (out offset_x, out offset_y);
+
+ int from_local_x, from_local_y;
+ if (offset_x > 0) {
+ from_local_x = 0;
+ from_local_y = from_allocation.height / 2;
+ } else {
+ from_local_x = from_allocation.width;
+ from_local_y = from_allocation.height / 2;
+ }
+ this.from_widget.translate_coordinates (this, from_local_x, from_local_y, out from_x, out from_y);
+ }
+
+ private void get_to_coordinates (out int to_x, out int to_y) {
+ // Is to_widget to the right or to the left?
+ Gtk.Allocation to_allocation;
+ this.to_widget.get_allocation (out to_allocation);
+
+ int offset_x, offset_y;
+ this.get_points_offset (out offset_x, out offset_y);
+
+ int to_local_x, to_local_y;
+ if (offset_y > 0) {
+ to_local_x = to_allocation.width / 2;
+ to_local_y = to_allocation.height;
+ } else {
+ to_local_x = to_allocation.width / 2;
+ to_local_y = 0;
+ }
+ this.to_widget.translate_coordinates (this, to_local_x, to_local_y, out to_x, out to_y);
+ }
}
}
diff --git a/settings/RestBreakType.vala b/settings/RestBreakType.vala
index 183ba59..d50e391 100644
--- a/settings/RestBreakType.vala
+++ b/settings/RestBreakType.vala
@@ -21,83 +21,83 @@ using GLib;
namespace BreakTimer.Settings {
public class RestBreakType : TimerBreakType {
- public RestBreakType () {
- GLib.Settings settings = new GLib.Settings ("org.gnome.BreakTimer.restbreak");
- base ("restbreak", settings);
-
- this.interval_options = { 1800, 2400, 3000, 3600 };
- this.duration_options = { 240, 300, 360, 480, 600 };
- }
-
- protected override BreakInfoPanel get_info_panel () {
- return new RestBreakInfoPanel (this);
- }
-
- protected override BreakStatusPanel get_status_panel () {
- return new RestBreakStatusPanel (this);
- }
-
- protected override BreakSettingsPanel get_settings_panel () {
- return new RestBreakSettingsPanel (this);
- }
+ public RestBreakType () {
+ GLib.Settings settings = new GLib.Settings ("org.gnome.BreakTimer.restbreak");
+ base ("restbreak", settings);
+
+ this.interval_options = { 1800, 2400, 3000, 3600 };
+ this.duration_options = { 240, 300, 360, 480, 600 };
+ }
+
+ protected override BreakInfoPanel get_info_panel () {
+ return new RestBreakInfoPanel (this);
+ }
+
+ protected override BreakStatusPanel get_status_panel () {
+ return new RestBreakStatusPanel (this);
+ }
+
+ protected override BreakSettingsPanel get_settings_panel () {
+ return new RestBreakSettingsPanel (this);
+ }
}
class RestBreakInfoPanel : BreakInfoPanel {
- private TimerBreakStatus? status;
-
- public RestBreakInfoPanel (RestBreakType break_type) {
- base (
- break_type,
- _("Break")
- );
-
- break_type.notify["duration"].connect (this.update_description);
- break_type.timer_status_changed.connect (this.timer_status_changed_cb);
- }
-
- private void timer_status_changed_cb (TimerBreakStatus? status) {
- this.status = status;
- this.update_description ();
- }
-
- private void update_description () {
- if (this.status == null) return;
-
- int time_remaining_value;
- string time_remaining_text = NaturalTime.instance.get_countdown_for_seconds_with_start (
- this.status.time_remaining, this.status.current_duration, out time_remaining_value);
- string detail_text = ngettext (
- /* %s will be replaced with a string that describes a time interval, such as "2
minutes", "40 seconds" or "1 hour" */
- "Your break has %s remaining. I’ll remind you when it’s over.",
- "Your break has %s remaining. I’ll remind you when it’s over.",
- time_remaining_value
- ).printf (time_remaining_text);
-
- this.set_heading ( _("It’s break time"));
- this.set_description (_("Take some time away from the computer. Stretch and move around."));
- this.set_detail (detail_text);
- }
+ private TimerBreakStatus? status;
+
+ public RestBreakInfoPanel (RestBreakType break_type) {
+ base (
+ break_type,
+ _("Break")
+ );
+
+ break_type.notify["duration"].connect (this.update_description);
+ break_type.timer_status_changed.connect (this.timer_status_changed_cb);
+ }
+
+ private void timer_status_changed_cb (TimerBreakStatus? status) {
+ this.status = status;
+ this.update_description ();
+ }
+
+ private void update_description () {
+ if (this.status == null) return;
+
+ int time_remaining_value;
+ string time_remaining_text = NaturalTime.instance.get_countdown_for_seconds_with_start (
+ this.status.time_remaining, this.status.current_duration, out time_remaining_value);
+ string detail_text = ngettext (
+ /* %s will be replaced with a string that describes a time interval, such as "2 minutes", "40
seconds" or "1 hour" */
+ "Your break has %s remaining. I’ll remind you when it’s over.",
+ "Your break has %s remaining. I’ll remind you when it’s over.",
+ time_remaining_value
+ ).printf (time_remaining_text);
+
+ this.set_heading ( _("It’s break time"));
+ this.set_description (_("Take some time away from the computer. Stretch and move around."));
+ this.set_detail (detail_text);
+ }
}
class RestBreakStatusPanel : TimerBreakStatusPanel {
- public RestBreakStatusPanel (RestBreakType break_type) {
- base (
- break_type,
- /* Label that explains a countdown timer, which shows a string such as "30 minutes" */
- _("Your next full break is in"),
- _("It's break time")
- );
- }
+ public RestBreakStatusPanel (RestBreakType break_type) {
+ base (
+ break_type,
+ /* Label that explains a countdown timer, which shows a string such as "30 minutes" */
+ _("Your next full break is in"),
+ _("It's break time")
+ );
+ }
}
class RestBreakSettingsPanel : TimerBreakSettingsPanel {
- public RestBreakSettingsPanel (RestBreakType break_type) {
- base (
- break_type,
- _("Full break"),
- _("And take some longer breaks to stretch your legs")
- );
- }
+ public RestBreakSettingsPanel (RestBreakType break_type) {
+ base (
+ break_type,
+ _("Full break"),
+ _("And take some longer breaks to stretch your legs")
+ );
+ }
}
}
diff --git a/settings/SettingsApplication.vala b/settings/SettingsApplication.vala
index 59779f2..f1e877e 100644
--- a/settings/SettingsApplication.vala
+++ b/settings/SettingsApplication.vala
@@ -21,114 +21,114 @@ using GLib;
namespace BreakTimer.Settings {
public class SettingsApplication : Gtk.Application {
- const string app_id = Config.SETTINGS_DESKTOP_ID;
-
- private const string STYLE_DATA =
- """
- ._settings-title {
- font-weight:bold;
- }
-
- ._break-info {
- }
-
- ._break-info-heading {
- font-size: xx-large;
- }
-
- ._break-status-heading {
- font-size: larger;
- }
-
- ._break-status-body {
- }
-
- ._break-status-hint {
- font-size: small;
- }
-
- ._break-status-icon {
- opacity: 0.2;
- }
-
- ._circle-counter {
- /* borrowed from gnome-clocks/data/css/gnome-clocks.css */
- color: mix(@theme_fg_color, @theme_bg_color, 0.5);
- background-color: mix(@theme_fg_color, @theme_bg_color, 0.85);
- }
- """;
-
- private BreakManager break_manager;
- private MainWindow main_window;
-
- public SettingsApplication () {
- Object (application_id: app_id, flags: ApplicationFlags.FLAGS_NONE);
- }
-
- public override void activate () {
- base.activate ();
-
- if (this.break_manager.is_working ()) {
- this.main_window.present ();
- } else {
- // Something may be wrong, but it could just be a delay before the
- // break helper starts. We'll wait before showing the main window.
- this.delayed_start ();
- }
- }
-
- public override void startup () {
- base.startup ();
-
- /* set up custom gtk style for application */
- Gdk.Screen screen = Gdk.Screen.get_default ();
- Gtk.CssProvider style_provider = new Gtk.CssProvider ();
-
- try {
- style_provider.load_from_data (STYLE_DATA, -1);
- } catch (Error error) {
- stderr.printf ("Error loading style data: %s\n", error.message);
- }
-
- Gtk.StyleContext.add_provider_for_screen (
- screen,
- style_provider,
- Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
-
- SimpleAction about_action = new SimpleAction ("about", null);
- this.add_action (about_action);
- about_action.activate.connect (this.on_about_activate_cb);
-
- SimpleAction quit_action = new SimpleAction ("quit", null);
- this.add_action (quit_action);
- quit_action.activate.connect (this.quit);
-
- GLib.Menu app_menu = new GLib.Menu ();
- app_menu.append ( _("About"), "app.about");
- app_menu.append ( _("Quit"), "app.quit");
- this.set_app_menu (app_menu);
-
- this.break_manager = new BreakManager (this);
- this.main_window = new MainWindow (this, this.break_manager);
- this.break_manager.load_breaks ();
- }
-
- private void delayed_start () {
- // Delay up to 500ms waiting for break_manager to initialize
- this.break_manager.break_status_available.connect (this.delayed_start_cb);
- Timeout.add (500, () => { delayed_start_cb (); return false; });
- }
-
- private void delayed_start_cb () {
- this.break_manager.break_status_available.disconnect (this.delayed_start_cb);
- if (! this.main_window.is_visible ()) {
- this.main_window.present ();
- }
- }
-
- private void on_about_activate_cb () {
- this.main_window.show_about_dialog ();
- }
+ const string app_id = Config.SETTINGS_DESKTOP_ID;
+
+ private const string STYLE_DATA =
+ """
+ ._settings-title {
+ font-weight:bold;
+ }
+
+ ._break-info {
+ }
+
+ ._break-info-heading {
+ font-size: xx-large;
+ }
+
+ ._break-status-heading {
+ font-size: larger;
+ }
+
+ ._break-status-body {
+ }
+
+ ._break-status-hint {
+ font-size: small;
+ }
+
+ ._break-status-icon {
+ opacity: 0.2;
+ }
+
+ ._circle-counter {
+ /* borrowed from gnome-clocks/data/css/gnome-clocks.css */
+ color: mix(@theme_fg_color, @theme_bg_color, 0.5);
+ background-color: mix(@theme_fg_color, @theme_bg_color, 0.85);
+ }
+ """;
+
+ private BreakManager break_manager;
+ private MainWindow main_window;
+
+ public SettingsApplication () {
+ Object (application_id: app_id, flags: ApplicationFlags.FLAGS_NONE);
+ }
+
+ public override void activate () {
+ base.activate ();
+
+ if (this.break_manager.is_working ()) {
+ this.main_window.present ();
+ } else {
+ // Something may be wrong, but it could just be a delay before the
+ // break helper starts. We'll wait before showing the main window.
+ this.delayed_start ();
+ }
+ }
+
+ public override void startup () {
+ base.startup ();
+
+ /* set up custom gtk style for application */
+ Gdk.Screen screen = Gdk.Screen.get_default ();
+ Gtk.CssProvider style_provider = new Gtk.CssProvider ();
+
+ try {
+ style_provider.load_from_data (STYLE_DATA, -1);
+ } catch (Error error) {
+ stderr.printf ("Error loading style data: %s\n", error.message);
+ }
+
+ Gtk.StyleContext.add_provider_for_screen (
+ screen,
+ style_provider,
+ Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
+
+ SimpleAction about_action = new SimpleAction ("about", null);
+ this.add_action (about_action);
+ about_action.activate.connect (this.on_about_activate_cb);
+
+ SimpleAction quit_action = new SimpleAction ("quit", null);
+ this.add_action (quit_action);
+ quit_action.activate.connect (this.quit);
+
+ GLib.Menu app_menu = new GLib.Menu ();
+ app_menu.append ( _("About"), "app.about");
+ app_menu.append ( _("Quit"), "app.quit");
+ this.set_app_menu (app_menu);
+
+ this.break_manager = new BreakManager (this);
+ this.main_window = new MainWindow (this, this.break_manager);
+ this.break_manager.load_breaks ();
+ }
+
+ private void delayed_start () {
+ // Delay up to 500ms waiting for break_manager to initialize
+ this.break_manager.break_status_available.connect (this.delayed_start_cb);
+ Timeout.add (500, () => { delayed_start_cb (); return false; });
+ }
+
+ private void delayed_start_cb () {
+ this.break_manager.break_status_available.disconnect (this.delayed_start_cb);
+ if (! this.main_window.is_visible ()) {
+ this.main_window.present ();
+ }
+ }
+
+ private void on_about_activate_cb () {
+ this.main_window.show_about_dialog ();
+ }
}
}
diff --git a/settings/TimeChooser.vala b/settings/TimeChooser.vala
index 256171c..38ef82b 100644
--- a/settings/TimeChooser.vala
+++ b/settings/TimeChooser.vala
@@ -21,108 +21,108 @@ using GLib;
namespace BreakTimer.Settings {
public class TimeChooser : Gtk.ComboBox {
- private Gtk.ListStore list_store;
-
- private Gtk.TreeIter? custom_item;
-
- private const int OPTION_OTHER = -1;
-
- public int time_seconds { get; set; }
-
- public signal void time_selected (int time);
-
- public TimeChooser (int[] options) {
- Object ();
-
- this.list_store = new Gtk.ListStore (3, typeof (string), typeof (string), typeof (int));
-
- this.set_model (this.list_store);
- this.set_id_column (1);
-
- Gtk.CellRendererText cell = new Gtk.CellRendererText ();
- this.pack_start (cell, true);
- this.set_attributes (cell, "text", null);
-
- foreach (int time in options) {
- string label = NaturalTime.instance.get_label_for_seconds (time);
- this.add_option (label, time);
- }
- this.custom_item = null;
-
- this.changed.connect (this.on_changed);
-
- this.notify["time-seconds"].connect ( (s, p) => {
- this.set_time (this.time_seconds);
- });
- }
-
- public bool set_time (int seconds) {
- string id = seconds.to_string ();
-
- bool option_exists = this.set_active_id (id);
-
- if (!option_exists) {
- if (seconds > 0) {
- Gtk.TreeIter new_option = this.add_custom_option (seconds);
- this.set_active_iter (new_option);
- return true;
- } else {
- return false;
- }
- } else {
- return true;
- }
- }
-
- public int get_time () {
- return this.time_seconds;
- }
-
- private Gtk.TreeIter add_option (string label, int seconds) {
- string id = seconds.to_string ();
-
- Gtk.TreeIter iter;
- this.list_store.append (out iter);
- this.list_store.set (iter, 0, label, 1, id, 2, seconds, -1);
-
- return iter;
- }
-
- private Gtk.TreeIter add_custom_option (int seconds) {
- string label = NaturalTime.instance.get_label_for_seconds (seconds);
- string id = seconds.to_string ();
-
- if (this.custom_item == null) {
- this.list_store.append (out this.custom_item);
- this.list_store.set (this.custom_item, 0, label, 1, id, 2, seconds, -1);
- return this.custom_item;
- } else {
- this.list_store.set (this.custom_item, 0, label, 1, id, 2, seconds, -1);
- return this.custom_item;
- }
- }
-
- private void on_changed () {
- if (this.get_active () < 0) {
- return;
- }
-
- Gtk.TreeIter iter;
- this.get_active_iter (out iter);
-
- int val;
- this.list_store.get (iter, 2, out val);
- if (val == OPTION_OTHER) {
- this.start_custom_input ();
- } else if (val > 0) {
- this.time_seconds = val;
- this.time_selected (val);
- }
- }
-
- private void start_custom_input () {
- GLib.warning("Custom time input is not implemented");
- }
+ private Gtk.ListStore list_store;
+
+ private Gtk.TreeIter? custom_item;
+
+ private const int OPTION_OTHER = -1;
+
+ public int time_seconds { get; set; }
+
+ public signal void time_selected (int time);
+
+ public TimeChooser (int[] options) {
+ Object ();
+
+ this.list_store = new Gtk.ListStore (3, typeof (string), typeof (string), typeof (int));
+
+ this.set_model (this.list_store);
+ this.set_id_column (1);
+
+ Gtk.CellRendererText cell = new Gtk.CellRendererText ();
+ this.pack_start (cell, true);
+ this.set_attributes (cell, "text", null);
+
+ foreach (int time in options) {
+ string label = NaturalTime.instance.get_label_for_seconds (time);
+ this.add_option (label, time);
+ }
+ this.custom_item = null;
+
+ this.changed.connect (this.on_changed);
+
+ this.notify["time-seconds"].connect ( (s, p) => {
+ this.set_time (this.time_seconds);
+ });
+ }
+
+ public bool set_time (int seconds) {
+ string id = seconds.to_string ();
+
+ bool option_exists = this.set_active_id (id);
+
+ if (!option_exists) {
+ if (seconds > 0) {
+ Gtk.TreeIter new_option = this.add_custom_option (seconds);
+ this.set_active_iter (new_option);
+ return true;
+ } else {
+ return false;
+ }
+ } else {
+ return true;
+ }
+ }
+
+ public int get_time () {
+ return this.time_seconds;
+ }
+
+ private Gtk.TreeIter add_option (string label, int seconds) {
+ string id = seconds.to_string ();
+
+ Gtk.TreeIter iter;
+ this.list_store.append (out iter);
+ this.list_store.set (iter, 0, label, 1, id, 2, seconds, -1);
+
+ return iter;
+ }
+
+ private Gtk.TreeIter add_custom_option (int seconds) {
+ string label = NaturalTime.instance.get_label_for_seconds (seconds);
+ string id = seconds.to_string ();
+
+ if (this.custom_item == null) {
+ this.list_store.append (out this.custom_item);
+ this.list_store.set (this.custom_item, 0, label, 1, id, 2, seconds, -1);
+ return this.custom_item;
+ } else {
+ this.list_store.set (this.custom_item, 0, label, 1, id, 2, seconds, -1);
+ return this.custom_item;
+ }
+ }
+
+ private void on_changed () {
+ if (this.get_active () < 0) {
+ return;
+ }
+
+ Gtk.TreeIter iter;
+ this.get_active_iter (out iter);
+
+ int val;
+ this.list_store.get (iter, 2, out val);
+ if (val == OPTION_OTHER) {
+ this.start_custom_input ();
+ } else if (val > 0) {
+ this.time_seconds = val;
+ this.time_selected (val);
+ }
+ }
+
+ private void start_custom_input () {
+ GLib.warning("Custom time input is not implemented");
+ }
}
}
diff --git a/settings/TimerBreakType.vala b/settings/TimerBreakType.vala
index 263219f..58fddc5 100644
--- a/settings/TimerBreakType.vala
+++ b/settings/TimerBreakType.vala
@@ -21,181 +21,181 @@ using GLib;
namespace BreakTimer.Settings {
public abstract class TimerBreakType : BreakType {
- public int interval { get; protected set; }
- public int duration { get; protected set; }
-
- public int[] interval_options;
- public int[] duration_options;
-
- public IBreakHelper_TimerBreak? break_server;
-
- public TimerBreakType (string name, GLib.Settings settings) {
- base (name, settings);
- settings.bind ("interval-seconds", this, "interval", SettingsBindFlags.GET);
- settings.bind ("duration-seconds", this, "duration", SettingsBindFlags.GET);
- }
-
- public signal void timer_status_changed (TimerBreakStatus? status);
-
- public override void initialize () {
- base.initialize ();
- Bus.watch_name (BusType.SESSION, Config.HELPER_BUS_NAME, BusNameWatcherFlags.NONE,
- this.breakhelper_appeared, this.breakhelper_disappeared);
- }
-
- protected new void update_status (TimerBreakStatus? status) {
- if (status != null) {
- base.update_status (BreakStatus () {
- is_enabled = status.is_enabled,
- is_focused = status.is_focused,
- is_active = status.is_active
- });
- } else {
- base.update_status (null);
- }
- this.timer_status_changed (status);
- }
-
- private uint update_timeout_id;
- private bool update_status_cb () {
- TimerBreakStatus? status = this.get_status ();
- this.update_status (status);
- return true;
- }
-
- private TimerBreakStatus? get_status () {
- if (this.break_server != null) {
- try {
- return this.break_server.get_status ();
- } catch (IOError error) {
- GLib.warning ("Error getting break status: %s", error.message);
- return null;
- }
- } else {
- return null;
- }
- }
-
- private void breakhelper_appeared () {
- try {
- this.break_server = Bus.get_proxy_sync (
- BusType.SESSION,
- Config.HELPER_BUS_NAME,
- Config.HELPER_BREAK_OBJECT_BASE_PATH+this.id,
- DBusProxyFlags.DO_NOT_AUTO_START
- );
- // We can only poll the break helper application for updates, so
- // for responsiveness we update at a faster than normal rate.
- this.update_timeout_id = Timeout.add (500, this.update_status_cb);
- this.update_status_cb ();
- } catch (IOError error) {
- this.break_server = null;
- GLib.warning ("Error connecting to break helper service: %s", error.message);
- }
- }
-
- private void breakhelper_disappeared () {
- if (this.update_timeout_id > 0) {
- Source.remove (this.update_timeout_id);
- this.update_timeout_id = 0;
- }
- this.break_server = null;
- this.update_status_cb ();
- }
+ public int interval { get; protected set; }
+ public int duration { get; protected set; }
+
+ public int[] interval_options;
+ public int[] duration_options;
+
+ public IBreakHelper_TimerBreak? break_server;
+
+ public TimerBreakType (string name, GLib.Settings settings) {
+ base (name, settings);
+ settings.bind ("interval-seconds", this, "interval", SettingsBindFlags.GET);
+ settings.bind ("duration-seconds", this, "duration", SettingsBindFlags.GET);
+ }
+
+ public signal void timer_status_changed (TimerBreakStatus? status);
+
+ public override void initialize () {
+ base.initialize ();
+ Bus.watch_name (BusType.SESSION, Config.HELPER_BUS_NAME, BusNameWatcherFlags.NONE,
+ this.breakhelper_appeared, this.breakhelper_disappeared);
+ }
+
+ protected new void update_status (TimerBreakStatus? status) {
+ if (status != null) {
+ base.update_status (BreakStatus () {
+ is_enabled = status.is_enabled,
+ is_focused = status.is_focused,
+ is_active = status.is_active
+ });
+ } else {
+ base.update_status (null);
+ }
+ this.timer_status_changed (status);
+ }
+
+ private uint update_timeout_id;
+ private bool update_status_cb () {
+ TimerBreakStatus? status = this.get_status ();
+ this.update_status (status);
+ return true;
+ }
+
+ private TimerBreakStatus? get_status () {
+ if (this.break_server != null) {
+ try {
+ return this.break_server.get_status ();
+ } catch (IOError error) {
+ GLib.warning ("Error getting break status: %s", error.message);
+ return null;
+ }
+ } else {
+ return null;
+ }
+ }
+
+ private void breakhelper_appeared () {
+ try {
+ this.break_server = Bus.get_proxy_sync (
+ BusType.SESSION,
+ Config.HELPER_BUS_NAME,
+ Config.HELPER_BREAK_OBJECT_BASE_PATH+this.id,
+ DBusProxyFlags.DO_NOT_AUTO_START
+ );
+ // We can only poll the break helper application for updates, so
+ // for responsiveness we update at a faster than normal rate.
+ this.update_timeout_id = Timeout.add (500, this.update_status_cb);
+ this.update_status_cb ();
+ } catch (IOError error) {
+ this.break_server = null;
+ GLib.warning ("Error connecting to break helper service: %s", error.message);
+ }
+ }
+
+ private void breakhelper_disappeared () {
+ if (this.update_timeout_id > 0) {
+ Source.remove (this.update_timeout_id);
+ this.update_timeout_id = 0;
+ }
+ this.break_server = null;
+ this.update_status_cb ();
+ }
}
public abstract class TimerBreakStatusPanel : BreakStatusPanel {
- private string upcoming_text;
- private string ongoing_text;
-
- private CircleCounter circle_counter;
- private Gtk.Label status_label;
- private Gtk.Label time_label;
-
- public TimerBreakStatusPanel (TimerBreakType break_type, string upcoming_text, string ongoing_text) {
- base (break_type);
- this.upcoming_text = upcoming_text;
- this.ongoing_text = ongoing_text;
-
- this.set_column_spacing (12);
-
- // FIXME: This is an application icon. It doesn't make sense here.
- this.circle_counter = new CircleCounter ();
- this.attach (this.circle_counter, 0, 0, 1, 1);
-
- var labels_grid = new Gtk.Grid ();
- this.attach (labels_grid, 1, 0, 1, 1);
- labels_grid.set_orientation (Gtk.Orientation.VERTICAL);
- labels_grid.set_row_spacing (18);
- labels_grid.set_valign (Gtk.Align.CENTER);
-
- this.status_label = new Gtk.Label (null);
- labels_grid.add (this.status_label);
- this.status_label.set_width_chars (25);
- this.status_label.get_style_context ().add_class ("_break-status-heading");
-
- this.time_label = new Gtk.Label (null);
- labels_grid.add (this.time_label);
- this.time_label.set_width_chars (25);
- this.time_label.get_style_context ().add_class ("_break-status-body");
-
- this.show_all ();
-
- break_type.timer_status_changed.connect (this.timer_status_changed_cb);
- }
-
- private void timer_status_changed_cb (TimerBreakStatus? status) {
- if (status == null) return;
-
- TimerBreakType timer_break = (TimerBreakType) this.break_type;
-
- if (status.is_active) {
- this.status_label.set_label (this.ongoing_text);
- string time_text = NaturalTime.instance.get_countdown_for_seconds_with_start (
- status.time_remaining, status.current_duration);
- this.time_label.set_label (time_text);
- this.circle_counter.direction = CircleCounter.Direction.COUNT_DOWN;
- this.circle_counter.progress = (status.current_duration - status.time_remaining) /
(double)status.current_duration;
- } else {
- this.status_label.set_label (this.upcoming_text);
- string time_text = NaturalTime.instance.get_countdown_for_seconds (status.starts_in);
- this.time_label.set_label (time_text);
- this.circle_counter.direction = CircleCounter.Direction.COUNT_UP;
- this.circle_counter.progress = (timer_break.interval - status.starts_in) /
(double)timer_break.interval;
- }
- }
+ private string upcoming_text;
+ private string ongoing_text;
+
+ private CircleCounter circle_counter;
+ private Gtk.Label status_label;
+ private Gtk.Label time_label;
+
+ public TimerBreakStatusPanel (TimerBreakType break_type, string upcoming_text, string ongoing_text) {
+ base (break_type);
+ this.upcoming_text = upcoming_text;
+ this.ongoing_text = ongoing_text;
+
+ this.set_column_spacing (12);
+
+ // FIXME: This is an application icon. It doesn't make sense here.
+ this.circle_counter = new CircleCounter ();
+ this.attach (this.circle_counter, 0, 0, 1, 1);
+
+ var labels_grid = new Gtk.Grid ();
+ this.attach (labels_grid, 1, 0, 1, 1);
+ labels_grid.set_orientation (Gtk.Orientation.VERTICAL);
+ labels_grid.set_row_spacing (18);
+ labels_grid.set_valign (Gtk.Align.CENTER);
+
+ this.status_label = new Gtk.Label (null);
+ labels_grid.add (this.status_label);
+ this.status_label.set_width_chars (25);
+ this.status_label.get_style_context ().add_class ("_break-status-heading");
+
+ this.time_label = new Gtk.Label (null);
+ labels_grid.add (this.time_label);
+ this.time_label.set_width_chars (25);
+ this.time_label.get_style_context ().add_class ("_break-status-body");
+
+ this.show_all ();
+
+ break_type.timer_status_changed.connect (this.timer_status_changed_cb);
+ }
+
+ private void timer_status_changed_cb (TimerBreakStatus? status) {
+ if (status == null) return;
+
+ TimerBreakType timer_break = (TimerBreakType) this.break_type;
+
+ if (status.is_active) {
+ this.status_label.set_label (this.ongoing_text);
+ string time_text = NaturalTime.instance.get_countdown_for_seconds_with_start (
+ status.time_remaining, status.current_duration);
+ this.time_label.set_label (time_text);
+ this.circle_counter.direction = CircleCounter.Direction.COUNT_DOWN;
+ this.circle_counter.progress = (status.current_duration - status.time_remaining) /
(double)status.current_duration;
+ } else {
+ this.status_label.set_label (this.upcoming_text);
+ string time_text = NaturalTime.instance.get_countdown_for_seconds (status.starts_in);
+ this.time_label.set_label (time_text);
+ this.circle_counter.direction = CircleCounter.Direction.COUNT_UP;
+ this.circle_counter.progress = (timer_break.interval - status.starts_in) /
(double)timer_break.interval;
+ }
+ }
}
public abstract class TimerBreakSettingsPanel : BreakSettingsPanel {
- public TimerBreakSettingsPanel (TimerBreakType break_type, string title, string? description) {
- base (break_type, title, description);
-
- var details_grid = new Gtk.Grid ();
- this.set_details (details_grid);
-
- details_grid.set_column_spacing (8);
- details_grid.set_row_spacing (8);
-
- /* Label for the widget to choose how frequently a break occurs. (Choices such as "6 minutes"
or "45 minutes") */
- var interval_label = new Gtk.Label.with_mnemonic ( _("Every"));
- interval_label.set_halign (Gtk.Align.END);
- details_grid.attach (interval_label, 0, 1, 1, 1);
-
- var interval_chooser = new TimeChooser (break_type.interval_options);
- details_grid.attach_next_to (interval_chooser, interval_label, Gtk.PositionType.RIGHT, 1, 1);
- break_type.settings.bind ("interval-seconds", interval_chooser, "time-seconds",
SettingsBindFlags.DEFAULT);
-
- /* Label for the widget to choose how long a break lasts when it occurs. (Choices such as "30
seconds" or "5 minutes") */
- var duration_label = new Gtk.Label.with_mnemonic ( _("For"));
- duration_label.set_halign (Gtk.Align.END);
- details_grid.attach (duration_label, 0, 2, 1, 1);
-
- var duration_chooser = new TimeChooser (break_type.duration_options);
- details_grid.attach_next_to (duration_chooser, duration_label, Gtk.PositionType.RIGHT, 1, 1);
- break_type.settings.bind ("duration-seconds", duration_chooser, "time-seconds",
SettingsBindFlags.DEFAULT);
-
- details_grid.show_all ();
- }
+ public TimerBreakSettingsPanel (TimerBreakType break_type, string title, string? description) {
+ base (break_type, title, description);
+
+ var details_grid = new Gtk.Grid ();
+ this.set_details (details_grid);
+
+ details_grid.set_column_spacing (8);
+ details_grid.set_row_spacing (8);
+
+ /* Label for the widget to choose how frequently a break occurs. (Choices such as "6 minutes" or "45
minutes") */
+ var interval_label = new Gtk.Label.with_mnemonic ( _("Every"));
+ interval_label.set_halign (Gtk.Align.END);
+ details_grid.attach (interval_label, 0, 1, 1, 1);
+
+ var interval_chooser = new TimeChooser (break_type.interval_options);
+ details_grid.attach_next_to (interval_chooser, interval_label, Gtk.PositionType.RIGHT, 1, 1);
+ break_type.settings.bind ("interval-seconds", interval_chooser, "time-seconds",
SettingsBindFlags.DEFAULT);
+
+ /* Label for the widget to choose how long a break lasts when it occurs. (Choices such as "30
seconds" or "5 minutes") */
+ var duration_label = new Gtk.Label.with_mnemonic ( _("For"));
+ duration_label.set_halign (Gtk.Align.END);
+ details_grid.attach (duration_label, 0, 2, 1, 1);
+
+ var duration_chooser = new TimeChooser (break_type.duration_options);
+ details_grid.attach_next_to (duration_chooser, duration_label, Gtk.PositionType.RIGHT, 1, 1);
+ break_type.settings.bind ("duration-seconds", duration_chooser, "time-seconds",
SettingsBindFlags.DEFAULT);
+
+ details_grid.show_all ();
+ }
}
}
diff --git a/settings/main.vala b/settings/main.vala
index c5414ea..1a9afc5 100644
--- a/settings/main.vala
+++ b/settings/main.vala
@@ -18,9 +18,9 @@
namespace BreakTimer.Settings {
public int main (string[] args) {
- SettingsApplication application = new SettingsApplication ();
- int status = application.run (args);
- return status;
+ SettingsApplication application = new SettingsApplication ();
+ int status = application.run (args);
+ return status;
}
}
diff --git a/tests/activity-monitor/activity-monitor_runner.vala
b/tests/activity-monitor/activity-monitor_runner.vala
index bfc59c9..438264e 100644
--- a/tests/activity-monitor/activity-monitor_runner.vala
+++ b/tests/activity-monitor/activity-monitor_runner.vala
@@ -16,7 +16,7 @@
*/
public static int main (string[] args) {
- var runner = new TestRunner (ref args);
- runner.add (new test_ActivityMonitor ());
- return runner.run ();
+ var runner = new TestRunner (ref args);
+ runner.add (new test_ActivityMonitor ());
+ return runner.run ();
}
diff --git a/tests/activity-monitor/test_ActivityMonitor.vala
b/tests/activity-monitor/test_ActivityMonitor.vala
index e10ff22..73e04b6 100644
--- a/tests/activity-monitor/test_ActivityMonitor.vala
+++ b/tests/activity-monitor/test_ActivityMonitor.vala
@@ -16,178 +16,178 @@
*/
public class test_ActivityMonitor : TestSuiteWithActivityMonitor {
- public test_ActivityMonitor () {
- new test_simple_idle ().add_to (this);
- new test_simple_active ().add_to (this);
- new test_lock_idle ().add_to (this);
- new test_active_then_idle ().add_to (this);
- new test_sleep_and_unlock ().add_to (this);
- new test_unlock_signal_activity ().add_to (this);
- }
+ public test_ActivityMonitor () {
+ new test_simple_idle ().add_to (this);
+ new test_simple_active ().add_to (this);
+ new test_lock_idle ().add_to (this);
+ new test_active_then_idle ().add_to (this);
+ new test_sleep_and_unlock ().add_to (this);
+ new test_unlock_signal_activity ().add_to (this);
+ }
- class test_simple_idle : Object, SimpleTestCase<test_ActivityMonitor> {
- public void run (test_ActivityMonitor context) {
- context.session_status.virt_is_locked = false;
- context.time_step (false, 0, 0);
- context.time_step (false, 1, 1);
+ class test_simple_idle : Object, SimpleTestCase<test_ActivityMonitor> {
+ public void run (test_ActivityMonitor context) {
+ context.session_status.virt_is_locked = false;
+ context.time_step (false, 0, 0);
+ context.time_step (false, 1, 1);
- assert (context.activity_log.size == 2);
+ assert (context.activity_log.size == 2);
- assert (context.activity_log[0].type == ActivityMonitor.ActivityType.NONE);
- assert (context.activity_log[0].is_active () == false);
- assert (context.activity_log[0].idle_time == 10);
+ assert (context.activity_log[0].type == ActivityMonitor.ActivityType.NONE);
+ assert (context.activity_log[0].is_active () == false);
+ assert (context.activity_log[0].idle_time == 10);
- assert (context.activity_log[1].type == ActivityMonitor.ActivityType.NONE);
- assert (context.activity_log[1].is_active () == false);
- assert (context.activity_log[1].idle_time == context.activity_log[0].idle_time + 1);
- }
- }
+ assert (context.activity_log[1].type == ActivityMonitor.ActivityType.NONE);
+ assert (context.activity_log[1].is_active () == false);
+ assert (context.activity_log[1].idle_time == context.activity_log[0].idle_time + 1);
+ }
+ }
- class test_simple_active : Object, SimpleTestCase<test_ActivityMonitor> {
- public void run (test_ActivityMonitor context) {
- context.session_status.virt_is_locked = false;
- context.time_step (true, 1, 1);
+ class test_simple_active : Object, SimpleTestCase<test_ActivityMonitor> {
+ public void run (test_ActivityMonitor context) {
+ context.session_status.virt_is_locked = false;
+ context.time_step (true, 1, 1);
- context.time_step (true, 1, 1);
+ context.time_step (true, 1, 1);
- context.time_step (true, 1, 1);
+ context.time_step (true, 1, 1);
- assert (context.activity_log.size == 3);
+ assert (context.activity_log.size == 3);
- assert (context.activity_log[0].type == ActivityMonitor.ActivityType.INPUT);
- assert (context.activity_log[0].is_active () == true);
- assert (context.activity_log[0].idle_time == 0);
+ assert (context.activity_log[0].type == ActivityMonitor.ActivityType.INPUT);
+ assert (context.activity_log[0].is_active () == true);
+ assert (context.activity_log[0].idle_time == 0);
- assert (context.activity_log[1].type == ActivityMonitor.ActivityType.INPUT);
- assert (context.activity_log[1].is_active () == true);
- assert (context.activity_log[1].idle_time == 0);
+ assert (context.activity_log[1].type == ActivityMonitor.ActivityType.INPUT);
+ assert (context.activity_log[1].is_active () == true);
+ assert (context.activity_log[1].idle_time == 0);
- assert (context.activity_log[2].type == ActivityMonitor.ActivityType.INPUT);
- assert (context.activity_log[2].is_active () == true);
- assert (context.activity_log[2].idle_time == 0);
- }
- }
+ assert (context.activity_log[2].type == ActivityMonitor.ActivityType.INPUT);
+ assert (context.activity_log[2].is_active () == true);
+ assert (context.activity_log[2].idle_time == 0);
+ }
+ }
- class test_active_then_idle : Object, SimpleTestCase<test_ActivityMonitor> {
- public void run (test_ActivityMonitor context) {
- context.session_status.virt_is_locked = false;
- context.time_step (true, 1, 1);
+ class test_active_then_idle : Object, SimpleTestCase<test_ActivityMonitor> {
+ public void run (test_ActivityMonitor context) {
+ context.session_status.virt_is_locked = false;
+ context.time_step (true, 1, 1);
- context.time_step (false, 1, 1);
+ context.time_step (false, 1, 1);
- context.time_step (false, 1, 1);
+ context.time_step (false, 1, 1);
- context.time_step (true, 1, 1);
+ context.time_step (true, 1, 1);
- context.time_step (true, 1, 1);
+ context.time_step (true, 1, 1);
- assert (context.activity_log.size == 5);
+ assert (context.activity_log.size == 5);
- assert (context.activity_log[0].type == ActivityMonitor.ActivityType.INPUT);
- assert (context.activity_log[0].is_active () == true);
- assert (context.activity_log[0].idle_time == 0);
+ assert (context.activity_log[0].type == ActivityMonitor.ActivityType.INPUT);
+ assert (context.activity_log[0].is_active () == true);
+ assert (context.activity_log[0].idle_time == 0);
- assert (context.activity_log[1].type == ActivityMonitor.ActivityType.NONE);
- assert (context.activity_log[1].is_active () == false);
- assert (context.activity_log[1].idle_time == 1);
- assert (context.activity_log[1].time_since_active == 1);
+ assert (context.activity_log[1].type == ActivityMonitor.ActivityType.NONE);
+ assert (context.activity_log[1].is_active () == false);
+ assert (context.activity_log[1].idle_time == 1);
+ assert (context.activity_log[1].time_since_active == 1);
- assert (context.activity_log[2].type == ActivityMonitor.ActivityType.NONE);
- assert (context.activity_log[2].is_active () == false);
- assert (context.activity_log[2].idle_time == 2);
- assert (context.activity_log[2].time_since_active == 2);
+ assert (context.activity_log[2].type == ActivityMonitor.ActivityType.NONE);
+ assert (context.activity_log[2].is_active () == false);
+ assert (context.activity_log[2].idle_time == 2);
+ assert (context.activity_log[2].time_since_active == 2);
- assert (context.activity_log[3].type == ActivityMonitor.ActivityType.INPUT);
- assert (context.activity_log[3].is_active () == true);
- assert (context.activity_log[3].idle_time == 0);
- assert (context.activity_log[3].time_since_active == 3);
+ assert (context.activity_log[3].type == ActivityMonitor.ActivityType.INPUT);
+ assert (context.activity_log[3].is_active () == true);
+ assert (context.activity_log[3].idle_time == 0);
+ assert (context.activity_log[3].time_since_active == 3);
- assert (context.activity_log[4].type == ActivityMonitor.ActivityType.INPUT);
- assert (context.activity_log[4].is_active () == true);
- assert (context.activity_log[4].idle_time == 0);
- assert (context.activity_log[4].time_since_active == 1);
- }
- }
+ assert (context.activity_log[4].type == ActivityMonitor.ActivityType.INPUT);
+ assert (context.activity_log[4].is_active () == true);
+ assert (context.activity_log[4].idle_time == 0);
+ assert (context.activity_log[4].time_since_active == 1);
+ }
+ }
- class test_lock_idle : Object, SimpleTestCase<test_ActivityMonitor> {
- public void run (test_ActivityMonitor context) {
- context.session_status.virt_is_locked = true;
- context.time_step (true, 1, 1);
+ class test_lock_idle : Object, SimpleTestCase<test_ActivityMonitor> {
+ public void run (test_ActivityMonitor context) {
+ context.session_status.virt_is_locked = true;
+ context.time_step (true, 1, 1);
- context.time_step (true, 1, 1);
+ context.time_step (true, 1, 1);
- context.time_step (false, 1, 1);
+ context.time_step (false, 1, 1);
- assert (context.activity_log.size == 3);
+ assert (context.activity_log.size == 3);
- assert (context.activity_log[0].type == ActivityMonitor.ActivityType.LOCKED);
- assert (context.activity_log[0].is_active () == false);
- assert (context.activity_log[0].idle_time == 0);
+ assert (context.activity_log[0].type == ActivityMonitor.ActivityType.LOCKED);
+ assert (context.activity_log[0].is_active () == false);
+ assert (context.activity_log[0].idle_time == 0);
- assert (context.activity_log[1].type == ActivityMonitor.ActivityType.LOCKED);
- assert (context.activity_log[1].is_active () == false);
- assert (context.activity_log[1].idle_time == 0);
+ assert (context.activity_log[1].type == ActivityMonitor.ActivityType.LOCKED);
+ assert (context.activity_log[1].is_active () == false);
+ assert (context.activity_log[1].idle_time == 0);
- assert (context.activity_log[2].type == ActivityMonitor.ActivityType.LOCKED);
- assert (context.activity_log[2].is_active () == false);
- assert (context.activity_log[2].idle_time == 1);
- }
- }
+ assert (context.activity_log[2].type == ActivityMonitor.ActivityType.LOCKED);
+ assert (context.activity_log[2].is_active () == false);
+ assert (context.activity_log[2].idle_time == 1);
+ }
+ }
- class test_sleep_and_unlock : Object, SimpleTestCase<test_ActivityMonitor> {
- public void run (test_ActivityMonitor context) {
- context.session_status.virt_is_locked = false;
- context.time_step (true, 1, 1);
+ class test_sleep_and_unlock : Object, SimpleTestCase<test_ActivityMonitor> {
+ public void run (test_ActivityMonitor context) {
+ context.session_status.virt_is_locked = false;
+ context.time_step (true, 1, 1);
- context.session_status.virt_is_locked = true;
- context.time_step (true, 120, 2);
+ context.session_status.virt_is_locked = true;
+ context.time_step (true, 120, 2);
- context.time_step (true, 1, 1);
+ context.time_step (true, 1, 1);
- context.session_status.virt_is_locked = false;
- context.time_step (true, 1, 1);
+ context.session_status.virt_is_locked = false;
+ context.time_step (true, 1, 1);
- assert (context.activity_log.size == 4);
+ assert (context.activity_log.size == 4);
- assert (context.activity_log[0].type == ActivityMonitor.ActivityType.INPUT);
- assert (context.activity_log[0].is_active () == true);
- assert (context.activity_log[0].idle_time == 0);
- assert (context.activity_log[0].time_correction == 0);
+ assert (context.activity_log[0].type == ActivityMonitor.ActivityType.INPUT);
+ assert (context.activity_log[0].is_active () == true);
+ assert (context.activity_log[0].idle_time == 0);
+ assert (context.activity_log[0].time_correction == 0);
- assert (context.activity_log[1].type == ActivityMonitor.ActivityType.SLEEP);
- assert (context.activity_log[1].is_active () == false);
- assert (context.activity_log[1].time_since_active == 120);
- assert (context.activity_log[1].idle_time == 0);
- assert (context.activity_log[1].time_correction == 120-2);
+ assert (context.activity_log[1].type == ActivityMonitor.ActivityType.SLEEP);
+ assert (context.activity_log[1].is_active () == false);
+ assert (context.activity_log[1].time_since_active == 120);
+ assert (context.activity_log[1].idle_time == 0);
+ assert (context.activity_log[1].time_correction == 120-2);
- assert (context.activity_log[2].type == ActivityMonitor.ActivityType.LOCKED);
- assert (context.activity_log[2].is_active () == false);
- assert (context.activity_log[2].idle_time == 0);
- assert (context.activity_log[2].time_correction == 0);
+ assert (context.activity_log[2].type == ActivityMonitor.ActivityType.LOCKED);
+ assert (context.activity_log[2].is_active () == false);
+ assert (context.activity_log[2].idle_time == 0);
+ assert (context.activity_log[2].time_correction == 0);
- assert (context.activity_log[3].type == ActivityMonitor.ActivityType.INPUT);
- assert (context.activity_log[3].is_active () == true);
- assert (context.activity_log[3].idle_time == 0);
- assert (context.activity_log[3].time_correction == 0);
- }
- }
+ assert (context.activity_log[3].type == ActivityMonitor.ActivityType.INPUT);
+ assert (context.activity_log[3].is_active () == true);
+ assert (context.activity_log[3].idle_time == 0);
+ assert (context.activity_log[3].time_correction == 0);
+ }
+ }
- class test_unlock_signal_activity : Object, SimpleTestCase<test_ActivityMonitor> {
- public void run (test_ActivityMonitor context) {
- context.session_status.virt_is_locked = true;
- context.time_step (true, 1, 1);
+ class test_unlock_signal_activity : Object, SimpleTestCase<test_ActivityMonitor> {
+ public void run (test_ActivityMonitor context) {
+ context.session_status.virt_is_locked = true;
+ context.time_step (true, 1, 1);
- context.session_status.do_unlock ();
+ context.session_status.do_unlock ();
- assert (context.activity_log.size == 2);
+ assert (context.activity_log.size == 2);
- assert (context.activity_log[0].type == ActivityMonitor.ActivityType.LOCKED);
- assert (context.activity_log[0].is_active () == false);
- assert (context.activity_log[0].idle_time == 0);
-
- assert (context.activity_log[1].type == ActivityMonitor.ActivityType.UNLOCK);
- assert (context.activity_log[1].is_active () == true);
- assert (context.activity_log[1].idle_time == 0);
- }
- }
+ assert (context.activity_log[0].type == ActivityMonitor.ActivityType.LOCKED);
+ assert (context.activity_log[0].is_active () == false);
+ assert (context.activity_log[0].idle_time == 0);
+
+ assert (context.activity_log[1].type == ActivityMonitor.ActivityType.UNLOCK);
+ assert (context.activity_log[1].is_active () == true);
+ assert (context.activity_log[1].idle_time == 0);
+ }
+ }
}
\ No newline at end of file
diff --git a/tests/breaks/breaks_runner.vala b/tests/breaks/breaks_runner.vala
index dd928c1..e12285c 100644
--- a/tests/breaks/breaks_runner.vala
+++ b/tests/breaks/breaks_runner.vala
@@ -16,7 +16,7 @@
*/
public static int main (string[] args) {
- var runner = new TestRunner (ref args);
- runner.add (new test_TimerBreakController ());
- return runner.run ();
+ var runner = new TestRunner (ref args);
+ runner.add (new test_TimerBreakController ());
+ return runner.run ();
}
diff --git a/tests/breaks/test_TimerBreakController.vala b/tests/breaks/test_TimerBreakController.vala
index aae3d5d..b6f5fbc 100644
--- a/tests/breaks/test_TimerBreakController.vala
+++ b/tests/breaks/test_TimerBreakController.vala
@@ -16,305 +16,305 @@
*/
public class test_TimerBreakController : TestSuiteWithActivityMonitor {
- public const int DEFAULT_INTERVAL = 360;
- public const int DEFAULT_DURATION = 30;
-
- public testable_TimerBreakController break_controller;
- public Gee.List<string> break_log;
- public Gee.List<string> break_timestep_log;
-
- public test_TimerBreakController () {
- new test_start_disabled ().add_to (this);
- new test_enable_and_idle ().add_to (this);
- new test_enable_and_active ().add_to (this);
- new test_force_activate ().add_to (this);
- new test_postpone ().add_to (this);
- new test_serialize ().add_to (this);
- }
-
- public override void setup () {
- this.break_log = new Gee.ArrayList<string> ();
- this.break_timestep_log = new Gee.ArrayList<string> ();
-
- base.setup ();
- }
-
- private void log_break_message (string message) {
- this.break_log.add (message);
- this.break_timestep_log.add (message);
- }
-
- public Json.Object save_state () {
- Json.Object root_object = new Json.Object ();
- root_object.set_object_member ("break_controller", this.break_controller.serialize ());
- root_object.set_object_member ("activity_monitor_backend",
this.activity_monitor_backend.serialize ());
- root_object.set_object_member ("activity_monitor", this.activity_monitor.serialize ());
- return root_object;
- }
-
- public void restore_state (ref Json.Object root_object) {
- this.refresh_environment ();
-
- Json.Object break_controller_json = root_object.get_object_member ("break_controller");
- this.break_controller.deserialize (ref break_controller_json);
-
- Json.Object activity_monitor_backend_json = root_object.get_object_member
("activity_monitor_backend");
- this.activity_monitor_backend.deserialize (ref activity_monitor_backend_json);
-
- Json.Object activity_monitor_json = root_object.get_object_member ("activity_monitor");
- this.activity_monitor.deserialize (ref activity_monitor_json);
-
- this.activity_monitor.poll_activity ();
- }
-
- public override void refresh_environment () {
- base.refresh_environment ();
-
- this.break_log.clear ();
- this.break_timestep_log.clear ();
-
- this.break_controller = new testable_TimerBreakController (this.activity_monitor);
- this.break_controller.interval = DEFAULT_INTERVAL;
- this.break_controller.duration = DEFAULT_DURATION;
- this.break_controller.set_enabled (true);
-
- this.break_controller.enabled.connect ( () => { this.log_break_message ("enabled"); } );
- this.break_controller.disabled.connect ( () => { this.log_break_message ("disabled"); } );
- this.break_controller.warned.connect ( () => { this.log_break_message ("warned"); } );
- this.break_controller.unwarned.connect ( () => { this.log_break_message ("unwarned"); } );
- this.break_controller.activated.connect ( () => { this.log_break_message ("activated"); } );
- this.break_controller.finished.connect ( () => { this.log_break_message ("finished"); } );
-
- this.break_controller.counting.connect ( () => { this.log_break_message ("counting"); } );
- this.break_controller.delayed.connect ( () => { this.log_break_message ("delayed"); } );
- }
-
- public override void time_step (bool is_active, int real_seconds, int monotonic_seconds) {
- this.break_timestep_log.clear ();
- base.time_step (is_active, real_seconds, monotonic_seconds);
- this.break_controller.time_step (real_seconds, monotonic_seconds);
- }
-
- public class testable_TimerBreakController : TimerBreakController {
- public testable_TimerBreakController (ActivityMonitor activity_monitor) {
- base (activity_monitor, 0);
- }
-
- public void time_step (int real_seconds, int monotonic_seconds) {
- this.countdowns_timeout.run_once ();
- }
-
- public void assert_timers (int? starts_in, int? remaining) {
- if (starts_in != null) assert (this.starts_in () == starts_in);
- if (remaining != null) assert (this.get_time_remaining () == remaining);
- }
- }
-
- class test_start_disabled : Object, SimpleTestCase<test_TimerBreakController> {
- public void run (test_TimerBreakController context) {
- context.break_controller.set_enabled (false);
-
- assert (context.break_controller.is_enabled () == false);
- assert (context.break_controller.is_active () == false);
- assert (context.break_controller.get_seconds_since_start () == 0);
- context.break_controller.assert_timers (test_TimerBreakController.DEFAULT_INTERVAL,
test_TimerBreakController.DEFAULT_DURATION);
-
- context.break_controller.activate ();
-
- assert (context.break_controller.is_enabled () == false);
- assert (context.break_log.last () == "disabled");
- }
- }
-
- class test_enable_and_idle : Object, SimpleTestCase<test_TimerBreakController> {
- public void run (test_TimerBreakController context) {
- // break_controller is enabled by default (emulating the behaviour of BreakManager
with default settings)
- assert (context.break_controller.is_enabled ());
-
- int expected_starts_in = test_TimerBreakController.DEFAULT_INTERVAL;
- int expected_remaining = test_TimerBreakController.DEFAULT_DURATION;
-
- context.time_step (true, 1, 1);
- expected_starts_in -= 1;
- context.break_controller.assert_timers (expected_starts_in, expected_remaining);
-
- for (int step = 0; step <= test_TimerBreakController.DEFAULT_DURATION; step++) {
- context.time_step (false, 1, 1);
- assert (context.break_timestep_log[0] == "counting");
- if (step == test_TimerBreakController.DEFAULT_DURATION) {
- assert (context.break_timestep_log[1] == "finished");
- }
- }
- expected_starts_in = test_TimerBreakController.DEFAULT_INTERVAL;
- expected_remaining = test_TimerBreakController.DEFAULT_DURATION;
- context.break_controller.assert_timers (expected_starts_in, expected_remaining);
-
- for (int step = 0; step < test_TimerBreakController.DEFAULT_INTERVAL; step++) {
- context.time_step (false, 1, 1);
- assert (context.break_timestep_log[0] == "counting");
- }
- context.break_controller.assert_timers (expected_starts_in, expected_remaining);
- }
- }
-
- class test_enable_and_active : Object, SimpleTestCase<test_TimerBreakController> {
- public void run (test_TimerBreakController context) {
- int expected_starts_in = test_TimerBreakController.DEFAULT_INTERVAL;
- int expected_remaining = test_TimerBreakController.DEFAULT_DURATION;
-
- var active_time_1 = 20;
- for (int step = 0; step < active_time_1; step++) {
- context.time_step (true, 1, 1);
- assert (context.break_timestep_log[0] == "delayed");
- }
- expected_starts_in -= active_time_1;
- context.break_controller.assert_timers (expected_starts_in, expected_remaining);
-
- var idle_time_1 = 10;
- for (int step = 0; step <= idle_time_1; step++) {
- context.time_step (false, 1, 1);
- assert (context.break_timestep_log[0] == "counting");
- }
- expected_starts_in -= 1;
- expected_remaining -= idle_time_1;
- context.break_controller.assert_timers (expected_starts_in, expected_remaining);
-
- var active_time_2 = test_TimerBreakController.DEFAULT_INTERVAL - active_time_1;
- var warn_step = active_time_2 - test_TimerBreakController.DEFAULT_DURATION - 1;
- for (int step = 0; step < active_time_2; step++) {
- context.time_step (true, 1, 1);
- assert (context.break_timestep_log[0] == "delayed");
- if (step == warn_step) {
- assert (context.break_timestep_log[1] == "warned");
- } else if (step == active_time_2-1) {
- assert (context.break_timestep_log[1] == "activated");
- }
- }
- expected_starts_in = 0;
- expected_remaining -= 1;
- context.break_controller.assert_timers (expected_starts_in, expected_remaining);
-
- for (int step = 0; step < 5; step++) {
- context.time_step (false, 1, 1);
- assert (context.break_timestep_log[0] == "counting");
- }
- expected_remaining -= 5;
- context.break_controller.assert_timers (expected_starts_in, expected_remaining);
-
- for (int step = 0; step < expected_remaining; step++) {
- context.time_step (false, 1, 1);
- assert (context.break_timestep_log[0] == "counting");
- if (step == expected_remaining-1) {
- assert (context.break_timestep_log[1] == "finished");
- }
- }
- expected_starts_in = test_TimerBreakController.DEFAULT_INTERVAL;
- expected_remaining = test_TimerBreakController.DEFAULT_DURATION;
- context.break_controller.assert_timers (expected_starts_in, expected_remaining);
- }
- }
-
- class test_force_activate : Object, SimpleTestCase<test_TimerBreakController> {
- public void run (test_TimerBreakController context) {
- int expected_remaining = test_TimerBreakController.DEFAULT_DURATION;
-
- context.break_controller.activate ();
- assert (context.break_log.last () == "activated");
-
- assert (context.break_controller.get_seconds_since_start () == 0);
- context.break_controller.assert_timers (null, expected_remaining);
-
- for (int step = 0; step < 10; step++) {
- context.time_step (false, 1, 1);
- }
- expected_remaining -= 10;
- context.break_controller.assert_timers (null, expected_remaining);
- }
- }
-
- class test_postpone : Object, SimpleTestCase<test_TimerBreakController> {
- public void run (test_TimerBreakController context) {
- int expected_starts_in = test_TimerBreakController.DEFAULT_INTERVAL;
- int expected_remaining = test_TimerBreakController.DEFAULT_DURATION;
-
- context.break_controller.activate ();
- for (int step = 0; step < 10; step++) {
- context.time_step (false, 1, 1);
- }
- expected_remaining -= 10;
- context.break_controller.assert_timers (null, expected_remaining);
- assert (context.break_controller.get_seconds_since_start () == 10);
-
- context.break_controller.postpone (60);
- expected_starts_in = 60;
- expected_remaining = test_TimerBreakController.DEFAULT_DURATION;
- assert (context.break_controller.is_active () == false);
- context.break_controller.assert_timers (expected_starts_in, expected_remaining);
-
- for (int step = 0; step < expected_starts_in; step++) {
- context.time_step (true, 1, 1);
- if (step == expected_starts_in-1) {
- assert (context.break_timestep_log[1] == "activated");
- }
- }
- expected_starts_in = 0;
- expected_remaining = test_TimerBreakController.DEFAULT_DURATION;
- assert (context.break_controller.is_active () == true);
- context.break_controller.assert_timers (expected_starts_in, expected_remaining);
- }
- }
-
- class test_serialize : Object, SimpleTestCase<test_TimerBreakController> {
- public void run (test_TimerBreakController context) {
- var initial_json = context.save_state ();
-
- for (int step = 0; step < 50; step++) {
- context.time_step (true, 1, 1);
- }
- assert (context.break_controller.is_active () == false);
- context.break_controller.assert_timers (test_TimerBreakController.DEFAULT_INTERVAL -
50, test_TimerBreakController.DEFAULT_DURATION);
- var active_waiting_json = context.save_state ();
-
- for (int step = 50; step < test_TimerBreakController.DEFAULT_INTERVAL; step++) {
- context.time_step (true, 1, 1);
- }
- assert (context.break_controller.is_active () == true);
- context.break_controller.assert_timers (0,
test_TimerBreakController.DEFAULT_DURATION);
- var activated_json = context.save_state ();
-
- for (int step = 0; step < 10; step++) {
- context.time_step (false, 1, 1);
- }
- assert (context.break_controller.is_active () == true);
- context.break_controller.assert_timers (0,
test_TimerBreakController.DEFAULT_DURATION-10);
- var counting_json = context.save_state ();
-
- context.time_step (true, 0, 0);
- for (int step = 0; step < 10; step++) {
- context.time_step (true, 1, 1);
- }
- assert (context.break_controller.is_active () == true);
- context.break_controller.assert_timers (0,
test_TimerBreakController.DEFAULT_DURATION-10);
-
- context.restore_state (ref initial_json);
- assert (context.break_controller.is_active () == false);
- context.break_controller.assert_timers (test_TimerBreakController.DEFAULT_INTERVAL,
test_TimerBreakController.DEFAULT_DURATION);
-
- context.restore_state (ref counting_json);
- assert (context.break_controller.is_active () == true);
- context.break_controller.assert_timers (0,
test_TimerBreakController.DEFAULT_DURATION-10);
-
- context.restore_state (ref active_waiting_json);
- assert (context.break_controller.is_active () == false);
- // The state was saved more than break duration ago, so it is immediately finished.
- context.break_controller.assert_timers (test_TimerBreakController.DEFAULT_INTERVAL,
test_TimerBreakController.DEFAULT_DURATION);
-
- context.restore_state (ref activated_json);
- assert (context.break_controller.is_active () == true);
- // 20 seconds have passed since the break was activated. The application should
assume all this time was spent idle.
- // Note that this will not happen with a gap smaller than 10+5 seconds, because
ActivityMonitor ignores detected
- // "sleep" time below 5 seconds + detected idle time (which is, initially, 10
seconds).
- context.break_controller.assert_timers (0,
test_TimerBreakController.DEFAULT_DURATION-20);
- }
- }
+ public const int DEFAULT_INTERVAL = 360;
+ public const int DEFAULT_DURATION = 30;
+
+ public testable_TimerBreakController break_controller;
+ public Gee.List<string> break_log;
+ public Gee.List<string> break_timestep_log;
+
+ public test_TimerBreakController () {
+ new test_start_disabled ().add_to (this);
+ new test_enable_and_idle ().add_to (this);
+ new test_enable_and_active ().add_to (this);
+ new test_force_activate ().add_to (this);
+ new test_postpone ().add_to (this);
+ new test_serialize ().add_to (this);
+ }
+
+ public override void setup () {
+ this.break_log = new Gee.ArrayList<string> ();
+ this.break_timestep_log = new Gee.ArrayList<string> ();
+
+ base.setup ();
+ }
+
+ private void log_break_message (string message) {
+ this.break_log.add (message);
+ this.break_timestep_log.add (message);
+ }
+
+ public Json.Object save_state () {
+ Json.Object root_object = new Json.Object ();
+ root_object.set_object_member ("break_controller", this.break_controller.serialize ());
+ root_object.set_object_member ("activity_monitor_backend", this.activity_monitor_backend.serialize
());
+ root_object.set_object_member ("activity_monitor", this.activity_monitor.serialize ());
+ return root_object;
+ }
+
+ public void restore_state (ref Json.Object root_object) {
+ this.refresh_environment ();
+
+ Json.Object break_controller_json = root_object.get_object_member ("break_controller");
+ this.break_controller.deserialize (ref break_controller_json);
+
+ Json.Object activity_monitor_backend_json = root_object.get_object_member
("activity_monitor_backend");
+ this.activity_monitor_backend.deserialize (ref activity_monitor_backend_json);
+
+ Json.Object activity_monitor_json = root_object.get_object_member ("activity_monitor");
+ this.activity_monitor.deserialize (ref activity_monitor_json);
+
+ this.activity_monitor.poll_activity ();
+ }
+
+ public override void refresh_environment () {
+ base.refresh_environment ();
+
+ this.break_log.clear ();
+ this.break_timestep_log.clear ();
+
+ this.break_controller = new testable_TimerBreakController (this.activity_monitor);
+ this.break_controller.interval = DEFAULT_INTERVAL;
+ this.break_controller.duration = DEFAULT_DURATION;
+ this.break_controller.set_enabled (true);
+
+ this.break_controller.enabled.connect ( () => { this.log_break_message ("enabled"); } );
+ this.break_controller.disabled.connect ( () => { this.log_break_message ("disabled"); } );
+ this.break_controller.warned.connect ( () => { this.log_break_message ("warned"); } );
+ this.break_controller.unwarned.connect ( () => { this.log_break_message ("unwarned"); } );
+ this.break_controller.activated.connect ( () => { this.log_break_message ("activated"); } );
+ this.break_controller.finished.connect ( () => { this.log_break_message ("finished"); } );
+
+ this.break_controller.counting.connect ( () => { this.log_break_message ("counting"); } );
+ this.break_controller.delayed.connect ( () => { this.log_break_message ("delayed"); } );
+ }
+
+ public override void time_step (bool is_active, int real_seconds, int monotonic_seconds) {
+ this.break_timestep_log.clear ();
+ base.time_step (is_active, real_seconds, monotonic_seconds);
+ this.break_controller.time_step (real_seconds, monotonic_seconds);
+ }
+
+ public class testable_TimerBreakController : TimerBreakController {
+ public testable_TimerBreakController (ActivityMonitor activity_monitor) {
+ base (activity_monitor, 0);
+ }
+
+ public void time_step (int real_seconds, int monotonic_seconds) {
+ this.countdowns_timeout.run_once ();
+ }
+
+ public void assert_timers (int? starts_in, int? remaining) {
+ if (starts_in != null) assert (this.starts_in () == starts_in);
+ if (remaining != null) assert (this.get_time_remaining () == remaining);
+ }
+ }
+
+ class test_start_disabled : Object, SimpleTestCase<test_TimerBreakController> {
+ public void run (test_TimerBreakController context) {
+ context.break_controller.set_enabled (false);
+
+ assert (context.break_controller.is_enabled () == false);
+ assert (context.break_controller.is_active () == false);
+ assert (context.break_controller.get_seconds_since_start () == 0);
+ context.break_controller.assert_timers (test_TimerBreakController.DEFAULT_INTERVAL,
test_TimerBreakController.DEFAULT_DURATION);
+
+ context.break_controller.activate ();
+
+ assert (context.break_controller.is_enabled () == false);
+ assert (context.break_log.last () == "disabled");
+ }
+ }
+
+ class test_enable_and_idle : Object, SimpleTestCase<test_TimerBreakController> {
+ public void run (test_TimerBreakController context) {
+ // break_controller is enabled by default (emulating the behaviour of BreakManager with default
settings)
+ assert (context.break_controller.is_enabled ());
+
+ int expected_starts_in = test_TimerBreakController.DEFAULT_INTERVAL;
+ int expected_remaining = test_TimerBreakController.DEFAULT_DURATION;
+
+ context.time_step (true, 1, 1);
+ expected_starts_in -= 1;
+ context.break_controller.assert_timers (expected_starts_in, expected_remaining);
+
+ for (int step = 0; step <= test_TimerBreakController.DEFAULT_DURATION; step++) {
+ context.time_step (false, 1, 1);
+ assert (context.break_timestep_log[0] == "counting");
+ if (step == test_TimerBreakController.DEFAULT_DURATION) {
+ assert (context.break_timestep_log[1] == "finished");
+ }
+ }
+ expected_starts_in = test_TimerBreakController.DEFAULT_INTERVAL;
+ expected_remaining = test_TimerBreakController.DEFAULT_DURATION;
+ context.break_controller.assert_timers (expected_starts_in, expected_remaining);
+
+ for (int step = 0; step < test_TimerBreakController.DEFAULT_INTERVAL; step++) {
+ context.time_step (false, 1, 1);
+ assert (context.break_timestep_log[0] == "counting");
+ }
+ context.break_controller.assert_timers (expected_starts_in, expected_remaining);
+ }
+ }
+
+ class test_enable_and_active : Object, SimpleTestCase<test_TimerBreakController> {
+ public void run (test_TimerBreakController context) {
+ int expected_starts_in = test_TimerBreakController.DEFAULT_INTERVAL;
+ int expected_remaining = test_TimerBreakController.DEFAULT_DURATION;
+
+ var active_time_1 = 20;
+ for (int step = 0; step < active_time_1; step++) {
+ context.time_step (true, 1, 1);
+ assert (context.break_timestep_log[0] == "delayed");
+ }
+ expected_starts_in -= active_time_1;
+ context.break_controller.assert_timers (expected_starts_in, expected_remaining);
+
+ var idle_time_1 = 10;
+ for (int step = 0; step <= idle_time_1; step++) {
+ context.time_step (false, 1, 1);
+ assert (context.break_timestep_log[0] == "counting");
+ }
+ expected_starts_in -= 1;
+ expected_remaining -= idle_time_1;
+ context.break_controller.assert_timers (expected_starts_in, expected_remaining);
+
+ var active_time_2 = test_TimerBreakController.DEFAULT_INTERVAL - active_time_1;
+ var warn_step = active_time_2 - test_TimerBreakController.DEFAULT_DURATION - 1;
+ for (int step = 0; step < active_time_2; step++) {
+ context.time_step (true, 1, 1);
+ assert (context.break_timestep_log[0] == "delayed");
+ if (step == warn_step) {
+ assert (context.break_timestep_log[1] == "warned");
+ } else if (step == active_time_2-1) {
+ assert (context.break_timestep_log[1] == "activated");
+ }
+ }
+ expected_starts_in = 0;
+ expected_remaining -= 1;
+ context.break_controller.assert_timers (expected_starts_in, expected_remaining);
+
+ for (int step = 0; step < 5; step++) {
+ context.time_step (false, 1, 1);
+ assert (context.break_timestep_log[0] == "counting");
+ }
+ expected_remaining -= 5;
+ context.break_controller.assert_timers (expected_starts_in, expected_remaining);
+
+ for (int step = 0; step < expected_remaining; step++) {
+ context.time_step (false, 1, 1);
+ assert (context.break_timestep_log[0] == "counting");
+ if (step == expected_remaining-1) {
+ assert (context.break_timestep_log[1] == "finished");
+ }
+ }
+ expected_starts_in = test_TimerBreakController.DEFAULT_INTERVAL;
+ expected_remaining = test_TimerBreakController.DEFAULT_DURATION;
+ context.break_controller.assert_timers (expected_starts_in, expected_remaining);
+ }
+ }
+
+ class test_force_activate : Object, SimpleTestCase<test_TimerBreakController> {
+ public void run (test_TimerBreakController context) {
+ int expected_remaining = test_TimerBreakController.DEFAULT_DURATION;
+
+ context.break_controller.activate ();
+ assert (context.break_log.last () == "activated");
+
+ assert (context.break_controller.get_seconds_since_start () == 0);
+ context.break_controller.assert_timers (null, expected_remaining);
+
+ for (int step = 0; step < 10; step++) {
+ context.time_step (false, 1, 1);
+ }
+ expected_remaining -= 10;
+ context.break_controller.assert_timers (null, expected_remaining);
+ }
+ }
+
+ class test_postpone : Object, SimpleTestCase<test_TimerBreakController> {
+ public void run (test_TimerBreakController context) {
+ int expected_starts_in = test_TimerBreakController.DEFAULT_INTERVAL;
+ int expected_remaining = test_TimerBreakController.DEFAULT_DURATION;
+
+ context.break_controller.activate ();
+ for (int step = 0; step < 10; step++) {
+ context.time_step (false, 1, 1);
+ }
+ expected_remaining -= 10;
+ context.break_controller.assert_timers (null, expected_remaining);
+ assert (context.break_controller.get_seconds_since_start () == 10);
+
+ context.break_controller.postpone (60);
+ expected_starts_in = 60;
+ expected_remaining = test_TimerBreakController.DEFAULT_DURATION;
+ assert (context.break_controller.is_active () == false);
+ context.break_controller.assert_timers (expected_starts_in, expected_remaining);
+
+ for (int step = 0; step < expected_starts_in; step++) {
+ context.time_step (true, 1, 1);
+ if (step == expected_starts_in-1) {
+ assert (context.break_timestep_log[1] == "activated");
+ }
+ }
+ expected_starts_in = 0;
+ expected_remaining = test_TimerBreakController.DEFAULT_DURATION;
+ assert (context.break_controller.is_active () == true);
+ context.break_controller.assert_timers (expected_starts_in, expected_remaining);
+ }
+ }
+
+ class test_serialize : Object, SimpleTestCase<test_TimerBreakController> {
+ public void run (test_TimerBreakController context) {
+ var initial_json = context.save_state ();
+
+ for (int step = 0; step < 50; step++) {
+ context.time_step (true, 1, 1);
+ }
+ assert (context.break_controller.is_active () == false);
+ context.break_controller.assert_timers (test_TimerBreakController.DEFAULT_INTERVAL - 50,
test_TimerBreakController.DEFAULT_DURATION);
+ var active_waiting_json = context.save_state ();
+
+ for (int step = 50; step < test_TimerBreakController.DEFAULT_INTERVAL; step++) {
+ context.time_step (true, 1, 1);
+ }
+ assert (context.break_controller.is_active () == true);
+ context.break_controller.assert_timers (0, test_TimerBreakController.DEFAULT_DURATION);
+ var activated_json = context.save_state ();
+
+ for (int step = 0; step < 10; step++) {
+ context.time_step (false, 1, 1);
+ }
+ assert (context.break_controller.is_active () == true);
+ context.break_controller.assert_timers (0, test_TimerBreakController.DEFAULT_DURATION-10);
+ var counting_json = context.save_state ();
+
+ context.time_step (true, 0, 0);
+ for (int step = 0; step < 10; step++) {
+ context.time_step (true, 1, 1);
+ }
+ assert (context.break_controller.is_active () == true);
+ context.break_controller.assert_timers (0, test_TimerBreakController.DEFAULT_DURATION-10);
+
+ context.restore_state (ref initial_json);
+ assert (context.break_controller.is_active () == false);
+ context.break_controller.assert_timers (test_TimerBreakController.DEFAULT_INTERVAL,
test_TimerBreakController.DEFAULT_DURATION);
+
+ context.restore_state (ref counting_json);
+ assert (context.break_controller.is_active () == true);
+ context.break_controller.assert_timers (0, test_TimerBreakController.DEFAULT_DURATION-10);
+
+ context.restore_state (ref active_waiting_json);
+ assert (context.break_controller.is_active () == false);
+ // The state was saved more than break duration ago, so it is immediately finished.
+ context.break_controller.assert_timers (test_TimerBreakController.DEFAULT_INTERVAL,
test_TimerBreakController.DEFAULT_DURATION);
+
+ context.restore_state (ref activated_json);
+ assert (context.break_controller.is_active () == true);
+ // 20 seconds have passed since the break was activated. The application should assume all this
time was spent idle.
+ // Note that this will not happen with a gap smaller than 10+5 seconds, because ActivityMonitor
ignores detected
+ // "sleep" time below 5 seconds + detected idle time (which is, initially, 10 seconds).
+ context.break_controller.assert_timers (0, test_TimerBreakController.DEFAULT_DURATION-20);
+ }
+ }
}
\ No newline at end of file
diff --git a/tests/common/common_runner.vala b/tests/common/common_runner.vala
index d87cd27..05b3906 100644
--- a/tests/common/common_runner.vala
+++ b/tests/common/common_runner.vala
@@ -16,7 +16,7 @@
*/
public static int main (string[] args) {
- var runner = new TestRunner (ref args);
- runner.add (new test_NaturalTime ());
- return runner.run ();
+ var runner = new TestRunner (ref args);
+ runner.add (new test_NaturalTime ());
+ return runner.run ();
}
diff --git a/tests/common/test_NaturalTime.vala b/tests/common/test_NaturalTime.vala
index 7bd50e0..3cb0c34 100644
--- a/tests/common/test_NaturalTime.vala
+++ b/tests/common/test_NaturalTime.vala
@@ -16,97 +16,97 @@
*/
public class test_NaturalTime : SimpleTestSuite {
- public NaturalTime natural_time;
-
- public test_NaturalTime () {
- new test_get_label_for_seconds ().add_to (this);
- new test_get_simplest_label_for_seconds ().add_to (this);
- new test_get_countdown_for_seconds ().add_to (this);
- new test_get_countdown_for_seconds_with_start ().add_to (this);
- }
-
- public override void setup () {
- this.natural_time = NaturalTime.instance;
- }
-
- class test_get_label_for_seconds : Object, SimpleTestCase<test_NaturalTime> {
- public void run (test_NaturalTime context) {
- int value_60;
- var label_60 = context.natural_time.get_label_for_seconds (60, out value_60);
- assert (label_60 == "%d minute".printf (1));
- assert (value_60 == 1);
-
- int value_61;
- var label_61 = context.natural_time.get_label_for_seconds (61, out value_61);
- assert (label_61 == "%d seconds".printf (61));
- assert (value_61 == 61);
- }
- }
-
- class test_get_simplest_label_for_seconds : Object, SimpleTestCase<test_NaturalTime> {
- public void run (test_NaturalTime context) {
- int value_60;
- var label_60 = context.natural_time.get_simplest_label_for_seconds (60, out value_60);
- assert (label_60 == "%d minute".printf (1));
- assert (value_60 == 1);
-
- int value_61;
- var label_61 = context.natural_time.get_simplest_label_for_seconds (61, out value_61);
- assert (label_61 == "%d minute".printf (1));
- assert (value_61 == 1);
- }
- }
-
- class test_get_countdown_for_seconds : Object, SimpleTestCase<test_NaturalTime> {
- public void run (test_NaturalTime context) {
- int value_90;
- var label_90 = context.natural_time.get_countdown_for_seconds (90, out value_90);
- assert (label_90 == "%d minutes".printf (2));
- assert (value_90 == 2);
-
- int value_60;
- var label_60 = context.natural_time.get_countdown_for_seconds (60, out value_60);
- assert (label_60 == "%d minute".printf (1));
- assert (value_60 == 1);
-
- int value_55;
- var label_55 = context.natural_time.get_countdown_for_seconds (55, out value_55);
- assert (label_55 == "%d minute".printf (1));
- assert (value_55 == 1);
-
- int value_42;
- var label_42 = context.natural_time.get_countdown_for_seconds (42, out value_42);
- assert (label_42 == "%d seconds".printf (50));
- assert (value_42 == 50);
-
- int value_8;
- var label_8 = context.natural_time.get_countdown_for_seconds (8, out value_8);
- assert (label_8 == "%d seconds".printf (8));
- assert (value_8 == 8);
- }
- }
-
- class test_get_countdown_for_seconds_with_start : Object, SimpleTestCase<test_NaturalTime> {
- public void run (test_NaturalTime context) {
- int value_90;
- var label_90 = context.natural_time.get_countdown_for_seconds_with_start (90, 90, out
value_90);
- assert (label_90 == "%d minute".printf (1));
- assert (value_90 == 1);
-
- int value_60;
- var label_60 = context.natural_time.get_countdown_for_seconds_with_start (60, 55, out
value_60);
- assert (label_60 == "%d seconds".printf (55));
- assert (value_60 == 55);
-
- int value_55;
- var label_55 = context.natural_time.get_countdown_for_seconds_with_start (55, 55, out
value_55);
- assert (label_55 == "%d seconds".printf (55));
- assert (value_55 == 55);
-
- int value_51;
- var label_51 = context.natural_time.get_countdown_for_seconds_with_start (51, 55, out
value_51);
- assert (label_51 == "%d seconds".printf (55));
- assert (value_51 == 55);
- }
- }
+ public NaturalTime natural_time;
+
+ public test_NaturalTime () {
+ new test_get_label_for_seconds ().add_to (this);
+ new test_get_simplest_label_for_seconds ().add_to (this);
+ new test_get_countdown_for_seconds ().add_to (this);
+ new test_get_countdown_for_seconds_with_start ().add_to (this);
+ }
+
+ public override void setup () {
+ this.natural_time = NaturalTime.instance;
+ }
+
+ class test_get_label_for_seconds : Object, SimpleTestCase<test_NaturalTime> {
+ public void run (test_NaturalTime context) {
+ int value_60;
+ var label_60 = context.natural_time.get_label_for_seconds (60, out value_60);
+ assert (label_60 == "%d minute".printf (1));
+ assert (value_60 == 1);
+
+ int value_61;
+ var label_61 = context.natural_time.get_label_for_seconds (61, out value_61);
+ assert (label_61 == "%d seconds".printf (61));
+ assert (value_61 == 61);
+ }
+ }
+
+ class test_get_simplest_label_for_seconds : Object, SimpleTestCase<test_NaturalTime> {
+ public void run (test_NaturalTime context) {
+ int value_60;
+ var label_60 = context.natural_time.get_simplest_label_for_seconds (60, out value_60);
+ assert (label_60 == "%d minute".printf (1));
+ assert (value_60 == 1);
+
+ int value_61;
+ var label_61 = context.natural_time.get_simplest_label_for_seconds (61, out value_61);
+ assert (label_61 == "%d minute".printf (1));
+ assert (value_61 == 1);
+ }
+ }
+
+ class test_get_countdown_for_seconds : Object, SimpleTestCase<test_NaturalTime> {
+ public void run (test_NaturalTime context) {
+ int value_90;
+ var label_90 = context.natural_time.get_countdown_for_seconds (90, out value_90);
+ assert (label_90 == "%d minutes".printf (2));
+ assert (value_90 == 2);
+
+ int value_60;
+ var label_60 = context.natural_time.get_countdown_for_seconds (60, out value_60);
+ assert (label_60 == "%d minute".printf (1));
+ assert (value_60 == 1);
+
+ int value_55;
+ var label_55 = context.natural_time.get_countdown_for_seconds (55, out value_55);
+ assert (label_55 == "%d minute".printf (1));
+ assert (value_55 == 1);
+
+ int value_42;
+ var label_42 = context.natural_time.get_countdown_for_seconds (42, out value_42);
+ assert (label_42 == "%d seconds".printf (50));
+ assert (value_42 == 50);
+
+ int value_8;
+ var label_8 = context.natural_time.get_countdown_for_seconds (8, out value_8);
+ assert (label_8 == "%d seconds".printf (8));
+ assert (value_8 == 8);
+ }
+ }
+
+ class test_get_countdown_for_seconds_with_start : Object, SimpleTestCase<test_NaturalTime> {
+ public void run (test_NaturalTime context) {
+ int value_90;
+ var label_90 = context.natural_time.get_countdown_for_seconds_with_start (90, 90, out value_90);
+ assert (label_90 == "%d minute".printf (1));
+ assert (value_90 == 1);
+
+ int value_60;
+ var label_60 = context.natural_time.get_countdown_for_seconds_with_start (60, 55, out value_60);
+ assert (label_60 == "%d seconds".printf (55));
+ assert (value_60 == 55);
+
+ int value_55;
+ var label_55 = context.natural_time.get_countdown_for_seconds_with_start (55, 55, out value_55);
+ assert (label_55 == "%d seconds".printf (55));
+ assert (value_55 == 55);
+
+ int value_51;
+ var label_51 = context.natural_time.get_countdown_for_seconds_with_start (51, 55, out value_51);
+ assert (label_51 == "%d seconds".printf (55));
+ assert (value_51 == 55);
+ }
+ }
}
\ No newline at end of file
diff --git a/tests/helper-util/helper_util_runner.vala b/tests/helper-util/helper_util_runner.vala
index a72dce2..9160330 100644
--- a/tests/helper-util/helper_util_runner.vala
+++ b/tests/helper-util/helper_util_runner.vala
@@ -16,8 +16,8 @@
*/
public static int main (string[] args) {
- var runner = new TestRunner (ref args);
- runner.add (new test_Countdown ());
- runner.add (new test_StatefulTimer ());
- return runner.run ();
+ var runner = new TestRunner (ref args);
+ runner.add (new test_Countdown ());
+ runner.add (new test_StatefulTimer ());
+ return runner.run ();
}
diff --git a/tests/helper-util/test_Countdown.vala b/tests/helper-util/test_Countdown.vala
index 1419abb..b53419f 100644
--- a/tests/helper-util/test_Countdown.vala
+++ b/tests/helper-util/test_Countdown.vala
@@ -16,308 +16,308 @@
*/
public class test_Countdown : TestSuiteWithActivityMonitor {
- public test_Countdown () {
- new test_construct ().add_to (this);
- new test_reset ().add_to (this);
- new test_start ().add_to (this);
- new test_start_from ().add_to (this);
- new test_pause ().add_to (this);
- new test_continue ().add_to (this);
- new test_continue_from ().add_to (this);
- new test_cancel_pause ().add_to (this);
- new test_advance_time ().add_to (this);
- new test_set_penalty ().add_to (this);
- new test_set_base_duration ().add_to (this);
- new test_get_duration ().add_to (this);
- new test_get_time_elapsed ().add_to (this);
- new test_timers ().add_to (this);
- new test_serialization ().add_to (this);
- }
-
- class test_construct : Object, SimpleTestCase<test_Countdown> {
- public void run (test_Countdown context) {
- var countdown = new Countdown (30);
-
- assert (countdown.get_time_remaining () == 30);
-
- context.time_step (false, 10, 10);
- assert (countdown.get_time_remaining () == 30);
- }
- }
-
- class test_reset : Object, SimpleTestCase<test_Countdown> {
- public void run (test_Countdown context) {
- var countdown = new Countdown (30);
-
- countdown.start_from (-10);
- countdown.set_penalty (20);
- assert (countdown.get_time_remaining () == 40);
- assert (countdown.is_counting () == true);
-
- countdown.reset ();
- assert (countdown.get_time_remaining () == 30);
- assert (countdown.is_counting () == false);
- }
- }
-
- class test_start : Object, SimpleTestCase<test_Countdown> {
- public void run (test_Countdown context) {
- var countdown = new Countdown (30);
-
- assert (countdown.is_counting () == false);
-
- countdown.start ();
- assert (countdown.get_time_remaining () == 30);
- assert (countdown.is_counting () == true);
-
- context.time_step (false, 10, 10);
- assert (countdown.get_time_remaining () == 20);
-
- countdown.start ();
- assert (countdown.get_time_remaining () == 30);
-
- context.time_step (false, 10, 10);
- assert (countdown.get_time_remaining () == 20);
-
- context.time_step (false, 35, 35);
- assert (countdown.get_time_remaining () == 0);
- }
- }
-
- class test_start_from : Object, SimpleTestCase<test_Countdown> {
- public void run (test_Countdown context) {
- var countdown = new Countdown (30);
-
- countdown.start_from (-10);
- assert (countdown.get_time_remaining () == 20);
-
- context.time_step (false, 5, 5);
- assert (countdown.get_time_remaining () == 15);
-
- countdown.start_from (-10);
- assert (countdown.get_time_remaining () == 20);
-
- countdown.start_from (-50);
- assert (countdown.get_time_remaining () == 0);
-
- // Test that start_from doesn't allow time_remaining to exceed duration
- countdown.start_from (10);
- assert (countdown.get_time_remaining () == 30);
- }
- }
-
- class test_pause : Object, SimpleTestCase<test_Countdown> {
- public void run (test_Countdown context) {
- var countdown = new Countdown (30);
-
- countdown.start ();
- context.time_step (false, 10, 10);
- assert (countdown.get_time_remaining () == 20);
-
- countdown.pause ();
- context.time_step (false, 10, 10);
- assert (countdown.get_time_remaining () == 20);
- }
- }
-
- class test_continue : Object, SimpleTestCase<test_Countdown> {
- public void run (test_Countdown context) {
- var countdown = new Countdown (30);
-
- countdown.continue ();
- context.time_step (false, 10, 10);
- assert (countdown.get_time_remaining () == 20);
-
- countdown.pause ();
- context.time_step (false, 10, 10);
- assert (countdown.get_time_remaining () == 20);
+ public test_Countdown () {
+ new test_construct ().add_to (this);
+ new test_reset ().add_to (this);
+ new test_start ().add_to (this);
+ new test_start_from ().add_to (this);
+ new test_pause ().add_to (this);
+ new test_continue ().add_to (this);
+ new test_continue_from ().add_to (this);
+ new test_cancel_pause ().add_to (this);
+ new test_advance_time ().add_to (this);
+ new test_set_penalty ().add_to (this);
+ new test_set_base_duration ().add_to (this);
+ new test_get_duration ().add_to (this);
+ new test_get_time_elapsed ().add_to (this);
+ new test_timers ().add_to (this);
+ new test_serialization ().add_to (this);
+ }
+
+ class test_construct : Object, SimpleTestCase<test_Countdown> {
+ public void run (test_Countdown context) {
+ var countdown = new Countdown (30);
+
+ assert (countdown.get_time_remaining () == 30);
+
+ context.time_step (false, 10, 10);
+ assert (countdown.get_time_remaining () == 30);
+ }
+ }
+
+ class test_reset : Object, SimpleTestCase<test_Countdown> {
+ public void run (test_Countdown context) {
+ var countdown = new Countdown (30);
+
+ countdown.start_from (-10);
+ countdown.set_penalty (20);
+ assert (countdown.get_time_remaining () == 40);
+ assert (countdown.is_counting () == true);
+
+ countdown.reset ();
+ assert (countdown.get_time_remaining () == 30);
+ assert (countdown.is_counting () == false);
+ }
+ }
+
+ class test_start : Object, SimpleTestCase<test_Countdown> {
+ public void run (test_Countdown context) {
+ var countdown = new Countdown (30);
+
+ assert (countdown.is_counting () == false);
+
+ countdown.start ();
+ assert (countdown.get_time_remaining () == 30);
+ assert (countdown.is_counting () == true);
+
+ context.time_step (false, 10, 10);
+ assert (countdown.get_time_remaining () == 20);
+
+ countdown.start ();
+ assert (countdown.get_time_remaining () == 30);
+
+ context.time_step (false, 10, 10);
+ assert (countdown.get_time_remaining () == 20);
+
+ context.time_step (false, 35, 35);
+ assert (countdown.get_time_remaining () == 0);
+ }
+ }
+
+ class test_start_from : Object, SimpleTestCase<test_Countdown> {
+ public void run (test_Countdown context) {
+ var countdown = new Countdown (30);
+
+ countdown.start_from (-10);
+ assert (countdown.get_time_remaining () == 20);
+
+ context.time_step (false, 5, 5);
+ assert (countdown.get_time_remaining () == 15);
+
+ countdown.start_from (-10);
+ assert (countdown.get_time_remaining () == 20);
+
+ countdown.start_from (-50);
+ assert (countdown.get_time_remaining () == 0);
+
+ // Test that start_from doesn't allow time_remaining to exceed duration
+ countdown.start_from (10);
+ assert (countdown.get_time_remaining () == 30);
+ }
+ }
+
+ class test_pause : Object, SimpleTestCase<test_Countdown> {
+ public void run (test_Countdown context) {
+ var countdown = new Countdown (30);
+
+ countdown.start ();
+ context.time_step (false, 10, 10);
+ assert (countdown.get_time_remaining () == 20);
+
+ countdown.pause ();
+ context.time_step (false, 10, 10);
+ assert (countdown.get_time_remaining () == 20);
+ }
+ }
+
+ class test_continue : Object, SimpleTestCase<test_Countdown> {
+ public void run (test_Countdown context) {
+ var countdown = new Countdown (30);
+
+ countdown.continue ();
+ context.time_step (false, 10, 10);
+ assert (countdown.get_time_remaining () == 20);
+
+ countdown.pause ();
+ context.time_step (false, 10, 10);
+ assert (countdown.get_time_remaining () == 20);
- countdown.continue ();
- context.time_step (false, 10, 10);
- assert (countdown.get_time_remaining () == 10);
- }
- }
+ countdown.continue ();
+ context.time_step (false, 10, 10);
+ assert (countdown.get_time_remaining () == 10);
+ }
+ }
- class test_continue_from : Object, SimpleTestCase<test_Countdown> {
- public void run (test_Countdown context) {
- var countdown = new Countdown (30);
+ class test_continue_from : Object, SimpleTestCase<test_Countdown> {
+ public void run (test_Countdown context) {
+ var countdown = new Countdown (30);
- countdown.continue_from (-10);
- assert (countdown.get_time_remaining () == 20);
- assert (countdown.is_counting () == true);
+ countdown.continue_from (-10);
+ assert (countdown.get_time_remaining () == 20);
+ assert (countdown.is_counting () == true);
- context.time_step (false, 10, 10);
- assert (countdown.get_time_remaining () == 10);
- assert (countdown.is_counting () == true);
+ context.time_step (false, 10, 10);
+ assert (countdown.get_time_remaining () == 10);
+ assert (countdown.is_counting () == true);
- // Test that continue_from doesn't do anything if countdown is already running
- countdown.continue_from (-10);
- assert (countdown.get_time_remaining () == 10);
- assert (countdown.is_counting () == true);
- }
- }
+ // Test that continue_from doesn't do anything if countdown is already running
+ countdown.continue_from (-10);
+ assert (countdown.get_time_remaining () == 10);
+ assert (countdown.is_counting () == true);
+ }
+ }
- class test_cancel_pause : Object, SimpleTestCase<test_Countdown> {
- public void run (test_Countdown context) {
- var countdown = new Countdown (30);
+ class test_cancel_pause : Object, SimpleTestCase<test_Countdown> {
+ public void run (test_Countdown context) {
+ var countdown = new Countdown (30);
- countdown.start ();
+ countdown.start ();
- countdown.pause ();
- context.time_step (false, 10, 10);
- assert (countdown.get_time_remaining () == 30);
- assert (countdown.is_counting () == false);
+ countdown.pause ();
+ context.time_step (false, 10, 10);
+ assert (countdown.get_time_remaining () == 30);
+ assert (countdown.is_counting () == false);
- countdown.cancel_pause ();
- assert (countdown.get_time_remaining () == 20);
- assert (countdown.is_counting () == true);
- }
- }
+ countdown.cancel_pause ();
+ assert (countdown.get_time_remaining () == 20);
+ assert (countdown.is_counting () == true);
+ }
+ }
- class test_advance_time : Object, SimpleTestCase<test_Countdown> {
- public void run (test_Countdown context) {
- var countdown = new Countdown (30);
+ class test_advance_time : Object, SimpleTestCase<test_Countdown> {
+ public void run (test_Countdown context) {
+ var countdown = new Countdown (30);
- countdown.advance_time (10);
- assert (countdown.get_time_remaining () == 20);
+ countdown.advance_time (10);
+ assert (countdown.get_time_remaining () == 20);
- countdown.continue ();
- assert (countdown.get_time_remaining () == 20);
+ countdown.continue ();
+ assert (countdown.get_time_remaining () == 20);
- countdown.advance_time (10);
- assert (countdown.get_time_remaining () == 10);
- }
- }
+ countdown.advance_time (10);
+ assert (countdown.get_time_remaining () == 10);
+ }
+ }
- class test_set_penalty : Object, SimpleTestCase<test_Countdown> {
- public void run (test_Countdown context) {
- var countdown = new Countdown (30);
+ class test_set_penalty : Object, SimpleTestCase<test_Countdown> {
+ public void run (test_Countdown context) {
+ var countdown = new Countdown (30);
- countdown.set_penalty (20);
- assert (countdown.get_penalty () == 20);
- assert (countdown.get_time_remaining () == 50);
+ countdown.set_penalty (20);
+ assert (countdown.get_penalty () == 20);
+ assert (countdown.get_time_remaining () == 50);
- countdown.continue ();
- context.time_step (false, 10, 10);
- assert (countdown.get_time_remaining () == 40);
-
- countdown.set_penalty (5);
- assert (countdown.get_penalty () == 5);
- assert (countdown.get_time_remaining () == 25);
-
- countdown.start ();
- assert (countdown.get_penalty () == 0);
- assert (countdown.get_time_remaining () == 30);
- }
- }
-
- class test_set_base_duration : Object, SimpleTestCase<test_Countdown> {
- public void run (test_Countdown context) {
- var countdown = new Countdown (30);
-
- countdown.start ();
-
- context.time_step (false, 10, 10);
- assert (countdown.get_time_remaining () == 20);
-
- countdown.set_base_duration (10);
- assert (countdown.get_time_remaining () == 0);
-
- countdown.set_base_duration (15);
- assert (countdown.get_time_remaining () == 5);
-
- countdown.start ();
- assert (countdown.get_time_remaining () == 15);
- }
- }
-
- class test_get_duration : Object, SimpleTestCase<test_Countdown> {
- public void run (test_Countdown context) {
- var countdown = new Countdown (30);
-
- assert (countdown.get_duration () == 30);
-
- countdown.set_penalty (5);
- assert (countdown.get_duration () == 35);
-
- countdown.set_base_duration (40);
- assert (countdown.get_duration () == 45);
-
- countdown.reset ();
- assert (countdown.get_duration () == 40);
- }
- }
-
- class test_get_time_elapsed : Object, SimpleTestCase<test_Countdown> {
- public void run (test_Countdown context) {
- var countdown = new Countdown (30);
-
- assert (countdown.get_time_elapsed () == 0);
- assert (countdown.get_time_remaining () == 30);
- assert (countdown.is_finished () == false);
-
- countdown.start ();
-
- context.time_step (false, 10, 10);
- assert (countdown.get_time_elapsed () == 10);
- assert (countdown.get_time_remaining () == 20);
- assert (countdown.is_finished () == false);
-
- context.time_step (false, 50, 50);
- assert (countdown.get_time_elapsed () == 60);
- assert (countdown.get_time_remaining () == 0);
- assert (countdown.is_finished () == true);
-
- countdown.reset ();
-
- assert (countdown.get_time_elapsed () == 0);
- assert (countdown.get_time_remaining () == 30);
- assert (countdown.is_finished () == false);
- }
- }
-
- class test_timers : Object, SimpleTestCase<test_Countdown> {
- public void run (test_Countdown context) {
- var countdown = new Countdown (30);
-
- countdown.start ();
-
- // Test that timer advances with change in wall time
- context.time_step (false, 10, 0);
- assert (countdown.get_time_remaining () == 20);
-
- // Test that it ignores change in monotonic time
- context.time_step (false, 0, 10);
- assert (countdown.get_time_remaining () == 20);
- }
- }
-
- class test_serialization : Object, SimpleTestCase<test_Countdown> {
- public void run (test_Countdown context) {
- var countdown = new Countdown (30);
-
- var data_0 = countdown.serialize ();
-
- countdown.start ();
- context.time_step (false, 10, 10);
- var data_1 = countdown.serialize ();
-
- countdown.pause ();
- var data_2 = countdown.serialize ();
- context.time_step (false, 10, 10);
-
- this.assert_deserialize (30, data_0, false, 0, 30);
- this.assert_deserialize (30, data_1, true, 10, 20);
- this.assert_deserialize (30, data_2, false, 10, 20);
- }
-
- private void assert_deserialize (int known_duration, string data, bool is_counting, int
time_elapsed, int time_remaining) {
- var countdown = new Countdown (known_duration);
- countdown.deserialize (data);
-
- assert (countdown.is_counting () == is_counting);
- assert (countdown.get_time_elapsed () == time_elapsed);
- assert (countdown.get_time_remaining () == time_remaining);
- }
- }
+ countdown.continue ();
+ context.time_step (false, 10, 10);
+ assert (countdown.get_time_remaining () == 40);
+
+ countdown.set_penalty (5);
+ assert (countdown.get_penalty () == 5);
+ assert (countdown.get_time_remaining () == 25);
+
+ countdown.start ();
+ assert (countdown.get_penalty () == 0);
+ assert (countdown.get_time_remaining () == 30);
+ }
+ }
+
+ class test_set_base_duration : Object, SimpleTestCase<test_Countdown> {
+ public void run (test_Countdown context) {
+ var countdown = new Countdown (30);
+
+ countdown.start ();
+
+ context.time_step (false, 10, 10);
+ assert (countdown.get_time_remaining () == 20);
+
+ countdown.set_base_duration (10);
+ assert (countdown.get_time_remaining () == 0);
+
+ countdown.set_base_duration (15);
+ assert (countdown.get_time_remaining () == 5);
+
+ countdown.start ();
+ assert (countdown.get_time_remaining () == 15);
+ }
+ }
+
+ class test_get_duration : Object, SimpleTestCase<test_Countdown> {
+ public void run (test_Countdown context) {
+ var countdown = new Countdown (30);
+
+ assert (countdown.get_duration () == 30);
+
+ countdown.set_penalty (5);
+ assert (countdown.get_duration () == 35);
+
+ countdown.set_base_duration (40);
+ assert (countdown.get_duration () == 45);
+
+ countdown.reset ();
+ assert (countdown.get_duration () == 40);
+ }
+ }
+
+ class test_get_time_elapsed : Object, SimpleTestCase<test_Countdown> {
+ public void run (test_Countdown context) {
+ var countdown = new Countdown (30);
+
+ assert (countdown.get_time_elapsed () == 0);
+ assert (countdown.get_time_remaining () == 30);
+ assert (countdown.is_finished () == false);
+
+ countdown.start ();
+
+ context.time_step (false, 10, 10);
+ assert (countdown.get_time_elapsed () == 10);
+ assert (countdown.get_time_remaining () == 20);
+ assert (countdown.is_finished () == false);
+
+ context.time_step (false, 50, 50);
+ assert (countdown.get_time_elapsed () == 60);
+ assert (countdown.get_time_remaining () == 0);
+ assert (countdown.is_finished () == true);
+
+ countdown.reset ();
+
+ assert (countdown.get_time_elapsed () == 0);
+ assert (countdown.get_time_remaining () == 30);
+ assert (countdown.is_finished () == false);
+ }
+ }
+
+ class test_timers : Object, SimpleTestCase<test_Countdown> {
+ public void run (test_Countdown context) {
+ var countdown = new Countdown (30);
+
+ countdown.start ();
+
+ // Test that timer advances with change in wall time
+ context.time_step (false, 10, 0);
+ assert (countdown.get_time_remaining () == 20);
+
+ // Test that it ignores change in monotonic time
+ context.time_step (false, 0, 10);
+ assert (countdown.get_time_remaining () == 20);
+ }
+ }
+
+ class test_serialization : Object, SimpleTestCase<test_Countdown> {
+ public void run (test_Countdown context) {
+ var countdown = new Countdown (30);
+
+ var data_0 = countdown.serialize ();
+
+ countdown.start ();
+ context.time_step (false, 10, 10);
+ var data_1 = countdown.serialize ();
+
+ countdown.pause ();
+ var data_2 = countdown.serialize ();
+ context.time_step (false, 10, 10);
+
+ this.assert_deserialize (30, data_0, false, 0, 30);
+ this.assert_deserialize (30, data_1, true, 10, 20);
+ this.assert_deserialize (30, data_2, false, 10, 20);
+ }
+
+ private void assert_deserialize (int known_duration, string data, bool is_counting, int
time_elapsed, int time_remaining) {
+ var countdown = new Countdown (known_duration);
+ countdown.deserialize (data);
+
+ assert (countdown.is_counting () == is_counting);
+ assert (countdown.get_time_elapsed () == time_elapsed);
+ assert (countdown.get_time_remaining () == time_remaining);
+ }
+ }
}
\ No newline at end of file
diff --git a/tests/helper-util/test_StatefulTimer.vala b/tests/helper-util/test_StatefulTimer.vala
index b125b10..92dee63 100644
--- a/tests/helper-util/test_StatefulTimer.vala
+++ b/tests/helper-util/test_StatefulTimer.vala
@@ -16,89 +16,89 @@
*/
public class test_StatefulTimer : TestSuiteWithActivityMonitor {
- /* We won't be able to test the timer mechanics in much detail because,
- * internally, it uses GTimer and the (real) system clock. Still, we can
- * test that StatefulTimer keeps track of state, as well as serialization.
- */
-
- public test_StatefulTimer () {
- new test_construct ().add_to (this);
- new test_stop_start ().add_to (this);
- new test_continue ().add_to (this);
- new test_start_lap ().add_to (this);
- new test_serialize_hardcoded ().add_to (this);
- new test_deserialize_hardcoded ().add_to (this);
- }
-
- class test_construct : Object, SimpleTestCase<test_StatefulTimer> {
- public void run (test_StatefulTimer context) {
- var timer = new StatefulTimer ();
-
- assert (timer.state == StatefulTimer.State.COUNTING);
- }
- }
-
- class test_stop_start : Object, SimpleTestCase<test_StatefulTimer> {
- public void run (test_StatefulTimer context) {
- var timer = new StatefulTimer ();
-
- timer.stop ();
- assert (timer.state == StatefulTimer.State.STOPPED);
- assert (timer.is_stopped () == true);
- assert (timer.is_counting () == false);
-
- timer.start ();
- assert (timer.state == StatefulTimer.State.COUNTING);
- assert (timer.is_stopped () == false);
- assert (timer.is_counting () == true);
- }
- }
-
- class test_continue : Object, SimpleTestCase<test_StatefulTimer> {
- public void run (test_StatefulTimer context) {
- var timer = new StatefulTimer ();
-
- timer.stop ();
-
- timer.continue ();
- assert (timer.state == StatefulTimer.State.COUNTING);
- }
- }
-
- class test_start_lap : Object, SimpleTestCase<test_StatefulTimer> {
- public void run (test_StatefulTimer context) {
- var timer = new StatefulTimer ();
-
- timer.stop ();
-
- timer.start_lap ();
- assert (timer.state == StatefulTimer.State.COUNTING);
- }
- }
-
- class test_serialize_hardcoded : Object, SimpleTestCase<test_StatefulTimer> {
- public void run (test_StatefulTimer context) {
- var timer = new StatefulTimer ();
-
- var data = timer.serialize ();
- string[] data_parts = data.split (",");
-
- assert (data_parts[0] == "1");
- }
- }
-
- class test_deserialize_hardcoded : Object, SimpleTestCase<test_StatefulTimer> {
- public void run (test_StatefulTimer context) {
- var timer = new StatefulTimer ();
-
- var data = "0,20.0,15.0";
- timer.deserialize (data);
-
- assert (timer.state == StatefulTimer.State.STOPPED);
- // FIXME: These asserts fail unpredictably on i386 with Launchpad's build service
- // Convert time values to ints to deal with floating point errors
- // assert ((int)timer.elapsed () == 20);
- // assert ((int)timer.lap_time () == 5);
- }
- }
+ /* We won't be able to test the timer mechanics in much detail because,
+ * internally, it uses GTimer and the (real) system clock. Still, we can
+ * test that StatefulTimer keeps track of state, as well as serialization.
+ */
+
+ public test_StatefulTimer () {
+ new test_construct ().add_to (this);
+ new test_stop_start ().add_to (this);
+ new test_continue ().add_to (this);
+ new test_start_lap ().add_to (this);
+ new test_serialize_hardcoded ().add_to (this);
+ new test_deserialize_hardcoded ().add_to (this);
+ }
+
+ class test_construct : Object, SimpleTestCase<test_StatefulTimer> {
+ public void run (test_StatefulTimer context) {
+ var timer = new StatefulTimer ();
+
+ assert (timer.state == StatefulTimer.State.COUNTING);
+ }
+ }
+
+ class test_stop_start : Object, SimpleTestCase<test_StatefulTimer> {
+ public void run (test_StatefulTimer context) {
+ var timer = new StatefulTimer ();
+
+ timer.stop ();
+ assert (timer.state == StatefulTimer.State.STOPPED);
+ assert (timer.is_stopped () == true);
+ assert (timer.is_counting () == false);
+
+ timer.start ();
+ assert (timer.state == StatefulTimer.State.COUNTING);
+ assert (timer.is_stopped () == false);
+ assert (timer.is_counting () == true);
+ }
+ }
+
+ class test_continue : Object, SimpleTestCase<test_StatefulTimer> {
+ public void run (test_StatefulTimer context) {
+ var timer = new StatefulTimer ();
+
+ timer.stop ();
+
+ timer.continue ();
+ assert (timer.state == StatefulTimer.State.COUNTING);
+ }
+ }
+
+ class test_start_lap : Object, SimpleTestCase<test_StatefulTimer> {
+ public void run (test_StatefulTimer context) {
+ var timer = new StatefulTimer ();
+
+ timer.stop ();
+
+ timer.start_lap ();
+ assert (timer.state == StatefulTimer.State.COUNTING);
+ }
+ }
+
+ class test_serialize_hardcoded : Object, SimpleTestCase<test_StatefulTimer> {
+ public void run (test_StatefulTimer context) {
+ var timer = new StatefulTimer ();
+
+ var data = timer.serialize ();
+ string[] data_parts = data.split (",");
+
+ assert (data_parts[0] == "1");
+ }
+ }
+
+ class test_deserialize_hardcoded : Object, SimpleTestCase<test_StatefulTimer> {
+ public void run (test_StatefulTimer context) {
+ var timer = new StatefulTimer ();
+
+ var data = "0,20.0,15.0";
+ timer.deserialize (data);
+
+ assert (timer.state == StatefulTimer.State.STOPPED);
+ // FIXME: These asserts fail unpredictably on i386 with Launchpad's build service
+ // Convert time values to ints to deal with floating point errors
+ // assert ((int)timer.elapsed () == 20);
+ // assert ((int)timer.lap_time () == 5);
+ }
+ }
}
\ No newline at end of file
diff --git a/tests/tests.vala b/tests/tests.vala
index 0d27600..50ecd86 100644
--- a/tests/tests.vala
+++ b/tests/tests.vala
@@ -19,280 +19,280 @@
// This base code is partly borrowed from libgee's test suite, at https://git.gnome.org/browse/libgee
public abstract class SimpleTestSuite : Object {
- private GLib.TestSuite g_test_suite;
- private Adaptor[] adaptors = new Adaptor[0];
-
- private class Adaptor {
- private SimpleTestSuite test_suite;
- private SimpleTestCase<SimpleTestSuite> test;
-
- public Adaptor (SimpleTestSuite test_suite, owned SimpleTestCase<SimpleTestSuite> test) {
- this.test_suite = test_suite;
- this.test = (owned)test;
- }
-
- private string get_short_name () {
- string base_name = this.test_suite.get_name ();
- string test_full_name = this.test.get_name ();
- if (test_full_name.has_prefix (base_name)) {
- return test_full_name.splice (0, base_name.length);
- } else {
- return test_full_name;
- }
- }
-
- private void setup (void *fixture) {
- this.test_suite.setup ();
- }
-
- private void run (void *fixture) {
- this.test.run (this.test_suite);
- }
-
- private void teardown (void *fixture) {
- this.test_suite.teardown ();
- }
-
- public GLib.TestCase get_g_test_case () {
- return new GLib.TestCase (
- this.get_short_name (),
- (TestFixtureFunc)this.setup,
- (TestFixtureFunc)this.run,
- (TestFixtureFunc)this.teardown
- );
- }
- }
-
- public SimpleTestSuite () {
- var name = this.get_name ();
- this.g_test_suite = new GLib.TestSuite (name);
- }
-
- public void add_to (GLib.TestSuite parent) {
- parent.add_suite (this.g_test_suite);
- }
-
- public GLib.TestSuite get_g_test_suite () {
- return this.g_test_suite;
- }
-
- public string get_name () {
- return this.get_type ().name ();
- }
-
- public void add_test (owned SimpleTestCase test) {
- var adaptor = new Adaptor (this, (owned)test);
- this.adaptors += adaptor;
- this.g_test_suite.add (adaptor.get_g_test_case ());
- }
-
- public virtual void setup () {
- }
-
- public virtual void teardown () {
- }
+ private GLib.TestSuite g_test_suite;
+ private Adaptor[] adaptors = new Adaptor[0];
+
+ private class Adaptor {
+ private SimpleTestSuite test_suite;
+ private SimpleTestCase<SimpleTestSuite> test;
+
+ public Adaptor (SimpleTestSuite test_suite, owned SimpleTestCase<SimpleTestSuite> test) {
+ this.test_suite = test_suite;
+ this.test = (owned)test;
+ }
+
+ private string get_short_name () {
+ string base_name = this.test_suite.get_name ();
+ string test_full_name = this.test.get_name ();
+ if (test_full_name.has_prefix (base_name)) {
+ return test_full_name.splice (0, base_name.length);
+ } else {
+ return test_full_name;
+ }
+ }
+
+ private void setup (void *fixture) {
+ this.test_suite.setup ();
+ }
+
+ private void run (void *fixture) {
+ this.test.run (this.test_suite);
+ }
+
+ private void teardown (void *fixture) {
+ this.test_suite.teardown ();
+ }
+
+ public GLib.TestCase get_g_test_case () {
+ return new GLib.TestCase (
+ this.get_short_name (),
+ (TestFixtureFunc)this.setup,
+ (TestFixtureFunc)this.run,
+ (TestFixtureFunc)this.teardown
+ );
+ }
+ }
+
+ public SimpleTestSuite () {
+ var name = this.get_name ();
+ this.g_test_suite = new GLib.TestSuite (name);
+ }
+
+ public void add_to (GLib.TestSuite parent) {
+ parent.add_suite (this.g_test_suite);
+ }
+
+ public GLib.TestSuite get_g_test_suite () {
+ return this.g_test_suite;
+ }
+
+ public string get_name () {
+ return this.get_type ().name ();
+ }
+
+ public void add_test (owned SimpleTestCase test) {
+ var adaptor = new Adaptor (this, (owned)test);
+ this.adaptors += adaptor;
+ this.g_test_suite.add (adaptor.get_g_test_case ());
+ }
+
+ public virtual void setup () {
+ }
+
+ public virtual void teardown () {
+ }
}
public interface SimpleTestCase<T> : Object {
- public abstract void run (T context);
+ public abstract void run (T context);
- public void add_to (SimpleTestSuite test_suite) {
- test_suite.add_test (this);
- }
+ public void add_to (SimpleTestSuite test_suite) {
+ test_suite.add_test (this);
+ }
- public string get_name () {
- return this.get_type ().name ();
- }
+ public string get_name () {
+ return this.get_type ().name ();
+ }
}
class TestRunner : Object {
- private GLib.TestSuite root_suite;
-
- private File tmp_dir;
- const string SCHEMA_FILE_NAME = "org.gnome.BreakTimer.gschema.xml";
-
- public TestRunner (ref unowned string[] args, GLib.TestSuite? root_suite = null) {
- GLib.Test.init (ref args);
- if (root_suite == null) {
- this.root_suite = GLib.TestSuite.get_root ();
- } else {
- this.root_suite = root_suite;
- }
- }
-
- public void add (SimpleTestSuite suite) {
- suite.add_to (this.root_suite);
- }
-
- public virtual void global_setup () {
- Environment.set_variable ("LANGUAGE", "C", true);
-
- try {
- var tmp_path = DirUtils.make_tmp ("gnome-break-timer-test-XXXXXX");
- tmp_dir = File.new_for_path (tmp_path);
- } catch (Error e) {
- GLib.warning ("Error creating temporary directory for test files: %s".printf
(e.message));
- }
-
- string target_data_path = Path.build_filename (tmp_dir.get_path (), "share");
- string target_schema_path = Path.build_filename (tmp_dir.get_path (), "share", "glib-2.0",
"schemas");
-
- Environment.set_variable ("GSETTINGS_BACKEND", "memory", true);
-
- var original_data_dirs = Environment.get_variable ("XDG_DATA_DIRS");
- Environment.set_variable ("XDG_DATA_DIRS", "%s:%s".printf (target_data_path,
original_data_dirs), true);
-
- File source_schema_file = File.new_for_path (
- Path.build_filename (get_top_builddir (), "data", SCHEMA_FILE_NAME)
- );
-
- File target_schema_dir = File.new_for_path (target_schema_path);
- try {
- target_schema_dir.make_directory_with_parents ();
- } catch (Error e) {
- GLib.warning ("Error creating directory for schema files: %s", e.message);
- }
-
- File target_schema_file = File.new_for_path (
- Path.build_filename (target_schema_dir.get_path (), SCHEMA_FILE_NAME)
- );
-
- try {
- source_schema_file.copy (target_schema_file, FileCopyFlags.OVERWRITE);
- } catch (Error e) {
- GLib.warning ("Error copying schema file: %s", e.message);
- }
-
- int compile_schemas_result = Posix.system ("glib-compile-schemas %s".printf
(target_schema_path));
- if (compile_schemas_result != 0) {
- GLib.warning ("Could not compile schemas in %s", target_schema_path);
- }
- }
-
- public virtual void global_teardown () {
- if (tmp_dir != null) {
- var tmp_dir_path = tmp_dir.get_path ();
- int delete_tmp_result = Posix.system ("rm -rf %s".printf (tmp_dir_path));
- if (delete_tmp_result != 0) {
- GLib.warning ("Could not delete temporary files in %s", tmp_dir_path);
- }
- }
- }
-
- public int run () {
- this.global_setup ();
- GLib.Test.run ();
- this.global_teardown ();
- return 0;
- }
-
- private static string get_top_builddir () {
- var builddir = Environment.get_variable ("top_builddir");
- if (builddir == null) builddir = "..";
- return builddir;
- }
+ private GLib.TestSuite root_suite;
+
+ private File tmp_dir;
+ const string SCHEMA_FILE_NAME = "org.gnome.BreakTimer.gschema.xml";
+
+ public TestRunner (ref unowned string[] args, GLib.TestSuite? root_suite = null) {
+ GLib.Test.init (ref args);
+ if (root_suite == null) {
+ this.root_suite = GLib.TestSuite.get_root ();
+ } else {
+ this.root_suite = root_suite;
+ }
+ }
+
+ public void add (SimpleTestSuite suite) {
+ suite.add_to (this.root_suite);
+ }
+
+ public virtual void global_setup () {
+ Environment.set_variable ("LANGUAGE", "C", true);
+
+ try {
+ var tmp_path = DirUtils.make_tmp ("gnome-break-timer-test-XXXXXX");
+ tmp_dir = File.new_for_path (tmp_path);
+ } catch (Error e) {
+ GLib.warning ("Error creating temporary directory for test files: %s".printf (e.message));
+ }
+
+ string target_data_path = Path.build_filename (tmp_dir.get_path (), "share");
+ string target_schema_path = Path.build_filename (tmp_dir.get_path (), "share", "glib-2.0",
"schemas");
+
+ Environment.set_variable ("GSETTINGS_BACKEND", "memory", true);
+
+ var original_data_dirs = Environment.get_variable ("XDG_DATA_DIRS");
+ Environment.set_variable ("XDG_DATA_DIRS", "%s:%s".printf (target_data_path, original_data_dirs),
true);
+
+ File source_schema_file = File.new_for_path (
+ Path.build_filename (get_top_builddir (), "data", SCHEMA_FILE_NAME)
+ );
+
+ File target_schema_dir = File.new_for_path (target_schema_path);
+ try {
+ target_schema_dir.make_directory_with_parents ();
+ } catch (Error e) {
+ GLib.warning ("Error creating directory for schema files: %s", e.message);
+ }
+
+ File target_schema_file = File.new_for_path (
+ Path.build_filename (target_schema_dir.get_path (), SCHEMA_FILE_NAME)
+ );
+
+ try {
+ source_schema_file.copy (target_schema_file, FileCopyFlags.OVERWRITE);
+ } catch (Error e) {
+ GLib.warning ("Error copying schema file: %s", e.message);
+ }
+
+ int compile_schemas_result = Posix.system ("glib-compile-schemas %s".printf (target_schema_path));
+ if (compile_schemas_result != 0) {
+ GLib.warning ("Could not compile schemas in %s", target_schema_path);
+ }
+ }
+
+ public virtual void global_teardown () {
+ if (tmp_dir != null) {
+ var tmp_dir_path = tmp_dir.get_path ();
+ int delete_tmp_result = Posix.system ("rm -rf %s".printf (tmp_dir_path));
+ if (delete_tmp_result != 0) {
+ GLib.warning ("Could not delete temporary files in %s", tmp_dir_path);
+ }
+ }
+ }
+
+ public int run () {
+ this.global_setup ();
+ GLib.Test.run ();
+ this.global_teardown ();
+ return 0;
+ }
+
+ private static string get_top_builddir () {
+ var builddir = Environment.get_variable ("top_builddir");
+ if (builddir == null) builddir = "..";
+ return builddir;
+ }
}
// Special test suites suited for particular pieces of the application
public class TestSuiteWithActivityMonitor : SimpleTestSuite {
- public testable_ActivityMonitorBackend activity_monitor_backend;
- public testable_SessionStatus session_status;
- public ActivityMonitor activity_monitor;
- public Gee.List<ActivityMonitor.UserActivity?> activity_log;
-
- public const int64 START_REAL_TIME = 100000 * Util.MICROSECONDS_IN_SECONDS;
- public const int64 START_MONOTONIC_TIME = 50 * Util.MICROSECONDS_IN_SECONDS;
-
- public override void setup () {
- base.setup ();
-
- Util._do_override_time = true;
- Util._override_real_time = START_REAL_TIME;
- Util._override_monotonic_time = START_MONOTONIC_TIME;
-
- this.activity_log = new Gee.ArrayList<ActivityMonitor.UserActivity?> ();
- this.refresh_environment ();
- }
-
- public override void teardown () {
- Util._do_override_time = false;
- Util._override_real_time = 0;
- Util._override_monotonic_time = 0;
- }
-
- public virtual void refresh_environment () {
- // We keep _override_real_time as it is, because time never goes backward within a test case
- Util._override_monotonic_time = START_MONOTONIC_TIME;
-
- this.activity_log.clear ();
- this.activity_monitor_backend = new testable_ActivityMonitorBackend ();
- this.session_status = new testable_SessionStatus ();
- this.activity_monitor = new ActivityMonitor (session_status, activity_monitor_backend);
- this.activity_monitor.detected_idle.connect (this.log_activity);
- this.activity_monitor.detected_activity.connect (this.log_activity);
- this.activity_monitor.stop ();
- }
-
- public virtual void time_step (bool is_active, int real_seconds, int monotonic_seconds) {
- Util._override_real_time += real_seconds * Util.MICROSECONDS_IN_SECONDS;
- Util._override_monotonic_time += monotonic_seconds * Util.MICROSECONDS_IN_SECONDS;
- if (is_active) this.activity_monitor_backend.push_activity ();
- this.activity_monitor.poll_activity ();
- }
-
- private void log_activity (ActivityMonitor.UserActivity activity) {
- this.activity_log.add (activity);
- }
+ public testable_ActivityMonitorBackend activity_monitor_backend;
+ public testable_SessionStatus session_status;
+ public ActivityMonitor activity_monitor;
+ public Gee.List<ActivityMonitor.UserActivity?> activity_log;
+
+ public const int64 START_REAL_TIME = 100000 * Util.MICROSECONDS_IN_SECONDS;
+ public const int64 START_MONOTONIC_TIME = 50 * Util.MICROSECONDS_IN_SECONDS;
+
+ public override void setup () {
+ base.setup ();
+
+ Util._do_override_time = true;
+ Util._override_real_time = START_REAL_TIME;
+ Util._override_monotonic_time = START_MONOTONIC_TIME;
+
+ this.activity_log = new Gee.ArrayList<ActivityMonitor.UserActivity?> ();
+ this.refresh_environment ();
+ }
+
+ public override void teardown () {
+ Util._do_override_time = false;
+ Util._override_real_time = 0;
+ Util._override_monotonic_time = 0;
+ }
+
+ public virtual void refresh_environment () {
+ // We keep _override_real_time as it is, because time never goes backward within a test case
+ Util._override_monotonic_time = START_MONOTONIC_TIME;
+
+ this.activity_log.clear ();
+ this.activity_monitor_backend = new testable_ActivityMonitorBackend ();
+ this.session_status = new testable_SessionStatus ();
+ this.activity_monitor = new ActivityMonitor (session_status, activity_monitor_backend);
+ this.activity_monitor.detected_idle.connect (this.log_activity);
+ this.activity_monitor.detected_activity.connect (this.log_activity);
+ this.activity_monitor.stop ();
+ }
+
+ public virtual void time_step (bool is_active, int real_seconds, int monotonic_seconds) {
+ Util._override_real_time += real_seconds * Util.MICROSECONDS_IN_SECONDS;
+ Util._override_monotonic_time += monotonic_seconds * Util.MICROSECONDS_IN_SECONDS;
+ if (is_active) this.activity_monitor_backend.push_activity ();
+ this.activity_monitor.poll_activity ();
+ }
+
+ private void log_activity (ActivityMonitor.UserActivity activity) {
+ this.activity_log.add (activity);
+ }
}
// We also need special testable implementations of certain classes and interfaces
public class testable_ActivityMonitorBackend : ActivityMonitorBackend {
- public int64 last_event_time = 0;
- public int64 start_time = 0;
-
- public testable_ActivityMonitorBackend () {
- this.start_time = Util.get_monotonic_time_seconds () - 10;
- }
-
- public void push_activity () {
- this.last_event_time = Util.get_monotonic_time_seconds ();
- }
-
- protected override int time_since_last_event () {
- int64 now_monotonic = Util.get_monotonic_time_seconds ();
- int64 event_time = this.last_event_time;
- if (event_time == 0) event_time = this.start_time;
- return (int) (now_monotonic - event_time);
- }
+ public int64 last_event_time = 0;
+ public int64 start_time = 0;
+
+ public testable_ActivityMonitorBackend () {
+ this.start_time = Util.get_monotonic_time_seconds () - 10;
+ }
+
+ public void push_activity () {
+ this.last_event_time = Util.get_monotonic_time_seconds ();
+ }
+
+ protected override int time_since_last_event () {
+ int64 now_monotonic = Util.get_monotonic_time_seconds ();
+ int64 event_time = this.last_event_time;
+ if (event_time == 0) event_time = this.start_time;
+ return (int) (now_monotonic - event_time);
+ }
}
public class testable_SessionStatus : Object, ISessionStatus {
- public bool virt_is_locked = false;
+ public bool virt_is_locked = false;
- public void do_lock () {
- this.virt_is_locked = true;
- this.locked ();
- }
+ public void do_lock () {
+ this.virt_is_locked = true;
+ this.locked ();
+ }
- public void do_unlock () {
- this.virt_is_locked = false;
- this.unlocked ();
- }
+ public void do_unlock () {
+ this.virt_is_locked = false;
+ this.unlocked ();
+ }
- public bool is_locked () {
- return this.virt_is_locked;
- }
+ public bool is_locked () {
+ return this.virt_is_locked;
+ }
- public void lock_screen () {
- this.virt_is_locked = true;
- }
+ public void lock_screen () {
+ this.virt_is_locked = true;
+ }
- public void blank_screen () {}
+ public void blank_screen () {}
- public void unblank_screen () {}
+ public void unblank_screen () {}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]