[eog-plugins] [fit-to-width] Migrate fit-to-width plugin to libpeas plugin engine
- From: Felix Riemann <friemann src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [eog-plugins] [fit-to-width] Migrate fit-to-width plugin to libpeas plugin engine
- Date: Sat, 5 Feb 2011 23:04:00 +0000 (UTC)
commit ce579bbc65c0cb4d795af95f34ba45ca8cbd6bf9
Author: Felix Riemann <friemann gnome org>
Date: Sun Jan 16 22:24:06 2011 +0100
[fit-to-width] Migrate fit-to-width plugin to libpeas plugin engine
plugins/fit-to-width/Makefile.am | 6 +-
plugins/fit-to-width/eog-fit-to-width-plugin.c | 166 ++++++++++++++------
plugins/fit-to-width/eog-fit-to-width-plugin.h | 23 ++-
...n.desktop.in => fit-to-width.plugin.desktop.in} | 2 +-
4 files changed, 135 insertions(+), 62 deletions(-)
---
diff --git a/plugins/fit-to-width/Makefile.am b/plugins/fit-to-width/Makefile.am
index efdf450..f5ecd55 100644
--- a/plugins/fit-to-width/Makefile.am
+++ b/plugins/fit-to-width/Makefile.am
@@ -20,11 +20,11 @@ libfit_to_width_la_LIBADD = $(EOG_LIBS)
# Plugin Info
-plugin_in_files = fit-to-width.eog-plugin.desktop.in
+plugin_in_files = fit-to-width.plugin.desktop.in
-%.eog-plugin: %.eog-plugin.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(AM_V_GEN)$(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache
+%.plugin: %.plugin.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(AM_V_GEN)$(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache
-plugin_DATA = $(plugin_in_files:.eog-plugin.desktop.in=.eog-plugin)
+plugin_DATA = $(plugin_in_files:.plugin.desktop.in=.plugin)
EXTRA_DIST = $(plugin_in_files)
diff --git a/plugins/fit-to-width/eog-fit-to-width-plugin.c b/plugins/fit-to-width/eog-fit-to-width-plugin.c
index a7766a6..740997e 100644
--- a/plugins/fit-to-width/eog-fit-to-width-plugin.c
+++ b/plugins/fit-to-width/eog-fit-to-width-plugin.c
@@ -26,23 +26,29 @@
#include <glib/gi18n-lib.h>
#include <eog/eog-scroll-view.h>
#include <eog/eog-image.h>
+#include <eog/eog-window.h>
+#include <eog/eog-window-activatable.h>
+
+#include <libpeas/peas.h>
#include "eog-fit-to-width-plugin.h"
-#define WINDOW_DATA_KEY "EogFitToWidthWindowData"
+static void
+eog_window_activatable_iface_init (EogWindowActivatableInterface *iface);
-EOG_PLUGIN_REGISTER_TYPE(EogFitToWidthPlugin, eog_fit_to_width_plugin)
+G_DEFINE_DYNAMIC_TYPE_EXTENDED (EogFitToWidthPlugin, eog_fit_to_width_plugin,
+ PEAS_TYPE_EXTENSION_BASE, 0,
+ G_IMPLEMENT_INTERFACE_DYNAMIC (EOG_TYPE_WINDOW_ACTIVATABLE,
+ eog_window_activatable_iface_init))
-typedef struct
-{
- GtkActionGroup *ui_action_group;
- guint ui_menuitem_id;
-} WindowData;
+enum {
+ PROP_0,
+ PROP_WINDOW
+};
static void
-fit_to_width_cb (GtkAction *action,
- EogWindow *window)
+fit_to_width_cb (GtkAction *action, EogWindow *window)
{
GtkWidget *view;
EogImage *image;
@@ -88,85 +94,143 @@ static const GtkActionEntry action_entries[] =
G_CALLBACK (fit_to_width_cb) }
};
-static void
-free_window_data (WindowData *data)
-{
- g_return_if_fail (data != NULL);
-
- g_object_unref (data->ui_action_group);
-
- g_free (data);
-}
-
static void
eog_fit_to_width_plugin_init (EogFitToWidthPlugin *plugin)
{
+ plugin->ui_action_group = NULL;
+ plugin->ui_menuitem_id = 0;
}
static void
-impl_activate (EogPlugin *plugin,
- EogWindow *window)
+impl_activate (EogWindowActivatable *activatable)
{
+ EogFitToWidthPlugin *plugin = EOG_FIT_TO_WIDTH_PLUGIN (activatable);
GtkUIManager *manager;
- WindowData *data;
- manager = eog_window_get_ui_manager (window);
- data = g_new (WindowData, 1);
+ manager = eog_window_get_ui_manager (plugin->window);
- data->ui_action_group = gtk_action_group_new ("EogFitToWidthPluginActions");
+ plugin->ui_action_group = gtk_action_group_new ("EogFitToWidthPluginActions");
- gtk_action_group_set_translation_domain (data->ui_action_group,
+ gtk_action_group_set_translation_domain (plugin->ui_action_group,
GETTEXT_PACKAGE);
- gtk_action_group_add_actions (data->ui_action_group,
+ gtk_action_group_add_actions (plugin->ui_action_group,
action_entries,
G_N_ELEMENTS (action_entries),
- window);
+ plugin->window);
gtk_ui_manager_insert_action_group (manager,
- data->ui_action_group,
+ plugin->ui_action_group,
-1);
- data->ui_menuitem_id = gtk_ui_manager_add_ui_from_string (manager,
+ plugin->ui_menuitem_id = gtk_ui_manager_add_ui_from_string (manager,
ui_definition,
-1, NULL);
-
- g_object_set_data_full (G_OBJECT (window),
- WINDOW_DATA_KEY,
- data,
- (GDestroyNotify) free_window_data);
}
static void
-impl_deactivate (EogPlugin *plugin,
- EogWindow *window)
+impl_deactivate (EogWindowActivatable *activatable)
{
+ EogFitToWidthPlugin *plugin = EOG_FIT_TO_WIDTH_PLUGIN (activatable);
GtkUIManager *manager;
- WindowData *data;
-
- manager = eog_window_get_ui_manager (window);
- data = (WindowData *) g_object_get_data (G_OBJECT (window),
- WINDOW_DATA_KEY);
- g_return_if_fail (data != NULL);
+ manager = eog_window_get_ui_manager (plugin->window);
gtk_ui_manager_remove_ui (manager,
- data->ui_menuitem_id);
+ plugin->ui_menuitem_id);
+
+ plugin->ui_menuitem_id = 0;
gtk_ui_manager_remove_action_group (manager,
- data->ui_action_group);
+ plugin->ui_action_group);
+ g_object_unref (plugin->ui_action_group);
+ plugin->ui_action_group = NULL;
+}
+
+static void
+eog_fit_to_width_plugin_dispose (GObject *object)
+{
+ EogFitToWidthPlugin *plugin = EOG_FIT_TO_WIDTH_PLUGIN (object);
+
+ if (plugin->window != NULL) {
+ g_object_unref (plugin->window);
+ plugin->window = NULL;
+ }
+
+ G_OBJECT_CLASS (eog_fit_to_width_plugin_parent_class)->dispose (object);
+}
+
+static void
+eog_fit_to_width_plugin_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ EogFitToWidthPlugin *plugin = EOG_FIT_TO_WIDTH_PLUGIN (object);
+
+ switch (prop_id)
+ {
+ case PROP_WINDOW:
+ g_value_set_object (value, plugin->window);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
- g_object_set_data (G_OBJECT (window),
- WINDOW_DATA_KEY,
- NULL);
+static void
+eog_fit_to_width_plugin_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ EogFitToWidthPlugin *plugin = EOG_FIT_TO_WIDTH_PLUGIN (object);
+
+ switch (prop_id)
+ {
+ case PROP_WINDOW:
+ plugin->window = EOG_WINDOW (g_value_dup_object (value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
}
static void
eog_fit_to_width_plugin_class_init (EogFitToWidthPluginClass *klass)
{
- EogPluginClass *plugin_class = EOG_PLUGIN_CLASS (klass);
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->dispose = eog_fit_to_width_plugin_dispose;
+ object_class->set_property = eog_fit_to_width_plugin_set_property;
+ object_class->get_property = eog_fit_to_width_plugin_get_property;
+
+ g_object_class_override_property (object_class, PROP_WINDOW, "window");
+}
- plugin_class->activate = impl_activate;
- plugin_class->deactivate = impl_deactivate;
+static void
+eog_fit_to_width_plugin_class_finalize (EogFitToWidthPluginClass *klass)
+{
+ /* Dummy needed for G_DEFINE_DYNAMIC_TYPE_EXTENDED */
+}
+
+static void
+eog_window_activatable_iface_init (EogWindowActivatableInterface *iface)
+{
+ iface->activate = impl_activate;
+ iface->deactivate = impl_deactivate;
+}
+
+G_MODULE_EXPORT void
+peas_register_types (PeasObjectModule *module)
+{
+ eog_fit_to_width_plugin_register_type (G_TYPE_MODULE (module));
+ peas_object_module_register_extension_type (module,
+ EOG_TYPE_WINDOW_ACTIVATABLE,
+ EOG_TYPE_FIT_TO_WIDTH_PLUGIN);
}
diff --git a/plugins/fit-to-width/eog-fit-to-width-plugin.h b/plugins/fit-to-width/eog-fit-to-width-plugin.h
index ef2210c..1392748 100644
--- a/plugins/fit-to-width/eog-fit-to-width-plugin.h
+++ b/plugins/fit-to-width/eog-fit-to-width-plugin.h
@@ -24,7 +24,10 @@
#include <glib.h>
#include <glib-object.h>
-#include <eog/eog-plugin.h>
+#include <gtk/gtk.h>
+#include <eog/eog-window.h>
+#include <libpeas/peas-extension-base.h>
+#include <libpeas/peas-object-module.h>
G_BEGIN_DECLS
@@ -32,11 +35,11 @@ G_BEGIN_DECLS
* Type checking and casting macros
*/
#define EOG_TYPE_FIT_TO_WIDTH_PLUGIN (eog_fit_to_width_plugin_get_type ())
-#define EOG_FIT_TO_WIDTH_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), EOG_TYPE_FIT_TO_WIDTH_PLUGIN, EogStatusbarDatePlugin))
-#define EOG_FIT_TO_WIDTH_PLUGIN_CLASS(k) G_TYPE_CHECK_CLASS_CAST((k), EOG_TYPE_FIT_TO_WIDTH_PLUGIN, EogStatusbarDatePluginClass))
+#define EOG_FIT_TO_WIDTH_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), EOG_TYPE_FIT_TO_WIDTH_PLUGIN, EogFitToWidthPlugin))
+#define EOG_FIT_TO_WIDTH_PLUGIN_CLASS(k) G_TYPE_CHECK_CLASS_CAST((k), EOG_TYPE_FIT_TO_WIDTH_PLUGIN, EogFitToWidthPluginClass))
#define EOG_IS_FIT_TO_WIDTH_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), EOG_TYPE_FIT_TO_WIDTH_PLUGIN))
#define EOG_IS_FIT_TO_WIDTH_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EOG_TYPE_FIT_TO_WIDTH_PLUGIN))
-#define EOG_FIT_TO_WIDTH_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), EOG_TYPE_FIT_TO_WIDTH_PLUGIN, EogStatusbarDatePluginClass))
+#define EOG_FIT_TO_WIDTH_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), EOG_TYPE_FIT_TO_WIDTH_PLUGIN, EogFitToWidthPluginClass))
/* Private structure type */
typedef struct _EogFitToWidthPluginPrivate EogFitToWidthPluginPrivate;
@@ -48,7 +51,13 @@ typedef struct _EogFitToWidthPlugin EogFitToWidthPlugin;
struct _EogFitToWidthPlugin
{
- EogPlugin parent_instance;
+ PeasExtensionBase parent_instance;
+
+ EogWindow *window;
+
+ GtkActionGroup *ui_action_group;
+ guint ui_menuitem_id;
+
};
/*
@@ -58,7 +67,7 @@ typedef struct _EogFitToWidthPluginClass EogFitToWidthPluginClass;
struct _EogFitToWidthPluginClass
{
- EogPluginClass parent_class;
+ PeasExtensionBaseClass parent_class;
};
/*
@@ -67,7 +76,7 @@ struct _EogFitToWidthPluginClass
GType eog_fit_to_width_plugin_get_type (void) G_GNUC_CONST;
/* All the plugins must implement this function */
-G_MODULE_EXPORT GType register_eog_plugin (GTypeModule *module);
+G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module);
G_END_DECLS
diff --git a/plugins/fit-to-width/fit-to-width.eog-plugin.desktop.in b/plugins/fit-to-width/fit-to-width.plugin.desktop.in
similarity index 94%
rename from plugins/fit-to-width/fit-to-width.eog-plugin.desktop.in
rename to plugins/fit-to-width/fit-to-width.plugin.desktop.in
index 537c217..be2fe84 100644
--- a/plugins/fit-to-width/fit-to-width.eog-plugin.desktop.in
+++ b/plugins/fit-to-width/fit-to-width.plugin.desktop.in
@@ -1,4 +1,4 @@
-[Eog Plugin]
+[Plugin]
Module=fit-to-width
IAge=2
_Name=Zoom to fit image width
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]