~hikiko/compiz/compiz.EZ

« back to all changes in this revision

Viewing changes to compizconfig/integration/gnome/gconf/src/ccs_gnome_integration_gconf_integrated_setting.c

  • Committer: CI Train Bot
  • Author(s): Marco Trevisan (Treviño)
  • Date: 2015-12-11 10:00:29 UTC
  • mfrom: (3988.2.3 compiz)
  • Revision ID: ci-train-bot@canonical.com-20151211100029-5tq13bj2xvpejtdv
backends: drop gconf support
Approved by: Sebastien Bacher

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include <stdlib.h>
2
 
#include <string.h>
3
 
 
4
 
#include <gconf/gconf.h>
5
 
#include <gconf/gconf-client.h>
6
 
#include <gconf/gconf-value.h>
7
 
 
8
 
#include <ccs.h>
9
 
#include <ccs-backend.h>
10
 
#include <ccs-object.h>
11
 
 
12
 
#include "ccs_gnome_integration_gconf_integrated_setting.h"
13
 
#include "ccs_gnome_integrated_setting.h"
14
 
#include "ccs_gnome_integration_constants.h"
15
 
 
16
 
 
17
 
/* CCSGConfIntegratedSetting implementation */
18
 
typedef struct _CCSGConfIntegratedSettingPrivate CCSGConfIntegratedSettingPrivate;
19
 
 
20
 
struct _CCSGConfIntegratedSettingPrivate
21
 
{
22
 
    CCSGNOMEIntegratedSettingInfo *gnomeIntegratedSettingInfo;
23
 
    GConfClient               *client;
24
 
    const char                *sectionName;
25
 
};
26
 
 
27
 
SpecialOptionType
28
 
ccsGConfIntegratedSettingGetSpecialOptionType (CCSGNOMEIntegratedSettingInfo *setting)
29
 
{
30
 
    CCSGConfIntegratedSettingPrivate *priv = (CCSGConfIntegratedSettingPrivate *) ccsObjectGetPrivate (setting);
31
 
 
32
 
    return ccsGNOMEIntegratedSettingInfoGetSpecialOptionType (priv->gnomeIntegratedSettingInfo);
33
 
}
34
 
 
35
 
const char *
36
 
ccsGConfIntegratedSettingGetGNOMEName (CCSGNOMEIntegratedSettingInfo *setting)
37
 
{
38
 
    CCSGConfIntegratedSettingPrivate *priv = (CCSGConfIntegratedSettingPrivate *) ccsObjectGetPrivate (setting);
39
 
 
40
 
    return ccsGNOMEIntegratedSettingInfoGetGNOMEName (priv->gnomeIntegratedSettingInfo);
41
 
}
42
 
 
43
 
CCSSettingValue *
44
 
ccsGConfIntegratedSettingReadValue (CCSIntegratedSetting *setting, CCSSettingType type)
45
 
{
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);
50
 
 
51
 
    v->isListChild = FALSE;
52
 
    v->parent = NULL;
53
 
    v->refCount = 1;
54
 
 
55
 
    GConfValue *gconfValue;
56
 
    GError     *err = NULL;
57
 
 
58
 
    gconfValue = gconf_client_get (priv->client,
59
 
                                   gnomeKeyPath,
60
 
                                   &err);
61
 
 
62
 
    if (!gconfValue)
63
 
    {
64
 
        ccsError ("NULL encountered while reading GConf setting");
65
 
        free (gnomeKeyPath);
66
 
        free (v);
67
 
        return NULL;
68
 
    }
69
 
 
70
 
    if (err)
71
 
    {
72
 
        ccsError ("%s", err->message);
73
 
        g_error_free (err);
74
 
        free (gnomeKeyPath);
75
 
        free (v);
76
 
        return NULL;
77
 
    }
78
 
 
79
 
    switch (type)
