[gedit-plugins] Port charmap plugin to libpeas.



commit d1b459223873feaf130320436daed825d5cff80d
Author: Ignacio Casal Quinteiro <icq gnome org>
Date:   Sun Jul 4 12:35:29 2010 +0200

    Port charmap plugin to libpeas.

 plugins/charmap/gedit-charmap-panel.c  |   14 +++-
 plugins/charmap/gedit-charmap-panel.h  |    3 +-
 plugins/charmap/gedit-charmap-plugin.c |  153 +++++++++++++++++---------------
 plugins/charmap/gedit-charmap-plugin.h |   36 +++-----
 4 files changed, 106 insertions(+), 100 deletions(-)
---
diff --git a/plugins/charmap/gedit-charmap-panel.c b/plugins/charmap/gedit-charmap-panel.c
index d9fc0e0..74227d7 100644
--- a/plugins/charmap/gedit-charmap-panel.c
+++ b/plugins/charmap/gedit-charmap-panel.c
@@ -22,7 +22,6 @@
 #include <config.h>
 #endif
 
-#include <gedit/gedit-plugin.h>
 #include "gedit-charmap-panel.h"
 
 #include <gucharmap/gucharmap.h>
@@ -38,7 +37,7 @@ struct _GeditCharmapPanelPrivate
 	GucharmapChartable *chartable;
 };
 
-GEDIT_PLUGIN_DEFINE_TYPE(GeditCharmapPanel, gedit_charmap_panel, GTK_TYPE_VBOX)
+G_DEFINE_DYNAMIC_TYPE (GeditCharmapPanel, gedit_charmap_panel, GTK_TYPE_VBOX)
 
 static void
 on_chapter_view_selection_changed (GtkTreeSelection *selection,
@@ -130,6 +129,11 @@ gedit_charmap_panel_class_init (GeditCharmapPanelClass *klass)
 	object_class->finalize = gedit_charmap_panel_finalize;
 }
 
+static void
+gedit_charmap_panel_class_finalize (GeditCharmapPanelClass *klass)
+{
+}
+
 GtkWidget *
 gedit_charmap_panel_new (void)
 {
@@ -141,3 +145,9 @@ gedit_charmap_panel_get_chartable (GeditCharmapPanel *panel)
 {
 	return panel->priv->chartable;
 }
+
+void
+_gedit_charmap_panel_register_type (GTypeModule *type_module)
+{
+	gedit_charmap_panel_register_type (type_module);
+}
diff --git a/plugins/charmap/gedit-charmap-panel.h b/plugins/charmap/gedit-charmap-panel.h
index 9dca838..6245f02 100644
--- a/plugins/charmap/gedit-charmap-panel.h
+++ b/plugins/charmap/gedit-charmap-panel.h
@@ -71,11 +71,12 @@ struct _GeditCharmapPanelClass
  * Public methods
  */
 GType		 gedit_charmap_panel_get_type	   (void) G_GNUC_CONST;
-GType		 gedit_charmap_panel_register_type (GTypeModule * module);
 GtkWidget	*gedit_charmap_panel_new	   (void);
 
 GucharmapChartable *gedit_charmap_panel_get_chartable (GeditCharmapPanel *panel);
 
+void		_gedit_charmap_panel_register_type (GTypeModule *type_module);
+
 G_END_DECLS
 
 #endif /* __CHARMAP_PANEL_H__ */
diff --git a/plugins/charmap/gedit-charmap-plugin.c b/plugins/charmap/gedit-charmap-plugin.c
index 86b8295..d7346a3 100644
--- a/plugins/charmap/gedit-charmap-plugin.c
+++ b/plugins/charmap/gedit-charmap-plugin.c
@@ -28,32 +28,43 @@
 #include <glib/gi18n-lib.h>
 #include <gedit/gedit-debug.h>
 #include <gedit/gedit-window.h>
+#include <gedit/gedit-window-activatable.h>
 #include <gedit/gedit-panel.h>
 #include <gedit/gedit-document.h>
 
 #include <gucharmap/gucharmap.h>
 
-#define WINDOW_DATA_KEY	"GeditCharmapPluginWindowData"
-
 #define GEDIT_CHARMAP_PLUGIN_GET_PRIVATE(object) \
 				(G_TYPE_INSTANCE_GET_PRIVATE ((object),	\
 				GEDIT_TYPE_CHARMAP_PLUGIN,		\
 				GeditCharmapPluginPrivate))
 
-typedef struct
+struct _GeditCharmapPluginPrivate
 {
-	GtkWidget	*panel;
-	guint		 context_id;
-} WindowData;
-
-GEDIT_PLUGIN_REGISTER_TYPE_WITH_CODE (GeditCharmapPlugin, gedit_charmap_plugin,
-		gedit_charmap_panel_register_type (module);
+	GeditWindow     *window;
+
+	GtkWidget       *panel;
+	guint            context_id;
+};
+
+static void gedit_window_activatable_iface_init (GeditWindowActivatableInterface *iface);
+
+G_DEFINE_DYNAMIC_TYPE_EXTENDED (GeditCharmapPlugin,
+				gedit_charmap_plugin,
+				PEAS_TYPE_EXTENSION_BASE,
+				0,
+				G_IMPLEMENT_INTERFACE_DYNAMIC (GEDIT_TYPE_WINDOW_ACTIVATABLE,
+							       gedit_window_activatable_iface_init)	\
+													\
+				_gedit_charmap_panel_register_type (type_module);			\
 )
 
 static void
 gedit_charmap_plugin_init (GeditCharmapPlugin *plugin)
 {
 	gedit_debug_message (DEBUG_PLUGINS, "GeditCharmapPlugin initializing");
+
+	plugin->priv = GEDIT_CHARMAP_PLUGIN_GET_PRIVATE (plugin);
 }
 
 static void
@@ -65,34 +76,24 @@ gedit_charmap_plugin_finalize (GObject *object)
 }
 
 static void
