[libpeas/proxys: 5/22] Add a way to know if a plugin provides a certain extension.



commit 7485a731f7c4b905f4e1fb10c514392078307060
Author: Steve Frécinaux <code istique net>
Date:   Fri May 14 16:06:00 2010 +0200

    Add a way to know if a plugin provides a certain extension.

 libpeas/peas-engine.c              |   14 ++++++++++++
 libpeas/peas-engine.h              |    3 ++
 libpeas/peas-plugin-loader.c       |   15 ++++++++++++
 libpeas/peas-plugin-loader.h       |    7 ++++++
 libpeasui/peas-ui-plugin-info.c    |   27 -----------------------
 libpeasui/peas-ui-plugin-info.h    |    2 -
 libpeasui/peas-ui-plugin-manager.c |   15 ++++++++++--
 loaders/c/peas-plugin-loader-c.c   |   42 +++++++++++++++++++++++++++--------
 8 files changed, 83 insertions(+), 42 deletions(-)
---
diff --git a/libpeas/peas-engine.c b/libpeas/peas-engine.c
index 52f4eb4..d44e916 100644
--- a/libpeas/peas-engine.c
+++ b/libpeas/peas-engine.c
@@ -791,6 +791,20 @@ peas_engine_update_plugins_ui (PeasEngine *engine,
     }
 }
 
+gboolean
+peas_engine_provides_extension (PeasEngine *engine,
+                                PeasPluginInfo *info,
+                                GType extension_type)
+{
+  PeasPluginLoader *loader;
+
+  g_return_val_if_fail (PEAS_IS_ENGINE (engine), FALSE);
+  g_return_val_if_fail (info != NULL, FALSE);
+
+  loader = get_plugin_loader (engine, info);
+  return peas_plugin_loader_provides_extension (loader, info, extension_type);
+}
+
 PeasExtension *
 peas_engine_get_extension (PeasEngine *engine,
                            PeasPluginInfo *info,
diff --git a/libpeas/peas-engine.h b/libpeas/peas-engine.h
index f828b7f..37b638c 100644
--- a/libpeas/peas-engine.h
+++ b/libpeas/peas-engine.h
@@ -92,6 +92,9 @@ gboolean          peas_engine_deactivate_plugin   (PeasEngine      *engine,
                                                    PeasPluginInfo  *info);
 void              peas_engine_garbage_collect     (PeasEngine      *engine);
 
+gboolean          peas_engine_provides_extension  (PeasEngine      *engine,
+                                                   PeasPluginInfo  *info,
+                                                   GType            ext_type);
 PeasExtension    *peas_engine_get_extension       (PeasEngine      *engine,
                                                    PeasPluginInfo  *info,
                                                    GType            ext_type);
diff --git a/libpeas/peas-plugin-loader.c b/libpeas/peas-plugin-loader.c
index 7e0cbb8..157036e 100644
--- a/libpeas/peas-plugin-loader.c
+++ b/libpeas/peas-plugin-loader.c
@@ -75,6 +75,21 @@ peas_plugin_loader_unload (PeasPluginLoader *loader,
   klass->unload (loader, info);
 }
 
+gboolean
+peas_plugin_loader_provides_extension (PeasPluginLoader *loader,
+                                       PeasPluginInfo   *info,
+                                       GType             ext_type)
+{
+  PeasPluginLoaderClass *klass;
+
+  g_return_val_if_fail (PEAS_IS_PLUGIN_LOADER (loader), FALSE);
+
+  klass = PEAS_PLUGIN_LOADER_GET_CLASS (loader);
+  g_return_val_if_fail (klass->provides_extension != NULL, FALSE);
+
+  return klass->provides_extension (loader, info, ext_type);
+}
+
 PeasExtension *
 peas_plugin_loader_get_extension (PeasPluginLoader *loader,
                                   PeasPluginInfo   *info,
diff --git a/libpeas/peas-plugin-loader.h b/libpeas/peas-plugin-loader.h
index 38c7b14..d7c1e01 100644
--- a/libpeas/peas-plugin-loader.h
+++ b/libpeas/peas-plugin-loader.h
@@ -54,6 +54,9 @@ struct _PeasPluginLoaderClass {
                                            PeasPluginInfo   *info);
   void          (*unload)                 (PeasPluginLoader *loader,
                                            PeasPluginInfo   *info);
+  gboolean       (*provides_extension)    (PeasPluginLoader *loader,
+                                           PeasPluginInfo   *info,
+                                           GType             ext_type);
   PeasExtension *(*get_extension)         (PeasPluginLoader *loader,
                                            PeasPluginInfo   *info,
                                            GType             ext_type);
@@ -70,6 +73,10 @@ PeasPlugin   *peas_plugin_loader_load                 (PeasPluginLoader *loader,
                                                        PeasPluginInfo   *info);
 void          peas_plugin_loader_unload               (PeasPluginLoader *loader,
                                                        PeasPluginInfo   *info);
+
+gboolean      peas_plugin_loader_provides_extension   (PeasPluginLoader *loader,
+                                                       PeasPluginInfo   *info,
+                                                       GType             ext_type);
 PeasExtension *peas_plugin_loader_get_extension       (PeasPluginLoader *loader,
                                                        PeasPluginInfo   *info,
                                                        GType             ext_type);
diff --git a/libpeasui/peas-ui-plugin-info.c b/libpeasui/peas-ui-plugin-info.c
index 1f5701b..bcf0050 100644
--- a/libpeasui/peas-ui-plugin-info.c
+++ b/libpeasui/peas-ui-plugin-info.c
@@ -36,30 +36,3 @@ peas_ui_plugin_info_get_icon_name (PeasPluginInfo *info)
   else
     return "libpeas-plugin";
 }
-
-/**
- * peas_ui_plugin_info_is_configurable:
- * @info: A #PeasPluginInfo
- *
- * Check if the plugin is configurable, given its #PeasPluginInfo.
- *
- * This function takes a #PeasPluginInfo as its argument and proxies the
- * is_configurable() method call to the #PeasPlugin, handling type checks and
- * casts for us. Calling this function on a #PeasPlugin which doesn't
- * implement #PeasUIConfigurable won't generate an error.
- *
- * Returns: %TRUE if the plugin is configurable.
- */
-gboolean
-peas_ui_plugin_info_is_configurable (PeasPluginInfo *info)
-{
-  g_return_val_if_fail (info != NULL, FALSE);
-
-  if (!peas_plugin_info_is_active (info))
-    return FALSE;
-
-  if (!PEAS_UI_IS_CONFIGURABLE (info->plugin))
-    return FALSE;
-
-  return peas_ui_configurable_is_configurable (PEAS_UI_CONFIGURABLE (info->plugin));
-}
diff --git a/libpeasui/peas-ui-plugin-info.h b/libpeasui/peas-ui-plugin-info.h
index 093f172..edac295 100644
--- a/libpeasui/peas-ui-plugin-info.h
+++ b/libpeasui/peas-ui-plugin-info.h
@@ -28,8 +28,6 @@
 G_BEGIN_DECLS
 
 const gchar  *peas_ui_plugin_info_get_icon_name            (PeasPluginInfo *info);
-gboolean      peas_ui_plugin_info_is_configurable          (PeasPluginInfo *info);
-GtkWidget    *peas_ui_plugin_info_create_configure_dialog  (PeasPluginInfo *info);
 
 G_END_DECLS
 
diff --git a/libpeasui/peas-ui-plugin-manager.c b/libpeasui/peas-ui-plugin-manager.c
index a8fecac..9b57500 100644
--- a/libpeasui/peas-ui-plugin-manager.c
+++ b/libpeasui/peas-ui-plugin-manager.c
@@ -85,6 +85,15 @@ static void             plugin_manager_toggle_active        (PeasUIPluginManager
 static void             peas_ui_plugin_manager_constructed  (GObject             *object);
 static void             peas_ui_plugin_manager_finalize     (GObject             *object);
 
+static gboolean
+plugin_is_configurable (PeasUIPluginManager *pm,
+                        PeasPluginInfo      *info)
+{
+  return peas_engine_provides_extension (pm->priv->engine,
+                                         info,
+                                         PEAS_UI_TYPE_CONFIGURABLE);
+}
+
 static void
 peas_ui_plugin_manager_set_property (GObject      *object,
                                      guint         prop_id,
@@ -311,7 +320,7 @@ cursor_changed_cb (GtkTreeView *view,
   gtk_widget_set_sensitive (GTK_WIDGET (pm->priv->about_button),
                             info != NULL);
   gtk_widget_set_sensitive (GTK_WIDGET (pm->priv->configure_button),
-                            info != NULL && peas_ui_plugin_info_is_configurable (info));
+                            info != NULL && plugin_is_configurable (pm, info));
 }
 
 static void
@@ -379,7 +388,7 @@ plugin_manager_populate_lists (PeasUIPluginManager *pm)
                           INFO_COLUMN, &info, -1);
 
       gtk_widget_set_sensitive (GTK_WIDGET (pm->priv->configure_button),
-                                peas_ui_plugin_info_is_configurable (info));
+                                plugin_is_configurable (pm, info));
     }
 }
 
