Skip to content

Instantly share code, notes, and snippets.

@ptomato
Created October 27, 2012 12:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ptomato/3964521 to your computer and use it in GitHub Desktop.
Save ptomato/3964521 to your computer and use it in GitHub Desktop.
Test case for strange libpeas behavior
AC_INIT([testconfplugin], [0])
AM_INIT_AUTOMAKE([-Wall foreign])
AM_SILENT_RULES([yes])
AC_PROG_CC
LT_INIT
PKG_PROG_PKG_CONFIG
PKG_CHECK_MODULES([PLUGIN], [glib-2.0 gtk+-3.0 libpeas-1.0 libpeas-gtk-1.0])
AC_CONFIG_FILES([Makefile testconfplugin.py])
AC_OUTPUT
#include <glib-object.h>
#include <gtk/gtk.h>
#include <libpeas/peas.h>
#include <libpeas-gtk/peas-gtk.h>
#define CONF_TYPE_PLUGIN (conf_plugin_get_type())
#define CONF_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST((o), CONF_TYPE_PLUGIN, ConfPlugin))
typedef struct {
PeasExtensionBase parent_instance;
gboolean flepping;
} ConfPlugin;
typedef struct {
PeasExtensionBaseClass parent_class;
} ConfPluginClass;
static void conf_plugin_configurable_init(PeasGtkConfigurableInterface *);
G_DEFINE_DYNAMIC_TYPE_EXTENDED(ConfPlugin, conf_plugin, PEAS_TYPE_EXTENSION_BASE, 0,
G_IMPLEMENT_INTERFACE_DYNAMIC(PEAS_GTK_TYPE_CONFIGURABLE, conf_plugin_configurable_init));
enum {
PROP_0,
PROP_FLEPPING
};
G_MODULE_EXPORT void
peas_register_types(PeasObjectModule *module)
{
conf_plugin_register_type(G_TYPE_MODULE(module));
peas_object_module_register_extension_type(module, PEAS_GTK_TYPE_CONFIGURABLE, CONF_TYPE_PLUGIN);
}
static void
conf_plugin_init(ConfPlugin *self)
{
self->flepping = TRUE;
}
static void
conf_plugin_set_property(GObject *self, unsigned prop_id, const GValue *value, GParamSpec *pspec)
{
switch(prop_id) {
case PROP_FLEPPING:
{
gboolean old_value = CONF_PLUGIN(self)->flepping;
gboolean new_value = g_value_get_boolean(value);
CONF_PLUGIN(self)->flepping = new_value;
g_print("You should see this when you turn flepping on or off!\n");
if(old_value != new_value)
g_object_notify(self, "flepping");
}
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(self, prop_id, pspec);
}
}
static void
conf_plugin_get_property(GObject *self, unsigned prop_id, GValue *value, GParamSpec *pspec)
{
switch(prop_id) {
case PROP_FLEPPING:
g_value_set_boolean(value, CONF_PLUGIN(self)->flepping);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(self, prop_id, pspec);
}
}
static void
conf_plugin_class_init(ConfPluginClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS(klass);
object_class->set_property = conf_plugin_set_property;
object_class->get_property = conf_plugin_get_property;
g_object_class_install_property(object_class, PROP_FLEPPING,
g_param_spec_boolean("flepping", "Flepping",
"Whether flepping should be turned on", TRUE,
G_PARAM_READWRITE | G_PARAM_LAX_VALIDATION | G_PARAM_STATIC_STRINGS));
}
static void
conf_plugin_class_finalize(ConfPluginClass *klass)
{
}
static GtkWidget *
conf_plugin_create_configure_widget(PeasGtkConfigurable *self)
{
GtkWidget *button = gtk_check_button_new_with_label("Turn on flepping");
/* Bind GUI widget property to this plugin's configuration property */
g_object_bind_property(self, "flepping", button, "active",
G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
return button;
}
static void
conf_plugin_configurable_init(PeasGtkConfigurableInterface *iface)
{
iface->create_configure_widget = conf_plugin_create_configure_widget;
}
[Plugin]
Module=confplugin
Name=Test Conf Plugin
plugindir = $(libdir)/plugins
dist_plugin_DATA = confplugin.plugin
plugin_LTLIBRARIES = libconfplugin.la
libconfplugin_la_SOURCES = confplugin.c
libconfplugin_la_LIBADD = $(PLUGIN_LIBS)
libconfplugin_la_LDFLAGS = -module -avoid-version -shared
AM_CFLAGS = $(PLUGIN_CFLAGS)
dist_noinst_SCRIPTS = testconfplugin.py
from gi.repository import Gtk, Peas, PeasGtk
e = Peas.Engine.get_default()
w = Gtk.Window()
m = PeasGtk.PluginManager(e)
e.add_search_path('''@libdir@''', None)
info = e.get_plugin_info('confplugin')
e.load_plugin(info)
w.add(m)
w.connect('destroy', Gtk.main_quit)
w.show_all()
Gtk.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment