From 13fb16f2793ee91099b1f2960c1875896991f1c4 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Sun, 21 Mar 2010 22:22:57 -0400 Subject: Demonstrate extending the EExtension API. Introduce e_extensible_list_extensions(), which provides extensible objects access to their own extensions, or a subset of them. Convert EShellBackend to an abstract EExtension subtype. EShell will load its extensions with e_extensible_load_extensions(), and then obtain a list of EShellBackend extensions as follows: shell_backends = e_extensible_list_extensions ( E_EXTENSIBLE (shell), E_TYPE_SHELL_BACKEND); Because EShellBackend is abstract, its GType is skipped while traversing the GType hierarchy to find EShell extensions. --- shell/e-shell.c | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) (limited to 'shell/e-shell.c') diff --git a/shell/e-shell.c b/shell/e-shell.c index c9dfd156e6..f877bca4ec 100644 --- a/shell/e-shell.c +++ b/shell/e-shell.c @@ -52,7 +52,7 @@ struct _EShellPrivate { GtkWidget *preferences_window; /* Shell Backends */ - GList *loaded_backends; + GList *loaded_backends; /* not referenced */ GHashTable *backends_by_name; GHashTable *backends_by_scheme; @@ -407,23 +407,14 @@ shell_split_and_insert_items (GHashTable *hash_table, } static void -shell_add_backend (GType type, - EShell *shell) +shell_process_backend (EShellBackend *shell_backend, + EShell *shell) { EShellBackendClass *class; - EShellBackend *shell_backend; GHashTable *backends_by_name; GHashTable *backends_by_scheme; const gchar *string; - shell_backend = g_object_new (type, "shell", shell, NULL); - - shell->priv->loaded_backends = g_list_insert_sorted ( - shell->priv->loaded_backends, shell_backend, - (GCompareFunc) e_shell_backend_compare); - - /* Bookkeeping */ - class = E_SHELL_BACKEND_GET_CLASS (shell_backend); backends_by_name = shell->priv->backends_by_name; backends_by_scheme = shell->priv->backends_by_scheme; @@ -601,10 +592,6 @@ shell_dispose (GObject *object) priv->preferences_window = NULL; } - g_list_foreach (priv->loaded_backends, (GFunc) g_object_unref, NULL); - g_list_free (priv->loaded_backends); - priv->loaded_backends = NULL; - if (priv->preparing_for_line_change != NULL) { g_object_remove_weak_pointer ( G_OBJECT (priv->preparing_for_line_change), @@ -629,6 +616,8 @@ shell_finalize (GObject *object) if (!unique_app_is_running (UNIQUE_APP (object))) e_file_lock_destroy (); + g_list_free (priv->loaded_backends); + g_free (priv->geometry); g_free (priv->module_directory); @@ -640,6 +629,7 @@ static void shell_constructed (GObject *object) { EShellPrivate *priv; + GList *list; priv = E_SHELL_GET_PRIVATE (object); @@ -659,11 +649,13 @@ shell_constructed (GObject *object) shell_load_modules (E_SHELL (object)); - e_type_traverse ( - E_TYPE_SHELL_BACKEND, (ETypeFunc) - shell_add_backend, object); - - e_extensible_load_extensions (E_EXTENSIBLE (object)); + /* Process shell backends. */ + list = g_list_sort ( + e_extensible_list_extensions ( + E_EXTENSIBLE (object), E_TYPE_SHELL_BACKEND), + (GCompareFunc) e_shell_backend_compare); + g_list_foreach (list, (GFunc) shell_process_backend, object); + priv->loaded_backends = list; } static UniqueResponse -- cgit v1.2.3