summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormonsta <[email protected]>2016-11-30 22:03:09 +0300
committermonsta <[email protected]>2016-11-30 22:34:49 +0300
commit5ee13bce9f5c4672d24006be64790bd206b68319 (patch)
tree7cfe6022cf9f3805a9beb3beb7270bcd060ccbe9
parentceae2747ae3fc8fc5319351643f841f9bb956f0f (diff)
downloadeom-5ee13bce9f5c4672d24006be64790bd206b68319.tar.bz2
eom-5ee13bce9f5c4672d24006be64790bd206b68319.tar.xz
statusbar-date plugin: port to libpeas
mostly adapted from: https://git.gnome.org/browse/eog/commit/?id=cf39e40b422dad061184ac67028661bd4dcb0106 https://git.gnome.org/browse/eog/commit/?id=8b0acfddc52c220393770a9895b6b56cab7821fd
-rw-r--r--plugins/statusbar-date/eom-statusbar-date-plugin.c160
-rw-r--r--plugins/statusbar-date/eom-statusbar-date-plugin.h14
2 files changed, 115 insertions, 59 deletions
diff --git a/plugins/statusbar-date/eom-statusbar-date-plugin.c b/plugins/statusbar-date/eom-statusbar-date-plugin.c
index 12c742d..bacb0b5 100644
--- a/plugins/statusbar-date/eom-statusbar-date-plugin.c
+++ b/plugins/statusbar-date/eom-statusbar-date-plugin.c
@@ -27,6 +27,7 @@
#include <gmodule.h>
#include <glib/gi18n-lib.h>
+#include <libpeas/peas-activatable.h>
#include <eom-debug.h>
#include <eom-image.h>
@@ -34,25 +35,19 @@
#include <eom-window.h>
#include <eom-exif-util.h>
+static void peas_activatable_iface_init (PeasActivatableInterface *iface);
-#define WINDOW_DATA_KEY "EomStatusbarDateWindowData"
+G_DEFINE_DYNAMIC_TYPE_EXTENDED (EomStatusbarDatePlugin,
+ eom_statusbar_date_plugin,
+ PEAS_TYPE_EXTENSION_BASE,
+ 0,
+ G_IMPLEMENT_INTERFACE_DYNAMIC (PEAS_TYPE_ACTIVATABLE,
+ peas_activatable_iface_init))
-EOM_PLUGIN_REGISTER_TYPE (EomStatusbarDatePlugin, eom_statusbar_date_plugin)
-
-typedef struct {
- GtkWidget* statusbar_date;
- gulong signal_id;
-} WindowData;
-
-static void
-free_window_data (WindowData *data)
-{
- g_return_if_fail (data != NULL);
-
- eom_debug (DEBUG_PLUGINS);
-
- g_free (data);
-}
+enum {
+ PROP_0,
+ PROP_OBJECT
+};
static void
statusbar_set_date (GtkStatusbar *statusbar,
@@ -101,10 +96,50 @@ statusbar_set_date (GtkStatusbar *statusbar,
}
static void
-selection_changed_cb (EomThumbView *view,
- WindowData *data)
+selection_changed_cb (EomThumbView *view,
+ EomStatusbarDatePlugin *plugin)
+{
+ statusbar_set_date (GTK_STATUSBAR (plugin->statusbar_date), view);
+}
+
+static void
+eom_statusbar_date_plugin_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
- statusbar_set_date (GTK_STATUSBAR (data->statusbar_date), view);
+ EomStatusbarDatePlugin *plugin = EOM_STATUSBAR_DATE_PLUGIN (object);
+
+ switch (prop_id)
+ {
+ case PROP_OBJECT:
+ plugin->window = GTK_WIDGET (g_value_dup_object (value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+eom_statusbar_date_plugin_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ EomStatusbarDatePlugin *plugin = EOM_STATUSBAR_DATE_PLUGIN (object);
+
+ switch (prop_id)
+ {
+ case PROP_OBJECT:
+ g_value_set_object (value, plugin->window);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
}
static void
@@ -114,71 +149,86 @@ eom_statusbar_date_plugin_init (EomStatusbarDatePlugin *plugin)
}
static void
-eom_statusbar_date_plugin_finalize (GObject *object)
+eom_statusbar_date_plugin_dispose (GObject *object)
{
- eom_debug_message (DEBUG_PLUGINS, "EomStatusbarDatePlugin finalizing");
+ EomStatusbarDatePlugin *plugin = EOM_STATUSBAR_DATE_PLUGIN (object);
+
+ eom_debug_message (DEBUG_PLUGINS, "EomStatusbarDatePlugin disposing");
- G_OBJECT_CLASS (eom_statusbar_date_plugin_parent_class)->finalize (object);
+ if (plugin->window != NULL) {
+ g_object_unref (plugin->window);
+ plugin->window = NULL;
+ }
+
+ G_OBJECT_CLASS (eom_statusbar_date_plugin_parent_class)->dispose (object);
}
static void
-impl_activate (EomPlugin *plugin,
- EomWindow *window)
+eom_statusbar_date_plugin_activate (PeasActivatable *activatable)
{
+ EomStatusbarDatePlugin *plugin = EOM_STATUSBAR_DATE_PLUGIN (activatable);
+ EomWindow *window = EOM_WINDOW (plugin->window);
GtkWidget *statusbar = eom_window_get_statusbar (window);
GtkWidget *thumbview = eom_window_get_thumb_view (window);
- WindowData *data;
eom_debug (DEBUG_PLUGINS);
- data = g_new (WindowData, 1);
- data->statusbar_date = gtk_statusbar_new ();
- gtk_widget_set_size_request (data->statusbar_date, 200, 10);
- gtk_widget_set_margin_top (GTK_WIDGET (data->statusbar_date), 0);
- gtk_widget_set_margin_bottom (GTK_WIDGET (data->statusbar_date), 0);
- gtk_box_pack_end (GTK_BOX (statusbar), data->statusbar_date, FALSE, FALSE, 0);
-
- data->signal_id = g_signal_connect_after (G_OBJECT (thumbview), "selection_changed",
- G_CALLBACK (selection_changed_cb), data);
+ plugin->statusbar_date = gtk_statusbar_new ();
+ gtk_widget_set_size_request (plugin->statusbar_date, 200, 10);
+ gtk_widget_set_margin_top (GTK_WIDGET (plugin->statusbar_date), 0);
+ gtk_widget_set_margin_bottom (GTK_WIDGET (plugin->statusbar_date), 0);
+ gtk_box_pack_end (GTK_BOX (statusbar), plugin->statusbar_date, FALSE, FALSE, 0);
- statusbar_set_date (GTK_STATUSBAR (data->statusbar_date), EOM_THUMB_VIEW (eom_window_get_thumb_view (window)));
+ plugin->signal_id = g_signal_connect_after (G_OBJECT (thumbview), "selection_changed",
+ G_CALLBACK (selection_changed_cb), plugin);
- g_object_set_data_full (G_OBJECT (window), WINDOW_DATA_KEY, data, (GDestroyNotify) free_window_data);
+ statusbar_set_date (GTK_STATUSBAR (plugin->statusbar_date),
+ EOM_THUMB_VIEW (eom_window_get_thumb_view (window)));
}
static void
-impl_deactivate (EomPlugin *plugin,
- EomWindow *window)
+eom_statusbar_date_plugin_deactivate (PeasActivatable *activatable)
{
+ EomStatusbarDatePlugin *plugin = EOM_STATUSBAR_DATE_PLUGIN (activatable);
+ EomWindow *window = EOM_WINDOW (plugin->window);
GtkWidget *statusbar = eom_window_get_statusbar (window);
GtkWidget *view = eom_window_get_thumb_view (window);
- WindowData *data;
- data = (WindowData *) g_object_get_data (G_OBJECT (window), WINDOW_DATA_KEY);
+ g_signal_handler_disconnect (view, plugin->signal_id);
- g_signal_handler_disconnect (view, data->signal_id);
+ gtk_container_remove (GTK_CONTAINER (statusbar), plugin->statusbar_date);
+}
- gtk_container_remove (GTK_CONTAINER (statusbar), data->statusbar_date);
+static void
+eom_statusbar_date_plugin_class_init (EomStatusbarDatePluginClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
- g_object_set_data (G_OBJECT(window), WINDOW_DATA_KEY, NULL);
+ object_class->dispose = eom_statusbar_date_plugin_dispose;
+ object_class->set_property = eom_statusbar_date_plugin_set_property;
+ object_class->get_property = eom_statusbar_date_plugin_get_property;
+
+ g_object_class_override_property (object_class, PROP_OBJECT, "object");
}
static void
-impl_update_ui (EomPlugin *plugin,
- EomWindow *window)
+eom_statusbar_date_plugin_class_finalize (EomStatusbarDatePluginClass *klass)
{
- /* nothing */
+ /* dummy function - used by G_DEFINE_DYNAMIC_TYPE_EXTENDED */
}
static void
-eom_statusbar_date_plugin_class_init (EomStatusbarDatePluginClass *klass)
+peas_activatable_iface_init (PeasActivatableInterface *iface)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- EomPluginClass *plugin_class = EOM_PLUGIN_CLASS (klass);
-
- object_class->finalize = eom_statusbar_date_plugin_finalize;
+ iface->activate = eom_statusbar_date_plugin_activate;
+ iface->deactivate = eom_statusbar_date_plugin_deactivate;
+}
- plugin_class->activate = impl_activate;
- plugin_class->deactivate = impl_deactivate;
- plugin_class->update_ui = impl_update_ui;
+G_MODULE_EXPORT void
+peas_register_types (PeasObjectModule *module)
+{
+ eom_statusbar_date_plugin_register_type (G_TYPE_MODULE (module));
+ peas_object_module_register_extension_type (module,
+ PEAS_TYPE_ACTIVATABLE,
+ EOM_TYPE_STATUSBAR_DATE_PLUGIN);
}
diff --git a/plugins/statusbar-date/eom-statusbar-date-plugin.h b/plugins/statusbar-date/eom-statusbar-date-plugin.h
index 0718bbe..b779fce 100644
--- a/plugins/statusbar-date/eom-statusbar-date-plugin.h
+++ b/plugins/statusbar-date/eom-statusbar-date-plugin.h
@@ -24,7 +24,9 @@
#include <glib.h>
#include <glib-object.h>
-#include <eom-plugin.h>
+#include <gtk/gtk.h>
+#include <libpeas/peas-extension-base.h>
+#include <libpeas/peas-object-module.h>
G_BEGIN_DECLS
@@ -53,7 +55,11 @@ typedef struct _EomStatusbarDatePluginPrivate EomStatusbarDatePluginPrivate;
typedef struct _EomStatusbarDatePlugin EomStatusbarDatePlugin;
struct _EomStatusbarDatePlugin {
- EomPlugin parent_instance;
+ PeasExtensionBase parent_instance;
+
+ GtkWidget *window;
+ GtkWidget *statusbar_date;
+ gulong signal_id;
};
/*
@@ -62,7 +68,7 @@ struct _EomStatusbarDatePlugin {
typedef struct _EomStatusbarDatePluginClass EomStatusbarDatePluginClass;
struct _EomStatusbarDatePluginClass {
- EomPluginClass parent_class;
+ PeasExtensionBaseClass parent_class;
};
/*
@@ -71,7 +77,7 @@ struct _EomStatusbarDatePluginClass {
GType eom_statusbar_date_plugin_get_type (void) G_GNUC_CONST;
/* All the plugins must implement this function */
-G_MODULE_EXPORT GType register_eom_plugin (GTypeModule* module);
+G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module);
G_END_DECLS