[libpeas] peas-demo: Update the C plugin to match latest best practices.
- From: Steve Frécinaux <sfre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libpeas] peas-demo: Update the C plugin to match latest best practices.
- Date: Thu, 15 Jul 2010 23:04:12 +0000 (UTC)
commit cb8710176c07f2a379ee36d3220577e842a0a5ca
Author: Steve Frécinaux <code istique net>
Date: Fri Jul 16 00:41:26 2010 +0200
peas-demo: Update the C plugin to match latest best practices.
We want it to:
- use plugin private members instead of g_object_set_data().
- use a separate class for various extensions.
peas-demo/plugins/helloworld/Makefile.am | 6 +-
.../helloworld/peasdemo-hello-world-configurable.c | 54 +++++++++++++++
.../helloworld/peasdemo-hello-world-configurable.h | 32 +++++++++
.../helloworld/peasdemo-hello-world-plugin.c | 72 ++++---------------
.../helloworld/peasdemo-hello-world-plugin.h | 23 +++---
5 files changed, 117 insertions(+), 70 deletions(-)
---
diff --git a/peas-demo/plugins/helloworld/Makefile.am b/peas-demo/plugins/helloworld/Makefile.am
index 5140f90..9bde239 100644
--- a/peas-demo/plugins/helloworld/Makefile.am
+++ b/peas-demo/plugins/helloworld/Makefile.am
@@ -8,8 +8,10 @@ INCLUDES = \
plugin_LTLIBRARIES = libhelloworld.la
libhelloworld_la_SOURCES = \
- peasdemo-hello-world-plugin.h \
- peasdemo-hello-world-plugin.c
+ peasdemo-hello-world-plugin.h \
+ peasdemo-hello-world-plugin.c \
+ peasdemo-hello-world-configurable.h \
+ peasdemo-hello-world-configurable.c
libhelloworld_la_LDFLAGS = $(PLUGIN_LIBTOOL_FLAGS)
libhelloworld_la_LIBADD = $(PEAS_LIBS) $(PEASUI_LIBS)
diff --git a/peas-demo/plugins/helloworld/peasdemo-hello-world-configurable.c b/peas-demo/plugins/helloworld/peasdemo-hello-world-configurable.c
new file mode 100644
index 0000000..20ae458
--- /dev/null
+++ b/peas-demo/plugins/helloworld/peasdemo-hello-world-configurable.c
@@ -0,0 +1,54 @@
+#include <glib.h>
+#include <glib-object.h>
+#include <gmodule.h>
+#include <gtk/gtk.h>
+
+#include <libpeas/peas.h>
+#include <libpeasui/peas-ui.h>
+
+#include "peasdemo-hello-world-configurable.h"
+
+static void peas_ui_configurable_iface_init (PeasUIConfigurableInterface *iface);
+
+G_DEFINE_DYNAMIC_TYPE_EXTENDED (PeasDemoHelloWorldConfigurable,
+ peasdemo_hello_world_configurable,
+ PEAS_TYPE_EXTENSION_BASE,
+ 0,
+ G_IMPLEMENT_INTERFACE (PEAS_UI_TYPE_CONFIGURABLE,
+ peas_ui_configurable_iface_init))
+
+static void
+peasdemo_hello_world_configurable_init (PeasDemoHelloWorldConfigurable *plugin)
+{
+ g_debug (G_STRFUNC);
+}
+
+static GtkWidget *
+peasdemo_hello_world_configurable_create_configure_widget (PeasUIConfigurable *configurable)
+{
+ g_debug (G_STRFUNC);
+
+ return gtk_label_new ("This is a configuration dialog for the HelloWorld plugin.");
+}
+
+static void
+peasdemo_hello_world_configurable_class_init (PeasDemoHelloWorldConfigurableClass *klass)
+{
+}
+
+static void
+peas_ui_configurable_iface_init (PeasUIConfigurableInterface *iface)
+{
+ iface->create_configure_widget = peasdemo_hello_world_configurable_create_configure_widget;
+}
+
+static void
+peasdemo_hello_world_configurable_class_finalize (PeasDemoHelloWorldConfigurableClass *klass)
+{
+}
+
+void
+peasdemo_hello_world_configurable_register (GTypeModule *module)
+{
+ peasdemo_hello_world_configurable_register_type (module);
+}
diff --git a/peas-demo/plugins/helloworld/peasdemo-hello-world-configurable.h b/peas-demo/plugins/helloworld/peasdemo-hello-world-configurable.h
new file mode 100644
index 0000000..8ec942d
--- /dev/null
+++ b/peas-demo/plugins/helloworld/peasdemo-hello-world-configurable.h
@@ -0,0 +1,32 @@
+#ifndef __PEASDEMO_HELLO_WORLD_CONFIGURABLE_H__
+#define __PEASDEMO_HELLO_WORLD_CONFIGURABLE_H__
+
+#include <gtk/gtk.h>
+#include <libpeas/peas.h>
+
+G_BEGIN_DECLS
+
+#define PEASDEMO_TYPE_HELLO_WORLD_CONFIGURABLE (peasdemo_hello_world_configurable_get_type ())
+#define PEASDEMO_HELLO_WORLD_CONFIGURABLE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), PEASDEMO_TYPE_HELLO_WORLD_CONFIGURABLE, PeasDemoHelloWorldConfigurable))
+#define PEASDEMO_HELLO_WORLD_CONFIGURABLE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), PEASDEMO_TYPE_HELLO_WORLD_CONFIGURABLE, PeasDemoHelloWorldConfigurable))
+#define PEASDEMO_IS_HELLO_WORLD_CONFIGURABLE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), PEASDEMO_TYPE_HELLO_WORLD_CONFIGURABLE))
+#define PEASDEMO_IS_HELLO_WORLD_CONFIGURABLE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), PEASDEMO_TYPE_HELLO_WORLD_CONFIGURABLE))
+#define PEASDEMO_HELLO_WORLD_CONFIGURABLE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), PEASDEMO_TYPE_HELLO_WORLD_CONFIGURABLE, PeasDemoHelloWorldConfigurableClass))
+
+typedef struct _PeasDemoHelloWorldConfigurable PeasDemoHelloWorldConfigurable;
+typedef struct _PeasDemoHelloWorldConfigurableClass PeasDemoHelloWorldConfigurableClass;
+
+struct _PeasDemoHelloWorldConfigurable {
+ PeasExtensionBase parent;
+};
+
+struct _PeasDemoHelloWorldConfigurableClass {
+ PeasExtensionBaseClass parent_class;
+};
+
+GType peasdemo_hello_world_configurable_get_type (void) G_GNUC_CONST;
+void peasdemo_hello_world_configurable_register (GTypeModule *module);
+
+G_END_DECLS
+
+#endif /* __PeasDEMO_HELLO_WORLD_CONFIGURABLE_H__ */
diff --git a/peas-demo/plugins/helloworld/peasdemo-hello-world-plugin.c b/peas-demo/plugins/helloworld/peasdemo-hello-world-plugin.c
index 186f1b5..7687a72 100644
--- a/peas-demo/plugins/helloworld/peasdemo-hello-world-plugin.c
+++ b/peas-demo/plugins/helloworld/peasdemo-hello-world-plugin.c
@@ -7,24 +7,16 @@
#include <libpeasui/peas-ui.h>
#include "peasdemo-hello-world-plugin.h"
-
-#define WINDOW_DATA_KEY "PeasDemoHelloWorldPluginWindowData"
+#include "peasdemo-hello-world-configurable.h"
static void peas_activatable_iface_init (PeasActivatableInterface *iface);
-static void peas_ui_configurable_iface_init (PeasUIConfigurableInterface *iface);
G_DEFINE_DYNAMIC_TYPE_EXTENDED (PeasDemoHelloWorldPlugin,
peasdemo_hello_world_plugin,
PEAS_TYPE_EXTENSION_BASE,
0,
G_IMPLEMENT_INTERFACE (PEAS_TYPE_ACTIVATABLE,
- peas_activatable_iface_init)
- G_IMPLEMENT_INTERFACE (PEAS_UI_TYPE_CONFIGURABLE,
- peas_ui_configurable_iface_init))
-
-typedef struct {
- GtkWidget *label;
-} WindowData;
+ peas_activatable_iface_init))
static void
peasdemo_hello_world_plugin_init (PeasDemoHelloWorldPlugin *plugin)
@@ -35,19 +27,13 @@ peasdemo_hello_world_plugin_init (PeasDemoHelloWorldPlugin *plugin)
static void
peasdemo_hello_world_plugin_finalize (GObject *object)
{
- g_debug (G_STRFUNC);
-
- G_OBJECT_CLASS (peasdemo_hello_world_plugin_parent_class)->finalize (object);
-}
+ PeasDemoHelloWorldPlugin *plugin = PEASDEMO_HELLO_WORLD_PLUGIN (object);
-static void
-free_window_data (WindowData *data)
-{
g_debug (G_STRFUNC);
- g_return_if_fail (data != NULL);
- g_object_unref (data->label);
- g_free (data);
+ g_object_unref (plugin->label);
+
+ G_OBJECT_CLASS (peasdemo_hello_world_plugin_parent_class)->finalize (object);
}
static GtkBox *
@@ -60,57 +46,34 @@ static void
peasdemo_hello_world_plugin_activate (PeasActivatable *activatable,
GObject *object)
{
+ PeasDemoHelloWorldPlugin *plugin = PEASDEMO_HELLO_WORLD_PLUGIN (activatable);
GtkWidget *window;
GtkWidget *label;
- WindowData *data;
g_debug (G_STRFUNC);
g_return_if_fail (GTK_IS_WINDOW (object));
window = GTK_WIDGET (object);
- label = gtk_label_new ("Hello World!");
- gtk_box_pack_start (get_box (window), label, 1, 1, 0);
- gtk_widget_show (label);
-
- data = g_new0 (WindowData, 1);
-
- data->label = label;
- g_object_ref (label);
-
- g_object_set_data_full (G_OBJECT (window),
- WINDOW_DATA_KEY,
- data,
- (GDestroyNotify) free_window_data);
+ plugin->label = gtk_label_new ("Hello World!");
+ gtk_box_pack_start (get_box (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)
{
+ PeasDemoHelloWorldPlugin *plugin = PEASDEMO_HELLO_WORLD_PLUGIN (activatable);
GtkWidget *window;
- WindowData *data;
g_debug (G_STRFUNC);
g_return_if_fail (GTK_IS_WINDOW (object));
window = GTK_WIDGET (object);
- data = (WindowData *) g_object_get_data (G_OBJECT (window),
- WINDOW_DATA_KEY);
- g_return_if_fail (data != NULL);
-
- gtk_container_remove (GTK_CONTAINER (get_box (window)), data->label);
-
- g_object_set_data (G_OBJECT (window), WINDOW_DATA_KEY, NULL);
-}
-
-static GtkWidget *
-peasdemo_hello_world_plugin_create_configure_widget (PeasUIConfigurable *configurable)
-{
- g_debug (G_STRFUNC);
-
- return gtk_label_new ("This is a configuration dialog for the HelloWorld plugin.");
+ gtk_container_remove (GTK_CONTAINER (get_box (window)), plugin->label);
}
static void
@@ -129,12 +92,6 @@ peas_activatable_iface_init (PeasActivatableInterface *iface)
}
static void
-peas_ui_configurable_iface_init (PeasUIConfigurableInterface *iface)
-{
- iface->create_configure_widget = peasdemo_hello_world_plugin_create_configure_widget;
-}
-
-static void
peasdemo_hello_world_plugin_class_finalize (PeasDemoHelloWorldPluginClass *klass)
{
}
@@ -143,11 +100,12 @@ G_MODULE_EXPORT void
peas_register_types (PeasObjectModule *module)
{
peasdemo_hello_world_plugin_register_type (G_TYPE_MODULE (module));
+ peasdemo_hello_world_configurable_register (G_TYPE_MODULE (module));
peas_object_module_register_extension_type (module,
PEAS_TYPE_ACTIVATABLE,
PEASDEMO_TYPE_HELLO_WORLD_PLUGIN);
peas_object_module_register_extension_type (module,
PEAS_UI_TYPE_CONFIGURABLE,
- PEASDEMO_TYPE_HELLO_WORLD_PLUGIN);
+ PEASDEMO_TYPE_HELLO_WORLD_CONFIGURABLE);
}
diff --git a/peas-demo/plugins/helloworld/peasdemo-hello-world-plugin.h b/peas-demo/plugins/helloworld/peasdemo-hello-world-plugin.h
index 4148785..75cd4a5 100644
--- a/peas-demo/plugins/helloworld/peasdemo-hello-world-plugin.h
+++ b/peas-demo/plugins/helloworld/peasdemo-hello-world-plugin.h
@@ -1,32 +1,33 @@
-#ifndef __PeasDEMO_HELLO_WORLD_PLUGIN_H__
-#define __PeasDEMO_HELLO_WORLD_PLUGIN_H__
+#ifndef __PEASDEMO_HELLO_WORLD_PLUGIN_H__
+#define __PEASDEMO_HELLO_WORLD_PLUGIN_H__
-#include <glib.h>
-#include <glib-object.h>
+#include <gtk/gtk.h>
#include <libpeas/peas.h>
G_BEGIN_DECLS
#define PEASDEMO_TYPE_HELLO_WORLD_PLUGIN (peasdemo_hello_world_plugin_get_type ())
-#define PEASDEMO_HELLO_WORLD_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), PeasDEMO_TYPE_HELLO_WORLD_PLUGIN, PeasDemoHelloWorldPlugin))
-#define PEASDEMO_HELLO_WORLD_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), PeasDEMO_TYPE_HELLO_WORLD_PLUGIN, PeasDemoHelloWorldPlugin))
-#define PEASDEMO_IS_HELLO_WORLD_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), PeasDEMO_TYPE_HELLO_WORLD_PLUGIN))
-#define PEASDEMO_IS_HELLO_WORLD_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), PeasDEMO_TYPE_HELLO_WORLD_PLUGIN))
-#define PEASDEMO_HELLO_WORLD_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), PeasDEMO_TYPE_HELLO_WORLD_PLUGIN, PeasDemoHelloWorldPluginClass))
+#define PEASDEMO_HELLO_WORLD_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), PEASDEMO_TYPE_HELLO_WORLD_PLUGIN, PeasDemoHelloWorldPlugin))
+#define PEASDEMO_HELLO_WORLD_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), PEASDEMO_TYPE_HELLO_WORLD_PLUGIN, PeasDemoHelloWorldPlugin))
+#define PEASDEMO_IS_HELLO_WORLD_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), PEASDEMO_TYPE_HELLO_WORLD_PLUGIN))
+#define PEASDEMO_IS_HELLO_WORLD_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), PEASDEMO_TYPE_HELLO_WORLD_PLUGIN))
+#define PEASDEMO_HELLO_WORLD_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), PEASDEMO_TYPE_HELLO_WORLD_PLUGIN, PeasDemoHelloWorldPluginClass))
typedef struct _PeasDemoHelloWorldPlugin PeasDemoHelloWorldPlugin;
typedef struct _PeasDemoHelloWorldPluginClass PeasDemoHelloWorldPluginClass;
struct _PeasDemoHelloWorldPlugin {
PeasExtensionBase parent_instance;
+
+ GtkWidget *label;
};
struct _PeasDemoHelloWorldPluginClass {
PeasExtensionBaseClass parent_class;
};
-GType peasdemo_hello_world_plugin_get_type (void) G_GNUC_CONST;
-G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module);
+GType peasdemo_hello_world_plugin_get_type (void) G_GNUC_CONST;
+G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]