~seb128/unity-settings-daemon/battery-info-key

« back to all changes in this revision

Viewing changes to src/gnome-settings-manager.c

  • Committer: William Jon McCann
  • Author(s): William Jon McCann
  • Date: 2007-12-14 05:06:55 UTC
  • Revision ID: git-v1:b7f5d9895c19338f10b0bdd494b221b13b540d9d
Initial checkin. Previously lived in gdm module.

2007-12-14  William Jon McCann  <mccann@jhu.edu>

        * configure.ac, etc: Initial checkin.  Previously
        lived in gdm module.


svn path=/trunk/; revision=2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
 
2
 *
 
3
 * Copyright (C) 2007 William Jon McCann <mccann@jhu.edu>
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License as published by
 
7
 * the Free Software Foundation; either version 2 of the License, or
 
8
 * (at your option) any later version.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program; if not, write to the Free Software
 
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
18
 *
 
19
 */
 
20
 
 
21
#include "config.h"
 
22
 
 
23
#include <stdlib.h>
 
24
#include <stdio.h>
 
25
#include <unistd.h>
 
26
#include <string.h>
 
27
 
 
28
#include <glib.h>
 
29
#include <glib/gi18n.h>
 
30
#include <glib-object.h>
 
31
 
 
32
#include "gnome-settings-manager.h"
 
33
#include "gnome-settings-plugins-engine.h"
 
34
 
 
35
#define GNOME_SETTINGS_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GNOME_TYPE_SETTINGS_MANAGER, GnomeSettingsManagerPrivate))
 
36
 
 
37
struct GnomeSettingsManagerPrivate
 
38
{
 
39
        char *gconf_prefix;
 
40
};
 
41
 
 
42
enum {
 
43
        PROP_0,
 
44
        PROP_GCONF_PREFIX,
 
45
};
 
46
 
 
47
static void     gnome_settings_manager_class_init  (GnomeSettingsManagerClass *klass);
 
48
static void     gnome_settings_manager_init        (GnomeSettingsManager      *settings_manager);
 
49
static void     gnome_settings_manager_finalize    (GObject                   *object);
 
50
 
 
51
G_DEFINE_TYPE (GnomeSettingsManager, gnome_settings_manager, G_TYPE_OBJECT)
 
52
 
 
53
static gpointer manager_object = NULL;
 
54
 
 
55
gboolean
 
56
gnome_settings_manager_start (GnomeSettingsManager *manager,
 
57
                              GError              **error)
 
58
{
 
59
        gboolean ret;
 
60
 
 
61
        g_debug ("Starting settings manager");
 
62
 
 
63
        gnome_settings_plugins_engine_init (manager->priv->gconf_prefix);
 
64
 
 
65
        ret = TRUE;
 
66
        return ret;
 
67
}
 
68
 
 
69
void
 
70
gnome_settings_manager_stop (GnomeSettingsManager *manager)
 
71
{
 
72
        g_debug ("Stopping settings manager");
 
73
 
 
74
        gnome_settings_plugins_engine_shutdown ();
 
75
}
 
76
 
 
77
static void
 
78
_set_gconf_prefix (GnomeSettingsManager *self,
 
79
                   const char           *prefix)
 
80
{
 
81
        g_free (self->priv->gconf_prefix);
 
82
        self->priv->gconf_prefix = g_strdup (prefix);
 
83
}
 
84
 
 
85
static void
 
86
gnome_settings_manager_set_property (GObject        *object,
 
87
                                     guint           prop_id,
 
88
                                     const GValue   *value,
 
89
                                     GParamSpec     *pspec)
 
90
{
 
91
        GnomeSettingsManager *self;
 
92
 
 
93
        self = GNOME_SETTINGS_MANAGER (object);
 
94
 
 
95
        switch (prop_id) {
 
96
        case PROP_GCONF_PREFIX:
 
97
                _set_gconf_prefix (self, g_value_get_string (value));
 
98
                break;
 
99
        default:
 
100
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
101
                break;
 
102
        }
 
103
}
 
104
 
 
105
static void
 
106
gnome_settings_manager_get_property (GObject        *object,
 
107
                                     guint           prop_id,
 
108
                                     GValue         *value,
 
109
                                     GParamSpec     *pspec)
 
