summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authormonsta <[email protected]>2016-11-30 21:46:53 +0300
committermonsta <[email protected]>2016-11-30 22:34:04 +0300
commitceae2747ae3fc8fc5319351643f841f9bb956f0f (patch)
tree085d8c097ad2d499161ad48379a8c0f9930a45ff /plugins
parentfe5d786a5dbbf3f2a12db6ef7b3adba5b1567614 (diff)
downloadeom-ceae2747ae3fc8fc5319351643f841f9bb956f0f.tar.bz2
eom-ceae2747ae3fc8fc5319351643f841f9bb956f0f.tar.xz
reload plugin: port to libpeas
mostly adapted from: https://git.gnome.org/browse/eog/commit/?id=cf39e40b422dad061184ac67028661bd4dcb0106 https://git.gnome.org/browse/eog/commit/?id=8b0acfddc52c220393770a9895b6b56cab7821fd
Diffstat (limited to 'plugins')
-rw-r--r--plugins/reload/eom-reload-plugin.c144
-rw-r--r--plugins/reload/eom-reload-plugin.h14
2 files changed, 108 insertions, 50 deletions
diff --git a/plugins/reload/eom-reload-plugin.c b/plugins/reload/eom-reload-plugin.c
index d404f02..62d2580 100644
--- a/plugins/reload/eom-reload-plugin.c
+++ b/plugins/reload/eom-reload-plugin.c
@@ -6,18 +6,24 @@
#include <gmodule.h>
#include <glib/gi18n-lib.h>
+#include <libpeas/peas-activatable.h>
#include <eom-debug.h>
#include <eom-window.h>
-#define WINDOW_DATA_KEY "EomReloadWindowData"
+static void peas_activatable_iface_init (PeasActivatableInterface *iface);
-EOM_PLUGIN_REGISTER_TYPE (EomReloadPlugin, eom_reload_plugin)
+G_DEFINE_DYNAMIC_TYPE_EXTENDED (EomReloadPlugin,
+ eom_reload_plugin,
+ PEAS_TYPE_EXTENSION_BASE,
+ 0,
+ G_IMPLEMENT_INTERFACE_DYNAMIC (PEAS_TYPE_ACTIVATABLE,
+ peas_activatable_iface_init))
-typedef struct {
- GtkActionGroup* ui_action_group;
- guint ui_id;
-} WindowData;
+enum {
+ PROP_0,
+ PROP_OBJECT
+};
static void
reload_cb (GtkAction *action,
@@ -39,15 +45,43 @@ static const GtkActionEntry action_entries[] = {
};
static void
-free_window_data (WindowData *data)
+eom_reload_plugin_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
- g_return_if_fail (data != NULL);
-
- eom_debug (DEBUG_PLUGINS);
-
- g_object_unref (data->ui_action_group);
+ EomReloadPlugin *plugin = EOM_RELOAD_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;
+ }
+}
- g_free (data);
+static void
+eom_reload_plugin_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ EomReloadPlugin *plugin = EOM_RELOAD_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
@@ -57,70 +91,88 @@ eom_reload_plugin_init (EomReloadPlugin *plugin)
}
static void
-eom_reload_plugin_finalize (GObject *object)
+eom_reload_plugin_dispose (GObject *object)
{
- eom_debug_message (DEBUG_PLUGINS, "EomReloadPlugin finalizing");
+ EomReloadPlugin *plugin = EOM_RELOAD_PLUGIN (object);
+
+ eom_debug_message (DEBUG_PLUGINS, "EomReloadPlugin disposing");
+
+ if (plugin->window != NULL) {
+ g_object_unref (plugin->window);
+ plugin->window = NULL;
+ }
- G_OBJECT_CLASS (eom_reload_plugin_parent_class)->finalize (object);
+ G_OBJECT_CLASS (eom_reload_plugin_parent_class)->dispose (object);
}
static void
-impl_activate (EomPlugin *plugin,
- EomWindow *window)
+eom_reload_plugin_activate (PeasActivatable *activatable)
{
+ EomReloadPlugin *plugin = EOM_RELOAD_PLUGIN (activatable);
GtkUIManager *manager;
- WindowData *data;
eom_debug (DEBUG_PLUGINS);
- data = g_new (WindowData, 1);
+ manager = eom_window_get_ui_manager (EOM_WINDOW (plugin->window));
- manager = eom_window_get_ui_manager (window);
+ plugin->ui_action_group = gtk_action_group_new ("EomReloadPluginActions");
- data->ui_action_group = gtk_action_group_new ("EomReloadPluginActions");
+ gtk_action_group_set_translation_domain (plugin->ui_action_group, GETTEXT_PACKAGE);
- gtk_action_group_set_translation_domain (data->ui_action_group, GETTEXT_PACKAGE);
+ gtk_action_group_add_actions (plugin->ui_action_group, action_entries,
+ G_N_ELEMENTS (action_entries), plugin->window);
- gtk_action_group_add_actions (data->ui_action_group, action_entries,
- G_N_ELEMENTS (action_entries), window);
+ gtk_ui_manager_insert_action_group (manager, plugin->ui_action_group, -1);
- gtk_ui_manager_insert_action_group (manager, data->ui_action_group, -1);
-
- g_object_set_data_full (G_OBJECT (window), WINDOW_DATA_KEY, data, (GDestroyNotify) free_window_data);
-
- data->ui_id = gtk_ui_manager_add_ui_from_string (manager, ui_definition, -1, NULL);
- g_warn_if_fail (data->ui_id != 0);
+ plugin->ui_id = gtk_ui_manager_add_ui_from_string (manager, ui_definition, -1, NULL);
+ g_warn_if_fail (plugin->ui_id != 0);
}
static void
-impl_deactivate (EomPlugin *plugin,
- EomWindow *window)
+eom_reload_plugin_deactivate (PeasActivatable *activatable)
{
+ EomReloadPlugin *plugin = EOM_RELOAD_PLUGIN (activatable);
GtkUIManager *manager;
- WindowData *data;
eom_debug (DEBUG_PLUGINS);
- manager = eom_window_get_ui_manager (window);
-
- data = (WindowData *) g_object_get_data (G_OBJECT (window), WINDOW_DATA_KEY);
- g_return_if_fail (data != NULL);
+ manager = eom_window_get_ui_manager (EOM_WINDOW (plugin->window));
- gtk_ui_manager_remove_ui (manager, data->ui_id);
+ gtk_ui_manager_remove_ui (manager, plugin->ui_id);
- gtk_ui_manager_remove_action_group (manager, data->ui_action_group);
-
- g_object_set_data (G_OBJECT (window), WINDOW_DATA_KEY, NULL);
+ gtk_ui_manager_remove_action_group (manager, plugin->ui_action_group);
}
static void
eom_reload_plugin_class_init (EomReloadPluginClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
- EomPluginClass *plugin_class = EOM_PLUGIN_CLASS (klass);
- object_class->finalize = eom_reload_plugin_finalize;
+ object_class->dispose = eom_reload_plugin_dispose;
+ object_class->set_property = eom_reload_plugin_set_property;
+ object_class->get_property = eom_reload_plugin_get_property;
+
+ g_object_class_override_property (object_class, PROP_OBJECT, "object");
+}
+
+static void
+eom_reload_plugin_class_finalize (EomReloadPluginClass *klass)
+{
+ /* dummy function - used by G_DEFINE_DYNAMIC_TYPE_EXTENDED */
+}
+
+static void
+peas_activatable_iface_init (PeasActivatableInterface *iface)
+{
+ iface->activate = eom_reload_plugin_activate;
+ iface->deactivate = eom_reload_plugin_deactivate;
+}
- plugin_class->activate = impl_activate;
- plugin_class->deactivate = impl_deactivate;
+G_MODULE_EXPORT void
+peas_register_types (PeasObjectModule *module)
+{
+ eom_reload_plugin_register_type (G_TYPE_MODULE (module));
+ peas_object_module_register_extension_type (module,
+ PEAS_TYPE_ACTIVATABLE,
+ EOM_TYPE_RELOAD_PLUGIN);
}
diff --git a/plugins/reload/eom-reload-plugin.h b/plugins/reload/eom-reload-plugin.h
index 5f285d2..f3830e1 100644
--- a/plugins/reload/eom-reload-plugin.h
+++ b/plugins/reload/eom-reload-plugin.h
@@ -3,7 +3,9 @@
#include <glib.h>
#include <glib-object.h>
-#include <eom-plugin.h>
+#include <gtk/gtk.h>
+#include <libpeas/peas-extension-base.h>
+#include <libpeas/peas-object-module.h>
G_BEGIN_DECLS
@@ -32,7 +34,11 @@ typedef struct _EomReloadPluginPrivate EomReloadPluginPrivate;
typedef struct _EomReloadPlugin EomReloadPlugin;
struct _EomReloadPlugin {
- EomPlugin parent_instance;
+ PeasExtensionBase parent_instance;
+
+ GtkWidget *window;
+ GtkActionGroup *ui_action_group;
+ guint ui_id;
};
/*
@@ -41,7 +47,7 @@ struct _EomReloadPlugin {
typedef struct _EomReloadPluginClass EomReloadPluginClass;
struct _EomReloadPluginClass {
- EomPluginClass parent_class;
+ PeasExtensionBaseClass parent_class;
};
/*
@@ -50,7 +56,7 @@ struct _EomReloadPluginClass {
GType eom_reload_plugin_get_type (void) G_GNUC_CONST;
/* All the plugins must implement this function */
-G_MODULE_EXPORT GType register_eom_plugin (GTypeModule* module);
+G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module);
G_END_DECLS