@@ -559,7 +568,7 @@ create_tree_popup_menu (PeasUIPluginManager *pm)
                                     GTK_ICON_SIZE_MENU);
   gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
   g_signal_connect (item, "activate", G_CALLBACK (configure_button_cb), pm);
-  gtk_widget_set_sensitive (item, peas_ui_plugin_info_is_configurable (info));
+  gtk_widget_set_sensitive (item, plugin_is_configurable (pm, info));
   gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
 
   item = gtk_check_menu_item_new_with_mnemonic (_("A_ctivate"));
diff --git a/loaders/c/peas-plugin-loader-c.c b/loaders/c/peas-plugin-loader-c.c
index 5272b08..e9c31c8 100644
--- a/loaders/c/peas-plugin-loader-c.c
+++ b/loaders/c/peas-plugin-loader-c.c
@@ -102,19 +102,15 @@ peas_plugin_loader_c_load (PeasPluginLoader * loader,
   return result;
 }
 
-static PeasExtension *
-peas_plugin_loader_c_get_extension (PeasPluginLoader *loader,
-                                    PeasPluginInfo   *info,
-                                    GType             exten_type)
+static CreateFunc
+get_create_function (PeasPluginLoaderC *cloader,
+                     PeasPluginInfo    *info,
+                     GType              exten_type)
 {
-  PeasPluginLoaderC *cloader;
   PeasObjectModule *module;
   gchar *symbol_name;
   gpointer symbol;
   gboolean ret;
-  gpointer instance;
-
-  cloader = PEAS_PLUGIN_LOADER_C (loader);
 
   module = (PeasObjectModule *) g_hash_table_lookup (cloader->priv->loaded_plugins,
                                                      info);
@@ -124,10 +120,35 @@ peas_plugin_loader_c_get_extension (PeasPluginLoader *loader,
   ret = g_module_symbol (peas_object_module_get_library (module), symbol_name, &symbol);
   g_free (symbol_name);
 
-  if (!ret || !symbol)
+  if (!ret)
+    return NULL;
+  return (CreateFunc) symbol;
+}
+
+static gboolean
+peas_plugin_loader_c_provides_extension  (PeasPluginLoader *loader,
+                                          PeasPluginInfo   *info,
+                                          GType             exten_type)
+{
+  PeasPluginLoaderC *cloader = PEAS_PLUGIN_LOADER_C (loader);
+
+  return get_create_function (cloader, info, exten_type) != NULL;
+}
+
+static PeasExtension *
+peas_plugin_loader_c_get_extension (PeasPluginLoader *loader,
+                                    PeasPluginInfo   *info,
+                                    GType             exten_type)
+{
+  PeasPluginLoaderC *cloader = PEAS_PLUGIN_LOADER_C (loader);
+  CreateFunc create_func;
+  gpointer instance;
+
+  create_func = get_create_function (cloader, info, exten_type);
+  if (!create_func)
     return NULL;
 
-  instance = ((CreateFunc) symbol) ();
+  instance = create_func ();
 
   g_return_val_if_fail (instance != NULL, NULL);
   g_return_val_if_fail (G_IS_OBJECT (instance), NULL);
@@ -198,6 +219,7 @@ peas_plugin_loader_c_class_init (PeasPluginLoaderCClass *klass)
   loader_class->add_module_directory = peas_plugin_loader_c_add_module_directory;
   loader_class->load = peas_plugin_loader_c_load;
   loader_class->unload = peas_plugin_loader_c_unload;
+  loader_class->provides_extension = peas_plugin_loader_c_provides_extension;
   loader_class->get_extension = peas_plugin_loader_c_get_extension;
 
   g_type_class_add_private (object_class, sizeof (PeasPluginLoaderCPrivate));



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