-free_window_data (WindowData *data)
-{
-	g_slice_free (WindowData, data);
-}
-
-static void
 on_table_status_message (GucharmapChartable *chartable,
-			 const gchar    *message,
-			 GeditWindow    *window)
+			 const gchar        *message,
+			 GeditCharmapPlugin *plugin)
 {
 	GtkStatusbar *statusbar;
-	WindowData *data;
 
-	statusbar = GTK_STATUSBAR (gedit_window_get_statusbar (window));
-	data = (WindowData *) g_object_get_data (G_OBJECT (window),
-						 WINDOW_DATA_KEY);
-	g_return_if_fail (data != NULL);
+	statusbar = GTK_STATUSBAR (gedit_window_get_statusbar (plugin->priv->window));
 
-	gtk_statusbar_pop (statusbar, data->context_id);
+	gtk_statusbar_pop (statusbar, plugin->priv->context_id);
 
 	if (message)
-		gtk_statusbar_push (statusbar, data->context_id, message);
+		gtk_statusbar_push (statusbar, plugin->priv->context_id, message);
 }
 
 static void
 on_table_sync_active_char (GucharmapChartable *chartable,
 			   GParamSpec         *psepc,
-			   GeditWindow        *window)
+			   GeditCharmapPlugin *plugin)
 {
 	GString *gs;
 	const gchar **temps;
@@ -123,41 +124,36 @@ on_table_sync_active_char (GucharmapChartable *chartable,
 		g_free (temps);
 	}
 
-	on_table_status_message (chartable, gs->str, window);
+	on_table_status_message (chartable, gs->str, plugin);
 	g_string_free (gs, TRUE);
 }
 
 static gboolean
-on_table_focus_out_event (GtkWidget      *drawing_area,
-			  GdkEventFocus  *event,
-			  GeditWindow    *window)
+on_table_focus_out_event (GtkWidget          *drawing_area,
+			  GdkEventFocus      *event,
+			  GeditCharmapPlugin *plugin)
 {
 	GucharmapChartable *chartable;
-	WindowData *data;
-
-	data = (WindowData *) g_object_get_data (G_OBJECT (window),
-						 WINDOW_DATA_KEY);
-	g_return_val_if_fail (data != NULL, FALSE);
 
 	chartable = gedit_charmap_panel_get_chartable
-					(GEDIT_CHARMAP_PANEL (data->panel));
+					(GEDIT_CHARMAP_PANEL (plugin->priv->panel));
 
-	on_table_status_message (chartable, NULL, window);
+	on_table_status_message (chartable, NULL, plugin);
 	return FALSE;
 }
 
 static void
 on_table_activate (GucharmapChartable *chartable,
-		   GeditWindow *window)
+		   GeditWindow        *window)
 {
 	GtkTextView   *view;
 	GtkTextBuffer *document;
 	GtkTextIter start, end;
 	gchar buffer[6];
 	gchar length;
-        gunichar wc;
+	gunichar wc;
 
-        wc = gucharmap_chartable_get_active_character (chartable);
+	wc = gucharmap_chartable_get_active_character (chartable);
 
 	g_return_if_fail (gucharmap_unichar_validate (wc));
 
@@ -213,10 +209,10 @@ get_document_font ()
 }
 
 static GtkWidget *