80
 
    {
81
 
        case TypeInt:
82
 
            if (gconfValue->type != GCONF_VALUE_INT)
83
 
            {
84
 
                ccsError ("Expected integer value");
85
 
                free (v);
86
 
                v = NULL;
87
 
                break;
88
 
            }
89
 
 
90
 
            v->value.asInt = gconf_value_get_int (gconfValue);
91
 
            break;
92
 
        case TypeBool:
93
 
            if (gconfValue->type != GCONF_VALUE_BOOL)
94
 
            {
95
 
                ccsError ("Expected boolean value");
96
 
                free (v);
97
 
                v = NULL;
98
 
                break;
99
 
            }
100
 
 
101
 
            v->value.asBool = gconf_value_get_bool (gconfValue) ? TRUE : FALSE;
102
 
            break;
103
 
        case TypeString:
104
 
        case TypeKey:
105
 
            if (gconfValue->type != GCONF_VALUE_STRING)
106
 
            {
107
 
                ccsError ("Expected string value");
108
 
                free (v);
109
 
                v = NULL;
110
 
                break;
111
 
            }
112
 
 
113
 
            const char *str = gconf_value_get_string (gconfValue);
114
 
 
115
 
            v->value.asString = strdup (str ? str : "");
116
 
            break;
117
 
        default:
118
 
            g_assert_not_reached ();
119
 
    }
120
 
 
121
 
    gconf_value_free (gconfValue);
122
 
    free (gnomeKeyPath);
123
 
 
124
 
    return v;
125
 
}
126
 
 
127
 
void
128
 
ccsGConfIntegratedSettingWriteValue (CCSIntegratedSetting *setting, CCSSettingValue *v, CCSSettingType type)
129
 
{
130
 
    CCSGConfIntegratedSettingPrivate *priv = (CCSGConfIntegratedSettingPrivate *) ccsObjectGetPrivate (setting);
131
 
    const char                       *gnomeKeyName = ccsGNOMEIntegratedSettingInfoGetGNOMEName ((CCSGNOMEIntegratedSettingInfo *) setting);
132
 
    char                             *gnomeKeyPath = g_strconcat (priv->sectionName, gnomeKeyName, NULL);
133
 
    GError                           *err = NULL;
134
 
 
135
 
    switch (type)
136
 
    {
137
 
        case TypeInt:
138
 
            {
139
 
                int currentValue = gconf_client_get_int (priv->client, gnomeKeyPath, &err);
140
 
 
141
 
                if (!err && (currentValue != v->value.asInt))
142
 
                    gconf_client_set_int(priv->client, gnomeKeyPath,
143
 
                                         v->value.asInt, NULL);
144
 
            }
145
 
            break;
146
 
        case TypeBool:
147
 
            {
148
 
                Bool     newValue = v->value.asBool;
149
 
                gboolean currentValue;
150
 
 
151
 
                currentValue = gconf_client_get_bool (priv->client, gnomeKeyPath, &err);
152
 
 
153
 
                if (!err && ((currentValue && !newValue) ||
154
 
                             (!currentValue && newValue)))
155
 
                    gconf_client_set_bool (priv->client, gnomeKeyPath,
156
 
                                           newValue, NULL);
157
 
            }
158
 
            break;
159
 
        case TypeString:
160
 
        case TypeKey:
161
 
            {
162
 
                char  *newValue = v->value.asString;
163
 
                gchar *currentValue;
164
 
 
165
 
                currentValue = gconf_client_get_string (priv->client, gnomeKeyPath, &err);
166
 
 
167
 
                if (!err && currentValue)
168
 
                {
169
 
                    if (strcmp (currentValue, newValue) != 0)
170
 
                        gconf_client_set_string (priv->client, gnomeKeyPath,
171
 
                                                 newValue, NULL);
172
 
                    g_free (currentValue);
173
 
                }
174
 
            }
175
 
            break;
176
 
        default:
177
 
            g_assert_not_reached ();
178
 
            break;
179
 
    }
180
 
 
181
 
    if (err)
182
 
    {
183
 
        ccsError ("%s", err->message);
184
 
        g_error_free (err);
185
 
    }
186
 
 
187
 
    free (gnomeKeyPath);
188
 
}
189
 
 
190
 
const char *
191
 
ccsGConfIntegratedSettingInfoPluginName (CCSIntegratedSettingInfo *info)
192
 
{
193
 
    CCSGConfIntegratedSettingPrivate *priv = (CCSGConfIntegratedSettingPrivate *) ccsObjectGetPrivate (info);
194
 
 
195
 
    return ccsIntegratedSettingInfoPluginName ((CCSIntegratedSettingInfo *) priv->gnomeIntegratedSettingInfo);
196
 
}
197
 
 
198
 
const char *
199
 
ccsGConfIntegratedSettingInfoSettingName (CCSIntegratedSettingInfo *info)
200
 
