[seahorse] common: Migrate SeahorseRegistry to vala code



commit 803b0820e4e95498483a3008ff03538f05483bb6
Author: Stef Walter <stefw gnome org>
Date:   Thu May 2 17:39:06 2013 +0200

    common: Migrate SeahorseRegistry to vala code
    
     * Remove seahorse_cleanup_xxx() code, as it's not really used
       that much in a general purpose anymore
     * Simplify the registry to what it's currently used for which is
       to just register instantiated objects

 common/Makefile.am                |    1 +
 common/registry.vala              |   96 ++++++++++
 gkr/seahorse-gkr-actions.c        |    4 +-
 libseahorse/Makefile.am           |    2 -
 libseahorse/seahorse-backend.c    |   11 +-
 libseahorse/seahorse-catalog.c    |    1 -
 libseahorse/seahorse-cleanup.c    |   86 ---------
 libseahorse/seahorse-cleanup.h    |   33 ----
 libseahorse/seahorse-place.c      |    2 +-
 libseahorse/seahorse-prefs.c      |    2 +-
 libseahorse/seahorse-registry.c   |  361 -------------------------------------
 libseahorse/seahorse-registry.h   |   78 --------
 libseahorse/seahorse-servers.c    |   13 +-
 libseahorse/seahorse-servers.h    |    2 +
 pgp/seahorse-gpgme-generate.c     |    4 +-
 pgp/seahorse-gpgme-keyring.c      |    2 +-
 pgp/seahorse-hkp-source.c         |    1 -
 pgp/seahorse-ldap-source.c        |    1 -
 pgp/seahorse-pgp-actions.c        |    2 +-
 pgp/seahorse-pgp-backend.c        |    2 +-
 pgp/seahorse-server-source.c      |    2 +-
 pgp/seahorse-unknown-source.c     |    1 -
 pkcs11/seahorse-pkcs11-generate.c |    4 +-
 pkcs11/seahorse-pkcs11-request.c  |    1 -
 pkcs11/seahorse-token.c           |    1 -
 src/seahorse-generate-select.c    |    4 +-
 src/seahorse-key-manager.c        |    1 -
 src/seahorse-main.c               |    7 +-
 ssh/seahorse-ssh-actions.c        |    1 -
 ssh/seahorse-ssh-generate.c       |    4 +-
 ssh/seahorse-ssh-source.c         |    1 -
 31 files changed, 130 insertions(+), 601 deletions(-)
---
diff --git a/common/Makefile.am b/common/Makefile.am
index e2c5e1b..320ce96 100644
--- a/common/Makefile.am
+++ b/common/Makefile.am
@@ -11,6 +11,7 @@ libcommon_la_SOURCES = \
        deleter.vala \
        exportable.vala \
        exporter.vala \
+       registry.vala \
        viewable.vala \
        $(NULL)
 
