[libpeas] Change PeasActivatable to take the object as a construct property.
- From: Steve Frécinaux <sfre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libpeas] Change PeasActivatable to take the object as a construct property.
- Date: Tue, 27 Jul 2010 18:54:04 +0000 (UTC)
commit 1c6a2e3d98d89f376d4520d20dd32945cde68dfc
Author: Steve Frécinaux <code istique net>
Date: Fri Jul 16 00:11:10 2010 +0200
Change PeasActivatable to take the object as a construct property.
This makes it more explicit that a PeasActivatable instance is bound to
a single object. It makes the C plugin code a bit more tedious, but the
changes in the python and seed code are very tight.
The Seed plugin part depends on Seed bugfixes attached to bug 624560
and 624562.
https://bugzilla.gnome.org/show_bug.cgi?id=620057
libpeas/peas-activatable.c | 29 ++++----
libpeas/peas-activatable.h | 18 ++----
peas-demo/peas-demo-window.c | 10 ++-
.../helloworld/peasdemo-hello-world-plugin.c | 68 ++++++++++++++++----
.../helloworld/peasdemo-hello-world-plugin.h | 1 +
peas-demo/plugins/pythonhello/pythonhello.py | 12 ++-
peas-demo/plugins/seedhello/seedhello.js | 16 ++--
7 files changed, 97 insertions(+), 57 deletions(-)
---
diff --git a/libpeas/peas-activatable.c b/libpeas/peas-activatable.c
index 1df309d..c922b30 100644
--- a/libpeas/peas-activatable.c
+++ b/libpeas/peas-activatable.c
@@ -45,69 +45,68 @@ G_DEFINE_INTERFACE(PeasActivatable, peas_activatable, G_TYPE_OBJECT)
void
peas_activatable_default_init (PeasActivatableInterface *iface)
{
+ g_object_interface_install_property (iface,
+ g_param_spec_object ("object",
+ "Object",
+ "Object",
+ G_TYPE_OBJECT,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
}
/**
* peas_activatable_activate:
* @activatable: A #PeasActivatable.
- * @object: The #GObject on which the plugin should be activated.
*
* Activates the extension on the given object.
*/
void
-peas_activatable_activate (PeasActivatable *activatable,
- GObject *object)
+peas_activatable_activate (PeasActivatable *activatable)
{
PeasActivatableInterface *iface;
g_return_if_fail (PEAS_IS_ACTIVATABLE (activatable));
- g_return_if_fail (G_IS_OBJECT (object));
iface = PEAS_ACTIVATABLE_GET_IFACE (activatable);
if (iface->activate != NULL)
- iface->activate (activatable, object);
+ iface->activate (activatable);
}
/**
* peas_activatable_deactivate:
* @activatable: A #PeasActivatable.
- * @object: A #GObject.
*
* Deactivates the plugin on the given object.
*/
void
-peas_activatable_deactivate (PeasActivatable *activatable,
- GObject *object)
+peas_activatable_deactivate (PeasActivatable *activatable)
{
PeasActivatableInterface *iface;
g_return_if_fail (PEAS_IS_ACTIVATABLE (activatable));
- g_return_if_fail (G_IS_OBJECT (object));
iface = PEAS_ACTIVATABLE_GET_IFACE (activatable);
if (iface->deactivate != NULL)
- iface->deactivate (activatable, object);
+ iface->deactivate (activatable);
}
/**
* peas_activatable_update_state:
* @activatable: A #PeasActivatable.
- * @object: A #GObject.
*
* Triggers an update of the plugin's internal state to take into account
* state changes in the targetted object, due to a plugin or user action.
*/
void
-peas_activatable_update_state (PeasActivatable *activatable,
- GObject *object)
+peas_activatable_update_state (PeasActivatable *activatable)
{
PeasActivatableInterface *iface;
g_return_if_fail (PEAS_IS_ACTIVATABLE (activatable));
- g_return_if_fail (G_IS_OBJECT (object));
iface = PEAS_ACTIVATABLE_GET_IFACE (activatable);
if (iface->update_state != NULL)
- iface->update_state (activatable, object);
+ iface->update_state (activatable);
}
diff --git a/libpeas/peas-activatable.h b/libpeas/peas-activatable.h
index 58004e3..ba87c33 100644
--- a/libpeas/peas-activatable.h
+++ b/libpeas/peas-activatable.h
@@ -42,12 +42,9 @@ struct _PeasActivatableInterface {
GTypeInterface g_iface;
/* Virtual public methods */
- void (*activate) (PeasActivatable *activatable,
- GObject *object);
- void (*deactivate) (PeasActivatable *activatable,
- GObject *object);
- void (*update_state) (PeasActivatable *activatable,
- GObject *object);
+ void (*activate) (PeasActivatable *activatable);
+ void (*deactivate) (PeasActivatable *activatable);
+ void (*update_state) (PeasActivatable *activatable);
};
/*
@@ -55,12 +52,9 @@ struct _PeasActivatableInterface {
*/
GType peas_activatable_get_type (void) G_GNUC_CONST;
-void peas_activatable_activate (PeasActivatable *activatable,
- GObject *object);
-void peas_activatable_deactivate (PeasActivatable *activatable,
- GObject *object);
-void peas_activatable_update_state (PeasActivatable *activatable,
- GObject *object);
+void peas_activatable_activate (PeasActivatable *activatable);
+void peas_activatable_deactivate (PeasActivatable *activatable);
+void peas_activatable_update_state (PeasActivatable *activatable);
G_END_DECLS
diff --git a/peas-demo/peas-demo-window.c b/peas-demo/peas-demo-window.c
index f61debe..9efd57c 100644
--- a/peas-demo/peas-demo-window.c
+++ b/peas-demo/peas-demo-window.c
@@ -56,7 +56,7 @@ on_extension_removed (PeasExtensionSet *set,
PeasExtension *exten,
DemoWindow *dw)
{
- peas_extension_call (exten, "deactivate", dw);
+ peas_extension_call (exten, "deactivate");
}
static gboolean
@@ -65,7 +65,7 @@ on_delete_event (GtkWidget *window,
gpointer user_data)
{
DemoWindow *dw = DEMO_WINDOW (window);
- peas_extension_set_call (dw->exten_set, "deactivate", dw);
+ peas_extension_set_call (dw->exten_set, "deactivate");
return FALSE;
}
@@ -77,9 +77,11 @@ demo_window_set_data (DemoWindow *dw,
dw->engine = engine;
g_object_ref (dw->engine);
- dw->exten_set = peas_extension_set_new (engine, PEAS_TYPE_ACTIVATABLE, NULL);
+ dw->exten_set = peas_extension_set_new (engine, PEAS_TYPE_ACTIVATABLE,
+ "object", dw,
+ NULL);
- peas_extension_set_call (dw->exten_set, "activate", dw);
+ peas_extension_set_call (dw->exten_set, "activate");
g_signal_connect (dw->exten_set, "extension-added", G_CALLBACK (on_extension_added), dw);
g_signal_connect (dw->exten_set, "extension-removed", G_CALLBACK (on_extension_removed), dw);
diff --git a/peas-demo/plugins/helloworld/peasdemo-hello-world-plugin.c b/peas-demo/plugins/helloworld/peasdemo-hello-world-plugin.c
index 015e9b4..ca1e20d 100644
--- a/peas-demo/plugins/helloworld/peasdemo-hello-world-plugin.c
+++ b/peas-demo/plugins/helloworld/peasdemo-hello-world-plugin.c
@@ -18,6 +18,52 @@ G_DEFINE_DYNAMIC_TYPE_EXTENDED (PeasDemoHelloWorldPlugin,
G_IMPLEMENT_INTERFACE_DYNAMIC (PEAS_TYPE_ACTIVATABLE,
peas_activatable_iface_init))
+enum {
+ PROP_0,
+ PROP_OBJECT
+};
+
+static void
+peasdemo_hello_world_plugin_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ PeasDemoHelloWorldPlugin *plugin = PEASDEMO_HELLO_WORLD_PLUGIN (object);
+
+ switch (prop_id)
+ {
+ case PROP_OBJECT:
+ plugin->window = GTK_WIDGET (g_value_dup_object (value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+peasdemo_hello_world_plugin_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ PeasDemoHelloWorldPlugin *plugin = PEASDEMO_HELLO_WORLD_PLUGIN (object);
+
+ switch (prop_id)
+ {
+ case PROP_OBJECT:
+ g_value_set_object (value, plugin->window);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+
static void
peasdemo_hello_world_plugin_init (PeasDemoHelloWorldPlugin *plugin)
{
@@ -43,37 +89,27 @@ get_box (GtkWidget *window)
}
static void
-peasdemo_hello_world_plugin_activate (PeasActivatable *activatable,
- GObject *object)
+peasdemo_hello_world_plugin_activate (PeasActivatable *activatable)
{
PeasDemoHelloWorldPlugin *plugin = PEASDEMO_HELLO_WORLD_PLUGIN (activatable);
- GtkWidget *window;
GtkWidget *label;
g_debug (G_STRFUNC);
- g_return_if_fail (GTK_IS_WINDOW (object));
- window = GTK_WIDGET (object);
-
plugin->label = gtk_label_new ("Hello World!");
- gtk_box_pack_start (get_box (window), plugin->label, 1, 1, 0);
+ gtk_box_pack_start (get_box (plugin->window), plugin->label, 1, 1, 0);
gtk_widget_show (plugin->label);
g_object_ref (plugin->label);
}
static void
-peasdemo_hello_world_plugin_deactivate (PeasActivatable *activatable,
- GObject *object)
+peasdemo_hello_world_plugin_deactivate (PeasActivatable *activatable)
{
PeasDemoHelloWorldPlugin *plugin = PEASDEMO_HELLO_WORLD_PLUGIN (activatable);
- GtkWidget *window;
g_debug (G_STRFUNC);
- g_return_if_fail (GTK_IS_WINDOW (object));
- window = GTK_WIDGET (object);
-
- gtk_container_remove (GTK_CONTAINER (get_box (window)), plugin->label);
+ gtk_container_remove (GTK_CONTAINER (get_box (plugin->window)), plugin->label);
}
static void
@@ -81,7 +117,11 @@ peasdemo_hello_world_plugin_class_init (PeasDemoHelloWorldPluginClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ object_class->set_property = peasdemo_hello_world_plugin_set_property;
+ object_class->get_property = peasdemo_hello_world_plugin_get_property;
object_class->finalize = peasdemo_hello_world_plugin_finalize;
+
+ g_object_class_override_property (object_class, PROP_OBJECT, "object");
}
static void
diff --git a/peas-demo/plugins/helloworld/peasdemo-hello-world-plugin.h b/peas-demo/plugins/helloworld/peasdemo-hello-world-plugin.h
index 75cd4a5..70e5d12 100644
--- a/peas-demo/plugins/helloworld/peasdemo-hello-world-plugin.h
+++ b/peas-demo/plugins/helloworld/peasdemo-hello-world-plugin.h
@@ -19,6 +19,7 @@ typedef struct _PeasDemoHelloWorldPluginClass PeasDemoHelloWorldPluginClass;
struct _PeasDemoHelloWorldPlugin {
PeasExtensionBase parent_instance;
+ GtkWidget *window;
GtkWidget *label;
};
diff --git a/peas-demo/plugins/pythonhello/pythonhello.py b/peas-demo/plugins/pythonhello/pythonhello.py
index 4c02494..4827b78 100644
--- a/peas-demo/plugins/pythonhello/pythonhello.py
+++ b/peas-demo/plugins/pythonhello/pythonhello.py
@@ -11,20 +11,24 @@ LABEL_STRING="Python Says Hello!"
class PythonHelloPlugin(gobject.GObject, Peas.Activatable):
__gtype_name__ = 'PythonHelloPlugin'
- def do_activate(self, window):
+ object = gobject.property(type=gobject.GObject)
+
+ def do_activate(self):
+ window = self.object
print "PythonHelloPlugin.do_activate", repr(window)
window._pythonhello_label = Gtk.Label()
window._pythonhello_label.set_text(LABEL_STRING)
window._pythonhello_label.show()
window.get_child().pack_start(window._pythonhello_label, True, True, 0)
- def do_deactivate(self, window):
+ def do_deactivate(self):
+ window = self.object
print "PythonHelloPlugin.do_deactivate", repr(window)
window.get_child().remove(window._pythonhello_label)
window._pythonhello_label.destroy()
- def do_update_state(self, window):
- print "PythonHelloPlugin.do_update_state", repr(window)
+ def do_update_state(self):
+ print "PythonHelloPlugin.do_update_state", repr(self.object)
class PythonHelloConfigurable(gobject.GObject, PeasUI.Configurable):
__gtype_name__ = 'PythonHelloConfigurable'
diff --git a/peas-demo/plugins/seedhello/seedhello.js b/peas-demo/plugins/seedhello/seedhello.js
index 114309e..43c60ad 100644
--- a/peas-demo/plugins/seedhello/seedhello.js
+++ b/peas-demo/plugins/seedhello/seedhello.js
@@ -5,18 +5,18 @@ var LABEL_STRING = "Seed Says Hello Too!";
print("LABEL_STRING=" + LABEL_STRING);
activatable_extension = {
- activate: function(win) {
+ activate: function() {
print("SeedHelloPlugin.activate");
- win._seedhello_label = new Gtk.Label({ label: LABEL_STRING });
- win._seedhello_label.show();
- win.get_child().pack_start(win._seedhello_label);
+ this.object._seedhello_label = new Gtk.Label({ label: LABEL_STRING });
+ this.object._seedhello_label.show();
+ this.object.get_child().pack_start(this.object._seedhello_label);
},
- deactivate: function(win) {
+ deactivate: function() {
print("SeedHelloPlugin.deactivate");
- win.get_child().remove(win._seedhello_label);
- win._seedhello_label.destroy();
+ this.object.get_child().remove(this.object._seedhello_label);
+ this.object._seedhello_label.destroy();
},
- update_state: function(win) {
+ update_state: function() {
print("SeedHelloPlugin.update_state");
}
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]