[libpeas/proxys: 4/22] Use PeasExtension for PeasUIConfigurable in PeasUIPluginManager.



commit 5ff8d4d54f5f34aa898468dfc3d99838d2593b68
Author: Steve Frécinaux <code istique net>
Date:   Fri May 14 15:29:55 2010 +0200

    Use PeasExtension for PeasUIConfigurable in PeasUIPluginManager.
    
    Also check if the PeasPlugin has a reference to a PeasPluginInfo,
    because our current small hacks makes it possible for that ref to be
    NULL. (This ought to be fixed at some point!)

 libpeas/peas-plugin.c                              |    3 +-
 libpeasui/peas-ui-configurable.c                   |   14 ++++---
 libpeasui/peas-ui-configurable.h                   |    6 ++-
 libpeasui/peas-ui-plugin-info.c                    |   41 --------------------
 libpeasui/peas-ui-plugin-manager.c                 |   12 +++++-
 .../helloworld/peasdemo-hello-world-plugin.c       |   26 +++++++-----
 .../helloworld/peasdemo-hello-world-plugin.h       |    1 +
 7 files changed, 40 insertions(+), 63 deletions(-)
---
diff --git a/libpeas/peas-plugin.c b/libpeas/peas-plugin.c
index e91ee26..542b718 100644
--- a/libpeas/peas-plugin.c
+++ b/libpeas/peas-plugin.c
@@ -119,7 +119,8 @@ peas_plugin_finalize (GObject *object)
 {
   PeasPlugin *plugin = PEAS_PLUGIN (object);
 
-  _peas_plugin_info_unref (plugin->priv->info);
+  if (plugin->priv->info)
+    _peas_plugin_info_unref (plugin->priv->info);
 
   G_OBJECT_CLASS (peas_plugin_parent_class)->finalize (object);
 }
diff --git a/libpeasui/peas-ui-configurable.c b/libpeasui/peas-ui-configurable.c
index e2d60b9..9c3c2e0 100644
--- a/libpeasui/peas-ui-configurable.c
+++ b/libpeasui/peas-ui-configurable.c
@@ -82,25 +82,27 @@ peas_ui_configurable_is_configurable (PeasUIConfigurable *configurable)
 /**
  * peas_ui_configurable_create_configure_dialog:
  * @configurable: A #PeasUIConfigurable
+ * @conf_dlg: (out) A #GtkWindow used for configuration
  *
  * Creates the configure dialog widget for the plugin.
  *
  * The default implementation returns %NULL.
  *
- * Returns: The configure dialog widget for the plugin.
+ * Returns: %TRUE on success.
  */
-GtkWidget *
-peas_ui_configurable_create_configure_dialog (PeasUIConfigurable *configurable)
+gboolean
+peas_ui_configurable_create_configure_dialog (PeasUIConfigurable *configurable,
+                                              GtkWidget         **conf_dlg)
 {
   PeasUIConfigurableInterface *iface;
 
-  g_return_val_if_fail (PEAS_UI_IS_CONFIGURABLE (configurable), NULL);
+  g_return_val_if_fail (PEAS_UI_IS_CONFIGURABLE (configurable), FALSE);
   
   iface = PEAS_UI_CONFIGURABLE_GET_IFACE (configurable);
 
   if (G_LIKELY (iface->create_configure_dialog != NULL))
-    return iface->create_configure_dialog (configurable);
+    return iface->create_configure_dialog (configurable, conf_dlg);
 
   /* Default implementation */
-  return NULL;
+  return FALSE;
 }
diff --git a/libpeasui/peas-ui-configurable.h b/libpeasui/peas-ui-configurable.h
index 711b3f4..8a8821b 100644
--- a/libpeasui/peas-ui-configurable.h
+++ b/libpeasui/peas-ui-configurable.h
@@ -42,7 +42,8 @@ struct _PeasUIConfigurableInterface
 {
   GTypeInterface g_iface;
 
-  GtkWidget  *(*create_configure_dialog)  (PeasUIConfigurable *configurable);
+  gboolean    (*create_configure_dialog)  (PeasUIConfigurable *configurable,
+                                           GtkWidget         **conf_dlg);
 
   /* Plugins should usually not override this, it's handled automatically
    * by the PeasPluginClass */
@@ -51,7 +52,8 @@ struct _PeasUIConfigurableInterface
 
 GType       peas_ui_configurable_get_type                (void);
 gboolean    peas_ui_configurable_is_configurable         (PeasUIConfigurable *configurable);
-GtkWidget  *peas_ui_configurable_create_configure_dialog (PeasUIConfigurable *configurable);
+gboolean    peas_ui_configurable_create_configure_dialog (PeasUIConfigurable *configurable,
+                                                          GtkWidget         **conf_dlg);
 
 G_END_DECLS
 
diff --git a/libpeasui/peas-ui-plugin-info.c b/libpeasui/peas-ui-plugin-info.c
index 53c3378..1f5701b 100644
--- a/libpeasui/peas-ui-plugin-info.c
+++ b/libpeasui/peas-ui-plugin-info.c
@@ -63,44 +63,3 @@ peas_ui_plugin_info_is_configurable (PeasPluginInfo *info)
 
   return peas_ui_configurable_is_configurable (PEAS_UI_CONFIGURABLE (info->plugin));
 }