diff --git a/common/registry.vala b/common/registry.vala
new file mode 100644
index 0000000..abd7b30
--- /dev/null
+++ b/common/registry.vala
@@ -0,0 +1,96 @@
+/*
+ * Seahorse
+ *
+ * Copyright (C) 2008 Stefan Walter
+ * Copyright (C) 2013 Stefan Walter
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+namespace Seahorse {
+
+public class Registry : GLib.Object {
+       private GLib.HashTable<string, GLib.HashTable<GLib.Object, GLib.Object>> _objects;
+
+       private static Registry _singleton;
+
+       private static Registry instance() {
+               if (_singleton == null)
+                       _singleton = new Registry();
+               return _singleton;
+       }
+
+       public static void cleanup() {
+               _singleton = null;
+       }
+
+       public static void register_object(GLib.Object object,
+                                          string category) {
+               Registry registry = Registry.instance();
+               GLib.HashTable<GLib.Object, GLib.Object>? oset;
+
+               oset = registry._objects.lookup(category);
+               if (oset == null) {
+                       oset = new GLib.HashTable<GLib.Object, GLib.Object>(GLib.direct_hash, 
GLib.direct_equal);
+                       registry._objects.replace(category, oset);
+               }
+
+               oset.replace(object, object);
+       }
+
+       public static GLib.Object? object_instance(string category) {
+               Registry registry = Registry.instance();
+               GLib.HashTable<GLib.Object, GLib.Object>? oset;
+
+               oset = registry._objects.lookup(category);
+               if (oset == null)
+                       return null;
+
+               var iter = HashTableIter<GLib.Object, GLib.Object> (oset);
+               unowned GLib.Object key;
+               unowned GLib.Object value;
+               while (iter.next (out key, out value)) {
+                       return value;
+               }
+
+               return null;
+       }
+
+       public static GLib.List<GLib.Object> object_instances(string category) {
+               Registry registry = Registry.instance();
+               GLib.HashTable<GLib.Object, GLib.Object>? oset;
+               GLib.List<GLib.Object> insts = null;
+
+               oset = registry._objects.lookup(category);
+               if (oset == null)
+                       return insts;
+
+               var iter = HashTableIter<GLib.Object, GLib.Object> (oset);
+               unowned GLib.Object key;
+               unowned GLib.Object value;
+               while (iter.next (out key, out value)) {
+                       insts.append(value);
+               }
+
+               return insts;
+       }
+
+       construct {
+               _objects = new GLib.HashTable<weak string, GLib.HashTable<GLib.Object, 
GLib.Object>>(GLib.str_hash, GLib.str_equal);
+       }
+}
+
+}
diff --git a/gkr/seahorse-gkr-actions.c b/gkr/seahorse-gkr-actions.c
index ab20598..c7f4d55 100644
--- a/gkr/seahorse-gkr-actions.c
+++ b/gkr/seahorse-gkr-actions.c
@@ -30,10 +30,10 @@
 
 #include "seahorse-action.h"
 #include "seahorse-actions.h"
+#include "seahorse-common.h"
 #include "seahorse-delete-dialog.h"
 #include "seahorse-object-list.h"
 #include "seahorse-progress.h"
-#include "seahorse-registry.h"
 #include "seahorse-util.h"
 
 #include <glib/gi18n.h>
@@ -119,7 +119,7 @@ on_backend_notify_service (GObject *obj,
        actions = gtk_action_group_new ("gkr-generate");
        gtk_action_group_set_translation_domain (actions, GETTEXT_PACKAGE);
        gtk_action_group_add_actions (actions, ENTRIES_NEW, G_N_ELEMENTS (ENTRIES_NEW), NULL);
-       seahorse_registry_register_object (NULL, G_OBJECT (actions), "generator", NULL);
+       seahorse_registry_register_object (G_OBJECT (actions), "generator");
        g_object_unref (actions);
 }
 
diff --git a/libseahorse/Makefile.am b/libseahorse/Makefile.am
index 79fa7c3..ad43c89 100644
--- a/libseahorse/Makefile.am
+++ b/libseahorse/Makefile.am
@@ -49,7 +49,6 @@ libseahorse_la_SOURCES = \
        seahorse-backend.c seahorse-backend.h \
        seahorse-bind.c seahorse-bind.h \
        seahorse-catalog.c seahorse-catalog.h \
-       seahorse-cleanup.c seahorse-cleanup.h \
        seahorse-collection.c seahorse-collection.h \
        seahorse-debug.c seahorse-debug.h \
        seahorse-delete-dialog.c seahorse-delete-dialog.h \
@@ -66,7 +65,6 @@ libseahorse_la_SOURCES = \
        seahorse-predicate.c seahorse-predicate.h \
        seahorse-prefs.c seahorse-prefs.h \
        seahorse-progress.c seahorse-progress.h \
-       seahorse-registry.c seahorse-registry.h \
        seahorse-search-provider.c seahorse-search-provider.h \
        seahorse-servers.c seahorse-servers.h \
        seahorse-types.c seahorse-types.h \
diff --git a/libseahorse/seahorse-backend.c b/libseahorse/seahorse-backend.c
index aa70c51..86155c3 100644
--- a/libseahorse/seahorse-backend.c
+++ b/libseahorse/seahorse-backend.c
@@ -22,7 +22,7 @@
 #include "config.h"
 
 #include "seahorse-backend.h"
-#include "seahorse-registry.h"
+#include "seahorse-common.h"
 
 #include <gcr/gcr.h>
 
@@ -72,17 +72,12 @@ seahorse_backend_lookup_place (SeahorseBackend *backend,
 void
 seahorse_backend_register (SeahorseBackend *backend)
 {
-       gchar *name = NULL;
-
        g_return_if_fail (SEAHORSE_IS_BACKEND (backend));
-
-       g_object_get (backend, "name", &name, NULL);
-       seahorse_registry_register_object (NULL, G_OBJECT (backend), "backend", name, NULL);
-       g_free (name);
+       seahorse_registry_register_object (G_OBJECT (backend), "backend");
 }
 
 GList *
 seahorse_backend_get_registered (void)
 {
-       return seahorse_registry_object_instances (NULL, "backend", NULL);
+       return seahorse_registry_object_instances ("backend");
 }
diff --git a/libseahorse/seahorse-catalog.c b/libseahorse/seahorse-catalog.c
index f358dba..ac76674 100644
--- a/libseahorse/seahorse-catalog.c
+++ b/libseahorse/seahorse-catalog.c
@@ -30,7 +30,6 @@
 #include "seahorse-object.h"
 #include "seahorse-prefs.h"
 #include "seahorse-progress.h"
-#include "seahorse-registry.h"
 #include "seahorse-util.h"
 
 #include <gcr/gcr.h>
diff --git a/libseahorse/seahorse-place.c b/libseahorse/seahorse-place.c
index d2f87e7..ba197c3 100644
--- a/libseahorse/seahorse-place.c
+++ b/libseahorse/seahorse-place.c
@@ -22,9 +22,9 @@
 
 #include "config.h"
 
+#include "seahorse-common.h"
 #include "seahorse-marshal.h"
 #include "seahorse-object.h"
-#include "seahorse-registry.h"
 #include "seahorse-place.h"
 #include "seahorse-util.h"
 
diff --git a/libseahorse/seahorse-prefs.c b/libseahorse/seahorse-prefs.c
index 2bd9224..d98dc61 100644
--- a/libseahorse/seahorse-prefs.c
+++ b/libseahorse/seahorse-prefs.c
@@ -23,10 +23,10 @@
 #include <glib/gi18n.h>
 
 #include "seahorse-application.h"
+#include "seahorse-common.h"
 #include "seahorse-icons.h"
 #include "seahorse-keyserver-control.h"
 #include "seahorse-prefs.h"
-#include "seahorse-registry.h"
 #include "seahorse-servers.h"
 #include "seahorse-util.h"
 #include "seahorse-widget.h"
diff --git a/libseahorse/seahorse-servers.c b/libseahorse/seahorse-servers.c
index 3ef4912..5a60200 100644
--- a/libseahorse/seahorse-servers.c
+++ b/libseahorse/seahorse-servers.c
@@ -20,7 +20,6 @@
  */
 
 #include "seahorse-application.h"
