[eog-plugins] [send-by-mail] Migrate to libpeas plugin engine
- From: Felix Riemann <friemann src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [eog-plugins] [send-by-mail] Migrate to libpeas plugin engine
- Date: Sat, 5 Feb 2011 23:04:16 +0000 (UTC)
commit 4a09f4db878f902c9d07b2c149ff86a5d754d3b2
Author: Felix Riemann <friemann gnome org>
Date: Sun Jan 16 22:54:56 2011 +0100
[send-by-mail] Migrate to libpeas plugin engine
plugins/send-by-mail/Makefile.am | 6 +-
plugins/send-by-mail/eog-send-by-mail-plugin.c | 149 ++++++++++++++------
plugins/send-by-mail/eog-send-by-mail-plugin.h | 24 ++-
...n.desktop.in => send-by-mail.plugin.desktop.in} | 2 +-
4 files changed, 124 insertions(+), 57 deletions(-)
---
diff --git a/plugins/send-by-mail/Makefile.am b/plugins/send-by-mail/Makefile.am
index d54504a..7e1f244 100644
--- a/plugins/send-by-mail/Makefile.am
+++ b/plugins/send-by-mail/Makefile.am
@@ -20,11 +20,11 @@ libsend_by_mail_la_LIBADD = $(EOG_LIBS)
# Plugin Info
-plugin_in_files = send-by-mail.eog-plugin.desktop.in
+plugin_in_files = send-by-mail.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/send-by-mail/eog-send-by-mail-plugin.c b/plugins/send-by-mail/eog-send-by-mail-plugin.c
index 64928e7..fab6a78 100644
--- a/plugins/send-by-mail/eog-send-by-mail-plugin.c
+++ b/plugins/send-by-mail/eog-send-by-mail-plugin.c
@@ -27,21 +27,24 @@
#include <eog/eog-image.h>
#include <eog/eog-thumb-view.h>
#include <eog/eog-window.h>
+#include <eog/eog-window-activatable.h>
#include "eog-send-by-mail-plugin.h"
-#define WINDOW_DATA_KEY "EogSendByMailWindowData"
+static void
+eog_window_activatable_iface_init (EogWindowActivatableInterface *iface);
-EOG_PLUGIN_REGISTER_TYPE(EogSendByMailPlugin, eog_send_by_mail_plugin)
+G_DEFINE_DYNAMIC_TYPE_EXTENDED (EogSendByMailPlugin, eog_send_by_mail_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 free_window_data (WindowData *data);
static void send_by_mail_cb (GtkAction *action, EogWindow *window);
static const gchar * const ui_definition =
@@ -66,83 +69,130 @@ static const GtkActionEntry action_entries[] =
static void
eog_send_by_mail_plugin_init (EogSendByMailPlugin *plugin)
{
+ plugin->ui_action_group = NULL;
+ plugin->ui_menuitem_id = 0;
}
static void
-impl_activate (EogPlugin *plugin,
- EogWindow *window)
+impl_activate (EogWindowActivatable *activatable)
{
+ EogSendByMailPlugin *plugin = EOG_SEND_BY_MAIL_PLUGIN (activatable);
GtkUIManager *manager;
- WindowData *data;
- manager = eog_window_get_ui_manager (window);
- data = g_slice_new (WindowData);
+ manager = eog_window_get_ui_manager (plugin->window);
- data->ui_action_group = gtk_action_group_new ("EogSendByMailPluginActions");
+ plugin->ui_action_group = gtk_action_group_new ("EogSendByMailPluginActions");
- 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)
{
+ EogSendByMailPlugin *plugin = EOG_SEND_BY_MAIL_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);
gtk_ui_manager_remove_action_group (manager,
- data->ui_action_group);
+ plugin->ui_action_group);
+ plugin->ui_action_group = NULL;
+ plugin->ui_menuitem_id = 0;
+}
+
+static void
+eog_send_by_mail_plugin_dispose (GObject *object)
+{
+ EogSendByMailPlugin *plugin = EOG_SEND_BY_MAIL_PLUGIN (object);
- g_object_set_data (G_OBJECT (window),
- WINDOW_DATA_KEY,
- NULL);
+ if (plugin->window != NULL) {
+ g_object_unref (plugin->window);
+ plugin->window = NULL;
+ }
+
+ G_OBJECT_CLASS (eog_send_by_mail_plugin_parent_class)->dispose (object);
}
static void
-eog_send_by_mail_plugin_class_init (EogSendByMailPluginClass *klass)
+eog_send_by_mail_plugin_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- EogPluginClass *plugin_class = EOG_PLUGIN_CLASS (klass);
+ EogSendByMailPlugin *plugin = EOG_SEND_BY_MAIL_PLUGIN (object);
+
+ switch (prop_id)
+ {
+ case PROP_WINDOW:
+ g_value_set_object (value, plugin->window);
+ break;
- plugin_class->activate = impl_activate;
- plugin_class->deactivate = impl_deactivate;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
}
static void
-free_window_data (WindowData *data)
+eog_send_by_mail_plugin_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
- g_return_if_fail (data != NULL);
+ EogSendByMailPlugin *plugin = EOG_SEND_BY_MAIL_PLUGIN (object);
- g_object_unref (data->ui_action_group);
+ switch (prop_id)
+ {
+ case PROP_WINDOW:
+ plugin->window = EOG_WINDOW (g_value_dup_object (value));
+ break;
- g_slice_free (WindowData, data);
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+eog_send_by_mail_plugin_class_init (EogSendByMailPluginClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->dispose = eog_send_by_mail_plugin_dispose;
+ object_class->set_property = eog_send_by_mail_plugin_set_property;
+ object_class->get_property = eog_send_by_mail_plugin_get_property;
+
+ g_object_class_override_property (object_class, PROP_WINDOW, "window");
+}
+
+static void
+eog_send_by_mail_plugin_class_finalize (EogSendByMailPluginClass *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;
}
static void
@@ -192,3 +242,12 @@ send_by_mail_cb (GtkAction *action, EogWindow *window)
g_string_free (uri, TRUE);
}
+
+G_MODULE_EXPORT void
+peas_register_types (PeasObjectModule *module)
+{
+ eog_send_by_mail_plugin_register_type (G_TYPE_MODULE (module));
+ peas_object_module_register_extension_type (module,
+ EOG_TYPE_WINDOW_ACTIVATABLE,
+ EOG_TYPE_SEND_BY_MAIL_PLUGIN);
+}
diff --git a/plugins/send-by-mail/eog-send-by-mail-plugin.h b/plugins/send-by-mail/eog-send-by-mail-plugin.h
index 1f473fb..aa8c10a 100644
--- a/plugins/send-by-mail/eog-send-by-mail-plugin.h
+++ b/plugins/send-by-mail/eog-send-by-mail-plugin.h
@@ -1,6 +1,6 @@
/* SendByMail -- Send images per email
*
- * Copyright (C) 2009 The Free Software Foundation
+ * Copyright (C) 2009-2011 The Free Software Foundation
*
* Author: Felix Riemann <friemann gnome org>
*
@@ -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_SEND_BY_MAIL_PLUGIN (eog_send_by_mail_plugin_get_type ())
-#define EOG_SEND_BY_MAIL_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), EOG_TYPE_SEND_BY_MAIL_PLUGIN, EogStatusbarDatePlugin))
-#define EOG_SEND_BY_MAIL_PLUGIN_CLASS(k) G_TYPE_CHECK_CLASS_CAST((k), EOG_TYPE_SEND_BY_MAIL_PLUGIN, EogStatusbarDatePluginClass))
+#define EOG_SEND_BY_MAIL_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), EOG_TYPE_SEND_BY_MAIL_PLUGIN, EogSendByMailPlugin))
+#define EOG_SEND_BY_MAIL_PLUGIN_CLASS(k) G_TYPE_CHECK_CLASS_CAST((k), EOG_TYPE_SEND_BY_MAIL_PLUGIN, EogSendByMailPluginClass))
#define EOG_IS_SEND_BY_MAIL_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), EOG_TYPE_SEND_BY_MAIL_PLUGIN))
#define EOG_IS_SEND_BY_MAIL_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EOG_TYPE_SEND_BY_MAIL_PLUGIN))
-#define EOG_SEND_BY_MAIL_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), EOG_TYPE_SEND_BY_MAIL_PLUGIN, EogStatusbarDatePluginClass))
+#define EOG_SEND_BY_MAIL_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), EOG_TYPE_SEND_BY_MAIL_PLUGIN, EogSendByMailPluginClass))
/* Private structure type */
typedef struct _EogSendByMailPluginPrivate EogSendByMailPluginPrivate;
@@ -48,7 +51,12 @@ typedef struct _EogSendByMailPlugin EogSendByMailPlugin;
struct _EogSendByMailPlugin
{
- EogPlugin parent_instance;
+ PeasExtensionBase parent_instance;
+
+ EogWindow *window;
+ GtkActionGroup *ui_action_group;
+ guint ui_menuitem_id;
+
};
/*
@@ -58,7 +66,7 @@ typedef struct _EogSendByMailPluginClass EogSendByMailPluginClass;
struct _EogSendByMailPluginClass
{
- EogPluginClass parent_class;
+ PeasExtensionBaseClass parent_class;
};
/*
@@ -67,7 +75,7 @@ struct _EogSendByMailPluginClass
GType eog_send_by_mail_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/send-by-mail/send-by-mail.eog-plugin.desktop.in b/plugins/send-by-mail/send-by-mail.plugin.desktop.in
similarity index 94%
rename from plugins/send-by-mail/send-by-mail.eog-plugin.desktop.in
rename to plugins/send-by-mail/send-by-mail.plugin.desktop.in
index ed0c454..541e27d 100644
--- a/plugins/send-by-mail/send-by-mail.eog-plugin.desktop.in
+++ b/plugins/send-by-mail/send-by-mail.plugin.desktop.in
@@ -1,4 +1,4 @@
-[Eog Plugin]
+[Plugin]
Module=send-by-mail
IAge=2
_Name=Send By Mail
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]