[gtranslator/gtk3] Port insert params plugin to libpeas.
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtranslator/gtk3] Port insert params plugin to libpeas.
- Date: Sun, 7 Nov 2010 22:11:51 +0000 (UTC)
commit a524d405387922f3cf2839ad3c5fc38f8a099e10
Author: Ignacio Casal Quinteiro <icq gnome org>
Date: Sun Nov 7 23:11:35 2010 +0100
Port insert params plugin to libpeas.
plugins/insert-params/Makefile.am | 18 +-
plugins/insert-params/gtr-insert-params-plugin.c | 255 +++++++++++++-------
plugins/insert-params/gtr-insert-params-plugin.h | 47 ++---
...ktop.in => gtr-insert-params.plugin.desktop.in} | 6 +-
4 files changed, 189 insertions(+), 137 deletions(-)
---
diff --git a/plugins/insert-params/Makefile.am b/plugins/insert-params/Makefile.am
index fbd3312..c542736 100644
--- a/plugins/insert-params/Makefile.am
+++ b/plugins/insert-params/Makefile.am
@@ -1,15 +1,12 @@
-# Alternate language plugin
+# Insert params plugin
plugindir = $(libdir)/gtranslator/plugins
INCLUDES = \
-I$(top_srcdir) \
-I$(top_srcdir)/src \
- -I$(top_srcdir)/src/plugin-system \
- -I$(top_srcdir)/src/dialogs \
- $(GTRANSLATOR_CFLAGS) \
+ $(GTRANSLATOR_CFLAGS) \
$(WARN_CFLAGS) \
- $(DISABLE_DEPRECATED) \
- -DGTR_LOCALEDIR=\""$(prefix)/$(DATADIRNAME)/locale"\"
+ $(DISABLE_DEPRECATED)
plugin_LTLIBRARIES = \
libinsertparams.la
@@ -18,23 +15,20 @@ libinsertparams_la_SOURCES = \
gtr-insert-params-plugin.c \
gtr-insert-params-plugin.h
-
libinsertparams_la_LDFLAGS = \
$(PLUGIN_LIBTOOL_FLAGS) \
$(GTRANSLATOR_LIBS)
# Plugin Info
-plugin_in_files = gtr-insert-params.gtranslator-plugin.desktop.in
+plugin_in_files = gtr-insert-params.plugin.desktop.in
-%.gtranslator.plugin: %.gtranslator-plugin.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(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) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache
-plugin_DATA = $(plugin_in_files:.gtranslator-plugin.desktop.in=.gtranslator.plugin)
+plugin_DATA = $(plugin_in_files:.plugin.desktop.in=.plugin)
EXTRA_DIST = $(plugin_in_files)
-
CLEANFILES = $(plugin_DATA)
DISTCLEANFILES = $(plugin_DATA)
-
-include $(top_srcdir)/git.mk
diff --git a/plugins/insert-params/gtr-insert-params-plugin.c b/plugins/insert-params/gtr-insert-params-plugin.c
index f967847..f04f7e7 100644
--- a/plugins/insert-params/gtr-insert-params-plugin.c
+++ b/plugins/insert-params/gtr-insert-params-plugin.c
@@ -24,26 +24,48 @@
#include "gtr-msg.h"
#include "gtr-notebook.h"
#include "gtr-window.h"
+#include "gtr-window-activatable.h"
-#include <glib/gi18n-lib.h>
+#include <glib/gi18n.h>
#include <gtk/gtk.h>
#include <string.h>
-#define WINDOW_DATA_KEY "GtrInsertParamsPluginWindowData"
+struct _GtrInsertParamsPluginPrivate
+{
+ GtrWindow *window;
+
+ GtkActionGroup *action_group;
+ guint ui_id;
+};
+
+enum
+{
+ PROP_0,
+ PROP_WINDOW
+};
+
+static void gtr_window_activatable_iface_init (GtrWindowActivatableInterface *iface);
+
+G_DEFINE_DYNAMIC_TYPE_EXTENDED (GtrInsertParamsPlugin,
+ gtr_insert_params_plugin,
+ PEAS_TYPE_EXTENSION_BASE,
+ 0,
+ G_IMPLEMENT_INTERFACE_DYNAMIC (GTR_TYPE_WINDOW_ACTIVATABLE,
+ gtr_window_activatable_iface_init))
-GTR_PLUGIN_REGISTER_TYPE (GtrInsertParamsPlugin, gtr_insert_params_plugin)
- static GSList *params = NULL;
- static gint param_position;
+static GSList *params = NULL;
+static gint param_position;
- static const gchar param_regex[] = "\\%\\%|\\%" "(?:[1-9][0-9]*\\$)?" // argument
- "[#0\\-\\ \\+\\'I]*" // flags
- "(?:[1-9][0-9]*|\\*)?" // width
- "(?:\\.\\-?(?:[0-9]+|\\*))?" // precision
- "(?:hh|ll|[hlLqjzt])?" // length modifier
- "[diouxXeEfFgGaAcsCSpnm]"; // conversion specifier
+static const gchar param_regex[] =
+ "\\%\\%|\\%" "(?:[1-9][0-9]*\\$)?" /* argument */
+ "[#0\\-\\ \\+\\'I]*" /* flags */
+ "(?:[1-9][0-9]*|\\*)?" /* width */
+ "(?:\\.\\-?(?:[0-9]+|\\*))?" /* precision */
+ "(?:hh|ll|[hlLqjzt])?" /* length modifier */
+ "[diouxXeEfFgGaAcsCSpnm]"; /* conversion specifier */
- static void
- on_next_tag_activated (GtkAction * action, GtrWindow * window)
+static void
+on_next_tag_activated (GtkAction * action, GtrWindow * window)
{
GtrView *view;
GtkTextBuffer *buffer;
@@ -84,59 +106,109 @@ static const gchar submenu[] =
" <placeholder name='EditOps_1'>"
" <menuitem name='EditNextParam' action='NextParam' />"
" <menuitem name='EditInsertParams' action='InsertParams' />"
- " </placeholder>" " </menu>" " </menubar>" "</ui>";
-
-typedef struct
-{
- GtkActionGroup *action_group;
- guint ui_id;
-} WindowData;
-
-static void
-free_window_data (WindowData * data)
-{
- g_return_if_fail (data != NULL);
-
- g_free (data);
-}
+ " </placeholder>"
+ " </menu>"
+ " </menubar>"
+ "</ui>";
static void
-update_ui_real (GtrWindow * window, WindowData * data)
+update_ui (GtrInsertParamsPlugin *plugin)
{
+ GtrInsertParamsPluginPrivate *priv = plugin->priv;
GtkTextView *view;
GtkAction *action;
- view = GTK_TEXT_VIEW (gtr_window_get_active_view (window));
+ view = GTK_TEXT_VIEW (gtr_window_get_active_view (priv->window));
- action = gtk_action_group_get_action (data->action_group, "InsertParams");
+ action = gtk_action_group_get_action (priv->action_group, "InsertParams");
gtk_action_set_sensitive (action,
(view != NULL) &&
gtk_text_view_get_editable (view));
- action = gtk_action_group_get_action (data->action_group, "NextParam");
+ action = gtk_action_group_get_action (priv->action_group, "NextParam");
gtk_action_set_sensitive (action,
(view != NULL) &&
gtk_text_view_get_editable (view));
}
static void
-gtr_insert_params_plugin_init (GtrInsertParamsPlugin * message_table)
+gtr_insert_params_plugin_init (GtrInsertParamsPlugin *plugin)
{
+ plugin->priv = G_TYPE_INSTANCE_GET_PRIVATE (plugin,
+ GTR_TYPE_INSERT_PARAMS_PLUGIN,
+ GtrInsertParamsPluginPrivate);
}
static void
-gtr_insert_params_plugin_finalize (GObject * object)
+gtr_insert_params_plugin_dispose (GObject *object)
{
- if (params != NULL)
+ GtrInsertParamsPluginPrivate *priv = GTR_INSERT_PARAMS_PLUGIN (object)->priv;
+
+ if (priv->window != NULL)
{
- g_slist_free (params);
- params = NULL;
+ g_object_unref (priv->window);
+ priv->window = NULL;
}
+ if (priv->action_group != NULL)
+ {
+ g_object_unref (priv->action_group);
+ priv->action_group = NULL;
+ }
+
+ G_OBJECT_CLASS (gtr_insert_params_plugin_parent_class)->dispose (object);
+}
+
+static void
+gtr_insert_params_plugin_finalize (GObject *object)
+{
+ g_slist_free (params);
+ params = NULL;
+
G_OBJECT_CLASS (gtr_insert_params_plugin_parent_class)->finalize (object);
}
static void
+gtr_insert_params_plugin_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GtrInsertParamsPluginPrivate *priv = GTR_INSERT_PARAMS_PLUGIN (object)->priv;
+
+ switch (prop_id)
+ {
+ case PROP_WINDOW:
+ priv->window = GTR_WINDOW (g_value_dup_object (value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+gtr_insert_params_plugin_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GtrInsertParamsPluginPrivate *priv = GTR_INSERT_PARAMS_PLUGIN (object)->priv;
+
+ switch (prop_id)
+ {
+ case PROP_WINDOW:
+ g_value_set_object (value, priv->window);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
on_menuitem_activated (GtkMenuItem * item, GtrWindow * window)
{
const gchar *name;
@@ -269,113 +341,112 @@ page_added_cb (GtkNotebook * notebook,
}
static void
-impl_activate (GtrPlugin * plugin, GtrWindow * window)
+gtr_insert_params_plugin_activate (GtrWindowActivatable *activatable)
{
+ GtrInsertParamsPluginPrivate *priv = GTR_INSERT_PARAMS_PLUGIN (activatable)->priv;
GtkUIManager *manager;
- WindowData *data;
GError *error = NULL;
GtrNotebook *notebook;
GList *tabs = NULL;
- g_return_if_fail (GTR_IS_WINDOW (window));
-
- data = g_new (WindowData, 1);
+ manager = gtr_window_get_ui_manager (priv->window);
- manager = gtr_window_get_ui_manager (window);
-
- data->action_group = gtk_action_group_new ("GtrInsertParamsPluginActions");
- gtk_action_group_set_translation_domain (data->action_group,
+ priv->action_group = gtk_action_group_new ("GtrInsertParamsPluginActions");
+ gtk_action_group_set_translation_domain (priv->action_group,
GETTEXT_PACKAGE);
- gtk_action_group_add_actions (data->action_group, action_entries,
- G_N_ELEMENTS (action_entries), window);
+ gtk_action_group_add_actions (priv->action_group, action_entries,
+ G_N_ELEMENTS (action_entries), priv->window);
- gtk_ui_manager_insert_action_group (manager, data->action_group, -1);
+ gtk_ui_manager_insert_action_group (manager, priv->action_group, -1);
- data->ui_id = gtk_ui_manager_add_ui_from_string (manager,
- submenu, -1, &error);
+ priv->ui_id = gtk_ui_manager_add_ui_from_string (manager,
+ submenu, -1,
+ &error);
if (error)
{
g_warning ("%s", error->message);
g_error_free (error);
- g_free (data);
return;
}
- g_object_set_data_full (G_OBJECT (window),
- WINDOW_DATA_KEY,
- data, (GDestroyNotify) free_window_data);
-
- update_ui_real (window, data);
+ update_ui (GTR_INSERT_PARAMS_PLUGIN (activatable));
/*Adding menuitems */
- notebook = gtr_window_get_notebook (window);
+ notebook = gtr_window_get_notebook (priv->window);
g_signal_connect (GTK_NOTEBOOK (notebook),
- "page-added", G_CALLBACK (page_added_cb), window);
+ "page-added", G_CALLBACK (page_added_cb), priv->window);
- tabs = gtr_window_get_all_tabs (window);
+ tabs = gtr_window_get_all_tabs (priv->window);
if (tabs == NULL)
return;
do
{
g_signal_connect (tabs->data, "showed-message",
- G_CALLBACK (showed_message_cb), window);
+ G_CALLBACK (showed_message_cb), priv->window);
}
while ((tabs = g_list_next (tabs)));
}
static void
-impl_deactivate (GtrPlugin * plugin, GtrWindow * window)
+gtr_insert_params_plugin_deactivate (GtrWindowActivatable *activatable)
{
+ GtrInsertParamsPluginPrivate *priv = GTR_INSERT_PARAMS_PLUGIN (activatable)->priv;
GtrNotebook *notebook;
GtkUIManager *manager;
- WindowData *data;
- manager = gtr_window_get_ui_manager (window);
-
- data =
- (WindowData *) g_object_get_data (G_OBJECT (window), WINDOW_DATA_KEY);
- g_return_if_fail (data != NULL);
+ manager = gtr_window_get_ui_manager (priv->window);
- gtk_ui_manager_remove_ui (manager, data->ui_id);
- gtk_ui_manager_remove_action_group (manager, data->action_group);
+ gtk_ui_manager_remove_ui (manager, priv->ui_id);
+ gtk_ui_manager_remove_action_group (manager, priv->action_group);
- g_object_set_data (G_OBJECT (window), WINDOW_DATA_KEY, NULL);
+ notebook = gtr_window_get_notebook (priv->window);
- notebook = gtr_window_get_notebook (window);
-
- g_signal_handlers_disconnect_by_func (notebook, page_added_cb, window);
+ g_signal_handlers_disconnect_by_func (notebook, page_added_cb, priv->window);
+}
- if (params != NULL)
- {
- g_slist_free (params);
- params = NULL;
- }
+static void
+gtr_insert_params_plugin_update_state (GtrWindowActivatable *activatable)
+{
+ update_ui (GTR_INSERT_PARAMS_PLUGIN (activatable));
}
static void
-impl_update_ui (GtrPlugin * plugin, GtrWindow * window)
+gtr_insert_params_plugin_class_init (GtrInsertParamsPluginClass * klass)
{
- WindowData *data;
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->dispose = gtr_insert_params_plugin_dispose;
+ object_class->finalize = gtr_insert_params_plugin_finalize;
+ object_class->set_property = gtr_insert_params_plugin_set_property;
+ object_class->get_property = gtr_insert_params_plugin_get_property;
- data =
- (WindowData *) g_object_get_data (G_OBJECT (window), WINDOW_DATA_KEY);
- g_return_if_fail (data != NULL);
+ g_object_class_override_property (object_class, PROP_WINDOW, "window");
- update_ui_real (window, data);
+ g_type_class_add_private (klass, sizeof (GtrInsertParamsPluginPrivate));
}
static void
- gtr_insert_params_plugin_class_init (GtrInsertParamsPluginClass * klass)
+gtr_insert_params_plugin_class_finalize (GtrInsertParamsPluginClass * klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- GtrPluginClass *plugin_class = GTR_PLUGIN_CLASS (klass);
+}
- object_class->finalize = gtr_insert_params_plugin_finalize;
+static void
+gtr_window_activatable_iface_init (GtrWindowActivatableInterface *iface)
+{
+ iface->activate = gtr_insert_params_plugin_activate;
+ iface->deactivate = gtr_insert_params_plugin_deactivate;
+ iface->update_state = gtr_insert_params_plugin_update_state;
+}
+
+G_MODULE_EXPORT void
+peas_register_types (PeasObjectModule *module)
+{
+ gtr_insert_params_plugin_register_type (G_TYPE_MODULE (module));
- plugin_class->activate = impl_activate;
- plugin_class->deactivate = impl_deactivate;
- plugin_class->update_ui = impl_update_ui;
+ peas_object_module_register_extension_type (module,
+ GTR_TYPE_WINDOW_ACTIVATABLE,
+ GTR_TYPE_INSERT_PARAMS_PLUGIN);
}
diff --git a/plugins/insert-params/gtr-insert-params-plugin.h b/plugins/insert-params/gtr-insert-params-plugin.h
index 4edfab4..95c8cb0 100644
--- a/plugins/insert-params/gtr-insert-params-plugin.h
+++ b/plugins/insert-params/gtr-insert-params-plugin.h
@@ -21,51 +21,38 @@
#include <glib.h>
#include <glib-object.h>
-
-#include "gtr-plugin.h"
+#include <libpeas/peas-extension-base.h>
+#include <libpeas/peas-object-module.h>
G_BEGIN_DECLS
-/*
- * Type checking and casting macros
- */
-#define GTR_TYPE_INSERT_PARAMS_PLUGIN (gtr_insert_params_get_type ())
-#define GTR_INSERT_PARAMS_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GTR_TYPE_MESSAGEINSERT_PARAMS_PLUGIN, GtrInsertParamsPlugin))
-#define GTR_INSERT_PARAMS_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GTR_TYPE_INSERT_PARAMS_PLUGIN, GtrInsertParamsPluginClass))
+
+#define GTR_TYPE_INSERT_PARAMS_PLUGIN (gtr_insert_params_plugin_get_type ())
+#define GTR_INSERT_PARAMS_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GTR_TYPE_INSERT_PARAMS_PLUGIN, GtrInsertParamsPlugin))
+#define GTR_INSERT_PARAMS_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GTR_TYPE_INSERT_PARAMS_PLUGIN, GtrInsertParamsPluginClass))
#define GTR_IS_INSERT_PARAMS_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GTR_TYPE_INSERT_PARAMS_PLUGIN))
-#define GTR_IS_INSERT_PARAMS_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GTR_TYPE_INSERT_PARAMS_PLUGIN))
+#define GTR_IS_INSERT_PARAMS_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GTR_TYPE_INSERT_PARAMS_PLUGIN))
#define GTR_INSERT_PARAMS_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GTR_TYPE_INSERT_PARAMS_PLUGIN_PLUGIN, GtrInsertParamsPluginClass))
-/* Private structure type */
-typedef struct _GtrInsertParamsPluginPrivate GtrInsertParamsPluginPrivate;
-/*
- * Main object structure
- */
-typedef struct _GtrInsertParamsPlugin GtrInsertParamsPlugin;
+typedef struct _GtrInsertParamsPlugin GtrInsertParamsPlugin;
+typedef struct _GtrInsertParamsPluginPrivate GtrInsertParamsPluginPrivate;
+typedef struct _GtrInsertParamsPluginClass GtrInsertParamsPluginClass;
struct _GtrInsertParamsPlugin
{
- GtrPlugin parent_instance;
-};
+ PeasExtensionBase parent_instance;
-/*
- * Class definition
- */
-typedef struct _GtrInsertParamsPluginClass GtrInsertParamsPluginClass;
+ /*< private >*/
+ GtrInsertParamsPluginPrivate *priv;
+};
struct _GtrInsertParamsPluginClass
{
- GtrPluginClass parent_class;
+ PeasExtensionBaseClass parent_class;
};
-/*
- * Public methods
- */
-GType
-gtr_insert_params_plugin_get_type (void)
- G_GNUC_CONST;
+GType gtr_insert_params_plugin_get_type (void) G_GNUC_CONST;
-/* All the plugins must implement this function */
- G_MODULE_EXPORT GType register_gtr_plugin (GTypeModule * module);
+G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module);
G_END_DECLS
#endif /* __GTR_INSERT_PARAMS_PLUGIN_H__ */
diff --git a/plugins/insert-params/gtr-insert-params.gtranslator-plugin.desktop.in b/plugins/insert-params/gtr-insert-params.plugin.desktop.in
similarity index 57%
rename from plugins/insert-params/gtr-insert-params.gtranslator-plugin.desktop.in
rename to plugins/insert-params/gtr-insert-params.plugin.desktop.in
index 2c2c0ef..471312f 100644
--- a/plugins/insert-params/gtr-insert-params.gtranslator-plugin.desktop.in
+++ b/plugins/insert-params/gtr-insert-params.plugin.desktop.in
@@ -1,8 +1,8 @@
-[Gtranslator Plugin]
+[Plugin]
Module=insertparams
IAge=2
_Name=Insert Params
_Description=Parameters detection and easy insertion.
-Authors=Ignacio Casal Quinteiro <nacho resa gmail com>
+Authors=Ignacio Casal Quinteiro <icq gnome org>
Copyright=Copyright @ 2008 Ignacio Casal Quinteiro
-Website=http://gtranslator.sf.net
+Website=http://projects.gnome.org/gtranslator
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]