Merge lp:~compiz-team/compiz-compizconfig-gsettings/compiz-compizconfig-gsettings.fix_874815 into lp:compiz-compizconfig-gsettings

Proposed by Sam Spilsbury
Status: Superseded
Proposed branch: lp:~compiz-team/compiz-compizconfig-gsettings/compiz-compizconfig-gsettings.fix_874815
Merge into: lp:compiz-compizconfig-gsettings
Diff against target: 2275 lines (+2252/-0) (has conflicts)
2 files modified
src/gconf-integration.c (+957/-0)
src/gsettings.c (+1295/-0)
Text conflict in src/gconf-integration.c
Text conflict in src/gsettings.c
To merge this branch: bzr merge lp:~compiz-team/compiz-compizconfig-gsettings/compiz-compizconfig-gsettings.fix_874815
Reviewer Review Type Date Requested Status
Sam Spilsbury Pending
Review via email: mp+79453@code.launchpad.net

This proposal has been superseded by a proposal from 2011-10-26.

Description of the change

To post a comment you must log in.
159. By Sam Spilsbury

Fix conflicts

160. By Sam Spilsbury

Merge in changes from truncation branch

161. By Sam Spilsbury

More descriptive names

Unmerged revisions

161. By Sam Spilsbury

More descriptive names

160. By Sam Spilsbury

Merge in changes from truncation branch

159. By Sam Spilsbury

