[seahorse/wip/sadiq/fixes: 2/2] application: Simplify handling commandline
- From: Niels De Graef <nielsdg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [seahorse/wip/sadiq/fixes: 2/2] application: Simplify handling commandline
- Date: Sat, 8 Sep 2018 08:35:02 +0000 (UTC)
commit 069807f69e1a31c7775612550e41ecbca72665e7
Author: Mohammed Sadiq <sadiq sadiqpk org>
Date: Wed Sep 5 18:35:20 2018 +0530
application: Simplify handling commandline
The commandline code was annoyingly large, and not working well.
It wasn't showing warning for unknown options. Also, the 'no-window'
choice is no longer required as the GNOME shell search now uses
gapplication-service
Let's simplify this so that it will work, and be easy to understand
src/application.vala | 68 +++++++---------------------------------------------
1 file changed, 9 insertions(+), 59 deletions(-)
---
diff --git a/src/application.vala b/src/application.vala
index bcedb0b8..e4762670 100644
--- a/src/application.vala
+++ b/src/application.vala
@@ -25,14 +25,18 @@ public class Seahorse.Application : Gtk.Application {
private SearchProvider? search_provider;
private uint search_provider_dbus_id = 0;
- private const int INACTIVITY_TIMEOUT = 120 * 1000; // Two minutes, in milliseconds
+ const OptionEntry[] cmd_options = {
+ { "version", 'v', 0, OptionArg.NONE, null, N_("Version of this application"), null },
+ { null }
+ };
public Application () {
GLib.Object (
application_id: "org.gnome.seahorse.Application",
- flags: ApplicationFlags.HANDLES_COMMAND_LINE
+ flags: ApplicationFlags.FLAGS_NONE
);
this.search_provider = new SearchProvider(this);
+ add_main_option_entries(cmd_options);
}
public override void startup() {
@@ -61,70 +65,16 @@ public class Seahorse.Application : Gtk.Application {
key_mgr.present();
}
- static bool show_version = false;
- const OptionEntry[] local_options = {
- { "version", 'v', 0, OptionArg.NONE, out show_version, N_("Version of this application"), null },
- { null }
- };
-
- public override bool local_command_line (ref weak string[] arguments, out int exit_status) {
- OptionContext context = new OptionContext(N_("- System Settings"));
- context.set_ignore_unknown_options(true);
- context.add_main_entries(local_options, Config.GETTEXT_PACKAGE);
- context.set_translation_domain(Config.GETTEXT_PACKAGE);
- context.add_group(Gtk.get_option_group (true));
-
- try {
- unowned string[] tmp = arguments;
- context.parse (ref tmp);
- } catch (Error e) {
- printerr ("seahorse: %s\n", e.message);
- exit_status = 1;
- return true;
- }
-
- if (show_version) {
+ public override int handle_local_options (VariantDict options) {
+ if (options.contains("version")) {
print ("%s\n", Config.PACKAGE_STRING);
#if WITH_PGP
print ("GNUPG: %s (%d.%d.%d)\n", Config.GNUPG, Config.GPG_MAJOR, Config.GPG_MINOR,
Config.GPG_MICRO);
#endif
- exit_status = 0;
- return true;
- }
-
- return base.local_command_line(ref arguments, out exit_status);
- }
-
- static bool no_window = false;
- const OptionEntry[] options = {
- { "no-window", 0, 0, OptionArg.NONE, out no_window, N_("Don't display a window"), null },
- { null }
- };
-
- public override int command_line (ApplicationCommandLine command_line) {
- OptionContext context = new OptionContext(N_("- System Settings"));
- context.set_ignore_unknown_options (true);
- context.add_main_entries (options, Config.GETTEXT_PACKAGE);
- context.set_translation_domain(Config.GETTEXT_PACKAGE);
-
- string[] arguments = command_line.get_arguments();
- try {
- unowned string[] tmp = arguments;
- context.parse (ref tmp);
- } catch (Error e) {
- printerr ("seahorse: %s\n", e.message);
- return 1;
- }
-
- if (no_window) {
- hold();
- set_inactivity_timeout(INACTIVITY_TIMEOUT);
- release();
return 0;
}
- activate ();
- return 0;
+ return -1;
}
public override bool dbus_register (DBusConnection connection, string object_path) throws Error {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]