-#include "seahorse-cleanup.h"
 #include "seahorse-servers.h"
 
 #include <string.h>
@@ -87,14 +86,18 @@ seahorse_servers_register_type (const char* type, const char* description,
        info->type = g_strdup (type);
        info->validator = validate;
        
-       if (!server_types) {
+       if (!server_types)
                server_types = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, free_server_info);
-               seahorse_cleanup_register ((GDestroyNotify)g_hash_table_destroy, server_types);
-       }
-       
        g_hash_table_replace (server_types, info->type, info);
 }
 
+void
+seahorse_servers_cleanup (void)
+{
+       if (server_types)
+               g_hash_table_destroy (server_types);
+       server_types = NULL;
+}
 
 gchar **
 seahorse_servers_get_uris (void)
diff --git a/libseahorse/seahorse-servers.h b/libseahorse/seahorse-servers.h
index 94c4820..8de621d 100644
--- a/libseahorse/seahorse-servers.h
+++ b/libseahorse/seahorse-servers.h
@@ -41,4 +41,6 @@ void            seahorse_servers_register_type          (const char* type,
                                                          const char* description, 
                                                          SeahorseValidUriFunc validate);
 
+void            seahorse_servers_cleanup                (void);
+
 #endif
diff --git a/pgp/seahorse-gpgme-generate.c b/pgp/seahorse-gpgme-generate.c
index d0768d1..f7cb203 100644
--- a/pgp/seahorse-gpgme-generate.c
+++ b/pgp/seahorse-gpgme-generate.c
@@ -30,8 +30,8 @@
 #include "egg-datetime.h"
 
 #include "seahorse-action.h"
