[gnome-break-timer/dylanmccall/meson-build: 23/25] Tidy up config constants and nested classes



commit 3ffbcb4899f7780ec8501f0c694e73f941349adc
Author: Dylan McCall <dylan dylanmccall com>
Date:   Sat Jan 19 12:29:32 2019 -0800

    Tidy up config constants and nested classes

 .editorconfig                                |  2 +-
 config.vapi                                  | 20 +++++-----
 gnome-break-timer.sh.in                      |  4 +-
 helper/HelperApplication.vala                |  3 +-
 helper/UIFragment.vala                       |  9 ++---
 helper/UIManager.vala                        | 18 +++++----
 helper/activity-monitor/ActivityMonitor.vala | 37 ------------------
 helper/activity-monitor/UserActivity.vala    | 57 ++++++++++++++++++++++++++++
 helper/break/BreakView.vala                  |  2 +-
 helper/break/TimerBreakController.vala       |  4 +-
 helper/meson.build                           |  1 +
 meson.build                                  | 31 +++++++--------
 settings/BreakManager.vala                   |  2 +-
 settings/MainWindow.vala                     |  6 +--
 settings/SettingsApplication.vala            |  7 ++--
 15 files changed, 113 insertions(+), 90 deletions(-)
---
diff --git a/.editorconfig b/.editorconfig
index d0ad051..95ece41 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -1,4 +1,4 @@
-[*.vala, *.c]
+[*.vala, *.vapi, *.c]
 indent_style = spaces
 indent_size = 4
 
diff --git a/config.vapi b/config.vapi
index ccde408..a254b6f 100644
--- a/config.vapi
+++ b/config.vapi
@@ -1,13 +1,13 @@
 [CCode (cprefix = "", lower_case_cprefix = "", cheader_filename = "config.h")]
 namespace Config {
-       public const string GETTEXT_PACKAGE;
-       public const string PACKAGE_NAME;
-       public const string PACKAGE_VERSION;
-       public const string PACKAGE_URL;
-       public const string VERSION;
-       public const string HELPER_DESKTOP_ID;
-       public const string SETTINGS_DESKTOP_ID;
-       public const string HELPER_BUS_NAME;
-       public const string HELPER_OBJECT_PATH;
-       public const string HELPER_BREAK_OBJECT_BASE_PATH;
+    public const string GETTEXT_PACKAGE;
+    public const string PROJECT_NAME;
+    public const string PROJECT_VERSION;
+    public const string APPLICATION_ICON;
+    public const string APPLICATION_URL;
+    public const string HELPER_APPLICATION_ID;
+    public const string SETTINGS_APPLICATION_ID;
+    public const string HELPER_BUS_NAME;
+    public const string HELPER_OBJECT_PATH;
+    public const string HELPER_BREAK_OBJECT_BASE_PATH;
 }
diff --git a/gnome-break-timer.sh.in b/gnome-break-timer.sh.in
index 6605382..174ba4b 100755
--- a/gnome-break-timer.sh.in
+++ b/gnome-break-timer.sh.in
@@ -4,7 +4,7 @@ if [ -n "$1" ]; then
     SUBCOMMAND=$1
     shift
 else
-    SUBCOMMAND='settings'
+    SUBCOMMAND='helper'
 fi
 
 if [ "${SUBCOMMAND}" = 'helper' ]; then
@@ -13,4 +13,4 @@ elif [ "${SUBCOMMAND}" = 'settings' ]; then
     exec @BINDIR@/gnome-break-timer-settings $@
 else
     echo "Unknown subcommand '${SUBCOMMAND}'"
-fi
+fi
\ No newline at end of file
diff --git a/helper/HelperApplication.vala b/helper/HelperApplication.vala
index 98db8ef..3e16144 100644
--- a/helper/HelperApplication.vala
+++ b/helper/HelperApplication.vala
@@ -18,7 +18,6 @@
 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;
 
