new class for modules.
2007-04-20 Rodrigo Moya <rodrigo@gnome-db.org> * gnome-settings-module.[ch]: new class for modules. * Makefile.am: added new files. svn path=/trunk/; revision=7478
This commit is contained in:
parent
99e9b414dd
commit
6535f4364e
4 changed files with 259 additions and 0 deletions
|
@ -1,3 +1,9 @@
|
|||
2007-04-20 Rodrigo Moya <rodrigo@gnome-db.org>
|
||||
|
||||
* gnome-settings-module.[ch]: new class for modules.
|
||||
|
||||
* Makefile.am: added new files.
|
||||
|
||||
2007-04-11 Ross Burton <ross@burtonini.com>
|
||||
|
||||
* xrdb/General.ad:
|
||||
|
|
|
@ -44,6 +44,8 @@ gnome_settings_daemon_SOURCES = \
|
|||
gnome-settings-keyboard.c \
|
||||
gnome-settings-locate-pointer.c \
|
||||
gnome-settings-locate-pointer.h \
|
||||
gnome-settings-module.c \
|
||||
gnome-settings-module.h \
|
||||
gnome-settings-mouse.h \
|
||||
gnome-settings-mouse.c \
|
||||
gnome-settings-multimedia-keys.h \
|
||||
|
|
176
gnome-settings-daemon/gnome-settings-module.c
Normal file
176
gnome-settings-daemon/gnome-settings-module.c
Normal file
|
@ -0,0 +1,176 @@
|
|||
/*
|
||||
* Copyright (C) 2007 The GNOME Foundation
|
||||
*
|
||||
* Authors: Rodrigo Moya
|
||||
*
|
||||
* 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 "gnome-settings-module.h"
|
||||
|
||||
#define CLASS(module) (GNOME_SETTINGS_MODULE_CLASS (G_OBJECT_GET_CLASS (module)))
|
||||
|
||||
struct _GnomeSettingsModulePrivate {
|
||||
GnomeSettingsModuleStatus status;
|
||||
GConfClient *config_client;
|
||||
};
|
||||
|
||||
static GObjectClass *parent_class = NULL;
|
||||
|
||||
static void
|
||||
gnome_settings_module_finalize (GObject *object)
|
||||
{
|
||||
GnomeSettingsModule *module = GNOME_SETTINGS_MODULE (object);
|
||||
|
||||
g_return_if_fail (GNOME_SETTINGS_IS_MODULE (module));
|
||||
|
||||
if (module->priv) {
|
||||
if (module->priv->config_client) {
|
||||
g_object_unref (G_OBJECT (module->priv->config_client));
|
||||
module->priv->config_client = NULL;
|
||||
}
|
||||
|
||||
g_free (module->priv);
|
||||
module->priv = NULL;
|
||||
}
|
||||
|
||||
if (parent_class->finalize)
|
||||
parent_class->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
gnome_settings_module_init (GnomeSettingsModule *module, GnomeSettingsModuleClass *klass)
|
||||
{
|
||||
module->priv = g_new0 (GnomeSettingsModulePrivate, 1);
|
||||
module->priv->status = GNOME_SETTINGS_MODULE_STATUS_NONE;
|
||||
}
|
||||
|
||||
static void
|
||||
gnome_settings_module_class_init (GnomeSettingsModuleClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
parent_class = g_type_class_peek_parent (klass);
|
||||
|
||||
object_class->finalize = gnome_settings_module_finalize;
|
||||
|
||||
klass->initialize = NULL;
|
||||
klass->start = NULL;
|
||||
klass->stop = NULL;
|
||||
klass->reload_settings = NULL;
|
||||
}
|
||||
|
||||
GType
|
||||
gnome_settings_module_get_type (void)
|
||||
{
|
||||
static GType module_type = 0;
|
||||
|
||||
if (!module_type) {
|
||||
static const GTypeInfo module_info = {
|
||||
sizeof (GnomeSettingsModuleClass),
|
||||
NULL, /* base_init */
|
||||
NULL, /* base_finalize */
|
||||
(GClassInitFunc) gnome_settings_module_class_init,
|
||||
NULL, /* class_finalize */
|
||||
NULL, /* class_data */
|
||||
sizeof (GnomeSettingsModule),
|
||||
0, /* n_preallocs */
|
||||
(GInstanceInitFunc) gnome_settings_module_init,
|
||||
};
|
||||
|
||||
module_type = g_type_register_static (G_TYPE_OBJECT,
|
||||
"GnomeSettingsModule",
|
||||
&module_info, 0);
|
||||
}
|
||||
|
||||
return module_type;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gnome_settings_module_initialize (GnomeSettingsModule *module, GConfClient *config_client)
|
||||
{
|
||||
g_return_val_if_fail (GNOME_SETTINGS_IS_MODULE (module), FALSE);
|
||||
g_return_val_if_fail (module->priv->status == GNOME_SETTINGS_MODULE_STATUS_NONE, FALSE);
|
||||
g_return_val_if_fail (CLASS (module)->initialize != NULL, FALSE);
|
||||
|
||||
/* associate GConfClient with this module */
|
||||
if (module->priv->config_client)
|
||||
g_object_unref (module->priv->config_client);
|
||||
|
||||
module->priv->config_client = g_object_ref (config_client);
|
||||
|
||||
if (CLASS (module)->initialize (module, config_client)) {
|
||||
module->priv->status = GNOME_SETTINGS_MODULE_STATUS_INITIALIZED;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gnome_settings_module_start (GnomeSettingsModule *module)
|
||||
{
|
||||
g_return_val_if_fail (GNOME_SETTINGS_IS_MODULE (module), FALSE);
|
||||
g_return_val_if_fail (module->priv->status == GNOME_SETTINGS_MODULE_STATUS_INITIALIZED, FALSE);
|
||||
g_return_val_if_fail (CLASS (module)->start != NULL, FALSE);
|
||||
|
||||
if (CLASS (module)->start (module)) {
|
||||
module->priv->status = GNOME_SETTINGS_MODULE_STATUS_STARTED;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gnome_settings_module_stop (GnomeSettingsModule *module)
|
||||
{
|
||||
g_return_val_if_fail (GNOME_SETTINGS_IS_MODULE (module), FALSE);
|
||||
g_return_val_if_fail (module->priv->status == GNOME_SETTINGS_MODULE_STATUS_STARTED, FALSE);
|
||||
g_return_val_if_fail (CLASS (module)->stop != NULL, FALSE);
|
||||
|
||||
if (CLASS (module)->stop (module)) {
|
||||
module->priv->status = GNOME_SETTINGS_MODULE_STATUS_STOPPED;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gnome_settings_module_reload_settings (GnomeSettingsModule *module)
|
||||
{
|
||||
g_return_val_if_fail (GNOME_SETTINGS_IS_MODULE (module), FALSE);
|
||||
g_return_val_if_fail (CLASS (module)->reload_settings != NULL, FALSE);
|
||||
|
||||
return CLASS (module)->reload_settings (module);
|
||||
}
|
||||
|
||||
GConfClient *
|
||||
gnome_settings_module_get_config_client (GnomeSettingsModule *module)
|
||||
{
|
||||
g_return_val_if_fail (GNOME_SETTINGS_IS_MODULE (module), NULL);
|
||||
|
||||
return module->priv->config_client;
|
||||
}
|
||||
|
||||
GnomeSettingsModuleStatus
|
||||
gnome_settings_module_get_status (GnomeSettingsModule *module)
|
||||
{
|
||||
g_return_val_if_fail (GNOME_SETTINGS_IS_MODULE (module), GNOME_SETTINGS_MODULE_STATUS_NONE);
|
||||
|
||||
return module->priv->status;
|
||||
}
|
75
gnome-settings-daemon/gnome-settings-module.h
Normal file
75
gnome-settings-daemon/gnome-settings-module.h
Normal file
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* Copyright (C) 2007 The GNOME Foundation
|
||||
*
|
||||
* Authors: Rodrigo Moya
|
||||
*
|
||||
* 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_MODULE_H__
|
||||
#define __GNOME_SETTINGS_MODULE_H__
|
||||
|
||||
#include <glib-object.h>
|
||||
#include <gconf/gconf-client.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GNOME_SETTINGS_TYPE_MODULE (gnome_settings_module_get_type ())
|
||||
#define GNOME_SETTINGS_MODULE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GNOME_SETTINGS_TYPE_MODULE, GnomeSettingsModule))
|
||||
#define GNOME_SETTINGS_MODULE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), GNOME_SETTINGS_TYPE_MODULE, GnomeSettingsModuleClass))
|
||||
#define GNOME_SETTINGS_IS_MODULE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNOME_SETTINGS_TYPE_MODULE))
|
||||
#define GNOME_SETTINGS_IS_MODULE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GNOME_SETTINGS_TYPE_MODULE))
|
||||
#define GNOME_SETTINGS_MODULE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GNOME_SETTINGS_TYPE_MODULE, GnomeSettingsModuleClass))
|
||||
|
||||
typedef struct _GnomeSettingsModule GnomeSettingsModule;
|
||||
typedef struct _GnomeSettingsModuleClass GnomeSettingsModuleClass;
|
||||
typedef struct _GnomeSettingsModulePrivate GnomeSettingsModulePrivate;
|
||||
|
||||
typedef enum {
|
||||
GNOME_SETTINGS_MODULE_STATUS_NONE,
|
||||
GNOME_SETTINGS_MODULE_STATUS_INITIALIZED,
|
||||
GNOME_SETTINGS_MODULE_STATUS_STARTED,
|
||||
GNOME_SETTINGS_MODULE_STATUS_STOPPED
|
||||
} GnomeSettingsModuleStatus;
|
||||
|
||||
struct _GnomeSettingsModule {
|
||||
GObject parent;
|
||||
GnomeSettingsModulePrivate *priv;
|
||||
};
|
||||
|
||||
struct _GnomeSettingsModuleClass {
|
||||
GObjectClass parent_class;
|
||||
|
||||
/* virtual methods */
|
||||
gboolean (* initialize) (GnomeSettingsModule *module, GConfClient *config_client);
|
||||
gboolean (* start) (GnomeSettingsModule *module);
|
||||
gboolean (* stop) (GnomeSettingsModule *module);
|
||||
gboolean (* reload_settings) (GnomeSettingsModule *module);
|
||||
};
|
||||
|
||||
GType gnome_settings_module_get_type (void);
|
||||
|
||||
gboolean gnome_settings_module_initialize (GnomeSettingsModule *module, GConfClient *client);
|
||||
gboolean gnome_settings_module_start (GnomeSettingsModule *module);
|
||||
gboolean gnome_settings_module_stop (GnomeSettingsModule *module);
|
||||
gboolean gnome_settings_module_reload_settings (GnomeSettingsModule *module);
|
||||
|
||||
GConfClient *gnome_settings_module_get_config_client (GnomeSettingsModule *module);
|
||||
GnomeSettingsModuleStatus gnome_settings_module_get_status (GnomeSettingsModule *module);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue