4
#include <gconf/gconf.h>
5
#include <gconf/gconf-client.h>
6
#include <gconf/gconf-value.h>
9
#include <ccs-backend.h>
10
#include <ccs-object.h>
12
#include "ccs_gnome_integration_gconf_integrated_setting.h"
13
#include "ccs_gnome_integrated_setting.h"
14
#include "ccs_gnome_integration_constants.h"
17
/* CCSGConfIntegratedSetting implementation */
18
typedef struct _CCSGConfIntegratedSettingPrivate CCSGConfIntegratedSettingPrivate;
20
struct _CCSGConfIntegratedSettingPrivate
22
CCSGNOMEIntegratedSettingInfo *gnomeIntegratedSettingInfo;
24
const char *sectionName;
28
ccsGConfIntegratedSettingGetSpecialOptionType (CCSGNOMEIntegratedSettingInfo *setting)
30
CCSGConfIntegratedSettingPrivate *priv = (CCSGConfIntegratedSettingPrivate *) ccsObjectGetPrivate (setting);
32
return ccsGNOMEIntegratedSettingInfoGetSpecialOptionType (priv->gnomeIntegratedSettingInfo);
36
ccsGConfIntegratedSettingGetGNOMEName (CCSGNOMEIntegratedSettingInfo *setting)
38
CCSGConfIntegratedSettingPrivate *priv = (CCSGConfIntegratedSettingPrivate *) ccsObjectGetPrivate (setting);
40
return ccsGNOMEIntegratedSettingInfoGetGNOMEName (priv->gnomeIntegratedSettingInfo);
44
ccsGConfIntegratedSettingReadValue (CCSIntegratedSetting *setting, CCSSettingType type)
46
CCSGConfIntegratedSettingPrivate *priv = (CCSGConfIntegratedSettingPrivate *) ccsObjectGetPrivate (setting);
47
CCSSettingValue *v = calloc (1, sizeof (CCSSettingValue));
48
const char *gnomeKeyName = ccsGNOMEIntegratedSettingInfoGetGNOMEName ((CCSGNOMEIntegratedSettingInfo *) setting);
49
char *gnomeKeyPath = g_strconcat (priv->sectionName, gnomeKeyName, NULL);
51
v->isListChild = FALSE;
55
GConfValue *gconfValue;
58
gconfValue = gconf_client_get (priv->client,
64
ccsError ("NULL encountered while reading GConf setting");
72
ccsError ("%s", err->message);
82
if (gconfValue->type != GCONF_VALUE_INT)
84
ccsError ("Expected integer value");
90
v->value.asInt = gconf_value_get_int (gconfValue);
93
if (gconfValue->type != GCONF_VALUE_BOOL)
95
ccsError ("Expected boolean value");
101
v->value.asBool = gconf_value_get_bool (gconfValue) ? TRUE : FALSE;
105
if (gconfValue->type != GCONF_VALUE_STRING)
107
ccsError ("Expected string value");
113
const char *str = gconf_value_get_string (gconfValue);
115
v->value.asString = strdup (str ? str : "");
118
g_assert_not_reached ();
121
gconf_value_free (gconfValue);
128
ccsGConfIntegratedSettingWriteValue (CCSIntegratedSetting *setting, CCSSettingValue *v, CCSSettingType type)
130
CCSGConfIntegratedSettingPrivate *priv = (CCSGConfIntegratedSettingPrivate *) ccsObjectGetPrivate (setting);
131
const char *gnomeKeyName = ccsGNOMEIntegratedSettingInfoGetGNOMEName ((CCSGNOMEIntegratedSettingInfo *) setting);
132
char *gnomeKeyPath = g_strconcat (priv->sectionName, gnomeKeyName, NULL);
139
int currentValue = gconf_client_get_int (priv->client, gnomeKeyPath, &err);
141
if (!err && (currentValue != v->value.asInt))
142
gconf_client_set_int(priv->client, gnomeKeyPath,
143
v->value.asInt, NULL);
148
Bool newValue = v->value.asBool;
149
gboolean currentValue;
151
currentValue = gconf_client_get_bool (priv->client, gnomeKeyPath, &err);
153
if (!err && ((currentValue && !newValue) ||
154
(!currentValue && newValue)))
155
gconf_client_set_bool (priv->client, gnomeKeyPath,
162
char *newValue = v->value.asString;
165
currentValue = gconf_client_get_string (priv->client, gnomeKeyPath, &err);
167
if (!err && currentValue)
169
if (strcmp (currentValue, newValue) != 0)
170
gconf_client_set_string (priv->client, gnomeKeyPath,
172
g_free (currentValue);
177
g_assert_not_reached ();
183
ccsError ("%s", err->message);
191
ccsGConfIntegratedSettingInfoPluginName (CCSIntegratedSettingInfo *info)
193
CCSGConfIntegratedSettingPrivate *priv = (CCSGConfIntegratedSettingPrivate *) ccsObjectGetPrivate (info);
195
return ccsIntegratedSettingInfoPluginName ((CCSIntegratedSettingInfo *) priv->gnomeIntegratedSettingInfo);
199
ccsGConfIntegratedSettingInfoSettingName (CCSIntegratedSettingInfo *info)
201
CCSGConfIntegratedSettingPrivate *priv = (CCSGConfIntegratedSettingPrivate *) ccsObjectGetPrivate (info);
203
return ccsIntegratedSettingInfoSettingName ((CCSIntegratedSettingInfo *) priv->gnomeIntegratedSettingInfo);
207
ccsGConfIntegratedSettingInfoGetType (CCSIntegratedSettingInfo *info)
209
CCSGConfIntegratedSettingPrivate *priv = (CCSGConfIntegratedSettingPrivate *) ccsObjectGetPrivate (info);
211
return ccsIntegratedSettingInfoGetType ((CCSIntegratedSettingInfo *) priv->gnomeIntegratedSettingInfo);
215
ccsGConfIntegratedSettingFree (CCSIntegratedSetting *setting)
217
CCSGConfIntegratedSettingPrivate *priv = (CCSGConfIntegratedSettingPrivate *) ccsObjectGetPrivate (setting);
219
ccsIntegratedSettingInfoUnref ((CCSIntegratedSettingInfo *) priv->gnomeIntegratedSettingInfo);
220
ccsObjectFinalize (setting);
222
(*setting->object.object_allocation->free_) (setting->object.object_allocation->allocator, setting);
226
ccsGConfIntegratedSettingInfoFree (CCSIntegratedSettingInfo *info)
228
ccsGConfIntegratedSettingFree ((CCSIntegratedSetting *) info);
232
ccsGConfGNOMEIntegratedSettingInfoFree (CCSGNOMEIntegratedSettingInfo *info)
234
ccsGConfIntegratedSettingFree ((CCSIntegratedSetting *) info);
237
const CCSGNOMEIntegratedSettingInfoInterface ccsGConfGNOMEIntegratedSettingInfoInterface =
239
ccsGConfIntegratedSettingGetSpecialOptionType,
240
ccsGConfIntegratedSettingGetGNOMEName,
241
ccsGConfGNOMEIntegratedSettingInfoFree
244
const CCSIntegratedSettingInterface ccsGConfIntegratedSettingInterface =
246
ccsGConfIntegratedSettingReadValue,
247
ccsGConfIntegratedSettingWriteValue,
248
ccsGConfIntegratedSettingFree
251
const CCSIntegratedSettingInfoInterface ccsGConfIntegratedSettingInfoInterface =
253
ccsGConfIntegratedSettingInfoPluginName,
254
ccsGConfIntegratedSettingInfoSettingName,
255
ccsGConfIntegratedSettingInfoGetType,
256
ccsGConfIntegratedSettingInfoFree
259
CCSIntegratedSetting *
260
ccsGConfIntegratedSettingNew (CCSGNOMEIntegratedSettingInfo *base,
263
CCSObjectAllocationInterface *ai)
265
CCSIntegratedSetting *setting = (*ai->calloc_) (ai->allocator, 1, sizeof (CCSIntegratedSetting));
270
CCSGConfIntegratedSettingPrivate *priv = (*ai->calloc_) (ai->allocator, 1, sizeof (CCSGConfIntegratedSettingPrivate));
274
(*ai->free_) (ai->allocator, priv);
278
priv->gnomeIntegratedSettingInfo = base;
279
priv->client = client;
280
priv->sectionName = section;
282
ccsObjectInit (setting, ai);
283
ccsObjectSetPrivate (setting, (CCSPrivate *) priv);
284
ccsObjectAddInterface (setting, (const CCSInterface *) &ccsGConfIntegratedSettingInfoInterface, GET_INTERFACE_TYPE (CCSIntegratedSettingInfoInterface));
285
ccsObjectAddInterface (setting, (const CCSInterface *) &ccsGConfIntegratedSettingInterface, GET_INTERFACE_TYPE (CCSIntegratedSettingInterface));
286
ccsObjectAddInterface (setting, (const CCSInterface *) &ccsGConfGNOMEIntegratedSettingInfoInterface, GET_INTERFACE_TYPE (CCSGNOMEIntegratedSettingInfoInterface));
287
ccsIntegratedSettingRef (setting);