[geary/wip/application-cleanup: 2/3] Clean up GearyAppliaction's path accssor implementaion
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/wip/application-cleanup: 2/3] Clean up GearyAppliaction's path accssor implementaion
- Date: Sun, 21 Apr 2019 01:13:55 +0000 (UTC)
commit 81bcd31b79865b7f4413561811c0f5f86b02ac58
Author: Michael Gratton <mike vee net>
Date: Fri Apr 19 12:16:53 2019 +1000
Clean up GearyAppliaction's path accssor implementaion
Convert a few methods into properties, remove some redundancies and
untangle some call chains.
.../application/application-startup-manager.vala | 34 ++----
src/client/application/geary-application.vala | 121 ++++++++++-----------
src/client/application/geary-controller.vala | 10 +-
src/client/notification/libmessagingmenu.vala | 20 ++--
.../notification/new-messages-indicator.vala | 5 +-
5 files changed, 85 insertions(+), 105 deletions(-)
---
diff --git a/src/client/application/application-startup-manager.vala
b/src/client/application/application-startup-manager.vala
index 2e62d7a1..1eb3bcd0 100644
--- a/src/client/application/application-startup-manager.vala
+++ b/src/client/application/application-startup-manager.vala
@@ -14,12 +14,12 @@ public class Application.StartupManager : GLib.Object {
private const string AUTOSTART_DESKTOP_FILE = "geary-autostart.desktop";
private Configuration config;
- private GLib.File? install_dir;
- private GLib.File startup_file; // Startup '.desktop' file
+ private GLib.File installed_file;
+ private GLib.File startup_file;
- public StartupManager(Configuration config, GLib.File? install_dir) {
+ public StartupManager(Configuration config, GLib.File desktop_dir) {
this.config = config;
- this.install_dir = install_dir;
+ this.installed_file = desktop_dir.get_child(AUTOSTART_DESKTOP_FILE);
this.startup_file = GLib.File.new_for_path(
GLib.Environment.get_user_config_dir()
).get_child(AUTOSTART_FOLDER)
@@ -32,28 +32,10 @@ public class Application.StartupManager : GLib.Object {
}
/**
- * Returns the system-wide autostart desktop file
+ * Returns the system-wide autostart desktop file if it exists.
*/
- public GLib.File? get_autostart_desktop_file() {
- GLib.File? parent = null;
- if (this.install_dir != null) {
- // Running from the installation directory
- parent = (
- this.install_dir
- .get_child("share")
- .get_child("applications")
- );
- } else {
- // Running from the source build directory
- parent = (
- GLib.File.new_for_path(GearyApplication.SOURCE_ROOT_DIR)
- .get_child("build")
- .get_child("desktop")
- );
- }
-
- GLib.File desktop_file = parent.get_child(AUTOSTART_DESKTOP_FILE);
- return desktop_file.query_exists() ? desktop_file : null;
+ public GLib.File? get_installed_desktop_file() {
+ return this.installed_file.query_exists() ? this.installed_file : null;
}
/**
@@ -65,7 +47,7 @@ public class Application.StartupManager : GLib.Object {
if (!autostart_dir.query_exists()) {
autostart_dir.make_directory_with_parents();
}
- GLib.File? autostart = get_autostart_desktop_file();
+ GLib.File? autostart = get_installed_desktop_file();
if (autostart == null) {
warning("Autostart file is not installed!");
} else {
diff --git a/src/client/application/geary-application.vala b/src/client/application/geary-application.vala
index e091d6a5..ed6a0fa0 100644
--- a/src/client/application/geary-application.vala
+++ b/src/client/application/geary-application.vala
@@ -232,8 +232,23 @@ public class GearyApplication : Gtk.Application {
}
}
- private string binary;
+ /**
+ * Determines if this instance is running from the install directory.
+ */
+ internal bool is_installed {
+ get {
+ return this.exec_dir.has_prefix(this.install_prefix);
+ }
+ }
+
+ /** Returns the compile-time configured installation directory. */
+ internal GLib.File install_prefix {
+ get; private set; default = GLib.File.new_for_path(INSTALL_PREFIX);
+ }
+
+
private File exec_dir;
+ private string binary;
private bool start_hidden = false;
private bool exiting_fired = false;
private int exitcode = 0;
@@ -371,7 +386,7 @@ public class GearyApplication : Gtk.Application {
Environment.set_application_name(NAME);
International.init(GETTEXT_PACKAGE, this.binary);
- Configuration.init(is_installed(), GSETTINGS_DIR);
+ Configuration.init(this.is_installed, GSETTINGS_DIR);
Geary.Logging.init();
Geary.Logging.log_to(stderr);
GLib.Log.set_default_handler(Geary.Logging.default_handler);
@@ -388,7 +403,7 @@ public class GearyApplication : Gtk.Application {
this.config = new Configuration(APP_ID);
this.autostart = new Application.StartupManager(
- this.config, get_install_dir()
+ this.config, this.get_desktop_directory()
);
// Ensure all geary windows have an icon
@@ -467,34 +482,39 @@ public class GearyApplication : Gtk.Application {
}
- public File get_user_data_directory() {
- return File.new_for_path(Environment.get_user_data_dir()).get_child("geary");
+ /** Returns the application's base user configuration directory. */
+ public GLib.File get_user_config_directory() {
+ return GLib.File.new_for_path(
+ Environment.get_user_config_dir()
+ ).get_child("geary");
}
- public File get_user_cache_directory() {
- return File.new_for_path(Environment.get_user_cache_dir()).get_child("geary");
+ /** Returns the application's base user cache directory. */
+ public GLib.File get_user_cache_directory() {
+ return GLib.File.new_for_path(
+ GLib.Environment.get_user_cache_dir()
+ ).get_child("geary");
}
- public File get_user_config_directory() {
- return File.new_for_path(Environment.get_user_config_dir()).get_child("geary");
+ /** Returns the application's base user data directory. */
+ public GLib.File get_user_data_directory() {
+ return GLib.File.new_for_path(
+ GLib.Environment.get_user_data_dir()
+ ).get_child("geary");
}
- /**
- * Returns the base directory that the application's various resource files are stored. If the
- * application is running from its installed directory, this will point to
- * $(BASEDIR)/share/<program name>. If it's running from the build directory, this points to
- * that.
- */
- public File get_resource_directory() {
- if (get_install_dir() != null)
- return get_install_dir().get_child("share").get_child("geary");
- else
- return File.new_for_path(SOURCE_ROOT_DIR);
+ /** Returns the application's base static resources directory. */
+ public GLib.File get_resource_directory() {
+ return (is_installed)
+ ? this.install_prefix.get_child("share").get_child("geary")
+ : GLib.File.new_for_path(SOURCE_ROOT_DIR);
}
- /** Returns the directory the application is currently executing from. */
- public File get_exec_dir() {
- return this.exec_dir;
+ /** Returns the location of the application's desktop files. */
+ public GLib.File get_desktop_directory() {
+ return (is_installed)
+ ? this.install_prefix.get_child("share").get_child("applications")
+ : GLib.File.new_for_path(BUILD_ROOT_DIR).get_child("desktop");
}
/**
@@ -504,42 +524,13 @@ public class GearyApplication : Gtk.Application {
* on the Meson `libdir` option, and can be set by invoking `meson
* configure` as appropriate.
*/
- public File get_web_extensions_dir() {
- return (get_install_dir() != null)
- ? File.new_for_path(_WEB_EXTENSIONS_DIR)
- : File.new_for_path(BUILD_ROOT_DIR).get_child("src");
- }
-
- public File? get_desktop_file() {
- File? install_dir = get_install_dir();
- File desktop_file = (install_dir != null)
- ? install_dir.get_child("share").get_child("applications").get_child("org.gnome.Geary.desktop")
- :
File.new_for_path(SOURCE_ROOT_DIR).get_child("build").get_child("desktop").get_child("org.gnome.Geary.desktop");
-
- return desktop_file.query_exists() ? desktop_file : null;
- }
-
- public bool is_installed() {
- return exec_dir.has_prefix(get_install_prefix_dir());
- }
-
- // Returns the configure installation prefix directory, which does not imply Geary is installed
- // or that it's running from this directory.
- public File get_install_prefix_dir() {
- return File.new_for_path(INSTALL_PREFIX);
- }
-
- // Returns the installation directory, or null if we're running outside of the installation
- // directory.
- public File? get_install_dir() {
- File prefix_dir = get_install_prefix_dir();
-
- return exec_dir.has_prefix(prefix_dir) ? prefix_dir : null;
+ public GLib.File get_web_extensions_dir() {
+ return (is_installed)
+ ? GLib.File.new_for_path(_WEB_EXTENSIONS_DIR)
+ : GLib.File.new_for_path(BUILD_ROOT_DIR).get_child("src");
}
- /**
- * Displays a URI on the current active window, if any.
- */
+ /** Displays a URI on the current active window, if any. */
public void show_uri(string uri) throws Error {
bool success = Gtk.show_uri_on_window(
get_active_window(), uri, Gdk.CURRENT_TIME
@@ -593,8 +584,12 @@ public class GearyApplication : Gtk.Application {
return false;
}
- // This call will fire "exiting" only if it's not already been
- // fired and halt the application in its tracks.
+ /**
+ * Causes the application to exit immediately.
+ *
+ * This call will fire "exiting" only if it's not already been
+ * fired and halt the application in its tracks
+ */
public void panic() {
if (!exiting_fired) {
exiting_fired = true;
@@ -617,7 +612,7 @@ public class GearyApplication : Gtk.Application {
// the other instances called when sending commands to the app
// via the command-line)
message("%s %s prefix=%s exec_dir=%s is_installed=%s", NAME, VERSION, INSTALL_PREFIX,
- exec_dir.get_path(), is_installed().to_string());
+ exec_dir.get_path(), this.is_installed.to_string());
yield this.controller.open_async(null);
@@ -737,7 +732,7 @@ public class GearyApplication : Gtk.Application {
private void add_app_accelerators(string action,
string[] accelerators,
- Variant? param = null) {
+ GLib.Variant? param = null) {
set_accels_for_action("app." + action, accelerators);
}
@@ -851,11 +846,11 @@ public class GearyApplication : Gtk.Application {
private void on_activate_help() {
try {
- if (is_installed()) {
+ if (this.is_installed) {
show_uri("help:geary");
} else {
Pid pid;
- File exec_dir = get_exec_dir();
+ File exec_dir = this.exec_dir;
string[] argv = new string[3];
argv[0] = "yelp";
argv[1] = GearyApplication.SOURCE_ROOT_DIR + "/help/C/";
diff --git a/src/client/application/geary-controller.vala b/src/client/application/geary-controller.vala
index 82cc170c..2f0fba6d 100644
--- a/src/client/application/geary-controller.vala
+++ b/src/client/application/geary-controller.vala
@@ -327,10 +327,12 @@ public class GearyController : Geary.BaseObject {
main_window.folder_list.set_new_messages_monitor(new_messages_monitor);
// New messages indicator (Ubuntuism)
- new_messages_indicator = NewMessagesIndicator.create(new_messages_monitor);
- new_messages_indicator.application_activated.connect(on_indicator_activated_application);
- new_messages_indicator.composer_activated.connect(on_indicator_activated_composer);
- new_messages_indicator.inbox_activated.connect(on_indicator_activated_inbox);
+ this.new_messages_indicator = NewMessagesIndicator.create(
+ this.new_messages_monitor, this.application.config
+ );
+ this.new_messages_indicator.application_activated.connect(on_indicator_activated_application);
+ this.new_messages_indicator.composer_activated.connect(on_indicator_activated_composer);
+ this.new_messages_indicator.inbox_activated.connect(on_indicator_activated_inbox);
unity_launcher = new UnityLauncher(new_messages_monitor);
diff --git a/src/client/notification/libmessagingmenu.vala b/src/client/notification/libmessagingmenu.vala
index 1624fe80..7b112529 100644
--- a/src/client/notification/libmessagingmenu.vala
+++ b/src/client/notification/libmessagingmenu.vala
@@ -8,18 +8,18 @@ public class Libmessagingmenu : NewMessagesIndicator {
#if HAVE_LIBMESSAGINGMENU
private MessagingMenu.App? app = null;
- public Libmessagingmenu(NewMessagesMonitor monitor) {
- base (monitor);
- File? desktop_file = GearyApplication.instance.get_desktop_file();
- if (desktop_file == null
- || !desktop_file.has_prefix(GearyApplication.instance.get_install_prefix_dir())) {
- debug("Only an installed version of Geary with its .desktop file installed can use Messaging
Menu");
+ private Configuration config;
- return;
- }
- app = new MessagingMenu.App("org.gnome.Geary.desktop");
+ public Libmessagingmenu(NewMessagesMonitor monitor,
+ Configuration config) {
+ base(monitor);
+ this.config = config;
+
+ app = new MessagingMenu.App(
+ "%s.desktop".printf(GearyApplication.APP_ID)
+ );
app.register();
app.activate_source.connect(on_activate_source);
@@ -63,7 +63,7 @@ public class Libmessagingmenu : NewMessagesIndicator {
}
private void show_new_messages_count(Geary.Folder folder, int count) {
- if (!GearyApplication.instance.config.show_notifications ||
!monitor.should_notify_new_messages(folder))
+ if (!this.config.show_notifications || !monitor.should_notify_new_messages(folder))
return;
string source_id = get_source_id(folder);
diff --git a/src/client/notification/new-messages-indicator.vala
b/src/client/notification/new-messages-indicator.vala
index d9da3439..5a235512 100644
--- a/src/client/notification/new-messages-indicator.vala
+++ b/src/client/notification/new-messages-indicator.vala
@@ -20,7 +20,8 @@ public abstract class NewMessagesIndicator : Geary.BaseObject {
this.monitor = monitor;
}
- public static NewMessagesIndicator create(NewMessagesMonitor monitor) {
+ public static NewMessagesIndicator create(NewMessagesMonitor monitor,
+ Configuration config) {
NewMessagesIndicator? indicator = null;
// Indicators are ordered from most to least prefered. If more than one is available,
@@ -28,7 +29,7 @@ public abstract class NewMessagesIndicator : Geary.BaseObject {
#if HAVE_LIBMESSAGINGMENU
if (indicator == null)
- indicator = new Libmessagingmenu(monitor);
+ indicator = new Libmessagingmenu(monitor, config);
#endif
if (indicator == null)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]