-
-/**
- * peas_ui_plugin_info_create_configure_dialog:
- * @info: A #PeasPluginInfo
- *
- * Creates the configure dialog widget for the plugin, 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: a #GtkWindow instance.
- */
-GtkWidget *
-peas_ui_plugin_info_create_configure_dialog (PeasPluginInfo *info)
-{
-  PeasUIConfigurable *configurable;
-  GtkWidget *dialog;
-
-  /* Obligatory checks. */
-  g_return_val_if_fail (info != NULL, NULL);
-
-  if (!peas_plugin_info_is_active (info))
-    return NULL;
-
-  if (!PEAS_UI_IS_CONFIGURABLE (info->plugin))
-    return NULL;
-
-  configurable = PEAS_UI_CONFIGURABLE (info->plugin);
-  dialog = peas_ui_configurable_create_configure_dialog (configurable);
-  
-  if (dialog != NULL && !GTK_IS_WINDOW (dialog)) {
-    g_object_unref (dialog);
-    dialog = NULL;
-    g_return_val_if_reached (NULL);
-  }
-
-  return dialog;
-}
diff --git a/libpeasui/peas-ui-plugin-manager.c b/libpeasui/peas-ui-plugin-manager.c
index b968f0c..a8fecac 100644
--- a/libpeasui/peas-ui-plugin-manager.c
+++ b/libpeasui/peas-ui-plugin-manager.c
@@ -33,6 +33,7 @@
 
 #include "peas-ui-plugin-manager.h"
 #include "peas-ui-plugin-info.h"
+#include "peas-ui-configurable.h"
 
 /**
  * SECTION:peas-ui-plugin-manager
@@ -190,14 +191,21 @@ configure_button_cb (GtkWidget           *button,
                      PeasUIPluginManager *pm)
 {
   PeasPluginInfo *info;
+  PeasExtension *exten;
   GtkWindow *toplevel;
-  GtkWidget *conf_dlg;
+  GtkWidget *conf_dlg = NULL;
   GtkWindowGroup *wg;
 
   info = plugin_manager_get_selected_plugin (pm);
   g_return_if_fail (info != NULL);
 
-  conf_dlg = peas_ui_plugin_info_create_configure_dialog (info);
+  exten = peas_engine_get_extension (pm->priv->engine, info, PEAS_UI_TYPE_CONFIGURABLE); 
+  g_return_if_fail (exten != NULL);
+
+  g_debug ("Calling create_configure_dialog on %p", exten);
+
+  peas_extension_call (exten, "create_configure_dialog", &conf_dlg);
+  g_object_unref (exten);
   g_return_if_fail (conf_dlg != NULL);
 
   toplevel = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (pm)));
diff --git a/peas-demo/plugins/helloworld/peasdemo-hello-world-plugin.c b/peas-demo/plugins/helloworld/peasdemo-hello-world-plugin.c
index 3c41dfd..bfbda88 100644
--- a/peas-demo/plugins/helloworld/peasdemo-hello-world-plugin.c
+++ b/peas-demo/plugins/helloworld/peasdemo-hello-world-plugin.c
@@ -109,22 +109,21 @@ on_configure_dialog_response (GtkDialog *dialog,
   gtk_widget_destroy (GTK_WIDGET (dialog));
 }
 
-static GtkWidget *
-peasdemo_hello_world_plugin_create_configure_dialog (PeasUIConfigurable *configurable)
+static gboolean
+peasdemo_hello_world_plugin_create_configure_dialog (PeasUIConfigurable *configurable,
+                                                     GtkWidget         **dialog)
 {
-  GtkWidget *dialog;
-
   g_debug (G_STRFUNC);
 
-  dialog = gtk_message_dialog_new (NULL,
-                                   0,
-                                   GTK_MESSAGE_INFO,
-                                   GTK_BUTTONS_OK,
-                                   "This is a configuration dialog for the HelloWorld plugin.");
-  g_signal_connect (dialog, "response",
+  *dialog = gtk_message_dialog_new (NULL,
+                                    0,
+                                    GTK_MESSAGE_INFO,
+                                    GTK_BUTTONS_OK,
+                                    "This is a configuration dialog for the HelloWorld plugin.");
+  g_signal_connect (*dialog, "response",
                     G_CALLBACK (on_configure_dialog_response), NULL);
 
-  return dialog;
+  return TRUE;
 }
 
 static void
@@ -158,3 +157,8 @@ register_peas_plugin (GTypeModule   *type_module)
         return g_object_new (PEASDEMO_TYPE_HELLO_WORLD_PLUGIN,
                              NULL);
 }
+
+G_MODULE_EXPORT GObject    *create_PeasUIConfigurable ()
+{
+  return g_object_new (PEASDEMO_TYPE_HELLO_WORLD_PLUGIN, NULL);
+}
diff --git a/peas-demo/plugins/helloworld/peasdemo-hello-world-plugin.h b/peas-demo/plugins/helloworld/peasdemo-hello-world-plugin.h
index e3f450f..482fd8b 100644
--- a/peas-demo/plugins/helloworld/peasdemo-hello-world-plugin.h
+++ b/peas-demo/plugins/helloworld/peasdemo-hello-world-plugin.h
@@ -28,6 +28,7 @@ struct _PeasDemoHelloWorldPluginClass {
 
 GType                       peasdemo_hello_world_plugin_get_type  (void) G_GNUC_CONST;
 G_MODULE_EXPORT GObject    *register_peas_plugin                  (GTypeModule *module);
+G_MODULE_EXPORT GObject    *create_PeasUIConfigurable ();
 
 G_END_DECLS
 



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