gnome-settings-daemon r165 - in trunk: . gnome-settings-daemon



Author: mccann
Date: Fri Feb 22 20:23:37 2008
New Revision: 165
URL: http://svn.gnome.org/viewvc/gnome-settings-daemon?rev=165&view=rev

Log:
2008-02-22  William Jon McCann  <jmccann redhat com>

	* gnome-settings-daemon/Makefile.am:
	* gnome-settings-daemon/gnome-settings-manager.c:
	(gnome_settings_manager_start), (gnome_settings_manager_stop),
	(gnome_settings_manager_constructor),
	(gnome_settings_manager_finalize):
	* gnome-settings-daemon/gnome-settings-plugin-info.c:
	(gnome_settings_plugin_info_finalize),
	(gnome_settings_plugin_info_class_init),
	(gnome_settings_plugin_info_init),
	(gnome_settings_plugin_info_fill_from_file), (plugin_enabled_cb),
	(gnome_settings_plugin_info_set_enabled_key_name),
	(gnome_settings_plugin_info_new_from_file), (_deactivate_plugin),
	(gnome_settings_plugin_info_deactivate), (load_plugin_module),
	(_activate_plugin), (gnome_settings_plugin_info_activate),
	(gnome_settings_plugin_info_is_active),
	(gnome_settings_plugin_info_get_enabled),
	(gnome_settings_plugin_info_is_available),
	(gnome_settings_plugin_info_get_name),
	(gnome_settings_plugin_info_get_description),
	(gnome_settings_plugin_info_get_authors),
	(gnome_settings_plugin_info_get_website),
	(gnome_settings_plugin_info_get_copyright),
	(gnome_settings_plugin_info_get_location),
	(gnome_settings_plugin_info_get_priority):
	* gnome-settings-daemon/gnome-settings-plugin-info.h:
	* gnome-settings-daemon/gnome-settings-plugins-engine.c:
	(gnome_settings_plugins_engine_load), (maybe_activate_plugin),
	(compare_location), (compare_priority),
	(gnome_settings_plugins_engine_load_file),
	(gnome_settings_plugins_engine_load_dir),
	(gnome_settings_plugins_engine_load_all),
	(gnome_settings_plugins_engine_unload_all),
	(gnome_settings_plugins_engine_start),
	(gnome_settings_plugins_engine_garbage_collect),
	(gnome_settings_plugins_engine_stop),
	(gnome_settings_plugins_engine_get_plugins_list),
	(_set_gconf_prefix), (gnome_settings_plugins_engine_set_property),
	(gnome_settings_plugins_engine_get_property),
	(gnome_settings_plugins_engine_class_init),
	(gnome_settings_plugins_engine_init),
	(gnome_settings_plugins_engine_finalize),
	(gnome_settings_plugins_engine_new):
	* gnome-settings-daemon/gnome-settings-plugins-engine.h:
	Refactor the PluginInfo structure into a class.  This
	will facilitate fixing bug #515341



Added:
   trunk/gnome-settings-daemon/gnome-settings-plugin-info.c
   trunk/gnome-settings-daemon/gnome-settings-plugin-info.h
Modified:
   trunk/ChangeLog
   trunk/gnome-settings-daemon/Makefile.am
   trunk/gnome-settings-daemon/gnome-settings-manager.c
   trunk/gnome-settings-daemon/gnome-settings-plugins-engine.c
   trunk/gnome-settings-daemon/gnome-settings-plugins-engine.h

Modified: trunk/gnome-settings-daemon/Makefile.am
==============================================================================
--- trunk/gnome-settings-daemon/Makefile.am	(original)
+++ trunk/gnome-settings-daemon/Makefile.am	Fri Feb 22 20:23:37 2008
@@ -31,6 +31,8 @@
 	gnome-settings-manager.h	\
 	gnome-settings-plugin.c		\
 	gnome-settings-plugin.h		\
+	gnome-settings-plugin-info.c	\
+	gnome-settings-plugin-info.h	\
 	gnome-settings-plugins-engine.c	\
 	gnome-settings-plugins-engine.h	\
 	gnome-settings-module.c		\

Modified: trunk/gnome-settings-daemon/gnome-settings-manager.c
==============================================================================
--- trunk/gnome-settings-daemon/gnome-settings-manager.c	(original)
+++ trunk/gnome-settings-daemon/gnome-settings-manager.c	Fri Feb 22 20:23:37 2008
@@ -43,8 +43,9 @@
 
 struct GnomeSettingsManagerPrivate
 {
-        DBusGConnection *connection;
-        char            *gconf_prefix;
+        DBusGConnection            *connection;
+        char                       *gconf_prefix;
+        GnomeSettingsPluginsEngine *engine;
 };
 
 enum {
@@ -103,7 +104,7 @@
 
         g_debug ("Starting settings manager");
 
-        gnome_settings_plugins_engine_init (manager->priv->gconf_prefix);
+        gnome_settings_plugins_engine_start (manager->priv->engine);
 
         ret = TRUE;
         return ret;
@@ -113,8 +114,7 @@
 gnome_settings_manager_stop (GnomeSettingsManager *manager)
 {
         g_debug ("Stopping settings manager");
-
-        gnome_settings_plugins_engine_shutdown ();
+        gnome_settings_plugins_engine_stop (manager->priv->engine);
 }
 
 static void
@@ -179,6 +179,8 @@
                                                                                                          n_construct_properties,
                                                                                                          construct_properties));
 
+        manager->priv->engine = gnome_settings_plugins_engine_new (manager->priv->gconf_prefix);
+
         return G_OBJECT (manager);
 }
 
@@ -239,6 +241,10 @@
 
         g_free (manager->priv->gconf_prefix);
 
+        if (manager->priv->engine != NULL) {
+                g_object_unref (manager->priv->engine);
+        }
+
         G_OBJECT_CLASS (gnome_settings_manager_parent_class)->finalize (object);
 }
 