+#include "seahorse-common.h"
 #include "seahorse-icons.h"
-#include "seahorse-registry.h"
 #include "seahorse-passphrase.h"
 #include "seahorse-progress.h"
 #include "seahorse-util.h"
@@ -113,7 +113,7 @@ seahorse_gpgme_generate_register (void)
        gtk_action_group_add_actions (actions, ACTION_ENTRIES, G_N_ELEMENTS (ACTION_ENTRIES), NULL);
        
        /* Register this as a generator */
-       seahorse_registry_register_object (NULL, G_OBJECT (actions), SEAHORSE_PGP_TYPE_STR, "generator", 
NULL);
+       seahorse_registry_register_object (G_OBJECT (actions), "generator");
 }
 
 /* --------------------------------------------------------------------------
diff --git a/pgp/seahorse-gpgme-keyring.c b/pgp/seahorse-gpgme-keyring.c
index da30fe6..0fb3bae 100644
--- a/pgp/seahorse-gpgme-keyring.c
+++ b/pgp/seahorse-gpgme-keyring.c
@@ -31,9 +31,9 @@
 #include "seahorse-pgp-actions.h"
 #include "seahorse-pgp-key.h"
 
+#include "seahorse-common.h"
 #include "seahorse-place.h"
 #include "seahorse-progress.h"
-#include "seahorse-registry.h"
 #include "seahorse-util.h"
 #include "seahorse-passphrase.h"
 
diff --git a/pgp/seahorse-hkp-source.c b/pgp/seahorse-hkp-source.c
index c25a0ca..629a15d 100644
--- a/pgp/seahorse-hkp-source.c
+++ b/pgp/seahorse-hkp-source.c
@@ -37,7 +37,6 @@
 #include "seahorse-object-list.h"
 #include "seahorse-place.h"
 #include "seahorse-progress.h"
-#include "seahorse-registry.h"
 #include "seahorse-util.h"
 
 #include <libsoup/soup.h>
diff --git a/pgp/seahorse-ldap-source.c b/pgp/seahorse-ldap-source.c
index fdbbd98..776912e 100644
--- a/pgp/seahorse-ldap-source.c
+++ b/pgp/seahorse-ldap-source.c
@@ -37,7 +37,6 @@
 #include "seahorse-object-list.h"
 #include "seahorse-place.h"
 #include "seahorse-progress.h"
-#include "seahorse-registry.h"
 #include "seahorse-servers.h"
 #include "seahorse-util.h"
 
diff --git a/pgp/seahorse-pgp-actions.c b/pgp/seahorse-pgp-actions.c
index e0223fe..60e59dc 100644
--- a/pgp/seahorse-pgp-actions.c
+++ b/pgp/seahorse-pgp-actions.c
@@ -36,10 +36,10 @@
 
 #include "seahorse-action.h"
 #include "seahorse-actions.h"
+#include "seahorse-common.h"
 #include "seahorse-delete-dialog.h"
 #include "seahorse-object.h"
 #include "seahorse-object-list.h"
-#include "seahorse-registry.h"
 #include "seahorse-util.h"
 
 GType   seahorse_pgp_backend_actions_get_type         (void) G_GNUC_CONST;
diff --git a/pgp/seahorse-pgp-backend.c b/pgp/seahorse-pgp-backend.c
index bb26aed..cfb7e1f 100644
--- a/pgp/seahorse-pgp-backend.c
+++ b/pgp/seahorse-pgp-backend.c
@@ -29,8 +29,8 @@
 #include "seahorse-unknown-source.h"
 
 #include "seahorse-backend.h"
+#include "seahorse-common.h"
 #include "seahorse-progress.h"
-#include "seahorse-registry.h"
 #include "seahorse-servers.h"
 #include "seahorse-util.h"
 
diff --git a/pgp/seahorse-server-source.c b/pgp/seahorse-server-source.c
index 6f1039f..0b2d541 100644
--- a/pgp/seahorse-server-source.c
+++ b/pgp/seahorse-server-source.c
@@ -32,7 +32,7 @@
 #include "seahorse-pgp-key.h"
 #include "seahorse-server-source.h"
 
-#include "seahorse-registry.h"
+#include "seahorse-common.h"
 #include "seahorse-util.h"
 
 /**
diff --git a/pgp/seahorse-unknown-source.c b/pgp/seahorse-unknown-source.c
index 1c428cd..26f1f82 100644
--- a/pgp/seahorse-unknown-source.c
+++ b/pgp/seahorse-unknown-source.c
@@ -26,7 +26,6 @@
 #include "seahorse-unknown-source.h"
 
 #include "seahorse-place.h"
-#include "seahorse-registry.h"
 #include "seahorse-unknown.h"
 
 #include <gcr/gcr-base.h>
diff --git a/pkcs11/seahorse-pkcs11-generate.c b/pkcs11/seahorse-pkcs11-generate.c
index b127989..db0f56a 100644
--- a/pkcs11/seahorse-pkcs11-generate.c
+++ b/pkcs11/seahorse-pkcs11-generate.c
@@ -27,9 +27,9 @@
 #include "seahorse-token.h"
 
 #include "seahorse-action.h"
+#include "seahorse-common.h"
 #include "seahorse-progress.h"
 #include "seahorse-interaction.h"
-#include "seahorse-registry.h"
 #include "seahorse-util.h"
 
 #include <glib/gi18n.h>
@@ -515,5 +515,5 @@ seahorse_pkcs11_generate_register (void)
        actions = gtk_action_group_new ("pkcs11-generate");
        gtk_action_group_set_translation_domain (actions, GETTEXT_PACKAGE);
        gtk_action_group_add_actions (actions, ACTION_ENTRIES, G_N_ELEMENTS (ACTION_ENTRIES), NULL);
-       seahorse_registry_register_object (NULL, G_OBJECT (actions), "generator", NULL);
+       seahorse_registry_register_object (G_OBJECT (actions), "generator");
 }
diff --git a/pkcs11/seahorse-pkcs11-request.c b/pkcs11/seahorse-pkcs11-request.c
index d4b8746..dae1df2 100644
--- a/pkcs11/seahorse-pkcs11-request.c
+++ b/pkcs11/seahorse-pkcs11-request.c
@@ -28,7 +28,6 @@
 #include "seahorse-action.h"
 #include "seahorse-progress.h"
 #include "seahorse-interaction.h"
-#include "seahorse-registry.h"
 #include "seahorse-util.h"
 
 #include <glib/gi18n.h>
diff --git a/pkcs11/seahorse-token.c b/pkcs11/seahorse-token.c
index e5d9727..575e8e4 100644
--- a/pkcs11/seahorse-token.c
+++ b/pkcs11/seahorse-token.c
@@ -36,7 +36,6 @@
 
 #include "seahorse-lockable.h"
 #include "seahorse-place.h"
-#include "seahorse-registry.h"
 #include "seahorse-util.h"
 
 enum {
diff --git a/src/seahorse-generate-select.c b/src/seahorse-generate-select.c
index aedada0..b3fbbe3 100644
--- a/src/seahorse-generate-select.c
+++ b/src/seahorse-generate-select.c
@@ -24,7 +24,7 @@
 #include "seahorse-generate-select.h"
 
 #include "seahorse-action.h"
-#include "seahorse-registry.h"
+#include "seahorse-common.h"
 
 #include <glib/gi18n.h>
 
@@ -178,7 +178,7 @@ seahorse_generate_select_constructed (GObject *obj)
        gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (self->store), on_list_sort, NULL, NULL);
        gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (self->store), 
GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, GTK_SORT_ASCENDING);
 
-       self->action_groups = seahorse_registry_object_instances (NULL, "generator", NULL);
+       self->action_groups = seahorse_registry_object_instances ("generator");
        for (l = self->action_groups; l != NULL; l = g_list_next (l)) {
                actions = gtk_action_group_list_actions (l->data);
                for (k = actions; k != NULL; k = g_list_next (k)) {
diff --git a/src/seahorse-key-manager.c b/src/seahorse-key-manager.c
index 6197cb3..171e37b 100644
--- a/src/seahorse-key-manager.c
+++ b/src/seahorse-key-manager.c
@@ -29,7 +29,6 @@
 #include "seahorse-sidebar.h"
 
 #include "seahorse-collection.h"
-#include "seahorse-registry.h"
 #include "seahorse-progress.h"
 #include "seahorse-util.h"
 
diff --git a/src/seahorse-main.c b/src/seahorse-main.c
index aa02ff3..f18f1bb 100644
--- a/src/seahorse-main.c
+++ b/src/seahorse-main.c
@@ -23,8 +23,8 @@
 #include "config.h"
 
 #include "seahorse-application.h"
-#include "seahorse-cleanup.h"
-#include "seahorse-registry.h"
+#include "seahorse-common.h"
+#include "seahorse-servers.h"
 #include "seahorse-util.h"
 
 #include "seahorse-key-manager.h"
@@ -62,7 +62,8 @@ main (int argc, char **argv)
        g_signal_connect (application, "activate", G_CALLBACK (on_application_activate), NULL);
        status = g_application_run (G_APPLICATION (application), argc, argv);
 
-       seahorse_cleanup_perform ();
+       seahorse_registry_cleanup ();
+       seahorse_servers_cleanup ();
        g_object_unref (application);
 
        return status;
diff --git a/ssh/seahorse-ssh-actions.c b/ssh/seahorse-ssh-actions.c
index a88b64e..3ea813b 100644
--- a/ssh/seahorse-ssh-actions.c
+++ b/ssh/seahorse-ssh-actions.c
@@ -32,7 +32,6 @@
 #include "seahorse-delete-dialog.h"
 #include "seahorse-object.h"
 #include "seahorse-object-list.h"
-#include "seahorse-registry.h"
 #include "seahorse-util.h"
 
 #include <glib/gi18n.h>
diff --git a/ssh/seahorse-ssh-generate.c b/ssh/seahorse-ssh-generate.c
index 6ba1019..6f9cb38 100644
--- a/ssh/seahorse-ssh-generate.c
+++ b/ssh/seahorse-ssh-generate.c
@@ -33,9 +33,9 @@
 #include "seahorse-ssh-operation.h"
 
 #include "seahorse-action.h"
+#include "seahorse-common.h"
 #include "seahorse-icons.h"
 #include "seahorse-progress.h"
-#include "seahorse-registry.h"
 #include "seahorse-util.h"
 #include "seahorse-widget.h"
 
@@ -67,7 +67,7 @@ seahorse_ssh_generate_register (void)
        gtk_action_group_add_actions (actions, ACTION_ENTRIES, G_N_ELEMENTS (ACTION_ENTRIES), NULL);
        
        /* Register this as a generator */
-       seahorse_registry_register_object (NULL, G_OBJECT (actions), SEAHORSE_SSH_TYPE_STR, "generator", 
NULL);
+       seahorse_registry_register_object (G_OBJECT (actions), "generator");
 }
 
 /* --------------------------------------------------------------------
diff --git a/ssh/seahorse-ssh-source.c b/ssh/seahorse-ssh-source.c
index 609c360..c77c28a 100644
--- a/ssh/seahorse-ssh-source.c
+++ b/ssh/seahorse-ssh-source.c
@@ -28,7 +28,6 @@
 #include "seahorse-ssh-source.h"
 
 #include "seahorse-place.h"
-#include "seahorse-registry.h"
 #include "seahorse-util.h"
 
 #include <gcr/gcr.h>


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