[libpeas] Added optional engine parameter back to libpeas-gtk API
- From: Steve Frécinaux <sfre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libpeas] Added optional engine parameter back to libpeas-gtk API
- Date: Sun, 13 Feb 2011 21:41:11 +0000 (UTC)
commit f875e35a412be9077d9ec3c13b8d7c9937eac842
Author: Garrett Regier <alias301 gmail com>
Date: Wed Feb 9 23:53:49 2011 -0800
Added optional engine parameter back to libpeas-gtk API
This is needed for multiple engines.
libpeas-gtk/peas-gtk-plugin-manager-store.c | 87 +++++++++++++++++++++++++-
libpeas-gtk/peas-gtk-plugin-manager-store.h | 2 +-
libpeas-gtk/peas-gtk-plugin-manager-view.c | 71 +++++++++++++++++-----
libpeas-gtk/peas-gtk-plugin-manager-view.h | 2 +-
libpeas-gtk/peas-gtk-plugin-manager.c | 71 ++++++++++++++++------
libpeas-gtk/peas-gtk-plugin-manager.h | 2 +-
peas-demo/peas-demo.c | 2 +-
tests/libpeas-gtk/plugin-manager-store.c | 2 +-
tests/libpeas-gtk/plugin-manager-view.c | 2 +-
tests/libpeas-gtk/plugin-manager.c | 2 +-
10 files changed, 198 insertions(+), 45 deletions(-)
---
diff --git a/libpeas-gtk/peas-gtk-plugin-manager-store.c b/libpeas-gtk/peas-gtk-plugin-manager-store.c
index 6be2436..025f5a6 100644
--- a/libpeas-gtk/peas-gtk-plugin-manager-store.c
+++ b/libpeas-gtk/peas-gtk-plugin-manager-store.c
@@ -51,6 +51,12 @@ struct _PeasGtkPluginManagerStorePrivate {
PeasEngine *engine;
};
+/* Properties */
+enum {
+ PROP_0,
+ PROP_ENGINE
+};
+
G_DEFINE_TYPE (PeasGtkPluginManagerStore, peas_gtk_plugin_manager_store, GTK_TYPE_LIST_STORE);
static void
@@ -192,9 +198,55 @@ peas_gtk_plugin_manager_store_init (PeasGtkPluginManagerStore *store)
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID,
GTK_SORT_ASCENDING);
+}
- /* Set up the engine synchronization */
- store->priv->engine = g_object_ref (peas_engine_get_default ());
+static void
+peas_gtk_plugin_manager_store_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ PeasGtkPluginManagerStore *store = PEAS_GTK_PLUGIN_MANAGER_STORE (object);
+
+ switch (prop_id)
+ {
+ case PROP_ENGINE:
+ store->priv->engine = g_value_get_object (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+peas_gtk_plugin_manager_store_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ PeasGtkPluginManagerStore *store = PEAS_GTK_PLUGIN_MANAGER_STORE (object);
+
+ switch (prop_id)
+ {
+ case PROP_ENGINE:
+ g_value_set_object (value, store->priv->engine);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+peas_gtk_plugin_manager_store_constructed (GObject *object)
+{
+ PeasGtkPluginManagerStore *store = PEAS_GTK_PLUGIN_MANAGER_STORE (object);
+
+ if (store->priv->engine == NULL)
+ store->priv->engine = peas_engine_get_default ();
+
+ g_object_ref (store->priv->engine);
g_signal_connect_after (store->priv->engine,
"load-plugin",
@@ -206,6 +258,9 @@ peas_gtk_plugin_manager_store_init (PeasGtkPluginManagerStore *store)
store);
peas_gtk_plugin_manager_store_reload (store);
+
+ if (G_OBJECT_CLASS (peas_gtk_plugin_manager_store_parent_class)->constructed != NULL)
+ G_OBJECT_CLASS (peas_gtk_plugin_manager_store_parent_class)->constructed (object);
}
static void
@@ -231,22 +286,46 @@ peas_gtk_plugin_manager_store_class_init (PeasGtkPluginManagerStoreClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ object_class->set_property = peas_gtk_plugin_manager_store_set_property;
+ object_class->get_property = peas_gtk_plugin_manager_store_get_property;
+ object_class->constructed = peas_gtk_plugin_manager_store_constructed;
object_class->dispose = peas_gtk_plugin_manager_store_dispose;
+ /*
+ * PeasGtkPLuginManagerStore:engine:
+ *
+ * The #PeasEngine this store is attached to.
+ */
+ g_object_class_install_property (object_class,
+ PROP_ENGINE,
+ g_param_spec_object ("engine",
+ "engine",
+ "The PeasEngine this store is attached to",
+ PEAS_TYPE_ENGINE,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
+
g_type_class_add_private (object_class, sizeof (PeasGtkPluginManagerStorePrivate));
}
/*
* peas_gtk_plugin_manager_store_new:
+ * @engine: (allow-none): A #PeasEngine, or %NULL.
+ *
+ * Creates a new plugin manager store for the given #PeasEngine.
*
- * Creates a new plugin manager store.
+ * If @engine is %NULL, then the default engine will be used.
*
* Returns: the new #PeasGtkPluginManagerStore.
*/
PeasGtkPluginManagerStore *
-peas_gtk_plugin_manager_store_new (void)
+peas_gtk_plugin_manager_store_new (PeasEngine *engine)
{
+ g_return_val_if_fail (engine == NULL || PEAS_IS_ENGINE (engine), NULL);
+
return PEAS_GTK_PLUGIN_MANAGER_STORE (g_object_new (PEAS_GTK_TYPE_PLUGIN_MANAGER_STORE,
+ "engine", engine,
NULL));
}
diff --git a/libpeas-gtk/peas-gtk-plugin-manager-store.h b/libpeas-gtk/peas-gtk-plugin-manager-store.h
index 587686a..11b1638 100644
--- a/libpeas-gtk/peas-gtk-plugin-manager-store.h
+++ b/libpeas-gtk/peas-gtk-plugin-manager-store.h
@@ -69,7 +69,7 @@ struct _PeasGtkPluginManagerStoreClass {
};
GType peas_gtk_plugin_manager_store_get_type (void) G_GNUC_CONST;
-PeasGtkPluginManagerStore *peas_gtk_plugin_manager_store_new (void);
+PeasGtkPluginManagerStore *peas_gtk_plugin_manager_store_new (PeasEngine *engine);
void peas_gtk_plugin_manager_store_reload (PeasGtkPluginManagerStore *store);
diff --git a/libpeas-gtk/peas-gtk-plugin-manager-view.c b/libpeas-gtk/peas-gtk-plugin-manager-view.c
index a7afa90..2209591 100644
--- a/libpeas-gtk/peas-gtk-plugin-manager-view.c
+++ b/libpeas-gtk/peas-gtk-plugin-manager-view.c
@@ -63,6 +63,7 @@ struct _PeasGtkPluginManagerViewPrivate {
/* Properties */
enum {
PROP_0,
+ PROP_ENGINE,
PROP_SHOW_BUILTIN
};
@@ -447,15 +448,6 @@ peas_gtk_plugin_manager_view_init (PeasGtkPluginManagerView *view)
PEAS_GTK_TYPE_PLUGIN_MANAGER_VIEW,
PeasGtkPluginManagerViewPrivate);
- view->priv->store = peas_gtk_plugin_manager_store_new ();
- view->priv->engine = g_object_ref (peas_engine_get_default ());
- g_signal_connect (view->priv->engine,
- "notify::plugin-list",
- G_CALLBACK (plugin_list_changed_cb),
- view);
-
- gtk_widget_set_has_tooltip (GTK_WIDGET (view), TRUE);
-
gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (view), TRUE);
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (view), FALSE);
@@ -510,10 +502,6 @@ peas_gtk_plugin_manager_view_init (PeasGtkPluginManagerView *view)
(GtkTreeViewSearchEqualFunc) name_search_cb,
view,
NULL);
-
- /* Properly set the model */
- view->priv->show_builtin = TRUE;
- peas_gtk_plugin_manager_view_set_show_builtin (view, FALSE);
}
static gboolean
@@ -619,6 +607,9 @@ peas_gtk_plugin_manager_view_set_property (GObject *object,
switch (prop_id)
{
+ case PROP_ENGINE:
+ view->priv->engine = g_value_get_object (value);
+ break;
case PROP_SHOW_BUILTIN:
peas_gtk_plugin_manager_view_set_show_builtin (view,
g_value_get_boolean (value));
@@ -639,6 +630,9 @@ peas_gtk_plugin_manager_view_get_property (GObject *object,
switch (prop_id)
{
+ case PROP_ENGINE:
+ g_value_set_object (value, view->priv->engine);
+ break;
case PROP_SHOW_BUILTIN:
g_value_set_boolean (value,
peas_gtk_plugin_manager_view_get_show_builtin (view));
@@ -650,6 +644,31 @@ peas_gtk_plugin_manager_view_get_property (GObject *object,
}
static void
+peas_gtk_plugin_manager_view_constructed (GObject *object)
+{
+ PeasGtkPluginManagerView *view = PEAS_GTK_PLUGIN_MANAGER_VIEW (object);
+
+ if (view->priv->engine == NULL)
+ view->priv->engine = peas_engine_get_default ();
+
+ g_object_ref (view->priv->engine);
+
+ view->priv->store = peas_gtk_plugin_manager_store_new (view->priv->engine);
+
+ /* Properly set the model */
+ view->priv->show_builtin = TRUE;
+ peas_gtk_plugin_manager_view_set_show_builtin (view, FALSE);
+
+ g_signal_connect (view->priv->engine,
+ "notify::plugin-list",
+ G_CALLBACK (plugin_list_changed_cb),
+ view);
+
+ if (G_OBJECT_CLASS (peas_gtk_plugin_manager_view_parent_class)->constructed != NULL)
+ G_OBJECT_CLASS (peas_gtk_plugin_manager_view_parent_class)->constructed (object);
+}
+
+static void
peas_gtk_plugin_manager_view_dispose (GObject *object)
{
PeasGtkPluginManagerView *view = PEAS_GTK_PLUGIN_MANAGER_VIEW (object);
@@ -689,6 +708,7 @@ peas_gtk_plugin_manager_view_class_init (PeasGtkPluginManagerViewClass *klass)
object_class->set_property = peas_gtk_plugin_manager_view_set_property;
object_class->get_property = peas_gtk_plugin_manager_view_get_property;
+ object_class->constructed = peas_gtk_plugin_manager_view_constructed;
object_class->dispose = peas_gtk_plugin_manager_view_dispose;
widget_class->button_press_event = peas_gtk_plugin_manager_view_button_press_event;
@@ -698,6 +718,21 @@ peas_gtk_plugin_manager_view_class_init (PeasGtkPluginManagerViewClass *klass)
tree_view_class->row_activated = peas_gtk_plugin_manager_view_row_activated;
/**
+ * PeasGtkPLuginManagerView:engine:
+ *
+ * The #PeasEngine this view is attached to.
+ */
+ g_object_class_install_property (object_class,
+ PROP_ENGINE,
+ g_param_spec_object ("engine",
+ "engine",
+ "The PeasEngine this view is attached to",
+ PEAS_TYPE_ENGINE,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
+
+ /**
* PeasGtkPluginManagerView:show-builtin:
*
* If builtin plugins should be shown.
@@ -736,15 +771,21 @@ peas_gtk_plugin_manager_view_class_init (PeasGtkPluginManagerViewClass *klass)
/**
* peas_gtk_plugin_manager_view_new:
+ * @engine: (allow-none): A #PeasEngine, or %NULL.
*
- * Creates a new plugin manager view.
+ * Creates a new plugin manager view for the given #PeasEngine.
+ *
+ * If @engine is %NULL, then the default engine will be used.
*
* Returns: the new #PeasGtkPluginManagerView.
*/
GtkWidget *
-peas_gtk_plugin_manager_view_new (void)
+peas_gtk_plugin_manager_view_new (PeasEngine *engine)
{
+ g_return_val_if_fail (engine == NULL || PEAS_IS_ENGINE (engine), NULL);
+
return GTK_WIDGET (g_object_new (PEAS_GTK_TYPE_PLUGIN_MANAGER_VIEW,
+ "engine", engine,
NULL));
}
diff --git a/libpeas-gtk/peas-gtk-plugin-manager-view.h b/libpeas-gtk/peas-gtk-plugin-manager-view.h
index 3345ca1..1ce9d1a 100644
--- a/libpeas-gtk/peas-gtk-plugin-manager-view.h
+++ b/libpeas-gtk/peas-gtk-plugin-manager-view.h
@@ -61,7 +61,7 @@ struct _PeasGtkPluginManagerViewClass {
};
GType peas_gtk_plugin_manager_view_get_type (void) G_GNUC_CONST;
-GtkWidget *peas_gtk_plugin_manager_view_new (void);
+GtkWidget *peas_gtk_plugin_manager_view_new (PeasEngine *engine);
void peas_gtk_plugin_manager_view_set_show_builtin (PeasGtkPluginManagerView *view,
gboolean show_builtin);
diff --git a/libpeas-gtk/peas-gtk-plugin-manager.c b/libpeas-gtk/peas-gtk-plugin-manager.c
index 4a4d578..7e4ce8e 100644
--- a/libpeas-gtk/peas-gtk-plugin-manager.c
+++ b/libpeas-gtk/peas-gtk-plugin-manager.c
@@ -72,6 +72,7 @@ struct _PeasGtkPluginManagerPrivate {
/* Properties */
enum {
PROP_0,
+ PROP_ENGINE,
PROP_VIEW
};
@@ -372,9 +373,6 @@ peas_gtk_plugin_manager_init (PeasGtkPluginManager *pm)
g_irepository_require (g_irepository_get_default (),
"PeasGtk", "1.0", 0, NULL);
- /* Let's initialize the widgets of the plugin manager now. */
- pm->priv->engine = g_object_ref (peas_engine_get_default ());
-
gtk_box_set_spacing (GTK_BOX (pm), 6);
gtk_widget_push_composite_child ();
@@ -416,15 +414,6 @@ peas_gtk_plugin_manager_init (PeasGtkPluginManager *pm)
"clicked",
G_CALLBACK (show_configure_cb),
pm);
-
- g_signal_connect_after (pm->priv->engine,
- "load-plugin",
- G_CALLBACK (plugin_loaded_toggled_cb),
- pm);
- g_signal_connect_after (pm->priv->engine,
- "unload-plugin",
- G_CALLBACK (plugin_loaded_toggled_cb),
- pm);
}
static void
@@ -437,6 +426,9 @@ peas_gtk_plugin_manager_set_property (GObject *object,
switch (prop_id)
{
+ case PROP_ENGINE:
+ pm->priv->engine = g_value_get_object (value);
+ break;
case PROP_VIEW:
pm->priv->view = g_value_get_object (value);
break;
@@ -456,6 +448,9 @@ peas_gtk_plugin_manager_get_property (GObject *object,
switch (prop_id)
{
+ case PROP_ENGINE:
+ g_value_set_object (value, pm->priv->engine);
+ break;
case PROP_VIEW:
g_value_set_object (value, peas_gtk_plugin_manager_get_view (pm));
break;
@@ -471,17 +466,23 @@ peas_gtk_plugin_manager_constructed (GObject *object)
PeasGtkPluginManager *pm = PEAS_GTK_PLUGIN_MANAGER (object);
GtkTreeSelection *selection;
+ if (pm->priv->engine == NULL)
+ pm->priv->engine = peas_engine_get_default ();
+
+ g_object_ref (pm->priv->engine);
+
+ /* When we create the manager, we always rescan the plugins directory
+ * Must come after the view has connected to notify::plugin-list
+ */
+ peas_engine_rescan_plugins (pm->priv->engine);
+
if (pm->priv->view == NULL)
- pm->priv->view = peas_gtk_plugin_manager_view_new ();
+ pm->priv->view = peas_gtk_plugin_manager_view_new (pm->priv->engine);
gtk_widget_push_composite_child ();
gtk_container_add (GTK_CONTAINER (pm->priv->sw), pm->priv->view);
gtk_widget_pop_composite_child ();
- /* When we create the manager, we always rescan the plugins directory
- Must come after the view has connected to notify::plugin-list */
- peas_engine_rescan_plugins (pm->priv->engine);
-
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (pm->priv->view));
g_signal_connect_swapped (selection,
@@ -496,9 +497,20 @@ peas_gtk_plugin_manager_constructed (GObject *object)
"populate-popup",
G_CALLBACK (populate_popup_cb),
pm);
+ g_signal_connect_after (pm->priv->engine,
+ "load-plugin",
+ G_CALLBACK (plugin_loaded_toggled_cb),
+ pm);
+ g_signal_connect_after (pm->priv->engine,
+ "unload-plugin",
+ G_CALLBACK (plugin_loaded_toggled_cb),
+ pm);
/* Update the button sensitivity */
selection_changed_cb (pm);
+
+ if (G_OBJECT_CLASS (peas_gtk_plugin_manager_parent_class)->constructed != NULL)
+ G_OBJECT_CLASS (peas_gtk_plugin_manager_parent_class)->constructed (object);
}
static void
@@ -530,6 +542,21 @@ peas_gtk_plugin_manager_class_init (PeasGtkPluginManagerClass *klass)
object_class->dispose = peas_gtk_plugin_manager_dispose;
/**
+ * PeasGtkPluginManager:engine:
+ *
+ * The #PeasEngine this manager is attached to.
+ */
+ g_object_class_install_property (object_class,
+ PROP_ENGINE,
+ g_param_spec_object ("engine",
+ "engine",
+ "The PeasEngine this manager is attached to",
+ PEAS_TYPE_ENGINE,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
+
+ /**
* PeasGtkPluginManager:view:
*
* The #PeasGtkPluginManagerView shown in the #PeasGtkPluginManager.
@@ -549,15 +576,21 @@ peas_gtk_plugin_manager_class_init (PeasGtkPluginManagerClass *klass)
/**
* peas_gtk_plugin_manager_new:
+ * @engine: (allow-none): A #PeasEngine, or %NULL.
*
- * Creates a new plugin manager.
+ * Creates a new plugin manager for the given #PeasEngine.
+ *
+ * If @engine is %NULL, then the default engine will be used.
*
* Returns: the new #PeasGtkPluginManager.
*/
GtkWidget *
-peas_gtk_plugin_manager_new (void)
+peas_gtk_plugin_manager_new (PeasEngine *engine)
{
+ g_return_val_if_fail (engine == NULL || PEAS_IS_ENGINE (engine), NULL);
+
return GTK_WIDGET (g_object_new (PEAS_GTK_TYPE_PLUGIN_MANAGER,
+ "engine", engine,
NULL));
}
diff --git a/libpeas-gtk/peas-gtk-plugin-manager.h b/libpeas-gtk/peas-gtk-plugin-manager.h
index 33f21e2..a5bf89c 100644
--- a/libpeas-gtk/peas-gtk-plugin-manager.h
+++ b/libpeas-gtk/peas-gtk-plugin-manager.h
@@ -57,7 +57,7 @@ struct _PeasGtkPluginManagerClass
};
GType peas_gtk_plugin_manager_get_type (void) G_GNUC_CONST;
-GtkWidget *peas_gtk_plugin_manager_new (void);
+GtkWidget *peas_gtk_plugin_manager_new (PeasEngine *engine);
GtkWidget *peas_gtk_plugin_manager_get_view (PeasGtkPluginManager *pm);
diff --git a/peas-demo/peas-demo.c b/peas-demo/peas-demo.c
index 4f762f6..4c8ddca 100644
--- a/peas-demo/peas-demo.c
+++ b/peas-demo/peas-demo.c
@@ -70,7 +70,7 @@ create_main_window (void)
box = gtk_vbox_new (FALSE, 6);
gtk_container_add (GTK_CONTAINER (window), box);
- manager = peas_gtk_plugin_manager_new ();
+ manager = peas_gtk_plugin_manager_new (peas_engine_get_default ());
gtk_box_pack_start (GTK_BOX (box), manager, TRUE, TRUE, 0);
button_box = gtk_hbutton_box_new ();
diff --git a/tests/libpeas-gtk/plugin-manager-store.c b/tests/libpeas-gtk/plugin-manager-store.c
index 006bbed..e3f2a0b 100644
--- a/tests/libpeas-gtk/plugin-manager-store.c
+++ b/tests/libpeas-gtk/plugin-manager-store.c
@@ -66,7 +66,7 @@ test_setup (TestFixture *fixture,
gconstpointer data)
{
fixture->engine = testing_engine_new ();
- fixture->tree_view = GTK_TREE_VIEW (peas_gtk_plugin_manager_view_new ());
+ fixture->tree_view = GTK_TREE_VIEW (peas_gtk_plugin_manager_view_new (NULL));
fixture->view = PEAS_GTK_PLUGIN_MANAGER_VIEW (fixture->tree_view);
fixture->selection = gtk_tree_view_get_selection (fixture->tree_view);
diff --git a/tests/libpeas-gtk/plugin-manager-view.c b/tests/libpeas-gtk/plugin-manager-view.c
index 2c64bbd..3c99f80 100644
--- a/tests/libpeas-gtk/plugin-manager-view.c
+++ b/tests/libpeas-gtk/plugin-manager-view.c
@@ -64,7 +64,7 @@ test_setup (TestFixture *fixture,
gconstpointer data)
{
fixture->engine = testing_engine_new ();
- fixture->tree_view = GTK_TREE_VIEW (peas_gtk_plugin_manager_view_new ());
+ fixture->tree_view = GTK_TREE_VIEW (peas_gtk_plugin_manager_view_new (NULL));
fixture->view = PEAS_GTK_PLUGIN_MANAGER_VIEW (fixture->tree_view);
fixture->selection = gtk_tree_view_get_selection (fixture->tree_view);
diff --git a/tests/libpeas-gtk/plugin-manager.c b/tests/libpeas-gtk/plugin-manager.c
index 62aa246..0d3836f 100644
--- a/tests/libpeas-gtk/plugin-manager.c
+++ b/tests/libpeas-gtk/plugin-manager.c
@@ -69,7 +69,7 @@ test_setup (TestFixture *fixture,
fixture->engine = testing_engine_new ();
fixture->window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
- fixture->manager = PEAS_GTK_PLUGIN_MANAGER (peas_gtk_plugin_manager_new ());
+ fixture->manager = PEAS_GTK_PLUGIN_MANAGER (peas_gtk_plugin_manager_new (NULL));
fixture->view = PEAS_GTK_PLUGIN_MANAGER_VIEW (peas_gtk_plugin_manager_get_view (fixture->manager));
fixture->selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (fixture->view));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]