-create_charmap_panel (GeditWindow *window)
+create_charmap_panel (GeditCharmapPlugin *plugin)
 {
 	GSettings *settings;
-	GtkWidget      *panel;
+	GtkWidget *panel;
 	GucharmapChartable *chartable;
 	PangoFontDescription *font_desc;
 	gchar *font;
@@ -236,19 +232,19 @@ create_charmap_panel (GeditWindow *window)
 	g_signal_connect (chartable,
 			  "notify::active-character",
 			  G_CALLBACK (on_table_sync_active_char),
-			  window);
+			  plugin);
 	g_signal_connect (chartable,
 			  "focus-out-event",
 			  G_CALLBACK (on_table_focus_out_event),
-			  window);
+			  plugin);
 	g_signal_connect (chartable,
 			  "status-message",
 			  G_CALLBACK (on_table_status_message),
-			  window);
+			  plugin);
 	g_signal_connect (chartable,
 			  "activate",
 			  G_CALLBACK (on_table_activate),
-			  window);
+			  plugin->priv->window);
 
 	gtk_widget_show_all (panel);
 
@@ -256,20 +252,21 @@ create_charmap_panel (GeditWindow *window)
 }
 
 static void
-impl_activate (GeditPlugin *plugin,
-	       GeditWindow *window)
+gedit_charmap_plugin_activate (GeditWindowActivatable *activatable,
+			       GeditWindow            *window)
 {
+	GeditCharmapPluginPrivate *priv;
 	GeditPanel *panel;
 	GtkWidget *image;
 	GtkIconTheme *theme;
 	GtkStatusbar *statusbar;
-	WindowData *data;
 
 	gedit_debug (DEBUG_PLUGINS);
 
-	panel = gedit_window_get_side_panel (window);
+	priv = GEDIT_CHARMAP_PLUGIN (activatable)->priv;
+	priv->window = window;
 
-	data = g_slice_new (WindowData);
+	panel = gedit_window_get_side_panel (window);
 
 	theme = gtk_icon_theme_get_default ();
 
@@ -280,10 +277,10 @@ impl_activate (GeditPlugin *plugin,
 		image = gtk_image_new_from_icon_name ("gucharmap",
 						      GTK_ICON_SIZE_MENU);
 
-	data->panel = create_charmap_panel (window);
+	priv->panel = create_charmap_panel (GEDIT_CHARMAP_PLUGIN (activatable));
 
 	gedit_panel_add_item (panel,
-			      data->panel,
+			      priv->panel,
 			      "GeditCharmapPanel",
 			      _("Character Map"),
 			      image);
@@ -291,47 +288,59 @@ impl_activate (GeditPlugin *plugin,
 	gtk_object_sink (GTK_OBJECT (image));
 
 	statusbar = GTK_STATUSBAR (gedit_window_get_statusbar (window));
-	data->context_id = gtk_statusbar_get_context_id (statusbar,
+	priv->context_id = gtk_statusbar_get_context_id (statusbar,
 							 "Character Description");
-
-	g_object_set_data_full (G_OBJECT (window),
-				WINDOW_DATA_KEY,
-				data,
-				(GDestroyNotify) free_window_data);
 }
 
 static void
-impl_deactivate	(GeditPlugin *plugin,
-		 GeditWindow *window)
+gedit_charmap_plugin_deactivate (GeditWindowActivatable *activatable,
+				 GeditWindow            *window)
 {
+	GeditCharmapPluginPrivate *priv;
 	GeditPanel *panel;
-	WindowData *data;
 	GucharmapChartable *chartable;
 
 	gedit_debug (DEBUG_PLUGINS);
 
-	data = (WindowData *) g_object_get_data (G_OBJECT (window),
-						 WINDOW_DATA_KEY);
-	g_return_if_fail (data != NULL);
+	priv = GEDIT_CHARMAP_PLUGIN (activatable)->priv;
 
 	chartable = gedit_charmap_panel_get_chartable
-					(GEDIT_CHARMAP_PANEL (data->panel));
-	on_table_status_message (chartable, NULL, window);
+					(GEDIT_CHARMAP_PANEL (priv->panel));
+	on_table_status_message (chartable, NULL,
+				 GEDIT_CHARMAP_PLUGIN (activatable));
 
 	panel = gedit_window_get_side_panel (window);
-	gedit_panel_remove_item (panel, data->panel);
-
-	g_object_set_data (G_OBJECT (window), WINDOW_DATA_KEY, NULL);
+	gedit_panel_remove_item (panel, priv->panel);
 }
 
 static void
 gedit_charmap_plugin_class_init (GeditCharmapPluginClass *klass)
 {
 	GObjectClass *object_class = G_OBJECT_CLASS (klass);
-	GeditPluginClass *plugin_class = GEDIT_PLUGIN_CLASS (klass);
 
 	object_class->finalize = gedit_charmap_plugin_finalize;
 
-	plugin_class->activate = impl_activate;
-	plugin_class->deactivate = impl_deactivate;
+	g_type_class_add_private (object_class, sizeof (GeditCharmapPluginPrivate));
+}
+
+static void
+gedit_charmap_plugin_class_finalize (GeditCharmapPluginClass *klass)
+{
+}
+
+static void
+gedit_window_activatable_iface_init (GeditWindowActivatableInterface *iface)
+{
+	iface->activate = gedit_charmap_plugin_activate;
+	iface->deactivate = gedit_charmap_plugin_deactivate;
+}
+
+G_MODULE_EXPORT void
+peas_register_types (PeasObjectModule *module)
+{
+	gedit_charmap_plugin_register_type (G_TYPE_MODULE (module));
+
+	peas_object_module_register_extension_type (module,
+						    GEDIT_TYPE_WINDOW_ACTIVATABLE,
+						    GEDIT_TYPE_CHARMAP_PLUGIN);
 }
diff --git a/plugins/charmap/gedit-charmap-plugin.h b/plugins/charmap/gedit-charmap-plugin.h
index 7313ef1..8d2f465 100644
--- a/plugins/charmap/gedit-charmap-plugin.h
+++ b/plugins/charmap/gedit-charmap-plugin.h
@@ -16,8 +16,6 @@
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- * $Id$
  */
 
 #ifndef __GEDIT_CHARMAP_PLUGIN_H__
@@ -25,13 +23,11 @@
 
 #include <glib.h>
 #include <glib-object.h>
-#include <gedit/gedit-plugin.h>
+#include <libpeas/peas-extension-base.h>
+#include <libpeas/peas-object-module.h>
 
 G_BEGIN_DECLS
 
-/*
- * Type checking and casting macros
- */
 #define GEDIT_TYPE_CHARMAP_PLUGIN		(gedit_charmap_plugin_get_type ())
 #define GEDIT_CHARMAP_PLUGIN(o)			(G_TYPE_CHECK_INSTANCE_CAST ((o), GEDIT_TYPE_CHARMAP_PLUGIN, GeditCharmapPlugin))
 #define GEDIT_CHARMAP_PLUGIN_CLASS(k)		(G_TYPE_CHECK_CLASS_CAST((k), GEDIT_TYPE_CHARMAP_PLUGIN, GeditCharmapPluginClass))
@@ -39,36 +35,26 @@ G_BEGIN_DECLS
 #define GEDIT_IS_CHARMAP_PLUGIN_CLASS(k)	(G_TYPE_CHECK_CLASS_TYPE ((k), GEDIT_TYPE_CHARMAP_PLUGIN))
 #define GEDIT_CHARMAP_PLUGIN_GET_CLASS(o)	(G_TYPE_INSTANCE_GET_CLASS ((o), GEDIT_TYPE_CHARMAP_PLUGIN, GeditCharmapPluginClass))
 
-/* Private structure type */
-typedef struct _GeditCharmapPluginPrivate	GeditCharmapPluginPrivate;
-
-/*
- * Main object structure
- */
 typedef struct _GeditCharmapPlugin		GeditCharmapPlugin;
+typedef struct _GeditCharmapPluginPrivate	GeditCharmapPluginPrivate;
+typedef struct _GeditCharmapPluginClass		GeditCharmapPluginClass;
 
 struct _GeditCharmapPlugin
 {
-	GeditPlugin parent_instance;
-};
+	PeasExtensionBase parent_instance;
 
-/*
- * Class definition
- */
-typedef struct _GeditCharmapPluginClass	GeditCharmapPluginClass;
+	/*< private >*/
+ 	GeditCharmapPluginPrivate *priv;
+};
 
 struct _GeditCharmapPluginClass
 {
-	GeditPluginClass parent_class;
+	PeasExtensionBaseClass parent_class;
 };
 
-/*
- * Public methods
- */
-GType	gedit_charmap_plugin_get_type	(void) G_GNUC_CONST;
+GType			gedit_charmap_plugin_get_type	(void) G_GNUC_CONST;
 
-/* All the plugins must implement this function */
-G_MODULE_EXPORT GType register_gedit_plugin (GTypeModule *module);
+G_MODULE_EXPORT void	peas_register_types		(PeasObjectModule *module);
 
 G_END_DECLS
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]