[gnome-break-timer] Style change: explicitly reference GLib namespace
- From: Dylan McCall <dylanmccall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-break-timer] Style change: explicitly reference GLib namespace
- Date: Sun, 15 Nov 2020 05:42:11 +0000 (UTC)
commit 2edac04d3a543df7fa074c9168c37f7d74787a4c
Author: Dylan McCall <dylan dylanmccall ca>
Date: Sat Nov 14 20:48:56 2020 -0800
Style change: explicitly reference GLib namespace
In addition, always split classes into their own files.
meson.build | 2 -
org.gnome.BreakTimer.local.json | 85 +++++++++
src/common/IBackgroundPortal.vala | 4 +-
src/common/{IBreakDaemon.vala => IBreakTimer.vala} | 36 +---
src/common/IBreakTimer_TimerBreak.vala | 44 +++++
src/common/IMutterActivityMonitor.vala | 4 +-
src/common/IScreenSaver.vala | 30 ++++
src/common/ISessionStatus.vala | 4 +-
src/common/NaturalTime.vala | 4 +-
src/common/meson.build | 4 +-
src/config.vapi | 3 +-
.../{DaemonApplication.vala => Application.vala} | 43 +++--
src/daemon/BreakManager.vala | 60 +------
src/daemon/BreakManagerDBusObject.vala | 67 +++++++
src/daemon/SessionStatus.vala | 30 ++--
src/daemon/UIFragment.vala | 2 +-
src/daemon/UIManager.vala | 4 +-
src/daemon/activity-monitor/ActivityMonitor.vala | 52 +-----
.../activity-monitor/ActivityMonitorBackend.vala | 70 ++++++++
.../MutterActivityMonitorBackend.vala | 18 +-
src/daemon/break/BreakController.vala | 2 +-
src/daemon/break/BreakType.vala | 2 +-
src/daemon/break/BreakView.vala | 8 +-
src/daemon/break/TimerBreakDBusObject.vala | 48 +++++
src/daemon/break/TimerBreakType.vala | 36 +---
src/daemon/main.vala | 4 +-
src/daemon/meson.build | 7 +-
src/daemon/microbreak/MicroBreakView.vala | 2 +
src/daemon/restbreak/RestBreakView.vala | 2 +
src/daemon/util/Countdown.vala | 2 +-
src/daemon/util/PausableTimeout.vala | 8 +-
src/daemon/util/SimpleFocusManager.vala | 10 +-
src/daemon/util/StatefulTimer.vala | 6 +-
.../{SettingsApplication.vala => Application.vala} | 25 +--
src/settings/BreakConfigurationChooser.vala | 102 +++++++++++
src/settings/BreakInfoPanel.vala | 3 +-
src/settings/BreakManager.vala | 52 +++---
src/settings/BreakSettingsDialog.vala | 119 +-----------
src/settings/BreakSettingsPanel.vala | 2 +-
src/settings/BreakStatusPanel.vala | 3 +-
src/settings/BreakType.vala | 4 +-
src/settings/CircleCounter.vala | 3 +-
src/settings/FixedSizeGrid.vala | 49 +++++
src/settings/MainWindow.vala | 199 +--------------------
src/settings/MicroBreakInfoPanel.vala | 2 +
src/settings/OverlayArrow.vala | 3 +-
src/settings/RestBreakInfoPanel.vala | 2 +
src/settings/StatusPanel.vala | 96 ++++++++++
src/settings/TimeChooser.vala | 4 +-
src/settings/TimerBreakStatusPanel.vala | 2 +
src/settings/TimerBreakType.vala | 29 +--
src/settings/WelcomePanel.vala | 139 ++++++++++++++
src/settings/main.vala | 2 +-
src/settings/meson.build | 8 +-
54 files changed, 938 insertions(+), 613 deletions(-)
---
diff --git a/meson.build b/meson.build
index 05f6bc3..9a8f2ce 100644
--- a/meson.build
+++ b/meson.build
@@ -40,7 +40,6 @@ application_icon = 'org.gnome.BreakTimer'
application_url = 'https://wiki.gnome.org/Apps/BreakTimer'
settings_application_id = 'org.gnome.BreakTimer.Settings'
daemon_application_id = 'org.gnome.BreakTimer'
-daemon_bus_name = 'org.gnome.BreakTimer'
daemon_object_path = '/org/gnome/BreakTimer'
daemon_break_object_base_path = '/org/gnome/BreakTimer/'
@@ -55,7 +54,6 @@ build_conf.set_quoted('SETTINGS_APPLICATION_ID', settings_application_id)
build_conf.set_quoted('SETTINGS_DESKTOP_FILE_ID', settings_application_id + '.desktop')
build_conf.set_quoted('DAEMON_APPLICATION_ID', daemon_application_id)
build_conf.set_quoted('DAEMON_DESKTOP_FILE_ID', daemon_application_id + '.desktop')
-build_conf.set_quoted('DAEMON_BUS_NAME', daemon_bus_name)
build_conf.set_quoted('DAEMON_OBJECT_PATH', daemon_object_path)
build_conf.set_quoted('DAEMON_BREAK_OBJECT_BASE_PATH', daemon_break_object_base_path)
diff --git a/org.gnome.BreakTimer.local.json b/org.gnome.BreakTimer.local.json
new file mode 100644
index 0000000..6d9ba00
--- /dev/null
+++ b/org.gnome.BreakTimer.local.json
@@ -0,0 +1,85 @@
+{
+ "id" : "org.gnome.BreakTimer",
+ "runtime" : "org.gnome.Platform",
+ "runtime-version" : "3.38",
+ "sdk" : "org.gnome.Sdk",
+ "command" : "gnome-break-timer-settings",
+ "finish-args" : [
+ "--share=ipc",
+ "--socket=x11",
+ "--socket=wayland",
+ "--socket=pulseaudio",
+ "--talk-name=org.gnome.Shell",
+ "--talk-name=org.gnome.Mutter.IdleMonitor",
+ "--talk-name=org.gnome.ScreenSaver",
+ "--talk-name=org.freedesktop.Notifications"
+ ],
+ "build-options" : {
+ "cflags" : "-O2 -g",
+ "cxxflags" : "-O2 -g",
+ "env" : {
+ "V" : "1"
+ }
+ },
+ "modules" : [
+ {
+ "name": "libcanberra",
+ "sources": [
+ {
+ "type": "archive",
+ "url": "http://0pointer.de/lennart/projects/libcanberra/libcanberra-0.30.tar.xz",
+ "sha256": "c2b671e67e0c288a69fc33dc1b6f1b534d07882c2aceed37004bf48c601afa72"
+ }
+ ],
+ "config-opts": [
+ "--disable-alsa",
+ "--disable-null",
+ "--disable-oss"
+ ]
+ },
+ {
+ "name": "gsound",
+ "sources": [
+ {
+ "type": "git",
+ "url": "https://gitlab.gnome.org/GNOME/gsound.git",
+ "branch": "master"
+ }
+ ]
+ },
+ {
+ "name": "intltool",
+ "sources": [
+ {
+ "type": "archive",
+ "url": "https://launchpad.net/intltool/trunk/0.51.0/+download/intltool-0.51.0.tar.gz",
+ "sha256": "67c74d94196b153b774ab9f89b2fa6c6ba79352407037c8c14d5aeb334e959cd"
+ }
+ ],
+ "cleanup": [
+ "*"
+ ]
+ },
+ {
+ "name": "sound-theme-freedesktop",
+ "sources": [
+ {
+ "type": "archive",
+ "url": "http://people.freedesktop.org/~mccann/dist/sound-theme-freedesktop-0.8.tar.bz2",
+ "sha256": "cb518b20eef05ec2e82dda1fa89a292c1760dc023aba91b8aa69bafac85e8a14"
+ }
+ ]
+ },
+ {
+ "name" : "gnome-break-timer",
+ "buildsystem" : "meson",
+ "builddir" : true,
+ "sources" : [
+ {
+ "type" : "dir",
+ "path" : "."
+ }
+ ]
+ }
+ ]
+}
diff --git a/src/common/IBackgroundPortal.vala b/src/common/IBackgroundPortal.vala
index e43a64a..9261356 100644
--- a/src/common/IBackgroundPortal.vala
+++ b/src/common/IBackgroundPortal.vala
@@ -15,10 +15,10 @@
* along with GNOME Break Timer. If not, see <http://www.gnu.org/licenses/>.
*/
-namespace BreakTimer {
+namespace BreakTimer.Common {
[DBus (name = "org.freedesktop.portal.Background")]
-public interface IBackgroundPortal : Object {
+public interface IBackgroundPortal : GLib.Object {
public abstract GLib.ObjectPath request_background(string parent_window, GLib.HashTable<string, Variant>
options) throws GLib.DBusError, GLib.IOError;
}
diff --git a/src/common/IBreakDaemon.vala b/src/common/IBreakTimer.vala
similarity index 60%
rename from src/common/IBreakDaemon.vala
rename to src/common/IBreakTimer.vala
index 2413ec7..51a18a7 100644
--- a/src/common/IBreakDaemon.vala
+++ b/src/common/IBreakTimer.vala
@@ -15,21 +15,21 @@
* along with GNOME Break Timer. If not, see <http://www.gnu.org/licenses/>.
*/
-namespace BreakTimer {
+namespace BreakTimer.Common {
[DBus (name = "org.gnome.BreakTimer")]
-public interface IBreakDaemon : Object {
+public interface IBreakTimer : GLib.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;
+ public abstract string? get_current_active_break () throws GLib.DBusError, GLib.IOError;
/** Returns a list of breaks that are currently known to the break daemon. */
- public abstract string[] get_break_ids () throws DBusError, IOError;
+ public abstract string[] get_break_ids () throws GLib.DBusError, GLib.IOError;
/** Returns a list of helpful status messages for each break, for debugging. */
- public abstract string[] get_status_messages () throws DBusError, IOError;
+ public abstract string[] get_status_messages () throws GLib.DBusError, GLib.IOError;
/** Activate the specified break immediately, regardless of the usual activation conditions. */
- public abstract void activate_break (string break_id) throws DBusError, IOError;
+ public abstract void activate_break (string break_id) throws GLib.DBusError, GLib.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
@@ -37,28 +37,4 @@ public interface IBreakDaemon : Object {
// dbus service regularly for updates.
}
-[DBus (name = "org.gnome.BreakTimer.TimerBreak")]
-public interface IBreakDaemon_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;
-
- /** Activate the break */
- public abstract void activate () throws DBusError, IOError;
-}
-
-public struct BreakStatus {
- 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;
-}
-
}
diff --git a/src/common/IBreakTimer_TimerBreak.vala b/src/common/IBreakTimer_TimerBreak.vala
new file mode 100644
index 0000000..688d69d
--- /dev/null
+++ b/src/common/IBreakTimer_TimerBreak.vala
@@ -0,0 +1,44 @@
+/*
+ * This file is part of GNOME Break Timer.
+ *
+ * GNOME Break Timer is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GNOME Break Timer is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNOME Break Timer. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+namespace BreakTimer.Common {
+
+[DBus (name = "org.gnome.BreakTimer.TimerBreak")]
+public interface IBreakTimer_TimerBreak : GLib.Object {
+ /** Get the break's current status, such as time remaining, or time until the break starts */
+ public abstract TimerBreakStatus get_status () throws GLib.DBusError, GLib.IOError;
+
+ /** Activate the break */
+ public abstract void activate () throws GLib.DBusError, GLib.IOError;
+}
+
+public struct BreakStatus {
+ 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;
+}
+
+}
diff --git a/src/common/IMutterActivityMonitor.vala b/src/common/IMutterActivityMonitor.vala
index 0e2301a..215e940 100644
--- a/src/common/IMutterActivityMonitor.vala
+++ b/src/common/IMutterActivityMonitor.vala
@@ -15,10 +15,10 @@
* along with GNOME Break Timer. If not, see <http://www.gnu.org/licenses/>.
*/
-namespace BreakTimer {
+namespace BreakTimer.Common {
[DBus (name = "org.gnome.Mutter.IdleMonitor")]
-public interface IMutterIdleMonitor : Object {
+public interface IMutterIdleMonitor : GLib.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;
diff --git a/src/common/IScreenSaver.vala b/src/common/IScreenSaver.vala
new file mode 100644
index 0000000..d0e3a3d
--- /dev/null
+++ b/src/common/IScreenSaver.vala
@@ -0,0 +1,30 @@
+/*
+ * This file is part of GNOME Break Timer.
+ *
+ * GNOME Break Timer is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GNOME Break Timer is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNOME Break Timer. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+namespace BreakTimer.Common {
+
+[DBus (name = "org.gnome.ScreenSaver")]
+public interface IScreenSaver : GLib.Object {
+ public abstract bool get_active () throws GLib.DBusError, GLib.IOError;
+ public abstract uint32 get_active_time () throws GLib.DBusError, GLib.IOError;
+ public abstract void lock () throws GLib.DBusError, GLib.IOError;
+ public abstract void set_active (bool active) throws GLib.DBusError, GLib.IOError;
+
+ public signal void active_changed (bool active);
+}
+
+}
diff --git a/src/common/ISessionStatus.vala b/src/common/ISessionStatus.vala
index f34942f..7c57915 100644
--- a/src/common/ISessionStatus.vala
+++ b/src/common/ISessionStatus.vala
@@ -15,9 +15,9 @@
* along with GNOME Break Timer. If not, see <http://www.gnu.org/licenses/>.
*/
-namespace BreakTimer {
+namespace BreakTimer.Common {
-public interface ISessionStatus : Object {
+public interface ISessionStatus : GLib.Object {
public signal void locked ();
public signal void unlocked ();
diff --git a/src/common/NaturalTime.vala b/src/common/NaturalTime.vala
index aecc519..4bf0d7f 100644
--- a/src/common/NaturalTime.vala
+++ b/src/common/NaturalTime.vala
@@ -15,9 +15,9 @@
* along with GNOME Break Timer. If not, see <http://www.gnu.org/licenses/>.
*/
-namespace BreakTimer {
+namespace BreakTimer.Common {
-public class NaturalTime : Object {
+public class NaturalTime : GLib.Object {
public delegate string FormatTimeCb (int seconds);
private struct TimeUnit {
diff --git a/src/common/meson.build b/src/common/meson.build
index 615d76f..520d655 100644
--- a/src/common/meson.build
+++ b/src/common/meson.build
@@ -1,7 +1,9 @@
common_sources = files(
'IBackgroundPortal.vala',
- 'IBreakDaemon.vala',
+ 'IBreakTimer_TimerBreak.vala',
+ 'IBreakTimer.vala',
'IMutterActivityMonitor.vala',
+ 'IScreenSaver.vala',
'ISessionStatus.vala',
'NaturalTime.vala'
)
diff --git a/src/config.vapi b/src/config.vapi
index 904d8cb..465f3b2 100644
--- a/src/config.vapi
+++ b/src/config.vapi
@@ -1,10 +1,9 @@
[CCode (cprefix = "", lower_case_cprefix = "", cheader_filename = "config.h")]
-namespace Config {
+namespace BreakTimer.Config {
public const string APPLICATION_ICON;
public const string APPLICATION_URL;
public const string DAEMON_APPLICATION_ID;
public const string DAEMON_BREAK_OBJECT_BASE_PATH;
- public const string DAEMON_BUS_NAME;
public const string DAEMON_DESKTOP_FILE_ID;
public const string DAEMON_OBJECT_PATH;
public const string GETTEXT_PACKAGE;
diff --git a/src/daemon/DaemonApplication.vala b/src/daemon/Application.vala
similarity index 82%
rename from src/daemon/DaemonApplication.vala
rename to src/daemon/Application.vala
index 7dd7fc9..39f36ae 100644
--- a/src/daemon/DaemonApplication.vala
+++ b/src/daemon/Application.vala
@@ -15,12 +15,17 @@
* along with GNOME Break Timer. If not, see <http://www.gnu.org/licenses/>.
*/
+using BreakTimer.Common;
+
namespace BreakTimer.Daemon {
-public class DaemonApplication : Gtk.Application {
+public class Application : Gtk.Application {
const string app_name = _("GNOME Break Timer");
const int DATA_VERSION = 0;
+ // Keep running for one minute after the last break is disabled
+ private const int ACTIVITY_TIMEOUT_MS = 60000;
+
private BreakManager break_manager;
private ISessionStatus session_status;
private ActivityMonitorBackend activity_monitor_backend;
@@ -29,18 +34,17 @@ public class DaemonApplication : Gtk.Application {
private string cache_path;
- public DaemonApplication () {
- Object (
+ public Application () {
+ GLib.Object (
application_id: Config.DAEMON_APPLICATION_ID,
- register_session: true,
- flags: ApplicationFlags.FLAGS_NONE
+ flags: ApplicationFlags.FLAGS_NONE,
+ inactivity_timeout: ACTIVITY_TIMEOUT_MS,
+ register_session: true
);
- Environment.set_application_name (app_name);
- // Keep running for one minute after the last break is disabled
- this.set_inactivity_timeout (60 * 1000);
+ GLib.Environment.set_application_name (app_name);
- string user_cache_path = Environment.get_user_cache_dir ();
+ string user_cache_path = GLib.Environment.get_user_cache_dir ();
this.cache_path = Path.build_filename (user_cache_path, "gnome-break-timer");
}
@@ -75,11 +79,6 @@ public class DaemonApplication : Gtk.Application {
this.restore_state ();
this.activity_monitor.start ();
-
- var connection = this.get_dbus_connection ();
- if (connection != null) {
- Bus.own_name_on_connection (connection, Config.DAEMON_BUS_NAME, BusNameOwnerFlags.REPLACE, null,
null);
- }
}
public override void shutdown () {
@@ -88,11 +87,11 @@ public class DaemonApplication : Gtk.Application {
this.save_state ();
}
- private File get_state_file () {
- File cache_dir = File.new_for_path (this.cache_path);
+ private GLib.File get_state_file () {
+ GLib.File cache_dir = GLib.File.new_for_path (this.cache_path);
try {
if (! cache_dir.query_exists ()) cache_dir.make_directory_with_parents ();
- } catch (Error e) {
+ } catch (GLib.Error e) {
GLib.warning ("Error creating cache directory: %s", e.message);
}
string state_file_name = "last-state-%d".printf (DATA_VERSION);
@@ -100,7 +99,7 @@ public class DaemonApplication : Gtk.Application {
}
private void save_state () {
- File state_file = this.get_state_file ();
+ GLib.File state_file = this.get_state_file ();
Json.Generator generator = new Json.Generator ();
Json.Node root = new Json.Node (Json.NodeType.OBJECT);
@@ -113,22 +112,22 @@ public class DaemonApplication : Gtk.Application {
root_object.set_object_member ("activity_monitor", this.activity_monitor.serialize ());
try {
- OutputStream state_stream = state_file.replace (null, false, FileCreateFlags.NONE);
+ OutputStream state_stream = state_file.replace (null, false, GLib.FileCreateFlags.NONE);
generator.to_stream (state_stream);
- } catch (Error e) {
+ } catch (GLib.Error e) {
GLib.warning ("Error writing to state file: %s", e.message);
}
}
private void restore_state () {
- File state_file = this.get_state_file ();
+ GLib.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) {
+ } catch (GLib.Error e) {
GLib.warning ("Error reading state file: %s", e.message);
}
diff --git a/src/daemon/BreakManager.vala b/src/daemon/BreakManager.vala
index 58e1f6c..172cc14 100644
--- a/src/daemon/BreakManager.vala
+++ b/src/daemon/BreakManager.vala
@@ -17,11 +17,11 @@
namespace BreakTimer.Daemon {
-public class BreakManager : Object {
+public class BreakManager : GLib.Object {
private UIManager ui_manager;
private Gee.Map<string, BreakType> breaks;
- private BreakDaemonServer break_daemon_server;
+ private BreakManagerDBusObject dbus_object;
private GLib.Settings settings;
public bool master_enabled { get; set; }
@@ -38,14 +38,17 @@ public class BreakManager : Object {
this.notify["master-enabled"].connect (this.update_enabled_breaks);
this.notify["selected-break-ids"].connect (this.update_enabled_breaks);
- this.break_daemon_server = new BreakDaemonServer (this);
+ this.dbus_object = new BreakManagerDBusObject (this);
try {
- DBusConnection connection = Bus.get_sync (BusType.SESSION, null);
+ GLib.DBusConnection connection = GLib.Bus.get_sync (
+ GLib.BusType.SESSION,
+ null
+ );
connection.register_object (
Config.DAEMON_OBJECT_PATH,
- this.break_daemon_server
+ this.dbus_object
);
- } catch (IOError error) {
+ } catch (GLib.IOError error) {
GLib.error ("Error registering daemon on the session bus: %s", error.message);
}
}
@@ -100,49 +103,4 @@ public class BreakManager : Object {
}
}
-[DBus (name = "org.gnome.BreakTimer")]
-public class BreakDaemonServer : Object, IBreakDaemon {
- private weak BreakManager break_manager;
-
- public BreakDaemonServer (BreakManager break_manager) {
- this.break_manager = break_manager;
- }
-
- public string? get_current_active_break () throws GLib.DBusError, GLib.IOError {
- /* 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 () throws GLib.DBusError, GLib.IOError {
- 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 () throws GLib.DBusError, GLib.IOError {
- return this.break_manager.all_break_ids ().to_array ();
- }
-
- public string[] get_status_messages () throws GLib.DBusError, GLib.IOError {
- 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) throws GLib.DBusError, GLib.IOError {
- 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/src/daemon/BreakManagerDBusObject.vala b/src/daemon/BreakManagerDBusObject.vala
new file mode 100644
index 0000000..de7771b
--- /dev/null
+++ b/src/daemon/BreakManagerDBusObject.vala
@@ -0,0 +1,67 @@
+/*
+ * This file is part of GNOME Break Timer.
+ *
+ * GNOME Break Timer is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GNOME Break Timer is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNOME Break Timer. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+using BreakTimer.Common;
+
+namespace BreakTimer.Daemon {
+
+[DBus (name = "org.gnome.BreakTimer")]
+public class BreakManagerDBusObject : GLib.Object, IBreakTimer {
+ private weak BreakManager break_manager;
+
+ public BreakManagerDBusObject (BreakManager break_manager) {
+ this.break_manager = break_manager;
+ }
+
+ public string? get_current_active_break () throws GLib.DBusError, GLib.IOError {
+ /* 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 () throws GLib.DBusError, GLib.IOError {
+ 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 () throws GLib.DBusError, GLib.IOError {
+ return this.break_manager.all_break_ids ().to_array ();
+ }
+
+ public string[] get_status_messages () throws GLib.DBusError, GLib.IOError {
+ 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) throws GLib.DBusError, GLib.IOError {
+ 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/src/daemon/SessionStatus.vala b/src/daemon/SessionStatus.vala
index d6a8dd5..19f6318 100644
--- a/src/daemon/SessionStatus.vala
+++ b/src/daemon/SessionStatus.vala
@@ -15,24 +15,15 @@
* along with GNOME Break Timer. If not, see <http://www.gnu.org/licenses/>.
*/
-namespace BreakTimer.Daemon {
-
-[DBus (name = "org.gnome.ScreenSaver")]
-public interface IScreenSaver : Object {
- public abstract bool get_active () throws DBusError, IOError;
- public abstract uint32 get_active_time () throws DBusError, IOError;
- public abstract void lock () throws DBusError, IOError;
- public abstract void set_active (bool active) throws DBusError, IOError;
-
- public signal void active_changed (bool active);
+using BreakTimer.Common;
-}
+namespace BreakTimer.Daemon {
/**
* Abstraction of GNOME Screensaver's dbus interface with gentle defaults in
* case we are unable to connect.
*/
-public class SessionStatus : ISessionStatus, Object {
+public class SessionStatus : GLib.Object, ISessionStatus {
private Gtk.Application application;
private IScreenSaver? screensaver;
private bool screensaver_is_active = false;
@@ -40,20 +31,25 @@ public class SessionStatus : ISessionStatus, Object {
public SessionStatus (Gtk.Application application) {
this.application = application;
- Bus.watch_name (BusType.SESSION, "org.gnome.ScreenSaver", BusNameWatcherFlags.NONE,
- this.screensaver_appeared, this.screensaver_disappeared);
+ GLib.Bus.watch_name (
+ GLib.BusType.SESSION,
+ "org.gnome.ScreenSaver",
+ GLib.BusNameWatcherFlags.NONE,
+ this.screensaver_appeared,
+ this.screensaver_disappeared
+ );
}
private void screensaver_appeared () {
try {
- this.screensaver = Bus.get_proxy_sync (
- BusType.SESSION,
+ this.screensaver = GLib.Bus.get_proxy_sync (
+ GLib.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) {
+ } catch (GLib.IOError error) {
this.screensaver = null;
GLib.warning ("Error connecting to screensaver service: %s", error.message);
} catch (GLib.DBusError error) {
diff --git a/src/daemon/UIFragment.vala b/src/daemon/UIFragment.vala
index b81e092..c2817c9 100644
--- a/src/daemon/UIFragment.vala
+++ b/src/daemon/UIFragment.vala
@@ -21,7 +21,7 @@ namespace BreakTimer.Daemon {
* Provides a simple interface for UIManager to create notifications and
* overlays.
*/
-public abstract class UIFragment : Object, IFocusable {
+public abstract class UIFragment : GLib.Object, IFocusable {
protected UIManager ui_manager;
protected Notify.Notification? notification;
diff --git a/src/daemon/UIManager.vala b/src/daemon/UIManager.vala
index b2898ba..279b417 100644
--- a/src/daemon/UIManager.vala
+++ b/src/daemon/UIManager.vala
@@ -15,6 +15,8 @@
* along with GNOME Break Timer. If not, see <http://www.gnu.org/licenses/>.
*/
+using BreakTimer.Common;
+
namespace BreakTimer.Daemon {
/**
@@ -32,7 +34,7 @@ public class UIManager : SimpleFocusManager {
private Notify.Notification? notification;
private Notify.Notification? lock_notification;
- private List<string> notify_capabilities;
+ private GLib.List<string> notify_capabilities;
public UIManager (Gtk.Application application, ISessionStatus session_status) {
this.application = application;
diff --git a/src/daemon/activity-monitor/ActivityMonitor.vala
b/src/daemon/activity-monitor/ActivityMonitor.vala
index de66c12..a4f7e26 100644
--- a/src/daemon/activity-monitor/ActivityMonitor.vala
+++ b/src/daemon/activity-monitor/ActivityMonitor.vala
@@ -15,9 +15,11 @@
* along with GNOME Break Timer. If not, see <http://www.gnu.org/licenses/>.
*/
+using BreakTimer.Common;
+
namespace BreakTimer.Daemon {
-public class ActivityMonitor : Object {
+public class ActivityMonitor : GLib.Object {
public signal void detected_idle (UserActivity activity);
public signal void detected_activity (UserActivity activity);
@@ -146,52 +148,4 @@ public class ActivityMonitor : Object {
}
}
-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 / TimeUnit.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 = TimeUnit.get_real_time_seconds ();
- int64 now_monotonic = TimeUnit.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/src/daemon/activity-monitor/ActivityMonitorBackend.vala
b/src/daemon/activity-monitor/ActivityMonitorBackend.vala
new file mode 100644
index 0000000..937498f
--- /dev/null
+++ b/src/daemon/activity-monitor/ActivityMonitorBackend.vala
@@ -0,0 +1,70 @@
+/*
+ * This file is part of GNOME Break Timer.
+ *
+ * GNOME Break Timer is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GNOME Break Timer is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNOME Break Timer. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+using BreakTimer.Common;
+
+namespace BreakTimer.Daemon {
+
+public abstract class ActivityMonitorBackend : GLib.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 / TimeUnit.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 = TimeUnit.get_real_time_seconds ();
+ int64 now_monotonic = TimeUnit.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/src/daemon/activity-monitor/MutterActivityMonitorBackend.vala
b/src/daemon/activity-monitor/MutterActivityMonitorBackend.vala
index f70e4b4..3dfa69c 100644
--- a/src/daemon/activity-monitor/MutterActivityMonitorBackend.vala
+++ b/src/daemon/activity-monitor/MutterActivityMonitorBackend.vala
@@ -15,6 +15,8 @@
* along with GNOME Break Timer. If not, see <http://www.gnu.org/licenses/>.
*/
+using BreakTimer.Common;
+
namespace BreakTimer.Daemon {
public class MutterActivityMonitorBackend : ActivityMonitorBackend {
@@ -30,10 +32,10 @@ public class MutterActivityMonitorBackend : ActivityMonitorBackend {
public MutterActivityMonitorBackend () {
this.user_is_active = false;
- Bus.watch_name (
- BusType.SESSION,
+ GLib.Bus.watch_name (
+ GLib.BusType.SESSION,
"org.gnome.Mutter.IdleMonitor",
- BusNameWatcherFlags.NONE,
+ GLib.BusNameWatcherFlags.NONE,
this.mutter_idle_monitor_appeared,
this.mutter_idle_monitor_disappeared
);
@@ -47,15 +49,15 @@ public class MutterActivityMonitorBackend : ActivityMonitorBackend {
private void mutter_idle_monitor_appeared () {
try {
- this.mutter_idle_monitor = Bus.get_proxy_sync (
- BusType.SESSION,
+ this.mutter_idle_monitor = GLib.Bus.get_proxy_sync (
+ GLib.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) {
+ } catch (GLib.IOError error) {
this.mutter_idle_monitor = null;
GLib.warning ("Error connecting to mutter idle monitor service: %s", error.message);
} catch (GLib.DBusError error) {
@@ -75,7 +77,7 @@ public class MutterActivityMonitorBackend : ActivityMonitorBackend {
this.update_last_idle_time();
try {
this.user_active_watch_id = this.mutter_idle_monitor.add_user_active_watch ();
- } catch (IOError error) {
+ } catch (GLib.IOError error) {
GLib.warning ("Error connecting to mutter idle monitor service: %s", error.message);
} catch (GLib.DBusError error) {
GLib.warning ("Error adding mutter user active watch: %s", error.message);
@@ -89,7 +91,7 @@ public class MutterActivityMonitorBackend : ActivityMonitorBackend {
private void update_last_idle_time() {
try {
this.last_idle_time_ms = this.mutter_idle_monitor.get_idletime ();
- } catch (IOError error) {
+ } catch (GLib.IOError error) {
GLib.warning ("Error connecting to mutter idle monitor service: %s", error.message);
} catch (GLib.DBusError error) {
GLib.warning ("Error getting mutter idletime: %s", error.message);
diff --git a/src/daemon/break/BreakController.vala b/src/daemon/break/BreakController.vala
index 1a6adf7..dfcb156 100644
--- a/src/daemon/break/BreakController.vala
+++ b/src/daemon/break/BreakController.vala
@@ -26,7 +26,7 @@ namespace BreakTimer.Daemon {
* This class provides mechanisms for tracking and directly setting the
* break's state, which can be either WAITING, ACTIVE, or DISABLED.
*/
-public abstract class BreakController : Object {
+public abstract class BreakController : GLib.Object {
/**
* ''WAITING'': The break has not started yet. For example, it may be
* monitoring user activity in the background, waiting
diff --git a/src/daemon/break/BreakType.vala b/src/daemon/break/BreakType.vala
index 0d10948..c9c99ea 100644
--- a/src/daemon/break/BreakType.vala
+++ b/src/daemon/break/BreakType.vala
@@ -17,7 +17,7 @@
namespace BreakTimer.Daemon {
-public abstract class BreakType : Object {
+public abstract class BreakType : GLib.Object {
public string id;
public BreakController break_controller;
public BreakView break_view;
diff --git a/src/daemon/break/BreakView.vala b/src/daemon/break/BreakView.vala
index 9deda4e..c7351bf 100644
--- a/src/daemon/break/BreakView.vala
+++ b/src/daemon/break/BreakView.vala
@@ -87,12 +87,12 @@ public abstract class BreakView : UIFragment {
}
protected void show_break_info () {
- AppInfo settings_app_info = new DesktopAppInfo (Config.SETTINGS_APPLICATION_ID);
- AppLaunchContext app_launch_context = new AppLaunchContext ();
+ GLib.AppInfo settings_app_info = new GLib.DesktopAppInfo (Config.SETTINGS_APPLICATION_ID);
+ GLib.AppLaunchContext app_launch_context = new GLib.AppLaunchContext ();
try {
settings_app_info.launch (null, app_launch_context);
- } catch (Error error) {
- stderr.printf ("Error launching settings application: %s\n", error.message);
+ } catch (GLib.Error error) {
+ GLib.warning ("Error launching settings application: %s", error.message);
}
}
diff --git a/src/daemon/break/TimerBreakDBusObject.vala b/src/daemon/break/TimerBreakDBusObject.vala
new file mode 100644
index 0000000..adfdad1
--- /dev/null
+++ b/src/daemon/break/TimerBreakDBusObject.vala
@@ -0,0 +1,48 @@
+/*
+ * This file is part of GNOME Break Timer.
+ *
+ * GNOME Break Timer is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GNOME Break Timer is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNOME Break Timer. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+using BreakTimer.Common;
+
+namespace BreakTimer.Daemon {
+
+[DBus (name = "org.gnome.BreakTimer.TimerBreak")]
+private class TimerBreakDBusObject : GLib.Object, IBreakTimer_TimerBreak {
+ private weak TimerBreakController break_controller;
+ private weak TimerBreakView break_view;
+
+ public TimerBreakDBusObject (TimerBreakController break_controller, TimerBreakView break_view) {
+ this.break_controller = break_controller;
+ this.break_view = break_view;
+ }
+
+ public TimerBreakStatus get_status () throws GLib.DBusError, GLib.IOError {
+ 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 () throws GLib.DBusError, GLib.IOError {
+ this.break_controller.activate ();
+ }
+}
+
+}
diff --git a/src/daemon/break/TimerBreakType.vala b/src/daemon/break/TimerBreakType.vala
index 6eb2861..8e2bc66 100644
--- a/src/daemon/break/TimerBreakType.vala
+++ b/src/daemon/break/TimerBreakType.vala
@@ -18,7 +18,7 @@
namespace BreakTimer.Daemon {
public abstract class TimerBreakType : BreakType {
- private BreakDaemon_TimerBreakServer break_type_server;
+ private TimerBreakDBusObject dbus_object;
protected TimerBreakType (string id, GLib.Settings settings) {
base (id, settings);
@@ -33,46 +33,20 @@ public abstract class TimerBreakType : BreakType {
this.settings.bind ("interval-seconds", timer_break_controller, "interval",
GLib.SettingsBindFlags.GET);
this.settings.bind ("duration-seconds", timer_break_controller, "duration",
GLib.SettingsBindFlags.GET);
- this.break_type_server = new BreakDaemon_TimerBreakServer (
+ this.dbus_object = new TimerBreakDBusObject (
timer_break_controller,
timer_break_view
);
try {
- DBusConnection connection = Bus.get_sync (BusType.SESSION, null);
+ GLib.DBusConnection connection = GLib.Bus.get_sync (GLib.BusType.SESSION, null);
connection.register_object (
Config.DAEMON_BREAK_OBJECT_BASE_PATH+this.id,
- this.break_type_server
+ this.dbus_object
);
- } catch (IOError error) {
+ } catch (GLib.IOError error) {
GLib.error ("Error registering break type on the session bus: %s", error.message);
}
}
}
-[DBus (name = "org.gnome.BreakTimer.TimerBreak")]
-private class BreakDaemon_TimerBreakServer : Object, IBreakDaemon_TimerBreak {
- private weak TimerBreakController break_controller;
- private weak TimerBreakView break_view;
-
- public BreakDaemon_TimerBreakServer (TimerBreakController break_controller, TimerBreakView break_view) {
- this.break_controller = break_controller;
- this.break_view = break_view;
- }
-
- public TimerBreakStatus get_status () throws GLib.DBusError, GLib.IOError {
- 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 () throws GLib.DBusError, GLib.IOError {
- this.break_controller.activate ();
- }
-}
-
}
diff --git a/src/daemon/main.vala b/src/daemon/main.vala
index b652851..18d83aa 100644
--- a/src/daemon/main.vala
+++ b/src/daemon/main.vala
@@ -17,10 +17,10 @@
namespace BreakTimer.Daemon {
-static DaemonApplication application;
+static Application application;
public int main (string[] args) {
- application = new DaemonApplication ();
+ application = new Application ();
Posix.signal (Posix.Signal.INT, sigint_cb);
Posix.signal (Posix.Signal.TERM, sigint_cb);
Posix.signal (Posix.Signal.HUP, sigint_cb);
diff --git a/src/daemon/meson.build b/src/daemon/meson.build
index efec58b..05c8c81 100644
--- a/src/daemon/meson.build
+++ b/src/daemon/meson.build
@@ -1,15 +1,18 @@
daemon_sources = files(
+ 'activity-monitor/ActivityMonitorBackend.vala',
'activity-monitor/ActivityMonitor.vala',
'activity-monitor/MutterActivityMonitorBackend.vala',
'activity-monitor/UserActivity.vala',
+ 'Application.vala',
'break/BreakController.vala',
'break/BreakType.vala',
'break/BreakView.vala',
+ 'BreakManagerDBusObject.vala',
+ 'BreakManager.vala',
'break/TimerBreakController.vala',
+ 'break/TimerBreakDBusObject.vala',
'break/TimerBreakType.vala',
'break/TimerBreakView.vala',
- 'BreakManager.vala',
- 'DaemonApplication.vala',
'main.vala',
'microbreak/MicroBreakController.vala',
'microbreak/MicroBreakType.vala',
diff --git a/src/daemon/microbreak/MicroBreakView.vala b/src/daemon/microbreak/MicroBreakView.vala
index dffb463..7d1ffe5 100644
--- a/src/daemon/microbreak/MicroBreakView.vala
+++ b/src/daemon/microbreak/MicroBreakView.vala
@@ -15,6 +15,8 @@
* along with GNOME Break Timer. If not, see <http://www.gnu.org/licenses/>.
*/
+using BreakTimer.Common;
+
namespace BreakTimer.Daemon {
/* TODO: notification when user is away for rest duration */
diff --git a/src/daemon/restbreak/RestBreakView.vala b/src/daemon/restbreak/RestBreakView.vala
index d3f8cd1..8f72321 100644
--- a/src/daemon/restbreak/RestBreakView.vala
+++ b/src/daemon/restbreak/RestBreakView.vala
@@ -15,6 +15,8 @@
* along with GNOME Break Timer. If not, see <http://www.gnu.org/licenses/>.
*/
+using BreakTimer.Common;
+
namespace BreakTimer.Daemon {
/* TODO: Use a single persistent notification throughout a given break */
diff --git a/src/daemon/util/Countdown.vala b/src/daemon/util/Countdown.vala
index 9305f57..1fc81cd 100644
--- a/src/daemon/util/Countdown.vala
+++ b/src/daemon/util/Countdown.vala
@@ -23,7 +23,7 @@ namespace BreakTimer.Daemon {
* of system state. The countdown can be paused, and its duration can be
* adjusted at any time using penalty and bonus time.
*/
-public class Countdown : Object {
+public class Countdown : GLib.Object {
private enum State {
STOPPED,
PAUSED,
diff --git a/src/daemon/util/PausableTimeout.vala b/src/daemon/util/PausableTimeout.vala
index 6530aa1..523740e 100644
--- a/src/daemon/util/PausableTimeout.vala
+++ b/src/daemon/util/PausableTimeout.vala
@@ -23,7 +23,7 @@ namespace BreakTimer.Daemon {
* so it is trivial to stop and start the timeout by calling the stop and
* start methods, respectively.
*/
-public class PausableTimeout : Object {
+public class PausableTimeout : GLib.Object {
public delegate void TimeoutCB (PausableTimeout timeout, int delta_millisecs);
private unowned TimeoutCB timeout_cb;
@@ -66,12 +66,12 @@ public class PausableTimeout : Object {
public void start () {
if (this.is_running ()) {
- Source.remove (this.source_id);
+ GLib.Source.remove (this.source_id);
}
this.last_time = TimeUnit.get_monotonic_time ();
- this.source_id = Timeout.add_seconds (this.frequency, this.timeout_wrapper);
+ this.source_id = GLib.Timeout.add_seconds (this.frequency, this.timeout_wrapper);
}
public void set_frequency (int frequency) {
@@ -83,7 +83,7 @@ public class PausableTimeout : Object {
public void stop () {
if (this.is_running ()) {
- Source.remove (this.source_id);
+ GLib.Source.remove (this.source_id);
this.source_id = 0;
}
}
diff --git a/src/daemon/util/SimpleFocusManager.vala b/src/daemon/util/SimpleFocusManager.vala
index 3da256e..cac6469 100644
--- a/src/daemon/util/SimpleFocusManager.vala
+++ b/src/daemon/util/SimpleFocusManager.vala
@@ -17,7 +17,7 @@
namespace BreakTimer.Daemon {
-public interface IFocusable : Object {
+public interface IFocusable : GLib.Object {
public abstract void focus_started ();
public abstract void focus_stopped ();
}
@@ -35,8 +35,8 @@ public enum FocusPriority {
* priority will be given focus. Focus can change at any time as other objects
* request or release focus.
*/
-public class SimpleFocusManager : Object {
- private class Request : Object {
+public class SimpleFocusManager : GLib.Object {
+ private class Request : GLib.Object {
public IFocusable owner;
public FocusPriority priority;
@@ -51,11 +51,11 @@ public class SimpleFocusManager : Object {
}
}
- private SList<Request> focus_requests;
+ private GLib.SList<Request> focus_requests;
private Request? current_focus;
public SimpleFocusManager () {
- this.focus_requests = new SList<Request> ();
+ this.focus_requests = new GLib.SList<Request> ();
this.current_focus = null;
}
diff --git a/src/daemon/util/StatefulTimer.vala b/src/daemon/util/StatefulTimer.vala
index f041a41..a897814 100644
--- a/src/daemon/util/StatefulTimer.vala
+++ b/src/daemon/util/StatefulTimer.vala
@@ -24,19 +24,19 @@ namespace BreakTimer.Daemon {
* - a state property to keep track of whether the timer is stopped.
* - a "lap" feature (start_lap, lap_time) to measure smaller time intervals
*/
-public class StatefulTimer : Object {
+public class StatefulTimer : GLib.Object {
public enum State {
STOPPED,
COUNTING
}
public State state { public get; private set; }
- private Timer timer;
+ private GLib.Timer timer;
private double timer_error;
private double lap_start;
public StatefulTimer () {
- this.timer = new Timer ();
+ this.timer = new GLib.Timer ();
this.state = State.COUNTING;
}
diff --git a/src/settings/SettingsApplication.vala b/src/settings/Application.vala
similarity index 84%
rename from src/settings/SettingsApplication.vala
rename to src/settings/Application.vala
index b7be9b4..bbd6e79 100644
--- a/src/settings/SettingsApplication.vala
+++ b/src/settings/Application.vala
@@ -17,7 +17,7 @@
namespace BreakTimer.Settings {
-public class SettingsApplication : Gtk.Application {
+public class Application : Gtk.Application {
private const string STYLE_DATA =
"""
._settings-title {
@@ -56,10 +56,10 @@ public class SettingsApplication : Gtk.Application {
private BreakManager break_manager;
private MainWindow main_window;
- public SettingsApplication () {
- Object (
+ public Application () {
+ GLib.Object (
application_id: Config.SETTINGS_APPLICATION_ID,
- flags: ApplicationFlags.FLAGS_NONE
+ flags: GLib.ApplicationFlags.FLAGS_NONE
);
}
@@ -84,20 +84,21 @@ public class SettingsApplication : Gtk.Application {
try {
style_provider.load_from_data (STYLE_DATA, -1);
- } catch (Error error) {
- stderr.printf ("Error loading style data: %s\n", error.message);
+ } catch (GLib.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);
+ screen,
+ style_provider,
+ Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
+ );
- SimpleAction about_action = new SimpleAction ("about", null);
+ GLib.SimpleAction about_action = new GLib.SimpleAction ("about", null);
this.add_action (about_action);
about_action.activate.connect (this.on_about_activate_cb);
- SimpleAction quit_action = new SimpleAction ("quit", null);
+ GLib.SimpleAction quit_action = new GLib.SimpleAction ("quit", null);
this.add_action (quit_action);
quit_action.activate.connect (this.quit);
@@ -111,7 +112,7 @@ public class SettingsApplication : Gtk.Application {
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; });
+ GLib.Timeout.add (500, () => { delayed_start_cb (); return false; });
}
private void delayed_start_cb () {
diff --git a/src/settings/BreakConfigurationChooser.vala b/src/settings/BreakConfigurationChooser.vala
new file mode 100644
index 0000000..1f0478b
--- /dev/null
+++ b/src/settings/BreakConfigurationChooser.vala
@@ -0,0 +1,102 @@
+/*
+ * This file is part of GNOME Break Timer.
+ *
+ * GNOME Break Timer is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GNOME Break Timer is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNOME Break Timer. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+namespace BreakTimer.Settings {
+
+class BreakConfigurationChooser : Gtk.ComboBox {
+ public class Configuration : GLib.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 () {
+ GLib.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;
+ }
+}
+
+}
diff --git a/src/settings/BreakInfoPanel.vala b/src/settings/BreakInfoPanel.vala
index 7c8640f..0afe67b 100644
--- a/src/settings/BreakInfoPanel.vala
+++ b/src/settings/BreakInfoPanel.vala
@@ -26,7 +26,8 @@ public abstract class BreakInfoPanel : Gtk.Grid {
private Gtk.Label detail_label;
protected BreakInfoPanel (BreakType break_type, string title) {
- Object ();
+ GLib.Object ();
+
this.break_type = break_type;
this.title = title;
diff --git a/src/settings/BreakManager.vala b/src/settings/BreakManager.vala
index ed3f073..d23da35 100644
--- a/src/settings/BreakManager.vala
+++ b/src/settings/BreakManager.vala
@@ -18,12 +18,14 @@
// TODO: This intentionally resembles BreakManager from the daemon
// application. Ideally, it should be common code in the future.
+using BreakTimer.Common;
+
namespace BreakTimer.Settings {
-public class BreakManager : Object {
- private SettingsApplication application;
+public class BreakManager : GLib.Object {
+ private Application application;
- private IBreakDaemon break_daemon;
+ private IBreakTimer break_daemon;
private Gee.Map<string, BreakType> breaks;
private GLib.List<BreakType> breaks_ordered;
@@ -35,7 +37,7 @@ public class BreakManager : Object {
IBackgroundPortal? background_portal = null;
- public BreakManager (SettingsApplication application) {
+ public BreakManager (Application application) {
this.application = application;
this.breaks = new Gee.HashMap<string, BreakType> ();
this.breaks_ordered = new GLib.List<BreakType> ();
@@ -44,8 +46,8 @@ public class BreakManager : Object {
// TODO: Does this work outside of a flatpak? We could remove the
// extra file we install in data/autostart, which would be nice.
try {
- this.background_portal = Bus.get_proxy_sync (
- BusType.SESSION,
+ this.background_portal = GLib.Bus.get_proxy_sync (
+ GLib.BusType.SESSION,
"org.freedesktop.portal.Desktop",
"/org/freedesktop/portal/desktop"
);
@@ -76,10 +78,10 @@ public class BreakManager : Object {
}
if (this.background_portal != null) {
- HashTable<string, Variant> options = new HashTable<string, Variant> (str_hash, str_equal);
- GLib.Variant commandline_variant = new GLib.Variant.strv ({"gnome-break-timer-daemon"});
+ var options = new HashTable<string, GLib.Variant> (str_hash, str_equal);
+ var commandline = new GLib.Variant.strv ({"gnome-break-timer-daemon"});
options.insert ("autostart", this.master_enabled);
- options.insert ("commandline", commandline_variant);
+ options.insert ("commandline", commandline);
// RequestBackground creates a desktop file with the same name as
// the flatpak, which happens to be the dbus name of the daemon
// (although it is not the dbus name of the settings application).
@@ -91,7 +93,7 @@ public class BreakManager : Object {
// TODO: Handle response, and display an error if the result
// includes `autostart == false || background == false`.
this.background_portal.request_background("", options);
- } catch (IOError error) {
+ } catch (GLib.IOError error) {
GLib.warning ("Error connecting to xdg desktop portal: %s", error.message);
} catch (GLib.DBusError error) {
GLib.warning ("Error enabling autostart: %s", error.message);
@@ -100,7 +102,10 @@ public class BreakManager : Object {
}
private bool get_is_in_flatpak () {
- string flatpak_info_path = GLib.Path.build_filename (GLib.Environment.get_user_runtime_dir (),
"flatpak-info");
+ string flatpak_info_path = GLib.Path.build_filename (
+ GLib.Environment.get_user_runtime_dir (),
+ "flatpak-info"
+ );
return GLib.FileUtils.test (flatpak_info_path, GLib.FileTest.EXISTS);
}
@@ -110,8 +115,13 @@ public class BreakManager : Object {
this.status_changed ();
- Bus.watch_name (BusType.SESSION, Config.DAEMON_BUS_NAME, BusNameWatcherFlags.NONE,
- this.break_daemon_appeared, this.break_daemon_disappeared);
+ GLib.Bus.watch_name (
+ GLib.BusType.SESSION,
+ Config.DAEMON_APPLICATION_ID,
+ GLib.BusNameWatcherFlags.NONE,
+ this.break_daemon_appeared,
+ this.break_daemon_disappeared
+ );
}
public Gee.Set<string> all_break_ids () {
@@ -159,14 +169,14 @@ public class BreakManager : Object {
private void break_daemon_appeared () {
try {
- this.break_daemon = Bus.get_proxy_sync (
- BusType.SESSION,
- Config.DAEMON_BUS_NAME,
+ this.break_daemon = GLib.Bus.get_proxy_sync (
+ GLib.BusType.SESSION,
+ Config.DAEMON_APPLICATION_ID,
Config.DAEMON_OBJECT_PATH,
- DBusProxyFlags.DO_NOT_AUTO_START
+ GLib.DBusProxyFlags.DO_NOT_AUTO_START
);
this.break_status_available ();
- } catch (IOError error) {
+ } catch (GLib.IOError error) {
this.break_daemon = null;
GLib.warning ("Error connecting to break daemon service: %s", error.message);
}
@@ -185,11 +195,11 @@ public class BreakManager : Object {
}
private void launch_break_timer_service () {
- AppInfo daemon_app_info = new DesktopAppInfo (Config.DAEMON_DESKTOP_FILE_ID);
- AppLaunchContext app_launch_context = new AppLaunchContext ();
+ GLib.AppInfo daemon_app_info = new GLib.DesktopAppInfo (Config.DAEMON_DESKTOP_FILE_ID);
+ GLib.AppLaunchContext app_launch_context = new GLib.AppLaunchContext ();
try {
daemon_app_info.launch (null, app_launch_context);
- } catch (Error error) {
+ } catch (GLib.Error error) {
GLib.warning ("Error launching daemon application: %s", error.message);
}
}
diff --git a/src/settings/BreakSettingsDialog.vala b/src/settings/BreakSettingsDialog.vala
index 5d360cb..0c165d2 100644
--- a/src/settings/BreakSettingsDialog.vala
+++ b/src/settings/BreakSettingsDialog.vala
@@ -26,7 +26,8 @@ public class BreakSettingsDialog : Gtk.Dialog {
private const int ABOUT_BUTTON_RESPONSE = 5;
public BreakSettingsDialog (BreakManager break_manager) {
- Object (use_header_bar: 1);
+ GLib.Object (use_header_bar: 1);
+
this.break_manager = break_manager;
GLib.Settings settings = new GLib.Settings ("org.gnome.BreakTimer");
@@ -103,120 +104,4 @@ public class BreakSettingsDialog : Gtk.Dialog {
}
}
-
-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;
- }
-}
-
-
-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;
- }
-}
-
}
diff --git a/src/settings/BreakSettingsPanel.vala b/src/settings/BreakSettingsPanel.vala
index e083c01..aa8faa0 100644
--- a/src/settings/BreakSettingsPanel.vala
+++ b/src/settings/BreakSettingsPanel.vala
@@ -22,7 +22,7 @@ public abstract class BreakSettingsPanel : Gtk.Grid {
private Gtk.Grid details;
protected BreakSettingsPanel (BreakType break_type, string title, string? description) {
- Object ();
+ GLib.Object ();
this.set_orientation (Gtk.Orientation.VERTICAL);
this.set_row_spacing (10);
diff --git a/src/settings/BreakStatusPanel.vala b/src/settings/BreakStatusPanel.vala
index 402d679..3ec29d6 100644
--- a/src/settings/BreakStatusPanel.vala
+++ b/src/settings/BreakStatusPanel.vala
@@ -22,7 +22,8 @@ public abstract class BreakStatusPanel : Gtk.Grid {
public bool is_enabled { get; set; default=false; }
protected BreakStatusPanel (BreakType break_type) {
- Object ();
+ GLib.Object ();
+
this.break_type = break_type;
this.get_style_context ().add_class ("_break-status");
diff --git a/src/settings/BreakType.vala b/src/settings/BreakType.vala
index 46283cd..65d4228 100644
--- a/src/settings/BreakType.vala
+++ b/src/settings/BreakType.vala
@@ -15,9 +15,11 @@
* along with GNOME Break Timer. If not, see <http://www.gnu.org/licenses/>.
*/
+using BreakTimer.Common;
+
namespace BreakTimer.Settings {
-public abstract class BreakType : Object {
+public abstract class BreakType : GLib.Object {
public string id { get; private set; }
public BreakStatus? status;
diff --git a/src/settings/CircleCounter.vala b/src/settings/CircleCounter.vala
index 3ce5a8c..2bf0f5b 100644
--- a/src/settings/CircleCounter.vala
+++ b/src/settings/CircleCounter.vala
@@ -47,7 +47,8 @@ public class CircleCounter : Gtk.Widget {
public double progress {get; set;}
public CircleCounter () {
- Object ();
+ GLib.Object ();
+
this.set_has_window (false);
this.get_style_context ().add_class ("_circle-counter");
diff --git a/src/settings/FixedSizeGrid.vala b/src/settings/FixedSizeGrid.vala
new file mode 100644
index 0000000..1fcb195
--- /dev/null
+++ b/src/settings/FixedSizeGrid.vala
@@ -0,0 +1,49 @@
+/*
+ * This file is part of GNOME Break Timer.
+ *
+ * GNOME Break Timer is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GNOME Break Timer is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNOME Break Timer. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+namespace BreakTimer.Settings {
+
+class FixedSizeGrid : Gtk.Grid {
+ 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 GLib.List<weak Gtk.Widget> get_hidden_children () {
+ var hidden_children = new GLib.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/src/settings/MainWindow.vala b/src/settings/MainWindow.vala
index 7ba8768..e5fd37f 100644
--- a/src/settings/MainWindow.vala
+++ b/src/settings/MainWindow.vala
@@ -34,8 +34,9 @@ public class MainWindow : Gtk.ApplicationWindow {
private WelcomePanel welcome_panel;
private StatusPanel status_panel;
- public MainWindow (SettingsApplication application, BreakManager break_manager) {
- Object (application: application);
+ public MainWindow (Application application, BreakManager break_manager) {
+ GLib.Object (application: application);
+
this.break_manager = break_manager;
this.set_title ( _("Break Timer"));
@@ -179,198 +180,4 @@ public class MainWindow : Gtk.ApplicationWindow {
}
}
-/* 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 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_end (20);
- this.set_margin_bottom (20);
- this.set_margin_start (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_end (20);
- status_panel.set_margin_bottom (18);
- status_panel.set_margin_start (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/src/settings/MicroBreakInfoPanel.vala b/src/settings/MicroBreakInfoPanel.vala
index d3f4cfe..ff7054f 100644
--- a/src/settings/MicroBreakInfoPanel.vala
+++ b/src/settings/MicroBreakInfoPanel.vala
@@ -15,6 +15,8 @@
* along with GNOME Break Timer. If not, see <http://www.gnu.org/licenses/>.
*/
+using BreakTimer.Common;
+
namespace BreakTimer.Settings {
class MicroBreakInfoPanel : BreakInfoPanel {
diff --git a/src/settings/OverlayArrow.vala b/src/settings/OverlayArrow.vala
index f68cf47..332f509 100644
--- a/src/settings/OverlayArrow.vala
+++ b/src/settings/OverlayArrow.vala
@@ -23,7 +23,8 @@ public class OverlayArrow : Gtk.Widget {
private Gtk.Widget to_widget;
public OverlayArrow (Gtk.Widget from_widget, Gtk.Widget to_widget) {
- Object ();
+ GLib.Object ();
+
this.set_has_window (false);
this.set_halign (Gtk.Align.FILL);
diff --git a/src/settings/RestBreakInfoPanel.vala b/src/settings/RestBreakInfoPanel.vala
index 0baf3e7..a6f83f9 100644
--- a/src/settings/RestBreakInfoPanel.vala
+++ b/src/settings/RestBreakInfoPanel.vala
@@ -15,6 +15,8 @@
* along with GNOME Break Timer. If not, see <http://www.gnu.org/licenses/>.
*/
+using BreakTimer.Common;
+
namespace BreakTimer.Settings {
class RestBreakInfoPanel : BreakInfoPanel {
diff --git a/src/settings/StatusPanel.vala b/src/settings/StatusPanel.vala
new file mode 100644
index 0000000..d1213f8
--- /dev/null
+++ b/src/settings/StatusPanel.vala
@@ -0,0 +1,96 @@
+/*
+ * This file is part of GNOME Break Timer.
+ *
+ * GNOME Break Timer is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GNOME Break Timer is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNOME Break Timer. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+namespace BreakTimer.Settings {
+
+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) {
+ GLib.Object ();
+
+ this.break_manager = break_manager;
+
+ this.set_margin_top (20);
+ this.set_margin_end (20);
+ this.set_margin_bottom (20);
+ this.set_margin_start (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_end (20);
+ status_panel.set_margin_bottom (18);
+ status_panel.set_margin_start (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/src/settings/TimeChooser.vala b/src/settings/TimeChooser.vala
index 363fed3..641bdf0 100644
--- a/src/settings/TimeChooser.vala
+++ b/src/settings/TimeChooser.vala
@@ -15,6 +15,8 @@
* along with GNOME Break Timer. If not, see <http://www.gnu.org/licenses/>.
*/
+using BreakTimer.Common;
+
namespace BreakTimer.Settings {
public class TimeChooser : Gtk.ComboBox {
@@ -29,7 +31,7 @@ public class TimeChooser : Gtk.ComboBox {
public signal void time_selected (int time);
public TimeChooser (int[] options) {
- Object ();
+ GLib.Object ();
this.list_store = new Gtk.ListStore (3, typeof (string), typeof (string), typeof (int));
diff --git a/src/settings/TimerBreakStatusPanel.vala b/src/settings/TimerBreakStatusPanel.vala
index a8f8b4a..d4ffc05 100644
--- a/src/settings/TimerBreakStatusPanel.vala
+++ b/src/settings/TimerBreakStatusPanel.vala
@@ -15,6 +15,8 @@
* along with GNOME Break Timer. If not, see <http://www.gnu.org/licenses/>.
*/
+using BreakTimer.Common;
+
namespace BreakTimer.Settings {
public abstract class TimerBreakStatusPanel : BreakStatusPanel {
diff --git a/src/settings/TimerBreakType.vala b/src/settings/TimerBreakType.vala
index 1f00638..07e4caa 100644
--- a/src/settings/TimerBreakType.vala
+++ b/src/settings/TimerBreakType.vala
@@ -15,6 +15,8 @@
* along with GNOME Break Timer. If not, see <http://www.gnu.org/licenses/>.
*/
+using BreakTimer.Common;
+
namespace BreakTimer.Settings {
public abstract class TimerBreakType : BreakType {
@@ -24,7 +26,7 @@ public abstract class TimerBreakType : BreakType {
public int[] interval_options;
public int[] duration_options;
- public IBreakDaemon_TimerBreak? break_server;
+ public IBreakTimer_TimerBreak? break_server;
protected TimerBreakType (string name, GLib.Settings settings) {
base (name, settings);
@@ -36,8 +38,13 @@ public abstract class TimerBreakType : BreakType {
public override void initialize () {
base.initialize ();
- Bus.watch_name (BusType.SESSION, Config.DAEMON_BUS_NAME, BusNameWatcherFlags.NONE,
- this.breakdaemon_appeared, this.breakdaemon_disappeared);
+ GLib.Bus.watch_name (
+ GLib.BusType.SESSION,
+ Config.DAEMON_APPLICATION_ID,
+ GLib.BusNameWatcherFlags.NONE,
+ this.breakdaemon_appeared,
+ this.breakdaemon_disappeared
+ );
}
protected new void update_status (TimerBreakStatus? status) {
@@ -64,7 +71,7 @@ public abstract class TimerBreakType : BreakType {
if (this.break_server != null) {
try {
return this.break_server.get_status ();
- } catch (IOError error) {
+ } catch (GLib.IOError error) {
GLib.warning ("Error connecting to break daemon service: %s", error.message);
return null;
} catch (GLib.DBusError error) {
@@ -82,17 +89,17 @@ public abstract class TimerBreakType : BreakType {
private void breakdaemon_appeared () {
try {
- this.break_server = Bus.get_proxy_sync (
- BusType.SESSION,
- Config.DAEMON_BUS_NAME,
+ this.break_server = GLib.Bus.get_proxy_sync (
+ GLib.BusType.SESSION,
+ Config.DAEMON_APPLICATION_ID,
Config.DAEMON_BREAK_OBJECT_BASE_PATH+this.id,
- DBusProxyFlags.DO_NOT_AUTO_START
+ GLib.DBusProxyFlags.DO_NOT_AUTO_START
);
// We can only poll the break daemon 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_timeout_id = GLib.Timeout.add (500, this.update_status_cb);
this.update_status_cb ();
- } catch (IOError error) {
+ } catch (GLib.IOError error) {
this.break_server = null;
GLib.warning ("Error connecting to break daemon service: %s", error.message);
}
@@ -100,7 +107,7 @@ public abstract class TimerBreakType : BreakType {
private void breakdaemon_disappeared () {
if (this.update_timeout_id > 0) {
- Source.remove (this.update_timeout_id);
+ GLib.Source.remove (this.update_timeout_id);
this.update_timeout_id = 0;
}
this.break_server = null;
diff --git a/src/settings/WelcomePanel.vala b/src/settings/WelcomePanel.vala
new file mode 100644
index 0000000..7d16e8e
--- /dev/null
+++ b/src/settings/WelcomePanel.vala
@@ -0,0 +1,139 @@
+/*
+ * This file is part of GNOME Break Timer.
+ *
+ * GNOME Break Timer is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GNOME Break Timer is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNOME Break Timer. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+namespace BreakTimer.Settings {
+
+/* 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) {
+ GLib.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);
+ }
+ }
+}
+
+}
diff --git a/src/settings/main.vala b/src/settings/main.vala
index 07c6151..dbd9025 100644
--- a/src/settings/main.vala
+++ b/src/settings/main.vala
@@ -23,7 +23,7 @@ public int main (string[] args) {
Intl.bind_textdomain_codeset (Config.GETTEXT_PACKAGE, "UTF-8");
Intl.textdomain (Config.GETTEXT_PACKAGE);
- SettingsApplication application = new SettingsApplication ();
+ Application application = new Application ();
int status = application.run (args);
return status;
}
diff --git a/src/settings/meson.build b/src/settings/meson.build
index 8d0ab32..c844c07 100644
--- a/src/settings/meson.build
+++ b/src/settings/meson.build
@@ -3,6 +3,8 @@
# $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(top_srcdir)/data/ --generate-source $<
settings_sources = files(
+ 'Application.vala',
+ 'BreakConfigurationChooser.vala',
'BreakInfoPanel.vala',
'BreakManager.vala',
'BreakSettingsDialog.vala',
@@ -10,6 +12,7 @@ settings_sources = files(
'BreakStatusPanel.vala',
'BreakType.vala',
'CircleCounter.vala',
+ 'FixedSizeGrid.vala',
'main.vala',
'MainWindow.vala',
'MicroBreakInfoPanel.vala',
@@ -21,9 +24,10 @@ settings_sources = files(
'RestBreakSettingsPanel.vala',
'RestBreakStatusPanel.vala',
'RestBreakType.vala',
- 'SettingsApplication.vala',
+ 'StatusPanel.vala',
'TimeChooser.vala',
'TimerBreakSettingsPanel.vala',
'TimerBreakStatusPanel.vala',
- 'TimerBreakType.vala'
+ 'TimerBreakType.vala',
+ 'WelcomePanel.vala'
)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]