{
201
 
    CCSGConfIntegratedSettingPrivate *priv = (CCSGConfIntegratedSettingPrivate *) ccsObjectGetPrivate (info);
202
 
 
203
 
    return ccsIntegratedSettingInfoSettingName ((CCSIntegratedSettingInfo *) priv->gnomeIntegratedSettingInfo);
204
 
}
205
 
 
206
 
CCSSettingType
207
 
ccsGConfIntegratedSettingInfoGetType (CCSIntegratedSettingInfo *info)
208
 
{
209
 
    CCSGConfIntegratedSettingPrivate *priv = (CCSGConfIntegratedSettingPrivate *) ccsObjectGetPrivate (info);
210
 
 
211
 
    return ccsIntegratedSettingInfoGetType ((CCSIntegratedSettingInfo *) priv->gnomeIntegratedSettingInfo);
212
 
}
213
 
 
214
 
void
215
 
ccsGConfIntegratedSettingFree (CCSIntegratedSetting *setting)
216
 
{
217
 
    CCSGConfIntegratedSettingPrivate *priv = (CCSGConfIntegratedSettingPrivate *) ccsObjectGetPrivate (setting);
218
 
 
219
 
    ccsIntegratedSettingInfoUnref ((CCSIntegratedSettingInfo *) priv->gnomeIntegratedSettingInfo);
220
 
    ccsObjectFinalize (setting);
221
 
 
222
 
    (*setting->object.object_allocation->free_) (setting->object.object_allocation->allocator, setting);
223
 
}
224
 
 
225
 
void
226
 
ccsGConfIntegratedSettingInfoFree (CCSIntegratedSettingInfo *info)
227
 
{
228
 
    ccsGConfIntegratedSettingFree ((CCSIntegratedSetting *) info);
229
 
}
230
 
 
231
 
void
232
 
ccsGConfGNOMEIntegratedSettingInfoFree (CCSGNOMEIntegratedSettingInfo *info)
233
 
{
234
 
    ccsGConfIntegratedSettingFree ((CCSIntegratedSetting *) info);
235
 
}
236
 
 
237
 
const CCSGNOMEIntegratedSettingInfoInterface ccsGConfGNOMEIntegratedSettingInfoInterface =
238
 
{
239
 
    ccsGConfIntegratedSettingGetSpecialOptionType,
240
 
    ccsGConfIntegratedSettingGetGNOMEName,
241
 
    ccsGConfGNOMEIntegratedSettingInfoFree
242
 
};
243
 
 
244
 
const CCSIntegratedSettingInterface ccsGConfIntegratedSettingInterface =
245
 
{
246
 
    ccsGConfIntegratedSettingReadValue,
247
 
    ccsGConfIntegratedSettingWriteValue,
248
 
    ccsGConfIntegratedSettingFree
249
 
};
250
 
 
251
 
const CCSIntegratedSettingInfoInterface ccsGConfIntegratedSettingInfoInterface =
252
 
{
253
 
    ccsGConfIntegratedSettingInfoPluginName,
254
 
    ccsGConfIntegratedSettingInfoSettingName,
255
 
    ccsGConfIntegratedSettingInfoGetType,
256
 
    ccsGConfIntegratedSettingInfoFree
257
 
};
258
 
 
259
 
CCSIntegratedSetting *
260
 
ccsGConfIntegratedSettingNew (CCSGNOMEIntegratedSettingInfo *base,
261
 
                              GConfClient               *client,
262
 
                              const char                *section,
263
 
                              CCSObjectAllocationInterface *ai)
264
 
{
265
 
    CCSIntegratedSetting *setting = (*ai->calloc_) (ai->allocator, 1, sizeof (CCSIntegratedSetting));
266
 
 
267
 
    if (!setting)
268
 
        return NULL;
269
 
 
270
 
    CCSGConfIntegratedSettingPrivate *priv = (*ai->calloc_) (ai->allocator, 1, sizeof (CCSGConfIntegratedSettingPrivate));
271
 
 
272
 
    if (!priv)
273
 
    {
274
 
        (*ai->free_) (ai->allocator, priv);
275
 
        return NULL;
276
 
    }
277
 
 
278
 
    priv->gnomeIntegratedSettingInfo = base;
279
 
    priv->client = client;
280
 
    priv->sectionName = section;
281
 
 
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);
288
 
 
289
 
    return setting;
290
 
}