[seahorse/wip/nielsdg/src-port: 2/4] WIP



commit 48534e34067ca3564566a1f48aa8d8c2a16998c4
Author: Niels De Graef <nielsdegraef gmail com>
Date:   Mon Jan 29 11:24:41 2018 +0100

    WIP

 common/catalog.vala                                |    3 -
 common/config.vapi                                 |   15 +-
 libseahorse/meson.build                            |    9 -
 libseahorse/seahorse-application.c                 |  248 --------------------
 libseahorse/seahorse-application.h                 |   49 ----
 libseahorse/seahorse-search-provider.h             |   49 ----
 libseahorse/seahorse-widget.h                      |    2 -
 src/application.vala                               |  143 +++++++++++
 src/key-manager.vala                               |    9 +-
 src/main.vala                                      |   18 --
 src/meson.build                                    |   15 ++-
 .../org.gnome.ShellSearchProvider2.xml             |    0
 .../search-provider.vala                           |   19 +--
 src/sidebar.vala                                   |   30 ++--
 14 files changed, 189 insertions(+), 420 deletions(-)
---
diff --git a/common/catalog.vala b/common/catalog.vala
index 394adc0..deef377 100644
--- a/common/catalog.vala
+++ b/common/catalog.vala
@@ -107,8 +107,6 @@ public abstract class Catalog : Gtk.Window {
                this._edit_copy = actions.get_action("edit-export-clipboard");
                this._file_export = actions.get_action("file-export");
                this._ui_manager.insert_action_group (actions, 0);
-
-               Seahorse.Application.get().add_window(this);
        }
 
        public override void dispose() {
@@ -131,7 +129,6 @@ public abstract class Catalog : Gtk.Window {
                        this.get_size(out width, out height);
                        this._settings.set_int("width", width);
                        this._settings.set_int("height", height);
-                       Seahorse.Application.get().remove_window (this);
                }
 
                base.dispose();
diff --git a/common/config.vapi b/common/config.vapi
index aa0b584..6e93f44 100644
--- a/common/config.vapi
+++ b/common/config.vapi
@@ -8,10 +8,16 @@ namespace Config
 
        public const string VERSION;
        public const string PACKAGE;
+       public const string PACKAGE_STRING;
        public const string GETTEXT_PACKAGE;
 
        public const string SSH_PATH;
        public const string SSH_KEYGEN_PATH;
+
+       public const string GNUPG;
+       public const int GPG_MAJOR;
+       public const int GPG_MINOR;
+       public const int GPG_MICRO;
 }
 
 /*
@@ -24,11 +30,6 @@ namespace Seahorse {
 
 public void register_resource();
 
-[CCode (cheader_filename = "libseahorse/seahorse-application.h")]
-public class Application : Gtk.Application {
-  public Application();
-}
-
 [CCode (cheader_filename = "libseahorse/seahorse-util.h")]
 public static GLib.HashFunc<ulong?> ulong_hash;
 
@@ -46,6 +47,10 @@ namespace Progress {
        public void show(GLib.Cancellable? cancellable, string title, bool delayed);
 }
 
+namespace Pgp.Backend {
+       public void initialize();
+}
+
 }
 
 namespace Egg {
diff --git a/libseahorse/meson.build b/libseahorse/meson.build
index c1a7bbc..b1e8045 100644
--- a/libseahorse/meson.build
+++ b/libseahorse/meson.build
@@ -3,27 +3,18 @@ marshaller = gnome.genmarshal('seahorse-marshal',
   prefix: 'seahorse_marshal',
 )
 
-search_provider_src = gnome.gdbus_codegen('seahorse-shell-search-provider-generated',
-  'org.gnome.ShellSearchProvider2.xml',
-  interface_prefix : 'org.gnome.',
-  namespace : 'Seahorse',
-)
-
 
 libseahorse_sources = [
-  'seahorse-application.c',
   'seahorse-bind.c',
   'seahorse-interaction.c',
   'seahorse-object-list.c',
   'seahorse-object-model.c',
   'seahorse-object-widget.c',
   'seahorse-progress.c',
-  'seahorse-search-provider.c',
   'seahorse-util.c',
   'seahorse-widget.c',
   marshaller,
   resources_src,
-  search_provider_src,
 ]
 
 libseahorse_deps = [
diff --git a/libseahorse/seahorse-widget.h b/libseahorse/seahorse-widget.h
index 068c104..f4ab2c5 100644
--- a/libseahorse/seahorse-widget.h
+++ b/libseahorse/seahorse-widget.h
@@ -24,8 +24,6 @@
 #include <glib.h>
 #include <gtk/gtk.h>
 
-#include "seahorse-application.h"
-
 #define SEAHORSE_TYPE_WIDGET            (seahorse_widget_get_type ())
 #define SEAHORSE_WIDGET(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), SEAHORSE_TYPE_WIDGET, 
SeahorseWidget))
 #define SEAHORSE_WIDGET_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), SEAHORSE_TYPE_WIDGET, 
SeahorseWidgetClass))
diff --git a/src/application.vala b/src/application.vala
new file mode 100644
index 0000000..3dbc3f3
--- /dev/null
+++ b/src/application.vala
@@ -0,0 +1,143 @@
+/*
+ * Seahorse
+ *
+ * Copyright (C) 2003 Jacob Perkins
+ * Copyright (C) 2005, 2006 Stefan Walter
+ * Copyright (C) 2011 Collabora Ltd.
+ * Copyright (C) 2012 Stefan Walter
+ * Copyright (C) 2018 Niels De Graef
+ *
+ * This program 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 this program; if not, see
+ * <http://www.gnu.org/licenses/>.
+ */
+
+public class Seahorse.Application : Gtk.Application {
+    /* private SearchProvider? search_provider; */
+
+    private const int INACTIVITY_TIMEOUT = 120 * 1000; /* Two minutes, in milliseconds */
+
+    public Application () {
+        GLib.Object (
+            application_id: "org.gnome.seahorse.Application",
+            flags: ApplicationFlags.HANDLES_COMMAND_LINE
+        );
+
+        /* this.search_provider = new SearchProvider(); */
+    }
+
+    public override void startup() {
+        // Insert Icons into Stock
+        icons_init ();
+
+        // Initialize the backends
+        Gkr.Backend.initialize();
+        Ssh.Backend.initialize();
+#if WITH_PGP
+        Pgp.Backend.initialize();
+#endif
+#if WITH_PKCS11
+        Pkcs11.Backend.initialize();
+#endif
+    }
+
+    public override void activate() {
+        KeyManager key_mgr = new Seahorse.KeyManager(this);
+        key_mgr.show();
+    }
+
+    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) {
+            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); */
+        return false;
+    }
+
+    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;
+    }
+
+    public override bool dbus_register (DBusConnection connection, string object_path) throws Error {
+        if (!base.dbus_register(connection, object_path))
+            return false;
+
+        return true;
+        /* return this.search_provider.dbus_register (connection, object_path); */
+    }
+
+    public override void dbus_unregister (DBusConnection connection, string object_path) {
+        /* if (this.search_provider != null) */
+        /*     this.search_provider.dbus_unregister(connection, object_path); */
+
+        base.dbus_unregister(connection, object_path);
+    }
+
+    public void initialize_search () {
+        /* this.search_provider.initialize(); */
+    }
+}
diff --git a/src/key-manager.vala b/src/key-manager.vala
index 39340f9..51bcbda 100644
--- a/src/key-manager.vala
+++ b/src/key-manager.vala
@@ -68,8 +68,11 @@ public class Seahorse.KeyManager : Catalog {
         { "view-any", null, N_("Show _Any"), null, N_("Show all keys, certificates and passwords"), 
ShowFilter.ANY },
     };
 