Added: trunk/gnome-settings-daemon/gnome-settings-plugin-info.c
==============================================================================
--- (empty file)
+++ trunk/gnome-settings-daemon/gnome-settings-plugin-info.c	Fri Feb 22 20:23:37 2008
@@ -0,0 +1,559 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2007      William Jon McCann <mccann jhu edu>
+ *
+ * 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * 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.
+ */
+
+#include "config.h"
+
+#include <string.h>
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <gmodule.h>
+#include <gconf/gconf-client.h>
+
+#include "gnome-settings-plugin-info.h"
+#include "gnome-settings-module.h"
+#include "gnome-settings-plugin.h"
+
+#define GNOME_SETTINGS_PLUGIN_INFO_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GNOME_TYPE_SETTINGS_PLUGIN_INFO, GnomeSettingsPluginInfoPrivate))
+
+#define PLUGIN_GROUP "GNOME Settings Plugin"
+
+#define PLUGIN_PRIORITY_MAX 1
+#define PLUGIN_PRIORITY_DEFAULT 100
+
+typedef enum
+{
+        GNOME_SETTINGS_PLUGIN_LOADER_C,
+        GNOME_SETTINGS_PLUGIN_LOADER_PY
+} GnomeSettingsPluginLoader;
+
+struct GnomeSettingsPluginInfoPrivate
+{
+        char                    *file;
+        GConfClient             *client;
+
+        char                    *location;
+        GnomeSettingsPluginLoader  loader;
+        GTypeModule             *module;
+
+        char                    *name;
+        char                    *desc;
+        char                   **authors;
+        char                    *copyright;
+        char                    *website;
+
+        GnomeSettingsPlugin     *plugin;
+
+        int                      enabled : 1;
+        int                      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) */
+        int                      available : 1;
+
+        guint                    enabled_notification_id;
+
+        /* Priority determines the order in which plugins are started and
+         * stopped. A lower number means higher priority. */
+        guint                    priority;
+};
+
+G_DEFINE_TYPE (GnomeSettingsPluginInfo, gnome_settings_plugin_info, G_TYPE_OBJECT)
+
+static void
+gnome_settings_plugin_info_finalize (GObject *object)
+{
+        GnomeSettingsPluginInfo *info;
+
+        g_return_if_fail (object != NULL);
+        g_return_if_fail (GNOME_IS_SETTINGS_PLUGIN_INFO (object));
+
+        info = GNOME_SETTINGS_PLUGIN_INFO (object);
+
+        g_return_if_fail (info->priv != NULL);
+
+        if (info->priv->plugin != NULL) {
+                g_debug ("Unref plugin %s", info->priv->name);
+
+                g_object_unref (info->priv->plugin);
+
+                /* info->priv->module must not be unref since it is not possible to finalize
+                 * a type module */
+        }
+
+        g_free (info->priv->file);
+        g_free (info->priv->location);
+        g_free (info->priv->name);
+        g_free (info->priv->desc);
+        g_free (info->priv->website);
+        g_free (info->priv->copyright);
+        g_strfreev (info->priv->authors);
+
+        if (info->priv->enabled_notification_id != 0) {
+                gconf_client_notify_remove (info->priv->client,
+                                            info->priv->enabled_notification_id);
+
+                info->priv->enabled_notification_id = 0;
+        }
+
+        g_object_unref (info->priv->client);
+
+        G_OBJECT_CLASS (gnome_settings_plugin_info_parent_class)->finalize (object);
+}
+
+static void
+gnome_settings_plugin_info_class_init (GnomeSettingsPluginInfoClass *klass)
+{
+        GObjectClass   *object_class = G_OBJECT_CLASS (klass);
+
+        object_class->finalize = gnome_settings_plugin_info_finalize;
+
+        g_type_class_add_private (klass, sizeof (GnomeSettingsPluginInfoPrivate));
+}
+
+static void
+gnome_settings_plugin_info_init (GnomeSettingsPluginInfo *info)
+{
+        info->priv = GNOME_SETTINGS_PLUGIN_INFO_GET_PRIVATE (info);
+        info->priv->client = gconf_client_get_default ();
+}
+
+static gboolean
+gnome_settings_plugin_info_fill_from_file (GnomeSettingsPluginInfo *info,
+                                           const char              *filename)
+{
+        GKeyFile *plugin_file = NULL;
+        char     *str;
+        int       priority;
+        gboolean  ret;
+
+        ret = FALSE;
+
+        info->priv->file = g_strdup (filename);
+
+        plugin_file = g_key_file_new ();
+        if (! g_key_file_load_from_file (plugin_file, filename, G_KEY_FILE_NONE, NULL)) {
+                g_warning ("Bad plugin file: %s", filename);
+                goto out;
+        }
+
+        if (! g_key_file_has_key (plugin_file, PLUGIN_GROUP, "IAge", NULL)) {
+                g_debug ("IAge key does not exist in file: %s", filename);
+                goto out;
+        }
+
+        /* Check IAge=2 */
+        if (g_key_file_get_integer (plugin_file, PLUGIN_GROUP, "IAge", NULL) != 0) {
+                g_debug ("Wrong IAge in file: %s", filename);
+                goto out;
+        }
+
+        /* Get Location */
+        str = g_key_file_get_string (plugin_file, PLUGIN_GROUP, "Module", NULL);
+
+        if ((str != NULL) && (*str != '\0')) {
+                info->priv->location = str;
+        } else {
+                g_warning ("Could not find 'Module' in %s", filename);
+                goto out;
+        }
+
+        /* Get the loader for this plugin */
+        str = g_key_file_get_string (plugin_file, PLUGIN_GROUP, "Loader", NULL);
+        if (str && strcmp(str, "python") == 0) {
+                info->priv->loader = GNOME_SETTINGS_PLUGIN_LOADER_PY;
+#ifndef ENABLE_PYTHON
+                g_warning ("Cannot load Python plugin '%s' since gnome_settings was not "
+                           "compiled with Python support.", filename);
+                goto out;
+#endif
+        } else {
+                info->priv->loader = GNOME_SETTINGS_PLUGIN_LOADER_C;
+        }
+        g_free (str);
+
+        /* Get Name */
+        str = g_key_file_get_locale_string (plugin_file, PLUGIN_GROUP, "Name", NULL, NULL);
+        if (str) {
+                info->priv->name = str;
+        } else {
+                g_warning ("Could not find 'Name' in %s", filename);
+                goto out;
+        }
+
+        /* Get Description */
+        str = g_key_file_get_locale_string (plugin_file, PLUGIN_GROUP, "Description", NULL, NULL);
+        if (str) {
+                info->priv->desc = str;
+        } else {
+                g_debug ("Could not find 'Description' in %s", filename);
+        }
+
+        /* Get Authors */
+        info->priv->authors = g_key_file_get_string_list (plugin_file, PLUGIN_GROUP, "Authors", NULL, NULL);
+        if (info->priv->authors == NULL) {
+                g_debug ("Could not find 'Authors' in %s", filename);
+        }
+
+        /* Get Copyright */
+        str = g_key_file_get_string (plugin_file, PLUGIN_GROUP, "Copyright", NULL);
+        if (str) {
+                info->priv->copyright = str;
+        } else {
+                g_debug ("Could not find 'Copyright' in %s", filename);
+        }
+
+        /* Get Website */
+        str = g_key_file_get_string (plugin_file, PLUGIN_GROUP, "Website", NULL);
+        if (str) {
+                info->priv->website = str;
+        } else {
+                g_debug ("Could not find 'Website' in %s", filename);
+        }
+
+        /* Get Priority */
+        priority = g_key_file_get_integer (plugin_file, PLUGIN_GROUP, "Priority", NULL);
+        if (priority >= PLUGIN_PRIORITY_MAX) {
+                info->priv->priority = priority;
+        } else {
+                g_debug ("Could not find valid 'Priority' in %s", filename);
+                info->priv->priority = PLUGIN_PRIORITY_DEFAULT;
+        }
+
+        g_key_file_free (plugin_file);
+
+        /* If we know nothing about the availability of the plugin,
+           set it as available */
+        info->priv->available = TRUE;
+
+        ret = TRUE;
+ out:
+        return ret;
+}
+
+static void
+plugin_enabled_cb (GConfClient             *client,
+                   guint                    cnxn_id,
+                   GConfEntry              *entry,
+                   GnomeSettingsPluginInfo *info)
+{
+        if (gconf_value_get_bool (entry->value)) {
+                gnome_settings_plugin_info_activate (info);
+        } else {
+                gnome_settings_plugin_info_deactivate (info);
+        }
+}
+
+void
+gnome_settings_plugin_info_set_enabled_key_name (GnomeSettingsPluginInfo *info,
+                                                 const char              *key_name)
+{
+#if 0
+        key_name = g_strdup_printf ("%s/%s",
+                                    engine->priv->gconf_prefix,
+                                    gnome_settings_plugin_info_get_location (info));
+        gconf_client_add_dir (info->priv->client, key_name, GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
+        g_free (key_name);
+#endif
+
+        info->priv->enabled_notification_id = gconf_client_notify_add (info->priv->client,
+                                                                       key_name,
+                                                                       (GConfClientNotifyFunc)plugin_enabled_cb,
+                                                                       info,
+                                                                       NULL,
+                                                                       NULL);
+
+        info->priv->enabled = gconf_client_get_bool (info->priv->client, key_name, NULL);
+}
+
+GnomeSettingsPluginInfo *
+gnome_settings_plugin_info_new_from_file (const char *filename)
+{
+        GnomeSettingsPluginInfo *info;
+        gboolean                 res;
+
+        info = g_object_new (GNOME_TYPE_SETTINGS_PLUGIN_INFO, NULL);
+
+        res = gnome_settings_plugin_info_fill_from_file (info, filename);
+        if (! res) {
+                g_object_unref (info);
+                info = NULL;
+        }
+
+        return info;
+}
+
+static void
+_deactivate_plugin (GnomeSettingsPluginInfo *info)
+{
+        gnome_settings_plugin_deactivate (info->priv->plugin);
+}
+
+gboolean
+gnome_settings_plugin_info_deactivate (GnomeSettingsPluginInfo *info)
+{
+        g_return_val_if_fail (info != NULL, FALSE);
+
+        if (!info->priv->active || !info->priv->available) {
+                return TRUE;
+        }
+
+        _deactivate_plugin (info);
+
+        /* Update plugin state */
+        info->priv->active = FALSE;
+
+        return TRUE;
+}
+
+
+static gboolean
+load_plugin_module (GnomeSettingsPluginInfo *info)
+{
+        char *path;
+        char *dirname;
+
+        g_return_val_if_fail (info != NULL, FALSE);
+        g_return_val_if_fail (info->priv->file != NULL, FALSE);
+        g_return_val_if_fail (info->priv->location != NULL, FALSE);
+        g_return_val_if_fail (info->priv->plugin == NULL, FALSE);
+        g_return_val_if_fail (info->priv->available, FALSE);
+
+        switch (info->priv->loader) {
+                case GNOME_SETTINGS_PLUGIN_LOADER_C:
+                        dirname = g_path_get_dirname (info->priv->file);
+                        g_return_val_if_fail (dirname != NULL, FALSE);
+
+                        path = g_module_build_path (dirname, info->priv->location);
+                        g_free (dirname);
+                        g_return_val_if_fail (path != NULL, FALSE);
+
+                        info->priv->module = G_TYPE_MODULE (gnome_settings_module_new (path));
+                        g_free (path);
+
+                        break;
+
+#ifdef ENABLE_PYTHON
+                case GNOME_SETTINGS_PLUGIN_LOADER_PY:
+                {
+                        char *dir;
+
+                        if (!gnome_settings_python_init ()) {
+                                /* Mark plugin as unavailable and fails */
+                                info->priv->available = FALSE;
+
+                                g_warning ("Cannot load Python plugin '%s' since gnome_settings "
+                                           "was not able to initialize the Python interpreter.",
+                                           info->priv->name);
+
+                                return FALSE;
+                        }
+
+                        dir = g_path_get_dirname (info->priv->file);
+
+                        g_return_val_if_fail ((info->priv->location != NULL) &&
+                                              (info->priv->location[0] != '\0'),
+                                              FALSE);
+
+                        info->priv->module = G_TYPE_MODULE (
+                                        gnome_settings_python_module_new (dir, info->priv->location));
+
+                        g_free (dir);
+                        break;
+                }
+#endif
+                default:
+                        g_return_val_if_reached (FALSE);
+        }
+
+        if (!g_type_module_use (info->priv->module)) {
+                switch (info->priv->loader) {
+                        case GNOME_SETTINGS_PLUGIN_LOADER_C:
+                                g_warning ("Cannot load plugin '%s' since file '%s' cannot be read.",
+                                           info->priv->name,
+                                           gnome_settings_module_get_path (GNOME_SETTINGS_MODULE (info->priv->module)));
+                                break;
+
+                        case GNOME_SETTINGS_PLUGIN_LOADER_PY:
+                                g_warning ("Cannot load Python plugin '%s' since file '%s' cannot be read.",
+                                           info->priv->name,
+                                           info->priv->location);
+                                break;
+
+                        default:
+                                g_return_val_if_reached (FALSE);
+                }
+
+                g_object_unref (G_OBJECT (info->priv->module));
+                info->priv->module = NULL;
+
+                /* Mark plugin as unavailable and fails */
+                info->priv->available = FALSE;
+
+                return FALSE;
+        }
+
+        switch (info->priv->loader) {
+                case GNOME_SETTINGS_PLUGIN_LOADER_C:
+                        info->priv->plugin =
+                                GNOME_SETTINGS_PLUGIN (gnome_settings_module_new_object (GNOME_SETTINGS_MODULE (info->priv->module)));
+                        break;
+
+#ifdef ENABLE_PYTHON
+                case GNOME_SETTINGS_PLUGIN_LOADER_PY:
+                        info->priv->plugin =
+                                GNOME_SETTINGS_PLUGIN (gnome_settings_python_module_new_object (GNOME_SETTINGS_PYTHON_MODULE (info->priv->module)));
+                        break;
+#endif
+
+                default:
+                        g_return_val_if_reached (FALSE);
+        }
+
+        g_type_module_unuse (info->priv->module);
+
+        return TRUE;
+}
+
+static gboolean
+_activate_plugin (GnomeSettingsPluginInfo *info)
+{
+        gboolean res = TRUE;
+
+        if (!info->priv->available) {
+                /* Plugin is not available, don't try to activate/load it */
+                return FALSE;
+        }
+
+        if (info->priv->plugin == NULL)
+                res = load_plugin_module (info);
+
+        if (res) {
+                gnome_settings_plugin_activate (info->priv->plugin);
+        } else {
+                g_warning ("Error activating plugin '%s'", info->priv->name);
+        }
+
+        return res;
+}
+
+gboolean
+gnome_settings_plugin_info_activate (GnomeSettingsPluginInfo *info)
+{
+
+        g_return_val_if_fail (info != NULL, FALSE);
+
+        if (! info->priv->available) {
+                return FALSE;
+        }
+
+        if (info->priv->active) {
+                return TRUE;
+        }
+
+        if (_activate_plugin (info)) {
+                info->priv->active = TRUE;
+                return TRUE;
+        }
+
+        return FALSE;
+}
+
+gboolean
+gnome_settings_plugin_info_is_active (GnomeSettingsPluginInfo *info)
+{
+        g_return_val_if_fail (info != NULL, FALSE);
+
+        return (info->priv->available && info->priv->active);
+}
+
+gboolean
+gnome_settings_plugin_info_get_enabled (GnomeSettingsPluginInfo *info)
+{
+        g_return_val_if_fail (info != NULL, FALSE);
+
+        return (info->priv->enabled);
+}
+
+gboolean
+gnome_settings_plugin_info_is_available (GnomeSettingsPluginInfo *info)
+{
+        g_return_val_if_fail (info != NULL, FALSE);
+
+        return (info->priv->available != FALSE);
+}
+
+const char *
+gnome_settings_plugin_info_get_name (GnomeSettingsPluginInfo *info)
+{
+        g_return_val_if_fail (info != NULL, NULL);
+
+        return info->priv->name;
+}
+
+const char *
+gnome_settings_plugin_info_get_description (GnomeSettingsPluginInfo *info)
+{
+        g_return_val_if_fail (info != NULL, NULL);
+
+        return info->priv->desc;
+}
+
+const char **
+gnome_settings_plugin_info_get_authors (GnomeSettingsPluginInfo *info)
+{
+        g_return_val_if_fail (info != NULL, (const char **)NULL);
+
+        return (const char **)info->priv->authors;
+}
+
+const char *
+gnome_settings_plugin_info_get_website (GnomeSettingsPluginInfo *info)
+{
+        g_return_val_if_fail (info != NULL, NULL);
+
+        return info->priv->website;
+}
+
+const char *
+gnome_settings_plugin_info_get_copyright (GnomeSettingsPluginInfo *info)
+{
+        g_return_val_if_fail (info != NULL, NULL);
+
+        return info->priv->copyright;
+}
+
+
+const char *
+gnome_settings_plugin_info_get_location (GnomeSettingsPluginInfo *info)
+{
+        g_return_val_if_fail (info != NULL, NULL);
+
+        return info->priv->location;
+}
+
+gint
+gnome_settings_plugin_info_get_priority (GnomeSettingsPluginInfo *info)
+{
+        g_return_val_if_fail (info != NULL, PLUGIN_PRIORITY_DEFAULT);
+
+        return info->priv->priority;
+}

Added: trunk/gnome-settings-daemon/gnome-settings-plugin-info.h
==============================================================================
--- (empty file)
+++ trunk/gnome-settings-daemon/gnome-settings-plugin-info.h	Fri Feb 22 20:23:37 2008
@@ -0,0 +1,72 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2008 Red Hat, Inc.
+ *
+ * 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * 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.
+ */
+
+#ifndef __GNOME_SETTINGS_PLUGIN_INFO_H__
+#define __GNOME_SETTINGS_PLUGIN_INFO_H__
+
+#include <glib-object.h>
+#include <gmodule.h>
+
+G_BEGIN_DECLS
+#define GNOME_TYPE_SETTINGS_PLUGIN_INFO              (gnome_settings_plugin_info_get_type())
+#define GNOME_SETTINGS_PLUGIN_INFO(obj)              (G_TYPE_CHECK_INSTANCE_CAST((obj), GNOME_TYPE_SETTINGS_PLUGIN_INFO, GnomeSettingsPluginInfo))
+#define GNOME_SETTINGS_PLUGIN_INFO_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST((klass),  GNOME_TYPE_SETTINGS_PLUGIN_INFO, GnomeSettingsPluginInfoClass))
+#define GNOME_IS_SETTINGS_PLUGIN_INFO(obj)           (G_TYPE_CHECK_INSTANCE_TYPE((obj), GNOME_TYPE_SETTINGS_PLUGIN_INFO))
+#define GNOME_IS_SETTINGS_PLUGIN_INFO_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE ((klass), GNOME_TYPE_SETTINGS_PLUGIN_INFO))
+#define GNOME_SETTINGS_PLUGIN_INFO_GET_CLASS(obj)    (G_TYPE_INSTANCE_GET_CLASS((obj),  GNOME_TYPE_SETTINGS_PLUGIN_INFO, GnomeSettingsPluginInfoClass))
+
+typedef struct GnomeSettingsPluginInfoPrivate GnomeSettingsPluginInfoPrivate;
+
+typedef struct
+{
+        GObject                         parent;
+        GnomeSettingsPluginInfoPrivate *priv;
+} GnomeSettingsPluginInfo;
+
+typedef struct
+{
+        GObjectClass parent_class;
+
+} GnomeSettingsPluginInfoClass;
+
+GType            gnome_settings_plugin_info_get_type           (void) G_GNUC_CONST;
+
+GnomeSettingsPluginInfo *gnome_settings_plugin_info_new_from_file (const char *filename);
+
+void             gnome_settings_plugin_info_set_enabled_key_name (GnomeSettingsPluginInfo *info,
+                                                                  const char              *key_name);
+gboolean         gnome_settings_plugin_info_activate        (GnomeSettingsPluginInfo *info);
+gboolean         gnome_settings_plugin_info_deactivate      (GnomeSettingsPluginInfo *info);
+
+gboolean         gnome_settings_plugin_info_is_active       (GnomeSettingsPluginInfo *info);
+gboolean         gnome_settings_plugin_info_get_enabled     (GnomeSettingsPluginInfo *info);
+gboolean         gnome_settings_plugin_info_is_available    (GnomeSettingsPluginInfo *info);
+
+const char      *gnome_settings_plugin_info_get_name        (GnomeSettingsPluginInfo *info);
+const char      *gnome_settings_plugin_info_get_description (GnomeSettingsPluginInfo *info);
+const char     **gnome_settings_plugin_info_get_authors     (GnomeSettingsPluginInfo *info);
+const char      *gnome_settings_plugin_info_get_website     (GnomeSettingsPluginInfo *info);
+const char      *gnome_settings_plugin_info_get_copyright   (GnomeSettingsPluginInfo *info);
+const char      *gnome_settings_plugin_info_get_location    (GnomeSettingsPluginInfo *info);
+gint             gnome_settings_plugin_info_get_priority    (GnomeSettingsPluginInfo *info);
+
+G_END_DECLS
+
+#endif  /* __GNOME_SETTINGS_PLUGIN_INFO_H__ */

Modified: trunk/gnome-settings-daemon/gnome-settings-plugins-engine.c
==============================================================================
--- trunk/gnome-settings-daemon/gnome-settings-plugins-engine.c	(original)
+++ trunk/gnome-settings-daemon/gnome-settings-plugins-engine.c	Fri Feb 22 20:23:37 2008
@@ -2,7 +2,8 @@
  *
  * Copyright (C) 2002-2005 Paolo Maggi
  * Copyright (C) 2007      William Jon McCann <mccann jhu edu>
- *                         Jens Granseuer <jensgr gmx net>
+ * Copyright (C) 2007      Jens Granseuer <jensgr gmx net>
+ * Copyright (C) 2008      Red Hat, Inc.
  *
  * 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
@@ -26,285 +27,122 @@
 
 #include <glib.h>
 #include <glib/gi18n.h>
-#include <gmodule.h>
-#include <gconf/gconf-client.h>
 
 #include "gnome-settings-plugins-engine.h"
-#include "gnome-settings-plugin.h"
-
-#include "gnome-settings-module.h"
+#include "gnome-settings-plugin-info.h"
 
 #define PLUGIN_EXT ".gnome-settings-plugin"
-#define PLUGIN_GROUP "GNOME Settings Plugin"
-
-#define PLUGIN_PRIORITY_MAX 1
-#define PLUGIN_PRIORITY_DEFAULT 100
 
-typedef enum
-{
-        GNOME_SETTINGS_PLUGIN_LOADER_C,
-        GNOME_SETTINGS_PLUGIN_LOADER_PY
-} GnomeSettingsPluginLoader;
+#define GNOME_SETTINGS_PLUGINS_ENGINE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GNOME_TYPE_SETTINGS_PLUGINS_ENGINE, GnomeSettingsPluginsEnginePrivate))
 
-struct _GnomeSettingsPluginInfo
+struct GnomeSettingsPluginsEnginePrivate
 {
-        char                    *file;
-
-        char                    *location;
-        GnomeSettingsPluginLoader  loader;
-        GTypeModule             *module;
-
-        char                    *name;
-        char                    *desc;
-        char                   **authors;
-        char                    *copyright;
-        char                    *website;
-
-        GnomeSettingsPlugin     *plugin;
-
-        gint                     activate : 1;
-        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;
-
-        guint                    active_notification_id;
-
-        /* Priority determines the order in which plugins are started and
-         * stopped. A lower number means higher priority. */
-        guint                    priority;
+        char        *gconf_prefix;
+        GSList      *plugins;
 };
 
-static char        *gnome_settings_gconf_prefix = NULL;
-static GSList      *gnome_settings_plugins = NULL;
-static GConfClient *client = NULL;
-
-static void
-gnome_settings_plugin_info_free (GnomeSettingsPluginInfo *info)
-{
-        if (info->plugin != NULL) {
-                g_debug ("Unref plugin %s", info->name);
-
-                g_object_unref (info->plugin);
+enum {
+        PROP_0,
+        PROP_GCONF_PREFIX,
+};
 
-                /* info->module must not be unref since it is not possible to finalize
-                 * a type module */
-        }
+static void     gnome_settings_plugins_engine_class_init  (GnomeSettingsPluginsEngineClass *klass);
+static void     gnome_settings_plugins_engine_init        (GnomeSettingsPluginsEngine      *settings_plugins_engine);
+static void     gnome_settings_plugins_engine_finalize    (GObject                   *object);
 
-        g_free (info->file);
-        g_free (info->location);
-        g_free (info->name);
-        g_free (info->desc);
-        g_free (info->website);
-        g_free (info->copyright);
-        g_strfreev (info->authors);
+G_DEFINE_TYPE (GnomeSettingsPluginsEngine, gnome_settings_plugins_engine, G_TYPE_OBJECT)
 
-        g_slice_free (GnomeSettingsPluginInfo, info);
-}
+static gpointer engine_object = NULL;
 
 static GnomeSettingsPluginInfo *
-gnome_settings_plugins_engine_load (const char *file)
+gnome_settings_plugins_engine_load (GnomeSettingsPluginsEngine *engine,
+                                    const char                 *file)
 {
         GnomeSettingsPluginInfo *info;
-        GKeyFile *plugin_file = NULL;
-        char *str;
-        gint priority;
 
         g_return_val_if_fail (file != NULL, NULL);
 
         g_debug ("Loading plugin: %s", file);
 
-        info = g_slice_new0 (GnomeSettingsPluginInfo);
-        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, PLUGIN_GROUP, "IAge", NULL)) {
-                g_debug ("IAge key does not exist in file: %s", file);
-                goto error;
-        }
-
-        /* Check IAge=2 */
-        if (g_key_file_get_integer (plugin_file, PLUGIN_GROUP, "IAge", NULL) != 0) {
-                g_debug ("Wrong IAge in file: %s", file);
-                goto error;
-        }
-
-        /* Get Location */
-        str = g_key_file_get_string (plugin_file, PLUGIN_GROUP, "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, PLUGIN_GROUP, "Loader", NULL);
-        if (str && strcmp(str, "python") == 0) {
-                info->loader = GNOME_SETTINGS_PLUGIN_LOADER_PY;
-#ifndef ENABLE_PYTHON
-                g_warning ("Cannot load Python plugin '%s' since gnome_settings was not "
-                           "compiled with Python support.", file);
-                goto error;
-#endif
-        } else {
-                info->loader = GNOME_SETTINGS_PLUGIN_LOADER_C;
-        }
-        g_free (str);
-
-        /* Get Name */
-        str = g_key_file_get_locale_string (plugin_file, PLUGIN_GROUP, "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, PLUGIN_GROUP, "Description", NULL, NULL);
-        if (str)
-                info->desc = str;
-        else
-                g_debug ("Could not find 'Description' in %s", file);
-
-        /* Get Authors */
-        info->authors = g_key_file_get_string_list (plugin_file, PLUGIN_GROUP, "Authors", NULL, NULL);
-        if (info->authors == NULL)
-                g_debug ("Could not find 'Authors' in %s", file);
-
-        /* Get Copyright */
-        str = g_key_file_get_string (plugin_file, PLUGIN_GROUP, "Copyright", NULL);
-        if (str)
-                info->copyright = str;
-        else
-                g_debug ("Could not find 'Copyright' in %s", file);
-
-        /* Get Website */
-        str = g_key_file_get_string (plugin_file, PLUGIN_GROUP, "Website", NULL);
-        if (str)
-                info->website = str;
-        else
-                g_debug ("Could not find 'Website' in %s", file);
-
-        /* Get Priority */
-        priority = g_key_file_get_integer (plugin_file, PLUGIN_GROUP, "Priority", NULL);
-        if (priority >= PLUGIN_PRIORITY_MAX) {
-                info->priority = priority;
-        } else {
-                g_debug ("Could not find valid 'Priority' in %s", file);
-                info->priority = PLUGIN_PRIORITY_DEFAULT;
-        }
-
-        g_key_file_free (plugin_file);
-
-        /* If we know nothing about the availability of the plugin,
-           set it as available */
-        info->available = TRUE;
+        info = gnome_settings_plugin_info_new_from_file (file);
 
         return info;
-
-error:
-        g_free (info->file);
-        g_free (info->location);
-        g_free (info->name);
-        g_slice_free (GnomeSettingsPluginInfo, info);
-
-        g_key_file_free (plugin_file);
-
-        return NULL;
-}
-
-static void
-gnome_settings_plugins_engine_plugin_active_cb (GConfClient           *client,
-                                              guint                  cnxn_id,
-                                              GConfEntry            *entry,
-                                              GnomeSettingsPluginInfo *info)
-{
-        if (gconf_value_get_bool (entry->value)) {
-                gnome_settings_plugins_engine_activate_plugin (info);
-        } else {
-                gnome_settings_plugins_engine_deactivate_plugin (info);
-        }
 }
 
 static void
-activate_plugin (GnomeSettingsPluginInfo *info, gpointer user_data)
+maybe_activate_plugin (GnomeSettingsPluginInfo *info, gpointer user_data)
 {
-        if (info->activate) {
+        if (gnome_settings_plugin_info_get_enabled (info)) {
                 gboolean res;
-                res = gnome_settings_plugins_engine_activate_plugin (info);
+                res = gnome_settings_plugin_info_activate (info);
                 if (res) {
-                        g_debug ("Plugin %s: active", info->location);
+                        g_debug ("Plugin %s: active", gnome_settings_plugin_info_get_location (info));
                 } else {
-                        g_debug ("Plugin %s: activation failed", info->location);
+                        g_debug ("Plugin %s: activation failed", gnome_settings_plugin_info_get_location (info));
                 }
         } else {
-                g_debug ("Plugin %s: inactive", info->location);
+                g_debug ("Plugin %s: inactive", gnome_settings_plugin_info_get_location (info));
         }
 }
 
 static gint
-compare_location (const GnomeSettingsPluginInfo *a,
-                  const GnomeSettingsPluginInfo *b)
+compare_location (GnomeSettingsPluginInfo *a,
+                  GnomeSettingsPluginInfo *b)
 {
-        return strcmp (a->location, b->location);
+        const char *loc_a;
+        const char *loc_b;
+
+        loc_a = gnome_settings_plugin_info_get_location (a);
+        loc_b = gnome_settings_plugin_info_get_location (b);
+
+        return strcmp (loc_a, loc_b);
 }
 
-static gint
-compare_priority (const GnomeSettingsPluginInfo *a,
-                  const GnomeSettingsPluginInfo *b)
+static int
+compare_priority (GnomeSettingsPluginInfo *a,
+                  GnomeSettingsPluginInfo *b)
 {
-        return a->priority - b->priority;
+        int prio_a;
+        int prio_b;
+
+        prio_a = gnome_settings_plugin_info_get_priority (a);
+        prio_b = gnome_settings_plugin_info_get_priority (b);
+
+        return prio_a - prio_b;
 }
 
 static void
-gnome_settings_plugins_engine_load_file (const char *filename)
+gnome_settings_plugins_engine_load_file (GnomeSettingsPluginsEngine *engine,
+                                         const char                 *filename)
 {
         GnomeSettingsPluginInfo *info;
         char                    *key_name;
 
-        info = gnome_settings_plugins_engine_load (filename);
+        info = gnome_settings_plugins_engine_load (engine, filename);
         if (info == NULL) {
                 return;
         }
 
-        if (g_slist_find_custom (gnome_settings_plugins,
+        if (g_slist_find_custom (engine->priv->plugins,
                                  info,
                                  (GCompareFunc) compare_location)) {
-                gnome_settings_plugin_info_free (info);
+                g_object_unref (info);
                 return;
         }
 
-        gnome_settings_plugins = g_slist_prepend (gnome_settings_plugins, info);
-
-        key_name = g_strdup_printf ("%s/%s", gnome_settings_gconf_prefix, info->location);
-        gconf_client_add_dir (client, key_name, GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
-        g_free (key_name);
-
-        key_name = g_strdup_printf ("%s/%s/active", gnome_settings_gconf_prefix, info->location);
+        engine->priv->plugins = g_slist_prepend (engine->priv->plugins, info);
 
-        info->active_notification_id = gconf_client_notify_add (client,
-                                                                key_name,
-                                                                (GConfClientNotifyFunc)gnome_settings_plugins_engine_plugin_active_cb,
-                                                                info,
-                                                                NULL,
-                                                                NULL);
 
-        info->activate = gconf_client_get_bool (client, key_name, NULL);
+        key_name = g_strdup_printf ("%s/%s/active",
+                                    engine->priv->gconf_prefix,
+                                    gnome_settings_plugin_info_get_location (info));
+        gnome_settings_plugin_info_set_enabled_key_name (info, key_name);
         g_free (key_name);
 }
 
 static void
-gnome_settings_plugins_engine_load_dir (const char *path)
+gnome_settings_plugins_engine_load_dir (GnomeSettingsPluginsEngine *engine,
+                                        const char                 *path)
 {
         GError     *error;
         GDir       *d;
@@ -328,7 +166,7 @@
 
                 filename = g_build_filename (path, name, NULL);
                 if (g_file_test (filename, G_FILE_TEST_IS_REGULAR)) {
-                        gnome_settings_plugins_engine_load_file (filename);
+                        gnome_settings_plugins_engine_load_file (engine, filename);
                 }
                 g_free (filename);
         }
@@ -337,45 +175,47 @@
 }
 
 static void
-gnome_settings_plugins_engine_load_all (void)
+gnome_settings_plugins_engine_load_all (GnomeSettingsPluginsEngine *engine)
 {
         /* load system plugins */
-        gnome_settings_plugins_engine_load_dir (GNOME_SETTINGS_PLUGINDIR G_DIR_SEPARATOR_S);
+        gnome_settings_plugins_engine_load_dir (engine,
+                                                GNOME_SETTINGS_PLUGINDIR G_DIR_SEPARATOR_S);
 
-        gnome_settings_plugins = g_slist_sort (gnome_settings_plugins, (GCompareFunc) compare_priority);
-        g_slist_foreach (gnome_settings_plugins, (GFunc) activate_plugin, NULL);
+        engine->priv->plugins = g_slist_sort (engine->priv->plugins, (GCompareFunc) compare_priority);
+        g_slist_foreach (engine->priv->plugins, (GFunc) maybe_activate_plugin, NULL);
 }
 
-gboolean
-gnome_settings_plugins_engine_init (const char *gconf_prefix)
+static void
+gnome_settings_plugins_engine_unload_all (GnomeSettingsPluginsEngine *engine)
 {
-        g_return_val_if_fail (gnome_settings_plugins == NULL, FALSE);
-        g_return_val_if_fail (gconf_prefix != NULL, FALSE);
+         g_slist_foreach (engine->priv->plugins, (GFunc) g_object_unref, NULL);
+         g_slist_free (engine->priv->plugins);
+         engine->priv->plugins = NULL;
+}
 
+gboolean
+gnome_settings_plugins_engine_start (GnomeSettingsPluginsEngine *engine)
+{
         if (!g_module_supported ()) {
                 g_warning ("gnome-settings-daemon is not able to initialize the plugins engine.");
                 return FALSE;
         }
 
-        gnome_settings_gconf_prefix = g_strdup (gconf_prefix);
-
-        client = gconf_client_get_default ();
-
-        gnome_settings_plugins_engine_load_all ();
+        gnome_settings_plugins_engine_load_all (engine);
 
         return TRUE;
 }
 
 void
-gnome_settings_plugins_engine_garbage_collect (void)
+gnome_settings_plugins_engine_garbage_collect (GnomeSettingsPluginsEngine *engine)
 {
 #ifdef ENABLE_PYTHON
         gnome_settings_python_garbage_collect ();
 #endif
 }
 
-void
-gnome_settings_plugins_engine_shutdown (void)
+gboolean
+gnome_settings_plugins_engine_stop (GnomeSettingsPluginsEngine *engine)
 {
 
 #ifdef ENABLE_PYTHON
@@ -387,279 +227,121 @@
         gnome_settings_python_shutdown ();
 #endif
 
-        g_slist_foreach (gnome_settings_plugins,
-                         (GFunc) gnome_settings_plugin_info_free,
-                         NULL);
-        g_slist_free (gnome_settings_plugins);
-        gnome_settings_plugins = NULL;
-
-        if (client != NULL) {
-                g_object_unref (client);
-                client = NULL;
-        }
+        gnome_settings_plugins_engine_unload_all (engine);
 
-        g_free (gnome_settings_gconf_prefix);
-        gnome_settings_gconf_prefix = NULL;
+        return TRUE;
 }
 
 const GSList *
-gnome_settings_plugins_engine_get_plugins_list (void)
-{
-        return gnome_settings_plugins;
-}
-
-static gboolean
-load_plugin_module (GnomeSettingsPluginInfo *info)
+gnome_settings_plugins_engine_get_plugins_list (GnomeSettingsPluginsEngine *engine)
 {
-        char *path;
-        char *dirname;
-
-        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 GNOME_SETTINGS_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 (gnome_settings_module_new (path));
-                        g_free (path);
-
-                        break;
-
-#ifdef ENABLE_PYTHON
-                case GNOME_SETTINGS_PLUGIN_LOADER_PY:
-                {
-                        char *dir;
-
-                        if (!gnome_settings_python_init ()) {
-                                /* Mark plugin as unavailable and fails */
-                                info->available = FALSE;
-
-                                g_warning ("Cannot load Python plugin '%s' since gnome_settings "
-                                           "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 (
-                                        gnome_settings_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 GNOME_SETTINGS_PLUGIN_LOADER_C:
-                                g_warning ("Cannot load plugin '%s' since file '%s' cannot be read.",
-                                           info->name,
-                                           gnome_settings_module_get_path (GNOME_SETTINGS_MODULE (info->module)));
-                                break;
-
-                        case GNOME_SETTINGS_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 GNOME_SETTINGS_PLUGIN_LOADER_C:
-                        info->plugin =
-                                GNOME_SETTINGS_PLUGIN (gnome_settings_module_new_object (GNOME_SETTINGS_MODULE (info->module)));
-                        break;
-
-#ifdef ENABLE_PYTHON
-                case GNOME_SETTINGS_PLUGIN_LOADER_PY:
-                        info->plugin =
-                                GNOME_SETTINGS_PLUGIN (gnome_settings_python_module_new_object (GNOME_SETTINGS_PYTHON_MODULE (info->module)));
-                        break;
-#endif
-
-                default:
-                        g_return_val_if_reached (FALSE);
-        }
-
-        g_type_module_unuse (info->module);
-
-        return TRUE;
+        return engine->priv->plugins;
 }
 
-static gboolean
-gnome_settings_plugins_engine_activate_plugin_real (GnomeSettingsPluginInfo *info)
+static void
+_set_gconf_prefix (GnomeSettingsPluginsEngine *self,
+                   const char           *prefix)
 {
-        gboolean res = TRUE;
-
-        if (!info->available) {
-                /* Plugin is not available, don't try to activate/load it */
-                return FALSE;
-        }
-
-        if (info->plugin == NULL)
-                res = load_plugin_module (info);
-
-        if (res) {
-                gnome_settings_plugin_activate (info->plugin);
-        } else {
-                g_warning ("Error activating plugin '%s'", info->name);
-        }
-
-        return res;
+        g_free (self->priv->gconf_prefix);
+        self->priv->gconf_prefix = g_strdup (prefix);
 }
 
-gboolean
-gnome_settings_plugins_engine_activate_plugin (GnomeSettingsPluginInfo *info)
-{
-
-        g_return_val_if_fail (info != NULL, FALSE);
-
-        if (! info->available) {
-                return FALSE;
-        }
-
-        if (info->active) {
-                return TRUE;
-        }
-
-        if (gnome_settings_plugins_engine_activate_plugin_real (info)) {
-                char *key_name;
-
-                key_name = g_strdup_printf ("%s/%s/active",
-                                            gnome_settings_gconf_prefix,
-                                            info->location);
-                gconf_client_set_bool (client, key_name, TRUE, NULL);
-                g_free (key_name);
-
-                info->active = TRUE;
-
-                return TRUE;
+static void
+gnome_settings_plugins_engine_set_property (GObject        *object,
+                                            guint           prop_id,
+                                            const GValue   *value,
+                                            GParamSpec     *pspec)
+{
+        GnomeSettingsPluginsEngine *self;
+
+        self = GNOME_SETTINGS_PLUGINS_ENGINE (object);
+
+        switch (prop_id) {
+        case PROP_GCONF_PREFIX:
+                _set_gconf_prefix (self, g_value_get_string (value));
+                break;
+        default:
+                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+                break;
         }
-
-        return FALSE;
 }
 
 static void
-gnome_settings_plugins_engine_deactivate_plugin_real (GnomeSettingsPluginInfo *info)
-{
-        gnome_settings_plugin_deactivate (info->plugin);
-}
-
-gboolean
-gnome_settings_plugins_engine_deactivate_plugin (GnomeSettingsPluginInfo *info)
-{
-        char *key_name;
-
-        g_return_val_if_fail (info != NULL, FALSE);
-
-        if (!info->active || !info->available) {
-                return TRUE;
+gnome_settings_plugins_engine_get_property (GObject        *object,
+                                            guint           prop_id,
+                                            GValue         *value,
+                                            GParamSpec     *pspec)
+{
+        GnomeSettingsPluginsEngine *self;
+
+        self = GNOME_SETTINGS_PLUGINS_ENGINE (object);
+
+        switch (prop_id) {
+        case PROP_GCONF_PREFIX:
+                g_value_set_string (value, self->priv->gconf_prefix);
+                break;
+        default:
+                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+                break;
         }
-
-        gnome_settings_plugins_engine_deactivate_plugin_real (info);
-
-        /* Update plugin state */
-        info->active = FALSE;
-
-        key_name = g_strdup_printf ("%s/%s/active",
-                                    gnome_settings_gconf_prefix,
-                                    info->location);
-        gconf_client_set_bool (client, key_name, FALSE, NULL);
-        g_free (key_name);
-
-        return TRUE;
 }
 
-gboolean
-gnome_settings_plugins_engine_plugin_is_active (GnomeSettingsPluginInfo *info)
+static void
+gnome_settings_plugins_engine_class_init (GnomeSettingsPluginsEngineClass *klass)
 {
-        g_return_val_if_fail (info != NULL, FALSE);
-
-        return (info->available && info->active);
-}
+        GObjectClass   *object_class = G_OBJECT_CLASS (klass);
 
-gboolean
-gnome_settings_plugins_engine_plugin_is_available (GnomeSettingsPluginInfo *info)
-{
-        g_return_val_if_fail (info != NULL, FALSE);
+        object_class->get_property = gnome_settings_plugins_engine_get_property;
+        object_class->set_property = gnome_settings_plugins_engine_set_property;
+        object_class->finalize = gnome_settings_plugins_engine_finalize;
+
+        g_object_class_install_property (object_class,
+                                         PROP_GCONF_PREFIX,
+                                         g_param_spec_string ("gconf-prefix",
+                                                              "gconf-prefix",
+                                                              "gconf-prefix",
+                                                              NULL,
+                                                              G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
 
-        return (info->available != FALSE);
+        g_type_class_add_private (klass, sizeof (GnomeSettingsPluginsEnginePrivate));
 }
 
-const char *
-gnome_settings_plugins_engine_get_plugin_name (GnomeSettingsPluginInfo *info)
+static void
+gnome_settings_plugins_engine_init (GnomeSettingsPluginsEngine *engine)
 {
-        g_return_val_if_fail (info != NULL, NULL);
-
-        return info->name;
+        engine->priv = GNOME_SETTINGS_PLUGINS_ENGINE_GET_PRIVATE (engine);
 }
 
-const char *
-gnome_settings_plugins_engine_get_plugin_description (GnomeSettingsPluginInfo *info)
+static void
+gnome_settings_plugins_engine_finalize (GObject *object)
 {
-        g_return_val_if_fail (info != NULL, NULL);
+        GnomeSettingsPluginsEngine *engine;
 
-        return info->desc;
-}
+        g_return_if_fail (object != NULL);
+        g_return_if_fail (GNOME_IS_SETTINGS_PLUGINS_ENGINE (object));
 
-const char **
-gnome_settings_plugins_engine_get_plugin_authors (GnomeSettingsPluginInfo *info)
-{
-        g_return_val_if_fail (info != NULL, (const char **)NULL);
+        engine = GNOME_SETTINGS_PLUGINS_ENGINE (object);
 
-        return (const char **)info->authors;
-}
+        g_return_if_fail (engine->priv != NULL);
 
-const char *
-gnome_settings_plugins_engine_get_plugin_website (GnomeSettingsPluginInfo *info)
-{
-        g_return_val_if_fail (info != NULL, NULL);
+        g_free (engine->priv->gconf_prefix);
 
-        return info->website;
+        G_OBJECT_CLASS (gnome_settings_plugins_engine_parent_class)->finalize (object);
 }
 
-const char *
-gnome_settings_plugins_engine_get_plugin_copyright (GnomeSettingsPluginInfo *info)
+GnomeSettingsPluginsEngine *
+gnome_settings_plugins_engine_new (const char *gconf_prefix)
 {
-        g_return_val_if_fail (info != NULL, NULL);
+        if (engine_object != NULL) {
+                g_object_ref (engine_object);
+        } else {
+                engine_object = g_object_new (GNOME_TYPE_SETTINGS_PLUGINS_ENGINE,
+                                              "gconf-prefix", gconf_prefix,
+                                              NULL);
+                g_object_add_weak_pointer (engine_object,
+                                           (gpointer *) &engine_object);
+        }
 
-        return info->copyright;
+        return GNOME_SETTINGS_PLUGINS_ENGINE (engine_object);
 }
 
-gint
-gnome_settings_plugins_engine_get_plugin_priority (GnomeSettingsPluginInfo *info)
-{
-        g_return_val_if_fail (info != NULL, PLUGIN_PRIORITY_DEFAULT);
-
-        return info->priority;
-}

Modified: trunk/gnome-settings-daemon/gnome-settings-plugins-engine.h
==============================================================================
--- trunk/gnome-settings-daemon/gnome-settings-plugins-engine.h	(original)
+++ trunk/gnome-settings-daemon/gnome-settings-plugins-engine.h	Fri Feb 22 20:23:37 2008
@@ -1,7 +1,8 @@
 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
  *
- * Copyright (C) 2002-2005 - Paolo Maggi
- * Copyright (C) 2007        William Jon McCann <mccann jhu edu>
+ * Copyright (C) 2002-2005 Paolo Maggi
+ * Copyright (C) 2007      William Jon McCann <mccann jhu edu>
+ * Copyright (C) 2008      Red Hat, Inc.
  *
  * 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
@@ -22,27 +23,42 @@
 #ifndef __GNOME_SETTINGS_PLUGINS_ENGINE_H__
 #define __GNOME_SETTINGS_PLUGINS_ENGINE_H__
 
-#include <glib.h>
+#include <glib-object.h>
 
-typedef struct _GnomeSettingsPluginInfo GnomeSettingsPluginInfo;
+G_BEGIN_DECLS
 
-gboolean         gnome_settings_plugins_engine_init                   (const char *gconf_prefix);
-void             gnome_settings_plugins_engine_shutdown               (void);
+#define GNOME_TYPE_SETTINGS_PLUGINS_ENGINE         (gnome_settings_plugins_engine_get_type ())
+#define GNOME_SETTINGS_PLUGINS_ENGINE(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), GNOME_TYPE_SETTINGS_PLUGINS_ENGINE, GnomeSettingsPluginsEngine))
+#define GNOME_SETTINGS_PLUGINS_ENGINE_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST((k), GNOME_TYPE_SETTINGS_PLUGINS_ENGINE, GnomeSettingsPluginsEngineClass))
+#define GNOME_IS_SETTINGS_PLUGINS_ENGINE(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNOME_TYPE_SETTINGS_PLUGINS_ENGINE))
+#define GNOME_IS_SETTINGS_PLUGINS_ENGINE_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), GNOME_TYPE_SETTINGS_PLUGINS_ENGINE))
+#define GNOME_SETTINGS_PLUGINS_ENGINE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GNOME_TYPE_SETTINGS_PLUGINS_ENGINE, GnomeSettingsPluginsEngineClass))
 
-void             gnome_settings_plugins_engine_garbage_collect        (void);
+typedef struct GnomeSettingsPluginsEnginePrivate GnomeSettingsPluginsEnginePrivate;
 
-const GSList    *gnome_settings_plugins_engine_get_plugins_list       (void);
+typedef struct
+{
+        GObject                            parent;
+        GnomeSettingsPluginsEnginePrivate *priv;
+} GnomeSettingsPluginsEngine;
 
-gboolean         gnome_settings_plugins_engine_activate_plugin        (GnomeSettingsPluginInfo *info);
-gboolean         gnome_settings_plugins_engine_deactivate_plugin      (GnomeSettingsPluginInfo *info);
-gboolean         gnome_settings_plugins_engine_plugin_is_active       (GnomeSettingsPluginInfo *info);
-gboolean         gnome_settings_plugins_engine_plugin_is_available    (GnomeSettingsPluginInfo *info);
+typedef struct
+{
+        GObjectClass   parent_class;
+} GnomeSettingsPluginsEngineClass;
 
-const char      *gnome_settings_plugins_engine_get_plugin_name        (GnomeSettingsPluginInfo *info);
-const char      *gnome_settings_plugins_engine_get_plugin_description (GnomeSettingsPluginInfo *info);
-const char     **gnome_settings_plugins_engine_get_plugin_authors     (GnomeSettingsPluginInfo *info);
-const char      *gnome_settings_plugins_engine_get_plugin_website     (GnomeSettingsPluginInfo *info);
-const char      *gnome_settings_plugins_engine_get_plugin_copyright   (GnomeSettingsPluginInfo *info);
-gint             gnome_settings_plugins_engine_get_plugin_priority    (GnomeSettingsPluginInfo *info);
+
+GType                       gnome_settings_plugins_engine_get_type               (void);
+
+GnomeSettingsPluginsEngine *gnome_settings_plugins_engine_new                    (const char *gconf_prefix);
+gboolean         gnome_settings_plugins_engine_start                  (GnomeSettingsPluginsEngine *engine);
+
+gboolean         gnome_settings_plugins_engine_stop                   (GnomeSettingsPluginsEngine *engine);
+
+void             gnome_settings_plugins_engine_garbage_collect        (GnomeSettingsPluginsEngine *engine);
+
+const GSList    *gnome_settings_plugins_engine_get_plugins_list       (GnomeSettingsPluginsEngine *engine);
+
+G_END_DECLS
 
 #endif  /* __GNOME_SETTINGS_PLUGINS_ENGINE_H__ */



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