Fix conflicts

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/gconf-integration.c'
2--- src/gconf-integration.c 2011-07-24 14:28:26 +0000
3+++ src/gconf-integration.c 2011-10-15 07:07:06 +0000
4@@ -1,3 +1,4 @@
5+<<<<<<< TREE
6 /**
7 *
8 * GSettings libccs backend
9@@ -952,3 +953,959 @@
10 g_error_free (err);
11 }
12 #endif
13+=======
14+/**
15+ *
16+ * GSettings libccs backend
17+ *
18+ * gconf-integration.c
19+ *
20+ * Copyright (c) 2011 Canonical Ltd
21+ *
22+ * Based on the original compizconfig-backend-gconf
23+ *
24+ * Copyright (c) 2007 Danny Baumann <maniac@opencompositing.org>
25+ *
26+ * Parts of this code are taken from libberylsettings
27+ * gconf backend, written by:
28+ *
29+ * Copyright (c) 2006 Robert Carr <racarr@opencompositing.org>
30+ * Copyright (c) 2007 Dennis Kasprzyk <onestone@opencompositing.org>
31+ *
32+ * This program is free software; you can redistribute it and/or
33+ * modify it under the terms of the GNU General Public License
34+ * as published by the Free Software Foundation; either version 2
35+ * of the License, or (at your option) any later version.
36+ *
37+ * This program is distributed in the hope that it will be useful,
38+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
39+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
40+ * GNU General Public License for more details.
41+ *
42+ * Authored By:
43+ * Sam Spilsbury <sam.spilsbury@canonical.com>
44+ *
45+ **/
46+
47+#include "gsettings.h"
48+#ifdef USE_GCONF
49+GConfClient *client = NULL;
50+guint gnomeGConfNotifyIds[NUM_WATCHED_DIRS];
51+
52+const SpecialOptionGConf specialOptions[] = {
53+ {"run_key", "gnomecompat", FALSE,
54+ METACITY "/global_keybindings/panel_run_dialog", OptionKey},
55+ {"main_menu_key", "gnomecompat", FALSE,
56+ METACITY "/global_keybindings/panel_main_menu", OptionKey},
57+ {"run_command_screenshot_key", "gnomecompat", FALSE,
58+ METACITY "/global_keybindings/run_command_screenshot", OptionKey},
59+ {"run_command_window_screenshot_key", "gnomecompat", FALSE,
60+ METACITY "/global_keybindings/run_command_window_screenshot", OptionKey},
61+ {"run_command_terminal_key", "gnomecompat", FALSE,
62+ METACITY "/global_keybindings/run_command_terminal", OptionKey},
63+
64+ {"toggle_window_maximized_key", "core", FALSE,
65+ METACITY "/window_keybindings/toggle_maximized", OptionKey},
66+ {"minimize_window_key", "core", FALSE,
67+ METACITY "/window_keybindings/minimize", OptionKey},
68+ {"maximize_window_key", "core", FALSE,
69+ METACITY "/window_keybindings/maximize", OptionKey},
70+ {"unmaximize_window_key", "core", FALSE,
71+ METACITY "/window_keybindings/unmaximize", OptionKey},
72+ {"maximize_window_horizontally_key", "core", FALSE,
73+ METACITY "/window_keybindings/maximize_horizontally", OptionKey},
74+ {"maximize_window_vertically_key", "core", FALSE,
75+ METACITY "/window_keybindings/maximize_vertically", OptionKey},
76+ {"raise_window_key", "core", FALSE,
77+ METACITY "/window_keybindings/raise", OptionKey},
78+ {"lower_window_key", "core", FALSE,
79+ METACITY "/window_keybindings/lower", OptionKey},
80+ {"close_window_key", "core", FALSE,
81+ METACITY "/window_keybindings/close", OptionKey},
82+ {"toggle_window_shaded_key", "core", FALSE,
83+ METACITY "/window_keybindings/toggle_shaded", OptionKey},
84+
85+ {"show_desktop_key", "core", FALSE,
86+ METACITY "/global_keybindings/show_desktop", OptionKey},
87+
88+ {"initiate_key", "move", FALSE,
89+ METACITY "/window_keybindings/begin_move", OptionKey},
90+ {"initiate_key", "resize", FALSE,
91+ METACITY "/window_keybindings/begin_resize", OptionKey},
92+ {"window_menu_key", "core", FALSE,
93+ METACITY "/window_keybindings/activate_window_menu", OptionKey},
94+
95+ /* integration of Metacity's mouse_button_modifier option */
96+ {"initiate_button", "move", FALSE,
97+ METACITY "/window_keybindings/begin_move", OptionSpecial},
98+ {"initiate_button", "resize", FALSE,
99+ METACITY "/window_keybindings/begin_resize", OptionSpecial},
100+ {"window_menu_button", "core", FALSE,
101+ METACITY "/window_keybindings/activate_window_menu", OptionSpecial},
102+ {"mouse_button_modifier", NULL, FALSE,
103+ METACITY "/general/mouse_button_modifier", OptionSpecial},
104+ /* integration of the Metacity's option to swap mouse buttons */
105+ {"resize_with_right_button", NULL, FALSE,
106+ METACITY "/general/resize_with_right_button", OptionSpecial},
107+
108+ {"visual_bell", "fade", TRUE,
109+ METACITY "/general/visual_bell", OptionBool},
110+ {"fullscreen_visual_bell", "fade", TRUE,
111+ METACITY "/general/visual_bell_type", OptionSpecial},
112+
113+ {"next_key", "staticswitcher", FALSE,
114+ METACITY "/global_keybindings/switch_windows", OptionKey},
115+ {"prev_key", "staticswitcher", FALSE,
116+ METACITY "/global_keybindings/switch_windows_backward", OptionKey},
117+
118+ {"toggle_sticky_key", "extrawm", FALSE,
119+ METACITY "/window_keybindings/toggle_on_all_workspaces", OptionKey},
120+ {"toggle_fullscreen_key", "extrawm", FALSE,
121+ METACITY "/window_keybindings/toggle_fullscreen", OptionKey},
122+
123+ {"command0", "commands", FALSE,
124+ METACITY "/keybinding_commands/command_1", OptionString},
125+ {"command1", "commands", FALSE,
126+ METACITY "/keybinding_commands/command_2", OptionString},
127+ {"command2", "commands", FALSE,
128+ METACITY "/keybinding_commands/command_3", OptionString},
129+ {"command3", "commands", FALSE,
130+ METACITY "/keybinding_commands/command_4", OptionString},
131+ {"command4", "commands", FALSE,
132+ METACITY "/keybinding_commands/command_5", OptionString},
133+ {"command5", "commands", FALSE,
134+ METACITY "/keybinding_commands/command_6", OptionString},
135+ {"command6", "commands", FALSE,
136+ METACITY "/keybinding_commands/command_7", OptionString},
137+ {"command7", "commands", FALSE,
138+ METACITY "/keybinding_commands/command_8", OptionString},
139+ {"command8", "commands", FALSE,
140+ METACITY "/keybinding_commands/command_9", OptionString},
141+ {"command9", "commands", FALSE,
142+ METACITY "/keybinding_commands/command_10", OptionString},
143+ {"command10", "commands", FALSE,
144+ METACITY "/keybinding_commands/command_11", OptionString},
145+ {"command11", "commands", FALSE,
146+ METACITY "/keybinding_commands/command_12", OptionString},
147+
148+ {"run_command0_key", "commands", FALSE,
149+ METACITY "/global_keybindings/run_command_1", OptionKey},
150+ {"run_command1_key", "commands", FALSE,
151+ METACITY "/global_keybindings/run_command_2", OptionKey},
152+ {"run_command2_key", "commands", FALSE,
153+ METACITY "/global_keybindings/run_command_3", OptionKey},
154+ {"run_command3_key", "commands", FALSE,
155+ METACITY "/global_keybindings/run_command_4", OptionKey},
156+ {"run_command4_key", "commands", FALSE,
157+ METACITY "/global_keybindings/run_command_5", OptionKey},
158+ {"run_command5_key", "commands", FALSE,
159+ METACITY "/global_keybindings/run_command_6", OptionKey},
160+ {"run_command6_key", "commands", FALSE,
161+ METACITY "/global_keybindings/run_command_7", OptionKey},
162+ {"run_command7_key", "commands", FALSE,
163+ METACITY "/global_keybindings/run_command_8", OptionKey},
164+ {"run_command8_key", "commands", FALSE,
165+ METACITY "/global_keybindings/run_command_9", OptionKey},
166+ {"run_command9_key", "commands", FALSE,
167+ METACITY "/global_keybindings/run_command_10", OptionKey},
168+ {"run_command10_key", "commands", FALSE,
169+ METACITY "/global_keybindings/run_command_11", OptionKey},
170+ {"run_command11_key", "commands", FALSE,
171+ METACITY "/global_keybindings/run_command_12", OptionKey},
172+
173+ {"rotate_to_1_key", "rotate", FALSE,
174+ METACITY "/global_keybindings/switch_to_workspace_1", OptionKey},
175+ {"rotate_to_2_key", "rotate", FALSE,
176+ METACITY "/global_keybindings/switch_to_workspace_2", OptionKey},
177+ {"rotate_to_3_key", "rotate", FALSE,
178+ METACITY "/global_keybindings/switch_to_workspace_3", OptionKey},
179+ {"rotate_to_4_key", "rotate", FALSE,
180+ METACITY "/global_keybindings/switch_to_workspace_4", OptionKey},
181+ {"rotate_to_5_key", "rotate", FALSE,
182+ METACITY "/global_keybindings/switch_to_workspace_5", OptionKey},
183+ {"rotate_to_6_key", "rotate", FALSE,
184+ METACITY "/global_keybindings/switch_to_workspace_6", OptionKey},
185+ {"rotate_to_7_key", "rotate", FALSE,
186+ METACITY "/global_keybindings/switch_to_workspace_7", OptionKey},
187+ {"rotate_to_8_key", "rotate", FALSE,
188+ METACITY "/global_keybindings/switch_to_workspace_8", OptionKey},
189+ {"rotate_to_9_key", "rotate", FALSE,
190+ METACITY "/global_keybindings/switch_to_workspace_9", OptionKey},
191+ {"rotate_to_10_key", "rotate", FALSE,
192+ METACITY "/global_keybindings/switch_to_workspace_10", OptionKey},
193+ {"rotate_to_11_key", "rotate", FALSE,
194+ METACITY "/global_keybindings/switch_to_workspace_11", OptionKey},
195+ {"rotate_to_12_key", "rotate", FALSE,
196+ METACITY "/global_keybindings/switch_to_workspace_12", OptionKey},
197+
198+ {"rotate_left_key", "rotate", FALSE,
199+ METACITY "/global_keybindings/switch_to_workspace_left", OptionKey},
200+ {"rotate_right_key", "rotate", FALSE,
201+ METACITY "/global_keybindings/switch_to_workspace_right", OptionKey},
202+
203+ {"switch_to_1_key", "vpswitch", FALSE,
204+ METACITY "/global_keybindings/switch_to_workspace_1", OptionKey},
205+ {"switch_to_2_key", "vpswitch", FALSE,
206+ METACITY "/global_keybindings/switch_to_workspace_2", OptionKey},
207+ {"switch_to_3_key", "vpswitch", FALSE,
208+ METACITY "/global_keybindings/switch_to_workspace_3", OptionKey},
209+ {"switch_to_4_key", "vpswitch", FALSE,
210+ METACITY "/global_keybindings/switch_to_workspace_4", OptionKey},
211+ {"switch_to_5_key", "vpswitch", FALSE,
212+ METACITY "/global_keybindings/switch_to_workspace_5", OptionKey},
213+ {"switch_to_6_key", "vpswitch", FALSE,
214+ METACITY "/global_keybindings/switch_to_workspace_6", OptionKey},
215+ {"switch_to_7_key", "vpswitch", FALSE,
216+ METACITY "/global_keybindings/switch_to_workspace_7", OptionKey},
217+ {"switch_to_8_key", "vpswitch", FALSE,
218+ METACITY "/global_keybindings/switch_to_workspace_8", OptionKey},
219+ {"switch_to_9_key", "vpswitch", FALSE,
220+ METACITY "/global_keybindings/switch_to_workspace_9", OptionKey},
221+ {"switch_to_10_key", "vpswitch", FALSE,
222+ METACITY "/global_keybindings/switch_to_workspace_10", OptionKey},
223+ {"switch_to_11_key", "vpswitch", FALSE,
224+ METACITY "/global_keybindings/switch_to_workspace_11", OptionKey},
225+ {"switch_to_12_key", "vpswitch", FALSE,
226+ METACITY "/global_keybindings/switch_to_workspace_12", OptionKey},
227+
228+ {"up_key", "wall", FALSE,
229+ METACITY "/global_keybindings/switch_to_workspace_up", OptionKey},
230+ {"down_key", "wall", FALSE,
231+ METACITY "/global_keybindings/switch_to_workspace_down", OptionKey},
232+ {"left_key", "wall", FALSE,
233+ METACITY "/global_keybindings/switch_to_workspace_left", OptionKey},
234+ {"right_key", "wall", FALSE,
235+ METACITY "/global_keybindings/switch_to_workspace_right", OptionKey},
236+ {"left_window_key", "wall", FALSE,
237+ METACITY "/window_keybindings/move_to_workspace_left", OptionKey},
238+ {"right_window_key", "wall", FALSE,
239+ METACITY "/window_keybindings/move_to_workspace_right", OptionKey},
240+ {"up_window_key", "wall", FALSE,
241+ METACITY "/window_keybindings/move_to_workspace_up", OptionKey},
242+ {"down_window_key", "wall", FALSE,
243+ METACITY "/window_keybindings/move_to_workspace_down", OptionKey},
244+
245+ {"put_topleft_key", "put", FALSE,
246+ METACITY "/window_keybindings/move_to_corner_nw", OptionKey},
247+ {"put_topright_key", "put", FALSE,
248+ METACITY "/window_keybindings/move_to_corner_ne", OptionKey},
249+ {"put_bottomleft_key", "put", FALSE,
250+ METACITY "/window_keybindings/move_to_corner_sw", OptionKey},
251+ {"put_bottomright_key", "put", FALSE,
252+ METACITY "/window_keybindings/move_to_corner_se", OptionKey},
253+ {"put_left_key", "put", FALSE,
254+ METACITY "/window_keybindings/move_to_side_w", OptionKey},
255+ {"put_right_key", "put", FALSE,
256+ METACITY "/window_keybindings/move_to_side_e", OptionKey},
257+ {"put_top_key", "put", FALSE,
258+ METACITY "/window_keybindings/move_to_side_n", OptionKey},
259+ {"put_bottom_key", "put", FALSE,
260+ METACITY "/window_keybindings/move_to_side_s", OptionKey},
261+
262+ {"rotate_to_1_window_key", "rotate", FALSE,
263+ METACITY "/window_keybindings/move_to_workspace_1", OptionKey},
264+ {"rotate_to_2_window_key", "rotate", FALSE,
265+ METACITY "/window_keybindings/move_to_workspace_2", OptionKey},
266+ {"rotate_to_3_window_key", "rotate", FALSE,
267+ METACITY "/window_keybindings/move_to_workspace_3", OptionKey},
268+ {"rotate_to_4_window_key", "rotate", FALSE,
269+ METACITY "/window_keybindings/move_to_workspace_4", OptionKey},
270+ {"rotate_to_5_window_key", "rotate", FALSE,
271+ METACITY "/window_keybindings/move_to_workspace_5", OptionKey},
272+ {"rotate_to_6_window_key", "rotate", FALSE,
273+ METACITY "/window_keybindings/move_to_workspace_6", OptionKey},
274+ {"rotate_to_7_window_key", "rotate", FALSE,
275+ METACITY "/window_keybindings/move_to_workspace_7", OptionKey},
276+ {"rotate_to_8_window_key", "rotate", FALSE,
277+ METACITY "/window_keybindings/move_to_workspace_8", OptionKey},
278+ {"rotate_to_9_window_key", "rotate", FALSE,
279+ METACITY "/window_keybindings/move_to_workspace_9", OptionKey},
280+ {"rotate_to_10_window_key", "rotate", FALSE,
281+ METACITY "/window_keybindings/move_to_workspace_10", OptionKey},
282+ {"rotate_to_11_window_key", "rotate", FALSE,
283+ METACITY "/window_keybindings/move_to_workspace_11", OptionKey},
284+ {"rotate_to_12_window_key", "rotate", FALSE,
285+ METACITY "/window_keybindings/move_to_workspace_12", OptionKey},
286+
287+ {"rotate_left_window_key", "rotate", FALSE,
288+ METACITY "/window_keybindings/move_to_workspace_left", OptionKey},
289+ {"rotate_right_window_key", "rotate", FALSE,
290+ METACITY "/window_keybindings/move_to_workspace_right", OptionKey},
291+
292+ {"command_screenshot", "gnomecompat", FALSE,
293+ METACITY "/keybinding_commands/command_screenshot", OptionString},
294+ {"command_window_screenshot", "gnomecompat", FALSE,
295+ METACITY "/keybinding_commands/command_window_screenshot", OptionString},
296+ {"command_terminal", "gnomecompat", FALSE,
297+ "/desktop/gnome/applications/terminal/exec", OptionString},
298+
299+ {"current_viewport", "thumbnail", TRUE,
300+ "/apps/panel/applets/window_list/prefs/display_all_workspaces",
301+ OptionSpecial},
302+
303+ {"autoraise", "core", FALSE,
304+ METACITY "/general/auto_raise", OptionBool},
305+ {"autoraise_delay", "core", FALSE,
306+ METACITY "/general/auto_raise_delay", OptionInt},
307+ {"raise_on_click", "core", FALSE,
308+ METACITY "/general/raise_on_click", OptionBool},
309+ {"click_to_focus", "core", FALSE,
310+ METACITY "/general/focus_mode", OptionSpecial},
311+
312+ {"audible_bell", "core", FALSE,
313+ METACITY "/general/audible_bell", OptionBool},
314+ /*{"hsize", "core", TRUE,
315+ METACITY "/general/num_workspaces", OptionInt},*/
316+};
317+
318+static const char* watchedGConfGnomeDirectories[] = {
319+ METACITY,
320+ "/desktop/gnome/applications/terminal",
321+ "/apps/panel/applets/window_list/prefs"
322+};
323+
324+#define N_SOPTIONS (sizeof (specialOptions) / sizeof (struct _SpecialOptionGConf))
325+
326+static CCSSetting *
327+findDisplaySettingForPlugin (CCSContext *context,
328+ const char *plugin,
329+ const char *setting)
330+{
331+ CCSPlugin *p;
332+ CCSSetting *s;
333+
334+ p = ccsFindPlugin (context, plugin);
335+ if (!p)
336+ return NULL;
337+
338+ s = ccsFindSetting (p, setting);
339+ if (!s)
340+ return NULL;
341+
342+ return s;
343+}
344+
345+Bool
346+isGConfIntegratedOption (CCSSetting *setting,
347+ int *index)
348+{
349+ unsigned int i;
350+
351+ for (i = 0; i < N_SOPTIONS; i++)
352+ {
353+ const SpecialOptionGConf *opt = &specialOptions[i];
354+
355+ if (strcmp (setting->name, opt->settingName) != 0)
356+ continue;
357+
358+ if (setting->parent->name)
359+ {
360+ if (!opt->pluginName)
361+ continue;
362+ if (strcmp (setting->parent->name, opt->pluginName) != 0)
363+ continue;
364+ }
365+ else
366+ {
367+ if (opt->pluginName)
368+ continue;
369+ }
370+
371+ if (index)
372+ *index = i;
373+
374+ return TRUE;
375+ }
376+
377+ return FALSE;
378+}
379+
380+void
381+gnomeGConfValueChanged (GConfClient *client,
382+ guint cnxn_id,
383+ GConfEntry *entry,
384+ gpointer user_data)
385+{
386+ CCSContext *context = (CCSContext *)user_data;
387+ char *keyName = (char*) gconf_entry_get_key (entry);
388+ int i, last = 0, num = 0;
389+ Bool needInit = TRUE;
390+
391+ if (!ccsGetIntegrationEnabled (context))
392+ return;
393+
394+ /* we have to loop multiple times here, because one Gnome
395+ option may be integrated with multiple Compiz options */
396+
397+ while (1)
398+ {
399+ for (i = last, num = -1; i < N_SOPTIONS; i++)
400+ {
401+ if (strcmp (specialOptions[i].gnomeName, keyName) == 0)
402+ {
403+ num = i;
404+ last = i + 1;
405+ break;
406+ }
407+ }
408+
409+ if (num < 0)
410+ break;
411+
412+ if ((strcmp (specialOptions[num].settingName,
413+ "mouse_button_modifier") == 0) ||
414+ (strcmp (specialOptions[num].settingName,
415+ "resize_with_right_button") == 0))
416+ {
417+ CCSSetting *s;
418+
419+ if (needInit)
420+ {
421+ readInit (context);
422+ needInit = FALSE;
423+ }
424+
425+ s = findDisplaySettingForPlugin (context, "core",
426+ "window_menu_button");
427+ if (s)
428+ readSetting (context, s);
429+
430+ s = findDisplaySettingForPlugin (context, "move",
431+ "initiate_button");
432+ if (s)
433+ readSetting (context, s);
434+
435+ s = findDisplaySettingForPlugin (context, "resize",
436+ "initiate_button");
437+ if (s)
438+ readSetting (context, s);
439+ }
440+ else
441+ {
442+ CCSPlugin *plugin = NULL;
443+ CCSSetting *setting;
444+ SpecialOptionGConf *opt = (SpecialOptionGConf *) &specialOptions[num];
445+
446+ plugin = ccsFindPlugin (context, (char*) opt->pluginName);
447+ if (plugin)
448+ {
449+ for (i = 0; i < 1; i++)
450+ {
451+ setting = ccsFindSetting (plugin, (char*) opt->settingName);
452+
453+ if (setting)
454+ {
455+ if (needInit)
456+ {
457+ readInit (context);
458+ needInit = FALSE;
459+ }
460+ readSetting (context, setting);
461+ }
462+
463+ /* do not read display settings multiple
464+ times for multiscreen environments */
465+ }
466+ }
467+ }
468+ }
469+}
470+
471+void
472+initGConfClient (CCSContext *context)
473+{
474+ int i;
475+
476+ client = gconf_client_get_default ();
477+
478+ for (i = 0; i < NUM_WATCHED_DIRS; i++)
479+ {
480+ gnomeGConfNotifyIds[i] = gconf_client_notify_add (client,
481+ watchedGConfGnomeDirectories[i],
482+ gnomeGConfValueChanged, context,
483+ NULL, NULL);
484+ gconf_client_add_dir (client, watchedGConfGnomeDirectories[i],
485+ GCONF_CLIENT_PRELOAD_NONE, NULL);
486+ }
487+}
488+
489+void
490+finiGConfClient (void)
491+{
492+ int i;
493+
494+ for (i = 0; i < NUM_WATCHED_DIRS; i++)
495+ {
496+ if (gnomeGConfNotifyIds[i])
497+ {
498+ gconf_client_notify_remove (client, gnomeGConfNotifyIds[0]);
499+ gnomeGConfNotifyIds[i] = 0;
500+ }
501+ gconf_client_remove_dir (client, watchedGConfGnomeDirectories[i], NULL);
502+ }
503+ gconf_client_suggest_sync (client, NULL);
504+
505+ g_object_unref (client);
506+ client = NULL;
507+}
508+
509+static unsigned int
510+getGnomeMouseButtonModifier(void)
511+{
512+ unsigned int modMask = 0;
513+ GError *err = NULL;
514+ char *value;
515+
516+ value = gconf_client_get_string (client,
517+ METACITY "/general/mouse_button_modifier",
518+ &err);
519+
520+ if (err)
521+ {
522+ g_error_free (err);
523+ return 0;
524+ }
525+
526+ if (!value)
527+ return 0;
528+
529+ modMask = ccsStringToModifiers (value);
530+ g_free (value);
531+
532+ return modMask;
533+}
534+
535+static unsigned int
536+getButtonBindingForSetting (CCSContext *context,
537+ const char *plugin,
538+ const char *setting)
539+{
540+ CCSSetting *s;
541+
542+ s = findDisplaySettingForPlugin (context, plugin, setting);
543+ if (!s)
544+ return 0;
545+
546+ if (s->type != TypeButton)
547+ return 0;
548+
549+ return s->value->value.asButton.button;
550+}
551+
552+Bool
553+readGConfIntegratedOption (CCSContext *context,
554+ CCSSetting *setting,
555+ int index)
556+{
557+ GConfValue *gconfValue;
558+ GError *err = NULL;
559+ Bool ret = FALSE;
560+
561+ ret = readOption (setting);
562+
563+ gconfValue = gconf_client_get (client,
564+ specialOptions[index].gnomeName,
565+ &err);
566+
567+ if (err)
568+ {
569+ g_error_free (err);
570+ return FALSE;
571+ }
572+
573+ if (!gconfValue)
574+ return FALSE;
575+
576+ switch (specialOptions[index].type) {
577+ case OptionInt:
578+ if (gconfValue->type == GCONF_VALUE_INT)
579+ {
580+ guint value;
581+
582+ value = gconf_value_get_int (gconfValue);
583+ ccsSetInt (setting, value, TRUE);
584+ ret = TRUE;
585+ }
586+ break;
587+ case OptionBool:
588+ if (gconfValue->type == GCONF_VALUE_BOOL)
589+ {
590+ gboolean value;
591+
592+ value = gconf_value_get_bool (gconfValue);
593+ ccsSetBool (setting, value ? TRUE : FALSE, FALSE);
594+ ret = TRUE;
595+ }
596+ break;
597+ case OptionString:
598+ if (gconfValue->type == GCONF_VALUE_STRING)
599+ {
600+ const char *value;
601+
602+ value = gconf_value_get_string (gconfValue);
603+ if (value)
604+ {
605+ ccsSetString (setting, value, FALSE);
606+ ret = TRUE;
607+ }
608+ }
609+ break;
610+ case OptionKey:
611+ if (gconfValue->type == GCONF_VALUE_STRING)
612+ {
613+ const char *value;
614+
615+ value = gconf_value_get_string (gconfValue);
616+ if (value)
617+ {
618+ CCSSettingKeyValue key;
619+
620+ memset (&key, 0, sizeof (CCSSettingKeyValue));
621+ ccsGetKey (setting, &key);
622+ if (ccsStringToKeyBinding (value, &key))
623+ {
624+ ccsSetKey (setting, key, TRUE);
625+ ret = TRUE;
626+ }
627+ }
628+ }
629+ break;
630+ case OptionSpecial:
631+ {
632+ const char *settingName = specialOptions[index].settingName;
633+ const char *pluginName = specialOptions[index].pluginName;
634+
635+ if (strcmp (settingName, "current_viewport") == 0)
636+ {
637+ if (gconfValue->type == GCONF_VALUE_BOOL)
638+ {
639+ gboolean showAll;
640+
641+ showAll = gconf_value_get_bool (gconfValue);
642+ ccsSetBool (setting, !showAll, FALSE);
643+ ret = TRUE;
644+ }
645+ }
646+ else if (strcmp (settingName, "fullscreen_visual_bell") == 0)
647+ {
648+ if (gconfValue->type == GCONF_VALUE_STRING)
649+ {
650+ const char *value;
651+
652+ value = gconf_value_get_string (gconfValue);
653+ if (value)
654+ {
655+ Bool fullscreen;
656+
657+ fullscreen = strcmp (value, "fullscreen") == 0;
658+ ccsSetBool (setting, fullscreen, FALSE);
659+ ret = TRUE;
660+ }
661+ }
662+ }
663+ else if (strcmp (settingName, "click_to_focus") == 0)
664+ {
665+ if (gconfValue->type == GCONF_VALUE_STRING)
666+ {
667+ const char *focusMode;
668+
669+ focusMode = gconf_value_get_string (gconfValue);
670+
671+ if (focusMode)
672+ {
673+ Bool clickToFocus = (strcmp (focusMode, "click") == 0);
674+ ccsSetBool (setting, clickToFocus, FALSE);
675+ ret = TRUE;
676+ }
677+ }
678+ }
679+ else if (((strcmp (settingName, "initiate_button") == 0) &&
680+ ((strcmp (pluginName, "move") == 0) ||
681+ (strcmp (pluginName, "resize") == 0))) ||
682+ ((strcmp (settingName, "window_menu_button") == 0) &&
683+ (strcmp (pluginName, "core") == 0)))
684+ {
685+ gboolean resizeWithRightButton;
686+ CCSSettingButtonValue button;
687+
688+ memset (&button, 0, sizeof (CCSSettingButtonValue));
689+ ccsGetButton (setting, &button);
690+
691+ button.buttonModMask = getGnomeMouseButtonModifier ();
692+
693+ resizeWithRightButton =
694+ gconf_client_get_bool (client, METACITY
695+ "/general/resize_with_right_button",
696+ &err);
697+
698+ if (strcmp (settingName, "window_menu_button") == 0)
699+ button.button = resizeWithRightButton ? 2 : 3;
700+ else if (strcmp (pluginName, "resize") == 0)
701+ button.button = resizeWithRightButton ? 3 : 2;
702+ else
703+ button.button = 1;
704+
705+ ccsSetButton (setting, button, FALSE);
706+ ret = TRUE;
707+ }
708+ }
709+ break;
710+ default:
711+ break;
712+ }
713+
714+ gconf_value_free (gconfValue);
715+
716+ return ret;
717+}
718+
719+static Bool
720+setGnomeMouseButtonModifier (unsigned int modMask)
721+{
722+ char *modifiers, *currentValue;
723+ GError *err = NULL;
724+
725+ modifiers = ccsModifiersToString (modMask);
726+ if (!modifiers)
727+ return FALSE;
728+
729+ currentValue = gconf_client_get_string (client,
730+ METACITY
731+ "/general/mouse_button_modifier",
732+ &err);
733+ if (err)
734+ {
735+ free (modifiers);
736+ g_error_free (err);
737+ return FALSE;
738+ }
739+
740+ if (!currentValue || (strcmp (currentValue, modifiers) != 0))
741+ gconf_client_set_string (client,
742+ METACITY "/general/mouse_button_modifier",
743+ modifiers, NULL);
744+ if (currentValue)
745+ g_free (currentValue);
746+
747+ free (modifiers);
748+
749+ return TRUE;
750+}
751+
752+static void
753+setButtonBindingForSetting (CCSContext *context,
754+ const char *plugin,
755+ const char *setting,
756+ unsigned int button,
757+ unsigned int buttonModMask)
758+{
759+ CCSSetting *s;
760+ CCSSettingButtonValue value;
761+
762+ s = findDisplaySettingForPlugin (context, plugin, setting);
763+ if (!s)
764+ return;
765+
766+ if (s->type != TypeButton)
767+ return;
768+
769+ value = s->value->value.asButton;
770+
771+ if ((value.button != button) || (value.buttonModMask != buttonModMask))
772+ {
773+ value.button = button;
774+ value.buttonModMask = buttonModMask;
775+
776+ ccsSetButton (s, value, FALSE);
777+ }
778+}
779+
780+void
781+writeGConfIntegratedOption (CCSContext *context,
782+ CCSSetting *setting,
783+ int index)
784+{
785+ GError *err = NULL;
786+ const char *optionName = specialOptions[index].gnomeName;
787+
788+ switch (specialOptions[index].type)
789+ {
790+ case OptionInt:
791+ {
792+ int newValue, currentValue;
793+ if (!ccsGetInt (setting, &newValue))
794+ break;
795+ currentValue = gconf_client_get_int (client, optionName, &err);
796+
797+ if (!err && (currentValue != newValue))
798+ gconf_client_set_int(client, specialOptions[index].gnomeName,
799+ newValue, NULL);
800+ }
801+ break;
802+ case OptionBool:
803+ {
804+ Bool newValue;
805+ gboolean currentValue;
806+ if (!ccsGetBool (setting, &newValue))
807+ break;
808+ currentValue = gconf_client_get_bool (client, optionName, &err);
809+
810+ if (!err && ((currentValue && !newValue) ||
811+ (!currentValue && newValue)))
812+ gconf_client_set_bool (client, specialOptions[index].gnomeName,
813+ newValue, NULL);
814+ }
815+ break;
816+ case OptionString:
817+ {
818+ char *newValue;
819+ gchar *currentValue;
820+ if (!ccsGetString (setting, &newValue))
821+ break;
822+ currentValue = gconf_client_get_string (client, optionName, &err);
823+
824+ if (!err && currentValue)
825+ {
826+ if (strcmp (currentValue, newValue) != 0)
827+ gconf_client_set_string (client, optionName,
828+ newValue, NULL);
829+ g_free (currentValue);
830+ }
831+ }
832+ break;
833+ case OptionKey:
834+ {
835+ char *newValue;
836+ gchar *currentValue;
837+
838+ newValue = ccsKeyBindingToString (&setting->value->value.asKey);
839+ if (newValue)
840+ {
841+ if (strcmp (newValue, "Disabled") == 0)
842+ {
843+ /* Metacity doesn't like "Disabled", it wants "disabled" */
844+ newValue[0] = 'd';
845+ }
846+
847+ currentValue = gconf_client_get_string (client,
848+ optionName, &err);
849+
850+ if (!err && currentValue)
851+ {
852+ if (strcmp (currentValue, newValue) != 0)
853+ gconf_client_set_string (client, optionName,
854+ newValue, NULL);
855+ g_free (currentValue);
856+ }
857+ free (newValue);
858+ }
859+ }
860+ break;
861+ case OptionSpecial:
862+ {
863+ const char *settingName = specialOptions[index].settingName;
864+ const char *pluginName = specialOptions[index].pluginName;
865+
866+ if (strcmp (settingName, "current_viewport") == 0)
867+ {
868+ Bool currentViewport;
869+
870+ if (!ccsGetBool (setting, &currentViewport))
871+ break;
872+
873+ gconf_client_set_bool (client, optionName,
874+ !currentViewport, NULL);
875+ }
876+ else if (strcmp (settingName, "fullscreen_visual_bell") == 0)
877+ {
878+ Bool fullscreen;
879+ gchar *currentValue, *newValue;
880+ if (!ccsGetBool (setting, &fullscreen))
881+ break;
882+
883+ newValue = fullscreen ? "fullscreen" : "frame_flash";
884+ currentValue = gconf_client_get_string (client,
885+ optionName, &err);
886+ if (!err && currentValue)
887+ {
888+ if (strcmp (currentValue, newValue) != 0)
889+ gconf_client_set_string (client, optionName,
890+ newValue, NULL);
891+ g_free (currentValue);
892+ }
893+ }
894+ else if (strcmp (settingName, "click_to_focus") == 0)
895+ {
896+ Bool clickToFocus;
897+ gchar *newValue, *currentValue;
898+ if (!ccsGetBool (setting, &clickToFocus))
899+ break;
900+
901+ newValue = clickToFocus ? "click" : "sloppy";
902+ currentValue = gconf_client_get_string (client,
903+ optionName, &err);
904+
905+ if (!err && currentValue)
906+ {
907+ if (strcmp (currentValue, newValue) != 0)
908+ gconf_client_set_string (client, optionName,
909+ newValue, NULL);
910+ g_free (currentValue);
911+ }
912+ }
913+ else if (((strcmp (settingName, "initiate_button") == 0) &&
914+ ((strcmp (pluginName, "move") == 0) ||
915+ (strcmp (pluginName, "resize") == 0))) ||
916+ ((strcmp (settingName, "window_menu_button") == 0) &&
917+ (strcmp (pluginName, "core") == 0)))
918+ {
919+ unsigned int modMask;
920+ Bool resizeWithRightButton = FALSE;
921+ gboolean currentValue;
922+
923+ if ((getButtonBindingForSetting (context, "resize",
924+ "initiate_button") == 3) ||
925+ (getButtonBindingForSetting (context, "core",
926+ "window_menu_button") == 2))
927+ {
928+ resizeWithRightButton = TRUE;
929+ }
930+
931+ currentValue =
932+ gconf_client_get_bool (client, METACITY
933+ "/general/resize_with_right_button",
934+ &err);
935+
936+ if (!err && ((currentValue && !resizeWithRightButton) ||
937+ (!currentValue && resizeWithRightButton)))
938+ {
939+ gconf_client_set_bool (client,
940+ METACITY
941+ "/general/resize_with_right_button",
942+ resizeWithRightButton, NULL);
943+ }
944+
945+ modMask = setting->value->value.asButton.buttonModMask;
946+ if (setGnomeMouseButtonModifier (modMask))
947+ {
948+ setButtonBindingForSetting (context, "move",
949+ "initiate_button", 1, modMask);
950+ setButtonBindingForSetting (context, "resize",
951+ "initiate_button",
952+ resizeWithRightButton ? 3 : 2,
953+ modMask);
954+ setButtonBindingForSetting (context, "core",
955+ "window_menu_button",
956+ resizeWithRightButton ? 2 : 3,
957+ modMask);
958+ }
959+ }
960+ }
961+ break;
962+ }
963+
964+ if (err)
965+ g_error_free (err);
966+}
967+#endif
968+>>>>>>> MERGE-SOURCE
969
970=== modified file 'src/gsettings.c'
971--- src/gsettings.c 2011-07-29 15:41:46 +0000
972+++ src/gsettings.c 2011-10-15 07:07:06 +0000
973@@ -1,3 +1,4 @@
974+<<<<<<< TREE
975 /**
976 *
977 * GSettings libccs backend
978@@ -1255,3 +1256,1297 @@
979 return &gsettingsVTable;
980 }
981
982+=======
983+/**
984+ *
985+ * GSettings libccs backend
986+ *
987+ * gsettings.c
988+ *
989+ * Copyright (c) 2011 Canonical Ltd
990+ *
991+ * Based on the original compizconfig-backend-gconf
992+ *
993+ * Copyright (c) 2007 Danny Baumann <maniac@opencompositing.org>
994+ *
995+ * Parts of this code are taken from libberylsettings
996+ * gconf backend, written by:
997+ *
998+ * Copyright (c) 2006 Robert Carr <racarr@opencompositing.org>
999+ * Copyright (c) 2007 Dennis Kasprzyk <onestone@opencompositing.org>
1000+ *
1001+ * This program is free software; you can redistribute it and/or
1002+ * modify it under the terms of the GNU General Public License
1003+ * as published by the Free Software Foundation; either version 2
1004+ * of the License, or (at your option) any later version.
1005+ *
1006+ * This program is distributed in the hope that it will be useful,
1007+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1008+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1009+ * GNU General Public License for more details.
1010+ *
1011+ * Authored By:
1012+ * Sam Spilsbury <sam.spilsbury@canonical.com>
1013+ *
1014+ **/
1015+
1016+#include "gsettings.h"
1017+
1018+static void
1019+valueChanged (GSettings *settings,
1020+ gchar *keyname,
1021+ gpointer user_data);
1022+
1023+static void
1024+gnomeValueChanged (GSettings *settings,
1025+ gchar *keyname,
1026+ gpointer user_data);
1027+
1028+static GList *settingsList = NULL;
1029+static GSettings *compizconfigSettings = NULL;
1030+static GSettings *currentProfileSettings = NULL;
1031+static GList *watchedGnomeSettings = NULL;
1032+
1033+char *currentProfile = NULL;
1034+
1035+/* some forward declarations */
1036+static void writeIntegratedOption (CCSContext *context,
1037+ CCSSetting *setting,
1038+ int index);
1039+
1040+typedef struct _SpecialOptionGSettings {
1041+ const char* settingName;
1042+ const char* pluginName;
1043+ const char* schemaName;
1044+ const char* keyName;
1045+ const char* type;
1046+} SpecialOption;
1047+
1048+static gchar *
1049+getSchemaNameForPlugin (const char *plugin)
1050+{
1051+ gchar *schemaName = NULL;
1052+
1053+ schemaName = g_strconcat (COMPIZ_SCHEMA_ID, ".", plugin, NULL);
1054+
1055+ return schemaName;
1056+}
1057+
1058+static inline gchar *
1059+translateKeyForGSettings (char *gsettingName)
1060+{
1061+ gchar *clean = NULL;
1062+ gchar **delimited = NULL;
1063+ guint i = 0;
1064+
1065+ /* Replace underscores with dashes */
1066+ delimited = g_strsplit (gsettingName, "_", 0);
1067+
1068+ clean = g_strjoinv ("-", delimited);
1069+
1070+ /* It can't be more than 32 chars, warn if that's the case */
1071+ gchar *ret = g_strndup (clean, 31);
1072+
1073+ if (strlen (clean) > 31)
1074+ printf ("GSettings Backend: Warning: key name %s is not valid in GSettings, it was changed to %s, this may cause problems!\n", clean, ret);
1075+
1076+ /* Everything must be lowercase */
1077+ for (; i < strlen (ret); i++)
1078+ ret[i] = g_ascii_tolower (ret[i]);
1079+
1080+ g_free (clean);
1081+ g_strfreev (delimited);
1082+
1083+ return ret;
1084+}
1085+
1086+static inline gchar *
1087+translateKeyForCCS (char *gsettingName)
1088+{
1089+ gchar *clean = NULL;
1090+ gchar **delimited = NULL;
1091+
1092+ /* Replace dashes with underscores */
1093+ delimited = g_strsplit (gsettingName, "-", 0);
1094+
1095+ clean = g_strjoinv ("_", delimited);
1096+
1097+ /* FIXME: Truncated and lowercased settings aren't going to work */
1098+
1099+ g_strfreev (delimited);
1100+
1101+ return clean;
1102+}
1103+
1104+static GSettings *
1105+getSettingsObjectForPluginWithPath (const char *plugin,
1106+ const char *path,
1107+ CCSContext *context)
1108+{
1109+ GSettings *settingsObj = NULL;
1110+ GList *l = settingsList;
1111+ gchar *schemaName = getSchemaNameForPlugin (plugin);
1112+ GVariant *writtenPlugins;
1113+ char *plug;
1114+ GVariant *newWrittenPlugins;
1115+ GVariantBuilder *newWrittenPluginsBuilder;
1116+ GVariantIter *iter;
1117+ gboolean found = FALSE;
1118+
1119+ while (l)
1120+ {
1121+ settingsObj = (GSettings *) l->data;
1122+ gchar *name = NULL;
1123+
1124+ g_object_get (G_OBJECT (settingsObj),
1125+ "schema",
1126+ &name, NULL);
1127+ if (g_strcmp0 (name, schemaName) == 0)
1128+ {
1129+ g_free (name);
1130+ g_free (schemaName);
1131+
1132+ return settingsObj;
1133+ }
1134+
1135+ l = g_list_next (l);
1136+ }
1137+
1138+ /* No existing settings object found for this schema, create one */
1139+
1140+ settingsObj = g_settings_new_with_path (schemaName, path);
1141+
1142+ g_signal_connect (G_OBJECT (settingsObj), "changed", (GCallback) valueChanged, (gpointer) context);
1143+
1144+ settingsList = g_list_append (settingsList, (void *) settingsObj);
1145+
1146+ /* Also write the plugin name to the list of modified plugins so
1147+ * that when we delete the profile the keys for that profile are also
1148+ * unset FIXME: This could be a little more efficient, like we could
1149+ * store keys that have changed from their defaults ... though
1150+ * gsettings doesn't seem to give you a way to get all of the schemas */
1151+
1152+ writtenPlugins = g_settings_get_value (currentProfileSettings, "plugins-with-set-keys");
1153+
1154+ newWrittenPluginsBuilder = g_variant_builder_new (G_VARIANT_TYPE ("as"));
1155+
1156+ iter = g_variant_iter_new (writtenPlugins);
1157+ while (g_variant_iter_next (iter, "s", &plug))
1158+ {
1159+ g_variant_builder_add (newWrittenPluginsBuilder, "s", plug);
1160+
1161+ if (!found)
1162+ found = (g_strcmp0 (plug, plugin) == 0);
1163+
1164+ g_free (plug);
1165+ }
1166+
1167+ if (!found)
1168+ g_variant_builder_add (newWrittenPluginsBuilder, "s", plugin);
1169+
1170+ newWrittenPlugins = g_variant_new ("as", newWrittenPluginsBuilder);
1171+ g_settings_set_value (currentProfileSettings, "plugins-with-set-keys", newWrittenPlugins);
1172+
1173+ g_variant_iter_free (iter);
1174+ g_variant_unref (newWrittenPlugins);
1175+ g_variant_builder_unref (newWrittenPluginsBuilder);
1176+
1177+ return settingsObj;
1178+}
1179+
1180+static GSettings *
1181+getSettingsObjectForCCSSetting (CCSSetting *setting)
1182+{
1183+ KEYNAME(setting->parent->context->screenNum);
1184+ PATHNAME (setting->parent->name, keyName);
1185+
1186+ return getSettingsObjectForPluginWithPath (setting->parent->name, pathName, setting->parent->context);
1187+}
1188+
1189+static Bool
1190+isIntegratedOption (CCSSetting *setting,
1191+ int *index)
1192+{
1193+#ifdef USE_GCONF
1194+ return isGConfIntegratedOption (setting, index);
1195+#else
1196+ return FALSE;
1197+#endif
1198+}
1199+
1200+static void
1201+gnomeValueChanged (GSettings *settings,
1202+ gchar *keyName,
1203+ gpointer user_data)
1204+{
1205+}
1206+
1207+static void
1208+valueChanged (GSettings *settings,
1209+ gchar *keyName,
1210+ gpointer user_data)
1211+{
1212+ CCSContext *context = (CCSContext *)user_data;
1213+ char *uncleanKeyName;
1214+ char *path;
1215+ char *token;
1216+ int index;
1217+ unsigned int screenNum;
1218+ CCSPlugin *plugin;
1219+ CCSSetting *setting;
1220+
1221+ g_object_get (G_OBJECT (settings), "path", &path, NULL);
1222+
1223+ path += strlen (COMPIZ) + 1;
1224+
1225+ token = strsep (&path, "/"); /* Profile name */
1226+ if (!token)
1227+ return;
1228+
1229+ token = strsep (&path, "/"); /* plugins */
1230+ if (!token)
1231+ return;
1232+
1233+ token = strsep (&path, "/"); /* plugin */
1234+ if (!token)
1235+ return;
1236+
1237+ plugin = ccsFindPlugin (context, token);
1238+ if (!plugin)
1239+ return;
1240+
1241+ token = strsep (&path, "/"); /* screen%i */
1242+ if (!token)
1243+ return;
1244+
1245+ sscanf (token, "screen%d", &screenNum);
1246+
1247+ uncleanKeyName = translateKeyForCCS (keyName);
1248+
1249+ setting = ccsFindSetting (plugin, uncleanKeyName);
1250+
1251+ /* Try again, this time truncating the settings themselves */
1252+ if (!setting)
1253+ {
1254+ char *cleanKeyName;
1255+ CCSSettingList it = ccsGetPluginSettings (plugin);
1256+
1257+ while (it)
1258+ {
1259+ cleanKeyName = translateKeyForGSettings (((CCSSetting *) it->data)->name);
1260+
1261+ if (g_strcmp0 (cleanKeyName, keyName) == 0)
1262+ {
1263+ free (cleanKeyName);
1264+ setting = it->data;
1265+ break;
1266+ }
1267+
1268+ free (cleanKeyName);
1269+
1270+ it = it->next;
1271+ }
1272+ }
1273+
1274+ if (!setting)
1275+ {
1276+ printf ("GSettings Backend: unable to find setting %s, for path %s\n", uncleanKeyName, path);
1277+ free (uncleanKeyName);
1278+ return;
1279+ }
1280+
1281+ readInit (context);
1282+ if (!readOption (setting))
1283+ {
1284+ ccsResetToDefault (setting, TRUE);
1285+ }
1286+
1287+ if (ccsGetIntegrationEnabled (context) &&
1288+ isIntegratedOption (setting, &index))
1289+ {
1290+ writeInit (context);
1291+ writeIntegratedOption (context, setting, index);
1292+ }
1293+
1294+ free (uncleanKeyName);
1295+}
1296+
1297+static Bool
1298+readListValue (CCSSetting *setting)
1299+{
1300+ GSettings *settings = getSettingsObjectForCCSSetting (setting);
1301+ gchar *variantType;
1302+ unsigned int nItems, i = 0;
1303+ CCSSettingValueList list = NULL;
1304+ GVariant *value;
1305+ GVariantIter *iter;
1306+
1307+ char *cleanSettingName = translateKeyForGSettings (setting->name);
1308+
1309+ switch (setting->info.forList.listType)
1310+ {
1311+ case TypeString:
1312+ case TypeMatch:
1313+ case TypeColor:
1314+ variantType = g_strdup ("s");
1315+ break;
1316+ case TypeBool:
1317+ variantType = g_strdup ("b");
1318+ break;
1319+ case TypeInt:
1320+ variantType = g_strdup ("i");
1321+ break;
1322+ case TypeFloat:
1323+ variantType = g_strdup ("d");
1324+ break;
1325+ default:
1326+ variantType = NULL;
1327+ break;
1328+ }
1329+
1330+ if (!variantType)
1331+ return FALSE;
1332+
1333+ value = g_settings_get_value (settings, cleanSettingName);
1334+ if (!value)
1335+ {
1336+ ccsResetToDefault (setting, TRUE);
1337+ return TRUE;
1338+ }
1339+
1340+ iter = g_variant_iter_new (value);
1341+ nItems = g_variant_iter_n_children (iter);
1342+
1343+ if (nItems)
1344+ {
1345+ switch (setting->info.forList.listType)
1346+ {
1347+ case TypeBool:
1348+ {
1349+ Bool *array = malloc (nItems * sizeof (Bool));
1350+ Bool *arrayCounter = array;
1351+ gboolean v;
1352+
1353+ if (!array)
1354+ break;
1355+
1356+ /* Reads each item from the variant into the position pointed
1357+ * at by arrayCounter */
1358+ while (g_variant_iter_next (iter, variantType, &v))
1359+ {
1360+ *arrayCounter++ = v;
1361+ }
1362+
1363+ list = ccsGetValueListFromBoolArray (array, nItems, setting);
1364+ free (array);
1365+ }
1366+ break;
1367+ case TypeInt:
1368+ {
1369+ int *array = malloc (nItems * sizeof (int));
1370+ int *arrayCounter = array;
1371+
1372+ if (!array)
1373+ break;
1374+
1375+ /* Reads each item from the variant into the position pointed
1376+ * at by arrayCounter */
1377+ while (g_variant_iter_next (iter, variantType, arrayCounter++));
1378+
1379+ list = ccsGetValueListFromIntArray (array, nItems, setting);
1380+ free (array);
1381+ }
1382+ break;
1383+ case TypeFloat:
1384+ {
1385+ double *array = malloc (nItems * sizeof (double));
1386+ double *arrayCounter = array;
1387+
1388+ if (!array)
1389+ break;
1390+
1391+ /* Reads each item from the variant into the position pointed
1392+ * at by arrayCounter */
1393+ while (g_variant_iter_next (iter, variantType, arrayCounter++));
1394+
1395+ list = ccsGetValueListFromFloatArray ((float *) array, nItems, setting);
1396+ free (array);
1397+ }
1398+ break;
1399+ case TypeString:
1400+ case TypeMatch:
1401+ {
1402+ char **array = calloc (1, (nItems + 1) * sizeof (char *));
1403+ char **arrayCounter = array;
1404+
1405+ if (!array)
1406+ {
1407+ break;
1408+ }
1409+
1410+ /* Reads each item from the variant into the position pointed
1411+ * at by arrayCounter */
1412+ while (g_variant_iter_next (iter, variantType, arrayCounter++));
1413+
1414+ list = ccsGetValueListFromStringArray (array, nItems, setting);
1415+ for (i = 0; i < nItems; i++)
1416+ if (array[i])
1417+ free (array[i]);
1418+ free (array);
1419+ }
1420+ break;
1421+ case TypeColor:
1422+ {
1423+ CCSSettingColorValue *array;
1424+ char *colorValue;
1425+ array = malloc (nItems * sizeof (CCSSettingColorValue));
1426+ if (!array)
1427+ break;
1428+
1429+ while (g_variant_iter_next (iter, variantType, &colorValue))
1430+ {
1431+ memset (&array[i], 0, sizeof (CCSSettingColorValue));
1432+ ccsStringToColor (colorValue,
1433+ &array[i]);
1434+ }
1435+ list = ccsGetValueListFromColorArray (array, nItems, setting);
1436+ free (array);
1437+ }
1438+ break;
1439+ default:
1440+ break;
1441+ }
1442+ }
1443+
1444+ free (cleanSettingName);
1445+ free (variantType);
1446+
1447+ if (list)
1448+ {
1449+ ccsSetList (setting, list, TRUE);
1450+ ccsSettingValueListFree (list, TRUE);
1451+ return TRUE;
1452+ }
1453+ else
1454+ ccsResetToDefault (setting, TRUE);
1455+
1456+ return FALSE;
1457+}
1458+
1459+static Bool
1460+readIntegratedOption (CCSContext *context,
1461+ CCSSetting *setting,
1462+ int index)
1463+{
1464+#ifdef USE_GCONF
1465+ return readGConfIntegratedOption (context, setting, index);
1466+#else
1467+ return FALSE;
1468+#endif
1469+}
1470+
1471+Bool
1472+readOption (CCSSetting * setting)
1473+{
1474+ GSettings *settings = getSettingsObjectForCCSSetting (setting);
1475+ GVariant *gsettingsValue = NULL;
1476+ Bool ret = FALSE;
1477+ Bool valid = TRUE;
1478+
1479+ /* It is impossible for certain settings to have a schema,
1480+ * such as actions and read only settings, so in that case
1481+ * just return FALSE since compizconfig doesn't expect us
1482+ * to read them anyways */
1483+
1484+ if (setting->type == TypeAction ||
1485+ ccsSettingIsReadOnly (setting))
1486+ {
1487+ return FALSE;
1488+ }
1489+
1490+ char *cleanSettingName = translateKeyForGSettings (setting->name);
1491+ KEYNAME(setting->parent->context->screenNum);
1492+ PATHNAME (setting->parent->name, keyName);
1493+
1494+ /* first check if the key is set */
1495+ gsettingsValue = g_settings_get_value (settings, cleanSettingName);
1496+
1497+ switch (setting->type)
1498+ {
1499+ case TypeString:
1500+ case TypeMatch:
1501+ case TypeColor:
1502+ case TypeKey:
1503+ case TypeButton:
1504+ case TypeEdge:
1505+ valid = (g_variant_type_is_subtype_of (G_VARIANT_TYPE_STRING, g_variant_get_type (gsettingsValue)));
1506+ break;
1507+ case TypeInt:
1508+ valid = (g_variant_type_is_subtype_of (G_VARIANT_TYPE_INT32, g_variant_get_type (gsettingsValue)));
1509+ break;
1510+ case TypeBool:
1511+ case TypeBell:
1512+ valid = (g_variant_type_is_subtype_of (G_VARIANT_TYPE_BOOLEAN, g_variant_get_type (gsettingsValue)));
1513+ break;
1514+ case TypeFloat:
1515+ valid = (g_variant_type_is_subtype_of (G_VARIANT_TYPE_DOUBLE, g_variant_get_type (gsettingsValue)));
1516+ break;
1517+ case TypeList:
1518+ valid = (g_variant_type_is_array (g_variant_get_type (gsettingsValue)));
1519+ break;
1520+ default:
1521+ break;
1522+ }
1523+
1524+ if (!valid)
1525+ {
1526+ printf ("GSettings backend: There is an unsupported value at path %s. "
1527+ "Settings from this path won't be read. Try to remove "
1528+ "that value so that operation can continue properly.\n",
1529+ pathName);
1530+ free (cleanSettingName);
1531+ g_variant_unref (gsettingsValue);
1532+ return FALSE;
1533+ }
1534+
1535+ switch (setting->type)
1536+ {
1537+ case TypeString:
1538+ {
1539+ const char *value;
1540+ value = g_variant_get_string (gsettingsValue, NULL);
1541+ if (value)
1542+ {
1543+ ccsSetString (setting, value, FALSE);
1544+ ret = TRUE;
1545+ }
1546+ }
1547+ break;
1548+ case TypeMatch:
1549+ {
1550+ const char * value;
1551+ value = g_variant_get_string (gsettingsValue, NULL);
1552+ if (value)
1553+ {
1554+ ccsSetMatch (setting, value, FALSE);
1555+ ret = TRUE;
1556+ }
1557+ }
1558+ break;
1559+ case TypeInt:
1560+ {
1561+ int value;
1562+ value = g_variant_get_int32 (gsettingsValue);
1563+
1564+ ccsSetInt (setting, value, FALSE);
1565+ ret = TRUE;
1566+ }
1567+ break;
1568+ case TypeBool:
1569+ {
1570+ gboolean value;
1571+ value = g_variant_get_boolean (gsettingsValue);
1572+
1573+ ccsSetBool (setting, value ? TRUE : FALSE, FALSE);
1574+ ret = TRUE;
1575+ }
1576+ break;
1577+ case TypeFloat:
1578+ {
1579+ double value;
1580+ value = g_variant_get_double (gsettingsValue);
1581+
1582+ ccsSetFloat (setting, (float)value, FALSE);
1583+ ret = TRUE;
1584+ }
1585+ break;
1586+ case TypeColor:
1587+ {
1588+ const char *value;
1589+ CCSSettingColorValue color;
1590+ value = g_variant_get_string (gsettingsValue, NULL);
1591+
1592+ if (value && ccsStringToColor (value, &color))
1593+ {
1594+ ccsSetColor (setting, color, FALSE);
1595+ ret = TRUE;
1596+ }
1597+ }
1598+ break;
1599+ case TypeKey:
1600+ {
1601+ const char *value;
1602+ CCSSettingKeyValue key;
1603+ value = g_variant_get_string (gsettingsValue, NULL);
1604+
1605+ if (value && ccsStringToKeyBinding (value, &key))
1606+ {
1607+ ccsSetKey (setting, key, FALSE);
1608+ ret = TRUE;
1609+ }
1610+ }
1611+ break;
1612+ case TypeButton:
1613+ {
1614+ const char *value;
1615+ CCSSettingButtonValue button;
1616+ value = g_variant_get_string (gsettingsValue, NULL);
1617+
1618+ if (value && ccsStringToButtonBinding (value, &button))
1619+ {
1620+ ccsSetButton (setting, button, FALSE);
1621+ ret = TRUE;
1622+ }
1623+ }
1624+ break;
1625+ case TypeEdge:
1626+ {
1627+ const char *value;
1628+ value = g_variant_get_string (gsettingsValue, NULL);
1629+
1630+ if (value)
1631+ {
1632+ unsigned int edges;
1633+ edges = ccsStringToEdges (value);
1634+ ccsSetEdge (setting, edges, FALSE);
1635+ ret = TRUE;
1636+ }
1637+ }
1638+ break;
1639+ case TypeBell:
1640+ {
1641+ gboolean value;
1642+ value = g_variant_get_boolean (gsettingsValue);
1643+
1644+ ccsSetBell (setting, value ? TRUE : FALSE, FALSE);
1645+ ret = TRUE;
1646+ }
1647+ break;
1648+ case TypeList:
1649+ ret = readListValue (setting);
1650+ break;
1651+ default:
1652+ printf("GSettings backend: attempt to read unsupported setting type %d!\n",
1653+ setting->type);
1654+ break;
1655+ }
1656+
1657+ free (cleanSettingName);
1658+ g_variant_unref (gsettingsValue);
1659+
1660+ return ret;
1661+}
1662+
1663+static void
1664+writeListValue (CCSSetting *setting,
1665+ char *pathName)
1666+{
1667+ GSettings *settings = getSettingsObjectForCCSSetting (setting);
1668+ GVariant *value;
1669+ gchar *variantType = NULL;
1670+ CCSSettingValueList list;
1671+
1672+ char *cleanSettingName = translateKeyForGSettings (setting->name);
1673+
1674+ if (!ccsGetList (setting, &list))
1675+ return;
1676+
1677+ switch (setting->info.forList.listType)
1678+ {
1679+ case TypeBool:
1680+ {
1681+ variantType = "ab";
1682+ GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE ("ab"));
1683+ while (list)
1684+ {
1685+ g_variant_builder_add (builder, "b", list->data->value.asBool);
1686+ list = list->next;
1687+ }
1688+ value = g_variant_new ("ab", builder);
1689+ g_variant_builder_unref (builder);
1690+ }
1691+ break;
1692+ case TypeInt:
1693+ {
1694+ variantType = "ai";
1695+ GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE ("ai"));
1696+ while (list)
1697+ {
1698+ g_variant_builder_add (builder, "i", list->data->value.asInt);
1699+ list = list->next;
1700+ }
1701+ value = g_variant_new ("ai", builder);
1702+ g_variant_builder_unref (builder);
1703+ }
1704+ break;
1705+ case TypeFloat:
1706+ {
1707+ variantType = "ad";
1708+ GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE ("ad"));
1709+ while (list)
1710+ {
1711+ g_variant_builder_add (builder, "d", (gdouble) list->data->value.asFloat);
1712+ list = list->next;
1713+ }
1714+ value = g_variant_new ("ad", builder);
1715+ g_variant_builder_unref (builder);
1716+ }
1717+ break;
1718+ case TypeString:
1719+ {
1720+ variantType = "as";
1721+ GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE ("as"));
1722+ while (list)
1723+ {
1724+ g_variant_builder_add (builder, "s", list->data->value.asString);
1725+ list = list->next;
1726+ }
1727+ value = g_variant_new ("as", builder);
1728+ g_variant_builder_unref (builder);
1729+ }
1730+ break;
1731+ case TypeMatch:
1732+ {
1733+ variantType = "as";
1734+ GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE ("as"));
1735+ while (list)
1736+ {
1737+ g_variant_builder_add (builder, "s", list->data->value.asMatch);
1738+ list = list->next;
1739+ }
1740+ value = g_variant_new ("as", builder);
1741+ g_variant_builder_unref (builder);
1742+ }
1743+ break;
1744+ case TypeColor:
1745+ {
1746+ variantType = "as";
1747+ GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE ("as"));
1748+ char *item;
1749+ while (list)
1750+ {
1751+ item = ccsColorToString (&list->data->value.asColor);
1752+ g_variant_builder_add (builder, "s", item);
1753+ list = list->next;
1754+ }
1755+ value = g_variant_new ("as", builder);
1756+ g_variant_builder_unref (builder);
1757+ }
1758+ break;
1759+ default:
1760+ printf("GSettings backend: attempt to write unsupported list type %d!\n",
1761+ setting->info.forList.listType);
1762+ variantType = NULL;
1763+ break;
1764+ }
1765+
1766+ if (variantType != NULL)
1767+ {
1768+ g_settings_set_value (settings, cleanSettingName, value);
1769+ g_variant_unref (value);
1770+ }
1771+
1772+ free (cleanSettingName);
1773+}
1774+
1775+static void
1776+writeIntegratedOption (CCSContext *context,
1777+ CCSSetting *setting,
1778+ int index)
1779+{
1780+#ifdef USE_GCONF
1781+ writeGConfIntegratedOption (context, setting, index);
1782+#endif
1783+
1784+ return;
1785+}
1786+
1787+static void
1788+resetOptionToDefault (CCSSetting * setting)
1789+{
1790+ GSettings *settings = getSettingsObjectForCCSSetting (setting);
1791+
1792+ char *cleanSettingName = translateKeyForGSettings (setting->name);
1793+ KEYNAME (setting->parent->context->screenNum);
1794+ PATHNAME (setting->parent->name, keyName);
1795+
1796+ g_settings_reset (settings, cleanSettingName);
1797+
1798+ free (cleanSettingName);
1799+}
1800+
1801+void
1802+writeOption (CCSSetting * setting)
1803+{
1804+ GSettings *settings = getSettingsObjectForCCSSetting (setting);
1805+ char *cleanSettingName = translateKeyForGSettings (setting->name);
1806+ KEYNAME (setting->parent->context->screenNum);
1807+ PATHNAME (setting->parent->name, keyName);
1808+
1809+ switch (setting->type)
1810+ {
1811+ case TypeString:
1812+ {
1813+ char *value;
1814+ if (ccsGetString (setting, &value))
1815+ {
1816+ g_settings_set (settings, cleanSettingName, "s", value, NULL);
1817+ }
1818+ }
1819+ break;
1820+ case TypeMatch:
1821+ {
1822+ char *value;
1823+ if (ccsGetMatch (setting, &value))
1824+ {
1825+ g_settings_set (settings, cleanSettingName, "s", value, NULL);
1826+ }
1827+ }
1828+ case TypeFloat:
1829+ {
1830+ float value;
1831+ if (ccsGetFloat (setting, &value))
1832+ {
1833+ g_settings_set (settings, cleanSettingName, "d", (double) value, NULL);
1834+ }
1835+ }
1836+ break;
1837+ case TypeInt:
1838+ {
1839+ int value;
1840+ if (ccsGetInt (setting, &value))
1841+ {
1842+ g_settings_set (settings, cleanSettingName, "i", value, NULL);
1843+ }
1844+ }
1845+ break;
1846+ case TypeBool:
1847+ {
1848+ Bool value;
1849+ if (ccsGetBool (setting, &value))
1850+ {
1851+ g_settings_set (settings, cleanSettingName, "b", value, NULL);
1852+ }
1853+ }
1854+ break;
1855+ case TypeColor:
1856+ {
1857+ CCSSettingColorValue value;
1858+ char *colString;
1859+
1860+ if (!ccsGetColor (setting, &value))
1861+ break;
1862+
1863+ colString = ccsColorToString (&value);
1864+ if (!colString)
1865+ break;
1866+
1867+ g_settings_set (settings, cleanSettingName, "s", colString, NULL);
1868+ free (colString);
1869+ }
1870+ break;
1871+ case TypeKey:
1872+ {
1873+ CCSSettingKeyValue key;
1874+ char *keyString;
1875+
1876+ if (!ccsGetKey (setting, &key))
1877+ break;
1878+
1879+ keyString = ccsKeyBindingToString (&key);
1880+ if (!keyString)
1881+ break;
1882+
1883+ g_settings_set (settings, cleanSettingName, "s", keyString, NULL);
1884+ free (keyString);
1885+ }
1886+ break;
1887+ case TypeButton:
1888+ {
1889+ CCSSettingButtonValue button;
1890+ char *buttonString;
1891+
1892+ if (!ccsGetButton (setting, &button))
1893+ break;
1894+
1895+ buttonString = ccsButtonBindingToString (&button);
1896+ if (!buttonString)
1897+ break;
1898+
1899+ g_settings_set (settings, cleanSettingName, "s", buttonString, NULL);
1900+ free (buttonString);
1901+ }
1902+ break;
1903+ case TypeEdge:
1904+ {
1905+ unsigned int edges;
1906+ char *edgeString;
1907+
1908+ if (!ccsGetEdge (setting, &edges))
1909+ break;
1910+
1911+ edgeString = ccsEdgesToString (edges);
1912+ if (!edgeString)
1913+ break;
1914+
1915+ g_settings_set (settings, cleanSettingName, "s", edgeString, NULL);
1916+ free (edgeString);
1917+ }
1918+ break;
1919+ case TypeBell:
1920+ {
1921+ Bool value;
1922+ if (ccsGetBell (setting, &value))
1923+ {
1924+ g_settings_set (settings, cleanSettingName, "s", value, NULL);
1925+ }
1926+ }
1927+ break;
1928+ case TypeList:
1929+ writeListValue (setting, pathName);
1930+ break;
1931+ default:
1932+ printf("GSettings backend: attempt to write unsupported setting type %d\n",
1933+ setting->type);
1934+ break;
1935+ }
1936+
1937+ free (cleanSettingName);
1938+}
1939+
1940+static void
1941+updateCurrentProfileName (char *profile)
1942+{
1943+ GVariant *profiles;
1944+ char *prof;
1945+ char *profilePath = COMPIZ_PROFILEPATH;
1946+ char *currentProfilePath;
1947+ GVariant *newProfiles;
1948+ GVariantBuilder *newProfilesBuilder;
1949+ GVariantIter *iter;
1950+ gboolean found = FALSE;
1951+
1952+ profiles = g_settings_get_value (compizconfigSettings, "existing-profiles");
1953+
1954+ newProfilesBuilder = g_variant_builder_new (G_VARIANT_TYPE ("as"));
1955+
1956+ iter = g_variant_iter_new (profiles);
1957+ while (g_variant_iter_next (iter, "s", &prof))
1958+ {
1959+ g_variant_builder_add (newProfilesBuilder, "s", prof);
1960+
1961+ if (!found)
1962+ found = (g_strcmp0 (prof, profile) == 0);
1963+ }
1964+
1965+ if (!found)
1966+ g_variant_builder_add (newProfilesBuilder, "s", profile);
1967+
1968+ newProfiles = g_variant_new ("as", newProfilesBuilder);
1969+ g_settings_set_value (compizconfigSettings, "existing-profiles", newProfiles);
1970+
1971+ g_variant_iter_free (iter);
1972+ g_variant_unref (newProfiles);
1973+ g_variant_builder_unref (newProfilesBuilder);
1974+
1975+ /* Change the current profile and current profile settings */
1976+ free (currentProfile);
1977+
1978+ currentProfile = strdup (profile);
1979+ currentProfilePath = g_strconcat (profilePath, profile, "/", NULL);
1980+ currentProfileSettings = g_settings_new_with_path (PROFILE_SCHEMA_ID, profilePath);
1981+
1982+ g_free (currentProfilePath);
1983+
1984+ g_settings_set (compizconfigSettings, "current-profile", "s", profile, NULL);
1985+}
1986+
1987+static gboolean
1988+updateProfile (CCSContext *context)
1989+{
1990+ char *profile = strdup (ccsGetProfile (context));
1991+
1992+ if (!profile || !strlen (profile))
1993+ profile = strdup (DEFAULTPROF);
1994+
1995+ if (g_strcmp0 (profile, currentProfile))
1996+ updateCurrentProfileName (profile);
1997+
1998+ free (profile);
1999+
2000+ return TRUE;
2001+}
2002+
2003+static char*
2004+getCurrentProfileName (void)
2005+{
2006+ GVariant *value;
2007+ char *ret = NULL;
2008+
2009+ value = g_settings_get_value (compizconfigSettings, "current-profile");
2010+
2011+ if (value)
2012+ ret = strdup (g_variant_get_string (value, NULL));
2013+ else
2014+ ret = strdup (DEFAULTPROF);
2015+
2016+ return ret;
2017+}
2018+
2019+static void
2020+processEvents (unsigned int flags)
2021+{
2022+ if (!(flags & ProcessEventsNoGlibMainLoopMask))
2023+ {
2024+ while (g_main_context_pending(NULL))
2025+ g_main_context_iteration(NULL, FALSE);
2026+ }
2027+}
2028+
2029+static Bool
2030+initBackend (CCSContext * context)
2031+{
2032+ const char *profilePath = PROFILEPATH;
2033+ char *currentProfilePath;
2034+
2035+ g_type_init ();
2036+
2037+ compizconfigSettings = g_settings_new (COMPIZCONFIG_SCHEMA_ID);
2038+
2039+#ifdef USE_GCONF
2040+ initGConfClient (context);
2041+#endif
2042+
2043+ currentProfile = getCurrentProfileName ();
2044+ currentProfilePath = g_strconcat (profilePath, currentProfile, "/", NULL);
2045+ currentProfileSettings = g_settings_new_with_path (PROFILE_SCHEMA_ID, currentProfilePath);
2046+
2047+ g_free (currentProfilePath);
2048+
2049+ return TRUE;
2050+}
2051+
2052+static Bool
2053+finiBackend (CCSContext * context)
2054+{
2055+ GList *l = settingsList;
2056+
2057+ processEvents (0);
2058+
2059+#ifdef USE_GCONF
2060+ gconf_client_clear_cache (client);
2061+ finiGConfClient ();
2062+#endif
2063+
2064+ if (currentProfile)
2065+ {
2066+ free (currentProfile);
2067+ currentProfile = NULL;
2068+ }
2069+
2070+ while (l)
2071+ {
2072+ g_object_unref (G_OBJECT (l->data));
2073+ l = g_list_next (l);
2074+ }
2075+
2076+ g_object_unref (G_OBJECT (compizconfigSettings));
2077+
2078+ processEvents (0);
2079+ return TRUE;
2080+}
2081+
2082+Bool
2083+readInit (CCSContext * context)
2084+{
2085+ return updateProfile (context);
2086+}
2087+
2088+void
2089+readSetting (CCSContext *context,
2090+ CCSSetting *setting)
2091+{
2092+ Bool status;
2093+ int index;
2094+
2095+ if (ccsGetIntegrationEnabled (context) &&
2096+ isIntegratedOption (setting, &index))
2097+ {
2098+ status = readIntegratedOption (context, setting, index);
2099+ }
2100+ else
2101+ status = readOption (setting);
2102+
2103+ if (!status)
2104+ ccsResetToDefault (setting, TRUE);
2105+}
2106+
2107+Bool
2108+writeInit (CCSContext * context)
2109+{
2110+ return updateProfile (context);
2111+}
2112+
2113+void
2114+writeSetting (CCSContext *context,
2115+ CCSSetting *setting)
2116+{
2117+ int index;
2118+
2119+ if (ccsGetIntegrationEnabled (context) &&
2120+ isIntegratedOption (setting, &index))
2121+ {
2122+ writeIntegratedOption (context, setting, index);
2123+ }
2124+ else if (setting->isDefault)
2125+ {
2126+ resetOptionToDefault (setting);
2127+ }
2128+ else
2129+ writeOption (setting);
2130+
2131+}
2132+
2133+static Bool
2134+getSettingIsIntegrated (CCSSetting * setting)
2135+{
2136+ if (!ccsGetIntegrationEnabled (setting->parent->context))
2137+ return FALSE;
2138+
2139+ if (!isIntegratedOption (setting, NULL))
2140+ return FALSE;
2141+
2142+ return TRUE;
2143+}
2144+
2145+static Bool
2146+getSettingIsReadOnly (CCSSetting * setting)
2147+{
2148+ /* FIXME */
2149+ return FALSE;
2150+}
2151+
2152+static CCSStringList
2153+getExistingProfiles (CCSContext *context)
2154+{
2155+ GVariant *value;
2156+ char *profile;
2157+ GVariantIter iter;
2158+ CCSStringList ret = NULL;
2159+
2160+ value = g_settings_get_value (compizconfigSettings, "existing-profiles");
2161+ g_variant_iter_init (&iter, value);
2162+ while (g_variant_iter_next (&iter, "s", &profile))
2163+ {
2164+ CCSString *str = malloc (sizeof (CCSString));
2165+
2166+ str->value = profile;
2167+
2168+ ret = ccsStringListAppend (ret, str);
2169+ }
2170+
2171+ g_variant_unref (value);
2172+
2173+ return ret;
2174+}
2175+
2176+static Bool
2177+deleteProfile (CCSContext *context,
2178+ char *profile)
2179+{
2180+ GVariant *plugins;
2181+ GVariant *profiles;
2182+ GVariant *newProfiles;
2183+ GVariantBuilder *newProfilesBuilder;
2184+ char *plugin, *prof;
2185+ GVariantIter *iter;
2186+ char *profileSettingsPath = g_strconcat (PROFILEPATH, profile, "/", NULL);
2187+ GSettings *profileSettings = g_settings_new_with_path (PROFILE_SCHEMA_ID, profileSettingsPath);
2188+
2189+ plugins = g_settings_get_value (currentProfileSettings, "plugins-with-set-keys");
2190+ profiles = g_settings_get_value (compizconfigSettings, "existing-profiles");
2191+
2192+ iter = g_variant_iter_new (plugins);
2193+ while (g_variant_iter_next (iter, "s", &plugin))
2194+ {
2195+ GSettings *settings;
2196+
2197+ KEYNAME (context->screenNum);
2198+ PATHNAME (plugin, keyName);
2199+
2200+ settings = getSettingsObjectForPluginWithPath (plugin, pathName, context);
2201+
2202+ /* The GSettings documentation says not to use this API
2203+ * because we should know our own schema ... though really
2204+ * we don't because we autogenerate schemas ... */
2205+ if (settings)
2206+ {
2207+ char **keys = g_settings_list_keys (settings);
2208+ char **key_ptr;
2209+
2210+ /* Unset all the keys */
2211+ for (key_ptr = keys; *key_ptr; key_ptr++)
2212+ g_settings_reset (settings, *key_ptr);
2213+
2214+ g_strfreev (keys);
2215+ }
2216+
2217+ g_free (plugin);
2218+ }
2219+
2220+ /* Remove the profile from existing-profiles */
2221+ g_variant_iter_free (iter);
2222+ g_settings_reset (profileSettings, "plugins-with-set-values");
2223+
2224+ iter = g_variant_iter_new (profiles);
2225+ newProfilesBuilder = g_variant_builder_new (G_VARIANT_TYPE ("as"));
2226+
2227+ while (g_variant_iter_next (iter, "s", &prof))
2228+ {
2229+ if (g_strcmp0 (prof, profile))
2230+ g_variant_builder_add (newProfilesBuilder, "s", prof);
2231+
2232+ g_free (prof);
2233+ }
2234+
2235+ newProfiles = g_variant_new ("as", newProfilesBuilder);
2236+ g_settings_set_value (compizconfigSettings, "existing-profiles", newProfiles);
2237+
2238+ g_variant_unref (newProfiles);
2239+ g_variant_builder_unref (newProfilesBuilder);
2240+
2241+ free (profileSettingsPath);
2242+
2243+ updateProfile (context);
2244+
2245+ return TRUE;
2246+}
2247+
2248+static CCSBackendVTable gsettingsVTable = {
2249+ "gsettings",
2250+ "GSettings Configuration Backend",
2251+ "GSettings Configuration Backend for libccs",
2252+ TRUE,
2253+ TRUE,
2254+ processEvents,
2255+ initBackend,
2256+ finiBackend,
2257+ readInit,
2258+ readSetting,
2259+ 0,
2260+ writeInit,
2261+ writeSetting,
2262+ 0,
2263+ getSettingIsIntegrated,
2264+ getSettingIsReadOnly,
2265+ getExistingProfiles,
2266+ deleteProfile
2267+};
2268+
2269+CCSBackendVTable *
2270+getBackendInfo (void)
2271+{
2272+ return &gsettingsVTable;
2273+}
2274+
2275+>>>>>>> MERGE-SOURCE

Subscribers

People subscribed via source and target branches