[eog] Port the plugin system to use libpeas
- From: Felix Riemann <friemann src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [eog] Port the plugin system to use libpeas
- Date: Sun, 2 Jan 2011 23:42:24 +0000 (UTC)
commit 1f79c321367c91c8e9063f1343a7e4ce4199c4d5
Author: Claudio Saavedra <csaavedra igalia com>
Date: Wed Aug 4 16:55:34 2010 +0300
Port the plugin system to use libpeas
This removes the internal implementation of EogPlugin,
EogPluginManager, EogModule, and EogPluginEngine in favor of the
implementation in libpeas and libpeasui.
https://bugzilla.gnome.org/show_bug.cgi?id=626091
configure.ac | 4 +-
src/Makefile.am | 8 +-
src/eog-application.c | 5 +
src/eog-application.h | 2 +
src/eog-module.c | 167 --------
src/eog-module.h | 72 ----
src/eog-plugin-engine.c | 929 ++---------------------------------------
src/eog-plugin-engine.h | 73 +---
src/eog-plugin-manager.c | 917 -----------------------------------------
src/eog-plugin-manager.h | 61 ---
src/eog-plugin.c | 108 -----
src/eog-plugin.h | 222 ----------
src/eog-preferences-dialog.c | 5 +-
src/eog-window.c | 46 ++-
src/main.c | 3 -
15 files changed, 125 insertions(+), 2497 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 0d413f5..be7e893 100644
--- a/configure.ac
+++ b/configure.ac
@@ -103,7 +103,9 @@ EOG_MODULES="gtk+-3.0 >= $GTK_REQUIRED \
gtk+-unix-print-3.0 >= $GTK_PRINT_REQUIRED \
gnome-icon-theme >= $GNOME_ICON_THEME_REQUIRED \
shared-mime-info >= $SHARED_MIME_INFO_REQUIRED \
- gsettings-desktop-schemas >= $DESKTOP_SCHEMAS_REQUIRED"
+ gsettings-desktop-schemas >= $DESKTOP_SCHEMAS_REQUIRED \
+ libpeas-1.0 >= 0.5.3 \
+ libpeasui-1.0 >= 0.5.3"
# ***************
# ZLIB (required)
diff --git a/src/Makefile.am b/src/Makefile.am
index 371333e..6bbe43d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -33,8 +33,6 @@ NOINST_H_FILES = \
eog-print-image-setup.h \
eog-print-preview.h \
eog-print.h \
- eog-module.h \
- eog-plugin-manager.h \
eog-plugin-engine.h \
uta.h \
eog-close-confirmation-dialog.h \
@@ -67,8 +65,7 @@ INST_H_FILES = \
eog-list-store.h \
eog-thumbnail.h \
eog-job-queue.h \
- eog-jobs.h \
- eog-plugin.h
+ eog-jobs.h
libeog_la_SOURCES = \
eog-application.c \
@@ -103,10 +100,7 @@ libeog_la_SOURCES = \
eog-print-image-setup.c \
eog-print-preview.c \
eog-print.c \
- eog-module.c \
eog-close-confirmation-dialog.c \
- eog-plugin.c \
- eog-plugin-manager.c \
eog-plugin-engine.c \
eog-clipboard-handler.c \
uta.c \
diff --git a/src/eog-application.c b/src/eog-application.c
index d0f22f9..012ca32 100644
--- a/src/eog-application.c
+++ b/src/eog-application.c
@@ -141,6 +141,7 @@ eog_application_init (EogApplication *eog_application)
eog_session_init (eog_application);
eog_application->toolbars_model = egg_toolbars_model_new ();
+ eog_application->plugin_engine = eog_plugin_engine_new ();
egg_toolbars_model_load_names (eog_application->toolbars_model,
EOG_DATA_DIR "/eog-toolbar.xml");
@@ -417,6 +418,10 @@ eog_application_shutdown (EogApplication *application)
g_free (application->toolbars_file);
application->toolbars_file = NULL;
}
+ if (application->plugin_engine) {
+ g_object_unref (application->plugin_engine);
+ application->plugin_engine = NULL;
+ }
eog_application_save_accelerators ();
diff --git a/src/eog-application.h b/src/eog-application.h
index 9254f37..1385dbd 100644
--- a/src/eog-application.h
+++ b/src/eog-application.h
@@ -27,6 +27,7 @@
#include "eog-window.h"
#include "egg-toolbars-model.h"
+#include "eog-plugin-engine.h"
#ifdef HAVE_DBUS
#include "totem-scrsaver.h"
@@ -55,6 +56,7 @@ struct _EogApplication {
EggToolbarsModel *toolbars_model;
gchar *toolbars_file;
+ EogPluginEngine *plugin_engine;
#ifdef HAVE_DBUS
TotemScrsaver *scr_saver;
#endif
diff --git a/src/eog-plugin-engine.c b/src/eog-plugin-engine.c
index 9700ed3..a8d083e 100644
--- a/src/eog-plugin-engine.c
+++ b/src/eog-plugin-engine.c
@@ -29,8 +29,6 @@
#include <string.h>
#include "eog-plugin-engine.h"
-#include "eog-plugin.h"
-#include "eog-module.h"
#include "eog-debug.h"
#include "eog-application.h"
#include "eog-config-keys.h"
@@ -39,6 +37,7 @@
#include <glib/gi18n.h>
#include <glib.h>
#include <gio/gio.h>
+#include <girepository.h>
#ifdef ENABLE_PYTHON
#include "eog-python-module.h"
@@ -46,919 +45,83 @@
#define USER_EOG_PLUGINS_LOCATION "plugins/"
-#define EOG_PLUGINS_ENGINE_BASE_KEY "/apps/eog/plugins"
-
#define PLUGIN_EXT ".eog-plugin"
-typedef enum {
- EOG_PLUGIN_LOADER_C,
- EOG_PLUGIN_LOADER_PY,
-} EogPluginLoader;
-
-struct _EogPluginInfo
-{
- gchar *file;
-
- gchar *location;
- EogPluginLoader loader;
- GTypeModule *module;
-
- gchar *name;
- gchar *desc;
- gchar *icon_name;
- gchar **authors;
- gchar *copyright;
- gchar *website;
+G_DEFINE_TYPE (EogPluginEngine, eog_plugin_engine, PEAS_TYPE_ENGINE)
- EogPlugin *plugin;
-
- gint active : 1;
-
- /* A plugin is unavailable if it is not possible to activate it
- due to an error loading the plugin module (e.g. for Python plugins
- when the interpreter has not been correctly initializated) */
- gint available : 1;
+struct _EogPluginEnginePrivate {
+ GSettings *plugins_settings;
};
-static void eog_plugin_engine_active_plugins_changed (GSettings *settings,
- gchar *key,
- gpointer user_data);
-
-static GList *eog_plugins_list = NULL;
-
-static GSettings *eog_plugin_engine_settings = NULL;
-
-static GSList *active_plugins = NULL;
-
-static void
-eog_plugin_info_free (EogPluginInfo *info)
-{
- if (info->plugin != NULL) {
- eog_debug_message (DEBUG_PLUGINS, "Unref plugin %s", info->name);
-
- g_object_unref (info->plugin);
- }
-
- g_free (info->file);
- g_free (info->location);
- g_free (info->name);
- g_free (info->desc);
- g_free (info->icon_name);
- g_free (info->website);
- g_free (info->copyright);
- g_strfreev (info->authors);
-
- g_free (info);
-}
-
-static EogPluginInfo *
-eog_plugin_engine_load (const gchar *file)
-{
- EogPluginInfo *info;
- GKeyFile *plugin_file = NULL;
- gchar *str;
-
- g_return_val_if_fail (file != NULL, NULL);
-
- eog_debug_message (DEBUG_PLUGINS, "Loading plugin: %s", file);
-
- info = g_new0 (EogPluginInfo, 1);
- info->file = g_strdup (file);
-
- plugin_file = g_key_file_new ();
-
- if (!g_key_file_load_from_file (plugin_file, file, G_KEY_FILE_NONE, NULL)) {
- g_warning ("Bad plugin file: %s", file);
-
- goto error;
- }
-
- if (!g_key_file_has_key (plugin_file,
- "Eog Plugin",
- "IAge",
- NULL)) {
- eog_debug_message (DEBUG_PLUGINS,
- "IAge key does not exist in file: %s", file);
-
- goto error;
- }
-
- /* Check IAge=2 */
- if (g_key_file_get_integer (plugin_file,
- "Eog Plugin",
- "IAge",
- NULL) != 2) {
- eog_debug_message (DEBUG_PLUGINS,
- "Wrong IAge in file: %s", file);
-
- goto error;
- }
-
- /* Get Location */
- str = g_key_file_get_string (plugin_file,
- "Eog Plugin",
- "Module",
- NULL);
-
- if ((str != NULL) && (*str != '\0')) {
- info->location = str;
- } else {
- g_warning ("Could not find 'Module' in %s", file);
-
- goto error;
- }
-
- /* Get the loader for this plugin */
- str = g_key_file_get_string (plugin_file,
- "Eog Plugin",
- "Loader",
- NULL);
-
- if (str && strcmp(str, "python") == 0) {
- info->loader = EOG_PLUGIN_LOADER_PY;
-
-#ifndef ENABLE_PYTHON
- g_warning ("Cannot load Python plugin '%s' since eog was not "
- "compiled with Python support.", file);
-
- goto error;
-#endif
-
- } else {
- info->loader = EOG_PLUGIN_LOADER_C;
- }
-
- g_free (str);
-
- /* Get Name */
- str = g_key_file_get_locale_string (plugin_file,
- "Eog Plugin",
- "Name",
- NULL, NULL);
- if (str) {
- info->name = str;
- } else {
- g_warning ("Could not find 'Name' in %s", file);
-
- goto error;
- }
-
- /* Get Description */
- str = g_key_file_get_locale_string (plugin_file,
- "Eog Plugin",
- "Description",
- NULL, NULL);
- if (str) {
- info->desc = str;
- } else {
- eog_debug_message (DEBUG_PLUGINS, "Could not find 'Description' in %s", file);
- }
-
- /* Get Icon */
- str = g_key_file_get_locale_string (plugin_file,
- "Eog Plugin",
- "Icon",
- NULL, NULL);
- if (str) {
- info->icon_name = str;
- } else {
- eog_debug_message (DEBUG_PLUGINS, "Could not find 'Icon' in %s, "
- "using 'eog-plugin'", file);
- }
-
- /* Get Authors */
- info->authors = g_key_file_get_string_list (plugin_file,
- "Eog Plugin",
- "Authors",
- NULL,
- NULL);
-
- if (info->authors == NULL)
- eog_debug_message (DEBUG_PLUGINS, "Could not find 'Authors' in %s", file);
-
-
- /* Get Copyright */
- str = g_key_file_get_string (plugin_file,
- "Eog Plugin",
- "Copyright",
- NULL);
- if (str) {
- info->copyright = str;
- } else {
- eog_debug_message (DEBUG_PLUGINS, "Could not find 'Copyright' in %s", file);
- }
-
- /* Get Website */
- str = g_key_file_get_string (plugin_file,
- "Eog Plugin",
- "Website",
- NULL);
- if (str) {
- info->website = str;
- } else {
- eog_debug_message (DEBUG_PLUGINS, "Could not find 'Website' in %s", file);
- }
-
- g_key_file_free (plugin_file);
-
- /* If we know nothing about the availability of the plugin,
- set it as available */
- info->available = TRUE;
-
- return info;
-
-error:
- g_free (info->file);
- g_free (info->location);
- g_free (info->name);
- g_free (info);
- g_key_file_free (plugin_file);
-
- return NULL;
-}
-
-static gint
-compare_plugin_info (EogPluginInfo *info1,
- EogPluginInfo *info2)
-{
- return strcmp (info1->location, info2->location);
-}
-
-static void
-eog_plugin_engine_load_dir (const gchar *dir)
-{
- GError *error = NULL;
- GDir *d;
- const gchar *dirent;
-
- if (!g_file_test (dir, G_FILE_TEST_IS_DIR)) {
- return;
- }
-
- g_return_if_fail (eog_plugin_engine_settings != NULL);
-
- eog_debug_message (DEBUG_PLUGINS, "DIR: %s", dir);
-
- d = g_dir_open (dir, 0, &error);
-
- if (!d) {
- g_warning ("%s", error->message);
- g_error_free (error);
-
- return;
- }
-
- while ((dirent = g_dir_read_name (d))) {
- if (g_str_has_suffix (dirent, PLUGIN_EXT)) {
- gchar *plugin_file;
- EogPluginInfo *info;
-
- plugin_file = g_build_filename (dir, dirent, NULL);
- info = eog_plugin_engine_load (plugin_file);
- g_free (plugin_file);
-
- if (info == NULL)
- continue;
-
- /* If a plugin with this name has already been loaded
- * drop this one (user plugins override system plugins) */
- if (g_list_find_custom (eog_plugins_list,
- info,
- (GCompareFunc)compare_plugin_info) != NULL) {
- g_warning ("Two or more plugins named '%s'. "
- "Only the first will be considered.\n",
- info->location);
-
- eog_plugin_info_free (info);
-
- continue;
- }
-
- /* Actually, the plugin will be activated when reactivate_all
- * will be called for the first time. */
- info->active = (g_slist_find_custom (active_plugins,
- info->location,
- (GCompareFunc)strcmp) != NULL);
-
- eog_plugins_list = g_list_prepend (eog_plugins_list, info);
-
- eog_debug_message (DEBUG_PLUGINS, "Plugin %s loaded", info->name);
- }
- }
-
- eog_plugins_list = g_list_reverse (eog_plugins_list);
-
- g_dir_close (d);
-}
-
static void
-eog_plugin_engine_load_all (void)
-{
- gchar *pdir;
-
- pdir = g_build_filename (eog_util_dot_dir (),
- USER_EOG_PLUGINS_LOCATION, NULL);
-
- /* Load user's plugins */
- eog_plugin_engine_load_dir (pdir);
-
- g_free (pdir);
-
- /* Load system plugins */
- eog_plugin_engine_load_dir (EOG_PLUGIN_DIR "/");
-}
-
-/*
- * GSettings List Helpers taken from gedit (gedit/gedit-settings.c)
- * by Ignacio Casal Quinteiro <icq gnome org>
- */
-static GSList *
-_eog_settings_get_list (GSettings *settings,
- const gchar *key)
+eog_plugin_engine_dispose (GObject *object)
{
- GSList *list = NULL;
- gchar **values;
- gsize i;
+ EogPluginEngine *engine = EOG_PLUGIN_ENGINE (object);
- g_return_val_if_fail (G_IS_SETTINGS (settings), NULL);
- g_return_val_if_fail (key != NULL, NULL);
-
- values = g_settings_get_strv (settings, key);
-
- for (i = 0; values[i] != NULL; i++)
+ if (engine->priv->plugins_settings != NULL)
{
- list = g_slist_prepend (list, values[i]);
+ g_object_unref (engine->priv->plugins_settings);
+ engine->priv->plugins_settings = NULL;
}
- g_free (values);
-
- return g_slist_reverse (list);
+ G_OBJECT_CLASS (eog_plugin_engine_parent_class)->dispose (object);
}
static void
-_eog_settings_set_list (GSettings *settings,
- const gchar *key,
- const GSList *list)
-{
- gchar **values;
- const GSList *l;
- gint i, len;
-
- g_return_if_fail (G_IS_SETTINGS (settings));
- g_return_if_fail (key != NULL);
-
- len = g_slist_length ((GSList *)list);
- values = g_new0 (gchar *, len+1);
-
- for (l = list, i = 0; l != NULL; l = g_slist_next (l), i++)
- {
- values[i] = l->data;
- }
-
- g_settings_set_strv (settings, key, (const gchar * const *)values);
- g_free (values);
-}
-
-gboolean
-eog_plugin_engine_init (void)
-{
- eog_debug (DEBUG_PLUGINS);
-
- g_return_val_if_fail (eog_plugins_list == NULL, FALSE);
-
- if (!g_module_supported ()) {
- g_warning ("eog is not able to initialize the plugins engine.");
-
- return FALSE;
- }
-
- eog_plugin_engine_settings = g_settings_new (EOG_CONF_PLUGINS);
-
- g_return_val_if_fail (eog_plugin_engine_settings != NULL, FALSE);
-
-
- g_signal_connect (eog_plugin_engine_settings,
- "changed::" EOG_CONF_PLUGINS_ACTIVE_PLUGINS,
- (GCallback) eog_plugin_engine_active_plugins_changed,
- NULL);
-
- active_plugins = _eog_settings_get_list (eog_plugin_engine_settings,
- EOG_CONF_PLUGINS_ACTIVE_PLUGINS);
-
- eog_plugin_engine_load_all ();
-
- return TRUE;
-}
-
-void
-eog_plugin_engine_garbage_collect (void)
-{
-#ifdef ENABLE_PYTHON
- eog_python_garbage_collect ();
-#endif
-}
-
-void
-eog_plugin_engine_shutdown (void)
+eog_plugin_engine_class_init (EogPluginEngineClass *klass)
{
- GList *pl;
-
- eog_debug (DEBUG_PLUGINS);
-
-#ifdef ENABLE_PYTHON
- /* Note: that this may cause finalization of objects (typically
- * the EogWindow) by running the garbage collector. Since some
- * of the plugin may have installed callbacks upon object
- * finalization (typically they need to free the WindowData)
- * it must run before we get rid of the plugins.
- */
- eog_python_shutdown ();
-#endif
-
- g_return_if_fail (eog_plugin_engine_settings != NULL);
-
- for (pl = eog_plugins_list; pl; pl = pl->next) {
- EogPluginInfo *info = (EogPluginInfo*) pl->data;
-
- eog_plugin_info_free (info);
- }
-
- g_slist_foreach (active_plugins, (GFunc)g_free, NULL);
- g_slist_free (active_plugins);
-
- active_plugins = NULL;
-
- g_list_free (eog_plugins_list);
- eog_plugins_list = NULL;
-
- g_object_unref (eog_plugin_engine_settings);
- eog_plugin_engine_settings = NULL;
-}
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
-const GList *
-eog_plugin_engine_get_plugins_list (void)
-{
- eog_debug (DEBUG_PLUGINS);
+ g_type_class_add_private (klass, sizeof (EogPluginEnginePrivate));
- return eog_plugins_list;
-}
-
-static gboolean
-load_plugin_module (EogPluginInfo *info)
-{
- gchar *path;
- gchar *dirname;
-
- eog_debug (DEBUG_PLUGINS);
-
- g_return_val_if_fail (info != NULL, FALSE);
- g_return_val_if_fail (info->file != NULL, FALSE);
- g_return_val_if_fail (info->location != NULL, FALSE);
- g_return_val_if_fail (info->plugin == NULL, FALSE);
- g_return_val_if_fail (info->available, FALSE);
-
- switch (info->loader) {
- case EOG_PLUGIN_LOADER_C:
- dirname = g_path_get_dirname (info->file);
- g_return_val_if_fail (dirname != NULL, FALSE);
-
- path = g_module_build_path (dirname, info->location);
-
- g_free (dirname);
-
- g_return_val_if_fail (path != NULL, FALSE);
-
- info->module = G_TYPE_MODULE (eog_module_new (path));
-
- g_free (path);
-
- break;
-
-#ifdef ENABLE_PYTHON
- case EOG_PLUGIN_LOADER_PY:
- {
- gchar *dir;
-
- if (!eog_python_init ()) {
- /* Mark plugin as unavailable and fails */
- info->available = FALSE;
-
- g_warning ("Cannot load Python plugin '%s' since eog "
- "was not able to initialize the Python interpreter.",
- info->name);
-
- return FALSE;
- }
-
- dir = g_path_get_dirname (info->file);
-
- g_return_val_if_fail ((info->location != NULL) &&
- (info->location[0] != '\0'),
- FALSE);
-
- info->module = G_TYPE_MODULE (
- eog_python_module_new (dir, info->location));
-
- g_free (dir);
-
- break;
- }
-#endif
- default:
- g_return_val_if_reached (FALSE);
- }
-
- if (!g_type_module_use (info->module)) {
- switch (info->loader) {
- case EOG_PLUGIN_LOADER_C:
- g_warning ("Cannot load plugin '%s' since file '%s' cannot be read.",
- info->name,
- eog_module_get_path (EOG_MODULE (info->module)));
- break;
-
- case EOG_PLUGIN_LOADER_PY:
- g_warning ("Cannot load Python plugin '%s' since file '%s' cannot be read.",
- info->name,
- info->location);
- break;
-
- default:
- g_return_val_if_reached (FALSE);
- }
-
- g_object_unref (G_OBJECT (info->module));
-
- info->module = NULL;
-
- /* Mark plugin as unavailable and fails */
- info->available = FALSE;
-
- return FALSE;
- }
-
- switch (info->loader) {
- case EOG_PLUGIN_LOADER_C:
- info->plugin =
- EOG_PLUGIN (eog_module_new_object (EOG_MODULE (info->module)));
- break;
-
-#ifdef ENABLE_PYTHON
- case EOG_PLUGIN_LOADER_PY:
- info->plugin =
- EOG_PLUGIN (eog_python_module_new_object (EOG_PYTHON_MODULE (info->module)));
- break;
-#endif
-
- default:
- g_return_val_if_reached (FALSE);
- }
-
- g_type_module_unuse (info->module);
-
- eog_debug_message (DEBUG_PLUGINS, "End");
-
- return TRUE;
-}
-
-static gboolean
-eog_plugin_engine_activate_plugin_real (EogPluginInfo *info)
-{
- gboolean res = TRUE;
-
- /* Plugin is not available, don't try to activate/load it */
- if (!info->available) {
- return FALSE;
- }
-
- if (info->plugin == NULL)
- res = load_plugin_module (info);
-
- if (res) {
- const GList *wins = eog_application_get_windows (EOG_APP);
-
- while (wins != NULL) {
- eog_plugin_activate (info->plugin,
- EOG_WINDOW (wins->data));
-
- wins = g_list_next (wins);
- }
- } else {
- g_warning ("Error activating plugin '%s'", info->name);
- }
-
- return res;
-}
-
-gboolean
-eog_plugin_engine_activate_plugin (EogPluginInfo *info)
-{
- eog_debug (DEBUG_PLUGINS);
-
- g_return_val_if_fail (info != NULL, FALSE);
-
- if (!info->available)
- return FALSE;
-
- if (info->active)
- return TRUE;
-
- if (eog_plugin_engine_activate_plugin_real (info)) {
- GSList *list;
-
- /* Update plugin state */
- info->active = TRUE;
-
- list = active_plugins;
-
- while (list != NULL) {
- if (strcmp (info->location, (gchar *)list->data) == 0) {
- g_warning ("Plugin '%s' is already active.", info->name);
-
- return TRUE;
- }
-
- list = g_slist_next (list);
- }
-
- active_plugins = g_slist_insert_sorted (active_plugins,
- g_strdup (info->location),
- (GCompareFunc)strcmp);
-
- _eog_settings_set_list (eog_plugin_engine_settings,
- EOG_CONF_PLUGINS_ACTIVE_PLUGINS,
- active_plugins);
-
- return TRUE;
- }
-
- return FALSE;
+ object_class->dispose = eog_plugin_engine_dispose;
}
static void
-eog_plugin_engine_deactivate_plugin_real (EogPluginInfo *info)
-{
- const GList *wins = eog_application_get_windows (EOG_APP);
-
- while (wins != NULL) {
- eog_plugin_deactivate (info->plugin,
- EOG_WINDOW (wins->data));
-
- wins = g_list_next (wins);
- }
-}
-
-gboolean
-eog_plugin_engine_deactivate_plugin (EogPluginInfo *info)
+eog_plugin_engine_init (EogPluginEngine *engine)
{
- gboolean res;
- GSList *list;
-
eog_debug (DEBUG_PLUGINS);
- g_return_val_if_fail (info != NULL, FALSE);
-
- if (!info->active || !info->available)
- return TRUE;
-
- eog_plugin_engine_deactivate_plugin_real (info);
+ engine->priv = G_TYPE_INSTANCE_GET_PRIVATE (engine,
+ EOG_TYPE_PLUGIN_ENGINE,
+ EogPluginEnginePrivate);
- /* Update plugin state */
- info->active = FALSE;
-
- list = active_plugins;
- res = (list == NULL);
-
- while (list != NULL) {
- if (strcmp (info->location, (gchar *)list->data) == 0) {
- g_free (list->data);
- active_plugins = g_slist_delete_link (active_plugins, list);
- list = NULL;
- res = TRUE;
- } else {
- list = g_slist_next (list);
- }
- }
-
- if (!res) {
- g_warning ("Plugin '%s' is already deactivated.", info->name);
-
- return TRUE;
- }
-
- _eog_settings_set_list (eog_plugin_engine_settings,
- EOG_CONF_PLUGINS_ACTIVE_PLUGINS,
- active_plugins);
-
- return TRUE;
+ engine->priv->plugins_settings = g_settings_new ("org.gnome.eog.plugins");
}
-gboolean
-eog_plugin_engine_plugin_is_active (EogPluginInfo *info)
+EogPluginEngine *
+eog_plugin_engine_new (void)
{
- g_return_val_if_fail (info != NULL, FALSE);
+ EogPluginEngine *engine;
+ gchar **search_paths;
- return (info->available && info->active);
-}
+ /* This should be moved to libpeas */
+ g_irepository_require (g_irepository_get_default (),
+ "Peas", "1.0", 0, NULL);
+ g_irepository_require (g_irepository_get_default (),
+ "PeasUI", "1.0", 0, NULL);
-gboolean
-eog_plugin_engine_plugin_is_available (EogPluginInfo *info)
-{
- g_return_val_if_fail (info != NULL, FALSE);
+ search_paths = g_new (gchar *, 5);
- return (info->available != FALSE);
-}
-
-static void
-reactivate_all (EogWindow *window)
-{
- GList *pl;
-
- eog_debug (DEBUG_PLUGINS);
-
- for (pl = eog_plugins_list; pl; pl = pl->next) {
- gboolean res = TRUE;
-
- EogPluginInfo *info = (EogPluginInfo*)pl->data;
-
- /* If plugin is not available, don't try to activate/load it */
- if (info->available && info->active) {
- if (info->plugin == NULL)
- res = load_plugin_module (info);
-
- if (res)
- eog_plugin_activate (info->plugin,
- window);
- }
- }
-
- eog_debug_message (DEBUG_PLUGINS, "End");
-}
-
-void
-eog_plugin_engine_update_plugins_ui (EogWindow *window,
- gboolean new_window)
-{
- GList *pl;
-
- eog_debug (DEBUG_PLUGINS);
-
- g_return_if_fail (EOG_IS_WINDOW (window));
-
- if (new_window)
- reactivate_all (window);
-
- /* Updated ui of all the plugins that implement update_ui */
- for (pl = eog_plugins_list; pl; pl = pl->next) {
- EogPluginInfo *info = (EogPluginInfo*)pl->data;
+ search_paths[0] = g_build_filename (eog_util_dot_dir (), USER_EOG_PLUGINS_LOCATION, NULL);
+ search_paths[1] = g_strdup (search_paths [0]);
+ search_paths[2] = g_strdup (EOG_PLUGIN_DIR);
+ search_paths[3] = g_strdup (EOG_PLUGIN_DIR);
+ search_paths[4] = NULL;
- if (!info->available || !info->active)
- continue;
+ engine = EOG_PLUGIN_ENGINE (g_object_new (EOG_TYPE_PLUGIN_ENGINE,
+ "app-name", "Eog",
+ /* "base-module-dir", modules_dir, */
+ "search-paths", search_paths,
+ NULL));
- eog_debug_message (DEBUG_PLUGINS, "Updating UI of %s", info->name);
+ g_settings_bind (engine->priv->plugins_settings,
+ EOG_CONF_PLUGINS_ACTIVE_PLUGINS,
+ engine,
+ "loaded-plugins",
+ G_SETTINGS_BIND_DEFAULT);
- eog_plugin_update_ui (info->plugin, window);
- }
-}
-
-gboolean
-eog_plugin_engine_plugin_is_configurable (EogPluginInfo *info) {
- eog_debug (DEBUG_PLUGINS);
-
- g_return_val_if_fail (info != NULL, FALSE);
-
- if ((info->plugin == NULL) || !info->active || !info->available)
- return FALSE;
-
- return eog_plugin_is_configurable (info->plugin);
-}
-
-void
-eog_plugin_engine_configure_plugin (EogPluginInfo *info,
- GtkWindow *parent)
-{
- GtkWidget *conf_dlg;
-
- GtkWindowGroup *wg;
-
- eog_debug (DEBUG_PLUGINS);
-
- g_return_if_fail (info != NULL);
-
- conf_dlg = eog_plugin_create_configure_dialog (info->plugin);
-
- g_return_if_fail (conf_dlg != NULL);
-
- gtk_window_set_transient_for (GTK_WINDOW (conf_dlg),
- parent);
-
- // Will return a default group if no group is set
- wg = gtk_window_get_group (parent);
-
- // For now assign a dedicated window group if it is
- // the default one until we know if this is really needed
- if (wg == gtk_window_get_group (NULL)) {
- wg = gtk_window_group_new ();
- gtk_window_group_add_window (wg, parent);
- }
-
- gtk_window_group_add_window (wg,
- GTK_WINDOW (conf_dlg));
-
- gtk_window_set_modal (GTK_WINDOW (conf_dlg), TRUE);
-
- gtk_widget_show (conf_dlg);
-}
-
-static void
-eog_plugin_engine_active_plugins_changed (GSettings *settings,
- gchar *key,
- gpointer user_data)
-{
- GList *pl;
- gboolean to_activate;
-
- eog_debug (DEBUG_PLUGINS);
-
- active_plugins = _eog_settings_get_list (eog_plugin_engine_settings,
- EOG_CONF_PLUGINS_ACTIVE_PLUGINS);
-
- for (pl = eog_plugins_list; pl; pl = pl->next) {
- EogPluginInfo *info = (EogPluginInfo*)pl->data;
-
- if (!info->available)
- continue;
-
- to_activate = (g_slist_find_custom (active_plugins,
- info->location,
- (GCompareFunc)strcmp) != NULL);
-
- if (!info->active && to_activate) {
- /* Activate plugin */
- if (eog_plugin_engine_activate_plugin_real (info))
- /* Update plugin state */
- info->active = TRUE;
- } else {
- if (info->active && !to_activate) {
- eog_plugin_engine_deactivate_plugin_real (info);
-
- /* Update plugin state */
- info->active = FALSE;
- }
- }
- }
-}
-
-const gchar *
-eog_plugin_engine_get_plugin_name (EogPluginInfo *info)
-{
- g_return_val_if_fail (info != NULL, NULL);
-
- return info->name;
-}
-
-const gchar *
-eog_plugin_engine_get_plugin_description (EogPluginInfo *info)
-{
- g_return_val_if_fail (info != NULL, NULL);
-
- return info->desc;
-}
-
-const gchar *
-eog_plugin_engine_get_plugin_icon_name (EogPluginInfo *info)
-{
- g_return_val_if_fail (info != NULL, NULL);
-
- /* Use the eog-plugin icon as a default if the plugin does not
- have its own */
- if (info->icon_name != NULL &&
- gtk_icon_theme_has_icon (gtk_icon_theme_get_default (),
- info->icon_name))
- return info->icon_name;
- else
- return "eog-plugin";
-}
-
-const gchar **
-eog_plugin_engine_get_plugin_authors (EogPluginInfo *info)
-{
- g_return_val_if_fail (info != NULL, (const gchar **)NULL);
-
- return (const gchar **) info->authors;
-}
-
-const gchar *
-eog_plugin_engine_get_plugin_website (EogPluginInfo *info)
-{
- g_return_val_if_fail (info != NULL, NULL);
-
- return info->website;
-}
-
-const gchar *
-eog_plugin_engine_get_plugin_copyright (EogPluginInfo *info)
-{
- g_return_val_if_fail (info != NULL, NULL);
+ g_strfreev (search_paths);
- return info->copyright;
+ return engine;
}
diff --git a/src/eog-plugin-engine.h b/src/eog-plugin-engine.h
index 43f3a76..0ba77e4 100644
--- a/src/eog-plugin-engine.h
+++ b/src/eog-plugin-engine.h
@@ -25,65 +25,36 @@
#ifndef __EOG_PLUGIN_ENGINE_H__
#define __EOG_PLUGIN_ENGINE_H__
-#include "eog-window.h"
-
+#include <libpeas/peas-engine.h>
#include <glib.h>
+#include <glib-object.h>
-typedef struct _EogPluginInfo EogPluginInfo;
-
-G_GNUC_INTERNAL
-gboolean eog_plugin_engine_init (void);
-
-G_GNUC_INTERNAL
-void eog_plugin_engine_shutdown (void);
-
-G_GNUC_INTERNAL
-void eog_plugin_engine_garbage_collect (void);
-
-G_GNUC_INTERNAL
-const GList *eog_plugin_engine_get_plugins_list (void);
-
-G_GNUC_INTERNAL
-gboolean eog_plugin_engine_activate_plugin (EogPluginInfo *info);
-
-G_GNUC_INTERNAL
-gboolean eog_plugin_engine_deactivate_plugin (EogPluginInfo *info);
-
-G_GNUC_INTERNAL
-gboolean eog_plugin_engine_plugin_is_active (EogPluginInfo *info);
-
-G_GNUC_INTERNAL
-gboolean eog_plugin_engine_plugin_is_available (EogPluginInfo *info);
-
-G_GNUC_INTERNAL
-gboolean eog_plugin_engine_plugin_is_configurable
- (EogPluginInfo *info);
-
-G_GNUC_INTERNAL
-void eog_plugin_engine_configure_plugin (EogPluginInfo *info,
- GtkWindow *parent);
+G_BEGIN_DECLS
-G_GNUC_INTERNAL
-void eog_plugin_engine_update_plugins_ui (EogWindow *window,
- gboolean new_window);
+typedef struct _EogPluginEngine EogPluginEngine;
+typedef struct _EogPluginEngineClass EogPluginEngineClass;
+typedef struct _EogPluginEnginePrivate EogPluginEnginePrivate;
-G_GNUC_INTERNAL
-const gchar *eog_plugin_engine_get_plugin_name (EogPluginInfo *info);
+#define EOG_TYPE_PLUGIN_ENGINE eog_plugin_engine_get_type()
+#define EOG_PLUGIN_ENGINE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EOG_TYPE_PLUGIN_ENGINE, EogPluginEngine))
+#define EOG_PLUGIN_ENGINE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EOG_TYPE_PLUGIN_ENGINE, EogPluginEngineClass))
+#define EOG_IS_PLUGIN_ENGINE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EOG_TYPE_PLUGIN_ENGINE))
+#define EOG_IS_PLUGIN_ENGINE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EOG_TYPE_PLUGIN_ENGINE))
+#define EOG_PLUGIN_ENGINE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EOG_TYPE_PLUGIN_ENGINE, EogPluginEngineClass))
-G_GNUC_INTERNAL
-const gchar *eog_plugin_engine_get_plugin_description
- (EogPluginInfo *info);
+struct _EogPluginEngine {
+ PeasEngine parent;
+ EogPluginEnginePrivate *priv;
+};
-G_GNUC_INTERNAL
-const gchar *eog_plugin_engine_get_plugin_icon_name (EogPluginInfo *info);
+struct _EogPluginEngineClass {
+ PeasEngineClass parent_class;
+};
-G_GNUC_INTERNAL
-const gchar **eog_plugin_engine_get_plugin_authors (EogPluginInfo *info);
+GType eog_plugin_engine_get_type (void) G_GNUC_CONST;
-G_GNUC_INTERNAL
-const gchar *eog_plugin_engine_get_plugin_website (EogPluginInfo *info);
+EogPluginEngine* eog_plugin_engine_new (void);
-G_GNUC_INTERNAL
-const gchar *eog_plugin_engine_get_plugin_copyright (EogPluginInfo *info);
+G_END_DECLS
#endif /* __EOG_PLUGIN_ENGINE_H__ */
diff --git a/src/eog-preferences-dialog.c b/src/eog-preferences-dialog.c
index f6afb83..dfac8b9 100644
--- a/src/eog-preferences-dialog.c
+++ b/src/eog-preferences-dialog.c
@@ -27,15 +27,16 @@
#endif
#include "eog-preferences-dialog.h"
-#include "eog-plugin-manager.h"
#include "eog-scroll-view.h"
#include "eog-util.h"
#include "eog-config-keys.h"
+#include "eog-application.h"
#include <glib.h>
#include <glib/gi18n.h>
#include <glib-object.h>
#include <gtk/gtk.h>
+#include <libpeasui/peas-ui-plugin-manager.h>
#define EOG_PREFERENCES_DIALOG_GET_PRIVATE(object) \
(G_TYPE_INSTANCE_GET_PRIVATE ((object), EOG_TYPE_PREFERENCES_DIALOG, EogPreferencesDialogPrivate))
@@ -255,7 +256,7 @@ eog_preferences_dialog_constructor (GType type,
g_settings_bind (priv->fullscreen_settings, EOG_CONF_FULLSCREEN_SECONDS,
seconds_spin, "value", G_SETTINGS_BIND_DEFAULT);
- plugin_manager = eog_plugin_manager_new ();
+ plugin_manager = peas_ui_plugin_manager_new (PEAS_ENGINE (EOG_APP->plugin_engine));
g_assert (plugin_manager != NULL);
diff --git a/src/eog-window.c b/src/eog-window.c
index fc86a71..f334cb0 100644
--- a/src/eog-window.c
+++ b/src/eog-window.c
@@ -68,6 +68,9 @@
#include <gio/gdesktopappinfo.h>
#include <gtk/gtk.h>
+#include <libpeas/peas-extension-set.h>
+#include <libpeas/peas-activatable.h>
+
#if HAVE_LCMS
#include <X11/Xlib.h>
#include <X11/Xatom.h>
@@ -4590,7 +4593,7 @@ eog_window_dispose (GObject *object)
window = EOG_WINDOW (object);
priv = window->priv;
- eog_plugin_engine_garbage_collect ();
+ peas_engine_garbage_collect (PEAS_ENGINE (EOG_APP->plugin_engine));
if (priv->store != NULL) {
g_signal_handlers_disconnect_by_func (priv->store,
@@ -4701,7 +4704,7 @@ eog_window_dispose (GObject *object)
priv->page_setup = NULL;
}
- eog_plugin_engine_garbage_collect ();
+ peas_engine_garbage_collect (PEAS_ENGINE (EOG_APP->plugin_engine));
G_OBJECT_CLASS (eog_window_parent_class)->dispose (object);
}
@@ -5051,19 +5054,56 @@ eog_window_get_property (GObject *object,
}
}
+static void
+on_extension_added (PeasExtensionSet *set,
+ PeasPluginInfo *info,
+ PeasExtension *exten,
+ GtkWindow *window)
+{
+ peas_extension_call (exten, "activate", window);
+}
+
+static void
+on_extension_removed (PeasExtensionSet *set,
+ PeasPluginInfo *info,
+ PeasExtension *exten,
+ GtkWindow *window)
+{
+ peas_extension_call (exten, "deactivate", window);
+}
+
+static
+gboolean on_window_delete (GtkWidget *widget,
+ GdkEvent *event,
+ PeasExtensionSet *set)
+{
+ peas_extension_set_call (set, "deactivate");
+ return FALSE;
+}
+
static GObject *
eog_window_constructor (GType type,
guint n_construct_properties,
GObjectConstructParam *construct_params)
{
GObject *object;
+ PeasExtensionSet *set;
object = G_OBJECT_CLASS (eog_window_parent_class)->constructor
(type, n_construct_properties, construct_params);
eog_window_construct_ui (EOG_WINDOW (object));
- eog_plugin_engine_update_plugins_ui (EOG_WINDOW (object), TRUE);
+ set = peas_extension_set_new (PEAS_ENGINE (EOG_APP->plugin_engine),
+ PEAS_TYPE_ACTIVATABLE,
+ "object", object, NULL);
+ peas_extension_set_call (set, "activate");
+ g_signal_connect (set, "extension-added",
+ G_CALLBACK (on_extension_added), object);
+ g_signal_connect (set, "extension-removed",
+ G_CALLBACK (on_extension_removed), object);
+ g_signal_connect (object, "delete-event",
+ G_CALLBACK (on_window_delete), set);
return object;
}
diff --git a/src/main.c b/src/main.c
index 93b9511..12788b4 100644
--- a/src/main.c
+++ b/src/main.c
@@ -239,7 +239,6 @@ main (int argc, char **argv)
eog_job_queue_init ();
gdk_threads_init ();
eog_thumbnail_init ();
- eog_plugin_engine_init ();
/* Add application specific icons to search path */
gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (),
@@ -264,8 +263,6 @@ main (int argc, char **argv)
if (startup_files)
g_strfreev (startup_files);
- eog_plugin_engine_shutdown ();
-
#ifdef HAVE_RSVG
rsvg_term();
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]