Merge lp:~compiz-team/compiz/compiz.split_gsettings_rw_funcs into lp:compiz/0.9.8
- compiz.split_gsettings_rw_funcs
- Merge into 0.9.8
Proposed by
Sam Spilsbury
Status: | Superseded |
---|---|
Proposed branch: | lp:~compiz-team/compiz/compiz.split_gsettings_rw_funcs |
Merge into: | lp:compiz/0.9.8 |
Prerequisite: | lp:~compiz-team/compiz/compiz.ccs_backend_conformance_test |
Diff against target: |
6281 lines (+4126/-1139) 31 files modified
compizconfig/gconf/src/gconf.c (+2/-2) compizconfig/gsettings/gsettings_backend_shared/CMakeLists.txt (+15/-1) compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface.c (+65/-0) compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface.h (+59/-0) compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c (+260/-0) compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.h (+21/-0) compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c (+935/-10) compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h (+242/-4) compizconfig/gsettings/src/gconf-integration.c (+55/-42) compizconfig/gsettings/src/gsettings.c (+336/-666) compizconfig/gsettings/src/gsettings.h (+31/-12) compizconfig/gsettings/tests/CMakeLists.txt (+29/-2) compizconfig/gsettings/tests/ccs_gsettings_backend_mock.cpp (+61/-0) compizconfig/gsettings/tests/ccs_gsettings_backend_mock.h (+176/-0) compizconfig/gsettings/tests/ccs_gsettings_wrapper_mock.cpp (+52/-0) compizconfig/gsettings/tests/ccs_gsettings_wrapper_mock.h (+113/-0) compizconfig/gsettings/tests/gsettings-mock-schemas-config.h.in (+7/-0) compizconfig/gsettings/tests/gsettings_mocks.cpp (+0/-200) compizconfig/gsettings/tests/gsettings_mocks.h (+0/-45) compizconfig/gsettings/tests/org.compiz.mock.gschema.xml (+53/-0) compizconfig/gsettings/tests/test_gsettings_tests.cpp (+1195/-45) compizconfig/gsettings/tests/test_gsettings_tests.h (+43/-2) compizconfig/gsettings/tests/test_gsettings_wrapper.cpp (+249/-0) compizconfig/libcompizconfig/include/ccs-defs.h (+18/-0) compizconfig/libcompizconfig/include/ccs-object.h (+11/-0) compizconfig/libcompizconfig/include/ccs.h (+0/-19) compizconfig/libcompizconfig/src/main.c (+0/-11) compizconfig/libcompizconfig/tests/CMakeLists.txt (+1/-1) compizconfig/libcompizconfig/tests/compizconfig_test_ccs_object.cpp (+1/-77) compizconfig/mocks/libcompizconfig/compizconfig_ccs_setting_mock.h (+5/-0) compizconfig/tests/compizconfig_ccs_mocked_allocator.h (+91/-0) |
To merge this branch: | bzr merge lp:~compiz-team/compiz/compiz.split_gsettings_rw_funcs |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Compiz Maintainers | Pending | ||
Review via email: mp+118459@code.launchpad.net |
This proposal supersedes a proposal from 2012-07-12.
This proposal has been superseded by a proposal from 2012-08-07.
Commit message
Description of the change
Split out the read and write functions to and from variants so that we can re-use them in the tests
Next: lp:~compiz-team/compiz/compiz.gsettings_conformance_test
To post a comment you must log in.
Unmerged revisions
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'compizconfig/gconf/src/gconf.c' |
2 | --- compizconfig/gconf/src/gconf.c 2012-08-07 01:05:13 +0000 |
3 | +++ compizconfig/gconf/src/gconf.c 2012-08-07 01:05:15 +0000 |
4 | @@ -1835,7 +1835,7 @@ |
5 | } |
6 | |
7 | static void |
8 | -updateCurrentProfileName (char *profile) |
9 | +ccsGSettingsBackendUpdateCurrentProfileName (char *profile) |
10 | { |
11 | GConfSchema *schema; |
12 | GConfValue *value; |
13 | @@ -1940,7 +1940,7 @@ |
14 | } |
15 | |
16 | /* update current profile name */ |
17 | - updateCurrentProfileName (currentProfile); |
18 | + ccsGSettingsBackendUpdateCurrentProfileName (currentProfile); |
19 | } |
20 | |
21 | if (lastProfile) |
22 | |
23 | === modified file 'compizconfig/gsettings/gsettings_backend_shared/CMakeLists.txt' |
24 | --- compizconfig/gsettings/gsettings_backend_shared/CMakeLists.txt 2012-07-05 21:11:17 +0000 |
25 | +++ compizconfig/gsettings/gsettings_backend_shared/CMakeLists.txt 2012-08-07 01:05:15 +0000 |
26 | @@ -15,12 +15,26 @@ |
27 | link_directories (${GSETTINGS_UTIL_LIBRARY_DIRS} |
28 | ${compiz_BINARY_DIR}/compizconfig/libcompizconfig) |
29 | |
30 | - add_library (gsettings_backend_shared STATIC |
31 | + add_library (gsettings_backend_shared SHARED |
32 | + ${CMAKE_CURRENT_SOURCE_DIR}/ccs_gsettings_interface_wrapper.c |
33 | + ${CMAKE_CURRENT_SOURCE_DIR}/ccs_gsettings_interface.c |
34 | ${CMAKE_CURRENT_SOURCE_DIR}/gsettings_constants.c |
35 | ${CMAKE_CURRENT_SOURCE_DIR}/gsettings_util.c) |
36 | |
37 | + |
38 | target_link_libraries (gsettings_backend_shared |
39 | ${GSETTINGS_UTIL_LIBRARIES} |
40 | compizconfig) |
41 | |
42 | + install (TARGETS gsettings_backend_shared |
43 | + DESTINATION ${CMAKE_INSTALL_PREFIX}/lib) |
44 | + |
45 | + # |
46 | + # Tell CMake that targets using gsettings_backend_shared should NOT re-import the |
47 | + # libraries that gsettings_backend_shared depends on (contains). |
48 | + # |
49 | + set_target_properties (gsettings_backend_shared PROPERTIES |
50 | + LINK_INTERFACE_LIBRARIES "" |
51 | + ) |
52 | + |
53 | endif (GSETTINGS_UTIL_FOUND) |
54 | |
55 | === added file 'compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface.c' |
56 | --- compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface.c 1970-01-01 00:00:00 +0000 |
57 | +++ compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface.c 2012-08-07 01:05:15 +0000 |
58 | @@ -0,0 +1,65 @@ |
59 | +#include <gio/gio.h> |
60 | +#include "ccs_gsettings_interface.h" |
61 | + |
62 | +INTERFACE_TYPE (CCSGSettingsWrapperInterface); |
63 | +CCSREF_OBJ (GSettingsWrapper, CCSGSettingsWrapper); |
64 | + |
65 | +void |
66 | +ccsGSettingsWrapperSetValue (CCSGSettingsWrapper *wrapper, |
67 | + const char *key, |
68 | + GVariant *value) |
69 | +{ |
70 | + (*(GET_INTERFACE (CCSGSettingsWrapperInterface, wrapper))->gsettingsWrapperSetValue) (wrapper, key, value); |
71 | +} |
72 | + |
73 | +GVariant * |
74 | +ccsGSettingsWrapperGetValue (CCSGSettingsWrapper *wrapper, |
75 | + const char *key) |
76 | +{ |
77 | + return (*(GET_INTERFACE (CCSGSettingsWrapperInterface, wrapper))->gsettingsWrapperGetValue) (wrapper, key); |
78 | +} |
79 | + |
80 | +void |
81 | +ccsGSettingsWrapperResetKey (CCSGSettingsWrapper *wrapper, |
82 | + const char *key) |
83 | +{ |
84 | + return (*(GET_INTERFACE (CCSGSettingsWrapperInterface, wrapper))->gsettingsWrapperResetKey) (wrapper, key); |
85 | +} |
86 | + |
87 | +char ** |
88 | +ccsGSettingsWrapperListKeys (CCSGSettingsWrapper *wrapper) |
89 | +{ |
90 | + return (*(GET_INTERFACE (CCSGSettingsWrapperInterface, wrapper))->gsettingsWrapperListKeys) (wrapper); |
91 | +} |
92 | + |
93 | +GSettings * |
94 | +ccsGSettingsWrapperGetGSettings (CCSGSettingsWrapper *wrapper) |
95 | +{ |
96 | + return (*(GET_INTERFACE (CCSGSettingsWrapperInterface, wrapper))->gsettingsWrapperGetGSettings) (wrapper); |
97 | +} |
98 | + |
99 | +const char * |
100 | +ccsGSettingsWrapperGetSchemaName (CCSGSettingsWrapper *wrapper) |
101 | +{ |
102 | + return (*(GET_INTERFACE (CCSGSettingsWrapperInterface, wrapper))->gsettingsWrapperGetSchemaName) (wrapper); |
103 | +} |
104 | + |
105 | +const char * |
106 | +ccsGSettingsWrapperGetPath (CCSGSettingsWrapper *wrapper) |
107 | +{ |
108 | + return (*(GET_INTERFACE (CCSGSettingsWrapperInterface, wrapper))->gsettingsWrapperGetPath) (wrapper); |
109 | +} |
110 | + |
111 | +void |
112 | +ccsGSettingsWrapperConnectToChangedSignal (CCSGSettingsWrapper *wrapper, |
113 | + GCallback callback, |
114 | + gpointer data) |
115 | +{ |
116 | + return (*(GET_INTERFACE (CCSGSettingsWrapperInterface, wrapper))->gsettingsWrapperConnectToChangedSignal) (wrapper, callback, data); |
117 | +} |
118 | + |
119 | +void |
120 | +ccsFreeGSettingsWrapper (CCSGSettingsWrapper *wrapper) |
121 | +{ |
122 | + return (*(GET_INTERFACE (CCSGSettingsWrapperInterface, wrapper))->gsettingsWrapperFree) (wrapper); |
123 | +} |
124 | |
125 | === added file 'compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface.h' |
126 | --- compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface.h 1970-01-01 00:00:00 +0000 |
127 | +++ compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface.h 2012-08-07 01:05:15 +0000 |
128 | @@ -0,0 +1,59 @@ |
129 | +#ifndef _CCS_GSETTINGS_INTERFACE_H |
130 | +#define _CCS_GSETTINGS_INTERFACE_H |
131 | + |
132 | +#include <ccs-defs.h> |
133 | + |
134 | +COMPIZCONFIG_BEGIN_DECLS |
135 | + |
136 | +#include <glib.h> |
137 | +#include <gio/gio.h> |
138 | +#include <ccs-object.h> |
139 | + |
140 | +typedef struct _CCSGSettingsWrapper CCSGSettingsWrapper; |
141 | +typedef struct _CCSGSettingsWrapperInterface CCSGSettingsWrapperInterface; |
142 | + |
143 | +typedef void (*CCSGSettingsWrapperSetValue) (CCSGSettingsWrapper *, const char *, GVariant *); |
144 | +typedef GVariant * (*CCSGSettingsWrapperGetValue) (CCSGSettingsWrapper *, const char *); |
145 | +typedef void (*CCSGSettingsWrapperResetKey) (CCSGSettingsWrapper *, const char *); |
146 | +typedef char ** (*CCSGSettingsWrapperListKeys) (CCSGSettingsWrapper *); |
147 | +typedef GSettings * (*CCSGSettingsWrapperGetGSettings) (CCSGSettingsWrapper *); |
148 | +typedef const char * (*CCSGSettingsWrapperGetSchemaName) (CCSGSettingsWrapper *); |
149 | +typedef const char * (*CCSGSettingsWrapperGetPath) (CCSGSettingsWrapper *); |
150 | +typedef void (*CCSGSettingsWrapperConnectToChangedSignal) (CCSGSettingsWrapper *, GCallback, gpointer); |
151 | +typedef void (*CCSGSettingsWrapperFree) (CCSGSettingsWrapper *); |
152 | + |
153 | +struct _CCSGSettingsWrapperInterface |
154 | +{ |
155 | + CCSGSettingsWrapperSetValue gsettingsWrapperSetValue; |
156 | + CCSGSettingsWrapperGetValue gsettingsWrapperGetValue; |
157 | + CCSGSettingsWrapperResetKey gsettingsWrapperResetKey; |
158 | + CCSGSettingsWrapperListKeys gsettingsWrapperListKeys; |
159 | + CCSGSettingsWrapperGetGSettings gsettingsWrapperGetGSettings; |
160 | + CCSGSettingsWrapperGetSchemaName gsettingsWrapperGetSchemaName; |
161 | + CCSGSettingsWrapperGetPath gsettingsWrapperGetPath; |
162 | + CCSGSettingsWrapperConnectToChangedSignal gsettingsWrapperConnectToChangedSignal; |
163 | + CCSGSettingsWrapperFree gsettingsWrapperFree; |
164 | +}; |
165 | + |
166 | +struct _CCSGSettingsWrapper |
167 | +{ |
168 | + CCSObject object; |
169 | +}; |
170 | + |
171 | +void ccsGSettingsWrapperSetValue (CCSGSettingsWrapper *, const char *, GVariant *); |
172 | +GVariant * ccsGSettingsWrapperGetValue (CCSGSettingsWrapper *, const char *); |
173 | +void ccsGSettingsWrapperResetKey (CCSGSettingsWrapper *, const char *); |
174 | +char **ccsGSettingsWrapperListKeys (CCSGSettingsWrapper *); |
175 | +GSettings * ccsGSettingsWrapperGetGSettings (CCSGSettingsWrapper *); |
176 | +const char * ccsGSettingsWrapperGetSchemaName (CCSGSettingsWrapper *); |
177 | +const char * ccsGSettingsWrapperGetPath (CCSGSettingsWrapper *); |
178 | +void ccsGSettingsWrapperConnectToChangedSignal (CCSGSettingsWrapper *, GCallback, gpointer); |
179 | +void ccsFreeGSettingsWrapper (CCSGSettingsWrapper *wrapper); |
180 | + |
181 | +unsigned int ccsCCSGSettingsWrapperInterfaceGetType (); |
182 | + |
183 | +CCSREF_HDR (GSettingsWrapper, CCSGSettingsWrapper); |
184 | + |
185 | +COMPIZCONFIG_END_DECLS |
186 | + |
187 | +#endif |
188 | |
189 | === added file 'compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c' |
190 | --- compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c 1970-01-01 00:00:00 +0000 |
191 | +++ compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c 2012-08-07 01:05:15 +0000 |
192 | @@ -0,0 +1,260 @@ |
193 | +#include <gio/gio.h> |
194 | +#include "ccs_gsettings_interface_wrapper.h" |
195 | + |
196 | +typedef struct _CCSGSettingsWrapperPrivate CCSGSettingsWrapperPrivate; |
197 | + |
198 | +struct _CCSGSettingsWrapperPrivate |
199 | +{ |
200 | + GSettings *settings; |
201 | + char *schema; |
202 | + char *path; |
203 | +}; |
204 | + |
205 | +#define GSETTINGS_WRAPPER_PRIVATE(w) \ |
206 | + CCSGSettingsWrapperPrivate *gswPrivate = (CCSGSettingsWrapperPrivate *) ccsObjectGetPrivate (w); |
207 | + |
208 | +static GVariant * ccsGSettingsWrapperGetValueDefault (CCSGSettingsWrapper *wrapper, const char *key) |
209 | +{ |
210 | + GSETTINGS_WRAPPER_PRIVATE (wrapper); |
211 | + |
212 | + return g_settings_get_value (gswPrivate->settings, key); |
213 | +} |
214 | + |
215 | +static void ccsGSettingsWrapperSetValueDefault (CCSGSettingsWrapper *wrapper, const char *key, GVariant *variant) |
216 | +{ |
217 | + GSETTINGS_WRAPPER_PRIVATE (wrapper); |
218 | + |
219 | + g_settings_set_value (gswPrivate->settings, key, variant); |
220 | +} |
221 | + |
222 | +static void ccsGSettingsWrapperResetKeyDefault (CCSGSettingsWrapper *wrapper, const char *key) |
223 | +{ |
224 | + GSETTINGS_WRAPPER_PRIVATE (wrapper); |
225 | + |
226 | + g_settings_reset (gswPrivate->settings, key); |
227 | +} |
228 | + |
229 | +static char ** ccsGSettingsWrapperListKeysDefault (CCSGSettingsWrapper *wrapper) |
230 | +{ |
231 | + GSETTINGS_WRAPPER_PRIVATE (wrapper); |
232 | + |
233 | + return g_settings_list_keys (gswPrivate->settings); |
234 | +} |
235 | + |
236 | +static GSettings * ccsGSettingsWrapperGetGSettingsDefault (CCSGSettingsWrapper *wrapper) |
237 | +{ |
238 | + GSETTINGS_WRAPPER_PRIVATE (wrapper); |
239 | + |
240 | + return gswPrivate->settings; |
241 | +} |
242 | + |
243 | +static const char * |
244 | +ccsGSettingsWrapperGetSchemaNameDefault (CCSGSettingsWrapper *wrapper) |
245 | +{ |
246 | + GSETTINGS_WRAPPER_PRIVATE (wrapper); |
247 | + |
248 | + return gswPrivate->schema; |
249 | +} |
250 | + |
251 | +static const char * |
252 | +ccsGSettingsWrapperGetPathDefault (CCSGSettingsWrapper *wrapper) |
253 | +{ |
254 | + GSETTINGS_WRAPPER_PRIVATE (wrapper); |
255 | + |
256 | + return gswPrivate->path; |
257 | +} |
258 | + |
259 | +void |
260 | +ccsGSettingsWrapperConnectToChangedSignalDefault (CCSGSettingsWrapper *wrapper, |
261 | + GCallback callback, |
262 | + gpointer data) |
263 | +{ |
264 | + GSETTINGS_WRAPPER_PRIVATE (wrapper); |
265 | + |
266 | + g_signal_connect (gswPrivate->settings, "changed", callback, data); |
267 | +} |
268 | + |
269 | +static void |
270 | +ccsFreeGSettingsWrapperDefault (CCSGSettingsWrapper *wrapper) |
271 | +{ |
272 | + GSETTINGS_WRAPPER_PRIVATE (wrapper); |
273 | + |
274 | + if (gswPrivate->settings) |
275 | + g_object_unref (gswPrivate->settings); |
276 | + |
277 | + if (gswPrivate->path) |
278 | + (*wrapper->object.object_allocation->free_) (wrapper->object.object_allocation->allocator, |
279 | + gswPrivate->path); |
280 | + |
281 | + if (gswPrivate->schema) |
282 | + (*wrapper->object.object_allocation->free_) (wrapper->object.object_allocation->allocator, |
283 | + gswPrivate->schema); |
284 | + |
285 | + ccsObjectFinalize (wrapper); |
286 | + |
287 | + (*wrapper->object.object_allocation->free_) (wrapper->object.object_allocation->allocator, |
288 | + wrapper); |
289 | +} |
290 | + |
291 | +const CCSGSettingsWrapperInterface interface = |
292 | +{ |
293 | + ccsGSettingsWrapperSetValueDefault, |
294 | + ccsGSettingsWrapperGetValueDefault, |
295 | + ccsGSettingsWrapperResetKeyDefault, |
296 | + ccsGSettingsWrapperListKeysDefault, |
297 | + ccsGSettingsWrapperGetGSettingsDefault, |
298 | + ccsGSettingsWrapperGetSchemaNameDefault, |
299 | + ccsGSettingsWrapperGetPathDefault, |
300 | + ccsGSettingsWrapperConnectToChangedSignalDefault, |
301 | + ccsFreeGSettingsWrapperDefault |
302 | +}; |
303 | + |
304 | +static CCSGSettingsWrapperPrivate * |
305 | +allocatePrivateWrapper (CCSObjectAllocationInterface *ai, CCSGSettingsWrapper *wrapper) |
306 | +{ |
307 | + CCSGSettingsWrapperPrivate *priv = (*ai->calloc_) (ai->allocator, 1, sizeof (CCSGSettingsWrapper)); |
308 | + |
309 | + if (!priv) |
310 | + { |
311 | + (*ai->free_) (ai->allocator, wrapper); |
312 | + return NULL; |
313 | + } |
314 | + |
315 | + return priv; |
316 | +} |
317 | + |
318 | +static CCSGSettingsWrapper * |
319 | +allocateWrapper (CCSObjectAllocationInterface *ai) |
320 | +{ |
321 | + CCSGSettingsWrapper *wrapper = (*ai->calloc_) (ai->allocator, 1, sizeof (CCSGSettingsWrapper)); |
322 | + |
323 | + if (!wrapper) |
324 | + return NULL; |
325 | + |
326 | + return wrapper; |
327 | +} |
328 | + |
329 | +static void |
330 | +freeWrapperAndPriv (CCSGSettingsWrapper *wrapper, |
331 | + CCSGSettingsWrapperPrivate *priv, |
332 | + CCSObjectAllocationInterface *ai) |
333 | +{ |
334 | + (*ai->free_) (ai->allocator, priv); |
335 | + (*ai->free_) (ai->allocator, wrapper); |
336 | +} |
337 | + |
338 | +static GSettings * |
339 | +newGSettingsWithPath (const char *schema, |
340 | + const char *path, |
341 | + CCSGSettingsWrapper *wrapper, |
342 | + CCSGSettingsWrapperPrivate *priv, |
343 | + CCSObjectAllocationInterface *ai) |
344 | +{ |
345 | + GSettings *settings = g_settings_new_with_path (schema, path); |
346 | + |
347 | + if (!settings) |
348 | + { |
349 | + freeWrapperAndPriv (wrapper, priv, ai); |
350 | + return NULL; |
351 | + } |
352 | + |
353 | + return settings; |
354 | +} |
355 | + |
356 | +static GSettings * |
357 | +newGSettings (const char *schema, |
358 | + CCSGSettingsWrapper *wrapper, |
359 | + CCSGSettingsWrapperPrivate *priv, |
360 | + CCSObjectAllocationInterface *ai) |
361 | +{ |
362 | + GSettings *settings = g_settings_new (schema); |
363 | + |
364 | + if (!settings) |
365 | + { |
366 | + freeWrapperAndPriv (wrapper, priv, ai); |
367 | + return NULL; |
368 | + } |
369 | + |
370 | + return settings; |
371 | +} |
372 | + |
373 | +static Bool |
374 | +allocateWrapperData (CCSObjectAllocationInterface *ai, |
375 | + CCSGSettingsWrapper **wrapper, |
376 | + CCSGSettingsWrapperPrivate **priv) |
377 | +{ |
378 | + *wrapper = allocateWrapper (ai); |
379 | + |
380 | + if (!*wrapper) |
381 | + return FALSE; |
382 | + |
383 | + *priv = allocatePrivateWrapper (ai, *wrapper); |
384 | + |
385 | + if (!*priv) |
386 | + return FALSE; |
387 | + |
388 | + return TRUE; |
389 | +} |
390 | + |
391 | +static void |
392 | +initCCSGSettingsWrapperObject (CCSGSettingsWrapper *wrapper, |
393 | + CCSGSettingsWrapperPrivate *priv, |
394 | + CCSObjectAllocationInterface *ai) |
395 | +{ |
396 | + ccsObjectInit (wrapper, ai); |
397 | + ccsObjectAddInterface (wrapper, (const CCSInterface *) &interface, GET_INTERFACE_TYPE (CCSGSettingsWrapperInterface)); |
398 | + ccsObjectSetPrivate (wrapper, (CCSPrivate *) priv); |
399 | + ccsGSettingsWrapperRef (wrapper); |
400 | +} |
401 | + |
402 | +CCSGSettingsWrapper * |
403 | +ccsGSettingsWrapperNewForSchemaWithPath (const char *schema, |
404 | + const char *path, |
405 | + CCSObjectAllocationInterface *ai) |
406 | +{ |
407 | + CCSGSettingsWrapper *wrapper = NULL; |
408 | + CCSGSettingsWrapperPrivate *priv = NULL; |
409 | + |
410 | + if (!allocateWrapperData (ai, &wrapper, &priv)) |
411 | + return NULL; |
412 | + |
413 | + priv->schema = g_strdup (schema); |
414 | + priv->path = g_strdup (path); |
415 | + priv->settings = newGSettingsWithPath (schema, path, wrapper, priv, ai); |
416 | + |
417 | + if (!priv->settings) |
418 | + return NULL; |
419 | + |
420 | + initCCSGSettingsWrapperObject (wrapper, priv, ai); |
421 | + |
422 | + return wrapper; |
423 | +} |
424 | + |
425 | +CCSGSettingsWrapper * |
426 | +ccsGSettingsWrapperNewForSchema (const char *schema, |
427 | + CCSObjectAllocationInterface *ai) |
428 | +{ |
429 | + CCSGSettingsWrapper *wrapper = NULL; |
430 | + CCSGSettingsWrapperPrivate *priv = NULL; |
431 | + |
432 | + if (!allocateWrapperData (ai, &wrapper, &priv)) |
433 | + return NULL; |
434 | + |
435 | + priv->schema = g_strdup (schema); |
436 | + priv->settings = newGSettings (schema, wrapper, priv, ai); |
437 | + |
438 | + if (!priv->settings) |
439 | + return NULL; |
440 | + |
441 | + GValue pathValue = G_VALUE_INIT; |
442 | + g_value_init (&pathValue, G_TYPE_STRING); |
443 | + g_object_get_property (G_OBJECT (priv->settings), "path", &pathValue); |
444 | + |
445 | + priv->path = g_value_dup_string (&pathValue); |
446 | + |
447 | + g_value_unset (&pathValue); |
448 | + |
449 | + initCCSGSettingsWrapperObject (wrapper, priv, ai); |
450 | + |
451 | + return wrapper; |
452 | +} |
453 | |
454 | === added file 'compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.h' |
455 | --- compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.h 1970-01-01 00:00:00 +0000 |
456 | +++ compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.h 2012-08-07 01:05:15 +0000 |
457 | @@ -0,0 +1,21 @@ |
458 | +#ifndef _CCS_GSETTINGS_INTERFACE_WRAPPER_H |
459 | +#define _CCS_GSETTINGS_INTERFACE_WRAPPER_H |
460 | + |
461 | +#include <ccs-defs.h> |
462 | + |
463 | +COMPIZCONFIG_BEGIN_DECLS |
464 | + |
465 | +#include "ccs_gsettings_interface.h" |
466 | + |
467 | +CCSGSettingsWrapper * |
468 | +ccsGSettingsWrapperNewForSchemaWithPath (const char *schema, |
469 | + const char *path, |
470 | + CCSObjectAllocationInterface *ai); |
471 | + |
472 | +CCSGSettingsWrapper * |
473 | +ccsGSettingsWrapperNewForSchema (const char *schema, |
474 | + CCSObjectAllocationInterface *ai); |
475 | + |
476 | +COMPIZCONFIG_END_DECLS |
477 | + |
478 | +#endif |
479 | |
480 | === added file 'compizconfig/gsettings/gsettings_backend_shared/gsettings_util.' |
481 | === modified file 'compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c' |
482 | --- compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c 2012-07-10 10:14:00 +0000 |
483 | +++ compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c 2012-08-07 01:05:15 +0000 |
484 | @@ -1,8 +1,21 @@ |
485 | #define CCS_LOG_DOMAIN "gsettings" |
486 | #include <string.h> |
487 | +#include <stdlib.h> |
488 | #include <stdio.h> |
489 | #include "gsettings_shared.h" |
490 | |
491 | +INTERFACE_TYPE (CCSGSettingsBackendInterface); |
492 | + |
493 | +const CCSBackendInfo gsettingsBackendInfo = |
494 | +{ |
495 | + "gsettings", |
496 | + "GSettings Configuration Backend", |
497 | + "GSettings Configuration Backend for libccs", |
498 | + TRUE, |
499 | + TRUE, |
500 | + 1 |
501 | +}; |
502 | + |
503 | GList * |
504 | variantTypeToPossibleSettingType (const gchar *vt) |
505 | { |
506 | @@ -38,23 +51,18 @@ |
507 | return possibleTypesList; |
508 | } |
509 | |
510 | -GObject * |
511 | -findObjectInListWithPropertySchemaName (const gchar *schemaName, |
512 | - GList *iter) |
513 | +CCSGSettingsWrapper * |
514 | +findCCSGSettingsWrapperBySchemaName (const gchar *schemaName, |
515 | + GList *iter) |
516 | { |
517 | while (iter) |
518 | { |
519 | - GObject *obj = (GObject *) iter->data; |
520 | - gchar *name = NULL; |
521 | + CCSGSettingsWrapper *obj = iter->data; |
522 | + const gchar *name = ccsGSettingsWrapperGetSchemaName (obj); |
523 | |
524 | - g_object_get (obj, |
525 | - "schema", |
526 | - &name, NULL); |
527 | if (g_strcmp0 (name, schemaName) != 0) |
528 | obj = NULL; |
529 | |
530 | - g_free (name); |
531 | - |
532 | if (obj) |
533 | return obj; |
534 | else |
535 | @@ -327,6 +335,101 @@ |
536 | return found; |
537 | } |
538 | |
539 | +Bool |
540 | +findSettingAndPluginToUpdateFromPath (CCSGSettingsWrapper *settings, |
541 | + const char *path, |
542 | + const gchar *keyName, |
543 | + CCSContext *context, |
544 | + CCSPlugin **plugin, |
545 | + CCSSetting **setting, |
546 | + char **uncleanKeyName) |
547 | +{ |
548 | + char *pluginName; |
549 | + unsigned int screenNum; |
550 | + |
551 | + if (!decomposeGSettingsPath (path, &pluginName, &screenNum)) |
552 | + return FALSE; |
553 | + |
554 | + *plugin = ccsFindPlugin (context, pluginName); |
555 | + |
556 | + if (*plugin) |
557 | + { |
558 | + *uncleanKeyName = translateKeyForCCS (keyName); |
559 | + |
560 | + *setting = ccsFindSetting (*plugin, *uncleanKeyName); |
561 | + if (!*setting) |
562 | + { |
563 | + /* Couldn't find setting straight off the bat, |
564 | + * try and find the best match */ |
565 | + GVariant *value = ccsGSettingsWrapperGetValue (settings, keyName); |
566 | + |
567 | + if (value) |
568 | + { |
569 | + GList *possibleSettingTypes = variantTypeToPossibleSettingType (g_variant_get_type_string (value)); |
570 | + GList *iter = possibleSettingTypes; |
571 | + |
572 | + while (iter) |
573 | + { |
574 | + *setting = attemptToFindCCSSettingFromLossyName (ccsGetPluginSettings (*plugin), |
575 | + keyName, |
576 | + (CCSSettingType) GPOINTER_TO_INT (iter->data)); |
577 | + |
578 | + if (*setting) |
579 | + break; |
580 | + |
581 | + iter = iter->next; |
582 | + } |
583 | + |
584 | + g_list_free (possibleSettingTypes); |
585 | + g_variant_unref (value); |
586 | + } |
587 | + } |
588 | + } |
589 | + |
590 | + g_free (pluginName); |
591 | + |
592 | + if (!*plugin || !*setting) |
593 | + return FALSE; |
594 | + |
595 | + return TRUE; |
596 | +} |
597 | + |
598 | +Bool |
599 | +updateSettingWithGSettingsKeyName (CCSBackend *backend, |
600 | + CCSGSettingsWrapper *settings, |
601 | + const gchar *keyName, |
602 | + CCSBackendUpdateFunc updateSetting) |
603 | +{ |
604 | + CCSContext *context = ccsGSettingsBackendGetContext (backend); |
605 | + char *uncleanKeyName = NULL; |
606 | + char *pathOrig; |
607 | + CCSPlugin *plugin; |
608 | + CCSSetting *setting; |
609 | + Bool ret = TRUE; |
610 | + |
611 | + pathOrig = strdup (ccsGSettingsWrapperGetPath (settings)); |
612 | + |
613 | + if (findSettingAndPluginToUpdateFromPath (settings, pathOrig, keyName, context, &plugin, &setting, &uncleanKeyName)) |
614 | + (*updateSetting) (backend, context, plugin, setting); |
615 | + else |
616 | + { |
617 | + /* We hit a situation where either the key stored in GSettings couldn't be |
618 | + * matched at all to a key in the xml file, or where there were multiple matches. |
619 | + * Unfortunately, there isn't much we can do about this, other than try |
620 | + * and warn the user and bail out. It just means that if the key was updated |
621 | + * externally we won't know about the change until the next reload of settings */ |
622 | + ccsWarning ("Unable to find setting %s, for path %s", uncleanKeyName, pathOrig); |
623 | + ret = FALSE; |
624 | + } |
625 | + |
626 | + g_free (pathOrig); |
627 | + |
628 | + if (uncleanKeyName) |
629 | + free (uncleanKeyName); |
630 | + |
631 | + return ret; |
632 | +} |
633 | + |
634 | gchar * |
635 | makeCompizProfilePath (const gchar *profilename) |
636 | { |
637 | @@ -340,3 +443,825 @@ |
638 | "plugins", pluginName, "/", NULL); |
639 | } |
640 | |
641 | +gchar * |
642 | +getNameForCCSSetting (CCSSetting *setting) |
643 | +{ |
644 | + return translateKeyForGSettings (ccsSettingGetName (setting)); |
645 | +} |
646 | + |
647 | +Bool |
648 | +checkReadVariantIsValid (GVariant *gsettingsValue, CCSSettingType type, const gchar *pathName) |
649 | +{ |
650 | + /* first check if the key is set */ |
651 | + if (!gsettingsValue) |
652 | + { |
653 | + ccsWarning ("There is no key at the path %s. " |
654 | + "Settings from this path won't be read. Try to remove " |
655 | + "that value so that operation can continue properly.", |
656 | + pathName); |
657 | + return FALSE; |
658 | + } |
659 | + |
660 | + if (!variantIsValidForCCSType (gsettingsValue, type)) |
661 | + { |
662 | + ccsWarning ("There is an unsupported value at path %s. " |
663 | + "Settings from this path won't be read. Try to remove " |
664 | + "that value so that operation can continue properly.", |
665 | + pathName); |
666 | + return FALSE; |
667 | + } |
668 | + |
669 | + return TRUE; |
670 | +} |
671 | + |
672 | +GVariant * |
673 | +getVariantAtKey (CCSGSettingsWrapper *settings, const char *key, const char *pathName, CCSSettingType type) |
674 | +{ |
675 | + GVariant *gsettingsValue = ccsGSettingsWrapperGetValue (settings, key); |
676 | + |
677 | + if (!checkReadVariantIsValid (gsettingsValue, type, pathName)) |
678 | + { |
679 | + g_variant_unref (gsettingsValue); |
680 | + return NULL; |
681 | + } |
682 | + |
683 | + return gsettingsValue; |
684 | +} |
685 | + |
686 | +CCSSettingValueList |
687 | +readBoolListValue (GVariantIter *iter, guint nItems, CCSSetting *setting, CCSObjectAllocationInterface *ai) |
688 | +{ |
689 | + CCSSettingValueList list = NULL; |
690 | + Bool *array = (*ai->calloc_) (ai->allocator, 1, nItems * sizeof (Bool)); |
691 | + Bool *arrayCounter = array; |
692 | + gboolean value; |
693 | + |
694 | + if (!array) |
695 | + return NULL; |
696 | + |
697 | + /* Reads each item from the variant into arrayCounter */ |
698 | + while (g_variant_iter_loop (iter, "b", &value)) |
699 | + *arrayCounter++ = value ? TRUE : FALSE; |
700 | + |
701 | + list = ccsGetValueListFromBoolArray (array, nItems, setting); |
702 | + free (array); |
703 | + |
704 | + return list; |
705 | +} |
706 | + |
707 | +CCSSettingValueList |
708 | +readIntListValue (GVariantIter *iter, guint nItems, CCSSetting *setting, CCSObjectAllocationInterface *ai) |
709 | +{ |
710 | + CCSSettingValueList list = NULL; |
711 | + int *array = (*ai->calloc_) (ai->allocator, 1, nItems * sizeof (int)); |
712 | + int *arrayCounter = array; |
713 | + gint value; |
714 | + |
715 | + if (!array) |
716 | + return NULL; |
717 | + |
718 | + /* Reads each item from the variant into arrayCounter */ |
719 | + while (g_variant_iter_loop (iter, "i", &value)) |
720 | + *arrayCounter++ = value; |
721 | + |
722 | + list = ccsGetValueListFromIntArray (array, nItems, setting); |
723 | + free (array); |
724 | + |
725 | + return list; |
726 | +} |
727 | + |
728 | +CCSSettingValueList |
729 | +readFloatListValue (GVariantIter *iter, guint nItems, CCSSetting *setting, CCSObjectAllocationInterface *ai) |
730 | +{ |
731 | + CCSSettingValueList list = NULL; |
732 | + float *array = (*ai->calloc_) (ai->allocator, 1, nItems * sizeof (float)); |
733 | + float *arrayCounter = array; |
734 | + gdouble value; |
735 | + |
736 | + if (!array) |
737 | + return NULL; |
738 | + |
739 | + /* Reads each item from the variant into arrayCounter */ |
740 | + while (g_variant_iter_loop (iter, "d", &value)) |
741 | + *arrayCounter++ = value; |
742 | + |
743 | + list = ccsGetValueListFromFloatArray (array, nItems, setting); |
744 | + free (array); |
745 | + |
746 | + return list; |
747 | +} |
748 | + |
749 | +CCSSettingValueList |
750 | +readStringListValue (GVariantIter *iter, guint nItems, CCSSetting *setting, CCSObjectAllocationInterface *ai) |
751 | +{ |
752 | + CCSSettingValueList list = NULL; |
753 | + const gchar **array = (*ai->calloc_) (ai->allocator, 1, (nItems + 1) * sizeof (gchar *)); |
754 | + const gchar **arrayCounter = array; |
755 | + gchar *value; |
756 | + |
757 | + if (!array) |
758 | + return NULL; |
759 | + |
760 | + array[nItems] = NULL; |
761 | + |
762 | + /* Reads each item from the variant into arrayCounter */ |
763 | + while (g_variant_iter_next (iter, "s", &value)) |
764 | + *arrayCounter++ = value; |
765 | + |
766 | + list = ccsGetValueListFromStringArray (array, nItems, setting); |
767 | + g_strfreev ((char **) array); |
768 | + |
769 | + return list; |
770 | +} |
771 | + |
772 | +CCSSettingValueList |
773 | +readColorListValue (GVariantIter *iter, guint nItems, CCSSetting *setting, CCSObjectAllocationInterface *ai) |
774 | +{ |
775 | + CCSSettingValueList list = NULL; |
776 | + char *colorValue; |
777 | + CCSSettingColorValue *array = (*ai->calloc_) (ai->allocator, 1, nItems * sizeof (CCSSettingColorValue)); |
778 | + unsigned int i = 0; |
779 | + |
780 | + if (!array) |
781 | + return NULL; |
782 | + |
783 | + while (g_variant_iter_loop (iter, "s", &colorValue)) |
784 | + { |
785 | + ccsStringToColor (colorValue, |
786 | + &array[i]); |
787 | + i++; |
788 | + } |
789 | + |
790 | + list = ccsGetValueListFromColorArray (array, nItems, setting); |
791 | + free (array); |
792 | + |
793 | + return list; |
794 | +} |
795 | + |
796 | +CCSSettingValueList |
797 | +readListValue (GVariant *gsettingsValue, CCSSetting *setting, CCSObjectAllocationInterface *ai) |
798 | +{ |
799 | + CCSSettingType listType = ccsSettingGetInfo (setting)->forList.listType; |
800 | + gboolean hasVariantType; |
801 | + unsigned int nItems; |
802 | + CCSSettingValueList list = NULL; |
803 | + GVariantIter iter; |
804 | + |
805 | + hasVariantType = compizconfigTypeHasVariantType (listType); |
806 | + |
807 | + if (!hasVariantType) |
808 | + return NULL; |
809 | + |
810 | + g_variant_iter_init (&iter, gsettingsValue); |
811 | + nItems = g_variant_iter_n_children (&iter); |
812 | + |
813 | + switch (listType) |
814 | + { |
815 | + case TypeBool: |
816 | + list = readBoolListValue (&iter, nItems, setting, ai); |
817 | + break; |
818 | + case TypeInt: |
819 | + list = readIntListValue (&iter, nItems, setting, ai); |
820 | + break; |
821 | + case TypeFloat: |
822 | + list = readFloatListValue (&iter, nItems, setting, ai); |
823 | + break; |
824 | + case TypeString: |
825 | + case TypeMatch: |
826 | + list = readStringListValue (&iter, nItems, setting, ai); |
827 | + break; |
828 | + case TypeColor: |
829 | + list = readColorListValue (&iter, nItems, setting, ai); |
830 | + break; |
831 | + default: |
832 | + break; |
833 | + } |
834 | + |
835 | + return list; |
836 | +} |
837 | + |
838 | +const char * readStringFromVariant (GVariant *gsettingsValue) |
839 | +{ |
840 | + return g_variant_get_string (gsettingsValue, NULL); |
841 | +} |
842 | + |
843 | +int readIntFromVariant (GVariant *gsettingsValue) |
844 | +{ |
845 | + return g_variant_get_int32 (gsettingsValue); |
846 | +} |
847 | + |
848 | +Bool readBoolFromVariant (GVariant *gsettingsValue) |
849 | +{ |
850 | + return g_variant_get_boolean (gsettingsValue) ? TRUE : FALSE; |
851 | +} |
852 | + |
853 | +float readFloatFromVariant (GVariant *gsettingsValue) |
854 | +{ |
855 | + return (float) g_variant_get_double (gsettingsValue); |
856 | +} |
857 | + |
858 | +CCSSettingColorValue readColorFromVariant (GVariant *gsettingsValue, Bool *success) |
859 | +{ |
860 | + const char *value; |
861 | + CCSSettingColorValue color; |
862 | + value = g_variant_get_string (gsettingsValue, NULL); |
863 | + |
864 | + if (value) |
865 | + *success = ccsStringToColor (value, &color); |
866 | + else |
867 | + *success = FALSE; |
868 | + |
869 | + return color; |
870 | +} |
871 | + |
872 | +CCSSettingKeyValue readKeyFromVariant (GVariant *gsettingsValue, Bool *success) |
873 | +{ |
874 | + const char *value; |
875 | + CCSSettingKeyValue key; |
876 | + value = g_variant_get_string (gsettingsValue, NULL); |
877 | + |
878 | + if (value) |
879 | + *success = ccsStringToKeyBinding (value, &key); |
880 | + else |
881 | + *success = FALSE; |
882 | + |
883 | + return key; |
884 | +} |
885 | + |
886 | +CCSSettingButtonValue readButtonFromVariant (GVariant *gsettingsValue, Bool *success) |
887 | +{ |
888 | + const char *value; |
889 | + CCSSettingButtonValue button; |
890 | + value = g_variant_get_string (gsettingsValue, NULL); |
891 | + |
892 | + if (value) |
893 | + *success = ccsStringToButtonBinding (value, &button); |
894 | + else |
895 | + *success = FALSE; |
896 | + |
897 | + return button; |
898 | +} |
899 | + |
900 | +unsigned int readEdgeFromVariant (GVariant *gsettingsValue) |
901 | +{ |
902 | + const char *value; |
903 | + value = g_variant_get_string (gsettingsValue, NULL); |
904 | + |
905 | + if (value) |
906 | + return ccsStringToEdges (value); |
907 | + |
908 | + return 0; |
909 | +} |
910 | + |
911 | +GVariant * |
912 | +writeBoolListValue (CCSSettingValueList list) |
913 | +{ |
914 | + GVariant *value = NULL; |
915 | + GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE ("ab")); |
916 | + while (list) |
917 | + { |
918 | + g_variant_builder_add (builder, "b", list->data->value.asBool); |
919 | + list = list->next; |
920 | + } |
921 | + value = g_variant_new ("ab", builder); |
922 | + g_variant_builder_unref (builder); |
923 | + |
924 | + return value; |
925 | +} |
926 | + |
927 | +GVariant * |
928 | +writeIntListValue (CCSSettingValueList list) |
929 | +{ |
930 | + GVariant *value = NULL; |
931 | + GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE ("ai")); |
932 | + while (list) |
933 | + { |
934 | + g_variant_builder_add (builder, "i", list->data->value.asInt); |
935 | + list = list->next; |
936 | + } |
937 | + value = g_variant_new ("ai", builder); |
938 | + g_variant_builder_unref (builder); |
939 | + |
940 | + return value; |
941 | +} |
942 | + |
943 | +GVariant * |
944 | +writeFloatListValue (CCSSettingValueList list) |
945 | +{ |
946 | + GVariant *value = NULL; |
947 | + GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE ("ad")); |
948 | + while (list) |
949 | + { |
950 | + g_variant_builder_add (builder, "d", (gdouble) list->data->value.asFloat); |
951 | + list = list->next; |
952 | + } |
953 | + value = g_variant_new ("ad", builder); |
954 | + g_variant_builder_unref (builder); |
955 | + |
956 | + return value; |
957 | +} |
958 | + |
959 | +GVariant * |
960 | +writeStringListValue (CCSSettingValueList list) |
961 | +{ |
962 | + GVariant *value = NULL; |
963 | + GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE ("as")); |
964 | + while (list) |
965 | + { |
966 | + g_variant_builder_add (builder, "s", list->data->value.asString); |
967 | + list = list->next; |
968 | + } |
969 | + value = g_variant_new ("as", builder); |
970 | + g_variant_builder_unref (builder); |
971 | + |
972 | + return value; |
973 | +} |
974 | + |
975 | +GVariant * |
976 | +writeMatchListValue (CCSSettingValueList list) |
977 | +{ |
978 | + GVariant *value = NULL; |
979 | + GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE ("as")); |
980 | + while (list) |
981 | + { |
982 | + g_variant_builder_add (builder, "s", list->data->value.asMatch); |
983 | + list = list->next; |
984 | + } |
985 | + value = g_variant_new ("as", builder); |
986 | + g_variant_builder_unref (builder); |
987 | + |
988 | + return value; |
989 | +} |
990 | + |
991 | +GVariant * |
992 | +writeColorListValue (CCSSettingValueList list) |
993 | +{ |
994 | + GVariant *value = NULL; |
995 | + GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE ("as")); |
996 | + char *item; |
997 | + while (list) |
998 | + { |
999 | + item = ccsColorToString (&list->data->value.asColor); |
1000 | + g_variant_builder_add (builder, "s", item); |
1001 | + g_free (item); |
1002 | + list = list->next; |
1003 | + } |
1004 | + value = g_variant_new ("as", builder); |
1005 | + g_variant_builder_unref (builder); |
1006 | + |
1007 | + return value; |
1008 | +} |
1009 | + |
1010 | +Bool |
1011 | +writeListValue (CCSSettingValueList list, |
1012 | + CCSSettingType listType, |
1013 | + GVariant **gsettingsValue) |
1014 | +{ |
1015 | + GVariant *value = NULL; |
1016 | + |
1017 | + switch (listType) |
1018 | + { |
1019 | + case TypeBool: |
1020 | + value = writeBoolListValue (list); |
1021 | + break; |
1022 | + case TypeInt: |
1023 | + value = writeIntListValue (list); |
1024 | + break; |
1025 | + case TypeFloat: |
1026 | + value = writeFloatListValue (list); |
1027 | + break; |
1028 | + case TypeString: |
1029 | + value = writeStringListValue (list); |
1030 | + break; |
1031 | + case TypeMatch: |
1032 | + value = writeMatchListValue (list); |
1033 | + break; |
1034 | + case TypeColor: |
1035 | + value = writeColorListValue (list); |
1036 | + break; |
1037 | + default: |
1038 | + ccsWarning ("Attempt to write unsupported list type %d!", |
1039 | + listType); |
1040 | + return FALSE; |
1041 | + break; |
1042 | + } |
1043 | + |
1044 | + *gsettingsValue = value; |
1045 | + return TRUE; |
1046 | +} |
1047 | + |
1048 | +Bool writeStringToVariant (const char *value, GVariant **variant) |
1049 | +{ |
1050 | + *variant = g_variant_new_string (value); |
1051 | + return TRUE; |
1052 | +} |
1053 | + |
1054 | +Bool writeFloatToVariant (float value, GVariant **variant) |
1055 | +{ |
1056 | + *variant = g_variant_new_double ((double) value); |
1057 | + return TRUE; |
1058 | +} |
1059 | + |
1060 | +Bool writeIntToVariant (int value, GVariant **variant) |
1061 | +{ |
1062 | + *variant = g_variant_new_int32 (value); |
1063 | + return TRUE; |
1064 | +} |
1065 | + |
1066 | +Bool writeBoolToVariant (Bool value, GVariant **variant) |
1067 | +{ |
1068 | + *variant = g_variant_new_boolean (value); |
1069 | + return TRUE; |
1070 | +} |
1071 | + |
1072 | +Bool writeColorToVariant (CCSSettingColorValue value, GVariant **variant) |
1073 | +{ |
1074 | + char *colString; |
1075 | + |
1076 | + colString = ccsColorToString (&value); |
1077 | + if (!colString) |
1078 | + return FALSE; |
1079 | + |
1080 | + *variant = g_variant_new_string (colString); |
1081 | + free (colString); |
1082 | + |
1083 | + return TRUE; |
1084 | +} |
1085 | + |
1086 | +Bool writeKeyToVariant (CCSSettingKeyValue key, GVariant **variant) |
1087 | +{ |
1088 | + char *keyString; |
1089 | + |
1090 | + keyString = ccsKeyBindingToString (&key); |
1091 | + if (!keyString) |
1092 | + return FALSE; |
1093 | + |
1094 | + *variant = g_variant_new_string (keyString); |
1095 | + free (keyString); |
1096 | + |
1097 | + return TRUE; |
1098 | +} |
1099 | + |
1100 | +Bool writeButtonToVariant (CCSSettingButtonValue button, GVariant **variant) |
1101 | +{ |
1102 | + char *buttonString; |
1103 | + |
1104 | + buttonString = ccsButtonBindingToString (&button); |
1105 | + if (!buttonString) |
1106 | + return FALSE; |
1107 | + |
1108 | + *variant = g_variant_new_string (buttonString); |
1109 | + free (buttonString); |
1110 | + return TRUE; |
1111 | +} |
1112 | + |
1113 | +Bool writeEdgeToVariant (unsigned int edges, GVariant **variant) |
1114 | +{ |
1115 | + char *edgeString; |
1116 | + |
1117 | + edgeString = ccsEdgesToString (edges); |
1118 | + if (!edgeString) |
1119 | + return FALSE; |
1120 | + |
1121 | + *variant = g_variant_new_string (edgeString); |
1122 | + free (edgeString); |
1123 | + return TRUE; |
1124 | +} |
1125 | + |
1126 | +void |
1127 | +writeVariantToKey (CCSGSettingsWrapper *settings, |
1128 | + const char *key, |
1129 | + GVariant *value) |
1130 | +{ |
1131 | + ccsGSettingsWrapperSetValue (settings, key, value); |
1132 | +} |
1133 | + |
1134 | +typedef void (*VariantItemCheckAndInsertFunc) (GVariantBuilder *, const char *item, void *userData); |
1135 | + |
1136 | +typedef struct _FindItemInVariantData |
1137 | +{ |
1138 | + gboolean found; |
1139 | + const char *item; |
1140 | +} FindItemInVariantData; |
1141 | + |
1142 | +static void |
1143 | +insertIfNotEqual (GVariantBuilder *builder, const char *item, void *userData) |
1144 | +{ |
1145 | + const char *cmp = (const char *) userData; |
1146 | + |
1147 | + if (g_strcmp0 (item, cmp)) |
1148 | + g_variant_builder_add (builder, "s", item); |
1149 | +} |
1150 | + |
1151 | +static void |
1152 | +findItemForVariantData (GVariantBuilder *builder, const char *item, void *userData) |
1153 | +{ |
1154 | + FindItemInVariantData *data = (FindItemInVariantData *) userData; |
1155 | + |
1156 | + if (!data->found) |
1157 | + data->found = g_str_equal (data->item, item); |
1158 | + |
1159 | + g_variant_builder_add (builder, "s", item); |
1160 | +} |
1161 | + |
1162 | +static void |
1163 | +rebuildVariant (GVariantBuilder *builder, |
1164 | + GVariant *originalVariant, |
1165 | + VariantItemCheckAndInsertFunc checkAndInsert, |
1166 | + void *userData) |
1167 | +{ |
1168 | + GVariantIter iter; |
1169 | + char *str; |
1170 | + |
1171 | + g_variant_iter_init (&iter, originalVariant); |
1172 | + while (g_variant_iter_loop (&iter, "s", &str)) |
1173 | + { |
1174 | + (*checkAndInsert) (builder, str, userData); |
1175 | + } |
1176 | +} |
1177 | + |
1178 | +gboolean |
1179 | +appendStringToVariantIfUnique (GVariant **variant, |
1180 | + const char *string) |
1181 | +{ |
1182 | + GVariantBuilder newVariantBuilder; |
1183 | + FindItemInVariantData findItemData; |
1184 | + |
1185 | + memset (&findItemData, 0, sizeof (FindItemInVariantData)); |
1186 | + g_variant_builder_init (&newVariantBuilder, G_VARIANT_TYPE ("as")); |
1187 | + |
1188 | + findItemData.item = string; |
1189 | + |
1190 | + rebuildVariant (&newVariantBuilder, *variant, findItemForVariantData, &findItemData); |
1191 | + |
1192 | + if (!findItemData.found) |
1193 | + g_variant_builder_add (&newVariantBuilder, "s", string); |
1194 | + |
1195 | + g_variant_unref (*variant); |
1196 | + *variant = g_variant_builder_end (&newVariantBuilder); |
1197 | + |
1198 | + return !findItemData.found; |
1199 | +} |
1200 | + |
1201 | +void |
1202 | +removeItemFromVariant (GVariant **variant, |
1203 | + const char *string) |
1204 | +{ |
1205 | + GVariantBuilder newVariantBuilder; |
1206 | + |
1207 | + g_variant_builder_init (&newVariantBuilder, G_VARIANT_TYPE ("as")); |
1208 | + |
1209 | + rebuildVariant (&newVariantBuilder, *variant, insertIfNotEqual, (void *) string); |
1210 | + |
1211 | + g_variant_unref (*variant); |
1212 | + *variant = g_variant_builder_end (&newVariantBuilder); |
1213 | +} |
1214 | + |
1215 | +void |
1216 | +resetOptionToDefault (CCSBackend *backend, CCSSetting * setting) |
1217 | +{ |
1218 | + CCSGSettingsWrapper *settings = getSettingsObjectForCCSSetting (backend, setting); |
1219 | + char *cleanSettingName = translateKeyForGSettings (ccsSettingGetName (setting)); |
1220 | + |
1221 | + ccsGSettingsWrapperResetKey (settings, cleanSettingName); |
1222 | + |
1223 | + free (cleanSettingName); |
1224 | +} |
1225 | + |
1226 | +gchar * |
1227 | +makeSettingPath (const char *currentProfile, CCSSetting *setting) |
1228 | +{ |
1229 | + return makeCompizPluginPath (currentProfile, |
1230 | + ccsPluginGetName (ccsSettingGetParent (setting))); |
1231 | +} |
1232 | + |
1233 | +CCSGSettingsWrapper * |
1234 | +getSettingsObjectForCCSSetting (CCSBackend *backend, CCSSetting *setting) |
1235 | +{ |
1236 | + CCSGSettingsWrapper *ret = NULL; |
1237 | + gchar *pathName = makeSettingPath (ccsGSettingsBackendGetCurrentProfile (backend), setting); |
1238 | + |
1239 | + ret = ccsGSettingsGetSettingsObjectForPluginWithPath (backend, |
1240 | + ccsPluginGetName (ccsSettingGetParent (setting)), |
1241 | + pathName, |
1242 | + ccsPluginGetContext (ccsSettingGetParent (setting))); |
1243 | + |
1244 | + g_free (pathName); |
1245 | + return ret; |
1246 | +} |
1247 | + |
1248 | +gboolean |
1249 | +ccsGSettingsBackendAddProfileDefault (CCSBackend *backend, const char *profile) |
1250 | +{ |
1251 | + GVariant *profiles; |
1252 | + gboolean ret = FALSE; |
1253 | + |
1254 | + profiles = ccsGSettingsBackendGetExistingProfiles (backend); |
1255 | + if (appendStringToVariantIfUnique (&profiles, profile)) |
1256 | + { |
1257 | + ret = TRUE; |
1258 | + ccsGSettingsBackendSetExistingProfiles (backend, profiles); |
1259 | + } |
1260 | + else |
1261 | + g_variant_unref (profiles); |
1262 | + |
1263 | + return ret; |
1264 | +} |
1265 | + |
1266 | +void |
1267 | +ccsGSettingsBackendUpdateCurrentProfileNameDefault (CCSBackend *backend, const char *profile) |
1268 | +{ |
1269 | + ccsGSettingsBackendAddProfile (backend, profile); |
1270 | + ccsGSettingsBackendSetCurrentProfile (backend, profile); |
1271 | +} |
1272 | + |
1273 | +gboolean |
1274 | +ccsGSettingsBackendUpdateProfileDefault (CCSBackend *backend, CCSContext *context) |
1275 | +{ |
1276 | + const char *currentProfile = ccsGSettingsBackendGetCurrentProfile (backend); |
1277 | + const char *ccsProfile = ccsGetProfile (context); |
1278 | + char *profile = NULL; |
1279 | + |
1280 | + if (!ccsProfile) |
1281 | + profile = strdup (DEFAULTPROF); |
1282 | + else |
1283 | + profile = strdup (ccsProfile); |
1284 | + |
1285 | + if (!strlen (profile)) |
1286 | + { |
1287 | + free (profile); |
1288 | + profile = strdup (DEFAULTPROF); |
1289 | + } |
1290 | + |
1291 | + if (g_strcmp0 (profile, currentProfile)) |
1292 | + ccsGSettingsBackendUpdateCurrentProfileName (backend, profile); |
1293 | + |
1294 | + free (profile); |
1295 | + |
1296 | + return TRUE; |
1297 | +} |
1298 | + |
1299 | +gboolean |
1300 | +deleteProfile (CCSBackend *backend, |
1301 | + CCSContext *context, |
1302 | + const char *profile) |
1303 | +{ |
1304 | + GVariant *plugins; |
1305 | + GVariant *profiles; |
1306 | + const char *currentProfile = ccsGSettingsBackendGetCurrentProfile (backend); |
1307 | + |
1308 | + plugins = ccsGSettingsBackendGetPluginsWithSetKeys (backend); |
1309 | + profiles = ccsGSettingsBackendGetExistingProfiles (backend); |
1310 | + |
1311 | + ccsGSettingsBackendUnsetAllChangedPluginKeysInProfile (backend, context, plugins, currentProfile); |
1312 | + ccsGSettingsBackendClearPluginsWithSetKeys (backend); |
1313 | + |
1314 | + removeItemFromVariant (&profiles, profile); |
1315 | + |
1316 | + /* Remove the profile from existing-profiles */ |
1317 | + ccsGSettingsBackendSetExistingProfiles (backend, profiles); |
1318 | + |
1319 | + ccsGSettingsBackendUpdateProfile (backend, context); |
1320 | + |
1321 | + /* Since we do not call g_settings_set_value on |
1322 | + * plugins, we must also unref the variant */ |
1323 | + g_variant_unref (plugins); |
1324 | + |
1325 | + return TRUE; |
1326 | +} |
1327 | + |
1328 | +void |
1329 | +ccsGSettingsBackendUnsetAllChangedPluginKeysInProfileDefault (CCSBackend *backend, |
1330 | + CCSContext *context, |
1331 | + GVariant *pluginsWithChangedKeys, |
1332 | + const char * profile) |
1333 | +{ |
1334 | + GVariantIter iter; |
1335 | + char *plugin; |
1336 | + |
1337 | + g_variant_iter_init (&iter, pluginsWithChangedKeys); |
1338 | + while (g_variant_iter_loop (&iter, "s", &plugin)) |
1339 | + { |
1340 | + CCSGSettingsWrapper *settings; |
1341 | + gchar *pathName = makeCompizPluginPath (profile, plugin); |
1342 | + |
1343 | + settings = ccsGSettingsGetSettingsObjectForPluginWithPath (backend, plugin, pathName, context); |
1344 | + g_free (pathName); |
1345 | + |
1346 | + /* The GSettings documentation says not to use this API |
1347 | + * because we should know our own schema ... though really |
1348 | + * we don't because we autogenerate schemas ... */ |
1349 | + if (settings) |
1350 | + { |
1351 | + char **keys = ccsGSettingsWrapperListKeys (settings); |
1352 | + char **key_ptr; |
1353 | + |
1354 | + /* Unset all the keys */ |
1355 | + for (key_ptr = keys; *key_ptr; key_ptr++) |
1356 | + ccsGSettingsWrapperResetKey (settings, *key_ptr); |
1357 | + |
1358 | + g_strfreev (keys); |
1359 | + } |
1360 | + } |
1361 | +} |
1362 | + |
1363 | +CCSContext * |
1364 | +ccsGSettingsBackendGetContext (CCSBackend *backend) |
1365 | +{ |
1366 | + return (*(GET_INTERFACE (CCSGSettingsBackendInterface, backend))->gsettingsBackendGetContext) (backend); |
1367 | +} |
1368 | + |
1369 | + |
1370 | +void |
1371 | +ccsGSettingsBackendConnectToChangedSignal (CCSBackend *backend, |
1372 | + CCSGSettingsWrapper *object) |
1373 | +{ |
1374 | + (*(GET_INTERFACE (CCSGSettingsBackendInterface, backend))->gsettingsBackendConnectToChangedSignal) (backend, object); |
1375 | +} |
1376 | + |
1377 | +CCSGSettingsWrapper * |
1378 | +ccsGSettingsGetSettingsObjectForPluginWithPath (CCSBackend *backend, |
1379 | + const char *plugin, |
1380 | + const char *path, |
1381 | + CCSContext *context) |
1382 | +{ |
1383 | + return (*(GET_INTERFACE (CCSGSettingsBackendInterface, backend))->gsettingsBackendGetSettingsObjectForPluginWithPath) (backend, plugin, path, context); |
1384 | +} |
1385 | + |
1386 | +void |
1387 | +ccsGSettingsBackendRegisterGConfClient (CCSBackend *backend) |
1388 | +{ |
1389 | + (*(GET_INTERFACE (CCSGSettingsBackendInterface, backend))->gsettingsBackendRegisterGConfClient) (backend); |
1390 | +} |
1391 | + |
1392 | +void |
1393 | +ccsGSettingsBackendUnregisterGConfClient (CCSBackend *backend) |
1394 | +{ |
1395 | + (*(GET_INTERFACE (CCSGSettingsBackendInterface, backend))->gsettingsBackendUnregisterGConfClient) (backend); |
1396 | +} |
1397 | + |
1398 | +const char * |
1399 | +ccsGSettingsBackendGetCurrentProfile (CCSBackend *backend) |
1400 | +{ |
1401 | + return (*(GET_INTERFACE (CCSGSettingsBackendInterface, backend))->gsettingsBackendGetCurrentProfile) (backend); |
1402 | +} |
1403 | + |
1404 | +GVariant * |
1405 | +ccsGSettingsBackendGetExistingProfiles (CCSBackend *backend) |
1406 | +{ |
1407 | + return (*(GET_INTERFACE (CCSGSettingsBackendInterface, backend))->gsettingsBackendGetExistingProfiles) (backend); |
1408 | +} |
1409 | + |
1410 | +void |
1411 | +ccsGSettingsBackendSetExistingProfiles (CCSBackend *backend, GVariant *value) |
1412 | +{ |
1413 | + (*(GET_INTERFACE (CCSGSettingsBackendInterface, backend))->gsettingsBackendSetExistingProfiles) (backend, value); |
1414 | +} |
1415 | + |
1416 | +void |
1417 | +ccsGSettingsBackendSetCurrentProfile (CCSBackend *backend, const gchar *value) |
1418 | +{ |
1419 | + (*(GET_INTERFACE (CCSGSettingsBackendInterface, backend))->gsettingsBackendSetCurrentProfile) (backend, value); |
1420 | +} |
1421 | + |
1422 | +GVariant * |
1423 | +ccsGSettingsBackendGetPluginsWithSetKeys (CCSBackend *backend) |
1424 | +{ |
1425 | + return (*(GET_INTERFACE (CCSGSettingsBackendInterface, backend))->gsettingsBackendGetPluginsWithSetKeys) (backend); |
1426 | +} |
1427 | + |
1428 | +void |
1429 | +ccsGSettingsBackendClearPluginsWithSetKeys (CCSBackend *backend) |
1430 | +{ |
1431 | + (*(GET_INTERFACE (CCSGSettingsBackendInterface, backend))->gsettingsBackendClearPluginsWithSetKeys) (backend); |
1432 | +} |
1433 | + |
1434 | +void |
1435 | +ccsGSettingsBackendUnsetAllChangedPluginKeysInProfile (CCSBackend *backend, |
1436 | + CCSContext *context, |
1437 | + GVariant *pluginKeys, |
1438 | + const char *profile) |
1439 | +{ |
1440 | + (*(GET_INTERFACE (CCSGSettingsBackendInterface, backend))->gsettingsBackendUnsetAllChangedPluginKeysInProfile) (backend, context, pluginKeys, profile); |
1441 | +} |
1442 | + |
1443 | +gboolean |
1444 | +ccsGSettingsBackendUpdateProfile (CCSBackend *backend, CCSContext *context) |
1445 | +{ |
1446 | + return (*(GET_INTERFACE (CCSGSettingsBackendInterface, backend))->gsettingsBackendUpdateProfile) (backend, context); |
1447 | +} |
1448 | + |
1449 | +void |
1450 | +ccsGSettingsBackendUpdateCurrentProfileName (CCSBackend *backend, const char *profile) |
1451 | +{ |
1452 | + (*(GET_INTERFACE (CCSGSettingsBackendInterface, backend))->gsettingsBackendUpdateCurrentProfileName) (backend, profile); |
1453 | +} |
1454 | + |
1455 | +void |
1456 | +ccsGSettingsBackendAddProfile (CCSBackend *backend, const char *profile) |
1457 | +{ |
1458 | + (*(GET_INTERFACE (CCSGSettingsBackendInterface, backend))->gsettingsBackendAddProfile) (backend, profile); |
1459 | +} |
1460 | + |
1461 | +CCSContext * |
1462 | +ccsGSettingsBackendGetContext (CCSBackend *backend); |
1463 | |
1464 | === modified file 'compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h' |
1465 | --- compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h 2012-07-10 10:14:00 +0000 |
1466 | +++ compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h 2012-08-07 01:05:15 +0000 |
1467 | @@ -1,9 +1,67 @@ |
1468 | #ifndef _COMPIZ_GSETTINGS_UTIL_H |
1469 | #define _COMPIZ_GSETTINGS_UTIL_H |
1470 | |
1471 | +#include <ccs.h> |
1472 | +#include <ccs-backend.h> |
1473 | + |
1474 | +COMPIZCONFIG_BEGIN_DECLS |
1475 | + |
1476 | #include <glib.h> |
1477 | #include <glib-object.h> |
1478 | -#include <ccs.h> |
1479 | +#include <gio/gio.h> |
1480 | + |
1481 | +#include "ccs_gsettings_interface.h" |
1482 | + |
1483 | +typedef struct _CCSGSettingsBackendPrivate CCSGSettingsBackendPrivate; |
1484 | +typedef struct _CCSGSettingsBackendInterface CCSGSettingsBackendInterface; |
1485 | + |
1486 | +extern const CCSBackendInfo gsettingsBackendInfo; |
1487 | + |
1488 | +typedef CCSContext * (*CCSGSettingsBackendGetContext) (CCSBackend *); |
1489 | +typedef void (*CCSGSettingsBackendConnectToChangedSignal) (CCSBackend *, CCSGSettingsWrapper *); |
1490 | +typedef CCSGSettingsWrapper * (*CCSGSettingsBackendGetSettingsObjectForPluginWithPath) (CCSBackend *backend, |
1491 | + const char *plugin, |
1492 | + const char *path, |
1493 | + CCSContext *context); |
1494 | +typedef void (*CCSGSettingsBackendRegisterGConfClient) (CCSBackend *backend); |
1495 | +typedef void (*CCSGSettingsBackendUnregisterGConfClient) (CCSBackend *backend); |
1496 | + |
1497 | +typedef const char * (*CCSGSettingsBackendGetCurrentProfile) (CCSBackend *backend); |
1498 | + |
1499 | +typedef GVariant * (*CCSGSettingsBackendGetExistingProfiles) (CCSBackend *backend); |
1500 | +typedef void (*CCSGSettingsBackendSetExistingProfiles) (CCSBackend *backend, GVariant *value); |
1501 | +typedef void (*CCSGSettingsBackendSetCurrentProfile) (CCSBackend *backend, const gchar *value); |
1502 | + |
1503 | +typedef GVariant * (*CCSGSettingsBackendGetPluginsWithSetKeys) (CCSBackend *backend); |
1504 | +typedef void (*CCSGSettingsBackendClearPluginsWithSetKeys) (CCSBackend *backend); |
1505 | + |
1506 | +typedef void (*CCSGSettingsBackendUnsetAllChangedPluginKeysInProfile) (CCSBackend *backend, CCSContext *, GVariant *, const char *); |
1507 | + |
1508 | +typedef gboolean (*CCSGSettingsBackendUpdateProfile) (CCSBackend *, CCSContext *); |
1509 | +typedef void (*CCSGSettingsBackendUpdateCurrentProfileName) (CCSBackend *backend, const char *profile); |
1510 | + |
1511 | +typedef gboolean (*CCSGSettingsBackendAddProfile) (CCSBackend *backend, const char *profile); |
1512 | + |
1513 | +struct _CCSGSettingsBackendInterface |
1514 | +{ |
1515 | + CCSGSettingsBackendGetContext gsettingsBackendGetContext; |
1516 | + CCSGSettingsBackendConnectToChangedSignal gsettingsBackendConnectToChangedSignal; |
1517 | + CCSGSettingsBackendGetSettingsObjectForPluginWithPath gsettingsBackendGetSettingsObjectForPluginWithPath; |
1518 | + CCSGSettingsBackendRegisterGConfClient gsettingsBackendRegisterGConfClient; |
1519 | + CCSGSettingsBackendUnregisterGConfClient gsettingsBackendUnregisterGConfClient; |
1520 | + CCSGSettingsBackendGetCurrentProfile gsettingsBackendGetCurrentProfile; |
1521 | + CCSGSettingsBackendGetExistingProfiles gsettingsBackendGetExistingProfiles; |
1522 | + CCSGSettingsBackendSetExistingProfiles gsettingsBackendSetExistingProfiles; |
1523 | + CCSGSettingsBackendSetCurrentProfile gsettingsBackendSetCurrentProfile; |
1524 | + CCSGSettingsBackendGetPluginsWithSetKeys gsettingsBackendGetPluginsWithSetKeys; |
1525 | + CCSGSettingsBackendClearPluginsWithSetKeys gsettingsBackendClearPluginsWithSetKeys; |
1526 | + CCSGSettingsBackendUnsetAllChangedPluginKeysInProfile gsettingsBackendUnsetAllChangedPluginKeysInProfile; |
1527 | + CCSGSettingsBackendUpdateProfile gsettingsBackendUpdateProfile; |
1528 | + CCSGSettingsBackendUpdateCurrentProfileName gsettingsBackendUpdateCurrentProfileName; |
1529 | + CCSGSettingsBackendAddProfile gsettingsBackendAddProfile; |
1530 | +}; |
1531 | + |
1532 | +unsigned int ccsCCSGSettingsBackendInterfaceGetType (); |
1533 | |
1534 | gchar * |
1535 | getSchemaNameForPlugin (const char *plugin); |
1536 | @@ -41,9 +99,9 @@ |
1537 | char ***newWrittenPlugins, |
1538 | gsize *newWrittenPluginsSize); |
1539 | |
1540 | -GObject * |
1541 | -findObjectInListWithPropertySchemaName (const gchar *schemaName, |
1542 | - GList *iter); |
1543 | +CCSGSettingsWrapper * |
1544 | +findCCSGSettingsWrapperBySchemaName (const gchar *schemaName, |
1545 | + GList *iter); |
1546 | |
1547 | CCSSettingList |
1548 | filterAllSettingsMatchingType (CCSSettingType type, |
1549 | @@ -56,6 +114,20 @@ |
1550 | CCSSetting * |
1551 | attemptToFindCCSSettingFromLossyName (CCSSettingList settingList, const gchar *lossyName, CCSSettingType type); |
1552 | |
1553 | +Bool |
1554 | +findSettingAndPluginToUpdateFromPath (CCSGSettingsWrapper *settings, |
1555 | + const char *path, |
1556 | + const gchar *keyName, |
1557 | + CCSContext *context, |
1558 | + CCSPlugin **plugin, |
1559 | + CCSSetting **setting, |
1560 | + char **uncleanKeyName); |
1561 | + |
1562 | +Bool updateSettingWithGSettingsKeyName (CCSBackend *backend, |
1563 | + CCSGSettingsWrapper *settings, |
1564 | + const gchar *keyName, |
1565 | + CCSBackendUpdateFunc updateSetting); |
1566 | + |
1567 | GList * |
1568 | variantTypeToPossibleSettingType (const gchar *vt); |
1569 | |
1570 | @@ -65,4 +137,170 @@ |
1571 | gchar * |
1572 | makeCompizPluginPath (const gchar *profileName, const gchar *pluginName); |
1573 | |
1574 | +gchar * |
1575 | +getNameForCCSSetting (CCSSetting *setting); |
1576 | + |
1577 | +Bool |
1578 | +checkReadVariantIsValid (GVariant *gsettingsValue, CCSSettingType type, const gchar *pathName); |
1579 | + |
1580 | +GVariant * |
1581 | +getVariantAtKey (CCSGSettingsWrapper *settings, const char *key, const char *pathName, CCSSettingType type); |
1582 | + |
1583 | +const char * readStringFromVariant (GVariant *gsettingsValue); |
1584 | + |
1585 | +int readIntFromVariant (GVariant *gsettingsValue); |
1586 | + |
1587 | +Bool readBoolFromVariant (GVariant *gsettingsValue); |
1588 | + |
1589 | +float readFloatFromVariant (GVariant *gsettingsValue); |
1590 | + |
1591 | +CCSSettingColorValue readColorFromVariant (GVariant *gsettingsValue, Bool *success); |
1592 | + |
1593 | +CCSSettingKeyValue readKeyFromVariant (GVariant *gsettingsValue, Bool *success); |
1594 | + |
1595 | +CCSSettingButtonValue readButtonFromVariant (GVariant *gsettingsValue, Bool *success); |
1596 | + |
1597 | +unsigned int readEdgeFromVariant (GVariant *gsettingsValue); |
1598 | + |
1599 | +CCSSettingValueList |
1600 | +readListValue (GVariant *gsettingsValue, CCSSetting *setting, CCSObjectAllocationInterface *allocator); |
1601 | + |
1602 | +Bool |
1603 | +writeListValue (CCSSettingValueList list, |
1604 | + CCSSettingType listType, |
1605 | + GVariant **gsettingsValue); |
1606 | + |
1607 | +Bool writeStringToVariant (const char *value, GVariant **variant); |
1608 | + |
1609 | +Bool writeFloatToVariant (float value, GVariant **variant); |
1610 | + |
1611 | +Bool writeIntToVariant (int value, GVariant **variant); |
1612 | + |
1613 | +Bool writeBoolToVariant (Bool value, GVariant **variant); |
1614 | + |
1615 | +Bool writeColorToVariant (CCSSettingColorValue value, GVariant **variant); |
1616 | + |
1617 | +Bool writeKeyToVariant (CCSSettingKeyValue key, GVariant **variant); |
1618 | + |
1619 | +Bool writeButtonToVariant (CCSSettingButtonValue button, GVariant **variant); |
1620 | + |
1621 | +Bool writeEdgeToVariant (unsigned int edges, GVariant **variant); |
1622 | + |
1623 | +void writeVariantToKey (CCSGSettingsWrapper *settings, |
1624 | + const char *key, |
1625 | + GVariant *value); |
1626 | + |
1627 | +typedef int (*ComparisonPredicate) (const void *s1, const void *s2); |
1628 | + |
1629 | +int voidcmp0 (const void *v1, const void *v2); |
1630 | + |
1631 | +gboolean |
1632 | +deleteProfile (CCSBackend *backend, |
1633 | + CCSContext *context, |
1634 | + const char *profile); |
1635 | + |
1636 | +gboolean |
1637 | +appendStringToVariantIfUnique (GVariant **variant, |
1638 | + const char *string); |
1639 | + |
1640 | +void |
1641 | +removeItemFromVariant (GVariant **variant, |
1642 | + const char *string); |
1643 | + |
1644 | +CCSSettingValueList |
1645 | +readBoolListValue (GVariantIter *iter, guint nItems, CCSSetting *setting, CCSObjectAllocationInterface *allocator); |
1646 | + |
1647 | +CCSSettingValueList |
1648 | +readIntListValue (GVariantIter *iter, guint nItems, CCSSetting *setting, CCSObjectAllocationInterface *allocator); |
1649 | + |
1650 | +CCSSettingValueList |
1651 | +readFloatListValue (GVariantIter *iter, guint nItems, CCSSetting *setting, CCSObjectAllocationInterface *allocator); |
1652 | + |
1653 | +CCSSettingValueList |
1654 | +readStringListValue (GVariantIter *iter, guint nItems, CCSSetting *setting, CCSObjectAllocationInterface *allocator); |
1655 | + |
1656 | +CCSSettingValueList |
1657 | +readColorListValue (GVariantIter *iter, guint nItems, CCSSetting *setting, CCSObjectAllocationInterface *allocator); |
1658 | + |
1659 | +gchar * |
1660 | +makeSettingPath (const char *currentProfile, CCSSetting *setting); |
1661 | + |
1662 | +CCSGSettingsWrapper * |
1663 | +getSettingsObjectForCCSSetting (CCSBackend *backend, CCSSetting *setting); |
1664 | + |
1665 | +void |
1666 | +resetOptionToDefault (CCSBackend *backend, CCSSetting * setting); |
1667 | + |
1668 | +gboolean |
1669 | +ccsGSettingsBackendUpdateProfile (CCSBackend *backend, CCSContext *context); |
1670 | + |
1671 | +void |
1672 | +ccsGSettingsBackendUpdateCurrentProfileName (CCSBackend *backend, const char *profile); |
1673 | + |
1674 | +CCSContext * |
1675 | +ccsGSettingsBackendGetContext (CCSBackend *backend); |
1676 | + |
1677 | +void |
1678 | +ccsGSettingsBackendConnectToChangedSignal (CCSBackend *backend, CCSGSettingsWrapper *object); |
1679 | + |
1680 | +CCSGSettingsWrapper * |
1681 | +ccsGSettingsGetSettingsObjectForPluginWithPath (CCSBackend *backend, |
1682 | + const char *plugin, |
1683 | + const char *path, |
1684 | + CCSContext *context); |
1685 | + |
1686 | +void |
1687 | +ccsGSettingsBackendRegisterGConfClient (CCSBackend *backend); |
1688 | + |
1689 | +void |
1690 | +ccsGSettingsBackendUnregisterGConfClient (CCSBackend *backend); |
1691 | + |
1692 | +const char * |
1693 | +ccsGSettingsBackendGetCurrentProfile (CCSBackend *backend); |
1694 | + |
1695 | +GVariant * |
1696 | +ccsGSettingsBackendGetExistingProfiles (CCSBackend *backend); |
1697 | + |
1698 | +void |
1699 | +ccsGSettingsBackendSetExistingProfiles (CCSBackend *backend, GVariant *value); |
1700 | + |
1701 | +void |
1702 | +ccsGSettingsBackendSetCurrentProfile (CCSBackend *backend, const gchar *value); |
1703 | + |
1704 | +GVariant * |
1705 | +ccsGSettingsBackendGetPluginsWithSetKeys (CCSBackend *backend); |
1706 | + |
1707 | +void |
1708 | +ccsGSettingsBackendClearPluginsWithSetKeys (CCSBackend *backend); |
1709 | + |
1710 | +void |
1711 | +ccsGSettingsBackendUnsetAllChangedPluginKeysInProfile (CCSBackend *backend, |
1712 | + CCSContext *context, |
1713 | + GVariant *pluginKeys, |
1714 | + const char *profile); |
1715 | + |
1716 | +void |
1717 | +ccsGSettingsBackendAddProfile (CCSBackend *backend, |
1718 | + const char *profile); |
1719 | + |
1720 | +/* Default implementations, should be moved */ |
1721 | + |
1722 | +void |
1723 | +ccsGSettingsBackendUpdateCurrentProfileNameDefault (CCSBackend *backend, const char *profile); |
1724 | + |
1725 | +gboolean |
1726 | +ccsGSettingsBackendUpdateProfileDefault (CCSBackend *backend, CCSContext *context); |
1727 | + |
1728 | +void |
1729 | +ccsGSettingsBackendUnsetAllChangedPluginKeysInProfileDefault (CCSBackend *backend, |
1730 | + CCSContext *context, |
1731 | + GVariant *pluginsWithChangedKeys, |
1732 | + const char * profile); |
1733 | + |
1734 | +gboolean ccsGSettingsBackendAddProfileDefault (CCSBackend *backend, |
1735 | + const char *profile); |
1736 | + |
1737 | + |
1738 | +COMPIZCONFIG_END_DECLS |
1739 | + |
1740 | #endif |
1741 | |
1742 | === modified file 'compizconfig/gsettings/src/gconf-integration.c' |
1743 | --- compizconfig/gsettings/src/gconf-integration.c 2012-08-07 01:05:13 +0000 |
1744 | +++ compizconfig/gsettings/src/gconf-integration.c 2012-08-07 01:05:15 +0000 |
1745 | @@ -33,8 +33,6 @@ |
1746 | |
1747 | #include "gsettings.h" |
1748 | #ifdef USE_GCONF |
1749 | -GConfClient *client = NULL; |
1750 | -guint gnomeGConfNotifyIds[NUM_WATCHED_DIRS]; |
1751 | |
1752 | const SpecialOptionGConf specialOptions[] = { |
1753 | {"run_key", "gnomecompat", FALSE, |
1754 | @@ -456,45 +454,48 @@ |
1755 | } |
1756 | |
1757 | void |
1758 | -initGConfClient (CCSContext *context) |
1759 | +initGConfClient (CCSBackend *backend) |
1760 | { |
1761 | int i; |
1762 | |
1763 | - client = gconf_client_get_default (); |
1764 | + CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); |
1765 | + priv->client = gconf_client_get_default (); |
1766 | |
1767 | for (i = 0; i < NUM_WATCHED_DIRS; i++) |
1768 | { |
1769 | - gnomeGConfNotifyIds[i] = gconf_client_notify_add (client, |
1770 | - watchedGConfGnomeDirectories[i], |
1771 | - gnomeGConfValueChanged, context, |
1772 | - NULL, NULL); |
1773 | - gconf_client_add_dir (client, watchedGConfGnomeDirectories[i], |
1774 | + priv->gnomeGConfNotifyIds[i] = gconf_client_notify_add (priv->client, |
1775 | + watchedGConfGnomeDirectories[i], |
1776 | + gnomeGConfValueChanged, priv->context, |
1777 | + NULL, NULL); |
1778 | + gconf_client_add_dir (priv->client, watchedGConfGnomeDirectories[i], |
1779 | GCONF_CLIENT_PRELOAD_NONE, NULL); |
1780 | } |
1781 | } |
1782 | |
1783 | void |
1784 | -finiGConfClient (void) |
1785 | +finiGConfClient (CCSBackend *backend) |
1786 | { |
1787 | int i; |
1788 | |
1789 | + CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); |
1790 | + |
1791 | for (i = 0; i < NUM_WATCHED_DIRS; i++) |
1792 | { |
1793 | - if (gnomeGConfNotifyIds[i]) |
1794 | + if (priv->gnomeGConfNotifyIds[i]) |
1795 | { |
1796 | - gconf_client_notify_remove (client, gnomeGConfNotifyIds[0]); |
1797 | - gnomeGConfNotifyIds[i] = 0; |
1798 | + gconf_client_notify_remove (priv->client, priv->gnomeGConfNotifyIds[0]); |
1799 | + priv->gnomeGConfNotifyIds[i] = 0; |
1800 | } |
1801 | - gconf_client_remove_dir (client, watchedGConfGnomeDirectories[i], NULL); |
1802 | + gconf_client_remove_dir (priv->client, watchedGConfGnomeDirectories[i], NULL); |
1803 | } |
1804 | - gconf_client_suggest_sync (client, NULL); |
1805 | + gconf_client_suggest_sync (priv->client, NULL); |
1806 | |
1807 | - g_object_unref (client); |
1808 | - client = NULL; |
1809 | + g_object_unref (priv->client); |
1810 | + priv->client = NULL; |
1811 | } |
1812 | |
1813 | static unsigned int |
1814 | -getGnomeMouseButtonModifier(void) |
1815 | +getGnomeMouseButtonModifier(GConfClient *client) |
1816 | { |
1817 | unsigned int modMask = 0; |
1818 | GError *err = NULL; |
1819 | @@ -537,17 +538,23 @@ |
1820 | } |
1821 | |
1822 | Bool |
1823 | -readGConfIntegratedOption (CCSContext *context, |
1824 | +readGConfIntegratedOption (CCSBackend *backend, |
1825 | + CCSContext *context, |
1826 | CCSSetting *setting, |
1827 | int index) |
1828 | { |
1829 | GConfValue *gconfValue; |
1830 | GError *err = NULL; |
1831 | Bool ret = FALSE; |
1832 | + |
1833 | + CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); |
1834 | |
1835 | - ret = readOption (setting); |
1836 | - |
1837 | - gconfValue = gconf_client_get (client, |
1838 | + if (!priv->client) |
1839 | + ccsGSettingsBackendRegisterGConfClient (backend); |
1840 | + |
1841 | + ret = readOption (backend, setting); |
1842 | + |
1843 | + gconfValue = gconf_client_get (priv->client, |
1844 | specialOptions[index].gnomeName, |
1845 | &err); |
1846 | |
1847 | @@ -675,10 +682,10 @@ |
1848 | memset (&button, 0, sizeof (CCSSettingButtonValue)); |
1849 | ccsGetButton (setting, &button); |
1850 | |
1851 | - button.buttonModMask = getGnomeMouseButtonModifier (); |
1852 | + button.buttonModMask = getGnomeMouseButtonModifier (priv->client); |
1853 | |
1854 | resizeWithRightButton = |
1855 | - gconf_client_get_bool (client, METACITY |
1856 | + gconf_client_get_bool (priv->client, METACITY |
1857 | "/general/resize_with_right_button", |
1858 | &err); |
1859 | |
1860 | @@ -704,7 +711,7 @@ |
1861 | } |
1862 | |
1863 | static Bool |
1864 | -setGnomeMouseButtonModifier (unsigned int modMask) |
1865 | +setGnomeMouseButtonModifier (GConfClient *client, unsigned int modMask) |
1866 | { |
1867 | char *modifiers, *currentValue; |
1868 | GError *err = NULL; |
1869 | @@ -765,13 +772,19 @@ |
1870 | } |
1871 | |
1872 | void |
1873 | -writeGConfIntegratedOption (CCSContext *context, |
1874 | +writeGConfIntegratedOption (CCSBackend *backend, |
1875 | + CCSContext *context, |
1876 | CCSSetting *setting, |
1877 | int index) |
1878 | { |
1879 | GError *err = NULL; |
1880 | const char *optionName = specialOptions[index].gnomeName; |
1881 | |
1882 | + CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); |
1883 | + |
1884 | + if (!priv->client) |
1885 | + ccsGSettingsBackendRegisterGConfClient (backend); |
1886 | + |
1887 | switch (specialOptions[index].type) |
1888 | { |
1889 | case OptionInt: |
1890 | @@ -779,10 +792,10 @@ |
1891 | int newValue, currentValue; |
1892 | if (!ccsGetInt (setting, &newValue)) |
1893 | break; |
1894 | - currentValue = gconf_client_get_int (client, optionName, &err); |
1895 | + currentValue = gconf_client_get_int (priv->client, optionName, &err); |
1896 | |
1897 | if (!err && (currentValue != newValue)) |
1898 | - gconf_client_set_int(client, specialOptions[index].gnomeName, |
1899 | + gconf_client_set_int(priv->client, specialOptions[index].gnomeName, |
1900 | newValue, NULL); |
1901 | } |
1902 | break; |
1903 | @@ -792,11 +805,11 @@ |
1904 | gboolean currentValue; |
1905 | if (!ccsGetBool (setting, &newValue)) |
1906 | break; |
1907 | - currentValue = gconf_client_get_bool (client, optionName, &err); |
1908 | + currentValue = gconf_client_get_bool (priv->client, optionName, &err); |
1909 | |
1910 | if (!err && ((currentValue && !newValue) || |
1911 | (!currentValue && newValue))) |
1912 | - gconf_client_set_bool (client, specialOptions[index].gnomeName, |
1913 | + gconf_client_set_bool (priv->client, specialOptions[index].gnomeName, |
1914 | newValue, NULL); |
1915 | } |
1916 | break; |
1917 | @@ -806,12 +819,12 @@ |
1918 | gchar *currentValue; |
1919 | if (!ccsGetString (setting, &newValue)) |
1920 | break; |
1921 | - currentValue = gconf_client_get_string (client, optionName, &err); |
1922 | + currentValue = gconf_client_get_string (priv->client, optionName, &err); |
1923 | |
1924 | if (!err && currentValue) |
1925 | { |
1926 | if (strcmp (currentValue, newValue) != 0) |
1927 | - gconf_client_set_string (client, optionName, |
1928 | + gconf_client_set_string (priv->client, optionName, |
1929 | newValue, NULL); |
1930 | g_free (currentValue); |
1931 | } |
1932 | @@ -831,13 +844,13 @@ |
1933 | newValue[0] = 'd'; |
1934 | } |
1935 | |
1936 | - currentValue = gconf_client_get_string (client, |
1937 | + currentValue = gconf_client_get_string (priv->client, |
1938 | optionName, &err); |
1939 | |
1940 | if (!err && currentValue) |
1941 | { |
1942 | if (strcmp (currentValue, newValue) != 0) |
1943 | - gconf_client_set_string (client, optionName, |
1944 | + gconf_client_set_string (priv->client, optionName, |
1945 | newValue, NULL); |
1946 | g_free (currentValue); |
1947 | } |
1948 | @@ -857,7 +870,7 @@ |
1949 | if (!ccsGetBool (setting, ¤tViewport)) |
1950 | break; |
1951 | |
1952 | - gconf_client_set_bool (client, optionName, |
1953 | + gconf_client_set_bool (priv->client, optionName, |
1954 | !currentViewport, NULL); |
1955 | } |
1956 | else if (strcmp (settingName, "fullscreen_visual_bell") == 0) |
1957 | @@ -868,12 +881,12 @@ |
1958 | break; |
1959 | |
1960 | newValue = fullscreen ? "fullscreen" : "frame_flash"; |
1961 | - currentValue = gconf_client_get_string (client, |
1962 | + currentValue = gconf_client_get_string (priv->client, |
1963 | optionName, &err); |
1964 | if (!err && currentValue) |
1965 | { |
1966 | if (strcmp (currentValue, newValue) != 0) |
1967 | - gconf_client_set_string (client, optionName, |
1968 | + gconf_client_set_string (priv->client, optionName, |
1969 | newValue, NULL); |
1970 | g_free (currentValue); |
1971 | } |
1972 | @@ -886,13 +899,13 @@ |
1973 | break; |
1974 | |
1975 | newValue = clickToFocus ? "click" : "sloppy"; |
1976 | - currentValue = gconf_client_get_string (client, |
1977 | + currentValue = gconf_client_get_string (priv->client, |
1978 | optionName, &err); |
1979 | |
1980 | if (!err && currentValue) |
1981 | { |
1982 | if (strcmp (currentValue, newValue) != 0) |
1983 | - gconf_client_set_string (client, optionName, |
1984 | + gconf_client_set_string (priv->client, optionName, |
1985 | newValue, NULL); |
1986 | g_free (currentValue); |
1987 | } |
1988 | @@ -916,21 +929,21 @@ |
1989 | } |
1990 | |
1991 | currentValue = |
1992 | - gconf_client_get_bool (client, METACITY |
1993 | + gconf_client_get_bool (priv->client, METACITY |
1994 | "/general/resize_with_right_button", |
1995 | &err); |
1996 | |
1997 | if (!err && ((currentValue && !resizeWithRightButton) || |
1998 | (!currentValue && resizeWithRightButton))) |
1999 | { |
2000 | - gconf_client_set_bool (client, |
2001 | + gconf_client_set_bool (priv->client, |
2002 | METACITY |
2003 | "/general/resize_with_right_button", |
2004 | resizeWithRightButton, NULL); |
2005 | } |
2006 | |
2007 | modMask = ccsSettingGetValue (setting)->value.asButton.buttonModMask; |
2008 | - if (setGnomeMouseButtonModifier (modMask)) |
2009 | + if (setGnomeMouseButtonModifier (priv->client, modMask)) |
2010 | { |
2011 | setButtonBindingForSetting (context, "move", |
2012 | "initiate_button", 1, modMask); |
2013 | |
2014 | === modified file 'compizconfig/gsettings/src/gsettings.c' |
2015 | --- compizconfig/gsettings/src/gsettings.c 2012-08-07 01:05:13 +0000 |
2016 | +++ compizconfig/gsettings/src/gsettings.c 2012-08-07 01:05:15 +0000 |
2017 | @@ -34,35 +34,34 @@ |
2018 | #define CCS_LOG_DOMAIN "gsettings" |
2019 | |
2020 | #include "gsettings.h" |
2021 | +#include <ccs_gsettings_interface_wrapper.h> |
2022 | |
2023 | static void |
2024 | valueChanged (GSettings *settings, |
2025 | gchar *keyname, |
2026 | gpointer user_data); |
2027 | |
2028 | -static GList *settingsList = NULL; |
2029 | -static GSettings *compizconfigSettings = NULL; |
2030 | -static GSettings *currentProfileSettings = NULL; |
2031 | - |
2032 | -char *currentProfile = NULL; |
2033 | - |
2034 | /* some forward declarations */ |
2035 | -static void writeIntegratedOption (CCSContext *context, |
2036 | +static void writeIntegratedOption (CCSBackend *backend, |
2037 | + CCSContext *context, |
2038 | CCSSetting *setting, |
2039 | int index); |
2040 | |
2041 | -static GSettings * |
2042 | -getSettingsObjectForPluginWithPath (const char *plugin, |
2043 | - const char *path, |
2044 | - CCSContext *context) |
2045 | +static CCSGSettingsWrapper * |
2046 | +ccsGSettingsBackendGetSettingsObjectForPluginWithPathDefault (CCSBackend *backend, |
2047 | + const char *plugin, |
2048 | + const char *path, |
2049 | + CCSContext *context) |
2050 | { |
2051 | - GSettings *settingsObj = NULL; |
2052 | + CCSGSettingsWrapper *settingsObj = NULL; |
2053 | gchar *schemaName = getSchemaNameForPlugin (plugin); |
2054 | GVariant *writtenPlugins; |
2055 | gsize newWrittenPluginsSize; |
2056 | gchar **newWrittenPlugins; |
2057 | |
2058 | - settingsObj = (GSettings *) findObjectInListWithPropertySchemaName (schemaName, settingsList); |
2059 | + CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); |
2060 | + |
2061 | + settingsObj = findCCSGSettingsWrapperBySchemaName (schemaName, priv->settingsList); |
2062 | |
2063 | if (settingsObj) |
2064 | { |
2065 | @@ -72,11 +71,9 @@ |
2066 | |
2067 | /* No existing settings object found for this schema, create one */ |
2068 | |
2069 | - settingsObj = g_settings_new_with_path (schemaName, path); |
2070 | - |
2071 | - g_signal_connect (G_OBJECT (settingsObj), "changed", (GCallback) valueChanged, (gpointer) context); |
2072 | - |
2073 | - settingsList = g_list_append (settingsList, (void *) settingsObj); |
2074 | + settingsObj = ccsGSettingsWrapperNewForSchemaWithPath (schemaName, path, &ccsDefaultObjectAllocator); |
2075 | + ccsGSettingsBackendConnectToChangedSignal (backend, settingsObj); |
2076 | + priv->settingsList = g_list_append (priv->settingsList, (void *) settingsObj); |
2077 | |
2078 | /* Also write the plugin name to the list of modified plugins so |
2079 | * that when we delete the profile the keys for that profile are also |
2080 | @@ -84,38 +81,22 @@ |
2081 | * store keys that have changed from their defaults ... though |
2082 | * gsettings doesn't seem to give you a way to get all of the schemas */ |
2083 | |
2084 | - writtenPlugins = g_settings_get_value (currentProfileSettings, "plugins-with-set-keys"); |
2085 | + writtenPlugins = ccsGSettingsWrapperGetValue (priv->currentProfileSettings, "plugins-with-set-keys"); |
2086 | |
2087 | appendToPluginsWithSetKeysList (plugin, writtenPlugins, &newWrittenPlugins, &newWrittenPluginsSize); |
2088 | |
2089 | - g_settings_set_strv (currentProfileSettings, "plugins-with-set-keys", (const gchar * const *)newWrittenPlugins); |
2090 | - |
2091 | + GVariant *newWrittenPluginsVariant = g_variant_new_strv ((const gchar * const *) newWrittenPlugins, newWrittenPluginsSize); |
2092 | + |
2093 | + ccsGSettingsWrapperSetValue (priv->currentProfileSettings, "plugins-with-set-keys", newWrittenPluginsVariant); |
2094 | + |
2095 | + g_variant_unref (writtenPlugins); |
2096 | g_free (schemaName); |
2097 | g_strfreev (newWrittenPlugins); |
2098 | |
2099 | return settingsObj; |
2100 | } |
2101 | |
2102 | -static gchar * |
2103 | -makeSettingPath (CCSSetting *setting) |
2104 | -{ |
2105 | - return makeCompizPluginPath (currentProfile, |
2106 | - ccsPluginGetName (ccsSettingGetParent (setting))); |
2107 | -} |
2108 | - |
2109 | -static GSettings * |
2110 | -getSettingsObjectForCCSSetting (CCSSetting *setting) |
2111 | -{ |
2112 | - GSettings *ret = NULL; |
2113 | - gchar *pathName = makeSettingPath (setting); |
2114 | - |
2115 | - ret = getSettingsObjectForPluginWithPath (ccsPluginGetName (ccsSettingGetParent (setting)), |
2116 | - pathName, |
2117 | - ccsPluginGetContext (ccsSettingGetParent (setting))); |
2118 | - |
2119 | - g_free (pathName); |
2120 | - return ret; |
2121 | -} |
2122 | + |
2123 | |
2124 | static Bool |
2125 | isIntegratedOption (CCSSetting *setting, |
2126 | @@ -134,7 +115,7 @@ |
2127 | int index; |
2128 | |
2129 | readInit (backend, context); |
2130 | - if (!readOption (setting)) |
2131 | + if (!readOption (backend, setting)) |
2132 | { |
2133 | ccsResetToDefault (setting, TRUE); |
2134 | } |
2135 | @@ -143,7 +124,7 @@ |
2136 | isIntegratedOption (setting, &index)) |
2137 | { |
2138 | writeInit (backend, context); |
2139 | - writeIntegratedOption (context, setting, index); |
2140 | + writeIntegratedOption (backend, context, setting, index); |
2141 | } |
2142 | } |
2143 | |
2144 | @@ -152,230 +133,57 @@ |
2145 | gchar *keyName, |
2146 | gpointer user_data) |
2147 | { |
2148 | - CCSContext *context = (CCSContext *)user_data; |
2149 | - char *uncleanKeyName; |
2150 | - char *path, *pathOrig; |
2151 | - char *pluginName; |
2152 | - unsigned int screenNum; |
2153 | - CCSPlugin *plugin; |
2154 | - CCSSetting *setting; |
2155 | - |
2156 | - g_object_get (G_OBJECT (settings), "path", &pathOrig, NULL); |
2157 | - |
2158 | - path = pathOrig; |
2159 | - |
2160 | - if (!decomposeGSettingsPath (path, &pluginName, &screenNum)) |
2161 | - { |
2162 | - g_free (pathOrig); |
2163 | - return; |
2164 | - } |
2165 | - |
2166 | - plugin = ccsFindPlugin (context, pluginName); |
2167 | - |
2168 | - uncleanKeyName = translateKeyForCCS (keyName); |
2169 | - |
2170 | - setting = ccsFindSetting (plugin, uncleanKeyName); |
2171 | - if (!setting) |
2172 | - { |
2173 | - /* Couldn't find setting straight off the bat, |
2174 | - * try and find the best match */ |
2175 | - GVariant *value = g_settings_get_value (settings, keyName); |
2176 | - |
2177 | - if (value) |
2178 | - { |
2179 | - GList *possibleSettingTypes = variantTypeToPossibleSettingType (g_variant_get_type_string (value)); |
2180 | - GList *iter = possibleSettingTypes; |
2181 | - |
2182 | - while (iter) |
2183 | - { |
2184 | - setting = attemptToFindCCSSettingFromLossyName (ccsGetPluginSettings (plugin), |
2185 | - keyName, |
2186 | - (CCSSettingType) GPOINTER_TO_INT (iter->data)); |
2187 | - |
2188 | - if (setting) |
2189 | - break; |
2190 | - |
2191 | - iter = iter->next; |
2192 | - } |
2193 | - |
2194 | - g_list_free (possibleSettingTypes); |
2195 | - g_variant_unref (value); |
2196 | - } |
2197 | - |
2198 | - /* We hit a situation where either the key stored in GSettings couldn't be |
2199 | - * matched at all to a key in the xml file, or where there were multiple matches. |
2200 | - * Unfortunately, there isn't much we can do about this, other than try |
2201 | - * and warn the user and bail out. It just means that if the key was updated |
2202 | - * externally we won't know about the change until the next reload of settings */ |
2203 | - if (!setting) |
2204 | - { |
2205 | - ccsWarning ("Unable to find setting %s, for path %s", uncleanKeyName, path); |
2206 | - g_free (pluginName); |
2207 | - free (uncleanKeyName); |
2208 | - g_free (pathOrig); |
2209 | - return; |
2210 | - } |
2211 | - } |
2212 | - |
2213 | - updateSetting (NULL, context, plugin, setting); |
2214 | - |
2215 | - g_free (pluginName); |
2216 | - free (uncleanKeyName); |
2217 | - g_free (pathOrig); |
2218 | -} |
2219 | - |
2220 | -static Bool |
2221 | -readListValue (CCSSetting *setting) |
2222 | -{ |
2223 | - GSettings *settings = getSettingsObjectForCCSSetting (setting); |
2224 | - gboolean hasVariantType; |
2225 | - unsigned int nItems, i = 0; |
2226 | - CCSSettingValueList list = NULL; |
2227 | - GVariant *value; |
2228 | - GVariantIter iter; |
2229 | - |
2230 | - char *cleanSettingName = translateKeyForGSettings (ccsSettingGetName (setting)); |
2231 | - |
2232 | - hasVariantType = compizconfigTypeHasVariantType (ccsSettingGetInfo (setting)->forList.listType); |
2233 | - |
2234 | - if (!hasVariantType) |
2235 | - return FALSE; |
2236 | - |
2237 | - value = g_settings_get_value (settings, cleanSettingName); |
2238 | - if (!value) |
2239 | - { |
2240 | - ccsSetList (setting, NULL, TRUE); |
2241 | - return TRUE; |
2242 | - } |
2243 | - |
2244 | - g_variant_iter_init (&iter, value); |
2245 | - nItems = g_variant_iter_n_children (&iter); |
2246 | - |
2247 | - switch (ccsSettingGetInfo (setting)->forList.listType) |
2248 | - { |
2249 | - case TypeBool: |
2250 | - { |
2251 | - Bool *array = malloc (nItems * sizeof (Bool)); |
2252 | - Bool *arrayCounter = array; |
2253 | - gboolean value; |
2254 | - |
2255 | - if (!array) |
2256 | - break; |
2257 | - |
2258 | - /* Reads each item from the variant into arrayCounter */ |
2259 | - while (g_variant_iter_loop (&iter, "b", &value)) |
2260 | - *arrayCounter++ = value; |
2261 | - |
2262 | - list = ccsGetValueListFromBoolArray (array, nItems, setting); |
2263 | - free (array); |
2264 | - } |
2265 | - break; |
2266 | - case TypeInt: |
2267 | - { |
2268 | - int *array = malloc (nItems * sizeof (int)); |
2269 | - int *arrayCounter = array; |
2270 | - gint value; |
2271 | - |
2272 | - if (!array) |
2273 | - break; |
2274 | - |
2275 | - /* Reads each item from the variant into arrayCounter */ |
2276 | - while (g_variant_iter_loop (&iter, "i", &value)) |
2277 | - *arrayCounter++ = value; |
2278 | - |
2279 | - list = ccsGetValueListFromIntArray (array, nItems, setting); |
2280 | - free (array); |
2281 | - } |
2282 | - break; |
2283 | - case TypeFloat: |
2284 | - { |
2285 | - double *array = malloc (nItems * sizeof (double)); |
2286 | - double *arrayCounter = array; |
2287 | - gdouble value; |
2288 | - |
2289 | - if (!array) |
2290 | - break; |
2291 | - |
2292 | - /* Reads each item from the variant into arrayCounter */ |
2293 | - while (g_variant_iter_loop (&iter, "d", &value)) |
2294 | - *arrayCounter++ = value; |
2295 | - |
2296 | - list = ccsGetValueListFromFloatArray ((float *) array, nItems, setting); |
2297 | - free (array); |
2298 | - } |
2299 | - break; |
2300 | - case TypeString: |
2301 | - case TypeMatch: |
2302 | - { |
2303 | - const gchar **array = g_malloc0 ((nItems + 1) * sizeof (gchar *)); |
2304 | - const gchar **arrayCounter = array; |
2305 | - gchar *value; |
2306 | - |
2307 | - if (!array) |
2308 | - break; |
2309 | - |
2310 | - array[nItems] = NULL; |
2311 | - |
2312 | - /* Reads each item from the variant into arrayCounter */ |
2313 | - while (g_variant_iter_next (&iter, "s", &value)) |
2314 | - *arrayCounter++ = value; |
2315 | - |
2316 | - list = ccsGetValueListFromStringArray (array, nItems, setting); |
2317 | - g_strfreev ((char **) array); |
2318 | - } |
2319 | - break; |
2320 | - case TypeColor: |
2321 | - { |
2322 | - CCSSettingColorValue *array; |
2323 | - char *colorValue; |
2324 | - array = malloc (nItems * sizeof (CCSSettingColorValue)); |
2325 | - if (!array) |
2326 | - break; |
2327 | - |
2328 | - while (g_variant_iter_loop (&iter, "s", &colorValue)) |
2329 | - { |
2330 | - memset (&array[i], 0, sizeof (CCSSettingColorValue)); |
2331 | - ccsStringToColor (colorValue, |
2332 | - &array[i]); |
2333 | - } |
2334 | - list = ccsGetValueListFromColorArray (array, nItems, setting); |
2335 | - free (array); |
2336 | - } |
2337 | - break; |
2338 | - default: |
2339 | - break; |
2340 | - } |
2341 | - |
2342 | - free (cleanSettingName); |
2343 | - |
2344 | - if (list) |
2345 | - { |
2346 | - ccsSetList (setting, list, TRUE); |
2347 | - ccsSettingValueListFree (list, TRUE); |
2348 | - return TRUE; |
2349 | - } |
2350 | - |
2351 | - return FALSE; |
2352 | -} |
2353 | - |
2354 | -static Bool |
2355 | -readIntegratedOption (CCSContext *context, |
2356 | + CCSBackend *backend = (CCSBackend *)user_data; |
2357 | + GValue schemaNameValue = G_VALUE_INIT; |
2358 | + CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); |
2359 | + |
2360 | + |
2361 | + g_value_init (&schemaNameValue, G_TYPE_STRING); |
2362 | + g_object_get_property (G_OBJECT (settings), "schema-id", &schemaNameValue); |
2363 | + |
2364 | + const char *schemaName = g_value_get_string (&schemaNameValue); |
2365 | + CCSGSettingsWrapper *wrapper = findCCSGSettingsWrapperBySchemaName (schemaName, priv->settingsList); |
2366 | + |
2367 | + g_value_unset (&schemaNameValue); |
2368 | + |
2369 | + updateSettingWithGSettingsKeyName (backend, wrapper, keyName, updateSetting); |
2370 | +} |
2371 | + |
2372 | +static Bool |
2373 | +readIntegratedOption (CCSBackend *backend, |
2374 | + CCSContext *context, |
2375 | CCSSetting *setting, |
2376 | int index) |
2377 | { |
2378 | #ifdef USE_GCONF |
2379 | - return readGConfIntegratedOption (context, setting, index); |
2380 | + return readGConfIntegratedOption (backend, context, setting, index); |
2381 | #else |
2382 | return FALSE; |
2383 | #endif |
2384 | } |
2385 | |
2386 | +static GVariant * |
2387 | +getVariantForCCSSetting (CCSBackend *backend, CCSSetting *setting) |
2388 | +{ |
2389 | + CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); |
2390 | + CCSGSettingsWrapper *settings = getSettingsObjectForCCSSetting (backend, setting); |
2391 | + char *cleanSettingName = getNameForCCSSetting (setting); |
2392 | + gchar *pathName = makeSettingPath (priv->currentProfile, setting); |
2393 | + GVariant *gsettingsValue = getVariantAtKey (settings, |
2394 | + cleanSettingName, |
2395 | + pathName, |
2396 | + ccsSettingGetType (setting)); |
2397 | + |
2398 | + free (cleanSettingName); |
2399 | + free (pathName); |
2400 | + return gsettingsValue; |
2401 | +} |
2402 | + |
2403 | Bool |
2404 | -readOption (CCSSetting * setting) |
2405 | +readOption (CCSBackend *backend, CCSSetting * setting) |
2406 | { |
2407 | - GSettings *settings = getSettingsObjectForCCSSetting (setting); |
2408 | + Bool ret = FALSE; |
2409 | GVariant *gsettingsValue = NULL; |
2410 | - Bool ret = FALSE; |
2411 | |
2412 | /* It is impossible for certain settings to have a schema, |
2413 | * such as actions and read only settings, so in that case |
2414 | @@ -388,36 +196,14 @@ |
2415 | return FALSE; |
2416 | } |
2417 | |
2418 | - char *cleanSettingName = translateKeyForGSettings (ccsSettingGetName (setting)); |
2419 | - |
2420 | - /* first check if the key is set */ |
2421 | - gsettingsValue = g_settings_get_value (settings, cleanSettingName); |
2422 | - |
2423 | - if (!gsettingsValue) |
2424 | - { |
2425 | - free (cleanSettingName); |
2426 | - return FALSE; |
2427 | - } |
2428 | - |
2429 | - if (!variantIsValidForCCSType (gsettingsValue, ccsSettingGetType (setting))) |
2430 | - { |
2431 | - gchar *pathName = makeSettingPath (setting); |
2432 | - ccsWarning ("There is an unsupported value at path %s. " |
2433 | - "Settings from this path won't be read. Try to remove " |
2434 | - "that value so that operation can continue properly.", |
2435 | - pathName); |
2436 | - g_free (pathName); |
2437 | - free (cleanSettingName); |
2438 | - g_variant_unref (gsettingsValue); |
2439 | - return FALSE; |
2440 | - } |
2441 | + gsettingsValue = getVariantForCCSSetting (backend, setting); |
2442 | |
2443 | switch (ccsSettingGetType (setting)) |
2444 | { |
2445 | case TypeString: |
2446 | { |
2447 | const char *value; |
2448 | - value = g_variant_get_string (gsettingsValue, NULL); |
2449 | + value = readStringFromVariant (gsettingsValue); |
2450 | if (value) |
2451 | { |
2452 | ccsSetString (setting, value, TRUE); |
2453 | @@ -428,7 +214,7 @@ |
2454 | case TypeMatch: |
2455 | { |
2456 | const char * value; |
2457 | - value = g_variant_get_string (gsettingsValue, NULL); |
2458 | + value = readStringFromVariant (gsettingsValue); |
2459 | if (value) |
2460 | { |
2461 | ccsSetMatch (setting, value, TRUE); |
2462 | @@ -439,7 +225,7 @@ |
2463 | case TypeInt: |
2464 | { |
2465 | int value; |
2466 | - value = g_variant_get_int32 (gsettingsValue); |
2467 | + value = readIntFromVariant (gsettingsValue); |
2468 | |
2469 | ccsSetInt (setting, value, TRUE); |
2470 | ret = TRUE; |
2471 | @@ -447,29 +233,28 @@ |
2472 | break; |
2473 | case TypeBool: |
2474 | { |
2475 | - gboolean value; |
2476 | - value = g_variant_get_boolean (gsettingsValue); |
2477 | + Bool value; |
2478 | + value = readBoolFromVariant (gsettingsValue); |
2479 | |
2480 | - ccsSetBool (setting, value ? TRUE : FALSE, TRUE); |
2481 | + ccsSetBool (setting, value, TRUE); |
2482 | ret = TRUE; |
2483 | } |
2484 | break; |
2485 | case TypeFloat: |
2486 | { |
2487 | - double value; |
2488 | - value = g_variant_get_double (gsettingsValue); |
2489 | + float value; |
2490 | + value = readFloatFromVariant (gsettingsValue); |
2491 | |
2492 | - ccsSetFloat (setting, (float)value, TRUE); |
2493 | + ccsSetFloat (setting, value, TRUE); |
2494 | ret = TRUE; |
2495 | } |
2496 | break; |
2497 | case TypeColor: |
2498 | { |
2499 | - const char *value; |
2500 | - CCSSettingColorValue color; |
2501 | - value = g_variant_get_string (gsettingsValue, NULL); |
2502 | + Bool success = FALSE; |
2503 | + CCSSettingColorValue color = readColorFromVariant (gsettingsValue, &success); |
2504 | |
2505 | - if (value && ccsStringToColor (value, &color)) |
2506 | + if (success) |
2507 | { |
2508 | ccsSetColor (setting, color, TRUE); |
2509 | ret = TRUE; |
2510 | @@ -478,11 +263,10 @@ |
2511 | break; |
2512 | case TypeKey: |
2513 | { |
2514 | - const char *value; |
2515 | - CCSSettingKeyValue key; |
2516 | - value = g_variant_get_string (gsettingsValue, NULL); |
2517 | + Bool success = FALSE; |
2518 | + CCSSettingKeyValue key = readKeyFromVariant (gsettingsValue, &success); |
2519 | |
2520 | - if (value && ccsStringToKeyBinding (value, &key)) |
2521 | + if (success) |
2522 | { |
2523 | ccsSetKey (setting, key, TRUE); |
2524 | ret = TRUE; |
2525 | @@ -491,11 +275,10 @@ |
2526 | break; |
2527 | case TypeButton: |
2528 | { |
2529 | - const char *value; |
2530 | - CCSSettingButtonValue button; |
2531 | - value = g_variant_get_string (gsettingsValue, NULL); |
2532 | + Bool success = FALSE; |
2533 | + CCSSettingButtonValue button = readButtonFromVariant (gsettingsValue, &success); |
2534 | |
2535 | - if (value && ccsStringToButtonBinding (value, &button)) |
2536 | + if (success) |
2537 | { |
2538 | ccsSetButton (setting, button, TRUE); |
2539 | ret = TRUE; |
2540 | @@ -504,29 +287,40 @@ |
2541 | break; |
2542 | case TypeEdge: |
2543 | { |
2544 | - const char *value; |
2545 | - value = g_variant_get_string (gsettingsValue, NULL); |
2546 | + unsigned int edges = readEdgeFromVariant (gsettingsValue); |
2547 | |
2548 | - if (value) |
2549 | - { |
2550 | - unsigned int edges; |
2551 | - edges = ccsStringToEdges (value); |
2552 | - ccsSetEdge (setting, edges, TRUE); |
2553 | - ret = TRUE; |
2554 | - } |
2555 | + ccsSetEdge (setting, edges, TRUE); |
2556 | + ret = TRUE; |
2557 | } |
2558 | break; |
2559 | case TypeBell: |
2560 | { |
2561 | - gboolean value; |
2562 | - value = g_variant_get_boolean (gsettingsValue); |
2563 | + Bool value; |
2564 | + value = readBoolFromVariant (gsettingsValue); |
2565 | |
2566 | - ccsSetBell (setting, value ? TRUE : FALSE, TRUE); |
2567 | + ccsSetBell (setting, value, TRUE); |
2568 | ret = TRUE; |
2569 | } |
2570 | break; |
2571 | case TypeList: |
2572 | - ret = readListValue (setting); |
2573 | + { |
2574 | + CCSSettingValueList list = readListValue (gsettingsValue, setting, &ccsDefaultObjectAllocator); |
2575 | + |
2576 | + if (list) |
2577 | + { |
2578 | + CCSSettingValueList iter = list; |
2579 | + |
2580 | + while (iter) |
2581 | + { |
2582 | + ((CCSSettingValue *) iter->data)->parent = setting; |
2583 | + iter = iter->next; |
2584 | + } |
2585 | + |
2586 | + ccsSetList (setting, list, TRUE); |
2587 | + ccsSettingValueListFree (list, TRUE); |
2588 | + ret = TRUE; |
2589 | + } |
2590 | + } |
2591 | break; |
2592 | default: |
2593 | ccsWarning ("Attempt to read unsupported setting type %d!", |
2594 | @@ -534,145 +328,31 @@ |
2595 | break; |
2596 | } |
2597 | |
2598 | - free (cleanSettingName); |
2599 | g_variant_unref (gsettingsValue); |
2600 | |
2601 | return ret; |
2602 | } |
2603 | |
2604 | static void |
2605 | -writeListValue (CCSSetting *setting, |
2606 | - char *pathName) |
2607 | -{ |
2608 | - GSettings *settings = getSettingsObjectForCCSSetting (setting); |
2609 | - GVariant *value = NULL; |
2610 | - CCSSettingValueList list; |
2611 | - |
2612 | - char *cleanSettingName = translateKeyForGSettings (ccsSettingGetName (setting)); |
2613 | - |
2614 | - if (!ccsGetList (setting, &list)) |
2615 | - return; |
2616 | - |
2617 | - switch (ccsSettingGetInfo (setting)->forList.listType) |
2618 | - { |
2619 | - case TypeBool: |
2620 | - { |
2621 | - GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE ("ab")); |
2622 | - while (list) |
2623 | - { |
2624 | - g_variant_builder_add (builder, "b", list->data->value.asBool); |
2625 | - list = list->next; |
2626 | - } |
2627 | - value = g_variant_new ("ab", builder); |
2628 | - g_variant_builder_unref (builder); |
2629 | - } |
2630 | - break; |
2631 | - case TypeInt: |
2632 | - { |
2633 | - GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE ("ai")); |
2634 | - while (list) |
2635 | - { |
2636 | - g_variant_builder_add (builder, "i", list->data->value.asInt); |
2637 | - list = list->next; |
2638 | - } |
2639 | - value = g_variant_new ("ai", builder); |
2640 | - g_variant_builder_unref (builder); |
2641 | - } |
2642 | - break; |
2643 | - case TypeFloat: |
2644 | - { |
2645 | - GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE ("ad")); |
2646 | - while (list) |
2647 | - { |
2648 | - g_variant_builder_add (builder, "d", (gdouble) list->data->value.asFloat); |
2649 | - list = list->next; |
2650 | - } |
2651 | - value = g_variant_new ("ad", builder); |
2652 | - g_variant_builder_unref (builder); |
2653 | - } |
2654 | - break; |
2655 | - case TypeString: |
2656 | - { |
2657 | - GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE ("as")); |
2658 | - while (list) |
2659 | - { |
2660 | - g_variant_builder_add (builder, "s", list->data->value.asString); |
2661 | - list = list->next; |
2662 | - } |
2663 | - value = g_variant_new ("as", builder); |
2664 | - g_variant_builder_unref (builder); |
2665 | - } |
2666 | - break; |
2667 | - case TypeMatch: |
2668 | - { |
2669 | - GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE ("as")); |
2670 | - while (list) |
2671 | - { |
2672 | - g_variant_builder_add (builder, "s", list->data->value.asMatch); |
2673 | - list = list->next; |
2674 | - } |
2675 | - value = g_variant_new ("as", builder); |
2676 | - g_variant_builder_unref (builder); |
2677 | - } |
2678 | - break; |
2679 | - case TypeColor: |
2680 | - { |
2681 | - GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE ("as")); |
2682 | - char *item; |
2683 | - while (list) |
2684 | - { |
2685 | - item = ccsColorToString (&list->data->value.asColor); |
2686 | - g_variant_builder_add (builder, "s", item); |
2687 | - list = list->next; |
2688 | - } |
2689 | - value = g_variant_new ("as", builder); |
2690 | - g_variant_builder_unref (builder); |
2691 | - } |
2692 | - break; |
2693 | - default: |
2694 | - ccsWarning ("Attempt to write unsupported list type %d!", |
2695 | - ccsSettingGetInfo (setting)->forList.listType); |
2696 | - break; |
2697 | - } |
2698 | - |
2699 | - if (value) |
2700 | - { |
2701 | - g_settings_set_value (settings, cleanSettingName, value); |
2702 | - g_variant_unref (value); |
2703 | - } |
2704 | - |
2705 | - free (cleanSettingName); |
2706 | -} |
2707 | - |
2708 | -static void |
2709 | -writeIntegratedOption (CCSContext *context, |
2710 | +writeIntegratedOption (CCSBackend *backend, |
2711 | + CCSContext *context, |
2712 | CCSSetting *setting, |
2713 | int index) |
2714 | { |
2715 | #ifdef USE_GCONF |
2716 | - writeGConfIntegratedOption (context, setting, index); |
2717 | + writeGConfIntegratedOption (backend, context, setting, index); |
2718 | #endif |
2719 | |
2720 | return; |
2721 | } |
2722 | |
2723 | -static void |
2724 | -resetOptionToDefault (CCSSetting * setting) |
2725 | -{ |
2726 | - GSettings *settings = getSettingsObjectForCCSSetting (setting); |
2727 | - |
2728 | - char *cleanSettingName = translateKeyForGSettings (ccsSettingGetName (setting)); |
2729 | - |
2730 | - g_settings_reset (settings, cleanSettingName); |
2731 | - |
2732 | - free (cleanSettingName); |
2733 | -} |
2734 | - |
2735 | void |
2736 | -writeOption (CCSSetting * setting) |
2737 | +writeOption (CCSBackend *backend, CCSSetting * setting) |
2738 | { |
2739 | - GSettings *settings = getSettingsObjectForCCSSetting (setting); |
2740 | + CCSGSettingsWrapper *settings = getSettingsObjectForCCSSetting (backend, setting); |
2741 | char *cleanSettingName = translateKeyForGSettings (ccsSettingGetName (setting)); |
2742 | + GVariant *gsettingsValue = NULL; |
2743 | + Bool success = FALSE; |
2744 | |
2745 | switch (ccsSettingGetType (setting)) |
2746 | { |
2747 | @@ -681,7 +361,7 @@ |
2748 | char *value; |
2749 | if (ccsGetString (setting, &value)) |
2750 | { |
2751 | - g_settings_set (settings, cleanSettingName, "s", value, NULL); |
2752 | + success = writeStringToVariant (value, &gsettingsValue); |
2753 | } |
2754 | } |
2755 | break; |
2756 | @@ -690,15 +370,16 @@ |
2757 | char *value; |
2758 | if (ccsGetMatch (setting, &value)) |
2759 | { |
2760 | - g_settings_set (settings, cleanSettingName, "s", value, NULL); |
2761 | + success = writeStringToVariant (value, &gsettingsValue); |
2762 | } |
2763 | } |
2764 | + break; |
2765 | case TypeFloat: |
2766 | { |
2767 | float value; |
2768 | if (ccsGetFloat (setting, &value)) |
2769 | { |
2770 | - g_settings_set (settings, cleanSettingName, "d", (double) value, NULL); |
2771 | + success = writeFloatToVariant (value, &gsettingsValue); |
2772 | } |
2773 | } |
2774 | break; |
2775 | @@ -707,7 +388,7 @@ |
2776 | int value; |
2777 | if (ccsGetInt (setting, &value)) |
2778 | { |
2779 | - g_settings_set (settings, cleanSettingName, "i", value, NULL); |
2780 | + success = writeIntToVariant (value, &gsettingsValue); |
2781 | } |
2782 | } |
2783 | break; |
2784 | @@ -716,72 +397,48 @@ |
2785 | Bool value; |
2786 | if (ccsGetBool (setting, &value)) |
2787 | { |
2788 | - g_settings_set (settings, cleanSettingName, "b", value, NULL); |
2789 | + success = writeBoolToVariant (value, &gsettingsValue); |
2790 | } |
2791 | } |
2792 | break; |
2793 | case TypeColor: |
2794 | { |
2795 | CCSSettingColorValue value; |
2796 | - char *colString; |
2797 | |
2798 | if (!ccsGetColor (setting, &value)) |
2799 | break; |
2800 | |
2801 | - colString = ccsColorToString (&value); |
2802 | - if (!colString) |
2803 | - break; |
2804 | - |
2805 | - g_settings_set (settings, cleanSettingName, "s", colString, NULL); |
2806 | - free (colString); |
2807 | + success = writeColorToVariant (value, &gsettingsValue); |
2808 | } |
2809 | break; |
2810 | case TypeKey: |
2811 | { |
2812 | CCSSettingKeyValue key; |
2813 | - char *keyString; |
2814 | |
2815 | if (!ccsGetKey (setting, &key)) |
2816 | break; |
2817 | |
2818 | - keyString = ccsKeyBindingToString (&key); |
2819 | - if (!keyString) |
2820 | - break; |
2821 | - |
2822 | - g_settings_set (settings, cleanSettingName, "s", keyString, NULL); |
2823 | - free (keyString); |
2824 | + success = writeKeyToVariant (key, &gsettingsValue); |
2825 | } |
2826 | break; |
2827 | case TypeButton: |
2828 | { |
2829 | CCSSettingButtonValue button; |
2830 | - char *buttonString; |
2831 | |
2832 | if (!ccsGetButton (setting, &button)) |
2833 | break; |
2834 | |
2835 | - buttonString = ccsButtonBindingToString (&button); |
2836 | - if (!buttonString) |
2837 | - break; |
2838 | - |
2839 | - g_settings_set (settings, cleanSettingName, "s", buttonString, NULL); |
2840 | - free (buttonString); |
2841 | + success = writeButtonToVariant (button, &gsettingsValue); |
2842 | } |
2843 | break; |
2844 | case TypeEdge: |
2845 | { |
2846 | unsigned int edges; |
2847 | - char *edgeString; |
2848 | |
2849 | if (!ccsGetEdge (setting, &edges)) |
2850 | break; |
2851 | |
2852 | - edgeString = ccsEdgesToString (edges); |
2853 | - if (!edgeString) |
2854 | - break; |
2855 | - |
2856 | - g_settings_set (settings, cleanSettingName, "s", edgeString, NULL); |
2857 | - free (edgeString); |
2858 | + success = writeEdgeToVariant (edges, &gsettingsValue); |
2859 | } |
2860 | break; |
2861 | case TypeBell: |
2862 | @@ -789,15 +446,20 @@ |
2863 | Bool value; |
2864 | if (ccsGetBell (setting, &value)) |
2865 | { |
2866 | - g_settings_set (settings, cleanSettingName, "s", value, NULL); |
2867 | + success = writeBoolToVariant (value, &gsettingsValue); |
2868 | } |
2869 | } |
2870 | break; |
2871 | case TypeList: |
2872 | { |
2873 | - gchar *pathName = makeSettingPath (setting); |
2874 | - writeListValue (setting, pathName); |
2875 | - g_free (pathName); |
2876 | + CCSSettingValueList list = NULL; |
2877 | + |
2878 | + if (!ccsGetList (setting, &list)) |
2879 | + return; |
2880 | + |
2881 | + success = writeListValue (list, |
2882 | + ccsSettingGetInfo (setting)->forList.listType, |
2883 | + &gsettingsValue); |
2884 | } |
2885 | break; |
2886 | default: |
2887 | @@ -806,88 +468,33 @@ |
2888 | break; |
2889 | } |
2890 | |
2891 | + if (success && gsettingsValue) |
2892 | + { |
2893 | + /* g_settings_set_value will consume the reference |
2894 | + * so there is no need to unref value here */ |
2895 | + writeVariantToKey (settings, cleanSettingName, gsettingsValue); |
2896 | + } |
2897 | + |
2898 | free (cleanSettingName); |
2899 | } |
2900 | |
2901 | -static void |
2902 | -updateCurrentProfileName (const char *profile) |
2903 | -{ |
2904 | - GVariant *profiles; |
2905 | - char *prof; |
2906 | - gchar *profilePath = makeCompizProfilePath (profile); |
2907 | - GVariant *newProfiles; |
2908 | - GVariantBuilder *newProfilesBuilder; |
2909 | - GVariantIter iter; |
2910 | - gboolean found = FALSE; |
2911 | - |
2912 | - profiles = g_settings_get_value (compizconfigSettings, "existing-profiles"); |
2913 | - |
2914 | - newProfilesBuilder = g_variant_builder_new (G_VARIANT_TYPE ("as")); |
2915 | - |
2916 | - g_variant_iter_init (&iter, profiles); |
2917 | - while (g_variant_iter_loop (&iter, "s", &prof)) |
2918 | - { |
2919 | - g_variant_builder_add (newProfilesBuilder, "s", prof); |
2920 | - |
2921 | - if (!found) |
2922 | - found = (g_strcmp0 (prof, profile) == 0); |
2923 | - } |
2924 | - |
2925 | - if (!found) |
2926 | - g_variant_builder_add (newProfilesBuilder, "s", profile); |
2927 | - |
2928 | - newProfiles = g_variant_new ("as", newProfilesBuilder); |
2929 | - g_settings_set_value (compizconfigSettings, "existing-profiles", newProfiles); |
2930 | - |
2931 | - g_variant_unref (newProfiles); |
2932 | - g_variant_builder_unref (newProfilesBuilder); |
2933 | - |
2934 | - /* Change the current profile and current profile settings */ |
2935 | - free (currentProfile); |
2936 | - |
2937 | - currentProfile = strdup (profile); |
2938 | - currentProfileSettings = g_settings_new_with_path (PROFILE_SCHEMA_ID, profilePath); |
2939 | - |
2940 | - g_settings_set (compizconfigSettings, "current-profile", "s", profile, NULL); |
2941 | - |
2942 | - g_free (profilePath); |
2943 | -} |
2944 | - |
2945 | -static gboolean |
2946 | -updateProfile (CCSContext *context) |
2947 | -{ |
2948 | - char *profile = strdup (ccsGetProfile (context)); |
2949 | - |
2950 | - if (!profile) |
2951 | - profile = strdup (DEFAULTPROF); |
2952 | - |
2953 | - if (!strlen (profile)) |
2954 | - { |
2955 | - free (profile); |
2956 | - profile = strdup (DEFAULTPROF); |
2957 | - } |
2958 | - |
2959 | - if (g_strcmp0 (profile, currentProfile)) |
2960 | - updateCurrentProfileName (profile); |
2961 | - |
2962 | - free (profile); |
2963 | - |
2964 | - return TRUE; |
2965 | -} |
2966 | - |
2967 | static char* |
2968 | -getCurrentProfileName (void) |
2969 | +getCurrentProfileName (CCSBackend *backend) |
2970 | { |
2971 | GVariant *value; |
2972 | char *ret = NULL; |
2973 | |
2974 | - value = g_settings_get_value (compizconfigSettings, "current-profile"); |
2975 | + CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); |
2976 | + |
2977 | + value = ccsGSettingsWrapperGetValue (priv->compizconfigSettings, "current-profile"); |
2978 | |
2979 | if (value) |
2980 | ret = strdup (g_variant_get_string (value, NULL)); |
2981 | else |
2982 | ret = strdup (DEFAULTPROF); |
2983 | |
2984 | + g_variant_unref (value); |
2985 | + |
2986 | return ret; |
2987 | } |
2988 | |
2989 | @@ -901,6 +508,120 @@ |
2990 | } |
2991 | } |
2992 | |
2993 | +static CCSContext * |
2994 | +ccsGSettingsBackendGetContextDefault (CCSBackend *backend) |
2995 | +{ |
2996 | + CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); |
2997 | + |
2998 | + return priv->context; |
2999 | +} |
3000 | + |
3001 | +static void |
3002 | +ccsGSettingsBackendConnectToValueChangedSignalDefault (CCSBackend *backend, CCSGSettingsWrapper *wrapper) |
3003 | +{ |
3004 | + ccsGSettingsWrapperConnectToChangedSignal (wrapper, (GCallback) valueChanged, (gpointer) backend); |
3005 | +} |
3006 | + |
3007 | +static void |
3008 | +ccsGSettingsBackendRegisterGConfClientDefault (CCSBackend *backend) |
3009 | +{ |
3010 | +#ifdef USE_GCONF |
3011 | + initGConfClient (backend); |
3012 | +#endif |
3013 | +} |
3014 | + |
3015 | +static void |
3016 | +ccsGSettingsBackendUnregisterGConfClientDefault (CCSBackend *backend) |
3017 | +{ |
3018 | +#ifdef USE_GCONF |
3019 | + CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); |
3020 | + |
3021 | + gconf_client_clear_cache (priv->client); |
3022 | + finiGConfClient (backend); |
3023 | +#endif |
3024 | +} |
3025 | + |
3026 | +static const char * |
3027 | +ccsGSettingsBackendGetCurrentProfileDefault (CCSBackend *backend) |
3028 | +{ |
3029 | + CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); |
3030 | + |
3031 | + return priv->currentProfile; |
3032 | +} |
3033 | + |
3034 | +static GVariant * |
3035 | +ccsGSettingsBackendGetExistingProfilesDefault (CCSBackend *backend) |
3036 | +{ |
3037 | + CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); |
3038 | + |
3039 | + return ccsGSettingsWrapperGetValue (priv->compizconfigSettings, "existing-profiles"); |
3040 | +} |
3041 | + |
3042 | +static void |
3043 | +ccsGSettingsBackendSetExistingProfilesDefault (CCSBackend *backend, GVariant *value) |
3044 | +{ |
3045 | + CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); |
3046 | + |
3047 | + ccsGSettingsWrapperSetValue (priv->compizconfigSettings, "existing-profiles", value); |
3048 | +} |
3049 | + |
3050 | +static void |
3051 | +ccsGSettingsBackendSetCurrentProfileDefault (CCSBackend *backend, const gchar *value) |
3052 | +{ |
3053 | + CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); |
3054 | + gchar *profilePath = makeCompizProfilePath (value); |
3055 | + |
3056 | + /* Change the current profile and current profile settings */ |
3057 | + if (priv->currentProfile) |
3058 | + free (priv->currentProfile); |
3059 | + |
3060 | + if (priv->currentProfileSettings) |
3061 | + ccsGSettingsWrapperUnref (priv->currentProfileSettings); |
3062 | + |
3063 | + priv->currentProfile = strdup (value); |
3064 | + priv->currentProfileSettings = ccsGSettingsWrapperNewForSchemaWithPath (PROFILE_SCHEMA_ID, |
3065 | + profilePath, |
3066 | + backend->object.object_allocation); |
3067 | + |
3068 | + GVariant *currentProfileVariant = g_variant_new ("s", value, NULL); |
3069 | + |
3070 | + ccsGSettingsWrapperSetValue (priv->compizconfigSettings, "current-profile", currentProfileVariant); |
3071 | + |
3072 | + g_free (profilePath); |
3073 | +} |
3074 | + |
3075 | +GVariant * |
3076 | +ccsGSettingsBackendGetPluginsWithSetKeysDefault (CCSBackend *backend) |
3077 | +{ |
3078 | + CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); |
3079 | + return ccsGSettingsWrapperGetValue (priv->currentProfileSettings, "plugins-with-set-keys"); |
3080 | +} |
3081 | + |
3082 | +void |
3083 | +ccsGSettingsBackendClearPluginsWithSetKeysDefault (CCSBackend *backend) |
3084 | +{ |
3085 | + CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); |
3086 | + ccsGSettingsWrapperResetKey (priv->currentProfileSettings, "plugins-with-set-keys"); |
3087 | +} |
3088 | + |
3089 | +static CCSGSettingsBackendInterface gsettingsAdditionalDefaultInterface = { |
3090 | + ccsGSettingsBackendGetContextDefault, |
3091 | + ccsGSettingsBackendConnectToValueChangedSignalDefault, |
3092 | + ccsGSettingsBackendGetSettingsObjectForPluginWithPathDefault, |
3093 | + ccsGSettingsBackendRegisterGConfClientDefault, |
3094 | + ccsGSettingsBackendUnregisterGConfClientDefault, |
3095 | + ccsGSettingsBackendGetCurrentProfileDefault, |
3096 | + ccsGSettingsBackendGetExistingProfilesDefault, |
3097 | + ccsGSettingsBackendSetExistingProfilesDefault, |
3098 | + ccsGSettingsBackendSetCurrentProfileDefault, |
3099 | + ccsGSettingsBackendGetPluginsWithSetKeysDefault, |
3100 | + ccsGSettingsBackendClearPluginsWithSetKeysDefault, |
3101 | + ccsGSettingsBackendUnsetAllChangedPluginKeysInProfileDefault, |
3102 | + ccsGSettingsBackendUpdateProfileDefault, |
3103 | + ccsGSettingsBackendUpdateCurrentProfileNameDefault, |
3104 | + ccsGSettingsBackendAddProfileDefault |
3105 | +}; |
3106 | + |
3107 | static Bool |
3108 | initBackend (CCSBackend *backend, CCSContext * context) |
3109 | { |
3110 | @@ -908,61 +629,75 @@ |
3111 | |
3112 | g_type_init (); |
3113 | |
3114 | - compizconfigSettings = g_settings_new (COMPIZCONFIG_SCHEMA_ID); |
3115 | - |
3116 | -#ifdef USE_GCONF |
3117 | - initGConfClient (context); |
3118 | -#endif |
3119 | - |
3120 | - currentProfile = getCurrentProfileName (); |
3121 | - currentProfilePath = makeCompizProfilePath (currentProfile); |
3122 | - currentProfileSettings = g_settings_new_with_path (PROFILE_SCHEMA_ID, currentProfilePath); |
3123 | + ccsObjectAddInterface (backend, (CCSInterface *) &gsettingsAdditionalDefaultInterface, GET_INTERFACE_TYPE (CCSGSettingsBackendInterface)); |
3124 | + |
3125 | + CCSGSettingsBackendPrivate *priv = calloc (1, sizeof (CCSGSettingsBackendPrivate)); |
3126 | + |
3127 | + if (!priv) |
3128 | + return FALSE; |
3129 | + |
3130 | + ccsObjectSetPrivate (backend, (CCSPrivate *) priv); |
3131 | + |
3132 | + priv->compizconfigSettings = ccsGSettingsWrapperNewForSchema (COMPIZCONFIG_SCHEMA_ID, |
3133 | + backend->object.object_allocation); |
3134 | + priv->currentProfile = getCurrentProfileName (backend); |
3135 | + currentProfilePath = makeCompizProfilePath (priv->currentProfile); |
3136 | + priv->currentProfileSettings = ccsGSettingsWrapperNewForSchemaWithPath (PROFILE_SCHEMA_ID, |
3137 | + currentProfilePath, |
3138 | + backend->object.object_allocation); |
3139 | + priv->context = context; |
3140 | |
3141 | g_free (currentProfilePath); |
3142 | |
3143 | return TRUE; |
3144 | } |
3145 | |
3146 | +static void |
3147 | +ccsGSettingsWrapperDestroyNotify (gpointer o) |
3148 | +{ |
3149 | + ccsGSettingsWrapperUnref ((CCSGSettingsWrapper *) o); |
3150 | +} |
3151 | + |
3152 | static Bool |
3153 | finiBackend (CCSBackend *backend) |
3154 | { |
3155 | - GList *l = settingsList; |
3156 | - |
3157 | - processEvents (backend, 0); |
3158 | - |
3159 | -#ifdef USE_GCONF |
3160 | - gconf_client_clear_cache (client); |
3161 | - finiGConfClient (); |
3162 | -#endif |
3163 | - |
3164 | - if (currentProfile) |
3165 | - { |
3166 | - free (currentProfile); |
3167 | - currentProfile = NULL; |
3168 | - } |
3169 | - |
3170 | - while (l) |
3171 | - { |
3172 | - g_object_unref (G_OBJECT (l->data)); |
3173 | - l = g_list_next (l); |
3174 | - } |
3175 | - |
3176 | - if (currentProfileSettings) |
3177 | - { |
3178 | - g_object_unref (currentProfileSettings); |
3179 | - currentProfileSettings = NULL; |
3180 | - } |
3181 | - |
3182 | - g_object_unref (G_OBJECT (compizconfigSettings)); |
3183 | - |
3184 | - processEvents (backend, 0); |
3185 | + CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); |
3186 | + |
3187 | + processEvents (backend, 0); |
3188 | + |
3189 | + ccsGSettingsBackendUnregisterGConfClient (backend); |
3190 | + |
3191 | + if (priv->currentProfile) |
3192 | + { |
3193 | + free (priv->currentProfile); |
3194 | + priv->currentProfile = NULL; |
3195 | + } |
3196 | + |
3197 | + g_list_free_full (priv->settingsList, ccsGSettingsWrapperDestroyNotify); |
3198 | + priv->settingsList = NULL; |
3199 | + |
3200 | + if (priv->currentProfileSettings) |
3201 | + { |
3202 | + ccsGSettingsWrapperUnref (priv->currentProfileSettings); |
3203 | + priv->currentProfileSettings = NULL; |
3204 | + } |
3205 | + |
3206 | + ccsGSettingsWrapperUnref (priv->compizconfigSettings); |
3207 | + |
3208 | + priv->compizconfigSettings = NULL; |
3209 | + |
3210 | + processEvents (backend, 0); |
3211 | + |
3212 | + free (priv); |
3213 | + ccsObjectSetPrivate (backend, NULL); |
3214 | + |
3215 | return TRUE; |
3216 | } |
3217 | |
3218 | Bool |
3219 | readInit (CCSBackend *backend, CCSContext * context) |
3220 | { |
3221 | - return updateProfile (context); |
3222 | + return ccsGSettingsBackendUpdateProfile (backend, context); |
3223 | } |
3224 | |
3225 | void |
3226 | @@ -976,10 +711,10 @@ |
3227 | if (ccsGetIntegrationEnabled (context) && |
3228 | isIntegratedOption (setting, &index)) |
3229 | { |
3230 | - status = readIntegratedOption (context, setting, index); |
3231 | + status = readIntegratedOption (backend, context, setting, index); |
3232 | } |
3233 | else |
3234 | - status = readOption (setting); |
3235 | + status = readOption (backend, setting); |
3236 | |
3237 | if (!status) |
3238 | ccsResetToDefault (setting, TRUE); |
3239 | @@ -988,7 +723,7 @@ |
3240 | Bool |
3241 | writeInit (CCSBackend *backend, CCSContext * context) |
3242 | { |
3243 | - return updateProfile (context); |
3244 | + return ccsGSettingsBackendUpdateProfile (backend, context); |
3245 | } |
3246 | |
3247 | void |
3248 | @@ -1001,14 +736,14 @@ |
3249 | if (ccsGetIntegrationEnabled (context) && |
3250 | isIntegratedOption (setting, &index)) |
3251 | { |
3252 | - writeIntegratedOption (context, setting, index); |
3253 | + writeIntegratedOption (backend, context, setting, index); |
3254 | } |
3255 | else if (ccsSettingGetIsDefault (setting)) |
3256 | { |
3257 | - resetOptionToDefault (setting); |
3258 | + resetOptionToDefault (backend, setting); |
3259 | } |
3260 | else |
3261 | - writeOption (setting); |
3262 | + writeOption (backend, setting); |
3263 | |
3264 | } |
3265 | |
3266 | @@ -1039,14 +774,16 @@ |
3267 | GVariantIter iter; |
3268 | CCSStringList ret = NULL; |
3269 | |
3270 | - value = g_settings_get_value (compizconfigSettings, "existing-profiles"); |
3271 | + CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); |
3272 | + |
3273 | + value = ccsGSettingsWrapperGetValue (priv->compizconfigSettings, "existing-profiles"); |
3274 | g_variant_iter_init (&iter, value); |
3275 | while (g_variant_iter_loop (&iter, "s", &profile)) |
3276 | { |
3277 | - CCSString *str = malloc (sizeof (CCSString)); |
3278 | - |
3279 | + CCSString *str = calloc (1, sizeof (CCSString)); |
3280 | str->value = strdup (profile); |
3281 | |
3282 | + ccsStringRef (str); |
3283 | ret = ccsStringListAppend (ret, str); |
3284 | } |
3285 | |
3286 | @@ -1055,87 +792,18 @@ |
3287 | return ret; |
3288 | } |
3289 | |
3290 | -static Bool |
3291 | -deleteProfile (CCSBackend *backend, |
3292 | - CCSContext *context, |
3293 | - char *profile) |
3294 | -{ |
3295 | - GVariant *plugins; |
3296 | - GVariant *profiles; |
3297 | - GVariant *newProfiles; |
3298 | - GVariantBuilder *newProfilesBuilder; |
3299 | - char *plugin, *prof; |
3300 | - GVariantIter iter; |
3301 | - char *profileSettingsPath = makeCompizProfilePath (profile); |
3302 | - GSettings *profileSettings = g_settings_new_with_path (PROFILE_SCHEMA_ID, profileSettingsPath); |
3303 | - |
3304 | - plugins = g_settings_get_value (currentProfileSettings, "plugins-with-set-keys"); |
3305 | - profiles = g_settings_get_value (compizconfigSettings, "existing-profiles"); |
3306 | - |
3307 | - g_variant_iter_init (&iter, plugins); |
3308 | - while (g_variant_iter_loop (&iter, "s", &plugin)) |
3309 | - { |
3310 | - GSettings *settings; |
3311 | - gchar *pathName = makeCompizPluginPath (currentProfile, plugin); |
3312 | - |
3313 | - settings = getSettingsObjectForPluginWithPath (plugin, pathName, context); |
3314 | - g_free (pathName); |
3315 | - |
3316 | - /* The GSettings documentation says not to use this API |
3317 | - * because we should know our own schema ... though really |
3318 | - * we don't because we autogenerate schemas ... */ |
3319 | - if (settings) |
3320 | - { |
3321 | - char **keys = g_settings_list_keys (settings); |
3322 | - char **key_ptr; |
3323 | - |
3324 | - /* Unset all the keys */ |
3325 | - for (key_ptr = keys; *key_ptr; key_ptr++) |
3326 | - g_settings_reset (settings, *key_ptr); |
3327 | - |
3328 | - g_strfreev (keys); |
3329 | - } |
3330 | - } |
3331 | - |
3332 | - /* Remove the profile from existing-profiles */ |
3333 | - g_settings_reset (profileSettings, "plugins-with-set-values"); |
3334 | - |
3335 | - g_variant_iter_init (&iter, profiles); |
3336 | - newProfilesBuilder = g_variant_builder_new (G_VARIANT_TYPE ("as")); |
3337 | - |
3338 | - while (g_variant_iter_loop (&iter, "s", &prof)) |
3339 | - { |
3340 | - if (g_strcmp0 (prof, profile)) |
3341 | - g_variant_builder_add (newProfilesBuilder, "s", prof); |
3342 | - } |
3343 | - |
3344 | - newProfiles = g_variant_new ("as", newProfilesBuilder); |
3345 | - g_settings_set_value (compizconfigSettings, "existing-profiles", newProfiles); |
3346 | - |
3347 | - g_variant_unref (newProfiles); |
3348 | - g_variant_builder_unref (newProfilesBuilder); |
3349 | - |
3350 | - g_free (profileSettingsPath); |
3351 | - |
3352 | - updateProfile (context); |
3353 | - |
3354 | - return TRUE; |
3355 | -} |
3356 | - |
3357 | -const CCSBackendInfo gconfBackendInfo = |
3358 | -{ |
3359 | - "gsettings", |
3360 | - "GSettings Configuration Backend", |
3361 | - "GSettings Configuration Backend for libccs", |
3362 | - TRUE, |
3363 | - TRUE, |
3364 | - 1 |
3365 | -}; |
3366 | - |
3367 | static const CCSBackendInfo * |
3368 | getInfo (CCSBackend *backend) |
3369 | { |
3370 | - return &gconfBackendInfo; |
3371 | + return &gsettingsBackendInfo; |
3372 | +} |
3373 | + |
3374 | +static Bool |
3375 | +ccsGSettingsDeleteProfileWrapper (CCSBackend *backend, |
3376 | + CCSContext *context, |
3377 | + char *profile) |
3378 | +{ |
3379 | + return deleteProfile (backend, context, profile); |
3380 | } |
3381 | |
3382 | static CCSBackendInterface gsettingsVTable = { |
3383 | @@ -1153,9 +821,11 @@ |
3384 | getSettingIsIntegrated, |
3385 | getSettingIsReadOnly, |
3386 | getExistingProfiles, |
3387 | - deleteProfile |
3388 | + ccsGSettingsDeleteProfileWrapper |
3389 | }; |
3390 | |
3391 | + |
3392 | + |
3393 | CCSBackendInterface * |
3394 | getBackendInfo (void) |
3395 | { |
3396 | |
3397 | === modified file 'compizconfig/gsettings/src/gsettings.h' |
3398 | --- compizconfig/gsettings/src/gsettings.h 2012-08-07 01:05:13 +0000 |
3399 | +++ compizconfig/gsettings/src/gsettings.h 2012-08-07 01:05:15 +0000 |
3400 | @@ -56,6 +56,14 @@ |
3401 | #define _GNU_SOURCE |
3402 | #endif |
3403 | |
3404 | +#ifdef USE_GCONF |
3405 | +#include <gconf/gconf.h> |
3406 | +#include <gconf/gconf-client.h> |
3407 | +#include <gconf/gconf-value.h> |
3408 | +#endif |
3409 | + |
3410 | +#include <ccs_gsettings_interface.h> |
3411 | + |
3412 | typedef enum { |
3413 | OptionInt, |
3414 | OptionBool, |
3415 | @@ -64,22 +72,31 @@ |
3416 | OptionSpecial, |
3417 | } SpecialOptionType; |
3418 | |
3419 | -char *currentProfile; |
3420 | +struct _CCSGSettingsBackendPrivate |
3421 | +{ |
3422 | + GList *settingsList; |
3423 | + CCSGSettingsWrapper *compizconfigSettings; |
3424 | + CCSGSettingsWrapper *currentProfileSettings; |
3425 | + |
3426 | + char *currentProfile; |
3427 | + CCSContext *context; |
3428 | + |
3429 | +#ifdef USE_GCONF |
3430 | + GConfClient *client; |
3431 | + guint *gnomeGConfNotifyIds; |
3432 | +#endif |
3433 | + |
3434 | +}; |
3435 | |
3436 | Bool readInit (CCSBackend *, CCSContext * context); |
3437 | void readSetting (CCSBackend *, CCSContext * context, CCSSetting * setting); |
3438 | -Bool readOption (CCSSetting * setting); |
3439 | +Bool readOption (CCSBackend *backend, CCSSetting * setting); |
3440 | Bool writeInit (CCSBackend *, CCSContext * context); |
3441 | -void writeOption (CCSSetting *setting); |
3442 | +void writeOption (CCSBackend *backend, CCSSetting *setting); |
3443 | |
3444 | #ifdef USE_GCONF |
3445 | |
3446 | -#include <gconf/gconf.h> |
3447 | -#include <gconf/gconf-client.h> |
3448 | -#include <gconf/gconf-value.h> |
3449 | |
3450 | -GConfClient *client; |
3451 | -guint gnomeGConfNotifyIds[NUM_WATCHED_DIRS]; |
3452 | |
3453 | typedef struct _SpecialOptionGConf { |
3454 | const char* settingName; |
3455 | @@ -100,18 +117,20 @@ |
3456 | gpointer user_data); |
3457 | |
3458 | void |
3459 | -initGConfClient (CCSContext *context); |
3460 | +initGConfClient (CCSBackend *backend); |
3461 | |
3462 | void |
3463 | -finiGConfClient (void); |
3464 | +finiGConfClient (CCSBackend *backend); |
3465 | |
3466 | Bool |
3467 | -readGConfIntegratedOption (CCSContext *context, |
3468 | +readGConfIntegratedOption (CCSBackend *backend, |
3469 | + CCSContext *context, |
3470 | CCSSetting *setting, |
3471 | int index); |
3472 | |
3473 | void |
3474 | -writeGConfIntegratedOption (CCSContext *context, |
3475 | +writeGConfIntegratedOption (CCSBackend *backend, |
3476 | + CCSContext *context, |
3477 | CCSSetting *setting, |
3478 | int index); |
3479 | |
3480 | |
3481 | === modified file 'compizconfig/gsettings/tests/CMakeLists.txt' |
3482 | --- compizconfig/gsettings/tests/CMakeLists.txt 2012-08-07 01:05:13 +0000 |
3483 | +++ compizconfig/gsettings/tests/CMakeLists.txt 2012-08-07 01:05:15 +0000 |
3484 | @@ -1,4 +1,7 @@ |
3485 | +include (CompizGSettings) |
3486 | + |
3487 | include_directories (${CMAKE_CURRENT_SOURCE_DIR} |
3488 | + ${CMAKE_CURRENT_BINARY_DIR} |
3489 | ${CMAKE_CURRENT_SOURCE_DIR}/../src |
3490 | ${CMAKE_CURRENT_SOURCE_DIR}/../../libcompizconfig/tests |
3491 | ${CMAKE_CURRENT_SOURCE_DIR}/../../mocks/libcompizconfig |
3492 | @@ -7,11 +10,18 @@ |
3493 | |
3494 | pkg_check_modules (COMPIZCONFIG_TEST_GSETTINGS libcompizconfig) |
3495 | |
3496 | +add_library (compizconfig_ccs_gsettings_wrapper_mock STATIC |
3497 | + ${CMAKE_CURRENT_SOURCE_DIR}/ccs_gsettings_wrapper_mock.cpp |
3498 | + ${CMAKE_CURRENT_SOURCE_DIR}/ccs_gsettings_wrapper_mock.h) |
3499 | + |
3500 | +add_library (compizconfig_ccs_gsettings_backend_mock STATIC |
3501 | + ${CMAKE_CURRENT_SOURCE_DIR}/ccs_gsettings_backend_mock.cpp |
3502 | + ${CMAKE_CURRENT_SOURCE_DIR}/ccs_gsettings_backend_mock.h) |
3503 | + |
3504 | add_executable (compizconfig_test_gsettings |
3505 | - ${CMAKE_CURRENT_SOURCE_DIR}/gsettings_mocks.cpp |
3506 | ${CMAKE_CURRENT_SOURCE_DIR}/test_gsettings_tests.cpp |
3507 | + ${CMAKE_CURRENT_SOURCE_DIR}/test_gsettings_wrapper.cpp |
3508 | ${CMAKE_CURRENT_SOURCE_DIR}/test_gsettings.cpp |
3509 | - ${CMAKE_CURRENT_SOURCE_DIR}/gsettings_mocks.h |
3510 | ${CMAKE_CURRENT_SOURCE_DIR}/test_gsettings_tests.h) |
3511 | |
3512 | link_directories (${CMAKE_CURRENT_BINARY_DIR}/../../libcompizconfig/tests) |
3513 | @@ -19,8 +29,25 @@ |
3514 | target_link_libraries (compizconfig_test_gsettings |
3515 | gsettings_backend_shared |
3516 | compizconfig_ccs_setting_mock |
3517 | + compizconfig_ccs_plugin_mock |
3518 | + compizconfig_ccs_context_mock |
3519 | + compizconfig_ccs_gsettings_backend_mock |
3520 | + compizconfig_ccs_gsettings_wrapper_mock |
3521 | ${COMPIZCONFIG_TEST_GSETTINGS_LIBRARIES} |
3522 | ${GTEST_BOTH_LIBRARIES} |
3523 | ${GMOCK_MAIN_LIBRARY}) |
3524 | |
3525 | +add_custom_command (OUTPUT ${CMAKE_BINARY_DIR}/generated/glib-2.0/schemas/org.compiz.mock.gschema.xml |
3526 | + COMMAND cp -r ${CMAKE_CURRENT_SOURCE_DIR}/org.compiz.mock.gschema.xml ${CMAKE_BINARY_DIR}/generated/glib-2.0/schemas/org.compiz.mock.gschema.xml |
3527 | + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/org.compiz.mock.gschema.xml |
3528 | + VERBATIM) |
3529 | + |
3530 | +add_custom_target (compiz_gsettings_mock_schema ALL |
3531 | + DEPENDS ${CMAKE_BINARY_DIR}/generated/glib-2.0/schemas/org.compiz.mock.gschema.xml) |
3532 | + |
3533 | +add_gsettings_schema_to_recompilation_list (compiz_gsettings_mock_schema) |
3534 | + |
3535 | +configure_file (${CMAKE_CURRENT_SOURCE_DIR}/gsettings-mock-schemas-config.h.in |
3536 | + ${CMAKE_CURRENT_BINARY_DIR}/gsettings-mock-schemas-config.h) |
3537 | + |
3538 | compiz_discover_tests (compizconfig_test_gsettings COVERAGE gsettings_backend_shared) |
3539 | |
3540 | === added file 'compizconfig/gsettings/tests/ccs_gsettings_backend_mock.cpp' |
3541 | --- compizconfig/gsettings/tests/ccs_gsettings_backend_mock.cpp 1970-01-01 00:00:00 +0000 |
3542 | +++ compizconfig/gsettings/tests/ccs_gsettings_backend_mock.cpp 2012-08-07 01:05:15 +0000 |
3543 | @@ -0,0 +1,61 @@ |
3544 | +#include <gtest/gtest.h> |
3545 | +#include <gmock/gmock.h> |
3546 | + |
3547 | +#include <ccs.h> |
3548 | + |
3549 | +#include "ccs_gsettings_backend_mock.h" |
3550 | + |
3551 | +CCSGSettingsBackendInterface ccsGSettingsBackendGMockInterface = |
3552 | +{ |
3553 | + CCSGSettingsBackendGMock::ccsGSettingsBackendGetContext, |
3554 | + CCSGSettingsBackendGMock::ccsGSettingsBackendConnectToValueChangedSignal, |
3555 | + CCSGSettingsBackendGMock::ccsGSettingsBackendGetSettingsObjectForPluginWithPath, |
3556 | + CCSGSettingsBackendGMock::ccsGSettingsBackendRegisterGConfClient, |
3557 | + CCSGSettingsBackendGMock::ccsGSettingsBackendUnregisterGConfClient, |
3558 | + CCSGSettingsBackendGMock::ccsGSettingsBackendGetCurrentProfile, |
3559 | + CCSGSettingsBackendGMock::ccsGSettingsBackendGetExistingProfiles, |
3560 | + CCSGSettingsBackendGMock::ccsGSettingsBackendSetExistingProfiles, |
3561 | + CCSGSettingsBackendGMock::ccsGSettingsBackendSetCurrentProfile, |
3562 | + CCSGSettingsBackendGMock::ccsGSettingsBackendGetPluginsWithSetKeys, |
3563 | + CCSGSettingsBackendGMock::ccsGSettingsBackendClearPluginsWithSetKeys, |
3564 | + CCSGSettingsBackendGMock::ccsGSettingsBackendUnsetAllChangedPluginKeysInProfile, |
3565 | + CCSGSettingsBackendGMock::ccsGSettingsBackendUpdateProfile, |
3566 | + CCSGSettingsBackendGMock::ccsGSettingsBackendUpdateCurrentProfileName, |
3567 | + CCSGSettingsBackendGMock::ccsGSettingsBackendAddProfile |
3568 | +}; |
3569 | + |
3570 | +CCSBackend * |
3571 | +ccsGSettingsBackendGMockNew () |
3572 | +{ |
3573 | + CCSBackend *backend = (CCSBackend *) calloc (1, sizeof (CCSBackend)); |
3574 | + |
3575 | + if (!backend) |
3576 | + return NULL; |
3577 | + |
3578 | + CCSGSettingsBackendGMock *gmock = new CCSGSettingsBackendGMock (backend); |
3579 | + |
3580 | + if (!gmock) |
3581 | + { |
3582 | + free (backend); |
3583 | + return NULL; |
3584 | + } |
3585 | + |
3586 | + ccsObjectInit (backend, &ccsDefaultObjectAllocator); |
3587 | + ccsObjectAddInterface (backend, (const CCSInterface *) &ccsGSettingsBackendGMockInterface, GET_INTERFACE_TYPE (CCSGSettingsBackendInterface)); |
3588 | + ccsObjectSetPrivate (backend, reinterpret_cast <CCSPrivate *> (gmock)); |
3589 | + |
3590 | + return backend; |
3591 | +} |
3592 | + |
3593 | +void |
3594 | +ccsGSettingsBackendGMockFree (CCSBackend *backend) |
3595 | +{ |
3596 | + CCSGSettingsBackendGMock *mock = reinterpret_cast <CCSGSettingsBackendGMock *> (ccsObjectGetPrivate (backend)); |
3597 | + |
3598 | + delete mock; |
3599 | + |
3600 | + ccsObjectSetPrivate (backend, NULL); |
3601 | + ccsObjectFinalize (backend); |
3602 | + |
3603 | + free (backend); |
3604 | +} |
3605 | |
3606 | === added file 'compizconfig/gsettings/tests/ccs_gsettings_backend_mock.h' |
3607 | --- compizconfig/gsettings/tests/ccs_gsettings_backend_mock.h 1970-01-01 00:00:00 +0000 |
3608 | +++ compizconfig/gsettings/tests/ccs_gsettings_backend_mock.h 2012-08-07 01:05:15 +0000 |
3609 | @@ -0,0 +1,176 @@ |
3610 | +#ifndef _COMPIZCONFIG_CCS_GSETTINGS_BACKEND_MOCK |
3611 | +#define _COMPIZCONFIG_CCS_GSETTINGS_BACKEND_MOCK |
3612 | + |
3613 | +#include <gtest/gtest.h> |
3614 | +#include <gmock/gmock.h> |
3615 | + |
3616 | +#include <gsettings_shared.h> |
3617 | +#include <ccs-backend.h> |
3618 | + |
3619 | +using ::testing::_; |
3620 | +using ::testing::Return; |
3621 | + |
3622 | +CCSBackend * ccsGSettingsBackendGMockNew (); |
3623 | +void ccsGSettingsBackendGMockFree (CCSBackend *backend); |
3624 | + |
3625 | +class CCSGSettingsBackendGMockInterface |
3626 | +{ |
3627 | + public: |
3628 | + |
3629 | + virtual ~CCSGSettingsBackendGMockInterface () {} |
3630 | + |
3631 | + virtual CCSContext * getContext () = 0; |
3632 | + virtual void connectToChangedSignal (CCSGSettingsWrapper *) = 0; |
3633 | + virtual CCSGSettingsWrapper * getSettingsObjectForPluginWithPath (const char * plugin, |
3634 | + const char * path, |
3635 | + CCSContext * context) = 0; |
3636 | + virtual void registerGConfClient () = 0; |
3637 | + virtual void unregisterGConfClient () = 0; |
3638 | + virtual const char * getCurrentProfile () = 0; |
3639 | + virtual GVariant * getExistingProfiles () = 0; |
3640 | + virtual void setExistingProfiles (GVariant *) = 0; |
3641 | + virtual void setCurrentProfile (const gchar *) = 0; |
3642 | + virtual GVariant * getPluginsWithSetKeys () = 0; |
3643 | + virtual void clearPluginsWithSetKeys () = 0; |
3644 | + virtual void unsetAllChangedPluginKeysInProfile (CCSContext *, GVariant *, const char *) = 0; |
3645 | + virtual gboolean updateProfile (CCSContext *) = 0; |
3646 | + virtual void updateCurrentProfileName (const char *) = 0; |
3647 | + virtual gboolean addProfile (const char *) = 0; |
3648 | +}; |
3649 | + |
3650 | +class CCSGSettingsBackendGMock : |
3651 | + public CCSGSettingsBackendGMockInterface |
3652 | +{ |
3653 | + public: |
3654 | + |
3655 | + CCSGSettingsBackendGMock (CCSBackend *backend) : |
3656 | + mBackend (backend) |
3657 | + { |
3658 | + } |
3659 | + |
3660 | + MOCK_METHOD0 (getContext, CCSContext * ()); |
3661 | + MOCK_METHOD1 (connectToChangedSignal, void (CCSGSettingsWrapper *)); |
3662 | + MOCK_METHOD3 (getSettingsObjectForPluginWithPath, CCSGSettingsWrapper * (const char * plugin, |
3663 | + const char * path, |
3664 | + CCSContext * context)); |
3665 | + MOCK_METHOD0 (registerGConfClient, void ()); |
3666 | + MOCK_METHOD0 (unregisterGConfClient, void ()); |
3667 | + MOCK_METHOD0 (getCurrentProfile, const char * ()); |
3668 | + MOCK_METHOD0 (getExistingProfiles, GVariant * ()); |
3669 | + MOCK_METHOD1 (setExistingProfiles, void (GVariant *)); |
3670 | + MOCK_METHOD1 (setCurrentProfile, void (const gchar *)); |
3671 | + MOCK_METHOD0 (getPluginsWithSetKeys, GVariant * ()); |
3672 | + MOCK_METHOD0 (clearPluginsWithSetKeys, void ()); |
3673 | + MOCK_METHOD3 (unsetAllChangedPluginKeysInProfile, void (CCSContext *, GVariant *, const char *)); |
3674 | + MOCK_METHOD1 (updateProfile, gboolean (CCSContext *)); |
3675 | + MOCK_METHOD1 (updateCurrentProfileName, void (const char *)); |
3676 | + MOCK_METHOD1 (addProfile, gboolean (const char *)); |
3677 | + |
3678 | + CCSBackend * getBackend () { return mBackend; } |
3679 | + |
3680 | + private: |
3681 | + |
3682 | + CCSBackend *mBackend; |
3683 | + |
3684 | + public: |
3685 | + |
3686 | + static CCSContext * |
3687 | + ccsGSettingsBackendGetContext (CCSBackend *backend) |
3688 | + { |
3689 | + return (reinterpret_cast <CCSGSettingsBackendGMock *> (ccsObjectGetPrivate (backend)))->getContext (); |
3690 | + } |
3691 | + |
3692 | + static void |
3693 | + ccsGSettingsBackendConnectToValueChangedSignal (CCSBackend *backend, CCSGSettingsWrapper *object) |
3694 | + { |
3695 | + (reinterpret_cast <CCSGSettingsBackendGMock *> (ccsObjectGetPrivate (backend)))->connectToChangedSignal(object); |
3696 | + } |
3697 | + |
3698 | + static CCSGSettingsWrapper * |
3699 | + ccsGSettingsBackendGetSettingsObjectForPluginWithPath (CCSBackend *backend, |
3700 | + const char *plugin, |
3701 | + const char *path, |
3702 | + CCSContext *context) |
3703 | + { |
3704 | + return (reinterpret_cast <CCSGSettingsBackendGMock *> (ccsObjectGetPrivate (backend)))->getSettingsObjectForPluginWithPath (plugin, |
3705 | + path, |
3706 | + context); |
3707 | + } |
3708 | + |
3709 | + static void |
3710 | + ccsGSettingsBackendRegisterGConfClient (CCSBackend *backend) |
3711 | + { |
3712 | + (reinterpret_cast <CCSGSettingsBackendGMock *> (ccsObjectGetPrivate (backend)))->registerGConfClient (); |
3713 | + } |
3714 | + |
3715 | + static void |
3716 | + ccsGSettingsBackendUnregisterGConfClient (CCSBackend *backend) |
3717 | + { |
3718 | + (reinterpret_cast <CCSGSettingsBackendGMock *> (ccsObjectGetPrivate (backend)))->unregisterGConfClient (); |
3719 | + } |
3720 | + |
3721 | + static const char * |
3722 | + ccsGSettingsBackendGetCurrentProfile (CCSBackend *backend) |
3723 | + { |
3724 | + return (reinterpret_cast <CCSGSettingsBackendGMock *> (ccsObjectGetPrivate (backend)))->getCurrentProfile (); |
3725 | + } |
3726 | + |
3727 | + static GVariant * |
3728 | + ccsGSettingsBackendGetExistingProfiles (CCSBackend *backend) |
3729 | + { |
3730 | + return (reinterpret_cast <CCSGSettingsBackendGMock *> (ccsObjectGetPrivate (backend)))->getExistingProfiles (); |
3731 | + } |
3732 | + |
3733 | + static void |
3734 | + ccsGSettingsBackendSetExistingProfiles (CCSBackend *backend, GVariant *value) |
3735 | + { |
3736 | + (reinterpret_cast <CCSGSettingsBackendGMock *> (ccsObjectGetPrivate (backend)))->setExistingProfiles (value); |
3737 | + } |
3738 | + |
3739 | + static void |
3740 | + ccsGSettingsBackendSetCurrentProfile (CCSBackend *backend, const gchar *value) |
3741 | + { |
3742 | + (reinterpret_cast <CCSGSettingsBackendGMock *> (ccsObjectGetPrivate (backend)))->setCurrentProfile (value); |
3743 | + } |
3744 | + |
3745 | + static GVariant * |
3746 | + ccsGSettingsBackendGetPluginsWithSetKeys (CCSBackend *backend) |
3747 | + { |
3748 | + return (reinterpret_cast <CCSGSettingsBackendGMock *> (ccsObjectGetPrivate (backend)))->getPluginsWithSetKeys (); |
3749 | + } |
3750 | + |
3751 | + static void |
3752 | + ccsGSettingsBackendClearPluginsWithSetKeys (CCSBackend *backend) |
3753 | + { |
3754 | + return (reinterpret_cast <CCSGSettingsBackendGMock *> (ccsObjectGetPrivate (backend)))->clearPluginsWithSetKeys (); |
3755 | + } |
3756 | + |
3757 | + static void |
3758 | + ccsGSettingsBackendUnsetAllChangedPluginKeysInProfile (CCSBackend *backend, |
3759 | + CCSContext *context, |
3760 | + GVariant *pluginKeys, |
3761 | + const char *profile) |
3762 | + { |
3763 | + return (reinterpret_cast <CCSGSettingsBackendGMock *> (ccsObjectGetPrivate (backend)))->unsetAllChangedPluginKeysInProfile (context, pluginKeys, profile); |
3764 | + } |
3765 | + |
3766 | + static gboolean |
3767 | + ccsGSettingsBackendUpdateProfile (CCSBackend *backend, CCSContext *context) |
3768 | + { |
3769 | + return (reinterpret_cast <CCSGSettingsBackendGMock *> (ccsObjectGetPrivate (backend)))->updateProfile (context); |
3770 | + } |
3771 | + |
3772 | + static void |
3773 | + ccsGSettingsBackendUpdateCurrentProfileName (CCSBackend *backend, const char *profile) |
3774 | + { |
3775 | + return (reinterpret_cast <CCSGSettingsBackendGMock *> (ccsObjectGetPrivate (backend)))->updateCurrentProfileName (profile); |
3776 | + } |
3777 | + |
3778 | + static gboolean |
3779 | + ccsGSettingsBackendAddProfile (CCSBackend *backend, const char *profile) |
3780 | + { |
3781 | + return (reinterpret_cast <CCSGSettingsBackendGMock *> (ccsObjectGetPrivate (backend)))->addProfile (profile); |
3782 | + } |
3783 | +}; |
3784 | + |
3785 | +#endif |
3786 | |
3787 | === added file 'compizconfig/gsettings/tests/ccs_gsettings_wrapper_mock.cpp' |
3788 | --- compizconfig/gsettings/tests/ccs_gsettings_wrapper_mock.cpp 1970-01-01 00:00:00 +0000 |
3789 | +++ compizconfig/gsettings/tests/ccs_gsettings_wrapper_mock.cpp 2012-08-07 01:05:15 +0000 |
3790 | @@ -0,0 +1,52 @@ |
3791 | +#include <ccs_gsettings_wrapper_mock.h> |
3792 | + |
3793 | +const CCSGSettingsWrapperInterface mockInterface = |
3794 | +{ |
3795 | + CCSGSettingsWrapperGMock::ccsGSettingsWrapperSetValue, |
3796 | + CCSGSettingsWrapperGMock::ccsGSettingsWrapperGetValue, |
3797 | + CCSGSettingsWrapperGMock::ccsGSettingsWrapperResetKey, |
3798 | + CCSGSettingsWrapperGMock::ccsGSettingsWrapperListKeys, |
3799 | + CCSGSettingsWrapperGMock::ccsGSettingsWrapperGetGSettings, |
3800 | + CCSGSettingsWrapperGMock::ccsGSettingsWrapperGetSchemaName, |
3801 | + CCSGSettingsWrapperGMock::ccsGSettingsWrapperGetPath, |
3802 | + CCSGSettingsWrapperGMock::ccsGSettingsWrapperConnectToChangedSignal, |
3803 | + CCSGSettingsWrapperGMock::ccsFreeGSettingsWrapper |
3804 | +}; |
3805 | + |
3806 | +CCSGSettingsWrapper * |
3807 | +ccsMockGSettingsWrapperNew () |
3808 | +{ |
3809 | + CCSGSettingsWrapper *wrapper = (CCSGSettingsWrapper *) calloc (1, sizeof (CCSGSettingsWrapper)); |
3810 | + |
3811 | + if (!wrapper) |
3812 | + return NULL; |
3813 | + |
3814 | + CCSGSettingsWrapperGMock *gmockWrapper = new CCSGSettingsWrapperGMock (wrapper); |
3815 | + |
3816 | + if (!gmockWrapper) |
3817 | + { |
3818 | + free (wrapper); |
3819 | + return NULL; |
3820 | + } |
3821 | + |
3822 | + ccsObjectInit (wrapper, &ccsDefaultObjectAllocator); |
3823 | + ccsObjectAddInterface (wrapper, (const CCSInterface *) &mockInterface, GET_INTERFACE_TYPE (CCSGSettingsWrapperInterface)); |
3824 | + ccsObjectSetPrivate (wrapper, (CCSPrivate *) gmockWrapper); |
3825 | + |
3826 | + ccsGSettingsWrapperRef (wrapper); |
3827 | + |
3828 | + return wrapper; |
3829 | +} |
3830 | + |
3831 | +void |
3832 | +ccsMockGSettingsWrapperFree (CCSGSettingsWrapper *wrapper) |
3833 | +{ |
3834 | + CCSGSettingsWrapperGMock *gmockWrapper = reinterpret_cast <CCSGSettingsWrapperGMock *> (ccsObjectGetPrivate (wrapper)); |
3835 | + |
3836 | + delete gmockWrapper; |
3837 | + |
3838 | + ccsObjectSetPrivate (wrapper, NULL); |
3839 | + ccsObjectFinalize (wrapper); |
3840 | + free (wrapper); |
3841 | +} |
3842 | + |
3843 | |
3844 | === added file 'compizconfig/gsettings/tests/ccs_gsettings_wrapper_mock.h' |
3845 | --- compizconfig/gsettings/tests/ccs_gsettings_wrapper_mock.h 1970-01-01 00:00:00 +0000 |
3846 | +++ compizconfig/gsettings/tests/ccs_gsettings_wrapper_mock.h 2012-08-07 01:05:15 +0000 |
3847 | @@ -0,0 +1,113 @@ |
3848 | +#ifndef _COMPIZCONFIG_CCS_GSETTINGS_WRAPPER_MOCK |
3849 | +#define _COMPIZCONFIG_CCS_GSETTINGS_WRAPPER_MOCK |
3850 | + |
3851 | +#include <gtest/gtest.h> |
3852 | +#include <gmock/gmock.h> |
3853 | + |
3854 | +#include <ccs_gsettings_interface.h> |
3855 | + |
3856 | +CCSGSettingsWrapper * ccsMockGSettingsWrapperNew (); |
3857 | +void ccsMockGSettingsWrapperFree (CCSGSettingsWrapper *); |
3858 | + |
3859 | +class CCSGSettingsWrapperMockInterface |
3860 | +{ |
3861 | + public: |
3862 | + |
3863 | + virtual ~CCSGSettingsWrapperMockInterface () {} |
3864 | + virtual void setValue (const char *, GVariant *) = 0; |
3865 | + virtual GVariant * getValue (const char *) = 0; |
3866 | + virtual void resetKey (const char *) = 0; |
3867 | + virtual char ** listKeys () = 0; |
3868 | + virtual GSettings * getGSettings () = 0; |
3869 | + virtual const char * getSchemaName () = 0; |
3870 | + virtual const char * getPath () = 0; |
3871 | + virtual void connectToChangedSignal (GCallback, gpointer) = 0; |
3872 | +}; |
3873 | + |
3874 | +class CCSGSettingsWrapperGMock : |
3875 | + public CCSGSettingsWrapperMockInterface |
3876 | +{ |
3877 | + public: |
3878 | + |
3879 | + CCSGSettingsWrapperGMock (CCSGSettingsWrapper *wrapper) : |
3880 | + mWrapper (wrapper) |
3881 | + { |
3882 | + } |
3883 | + |
3884 | + MOCK_METHOD2 (setValue, void (const char *, GVariant *)); |
3885 | + MOCK_METHOD1 (getValue, GVariant * (const char *)); |
3886 | + MOCK_METHOD1 (resetKey, void (const char *)); |
3887 | + MOCK_METHOD0 (listKeys, char ** ()); |
3888 | + MOCK_METHOD0 (getGSettings, GSettings * ()); |
3889 | + MOCK_METHOD0 (getSchemaName, const char * ()); |
3890 | + MOCK_METHOD0 (getPath, const char * ()); |
3891 | + MOCK_METHOD2 (connectToChangedSignal, void (GCallback, gpointer)); |
3892 | + |
3893 | + private: |
3894 | + |
3895 | + CCSGSettingsWrapper *mWrapper; |
3896 | + |
3897 | + public: |
3898 | + |
3899 | + static void |
3900 | + ccsGSettingsWrapperSetValue (CCSGSettingsWrapper *wrapper, |
3901 | + const char *key, |
3902 | + GVariant *value) |
3903 | + { |
3904 | + reinterpret_cast <CCSGSettingsWrapperMockInterface *> (ccsObjectGetPrivate (wrapper))->setValue (key, value); |
3905 | + } |
3906 | + |
3907 | + static GVariant * |
3908 | + ccsGSettingsWrapperGetValue (CCSGSettingsWrapper *wrapper, |
3909 | + const char *key) |
3910 | + { |
3911 | + return reinterpret_cast <CCSGSettingsWrapperMockInterface *> (ccsObjectGetPrivate (wrapper))->getValue (key); |
3912 | + } |
3913 | + |
3914 | + static void |
3915 | + ccsGSettingsWrapperResetKey (CCSGSettingsWrapper *wrapper, |
3916 | + const char *key) |
3917 | + { |
3918 | + reinterpret_cast <CCSGSettingsWrapperMockInterface *> (ccsObjectGetPrivate (wrapper))->resetKey (key); |
3919 | + } |
3920 | + |
3921 | + static char ** |
3922 | + ccsGSettingsWrapperListKeys (CCSGSettingsWrapper *wrapper) |
3923 | + { |
3924 | + return reinterpret_cast <CCSGSettingsWrapperMockInterface *> (ccsObjectGetPrivate (wrapper))->listKeys (); |
3925 | + } |
3926 | + |
3927 | + static GSettings * |
3928 | + ccsGSettingsWrapperGetGSettings (CCSGSettingsWrapper *wrapper) |
3929 | + { |
3930 | + return reinterpret_cast <CCSGSettingsWrapperMockInterface *> (ccsObjectGetPrivate (wrapper))->getGSettings (); |
3931 | + } |
3932 | + |
3933 | + static const char * |
3934 | + ccsGSettingsWrapperGetSchemaName (CCSGSettingsWrapper *wrapper) |
3935 | + { |
3936 | + return reinterpret_cast <CCSGSettingsWrapperMockInterface *> (ccsObjectGetPrivate (wrapper))->getSchemaName (); |
3937 | + } |
3938 | + |
3939 | + static const char * |
3940 | + ccsGSettingsWrapperGetPath (CCSGSettingsWrapper *wrapper) |
3941 | + { |
3942 | + return reinterpret_cast <CCSGSettingsWrapperMockInterface *> (ccsObjectGetPrivate (wrapper))->getPath (); |
3943 | + } |
3944 | + |
3945 | + static void |
3946 | + ccsGSettingsWrapperConnectToChangedSignal (CCSGSettingsWrapper *wrapper, |
3947 | + GCallback callback, |
3948 | + gpointer data) |
3949 | + { |
3950 | + reinterpret_cast <CCSGSettingsWrapperMockInterface *> (ccsObjectGetPrivate (wrapper))->connectToChangedSignal (callback, data); |
3951 | + } |
3952 | + |
3953 | + static void |
3954 | + ccsFreeGSettingsWrapper (CCSGSettingsWrapper *wrapper) |
3955 | + { |
3956 | + ccsMockGSettingsWrapperFree (wrapper); |
3957 | + } |
3958 | +}; |
3959 | + |
3960 | +#endif |
3961 | |
3962 | === added file 'compizconfig/gsettings/tests/gsettings-mock-schemas-config.h.in' |
3963 | --- compizconfig/gsettings/tests/gsettings-mock-schemas-config.h.in 1970-01-01 00:00:00 +0000 |
3964 | +++ compizconfig/gsettings/tests/gsettings-mock-schemas-config.h.in 2012-08-07 01:05:15 +0000 |
3965 | @@ -0,0 +1,7 @@ |
3966 | +#define MOCK_SCHEMA_PATH "@CMAKE_BINARY_DIR@/generated/glib-2.0/schemas" |
3967 | + |
3968 | +namespace |
3969 | +{ |
3970 | +const std::string MOCK_SCHEMA ("org.compiz.mock"); |
3971 | +const std::string MOCK_PATH (MOCK_SCHEMA_PATH); |
3972 | +} |
3973 | |
3974 | === removed file 'compizconfig/gsettings/tests/gsettings_mocks.cpp' |
3975 | --- compizconfig/gsettings/tests/gsettings_mocks.cpp 2012-07-06 04:53:09 +0000 |
3976 | +++ compizconfig/gsettings/tests/gsettings_mocks.cpp 1970-01-01 00:00:00 +0000 |
3977 | @@ -1,200 +0,0 @@ |
3978 | -#include <gsettings_mocks.h> |
3979 | - |
3980 | -static void compizconfig_gsettings_wrap_gsettings_default_init (CCSGSettingsWrapGSettingsInterface *interface); |
3981 | - |
3982 | -G_DEFINE_INTERFACE (CCSGSettingsWrapGSettings, compizconfig_gsettings_wrap_gsettings, G_TYPE_OBJECT) |
3983 | - |
3984 | -static void compizconfig_gsettings_wrap_gsettings_default_init (CCSGSettingsWrapGSettingsInterface *klass) |
3985 | -{ |
3986 | - g_object_interface_install_property (klass, |
3987 | - g_param_spec_string ("schema", |
3988 | - "schema", |
3989 | - "Schema Name", |
3990 | - "invalid.invalid", |
3991 | - static_cast <GParamFlags> (G_PARAM_CONSTRUCT_ONLY | |
3992 | - G_PARAM_WRITABLE | |
3993 | - G_PARAM_READABLE))); |
3994 | -} |
3995 | - |
3996 | -CCSGSettingsWrapGSettings * |
3997 | -compizconfig_gsettings_wrap_gsettings_new (GType type, const gchar *name) |
3998 | -{ |
3999 | - GValue name_v = G_VALUE_INIT; |
4000 | - |
4001 | - g_value_init (&name_v, G_TYPE_STRING); |
4002 | - |
4003 | - g_value_set_string (&name_v, name); |
4004 | - |
4005 | - GParameter param[1] = |
4006 | - { |
4007 | - { "schema", name_v } |
4008 | - }; |
4009 | - |
4010 | - CCSGSettingsWrapGSettings *wrap_gsettings = COMPIZCONFIG_GSETTINGS_WRAP_GSETTINGS (g_object_newv (type, 1, param)); |
4011 | - |
4012 | - g_value_unset (&name_v); |
4013 | - |
4014 | - return wrap_gsettings; |
4015 | -} |
4016 | - |
4017 | -G_BEGIN_DECLS |
4018 | - |
4019 | -#define COMPIZCONFIG_GSETTINGS_MOCK_WRAP_GSETTINGS(obj) \ |
4020 | - (G_TYPE_CHECK_INSTANCE_CAST ((obj), COMPIZCONFIG_GSETTINGS_TYPE_MOCK_WRAP_GSETTINGS, CCSGSettingsMockWrapGSettings)) |
4021 | - |
4022 | -#define COMPIZCONFIG_GSETTINGS_TYPE_MOCK_GSETTINGS_CONCRETE_CLASS(klass) \ |
4023 | - (G_TYPE_CHECK_CLASS_CAST ((klass), COMPIZCONFIG_GSETTINGS_TYPE_MOCK_WRAP_GSETTINGS, CCSGSettingsMockWrapGSettingsClass)) |
4024 | - |
4025 | -#define COMPIZCONFIG_GSETTINGS_IS_MOCK_WRAP_GSETTINGS(obj) \ |
4026 | - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), COMPIZCONFIG_GSETTINGS_TYPE_MOCK_WRAP_GSETTINGS) |
4027 | - |
4028 | -#define COMPIZCONFIG_GSETTINGS_IS_MOCK_WRAP_GSETTINGS_CLASS(klass) \ |
4029 | - (G_TYPE_CHECK_CLASS_TYPE ((klass), COMPIZCONFIG_GSETTINGS_TYPE_MOCK_WRAP_GSETTINGS)) |
4030 | - |
4031 | -#define COMPIZCONFIG_GSETTINGS_TYPE_MOCK_GSETTINGS_CONCRETE_GET_CLASS(obj) \ |
4032 | - (G_TYPE_INSTANCE_GET_CLASS ((obj), COMPIZCONFIG_GSETTINGS_TYPE_MOCK_WRAP_GSETTINGS, CCSGSettingsMockWrapGSettingsClass)) |
4033 | - |
4034 | -typedef struct { |
4035 | - GObject parent; |
4036 | -} CCSGSettingsMockWrapGSettings; |
4037 | - |
4038 | -typedef struct { |
4039 | - GObjectClass parent_class; |
4040 | -} CCSGSettingsMockWrapGSettingsClass; |
4041 | - |
4042 | -G_END_DECLS |
4043 | - |
4044 | -static void compizconfig_gsettings_mock_wrap_gsettings_interface_init (CCSGSettingsWrapGSettingsInterface *interface); |
4045 | - |
4046 | -G_DEFINE_TYPE_WITH_CODE (CCSGSettingsMockWrapGSettings, compizconfig_gsettings_mock_wrap_gsettings, G_TYPE_OBJECT, |
4047 | - G_IMPLEMENT_INTERFACE (COMPIZCONFIG_GSETTINGS_TYPE_WRAP_GSETTINGS, |
4048 | - compizconfig_gsettings_mock_wrap_gsettings_interface_init)) |
4049 | - |
4050 | -#define GET_PRIVATE(o) \ |
4051 | - (G_TYPE_INSTANCE_GET_PRIVATE ((o), COMPIZCONFIG_GSETTINGS_TYPE_MOCK_WRAP_GSETTINGS, CCSGSettingsMockWrapGSettingsPrivate)) |
4052 | - |
4053 | -typedef struct _CCSGSettingsMockWrapGSettingsPrivate CCSGSettingsMockWrapGSettingsPrivate; |
4054 | - |
4055 | -struct _CCSGSettingsMockWrapGSettingsPrivate |
4056 | -{ |
4057 | - gchar *name; |
4058 | -}; |
4059 | - |
4060 | -static void |
4061 | -compizconfig_gsettings_mock_wrap_gsettings_dispose (GObject *object) |
4062 | -{ |
4063 | - CCSGSettingsMockWrapGSettingsPrivate *priv = GET_PRIVATE (object); |
4064 | - G_OBJECT_CLASS (compizconfig_gsettings_mock_wrap_gsettings_parent_class)->dispose (object); |
4065 | - |
4066 | - if (priv->name) |
4067 | - g_free (priv->name); |
4068 | - |
4069 | - priv->name = NULL; |
4070 | -} |
4071 | - |
4072 | -static void |
4073 | -compizconfig_gsettings_mock_wrap_gsettings_finalize (GObject *object) |
4074 | -{ |
4075 | - G_OBJECT_CLASS (compizconfig_gsettings_mock_wrap_gsettings_parent_class)->finalize (object); |
4076 | -} |
4077 | - |
4078 | -static void |
4079 | -compizconfig_gsettings_mock_wrap_gsettings_interface_init (CCSGSettingsWrapGSettingsInterface *interface) |
4080 | -{ |
4081 | -} |
4082 | - |
4083 | -static void |
4084 | -compizconfig_gsettings_mock_wrap_gsettings_set_property (GObject *object, |
4085 | - guint property_id, |
4086 | - const GValue *value, |
4087 | - GParamSpec *pspec) |
4088 | -{ |
4089 | - CCSGSettingsMockWrapGSettingsPrivate *priv = GET_PRIVATE (object); |
4090 | - |
4091 | - switch (property_id) |
4092 | - { |
4093 | - case COMPIZCONFIG_GSETTINGS_WRAP_GSETTINGS_PROPERTY_SCHEMA_NAME: |
4094 | - if (priv->name) |
4095 | - g_free (priv->name); |
4096 | - |
4097 | - priv->name = g_value_dup_string (value); |
4098 | - break; |
4099 | - default: |
4100 | - g_assert_not_reached (); |
4101 | - break; |
4102 | - } |
4103 | -} |
4104 | - |
4105 | -static void |
4106 | -compizconfig_gsettings_mock_wrap_gsettings_get_property (GObject *object, |
4107 | - guint property_id, |
4108 | - GValue *value, |
4109 | - GParamSpec *pspec) |
4110 | -{ |
4111 | - CCSGSettingsMockWrapGSettingsPrivate *priv = GET_PRIVATE (object); |
4112 | - |
4113 | - switch (property_id) |
4114 | - { |
4115 | - case COMPIZCONFIG_GSETTINGS_WRAP_GSETTINGS_PROPERTY_SCHEMA_NAME: |
4116 | - g_value_set_string (value, priv->name); |
4117 | - break; |
4118 | - default: |
4119 | - g_assert_not_reached (); |
4120 | - break; |
4121 | - } |
4122 | -} |
4123 | - |
4124 | -static GObject * |
4125 | -compizconfig_gsettings_mock_wrap_gsettings_constructor (GType type, |
4126 | - guint n_construct_properties, |
4127 | - GObjectConstructParam *construction_properties) |
4128 | -{ |
4129 | - GObject *object; |
4130 | - CCSGSettingsMockWrapGSettingsPrivate *priv; |
4131 | - |
4132 | - { |
4133 | - object = G_OBJECT_CLASS (compizconfig_gsettings_mock_wrap_gsettings_parent_class)->constructor (type, |
4134 | - n_construct_properties, |
4135 | - construction_properties); |
4136 | - } |
4137 | - |
4138 | - priv = GET_PRIVATE (object); |
4139 | - |
4140 | - for (guint i = 0; i < n_construct_properties; i++) |
4141 | - { |
4142 | - if (g_strcmp0 (construction_properties[i].pspec->name, "schema") == 0) |
4143 | - { |
4144 | - if (!priv->name) |
4145 | - priv->name = g_value_dup_string (construction_properties[i].value); |
4146 | - } |
4147 | - else |
4148 | - { |
4149 | - g_assert_not_reached (); |
4150 | - } |
4151 | - } |
4152 | - |
4153 | - return object; |
4154 | -} |
4155 | - |
4156 | -static void |
4157 | -compizconfig_gsettings_mock_wrap_gsettings_class_init (CCSGSettingsMockWrapGSettingsClass *klass) |
4158 | -{ |
4159 | - GObjectClass *object_class = G_OBJECT_CLASS (klass); |
4160 | - |
4161 | - g_type_class_add_private (klass, sizeof (CCSGSettingsMockWrapGSettingsPrivate)); |
4162 | - |
4163 | - object_class->dispose = compizconfig_gsettings_mock_wrap_gsettings_dispose; |
4164 | - object_class->finalize = compizconfig_gsettings_mock_wrap_gsettings_finalize; |
4165 | - object_class->set_property = compizconfig_gsettings_mock_wrap_gsettings_set_property; |
4166 | - object_class->get_property = compizconfig_gsettings_mock_wrap_gsettings_get_property; |
4167 | - object_class->constructor = compizconfig_gsettings_mock_wrap_gsettings_constructor; |
4168 | - |
4169 | - g_object_class_override_property (G_OBJECT_CLASS (klass), |
4170 | - COMPIZCONFIG_GSETTINGS_WRAP_GSETTINGS_PROPERTY_SCHEMA_NAME, |
4171 | - "schema"); |
4172 | -} |
4173 | - |
4174 | -static void |
4175 | -compizconfig_gsettings_mock_wrap_gsettings_init (CCSGSettingsMockWrapGSettings *self) |
4176 | -{ |
4177 | -} |
4178 | |
4179 | === removed file 'compizconfig/gsettings/tests/gsettings_mocks.h' |
4180 | --- compizconfig/gsettings/tests/gsettings_mocks.h 2012-08-07 01:05:13 +0000 |
4181 | +++ compizconfig/gsettings/tests/gsettings_mocks.h 1970-01-01 00:00:00 +0000 |
4182 | @@ -1,45 +0,0 @@ |
4183 | -#ifndef _COMPIZ_COMPIZCONFIG_GSETTINGS_MOCKS |
4184 | -#define _COMPIZ_COMPIZCONFIG_GSETTINGS_MOCKS |
4185 | - |
4186 | -#include <glib-object.h> |
4187 | -#include <compizconfig_ccs_setting_mock.h> |
4188 | - |
4189 | -G_BEGIN_DECLS |
4190 | - |
4191 | -#define COMPIZCONFIG_GSETTINGS_WRAP_GSETTINGS(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), COMPIZCONFIG_GSETTINGS_TYPE_WRAP_GSETTINGS, CCSGSettingsWrapGSettings)) |
4192 | - |
4193 | -#define COMPIZCONFIG_GSETTINGS_WRAP_GSETTINGS_GET_INTERFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE((inst), COMPIZCONFIG_GSETTINGS_TYPE_WRAP_GSETTINGS, CCSGSettingsWrapGSettingsInterface)) |
4194 | - |
4195 | -#define COMPIZCONFIG_GSETTINGS_TYPE_WRAP_GSETTINGS (compizconfig_gsettings_wrap_gsettings_get_type()) |
4196 | - |
4197 | -GType compizconfig_gsettings_wrap_gsettings_get_type (void); |
4198 | - |
4199 | -typedef struct _CCSGSettingsWrapGSettings CCSGSettingsWrapGSettings; /* dummy typedef */ |
4200 | -typedef struct _CCSGSettingsWrapGSettingsInterface CCSGSettingsWrapGSettingsInterface; |
4201 | - |
4202 | -struct _CCSGSettingsWrapGSettingsInterface { |
4203 | - GTypeInterface parent; |
4204 | - |
4205 | -}; |
4206 | - |
4207 | -enum |
4208 | -{ |
4209 | - COMPIZCONFIG_GSETTINGS_WRAP_GSETTINGS_PROPERTY_SCHEMA_NAME = 1, |
4210 | - COMPIZCONFIG_GSETTINGS_WRAP_GSETTINGS_PROPERTY_NUM = 2 |
4211 | -}; |
4212 | - |
4213 | -#define COMPIZCONFIG_GSETTINGS_TYPE_MOCK_WRAP_GSETTINGS (compizconfig_gsettings_mock_wrap_gsettings_get_type ()) |
4214 | - |
4215 | -GType compizconfig_gsettings_mock_wrap_gsettings_get_type (); |
4216 | - |
4217 | -/** |
4218 | - * compizconfig_gsettings_wrap_gsettings_new: |
4219 | - * @type: (in) (transfer none): a GType of the object type to be created |
4220 | - * @name: (in) (transfer none): schema name |
4221 | - * Return value: (transfer full): a new CCSGSettingsWrapGSettings |
4222 | - */ |
4223 | -CCSGSettingsWrapGSettings * compizconfig_gsettings_wrap_gsettings_new (GType type, const gchar *name); |
4224 | - |
4225 | -G_END_DECLS |
4226 | - |
4227 | -#endif |
4228 | |
4229 | === added file 'compizconfig/gsettings/tests/org.compiz.mock.gschema.xml' |
4230 | --- compizconfig/gsettings/tests/org.compiz.mock.gschema.xml 1970-01-01 00:00:00 +0000 |
4231 | +++ compizconfig/gsettings/tests/org.compiz.mock.gschema.xml 2012-08-07 01:05:15 +0000 |
4232 | @@ -0,0 +1,53 @@ |
4233 | +<?xml version="1.0"?> |
4234 | +<schemalist> |
4235 | + <schema id="org.compiz.mock" gettext-domain="compiz"> |
4236 | + <key type="i" name="integer-setting"> |
4237 | + <default>0</default> |
4238 | + </key> |
4239 | + <key type="b" name="boolean-setting"> |
4240 | + <default>false</default> |
4241 | + </key> |
4242 | + <key type="d" name="float-setting"> |
4243 | + <default>0.0</default> |
4244 | + </key> |
4245 | + <key type="s" name="string-setting"> |
4246 | + <default>""</default> |
4247 | + </key> |
4248 | + <key type="s" name="match-setting"> |
4249 | + <default>""</default> |
4250 | + </key> |
4251 | + <key type="b" name="bell-setting"> |
4252 | + <default>false</default> |
4253 | + </key> |
4254 | + <key type="s" name="color-setting"> |
4255 | + <default>""</default> |
4256 | + </key> |
4257 | + <key type="s" name="key-setting"> |
4258 | + <default>""</default> |
4259 | + </key> |
4260 | + <key type="s" name="button-setting"> |
4261 | + <default>""</default> |
4262 | + </key> |
4263 | + <key type="s" name="edge-setting"> |
4264 | + <default>""</default> |
4265 | + </key> |
4266 | + <key type="ai" name="int-list-setting"> |
4267 | + <default>[0]</default> |
4268 | + </key> |
4269 | + <key type="ad" name="float-list-setting"> |
4270 | + <default>[0.0]</default> |
4271 | + </key> |
4272 | + <key type="ab" name="bool-list-setting"> |
4273 | + <default>[true]</default> |
4274 | + </key> |
4275 | + <key type="as" name="string-list-setting"> |
4276 | + <default>[""]</default> |
4277 | + </key> |
4278 | + <key type="as" name="match-list-setting"> |
4279 | + <default>[""]</default> |
4280 | + </key> |
4281 | + <key type="as" name="color-list-setting"> |
4282 | + <default>[""]</default> |
4283 | + </key> |
4284 | + </schema> |
4285 | +</schemalist> |
4286 | |
4287 | === modified file 'compizconfig/gsettings/tests/test_gsettings_tests.cpp' |
4288 | --- compizconfig/gsettings/tests/test_gsettings_tests.cpp 2012-07-10 10:35:16 +0000 |
4289 | +++ compizconfig/gsettings/tests/test_gsettings_tests.cpp 2012-08-07 01:05:15 +0000 |
4290 | @@ -1,13 +1,114 @@ |
4291 | #include <boost/function.hpp> |
4292 | #include <boost/bind.hpp> |
4293 | |
4294 | +#include <boost/shared_ptr.hpp> |
4295 | +#include <boost/scoped_array.hpp> |
4296 | + |
4297 | #include "test_gsettings_tests.h" |
4298 | #include "gsettings.h" |
4299 | -#include "gsettings_mocks.h" |
4300 | +#include "ccs_gsettings_backend_mock.h" |
4301 | +#include "compizconfig_ccs_context_mock.h" |
4302 | +#include "compizconfig_ccs_plugin_mock.h" |
4303 | +#include "compizconfig_ccs_setting_mock.h" |
4304 | +#include "gtest_shared_characterwrapper.h" |
4305 | +#include "compizconfig_test_value_combiners.h" |
4306 | +#include "compizconfig_ccs_mocked_allocator.h" |
4307 | +#include "ccs_gsettings_wrapper_mock.h" |
4308 | |
4309 | using ::testing::Values; |
4310 | using ::testing::ValuesIn; |
4311 | using ::testing::Return; |
4312 | +using ::testing::ReturnNull; |
4313 | +using ::testing::Invoke; |
4314 | +using ::testing::WithArgs; |
4315 | +using ::testing::MatcherInterface; |
4316 | +using ::testing::MatchResultListener; |
4317 | +using ::testing::AllOf; |
4318 | +using ::testing::Not; |
4319 | +using ::testing::Matcher; |
4320 | +using ::testing::Eq; |
4321 | +using ::testing::NiceMock; |
4322 | +using ::testing::StrictMock; |
4323 | +using ::testing::IsNull; |
4324 | + |
4325 | +class GVariantSubtypeMatcher : |
4326 | + public ::testing::MatcherInterface<GVariant *> |
4327 | +{ |
4328 | + public: |
4329 | + GVariantSubtypeMatcher (const std::string &type) : |
4330 | + mType (type) |
4331 | + { |
4332 | + } |
4333 | + |
4334 | + virtual ~GVariantSubtypeMatcher () {} |
4335 | + virtual bool MatchAndExplain (GVariant *x, MatchResultListener *listener) const |
4336 | + { |
4337 | + return g_variant_type_is_subtype_of (G_VARIANT_TYPE (mType.c_str ()), g_variant_get_type (x)); |
4338 | + } |
4339 | + |
4340 | + virtual void DescribeTo (std::ostream *os) const |
4341 | + { |
4342 | + *os << "is subtype of " << mType; |
4343 | + } |
4344 | + private: |
4345 | + |
4346 | + std::string mType; |
4347 | +}; |
4348 | + |
4349 | +template <typename T> |
4350 | +class GVariantHasValueInArrayMatcher : |
4351 | + public ::testing::MatcherInterface<GVariant *> |
4352 | +{ |
4353 | + public: |
4354 | + GVariantHasValueInArrayMatcher (const std::string &type, |
4355 | + const T &t, |
4356 | + const boost::function <bool (T const&, T const&)> &eq) : |
4357 | + mType (type), |
4358 | + mT (t), |
4359 | + mEq (eq) |
4360 | + { |
4361 | + } |
4362 | + |
4363 | + virtual ~GVariantHasValueInArrayMatcher () {} |
4364 | + virtual bool MatchAndExplain (GVariant *x, MatchResultListener *listener) const |
4365 | + { |
4366 | + GVariantIter iter; |
4367 | + T match; |
4368 | + bool found = false; |
4369 | + |
4370 | + g_variant_iter_init (&iter, x); |
4371 | + while (g_variant_iter_loop (&iter, mType.c_str (), &match)) |
4372 | + { |
4373 | + if (mEq (match, mT)) |
4374 | + found = true; |
4375 | + } |
4376 | + |
4377 | + return found; |
4378 | + } |
4379 | + |
4380 | + virtual void DescribeTo (std::ostream *os) const |
4381 | + { |
4382 | + *os << "contains " << mT; |
4383 | + } |
4384 | + private: |
4385 | + |
4386 | + std::string mType; |
4387 | + T mT; |
4388 | + boost::function <bool (T const&, T const&)> mEq; |
4389 | +}; |
4390 | + |
4391 | +template <typename T> |
4392 | +inline Matcher<GVariant *> GVariantHasValueInArray (const std::string &type, |
4393 | + const T &t, |
4394 | + const boost::function <bool (T const &, T const &)> &eq) |
4395 | +{ |
4396 | + return MakeMatcher (new GVariantHasValueInArrayMatcher<T> (type, t, eq)); |
4397 | +} |
4398 | + |
4399 | +inline Matcher<GVariant *> IsVariantSubtypeOf (const std::string &type) |
4400 | +{ |
4401 | + return MakeMatcher (new GVariantSubtypeMatcher (type)); |
4402 | +} |
4403 | |
4404 | TEST_P(CCSGSettingsTest, TestTestFixtures) |
4405 | { |
4406 | @@ -17,6 +118,115 @@ |
4407 | { |
4408 | } |
4409 | |
4410 | +namespace |
4411 | +{ |
4412 | +bool streq (const char * const &s1, const char * const &s2) |
4413 | +{ |
4414 | + return g_str_equal (s1, s2); |
4415 | +} |
4416 | + |
4417 | +} |
4418 | + |
4419 | +class CCSGSettingsTestProfiles : |
4420 | + public CCSGSettingsTestIndependent |
4421 | +{ |
4422 | + public: |
4423 | + |
4424 | + static const std::string newProfileName; |
4425 | + static const std::string existingProfileName; |
4426 | +}; |
4427 | + |
4428 | +const std::string CCSGSettingsTestProfiles::existingProfileName ("ExistingProfile"); |
4429 | +const std::string CCSGSettingsTestProfiles::newProfileName ("NewProfile"); |
4430 | + |
4431 | +TEST_F(CCSGSettingsTestProfiles, TestAddProfile) |
4432 | +{ |
4433 | + boost::shared_ptr <CCSBackend> backend (ccsGSettingsBackendGMockNew (), |
4434 | + boost::bind (ccsGSettingsBackendGMockFree, _1)); |
4435 | + CCSGSettingsBackendGMock *gmock = reinterpret_cast <CCSGSettingsBackendGMock *> (ccsObjectGetPrivate (backend.get ())); |
4436 | + |
4437 | + GVariantBuilder builder; |
4438 | + |
4439 | + g_variant_builder_init (&builder, G_VARIANT_TYPE ("as")); |
4440 | + g_variant_builder_add (&builder, "s", existingProfileName.c_str ()); |
4441 | + |
4442 | + GVariant *existingProfiles = g_variant_builder_end (&builder); |
4443 | + |
4444 | + EXPECT_CALL (*gmock, getExistingProfiles ()).WillOnce (Return (existingProfiles)); |
4445 | + EXPECT_CALL (*gmock, setExistingProfiles (AllOf (IsVariantSubtypeOf ("as"), |
4446 | + GVariantHasValueInArray<const gchar *> ("s", |
4447 | + newProfileName.c_str (), |
4448 | + boost::bind (streq, _1, _2))))) |
4449 | + .WillOnce (WithArgs <0> (Invoke (g_variant_unref))); |
4450 | + |
4451 | + ccsGSettingsBackendAddProfileDefault (backend.get (), newProfileName.c_str ()); |
4452 | +} |
4453 | + |
4454 | +TEST_F(CCSGSettingsTestProfiles, TestUpdateCurrentProfileNameAppendNew) |
4455 | +{ |
4456 | + boost::shared_ptr <CCSBackend> backend (ccsGSettingsBackendGMockNew (), |
4457 | + boost::bind (ccsGSettingsBackendGMockFree, _1)); |
4458 | + CCSGSettingsBackendGMock *gmock = reinterpret_cast <CCSGSettingsBackendGMock *> (ccsObjectGetPrivate (backend.get ())); |
4459 | + |
4460 | + EXPECT_CALL (*gmock, addProfile (Eq (newProfileName))); |
4461 | + EXPECT_CALL (*gmock, setCurrentProfile (Eq (newProfileName))); |
4462 | + |
4463 | + ccsGSettingsBackendUpdateCurrentProfileNameDefault (backend.get (), newProfileName.c_str ()); |
4464 | +} |
4465 | + |
4466 | +TEST_F(CCSGSettingsTestProfiles, TestUpdateCurrentProfileNameExisting) |
4467 | +{ |
4468 | + boost::shared_ptr <CCSBackend> backend (ccsGSettingsBackendGMockNew (), |
4469 | + boost::bind (ccsGSettingsBackendGMockFree, _1)); |
4470 | + CCSGSettingsBackendGMock *gmock = reinterpret_cast <CCSGSettingsBackendGMock *> (ccsObjectGetPrivate (backend.get ())); |
4471 | + |
4472 | + EXPECT_CALL (*gmock, addProfile (Eq (existingProfileName))); |
4473 | + EXPECT_CALL (*gmock, setCurrentProfile (Eq (existingProfileName))); |
4474 | + |
4475 | + ccsGSettingsBackendUpdateCurrentProfileNameDefault (backend.get (), existingProfileName.c_str ()); |
4476 | +} |
4477 | + |
4478 | +TEST_F(CCSGSettingsTestProfiles, TestDeleteProfileExistingProfile) |
4479 | +{ |
4480 | + boost::shared_ptr <CCSBackend> backend (ccsGSettingsBackendGMockNew (), |
4481 | + boost::bind (ccsGSettingsBackendGMockFree, _1)); |
4482 | + boost::shared_ptr <CCSContext> context (ccsMockContextNew (), |
4483 | + boost::bind (ccsFreeMockContext, _1)); |
4484 | + |
4485 | + CCSGSettingsBackendGMock *mockBackend = reinterpret_cast <CCSGSettingsBackendGMock *> (ccsObjectGetPrivate (backend.get ())); |
4486 | + |
4487 | + std::string currentProfile ("foo"); |
4488 | + std::string otherProfile ("other"); |
4489 | + |
4490 | + GVariant *existingProfiles = NULL; |
4491 | + GVariantBuilder existingProfilesBuilder; |
4492 | + |
4493 | + g_variant_builder_init (&existingProfilesBuilder, G_VARIANT_TYPE ("as")); |
4494 | + g_variant_builder_add (&existingProfilesBuilder, "s", currentProfile.c_str ()); |
4495 | + g_variant_builder_add (&existingProfilesBuilder, "s", otherProfile.c_str ()); |
4496 | + |
4497 | + existingProfiles = g_variant_builder_end (&existingProfilesBuilder); |
4498 | + |
4499 | + EXPECT_CALL (*mockBackend, getPluginsWithSetKeys ()).WillOnce (ReturnNull ()); |
4500 | + EXPECT_CALL (*mockBackend, unsetAllChangedPluginKeysInProfile (context.get (), NULL, Eq (currentProfile))); |
4501 | + EXPECT_CALL (*mockBackend, clearPluginsWithSetKeys ()); |
4502 | + |
4503 | + EXPECT_CALL (*mockBackend, getCurrentProfile ()).WillOnce (Return (currentProfile.c_str ())); |
4504 | + EXPECT_CALL (*mockBackend, getExistingProfiles ()).WillOnce (Return (existingProfiles)); |
4505 | + EXPECT_CALL (*mockBackend, setExistingProfiles (AllOf (IsVariantSubtypeOf ("as"), |
4506 | + Not (GVariantHasValueInArray<const gchar *> ("s", |
4507 | + currentProfile.c_str (), |
4508 | + boost::bind (streq, _1, _2))), |
4509 | + GVariantHasValueInArray<const gchar *> ("s", |
4510 | + otherProfile.c_str (), |
4511 | + boost::bind (streq, _1, _2))))) |
4512 | + .WillOnce (WithArgs <0> (Invoke (g_variant_unref))); |
4513 | + |
4514 | + EXPECT_CALL (*mockBackend, updateProfile (context.get ())); |
4515 | + |
4516 | + deleteProfile (backend.get (), context.get (), currentProfile.c_str ()); |
4517 | +} |
4518 | + |
4519 | TEST_F(CCSGSettingsTestIndependent, TestGetSchemaNameForPlugin) |
4520 | { |
4521 | const gchar *plugin = "foo"; |
4522 | @@ -88,6 +298,32 @@ |
4523 | EXPECT_EQ (std::string (keyname), "plugin-option"); |
4524 | } |
4525 | |
4526 | +TEST_F(CCSGSettingsTestIndependent, TestTranslateKeyForGSettingsNoTrunc) |
4527 | +{ |
4528 | + std::string keyname ("FoO_BaR"); |
4529 | + std::string expected ("foo-bar"); |
4530 | + |
4531 | + CharacterWrapper translated (translateKeyForGSettings (keyname.c_str ())); |
4532 | + |
4533 | + EXPECT_EQ (std::string (translated), expected); |
4534 | +} |
4535 | + |
4536 | +TEST_F(CCSGSettingsTestIndependent, TestTranslateKeyForGSettingsTrunc) |
4537 | +{ |
4538 | + const unsigned int OVER_KEY_SIZE = MAX_GSETTINGS_KEY_SIZE + 1; |
4539 | + std::string keyname; |
4540 | + |
4541 | + for (unsigned int i = 0; i <= OVER_KEY_SIZE - 1; i++) |
4542 | + keyname.push_back ('a'); |
4543 | + |
4544 | + ASSERT_EQ (keyname.size (), OVER_KEY_SIZE); |
4545 | + |
4546 | + CharacterWrapper translated (translateKeyForGSettings (keyname.c_str ())); |
4547 | + std::string stringOfTranslated (translated); |
4548 | + |
4549 | + EXPECT_EQ (stringOfTranslated.size (), MAX_GSETTINGS_KEY_SIZE); |
4550 | +} |
4551 | + |
4552 | TEST_F(CCSGSettingsTestIndependent, TestTranslateKeyForCCS) |
4553 | { |
4554 | std::string keyname ("plugin-option"); |
4555 | @@ -165,6 +401,22 @@ |
4556 | g_free (pluginName); |
4557 | } |
4558 | |
4559 | +TEST_F(CCSGSettingsTestIndependent, TestDecomposeGSettingsPathBadPathname) |
4560 | +{ |
4561 | + std::string compiz_gsettings_path ("org/this/path/is/wrong/"); |
4562 | + std::string fake_option_path ("PROFILENAME/plugins/PLUGINNAME"); |
4563 | + |
4564 | + compiz_gsettings_path += fake_option_path; |
4565 | + |
4566 | + CharacterWrapper pluginName (strdup ("aaa")); |
4567 | + char *pluginNameC = pluginName; |
4568 | + unsigned int screenNum = 1; |
4569 | + |
4570 | + EXPECT_FALSE (decomposeGSettingsPath (compiz_gsettings_path.c_str (), &pluginNameC, &screenNum)); |
4571 | + EXPECT_EQ (std::string (pluginNameC), "aaa"); |
4572 | + EXPECT_EQ (screenNum, 1); |
4573 | +} |
4574 | + |
4575 | TEST_F(CCSGSettingsTestIndependent, TestMakeCompizProfilePath) |
4576 | { |
4577 | gchar *a = makeCompizProfilePath ("alpha"); |
4578 | @@ -259,6 +511,11 @@ |
4579 | { |
4580 | return g_variant_type_is_array (g_variant_get_type (v)); |
4581 | } |
4582 | + |
4583 | + gboolean unknown (GVariant *) |
4584 | + { |
4585 | + return FALSE; |
4586 | + } |
4587 | } |
4588 | |
4589 | struct ArrayVariantInfo |
4590 | @@ -275,6 +532,7 @@ |
4591 | const char *vInt = "i"; |
4592 | const char *vDouble = "d"; |
4593 | const char *vArray = "as"; |
4594 | + const char *vUnknown = ""; |
4595 | |
4596 | ArrayVariantInfo arrayVariantInfo[] = |
4597 | { |
4598 | @@ -288,7 +546,8 @@ |
4599 | { &GVariantSubtypeWrappers::edge, TypeEdge, vString }, |
4600 | { &GVariantSubtypeWrappers::integer, TypeInt, vInt }, |
4601 | { &GVariantSubtypeWrappers::doubleprecision, TypeFloat, vDouble }, |
4602 | - { &GVariantSubtypeWrappers::list, TypeList, vArray } |
4603 | + { &GVariantSubtypeWrappers::list, TypeList, vArray }, |
4604 | + { &GVariantSubtypeWrappers::unknown, TypeNum, vUnknown } |
4605 | }; |
4606 | } |
4607 | |
4608 | @@ -365,6 +624,7 @@ |
4609 | |
4610 | virtual void SetUp () |
4611 | { |
4612 | + CCSGSettingsTestIndependent::SetUp (); |
4613 | builder = g_variant_builder_new (G_VARIANT_TYPE ("as")); |
4614 | |
4615 | g_variant_builder_add (builder, "s", "foo"); |
4616 | @@ -382,6 +642,7 @@ |
4617 | { |
4618 | g_variant_unref (writtenPlugins); |
4619 | g_strfreev (newWrittenPlugins); |
4620 | + CCSGSettingsTestIndependent::TearDown (); |
4621 | } |
4622 | |
4623 | protected: |
4624 | @@ -418,58 +679,72 @@ |
4625 | EXPECT_EQ (std::string (newWrittenPlugins[1]), std::string ("bar")); |
4626 | } |
4627 | |
4628 | -class CCSGSettingsTestGObjectListWithProperty : |
4629 | +class CCSGSettingsTestGSettingsWrapperWithSchemaName : |
4630 | public CCSGSettingsTestIndependent |
4631 | { |
4632 | public: |
4633 | |
4634 | - virtual void SetUp () |
4635 | - { |
4636 | - g_type_init (); |
4637 | - |
4638 | - objectSchemaList = NULL; |
4639 | - } |
4640 | - |
4641 | - virtual void TearDown () |
4642 | - { |
4643 | - GList *iter = objectSchemaList; |
4644 | - |
4645 | - while (iter) |
4646 | - { |
4647 | - g_object_unref ((GObject *) iter->data); |
4648 | - iter = g_list_next (iter); |
4649 | - } |
4650 | - |
4651 | - g_list_free (objectSchemaList); |
4652 | - objectSchemaList = NULL; |
4653 | - } |
4654 | - |
4655 | - CCSGSettingsWrapGSettings * AddObjectWithSchemaName (const std::string &schemaName) |
4656 | - { |
4657 | - CCSGSettingsWrapGSettings *wrapGSettingsObject = |
4658 | - compizconfig_gsettings_wrap_gsettings_new (COMPIZCONFIG_GSETTINGS_TYPE_MOCK_WRAP_GSETTINGS, schemaName.c_str ()); |
4659 | - objectSchemaList = g_list_append (objectSchemaList, wrapGSettingsObject); |
4660 | - |
4661 | - return wrapGSettingsObject; |
4662 | - } |
4663 | + typedef std::tr1::tuple <boost::shared_ptr <CCSGSettingsWrapper>, CCSGSettingsWrapperGMock *> WrapperMock; |
4664 | + |
4665 | + CCSGSettingsTestGSettingsWrapperWithSchemaName () : |
4666 | + objectSchemaGList (NULL) |
4667 | + { |
4668 | + CCSGSettingsTestIndependent::SetUp (); |
4669 | + } |
4670 | + |
4671 | + ~CCSGSettingsTestGSettingsWrapperWithSchemaName () |
4672 | + { |
4673 | + g_list_free (objectSchemaGList); |
4674 | + CCSGSettingsTestIndependent::TearDown (); |
4675 | + } |
4676 | + |
4677 | + WrapperMock |
4678 | + AddObject () |
4679 | + { |
4680 | + boost::shared_ptr <CCSGSettingsWrapper> wrapper (ccsMockGSettingsWrapperNew (), |
4681 | + boost::bind (ccsGSettingsWrapperUnref, _1)); |
4682 | + CCSGSettingsWrapperGMock *gmockWrapper = reinterpret_cast <CCSGSettingsWrapperGMock *> (ccsObjectGetPrivate (wrapper.get ())); |
4683 | + |
4684 | + objectSchemaGList = g_list_append (objectSchemaGList, wrapper.get ()); |
4685 | + objectSchemaList.push_back (wrapper); |
4686 | + |
4687 | + return WrapperMock (wrapper, gmockWrapper); |
4688 | + } |
4689 | + |
4690 | + static const std::string VALUE_FOO; |
4691 | + static const std::string VALUE_BAR; |
4692 | + static const std::string VALUE_BAZ; |
4693 | |
4694 | protected: |
4695 | |
4696 | - GList *objectSchemaList; |
4697 | + GList *objectSchemaGList; |
4698 | + std::vector <boost::shared_ptr <CCSGSettingsWrapper> > objectSchemaList; |
4699 | }; |
4700 | |
4701 | -TEST_F(CCSGSettingsTestGObjectListWithProperty, TestFindExistingObjectWithSchema) |
4702 | +const std::string CCSGSettingsTestGSettingsWrapperWithSchemaName::VALUE_FOO = "foo"; |
4703 | +const std::string CCSGSettingsTestGSettingsWrapperWithSchemaName::VALUE_BAR = "bar"; |
4704 | +const std::string CCSGSettingsTestGSettingsWrapperWithSchemaName::VALUE_BAZ = "baz"; |
4705 | + |
4706 | +TEST_F(CCSGSettingsTestGSettingsWrapperWithSchemaName, TestFindExistingObjectWithSchema) |
4707 | { |
4708 | - GObject *obj = reinterpret_cast <GObject *> (AddObjectWithSchemaName ("foo")); |
4709 | - |
4710 | - EXPECT_EQ (findObjectInListWithPropertySchemaName ("foo", objectSchemaList), obj); |
4711 | + WrapperMock wr1 (AddObject ()); |
4712 | + WrapperMock wr2 (AddObject ()); |
4713 | + |
4714 | + EXPECT_CALL (*(std::tr1::get <1> (wr1)), getSchemaName ()).WillRepeatedly (Return (VALUE_BAR.c_str ())); |
4715 | + EXPECT_CALL (*(std::tr1::get <1> (wr2)), getSchemaName ()).WillRepeatedly (Return (VALUE_FOO.c_str ())); |
4716 | + |
4717 | + EXPECT_EQ (findCCSGSettingsWrapperBySchemaName (VALUE_FOO.c_str (), objectSchemaGList), (std::tr1::get <0> (wr2)).get ()); |
4718 | } |
4719 | |
4720 | -TEST_F(CCSGSettingsTestGObjectListWithProperty, TestNoFindNonexistingObjectWithSchema) |
4721 | +TEST_F(CCSGSettingsTestGSettingsWrapperWithSchemaName, TestNoFindNonexistingObjectWithSchema) |
4722 | { |
4723 | - AddObjectWithSchemaName ("bar"); |
4724 | - |
4725 | - EXPECT_EQ (NULL, findObjectInListWithPropertySchemaName ("foo", objectSchemaList)); |
4726 | + WrapperMock wr1 (AddObject ()); |
4727 | + WrapperMock wr2 (AddObject ()); |
4728 | + |
4729 | + EXPECT_CALL (*(std::tr1::get <1> (wr1)), getSchemaName ()).WillRepeatedly (Return (VALUE_BAR.c_str ())); |
4730 | + EXPECT_CALL (*(std::tr1::get <1> (wr2)), getSchemaName ()).WillRepeatedly (Return (VALUE_BAZ.c_str ())); |
4731 | + |
4732 | + EXPECT_THAT (findCCSGSettingsWrapperBySchemaName (VALUE_FOO.c_str (), objectSchemaGList), IsNull ()); |
4733 | } |
4734 | |
4735 | class CCSGSettingsTestFindSettingLossy : |
4736 | @@ -479,6 +754,7 @@ |
4737 | |
4738 | virtual void SetUp () |
4739 | { |
4740 | + CCSGSettingsTestIndependent::SetUp (); |
4741 | settingList = NULL; |
4742 | } |
4743 | |
4744 | @@ -486,6 +762,7 @@ |
4745 | { |
4746 | ccsSettingListFree (settingList, TRUE); |
4747 | settingList = NULL; |
4748 | + CCSGSettingsTestIndependent::TearDown (); |
4749 | } |
4750 | |
4751 | CCSSetting * AddMockSettingWithNameAndType (char *name, |
4752 | @@ -726,14 +1003,18 @@ |
4753 | |
4754 | typedef boost::function <GList * (void)> PopulateFunc; |
4755 | |
4756 | - GListContainerEqualityBase (const PopulateFunc &populateGList) : |
4757 | - mList (populateGList ()) |
4758 | + GListContainerEqualityBase (const PopulateFunc &populateGList) |
4759 | { |
4760 | + g_setenv ("G_SLICE", "always-malloc", 1); |
4761 | + mList = populateGList (); |
4762 | + g_unsetenv ("G_SLICE"); |
4763 | } |
4764 | |
4765 | - GListContainerEqualityBase (const GListContainerEqualityBase &other) : |
4766 | - mList (g_list_copy (other.mList)) |
4767 | + GListContainerEqualityBase (const GListContainerEqualityBase &other) |
4768 | { |
4769 | + g_setenv ("G_SLICE", "always-malloc", 1); |
4770 | + mList = g_list_copy (other.mList); |
4771 | + g_unsetenv ("G_SLICE"); |
4772 | } |
4773 | |
4774 | GListContainerEqualityBase & |
4775 | @@ -869,3 +1150,872 @@ |
4776 | |
4777 | INSTANTIATE_TEST_CASE_P(CCSGSettingsTestVariantTypeToCCSTypeListInstantiation, CCSGSettingsTestVariantTypeToCCSTypeListFixture, |
4778 | ValuesIn (variantTypeToListOfCCSTypes)); |
4779 | + |
4780 | +TEST_F(CCSGSettingsTestIndependent, TestGetNameForCCSSetting) |
4781 | +{ |
4782 | + CCSSetting *setting = ccsMockSettingNew (); |
4783 | + CCSSettingGMock *gmock = (CCSSettingGMock *) ccsObjectGetPrivate (setting); |
4784 | + char *rawSettingName = strdup ("FoO_BaR"); |
4785 | + char *properSettingName = translateKeyForGSettings (rawSettingName); |
4786 | + |
4787 | + EXPECT_CALL (*gmock, getName ()).WillOnce (Return (rawSettingName)); |
4788 | + |
4789 | + char *translatedSettingName = getNameForCCSSetting (setting); |
4790 | + |
4791 | + EXPECT_EQ (std::string (translatedSettingName), std::string (properSettingName)); |
4792 | + EXPECT_NE (std::string (translatedSettingName), std::string (rawSettingName)); |
4793 | + |
4794 | + free (translatedSettingName); |
4795 | + free (properSettingName); |
4796 | + free (rawSettingName); |
4797 | + |
4798 | + ccsSettingUnref (setting); |
4799 | +} |
4800 | + |
4801 | +TEST_F(CCSGSettingsTestIndependent, TestReadVariantIsValidNULL) |
4802 | +{ |
4803 | + EXPECT_FALSE (checkReadVariantIsValid (NULL, TypeNum, "foo/bar")); |
4804 | +} |
4805 | + |
4806 | +TEST_F(CCSGSettingsTestIndependent, TestReadVariantIsValidTypeBad) |
4807 | +{ |
4808 | + GVariant *v = g_variant_new ("i", 1); |
4809 | + |
4810 | + EXPECT_FALSE (checkReadVariantIsValid (v, TypeString, "foo/bar")); |
4811 | + |
4812 | + g_variant_unref (v); |
4813 | +} |
4814 | + |
4815 | +TEST_F(CCSGSettingsTestIndependent, TestReadVariantIsValidTypeGood) |
4816 | +{ |
4817 | + GVariant *v = g_variant_new ("i", 1); |
4818 | + |
4819 | + EXPECT_TRUE (checkReadVariantIsValid (v, TypeInt, "foo/bar")); |
4820 | + |
4821 | + g_variant_unref (v); |
4822 | +} |
4823 | + |
4824 | +typedef CCSSettingValueList (*ReadValueListOfDataTypeFunc) (GVariantIter *, guint nItems, CCSSetting *setting); |
4825 | + |
4826 | +class ReadListValueTypeTestParam |
4827 | +{ |
4828 | + public: |
4829 | + |
4830 | + typedef boost::function <CCSSettingValueList (GVariantIter *, |
4831 | + guint nItems, |
4832 | + CCSSetting *setting, |
4833 | + CCSObjectAllocationInterface *allocator)> ReadValueListFunc; |
4834 | + typedef boost::function <GVariant * ()> GVariantPopulator; |
4835 | + typedef boost::function <CCSSettingValueList (CCSSetting *)> CCSSettingValueListPopulator; |
4836 | + |
4837 | + ReadListValueTypeTestParam (const ReadValueListFunc &readFunc, |
4838 | + const GVariantPopulator &variantPopulator, |
4839 | + const CCSSettingValueListPopulator &listPopulator, |
4840 | + const CCSSettingType &type) : |
4841 | + mReadFunc (readFunc), |
4842 | + mVariantPopulator (variantPopulator), |
4843 | + mListPopulator (listPopulator), |
4844 | + mType (type) |
4845 | + { |
4846 | + } |
4847 | + |
4848 | + CCSSettingValueList read (GVariantIter *iter, |
4849 | + guint nItems, |
4850 | + CCSSetting *setting, |
4851 | + CCSObjectAllocationInterface *allocator) const |
4852 | + { |
4853 | + return mReadFunc (iter, nItems, setting, allocator); |
4854 | + } |
4855 | + |
4856 | + boost::shared_ptr <GVariant> populateVariant () const |
4857 | + { |
4858 | + return boost::shared_ptr <GVariant> (mVariantPopulator (), boost::bind (g_variant_unref, _1)); |
4859 | + } |
4860 | + |
4861 | + boost::shared_ptr <_CCSSettingValueList> populateList (CCSSetting *setting) const |
4862 | + { |
4863 | + return boost::shared_ptr <_CCSSettingValueList> (mListPopulator (setting), boost::bind (ccsSettingValueListFree, _1, TRUE)); |
4864 | + } |
4865 | + |
4866 | + CCSSettingType type () const { return mType; } |
4867 | + |
4868 | + private: |
4869 | + |
4870 | + ReadValueListFunc mReadFunc; |
4871 | + GVariantPopulator mVariantPopulator; |
4872 | + CCSSettingValueListPopulator mListPopulator; |
4873 | + CCSSettingType mType; |
4874 | + |
4875 | +}; |
4876 | + |
4877 | +namespace compizconfig |
4878 | +{ |
4879 | + namespace test |
4880 | + { |
4881 | + namespace impl |
4882 | + { |
4883 | + namespace populators |
4884 | + { |
4885 | + namespace variant |
4886 | + { |
4887 | + GVariant * boolean () |
4888 | + { |
4889 | + GVariantBuilder vb; |
4890 | + g_variant_builder_init (&vb, G_VARIANT_TYPE ("ab")); |
4891 | + g_variant_builder_add (&vb, "b", boolValues[0]); |
4892 | + g_variant_builder_add (&vb, "b", boolValues[1]); |
4893 | + g_variant_builder_add (&vb, "b", boolValues[2]); |
4894 | + return g_variant_builder_end (&vb); |
4895 | + } |
4896 | + |
4897 | + GVariant * integer () |
4898 | + { |
4899 | + GVariantBuilder vb; |
4900 | + g_variant_builder_init (&vb, G_VARIANT_TYPE ("ai")); |
4901 | + g_variant_builder_add (&vb, "i", intValues[0]); |
4902 | + g_variant_builder_add (&vb, "i", intValues[1]); |
4903 | + g_variant_builder_add (&vb, "i", intValues[2]); |
4904 | + return g_variant_builder_end (&vb); |
4905 | + } |
4906 | + |
4907 | + GVariant * doubleprecision () |
4908 | + { |
4909 | + GVariantBuilder vb; |
4910 | + g_variant_builder_init (&vb, G_VARIANT_TYPE ("ad")); |
4911 | + g_variant_builder_add (&vb, "d", floatValues[0]); |
4912 | + g_variant_builder_add (&vb, "d", floatValues[1]); |
4913 | + g_variant_builder_add (&vb, "d", floatValues[2]); |
4914 | + return g_variant_builder_end (&vb); |
4915 | + } |
4916 | + |
4917 | + GVariant * string () |
4918 | + { |
4919 | + GVariantBuilder vb; |
4920 | + g_variant_builder_init (&vb, G_VARIANT_TYPE ("as")); |
4921 | + g_variant_builder_add (&vb, "s", stringValues[0]); |
4922 | + g_variant_builder_add (&vb, "s", stringValues[1]); |
4923 | + g_variant_builder_add (&vb, "s", stringValues[2]); |
4924 | + return g_variant_builder_end (&vb); |
4925 | + } |
4926 | + |
4927 | + GVariant * color () |
4928 | + { |
4929 | + GVariantBuilder vb; |
4930 | + |
4931 | + CharacterWrapper s1 (ccsColorToString (&(getColorValueList ()[0]))); |
4932 | + CharacterWrapper s2 (ccsColorToString (&(getColorValueList ()[1]))); |
4933 | + CharacterWrapper s3 (ccsColorToString (&(getColorValueList ()[2]))); |
4934 | + |
4935 | + char * c1 = s1; |
4936 | + char * c2 = s2; |
4937 | + char * c3 = s3; |
4938 | + |
4939 | + g_variant_builder_init (&vb, G_VARIANT_TYPE ("as")); |
4940 | + g_variant_builder_add (&vb, "s", c1); |
4941 | + g_variant_builder_add (&vb, "s", c2); |
4942 | + g_variant_builder_add (&vb, "s", c3); |
4943 | + return g_variant_builder_end (&vb); |
4944 | + } |
4945 | + } |
4946 | + } |
4947 | + } |
4948 | + } |
4949 | +} |
4950 | + |
4951 | +class CCSGSettingsTestReadListValueTypes : |
4952 | + public ::testing::TestWithParam <ReadListValueTypeTestParam> |
4953 | +{ |
4954 | +}; |
4955 | + |
4956 | +TEST_P(CCSGSettingsTestReadListValueTypes, TestListValueGoodAllocation) |
4957 | +{ |
4958 | + boost::shared_ptr <GVariant> variant = GetParam ().populateVariant (); |
4959 | + boost::shared_ptr <CCSSetting> mockSetting (ccsNiceMockSettingNew (), boost::bind (ccsFreeMockSetting, _1)); |
4960 | + NiceMock <CCSSettingGMock> *gmockSetting = reinterpret_cast <NiceMock <CCSSettingGMock> *> (ccsObjectGetPrivate (mockSetting.get ())); |
4961 | + |
4962 | + ON_CALL (*gmockSetting, getType ()).WillByDefault (Return (TypeList)); |
4963 | + |
4964 | + CCSSettingInfo info = |
4965 | + { |
4966 | + .forList = |
4967 | + { |
4968 | + GetParam ().type (), |
4969 | + NULL |
4970 | + } |
4971 | + }; |
4972 | + |
4973 | + boost::shared_ptr <_CCSSettingValueList> valueList (GetParam ().populateList (mockSetting.get ())); |
4974 | + GVariantIter iter; |
4975 | + |
4976 | + g_variant_iter_init (&iter, variant.get ()); |
4977 | + |
4978 | + ON_CALL (*gmockSetting, getInfo ()).WillByDefault (Return (&info)); |
4979 | + ON_CALL (*gmockSetting, getDefaultValue ()).WillByDefault (ReturnNull ()); |
4980 | + |
4981 | + boost::shared_ptr <_CCSSettingValueList> readValueList (GetParam ().read (&iter, |
4982 | + 3, |
4983 | + mockSetting.get (), |
4984 | + &ccsDefaultObjectAllocator), |
4985 | + boost::bind (ccsSettingValueListFree, _1, TRUE)); |
4986 | + |
4987 | + EXPECT_TRUE (ccsCompareLists (valueList.get (), readValueList.get (), info.forList)); |
4988 | +} |
4989 | + |
4990 | +TEST_P(CCSGSettingsTestReadListValueTypes, TestListValueThroughListValueDispatch) |
4991 | +{ |
4992 | + boost::shared_ptr <GVariant> variant = GetParam ().populateVariant (); |
4993 | + boost::shared_ptr <CCSSetting> mockSetting (ccsNiceMockSettingNew (), boost::bind (ccsFreeMockSetting, _1)); |
4994 | + NiceMock <CCSSettingGMock> *gmockSetting = reinterpret_cast <NiceMock <CCSSettingGMock> *> (ccsObjectGetPrivate (mockSetting.get ())); |
4995 | + |
4996 | + ON_CALL (*gmockSetting, getType ()).WillByDefault (Return (TypeList)); |
4997 | + |
4998 | + CCSSettingInfo info = |
4999 | + { |
5000 | + .forList = |
The diff has been truncated for viewing.