taglist-plugin: Port to libpeas

Adapted from:
2aafaabdaa
This commit is contained in:
JosephMcc 2016-12-26 13:50:48 -08:00
parent e389368a91
commit 804259fe1f
4 changed files with 197 additions and 106 deletions

View File

@ -39,7 +39,6 @@
#include <xed/xed-utils.h> #include <xed/xed-utils.h>
#include <xed/xed-debug.h> #include <xed/xed-debug.h>
#include <xed/xed-plugin.h>
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h> #include <gdk/gdkkeysyms.h>
@ -65,11 +64,11 @@ struct _XedTaglistPluginPanelPrivate
GtkWidget *preview; GtkWidget *preview;
TagGroup *selected_tag_group; TagGroup *selected_tag_group;
gchar *data_dir; gchar *data_dir;
}; };
XED_PLUGIN_DEFINE_TYPE (XedTaglistPluginPanel, xed_taglist_plugin_panel, GTK_TYPE_BOX) G_DEFINE_DYNAMIC_TYPE (XedTaglistPluginPanel, xed_taglist_plugin_panel, GTK_TYPE_BOX)
enum enum
{ {
@ -133,7 +132,7 @@ static void
xed_taglist_plugin_panel_finalize (GObject *object) xed_taglist_plugin_panel_finalize (GObject *object)
{ {
XedTaglistPluginPanel *panel = XED_TAGLIST_PLUGIN_PANEL (object); XedTaglistPluginPanel *panel = XED_TAGLIST_PLUGIN_PANEL (object);
g_free (panel->priv->data_dir); g_free (panel->priv->data_dir);
G_OBJECT_CLASS (xed_taglist_plugin_panel_parent_class)->finalize (object); G_OBJECT_CLASS (xed_taglist_plugin_panel_parent_class)->finalize (object);
@ -160,6 +159,12 @@ xed_taglist_plugin_panel_class_init (XedTaglistPluginPanelClass *klass)
g_type_class_add_private (object_class, sizeof(XedTaglistPluginPanelPrivate)); g_type_class_add_private (object_class, sizeof(XedTaglistPluginPanelPrivate));
} }
static void
xed_taglist_plugin_panel_class_finalize (XedTaglistPluginPanelClass *klass)
{
/* dummy function - used by G_DEFINE_DYNAMIC_TYPE */
}
static void static void
insert_tag (XedTaglistPluginPanel *panel, insert_tag (XedTaglistPluginPanel *panel,
Tag *tag, Tag *tag,
@ -431,7 +436,7 @@ selected_group_changed (GtkComboBox *combo,
populate_tags_list (panel); populate_tags_list (panel);
} }
/* Clean up preview */ /* Clean up preview */
gtk_label_set_text (GTK_LABEL (panel->priv->preview), gtk_label_set_text (GTK_LABEL (panel->priv->preview),
""); "");
@ -781,8 +786,14 @@ xed_taglist_plugin_panel_new (XedWindow *window,
panel = g_object_new (XED_TYPE_TAGLIST_PLUGIN_PANEL, panel = g_object_new (XED_TYPE_TAGLIST_PLUGIN_PANEL,
"window", window, "window", window,
NULL); NULL);
panel->priv->data_dir = g_strdup (data_dir); panel->priv->data_dir = g_strdup (data_dir);
return GTK_WIDGET (panel); return GTK_WIDGET (panel);
} }
void
_xed_taglist_plugin_panel_register_type (GTypeModule *type_module)
{
xed_taglist_plugin_panel_register_type (type_module);
}

View File

@ -2,7 +2,7 @@
* xed-taglist-plugin-panel.h * xed-taglist-plugin-panel.h
* This file is part of xed * This file is part of xed
* *
* Copyright (C) 2005 - Paolo Maggi * Copyright (C) 2005 - Paolo Maggi
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -16,14 +16,14 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, * Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA. * Boston, MA 02110-1301, USA.
*/ */
/* /*
* Modified by the xed Team, 2005. See the AUTHORS file for a * Modified by the xed Team, 2005. See the AUTHORS file for a
* list of people on the xed Team. * list of people on the xed Team.
* See the ChangeLog files for a list of changes. * See the ChangeLog files for a list of changes.
* *
* $Id$ * $Id$
*/ */
@ -56,12 +56,12 @@ typedef struct _XedTaglistPluginPanelPrivate XedTaglistPluginPanelPrivate;
*/ */
typedef struct _XedTaglistPluginPanel XedTaglistPluginPanel; typedef struct _XedTaglistPluginPanel XedTaglistPluginPanel;
struct _XedTaglistPluginPanel struct _XedTaglistPluginPanel
{ {
GtkBox vbox; GtkBox vbox;
/*< private > */ /*< private > */
XedTaglistPluginPanelPrivate *priv; XedTaglistPluginPanelPrivate *priv;
}; };
/* /*
@ -69,20 +69,20 @@ struct _XedTaglistPluginPanel
*/ */
typedef struct _XedTaglistPluginPanelClass XedTaglistPluginPanelClass; typedef struct _XedTaglistPluginPanelClass XedTaglistPluginPanelClass;
struct _XedTaglistPluginPanelClass struct _XedTaglistPluginPanelClass
{ {
GtkBoxClass parent_class; GtkBoxClass parent_class;
}; };
/* /*
* Public methods * Public methods
*/ */
GType xed_taglist_plugin_panel_register_type (GTypeModule *module); void _xed_taglist_plugin_panel_register_type (GTypeModule *module);
GType xed_taglist_plugin_panel_get_type (void) G_GNUC_CONST;
GtkWidget *xed_taglist_plugin_panel_new (XedWindow *window, GType xed_taglist_plugin_panel_get_type (void) G_GNUC_CONST;
const gchar *data_dir);
GtkWidget *xed_taglist_plugin_panel_new (XedWindow *window,
const gchar *data_dir);
G_END_DECLS G_END_DECLS

View File

@ -1,6 +1,6 @@
/* /*
* xed-taglist-plugin.h * xed-taglist-plugin.h
* *
* Copyright (C) 2002-2005 - Paolo Maggi * Copyright (C) 2002-2005 - Paolo Maggi
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -20,9 +20,9 @@
*/ */
/* /*
* Modified by the xed Team, 2002-2005. See the AUTHORS file for a * Modified by the xed Team, 2002-2005. See the AUTHORS file for a
* list of people on the xed Team. * list of people on the xed Team.
* See the ChangeLog files for a list of changes. * See the ChangeLog files for a list of changes.
* *
* $Id$ * $Id$
*/ */
@ -37,23 +37,38 @@
#include <glib/gi18n-lib.h> #include <glib/gi18n-lib.h>
#include <gmodule.h> #include <gmodule.h>
#include <libpeas/peas-activatable.h>
#include <xed/xed-plugin.h> #include <xed/xed-window.h>
#include <xed/xed-debug.h> #include <xed/xed-debug.h>
#define WINDOW_DATA_KEY "XedTaglistPluginWindowData"
#define XED_TAGLIST_PLUGIN_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), XED_TYPE_TAGLIST_PLUGIN, XedTaglistPluginPrivate)) #define XED_TAGLIST_PLUGIN_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), XED_TYPE_TAGLIST_PLUGIN, XedTaglistPluginPrivate))
struct _XedTaglistPluginPrivate struct _XedTaglistPluginPrivate
{ {
gpointer dummy; GtkWidget *window;
GtkWidget *taglist_panel;
}; };
XED_PLUGIN_REGISTER_TYPE_WITH_CODE (XedTaglistPlugin, xed_taglist_plugin, static void peas_activatable_iface_init (PeasActivatableInterface *iface);
xed_taglist_plugin_panel_register_type (module);
G_DEFINE_DYNAMIC_TYPE_EXTENDED (XedTaglistPlugin,
xed_taglist_plugin,
PEAS_TYPE_EXTENSION_BASE,
0,
G_IMPLEMENT_INTERFACE_DYNAMIC (PEAS_TYPE_ACTIVATABLE,
peas_activatable_iface_init) \
\
_xed_taglist_plugin_panel_register_type (type_module); \
) )
enum
{
PROP_0,
PROP_OBJECT
};
static void static void
xed_taglist_plugin_init (XedTaglistPlugin *plugin) xed_taglist_plugin_init (XedTaglistPlugin *plugin)
{ {
@ -62,99 +77,163 @@ xed_taglist_plugin_init (XedTaglistPlugin *plugin)
xed_debug_message (DEBUG_PLUGINS, "XedTaglistPlugin initializing"); xed_debug_message (DEBUG_PLUGINS, "XedTaglistPlugin initializing");
} }
static void
xed_taglist_plugin_dispose (GObject *object)
{
XedTaglistPlugin *plugin = XED_TAGLIST_PLUGIN (object);
xed_debug_message (DEBUG_PLUGINS, "XedTaglistPlugin disposing");
if (plugin->priv->window != NULL)
{
g_object_unref (plugin->priv->window);
plugin->priv->window = NULL;
}
G_OBJECT_CLASS (xed_taglist_plugin_parent_class)->dispose (object);
}
static void static void
xed_taglist_plugin_finalize (GObject *object) xed_taglist_plugin_finalize (GObject *object)
{ {
/* xed_debug_message (DEBUG_PLUGINS, "XedTaglistPlugin finalizing");
XedTaglistPlugin *plugin = XED_TAGLIST_PLUGIN (object);
*/
xed_debug_message (DEBUG_PLUGINS, "XedTaglistPlugin finalizing");
free_taglist (); free_taglist ();
G_OBJECT_CLASS (xed_taglist_plugin_parent_class)->finalize (object); G_OBJECT_CLASS (xed_taglist_plugin_parent_class)->finalize (object);
} }
static void static void
impl_activate (XedPlugin *plugin, xed_taglist_plugin_activate (PeasActivatable *activatable)
XedWindow *window)
{ {
XedTaglistPluginPrivate *priv;
XedWindow *window;
XedPanel *side_panel; XedPanel *side_panel;
GtkWidget *taglist_panel;
gchar *data_dir; gchar *data_dir;
xed_debug (DEBUG_PLUGINS); xed_debug (DEBUG_PLUGINS);
g_return_if_fail (g_object_get_data (G_OBJECT (window), WINDOW_DATA_KEY) == NULL); priv = XED_TAGLIST_PLUGIN (activatable)->priv;
window = XED_WINDOW (priv->window);
side_panel = xed_window_get_side_panel (window); side_panel = xed_window_get_side_panel (window);
data_dir = xed_plugin_get_data_dir (plugin); data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (activatable));
taglist_panel = xed_taglist_plugin_panel_new (window, data_dir); priv->taglist_panel = xed_taglist_plugin_panel_new (window, data_dir);
g_free (data_dir); g_free (data_dir);
xed_panel_add_item_with_stock_icon (side_panel,
taglist_panel,
_("Tags"),
GTK_STOCK_ADD);
g_object_set_data (G_OBJECT (window), xed_panel_add_item_with_stock_icon (side_panel,
WINDOW_DATA_KEY, priv->taglist_panel,
taglist_panel); _("Tags"),
GTK_STOCK_ADD);
} }
static void static void
impl_deactivate (XedPlugin *plugin, xed_taglist_plugin_deactivate (PeasActivatable *activatable)
XedWindow *window)
{ {
XedTaglistPluginPrivate *priv;
XedWindow *window;
XedPanel *side_panel; XedPanel *side_panel;
gpointer data;
xed_debug (DEBUG_PLUGINS); xed_debug (DEBUG_PLUGINS);
data = g_object_get_data (G_OBJECT (window), WINDOW_DATA_KEY); priv = XED_TAGLIST_PLUGIN (activatable)->priv;
g_return_if_fail (data != NULL); window = XED_WINDOW (priv->window);
side_panel = xed_window_get_side_panel (window); side_panel = xed_window_get_side_panel (window);
xed_panel_remove_item (side_panel, xed_panel_remove_item (side_panel, priv->taglist_panel);
GTK_WIDGET (data));
g_object_set_data (G_OBJECT (window),
WINDOW_DATA_KEY,
NULL);
} }
static void static void
impl_update_ui (XedPlugin *plugin, xed_taglist_plugin_update_state (PeasActivatable *activatable)
XedWindow *window)
{ {
gpointer data; XedTaglistPluginPrivate *priv;
XedWindow *window;
XedView *view; XedView *view;
xed_debug (DEBUG_PLUGINS); xed_debug (DEBUG_PLUGINS);
data = g_object_get_data (G_OBJECT (window), WINDOW_DATA_KEY); priv = XED_TAGLIST_PLUGIN (activatable)->priv;
g_return_if_fail (data != NULL); window = XED_WINDOW (priv->window);
view = xed_window_get_active_view (window); view = xed_window_get_active_view (window);
gtk_widget_set_sensitive (GTK_WIDGET (data), gtk_widget_set_sensitive (priv->taglist_panel,
(view != NULL) && (view != NULL) &&
gtk_text_view_get_editable (GTK_TEXT_VIEW (view))); gtk_text_view_get_editable (GTK_TEXT_VIEW (view)));
} }
static void
xed_taglist_plugin_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
XedTaglistPlugin *plugin = XED_TAGLIST_PLUGIN (object);
switch (prop_id)
{
case PROP_OBJECT:
plugin->priv->window = GTK_WIDGET (g_value_dup_object (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
xed_taglist_plugin_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
XedTaglistPlugin *plugin = XED_TAGLIST_PLUGIN (object);
switch (prop_id)
{
case PROP_OBJECT:
g_value_set_object (value, plugin->priv->window);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void static void
xed_taglist_plugin_class_init (XedTaglistPluginClass *klass) xed_taglist_plugin_class_init (XedTaglistPluginClass *klass)
{ {
GObjectClass *object_class = G_OBJECT_CLASS (klass); GObjectClass *object_class = G_OBJECT_CLASS (klass);
XedPluginClass *plugin_class = XED_PLUGIN_CLASS (klass);
object_class->finalize = xed_taglist_plugin_finalize; object_class->finalize = xed_taglist_plugin_finalize;
object_class->dispose = xed_taglist_plugin_dispose;
object_class->set_property = xed_taglist_plugin_set_property;
object_class->get_property = xed_taglist_plugin_get_property;
plugin_class->activate = impl_activate; g_object_class_override_property (object_class, PROP_OBJECT, "object");
plugin_class->deactivate = impl_deactivate;
plugin_class->update_ui = impl_update_ui;
g_type_class_add_private (object_class, sizeof (XedTaglistPluginPrivate)); g_type_class_add_private (object_class, sizeof (XedTaglistPluginPrivate));
} }
static void
xed_taglist_plugin_class_finalize (XedTaglistPluginClass *klass)
{
/* dummy function - used by G_DEFINE_DYNAMIC_TYPE_EXTENDED */
}
static void
peas_activatable_iface_init (PeasActivatableInterface *iface)
{
iface->activate = xed_taglist_plugin_activate;
iface->deactivate = xed_taglist_plugin_deactivate;
iface->update_state = xed_taglist_plugin_update_state;
}
G_MODULE_EXPORT void
peas_register_types (PeasObjectModule *module)
{
xed_taglist_plugin_register_type (G_TYPE_MODULE (module));
peas_object_module_register_extension_type (module,
PEAS_TYPE_ACTIVATABLE,
XED_TYPE_TAGLIST_PLUGIN);
}

View File

@ -1,6 +1,6 @@
/* /*
* xed-taglist-plugin.h * xed-taglist-plugin.h
* *
* Copyright (C) 2002-2005 - Paolo Maggi * Copyright (C) 2002-2005 - Paolo Maggi
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -20,65 +20,66 @@
*/ */
/* /*
* Modified by the xed Team, 2002-2005. See the AUTHORS file for a * Modified by the xed Team, 2002-2005. See the AUTHORS file for a
* list of people on the xed Team. * list of people on the xed Team.
* See the ChangeLog files for a list of changes. * See the ChangeLog files for a list of changes.
* *
* $Id$ * $Id$
*/ */
#ifndef __XED_TAGLIST_PLUGIN_H__ #ifndef __XED_TAGLIST_PLUGIN_H__
#define __XED_TAGLIST_PLUGIN_H__ #define __XED_TAGLIST_PLUGIN_H__
#include <glib.h> #include <glib.h>
#include <glib-object.h> #include <glib-object.h>
#include <xed/xed-plugin.h> #include <libpeas/peas-extension-base.h>
#include <libpeas/peas-object-module.h>
G_BEGIN_DECLS G_BEGIN_DECLS
/* /*
* Type checking and casting macros * Type checking and casting macros
*/ */
#define XED_TYPE_TAGLIST_PLUGIN (xed_taglist_plugin_get_type ()) #define XED_TYPE_TAGLIST_PLUGIN (xed_taglist_plugin_get_type ())
#define XED_TAGLIST_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), XED_TYPE_TAGLIST_PLUGIN, XedTaglistPlugin)) #define XED_TAGLIST_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), XED_TYPE_TAGLIST_PLUGIN, XedTaglistPlugin))
#define XED_TAGLIST_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), XED_TYPE_TAGLIST_PLUGIN, XedTaglistPluginClass)) #define XED_TAGLIST_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), XED_TYPE_TAGLIST_PLUGIN, XedTaglistPluginClass))
#define XED_IS_TAGLIST_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), XED_TYPE_TAGLIST_PLUGIN)) #define XED_IS_TAGLIST_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), XED_TYPE_TAGLIST_PLUGIN))
#define XED_IS_TAGLIST_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), XED_TYPE_TAGLIST_PLUGIN)) #define XED_IS_TAGLIST_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), XED_TYPE_TAGLIST_PLUGIN))
#define XED_TAGLIST_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), XED_TYPE_TAGLIST_PLUGIN, XedTaglistPluginClass)) #define XED_TAGLIST_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), XED_TYPE_TAGLIST_PLUGIN, XedTaglistPluginClass))
/* Private structure type */ /* Private structure type */
typedef struct _XedTaglistPluginPrivate XedTaglistPluginPrivate; typedef struct _XedTaglistPluginPrivate XedTaglistPluginPrivate;
/* /*
* Main object structure * Main object structure
*/ */
typedef struct _XedTaglistPlugin XedTaglistPlugin; typedef struct _XedTaglistPlugin XedTaglistPlugin;
struct _XedTaglistPlugin struct _XedTaglistPlugin
{ {
XedPlugin parent_instance; PeasExtensionBase parent_instance;
/*< private >*/ /*< private >*/
XedTaglistPluginPrivate *priv; XedTaglistPluginPrivate *priv;
}; };
/* /*
* Class definition * Class definition
*/ */
typedef struct _XedTaglistPluginClass XedTaglistPluginClass; typedef struct _XedTaglistPluginClass XedTaglistPluginClass;
struct _XedTaglistPluginClass struct _XedTaglistPluginClass
{ {
XedPluginClass parent_class; PeasExtensionBaseClass parent_class;
}; };
/* /*
* Public methods * Public methods
*/ */
GType xed_taglist_plugin_get_type (void) G_GNUC_CONST; GType xed_taglist_plugin_get_type (void) G_GNUC_CONST;
/* All the plugins must implement this function */ /* All the plugins must implement this function */
G_MODULE_EXPORT GType register_xed_plugin (GTypeModule *module); G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module);
G_END_DECLS G_END_DECLS