@@ -32,7 +31,7 @@ public class HelperApplication : Gtk.Application {
 
     public HelperApplication () {
         Object (
-            application_id: app_id,
+            application_id: Config.HELPER_APPLICATION_ID,
             register_session: true,
             flags: ApplicationFlags.FLAGS_NONE
         );
diff --git a/helper/UIFragment.vala b/helper/UIFragment.vala
index 94d4f0c..49dd7b9 100644
--- a/helper/UIFragment.vala
+++ b/helper/UIFragment.vala
@@ -17,12 +17,11 @@
 
 namespace BreakTimer.Helper {
 
+/**
+ * Provides a simple interface for UIManager to create notifications and
+ * overlays.
+ */
 public abstract class UIFragment : Object, IFocusable {
-    /**
-     * Provides a simple interface for UIManager to create notifications and
-     * overlays.
-     */
-
     protected UIManager ui_manager;
 
     protected Notify.Notification? notification;
diff --git a/helper/UIManager.vala b/helper/UIManager.vala
index 2160b1f..035a3f6 100644
--- a/helper/UIManager.vala
+++ b/helper/UIManager.vala
@@ -17,14 +17,13 @@
 
 namespace BreakTimer.Helper {
 
+/**
+ * Central place to manage UI throughout the application. We need this to
+ * maintain a simple, modal structure. This uses SimpleFocusManager to make
+ * sure only one break is affecting the UI at a time. This class also tries to
+ * keep UI events nicely spaced so they don't generate excessive noise.
+ */
 public class UIManager : SimpleFocusManager {
-    /**
-     * Central place to manage UI throughout the application. We need this to
-     * maintain a simple, modal structure. This uses SimpleFocusManager to
-     * make sure only one break is affecting the UI at a time. This class also
-     * tries to keep UI events nicely spaced so they don't turn into noise.
-     */
-
     private weak Gtk.Application application;
     private ISessionStatus session_status;
 
@@ -44,6 +43,9 @@ public class UIManager : SimpleFocusManager {
         }
 
         if (this.canberra != null) {
+            this.canberra.change_props(Canberra.PROP_APPLICATION_ID, Config.HELPER_APPLICATION_ID);
+            this.canberra.change_props(Canberra.PROP_APPLICATION_NAME, _("GNOME Break Timer"));
+            this.canberra.change_props(Canberra.PROP_APPLICATION_ICON_NAME, Config.APPLICATION_ICON);
             this.canberra.open();
         }
 
@@ -70,7 +72,7 @@ public class UIManager : SimpleFocusManager {
             this.hide_notification (this.notification);
         }
 
-        notification.set_hint ("desktop-entry", Config.HELPER_DESKTOP_ID);
+        notification.set_hint ("desktop-entry", Config.HELPER_APPLICATION_ID);
 
         try {
             notification.show ();
diff --git a/helper/activity-monitor/ActivityMonitor.vala b/helper/activity-monitor/ActivityMonitor.vala
index 1b832ee..88afb2f 100644
--- a/helper/activity-monitor/ActivityMonitor.vala
+++ b/helper/activity-monitor/ActivityMonitor.vala
@@ -18,43 +18,6 @@
 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);
 
diff --git a/helper/activity-monitor/UserActivity.vala b/helper/activity-monitor/UserActivity.vala
new file mode 100644
index 0000000..a5eeeeb
--- /dev/null
+++ b/helper/activity-monitor/UserActivity.vala
@@ -0,0 +1,57 @@
+/*
+ * 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.Helper {
+
+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;
+    }
+}
+
+}
diff --git a/helper/break/BreakView.vala b/helper/break/BreakView.vala
index 4769ee4..66116df 100644
--- a/helper/break/BreakView.vala
+++ b/helper/break/BreakView.vala
@@ -88,7 +88,7 @@ public abstract class BreakView : UIFragment {
 
     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);
+        AppInfo settings_app_info = new DesktopAppInfo (Config.SETTINGS_APPLICATION_ID);
         AppLaunchContext app_launch_context = new AppLaunchContext ();
         try {
             settings_app_info.launch (null, app_launch_context);
diff --git a/helper/break/TimerBreakController.vala b/helper/break/TimerBreakController.vala
index 78baf3c..b73bc16 100644
--- a/helper/break/TimerBreakController.vala
+++ b/helper/break/TimerBreakController.vala
@@ -162,7 +162,7 @@ public abstract class TimerBreakController : BreakController {
         return this.duration_countdown.get_duration ();
     }
 
-    private void detected_idle_cb (ActivityMonitor.UserActivity activity) {
+    private void detected_idle_cb (UserActivity activity) {
         if (! this.is_enabled ()) return;
 
         if (activity.time_since_active < this.fuzzy_seconds) {
@@ -201,7 +201,7 @@ public abstract class TimerBreakController : BreakController {
         this.countdowns_timeout.run_once ();
     }
 
-    private void detected_activity_cb (ActivityMonitor.UserActivity activity) {
+    private void detected_activity_cb (UserActivity activity) {
         if (! this.is_enabled ()) return;
 
         int lap_time;
diff --git a/helper/meson.build b/helper/meson.build
index 4e0d9b7..0d83a7f 100644
--- a/helper/meson.build
+++ b/helper/meson.build
@@ -1,6 +1,7 @@
 helper_sources = [
     'activity-monitor/ActivityMonitor.vala',
     'activity-monitor/MutterActivityMonitorBackend.vala',
+    'activity-monitor/UserActivity.vala',
     'util/Countdown.vala',
     'util/PausableTimeout.vala',
     'util/SimpleFocusManager.vala',
diff --git a/meson.build b/meson.build
index cf8da6c..02e6e26 100644
--- a/meson.build
+++ b/meson.build
@@ -29,9 +29,10 @@ libdir = join_paths(prefix, get_option('libdir'))
 datadir = join_paths(prefix, get_option('datadir'))
 libexecdir = join_paths(prefix, get_option('libexecdir'))
 
-package_url = 'https://wiki.gnome.org/Apps/BreakTimer'
-settings_desktop_id = 'org.gnome.BreakTimer'
-helper_desktop_id = 'org.gnome.BreakTimer.Helper'
+application_icon = 'org.gnome.BreakTimer'
+application_url = 'https://wiki.gnome.org/Apps/BreakTimer'
+settings_application_id = 'org.gnome.BreakTimer'
+helper_application_id = 'org.gnome.BreakTimer.Helper'
 helper_bus_name = 'org.gnome.BreakTimer.Helper'
 helper_object_path = '/org/gnome/BreakTimer'
 helper_break_object_base_path = '/org/gnome/BreakTimer/'
@@ -39,12 +40,12 @@ helper_break_object_base_path = '/org/gnome/BreakTimer/'
 build_conf = configuration_data()
 build_conf.set('BINDIR', bindir)
 build_conf.set('GETTEXT_PACKAGE', gettext_package)
-build_conf.set('PACKAGE_NAME', meson.project_name())
-build_conf.set('PACKAGE_VERSION', meson.project_version())
-build_conf.set('PACKAGE_URL', package_url)
-build_conf.set('VERSION', meson.project_version())
-build_conf.set('SETTINGS_DESKTOP_ID', settings_desktop_id)
-build_conf.set('HELPER_DESKTOP_ID', helper_desktop_id)
+build_conf.set('PROJECT_NAME', meson.project_name())
+build_conf.set('PROJECT_VERSION', meson.project_version())
+build_conf.set('APPLICATION_ICON', application_icon)
+build_conf.set('APPLICATION_URL', application_url)
+build_conf.set('SETTINGS_APPLICATION_ID', settings_application_id)
+build_conf.set('HELPER_APPLICATION_ID', helper_application_id)
 build_conf.set('HELPER_BUS_NAME', helper_bus_name)
 build_conf.set('HELPER_OBJECT_PATH', helper_object_path)
 build_conf.set('HELPER_BREAK_OBJECT_BASE_PATH', helper_break_object_base_path)
@@ -52,12 +53,12 @@ build_conf.set('HELPER_BREAK_OBJECT_BASE_PATH', helper_break_object_base_path)
 build_conf_quoted = configuration_data()
 build_conf_quoted.set_quoted('BINDIR', bindir)
 build_conf_quoted.set_quoted('GETTEXT_PACKAGE', gettext_package)
-build_conf_quoted.set_quoted('PACKAGE_NAME', meson.project_name())
-build_conf_quoted.set_quoted('PACKAGE_VERSION', meson.project_version())
-build_conf_quoted.set_quoted('PACKAGE_URL', package_url)
-build_conf_quoted.set_quoted('VERSION', meson.project_version())
-build_conf_quoted.set_quoted('SETTINGS_DESKTOP_ID', settings_desktop_id)
-build_conf_quoted.set_quoted('HELPER_DESKTOP_ID', helper_desktop_id)
+build_conf_quoted.set_quoted('PROJECT_NAME', meson.project_name())
+build_conf_quoted.set_quoted('PROJECT_VERSION', meson.project_version())
+build_conf_quoted.set_quoted('APPLICATION_ICON', application_icon)
+build_conf_quoted.set_quoted('APPLICATION_URL', application_url)
+build_conf_quoted.set_quoted('SETTINGS_APPLICATION_ID', settings_application_id)
+build_conf_quoted.set_quoted('HELPER_APPLICATION_ID', helper_application_id)
 build_conf_quoted.set_quoted('HELPER_BUS_NAME', helper_bus_name)
 build_conf_quoted.set_quoted('HELPER_OBJECT_PATH', helper_object_path)
 build_conf_quoted.set_quoted('HELPER_BREAK_OBJECT_BASE_PATH', helper_break_object_base_path)
diff --git a/settings/BreakManager.vala b/settings/BreakManager.vala
index b94277f..3b22803 100644
--- a/settings/BreakManager.vala
+++ b/settings/BreakManager.vala
@@ -140,7 +140,7 @@ public class BreakManager : Object {
 
     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);
+        AppInfo helper_app_info = new DesktopAppInfo (Config.HELPER_APPLICATION_ID);
         AppLaunchContext app_launch_context = new AppLaunchContext ();
         try {
             helper_app_info.launch (null, app_launch_context);
diff --git a/settings/MainWindow.vala b/settings/MainWindow.vala
index ce71f02..5018491 100644
--- a/settings/MainWindow.vala
+++ b/settings/MainWindow.vala
@@ -148,10 +148,10 @@ public class MainWindow : Gtk.ApplicationWindow {
 
         Gtk.show_about_dialog (this,
             "program-name", _("GNOME Break Timer"),
-            "logo-icon-name", "org.gnome.BreakTimer",
-            "version", Config.VERSION,
+            "logo-icon-name", Config.APPLICATION_ICON,
+            "version", Config.PROJECT_VERSION,
             "comments", _("Computer break reminders for active minds"),
-            "website", Config.PACKAGE_URL,
+            "website", Config.APPLICATION_URL,
             "website-label", _("GNOME Break Timer Website"),
             "copyright", copyright,
             "license-type", Gtk.License.GPL_3_0,
diff --git a/settings/SettingsApplication.vala b/settings/SettingsApplication.vala
index 489573a..606fef8 100644
--- a/settings/SettingsApplication.vala
+++ b/settings/SettingsApplication.vala
@@ -18,8 +18,6 @@
 namespace BreakTimer.Settings {
 
 public class SettingsApplication : Gtk.Application {
-    const string app_id = Config.SETTINGS_DESKTOP_ID;
-
     private const string STYLE_DATA =
         """
         ._settings-title {
@@ -59,7 +57,10 @@ public class SettingsApplication : Gtk.Application {
     private MainWindow main_window;
 
     public SettingsApplication () {
-        Object (application_id: app_id, flags: ApplicationFlags.FLAGS_NONE);
+        Object (
+            application_id: Config.SETTINGS_APPLICATION_ID,
+            flags: ApplicationFlags.FLAGS_NONE
+        );
     }
 
     public override void activate () {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]