110
{
 
111
        GnomeSettingsManager *self;
 
112
 
 
113
        self = GNOME_SETTINGS_MANAGER (object);
 
114
 
 
115
        switch (prop_id) {
 
116
        case PROP_GCONF_PREFIX:
 
117
                g_value_set_string (value, self->priv->gconf_prefix);
 
118
                break;
 
119
        default:
 
120
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
121
                break;
 
122
        }
 
123
}
 
124
 
 
125
static GObject *
 
126
gnome_settings_manager_constructor (GType                  type,
 
127
                                    guint                  n_construct_properties,
 
128
                                    GObjectConstructParam *construct_properties)
 
129
{
 
130
        GnomeSettingsManager      *manager;
 
131
        GnomeSettingsManagerClass *klass;
 
132
 
 
133
        klass = GNOME_SETTINGS_MANAGER_CLASS (g_type_class_peek (GNOME_TYPE_SETTINGS_MANAGER));
 
134
 
 
135
        manager = GNOME_SETTINGS_MANAGER (G_OBJECT_CLASS (gnome_settings_manager_parent_class)->constructor (type,
 
136
                                                                                                         n_construct_properties,
 
137
                                                                                                         construct_properties));
 
138
 
 
139
        return G_OBJECT (manager);
 
140
}
 
141
 
 
142
static void
 
143
gnome_settings_manager_dispose (GObject *object)
 
144
{
 
145
        GnomeSettingsManager *manager;
 
146
 
 
147
        manager = GNOME_SETTINGS_MANAGER (object);
 
148
 
 
149
        gnome_settings_manager_stop (manager);
 
150
 
 
151
        G_OBJECT_CLASS (gnome_settings_manager_parent_class)->dispose (object);
 
152
}
 
153
 
 
154
static void
 
155
gnome_settings_manager_class_init (GnomeSettingsManagerClass *klass)
 
156
{
 
157
        GObjectClass   *object_class = G_OBJECT_CLASS (klass);
 
158
 
 
159
        object_class->get_property = gnome_settings_manager_get_property;
 
160
        object_class->set_property = gnome_settings_manager_set_property;
 
161
        object_class->constructor = gnome_settings_manager_constructor;
 
162
        object_class->dispose = gnome_settings_manager_dispose;
 
163
        object_class->finalize = gnome_settings_manager_finalize;
 
164
 
 
165
        g_object_class_install_property (object_class,
 
166
                                         PROP_GCONF_PREFIX,
 
167
                                         g_param_spec_string ("gconf-prefix",
 
168
                                                              "gconf-prefix",
 
169
                                                              "gconf-prefix",
 
170
                                                              NULL,
 
171
                                                              G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
 
172
 
 
173
        g_type_class_add_private (klass, sizeof (GnomeSettingsManagerPrivate));
 
174
}
 
175
 
 
176
static void
 
177
gnome_settings_manager_init (GnomeSettingsManager *manager)
 
178
{
 
179
 
 
180
        manager->priv = GNOME_SETTINGS_MANAGER_GET_PRIVATE (manager);
 
181
}
 
182
 
 
183
static void
 
184
gnome_settings_manager_finalize (GObject *object)
 
185
{
 
186
        GnomeSettingsManager *manager;
 
187
 
 
188
        g_return_if_fail (object != NULL);
 
189
        g_return_if_fail (GNOME_IS_SETTINGS_MANAGER (object));
 
190
 
 
191
        manager = GNOME_SETTINGS_MANAGER (object);
 
192
 
 
193
        g_return_if_fail (manager->priv != NULL);
 
194
 
 
195
        g_free (manager->priv->gconf_prefix);
 
196
 
 
197
        G_OBJECT_CLASS (gnome_settings_manager_parent_class)->finalize (object);
 
198
}
 
199
 
 
200
GnomeSettingsManager *
 
201
gnome_settings_manager_new (const char *gconf_prefix)
 
202
{
 
203
        if (manager_object != NULL) {
 
204
                g_object_ref (manager_object);
 
205
        } else {
 
206
                manager_object = g_object_new (GNOME_TYPE_SETTINGS_MANAGER,
 
207
                                               "gconf-prefix", gconf_prefix,
 
208
                                               NULL);
 
209
                g_object_add_weak_pointer (manager_object,
 
210
                                           (gpointer *) &manager_object);
 
211
        }
 
212
 
 
213
        return GNOME_SETTINGS_MANAGER (manager_object);
 
214
}