-    public KeyManager() {
-        GLib.Object(ui_name: "key-manager");
+    public KeyManager(Application app) {
+        GLib.Object(
+                       ui_name: "key-manager",
+                       application: app
+               );
         this.settings = new GLib.Settings("org.gnome.seahorse.manager");
 
         Gtk.Window window = this.window;
@@ -406,7 +409,7 @@ public class Seahorse.KeyManager : Catalog {
     }
 
     private void on_app_quit(Gtk.Action action) {
-        Application.get().quit();
+        this.application.quit();
     }
 
     private string update_view_filter() {
diff --git a/src/main.vala b/src/main.vala
index f2ed405..6746b2d 100644
--- a/src/main.vala
+++ b/src/main.vala
@@ -27,24 +27,6 @@ public int main (string[] args) {
     Seahorse.register_resource();
 
     Seahorse.Application app = new Seahorse.Application();
-
-    app.activate.connect(() => {
-        Seahorse.KeyManager key_mgr = new Seahorse.KeyManager();
-        key_mgr.show();
-    });
-
-    // Initialize the backends
-    app.startup.connect(() => {
-        Seahorse.Gkr.Backend.initialize();
-        Seahorse.Ssh.Backend.initialize();
-#if WITH_PGP
-        Seahorse.Pgp.Backend.initialize();
-#endif
-#if WITH_PKCS11
-        Seahorse.Pkcs11.Backend.initialize();
-#endif
-    });
-
     int status = app.run(args);
 
     Seahorse.Registry.cleanup();
diff --git a/src/meson.build b/src/meson.build
index 8c04772..c17ef0e 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -1,11 +1,20 @@
+# search_provider_src = gnome.gdbus_codegen('seahorse-shell-search-provider-generated',
+#   'org.gnome.ShellSearchProvider2.xml',
+#   interface_prefix : 'org.gnome.',
+#   namespace : 'Seahorse',
+# )
+
 seahorse_sources = [
+  'application.vala',
   'generate-select.vala',
   'import-dialog.vala',
   'key-manager.vala',
   'main.vala',
+  # 'search-provider.vala',
   'sidebar.vala',
 
   resources_src,
+  # search_provider_src,
 ]
 
 seahorse_dependencies = [
@@ -14,7 +23,6 @@ seahorse_dependencies = [
   gcr,
   gcr_ui,
   libsecret,
-  config,
   common_dep,
   libseahorse_dep,
 ]
@@ -26,8 +34,12 @@ seahorse_linkedlibs = [
   ssh_lib,
 ]
 
+seahorse_vala_flags = [
+]
+
 if with_pgp
   seahorse_linkedlibs += pgp_lib
+  seahorse_vala_flags += ['-D', 'WITH_PGP' ]
 endif
 if with_pkcs11
   seahorse_linkedlibs += pkcs11_lib
@@ -37,6 +49,7 @@ endif
 seahorse_exe = executable('seahorse',
   seahorse_sources,
   dependencies: seahorse_dependencies,
+  vala_args: seahorse_vala_flags,
   link_with: seahorse_linkedlibs,
   install: true,
 )
diff --git a/libseahorse/org.gnome.ShellSearchProvider2.xml b/src/org.gnome.ShellSearchProvider2.xml
similarity index 100%
rename from libseahorse/org.gnome.ShellSearchProvider2.xml
rename to src/org.gnome.ShellSearchProvider2.xml
diff --git a/libseahorse/seahorse-search-provider.c b/src/search-provider.vala
similarity index 97%
rename from libseahorse/seahorse-search-provider.c
rename to src/search-provider.vala
index 976ff18..5941952 100644
--- a/libseahorse/seahorse-search-provider.c
+++ b/src/search-provider.vala
@@ -17,24 +17,7 @@
  * <http://www.gnu.org/licenses/>.
  */
 
-#include "config.h"
-
-#include "seahorse-search-provider.h"
-
-#include "seahorse-application.h"
-#include "seahorse-widget.h"
-#include "seahorse-shell-search-provider-generated.h"
-
-#include "seahorse-common.h"
-
-#include <glib/gi18n.h>
-
-#include <gcr/gcr.h>
-
-#define SECRET_API_SUBJECT_TO_CHANGE
-#include <libsecret/secret.h>
-
-#include <string.h>
+/* #define SECRET_API_SUBJECT_TO_CHANGE */
 
 struct _SeahorseSearchProvider {
        SeahorseShellSearchProvider2Skeleton parent;
diff --git a/src/sidebar.vala b/src/sidebar.vala
index cd11199..e7d29e6 100644
--- a/src/sidebar.vala
+++ b/src/sidebar.vala
@@ -33,7 +33,7 @@ public class Seahorse.Sidebar : Gtk.ScrolledWindow {
     private bool updating;
 
     // A set of chosen uris, used with settings
-    private HashTable<string, string>? chosen;
+    private GenericSet<string?> chosen;
 
     // Action icons
     private Gdk.Pixbuf? pixbuf_lock;
@@ -58,8 +58,8 @@ public class Seahorse.Sidebar : Gtk.ScrolledWindow {
      * The URIs selected by the user
      */
     public string[] selected_uris {
-        owned get { return get_selected_uris(); }
-        set { set_selected_uris(value); }
+        owned get { return chosen_uris_to_array(); }
+        set { replace_chosen_uris(value); }
     }
 
     /**
@@ -110,7 +110,7 @@ public class Seahorse.Sidebar : Gtk.ScrolledWindow {
         this.backends = new List<Backend>();
         this.selection = new HashTable<Gcr.Collection, Gcr.Collection>(direct_hash, direct_equal);
         this.objects = new Gcr.UnionCollection();
-        this.chosen = new HashTable<string, string>(str_hash, str_equal);
+        this.chosen = new GenericSet<string?>(str_hash, str_equal);
 
         this.accel_group = new Gtk.AccelGroup();
 
@@ -415,9 +415,9 @@ public class Seahorse.Sidebar : Gtk.ScrolledWindow {
 
                 if (update_chosen) {
                     string? uri = place.uri;
-                    bool have = (this.chosen.lookup(uri) != null);
+                    bool have = (uri in this.chosen);
                     if (include && !have) {
-                        this.chosen.insert(uri, "");
+                        this.chosen.add(uri);
                         changed = true;
                     } else if (!include && have) {
                         this.chosen.remove(uri);
@@ -456,7 +456,7 @@ public class Seahorse.Sidebar : Gtk.ScrolledWindow {
             update_objects_in_collection(true);
     }
 
-    private void update_objects_for_chosen(HashTable<string, string>? chosen) {
+    private void update_objects_for_chosen(GenericSet<string?> chosen) {
         this.updating = true;
 
         Gtk.TreeSelection selection = this.tree_view.get_selection();
@@ -471,7 +471,7 @@ public class Seahorse.Sidebar : Gtk.ScrolledWindow {
                                      Columns.URI, out uri, -1);
 
                 if (collection != null && uri != null) {
-                    if (chosen.lookup(uri) != null)
+                    if (uri in chosen)
                         selection.select_iter(iter);
                     else
                         selection.unselect_iter(iter);
@@ -828,21 +828,21 @@ public class Seahorse.Sidebar : Gtk.ScrolledWindow {
         return true;
     }
 
-    public string[] get_selected_uris() {
+    public string[] chosen_uris_to_array() {
         string[] results = {};
-        this.chosen.foreach((key, v) => {
-            results += key;
-        });
+        foreach (string? uri in this.chosen)
+            results += uri;
+
         results += null;
 
         return results;
     }
 
-    public void set_selected_uris(string[] uris) {
+    public void replace_chosen_uris(string[] uris) {
         // For quick lookups
-        HashTable<string, string>? chosen = new HashTable<string, string>(str_hash, str_equal);
+        GenericSet<string?> chosen = new GenericSet<string?>(str_hash, str_equal);
         foreach (string uri in uris)
-            chosen.insert(uri, "");
+            chosen.add(uri);
 
         update_objects_for_chosen(chosen);
         this.chosen = chosen;


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