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
=== modified file 'src/gconf-integration.c'
--- src/gconf-integration.c 2011-07-24 14:28:26 +0000
+++ src/gconf-integration.c 2011-10-15 07:07:06 +0000
@@ -1,3 +1,4 @@
1<<<<<<< TREE
1/**2/**
2 *3 *
3 * GSettings libccs backend4 * GSettings libccs backend
@@ -952,3 +953,959 @@
952 g_error_free (err);953 g_error_free (err);
953}954}
954#endif955#endif
956=======
957/**
958 *
959 * GSettings libccs backend
960 *
961 * gconf-integration.c
962 *
963 * Copyright (c) 2011 Canonical Ltd
964 *
965 * Based on the original compizconfig-backend-gconf
966 *
967 * Copyright (c) 2007 Danny Baumann <maniac@opencompositing.org>
968 *
969 * Parts of this code are taken from libberylsettings
970 * gconf backend, written by:
971 *
972 * Copyright (c) 2006 Robert Carr <racarr@opencompositing.org>
973 * Copyright (c) 2007 Dennis Kasprzyk <onestone@opencompositing.org>
974 *
975 * This program is free software; you can redistribute it and/or
976 * modify it under the terms of the GNU General Public License
977 * as published by the Free Software Foundation; either version 2
978 * of the License, or (at your option) any later version.
979 *
980 * This program is distributed in the hope that it will be useful,
981 * but WITHOUT ANY WARRANTY; without even the implied warranty of
982 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
983 * GNU General Public License for more details.
984 *
985 * Authored By:
986 * Sam Spilsbury <sam.spilsbury@canonical.com>
987 *
988 **/
989
990#include "gsettings.h"
991#ifdef USE_GCONF
992GConfClient *client = NULL;
993guint gnomeGConfNotifyIds[NUM_WATCHED_DIRS];
994
995const SpecialOptionGConf specialOptions[] = {
996 {"run_key", "gnomecompat", FALSE,
997 METACITY "/global_keybindings/panel_run_dialog", OptionKey},
998 {"main_menu_key", "gnomecompat", FALSE,
999 METACITY "/global_keybindings/panel_main_menu", OptionKey},
1000 {"run_command_screenshot_key", "gnomecompat", FALSE,
1001 METACITY "/global_keybindings/run_command_screenshot", OptionKey},
1002 {"run_command_window_screenshot_key", "gnomecompat", FALSE,
1003 METACITY "/global_keybindings/run_command_window_screenshot", OptionKey},
1004 {"run_command_terminal_key", "gnomecompat", FALSE,
1005 METACITY "/global_keybindings/run_command_terminal", OptionKey},
1006
1007 {"toggle_window_maximized_key", "core", FALSE,
1008 METACITY "/window_keybindings/toggle_maximized", OptionKey},
1009 {"minimize_window_key", "core", FALSE,
1010 METACITY "/window_keybindings/minimize", OptionKey},
1011 {"maximize_window_key", "core", FALSE,
1012 METACITY "/window_keybindings/maximize", OptionKey},
1013 {"unmaximize_window_key", "core", FALSE,
1014 METACITY "/window_keybindings/unmaximize", OptionKey},
1015 {"maximize_window_horizontally_key", "core", FALSE,
1016 METACITY "/window_keybindings/maximize_horizontally", OptionKey},
1017 {"maximize_window_vertically_key", "core", FALSE,
1018 METACITY "/window_keybindings/maximize_vertically", OptionKey},
1019 {"raise_window_key", "core", FALSE,
1020 METACITY "/window_keybindings/raise", OptionKey},
1021 {"lower_window_key", "core", FALSE,
1022 METACITY "/window_keybindings/lower", OptionKey},
1023 {"close_window_key", "core", FALSE,
1024 METACITY "/window_keybindings/close", OptionKey},
1025 {"toggle_window_shaded_key", "core", FALSE,
1026 METACITY "/window_keybindings/toggle_shaded", OptionKey},
1027
1028 {"show_desktop_key", "core", FALSE,
1029 METACITY "/global_keybindings/show_desktop", OptionKey},
1030
1031 {"initiate_key", "move", FALSE,
1032 METACITY "/window_keybindings/begin_move", OptionKey},
1033 {"initiate_key", "resize", FALSE,
1034 METACITY "/window_keybindings/begin_resize", OptionKey},
1035 {"window_menu_key", "core", FALSE,
1036 METACITY "/window_keybindings/activate_window_menu", OptionKey},
1037
1038 /* integration of Metacity's mouse_button_modifier option */
1039 {"initiate_button", "move", FALSE,
1040 METACITY "/window_keybindings/begin_move", OptionSpecial},
1041 {"initiate_button", "resize", FALSE,
1042 METACITY "/window_keybindings/begin_resize", OptionSpecial},
1043 {"window_menu_button", "core", FALSE,
1044 METACITY "/window_keybindings/activate_window_menu", OptionSpecial},
1045 {"mouse_button_modifier", NULL, FALSE,
1046 METACITY "/general/mouse_button_modifier", OptionSpecial},
1047 /* integration of the Metacity's option to swap mouse buttons */
1048 {"resize_with_right_button", NULL, FALSE,
1049 METACITY "/general/resize_with_right_button", OptionSpecial},
1050
1051 {"visual_bell", "fade", TRUE,
1052 METACITY "/general/visual_bell", OptionBool},
1053 {"fullscreen_visual_bell", "fade", TRUE,
1054 METACITY "/general/visual_bell_type", OptionSpecial},
1055
1056 {"next_key", "staticswitcher", FALSE,
1057 METACITY "/global_keybindings/switch_windows", OptionKey},
1058 {"prev_key", "staticswitcher", FALSE,
1059 METACITY "/global_keybindings/switch_windows_backward", OptionKey},
1060
1061 {"toggle_sticky_key", "extrawm", FALSE,
1062 METACITY "/window_keybindings/toggle_on_all_workspaces", OptionKey},
1063 {"toggle_fullscreen_key", "extrawm", FALSE,
1064 METACITY "/window_keybindings/toggle_fullscreen", OptionKey},
1065
1066 {"command0", "commands", FALSE,
1067 METACITY "/keybinding_commands/command_1", OptionString},
1068 {"command1", "commands", FALSE,
1069 METACITY "/keybinding_commands/command_2", OptionString},
1070 {"command2", "commands", FALSE,
1071 METACITY "/keybinding_commands/command_3", OptionString},
1072 {"command3", "commands", FALSE,
1073 METACITY "/keybinding_commands/command_4", OptionString},
1074 {"command4", "commands", FALSE,
1075 METACITY "/keybinding_commands/command_5", OptionString},
1076 {"command5", "commands", FALSE,
1077 METACITY "/keybinding_commands/command_6", OptionString},
1078 {"command6", "commands", FALSE,
1079 METACITY "/keybinding_commands/command_7", OptionString},
1080 {"command7", "commands", FALSE,
1081 METACITY "/keybinding_commands/command_8", OptionString},
1082 {"command8", "commands", FALSE,
1083 METACITY "/keybinding_commands/command_9", OptionString},
1084 {"command9", "commands", FALSE,
1085 METACITY "/keybinding_commands/command_10", OptionString},
1086 {"command10", "commands", FALSE,
1087 METACITY "/keybinding_commands/command_11", OptionString},
1088 {"command11", "commands", FALSE,
1089 METACITY "/keybinding_commands/command_12", OptionString},
1090
1091 {"run_command0_key", "commands", FALSE,
1092 METACITY "/global_keybindings/run_command_1", OptionKey},
1093 {"run_command1_key", "commands", FALSE,
1094 METACITY "/global_keybindings/run_command_2", OptionKey},
1095 {"run_command2_key", "commands", FALSE,
1096 METACITY "/global_keybindings/run_command_3", OptionKey},
1097 {"run_command3_key", "commands", FALSE,
1098 METACITY "/global_keybindings/run_command_4", OptionKey},
1099 {"run_command4_key", "commands", FALSE,
1100 METACITY "/global_keybindings/run_command_5", OptionKey},
1101 {"run_command5_key", "commands", FALSE,
1102 METACITY "/global_keybindings/run_command_6", OptionKey},
1103 {"run_command6_key", "commands", FALSE,
1104 METACITY "/global_keybindings/run_command_7", OptionKey},
1105 {"run_command7_key", "commands", FALSE,
1106 METACITY "/global_keybindings/run_command_8", OptionKey},
1107 {"run_command8_key", "commands", FALSE,
1108 METACITY "/global_keybindings/run_command_9", OptionKey},
1109 {"run_command9_key", "commands", FALSE,
1110 METACITY "/global_keybindings/run_command_10", OptionKey},
1111 {"run_command10_key", "commands", FALSE,
1112 METACITY "/global_keybindings/run_command_11", OptionKey},
1113 {"run_command11_key", "commands", FALSE,
1114 METACITY "/global_keybindings/run_command_12", OptionKey},
1115
1116 {"rotate_to_1_key", "rotate", FALSE,
1117 METACITY "/global_keybindings/switch_to_workspace_1", OptionKey},
1118 {"rotate_to_2_key", "rotate", FALSE,
1119 METACITY "/global_keybindings/switch_to_workspace_2", OptionKey},
1120 {"rotate_to_3_key", "rotate", FALSE,
1121 METACITY "/global_keybindings/switch_to_workspace_3", OptionKey},
1122 {"rotate_to_4_key", "rotate", FALSE,
1123 METACITY "/global_keybindings/switch_to_workspace_4", OptionKey},
1124 {"rotate_to_5_key", "rotate", FALSE,
1125 METACITY "/global_keybindings/switch_to_workspace_5", OptionKey},
1126 {"rotate_to_6_key", "rotate", FALSE,
1127 METACITY "/global_keybindings/switch_to_workspace_6", OptionKey},
1128 {"rotate_to_7_key", "rotate", FALSE,
1129 METACITY "/global_keybindings/switch_to_workspace_7", OptionKey},
1130 {"rotate_to_8_key", "rotate", FALSE,
1131 METACITY "/global_keybindings/switch_to_workspace_8", OptionKey},
1132 {"rotate_to_9_key", "rotate", FALSE,
1133 METACITY "/global_keybindings/switch_to_workspace_9", OptionKey},
1134 {"rotate_to_10_key", "rotate", FALSE,
1135 METACITY "/global_keybindings/switch_to_workspace_10", OptionKey},
1136 {"rotate_to_11_key", "rotate", FALSE,
1137 METACITY "/global_keybindings/switch_to_workspace_11", OptionKey},
1138 {"rotate_to_12_key", "rotate", FALSE,
1139 METACITY "/global_keybindings/switch_to_workspace_12", OptionKey},
1140
1141 {"rotate_left_key", "rotate", FALSE,
1142 METACITY "/global_keybindings/switch_to_workspace_left", OptionKey},
1143 {"rotate_right_key", "rotate", FALSE,
1144 METACITY "/global_keybindings/switch_to_workspace_right", OptionKey},
1145
1146 {"switch_to_1_key", "vpswitch", FALSE,
1147 METACITY "/global_keybindings/switch_to_workspace_1", OptionKey},
1148 {"switch_to_2_key", "vpswitch", FALSE,
1149 METACITY "/global_keybindings/switch_to_workspace_2", OptionKey},
1150 {"switch_to_3_key", "vpswitch", FALSE,
1151 METACITY "/global_keybindings/switch_to_workspace_3", OptionKey},
1152 {"switch_to_4_key", "vpswitch", FALSE,
1153 METACITY "/global_keybindings/switch_to_workspace_4", OptionKey},
1154 {"switch_to_5_key", "vpswitch", FALSE,
1155 METACITY "/global_keybindings/switch_to_workspace_5", OptionKey},
1156 {"switch_to_6_key", "vpswitch", FALSE,
1157 METACITY "/global_keybindings/switch_to_workspace_6", OptionKey},
1158 {"switch_to_7_key", "vpswitch", FALSE,
1159 METACITY "/global_keybindings/switch_to_workspace_7", OptionKey},
1160 {"switch_to_8_key", "vpswitch", FALSE,
1161 METACITY "/global_keybindings/switch_to_workspace_8", OptionKey},
1162 {"switch_to_9_key", "vpswitch", FALSE,
1163 METACITY "/global_keybindings/switch_to_workspace_9", OptionKey},
1164 {"switch_to_10_key", "vpswitch", FALSE,
1165 METACITY "/global_keybindings/switch_to_workspace_10", OptionKey},
1166 {"switch_to_11_key", "vpswitch", FALSE,
1167 METACITY "/global_keybindings/switch_to_workspace_11", OptionKey},
1168 {"switch_to_12_key", "vpswitch", FALSE,
1169 METACITY "/global_keybindings/switch_to_workspace_12", OptionKey},
1170
1171 {"up_key", "wall", FALSE,
1172 METACITY "/global_keybindings/switch_to_workspace_up", OptionKey},
1173 {"down_key", "wall", FALSE,
1174 METACITY "/global_keybindings/switch_to_workspace_down", OptionKey},
1175 {"left_key", "wall", FALSE,
1176 METACITY "/global_keybindings/switch_to_workspace_left", OptionKey},
1177 {"right_key", "wall", FALSE,
1178 METACITY "/global_keybindings/switch_to_workspace_right", OptionKey},
1179 {"left_window_key", "wall", FALSE,
1180 METACITY "/window_keybindings/move_to_workspace_left", OptionKey},
1181 {"right_window_key", "wall", FALSE,
1182 METACITY "/window_keybindings/move_to_workspace_right", OptionKey},
1183 {"up_window_key", "wall", FALSE,
1184 METACITY "/window_keybindings/move_to_workspace_up", OptionKey},
1185 {"down_window_key", "wall", FALSE,
1186 METACITY "/window_keybindings/move_to_workspace_down", OptionKey},
1187
1188 {"put_topleft_key", "put", FALSE,
1189 METACITY "/window_keybindings/move_to_corner_nw", OptionKey},
1190 {"put_topright_key", "put", FALSE,
1191 METACITY "/window_keybindings/move_to_corner_ne", OptionKey},
1192 {"put_bottomleft_key", "put", FALSE,
1193 METACITY "/window_keybindings/move_to_corner_sw", OptionKey},
1194 {"put_bottomright_key", "put", FALSE,
1195 METACITY "/window_keybindings/move_to_corner_se", OptionKey},
1196 {"put_left_key", "put", FALSE,
1197 METACITY "/window_keybindings/move_to_side_w", OptionKey},
1198 {"put_right_key", "put", FALSE,
1199 METACITY "/window_keybindings/move_to_side_e", OptionKey},
1200 {"put_top_key", "put", FALSE,
1201 METACITY "/window_keybindings/move_to_side_n", OptionKey},
1202 {"put_bottom_key", "put", FALSE,
1203 METACITY "/window_keybindings/move_to_side_s", OptionKey},
1204
1205 {"rotate_to_1_window_key", "rotate", FALSE,
1206 METACITY "/window_keybindings/move_to_workspace_1", OptionKey},
1207 {"rotate_to_2_window_key", "rotate", FALSE,
1208 METACITY "/window_keybindings/move_to_workspace_2", OptionKey},
1209 {"rotate_to_3_window_key", "rotate", FALSE,
1210 METACITY "/window_keybindings/move_to_workspace_3", OptionKey},
1211 {"rotate_to_4_window_key", "rotate", FALSE,
1212 METACITY "/window_keybindings/move_to_workspace_4", OptionKey},
1213 {"rotate_to_5_window_key", "rotate", FALSE,
1214 METACITY "/window_keybindings/move_to_workspace_5", OptionKey},
1215 {"rotate_to_6_window_key", "rotate", FALSE,
1216 METACITY "/window_keybindings/move_to_workspace_6", OptionKey},
1217 {"rotate_to_7_window_key", "rotate", FALSE,
1218 METACITY "/window_keybindings/move_to_workspace_7", OptionKey},
1219 {"rotate_to_8_window_key", "rotate", FALSE,
1220 METACITY "/window_keybindings/move_to_workspace_8", OptionKey},
1221 {"rotate_to_9_window_key", "rotate", FALSE,
1222 METACITY "/window_keybindings/move_to_workspace_9", OptionKey},
1223 {"rotate_to_10_window_key", "rotate", FALSE,
1224 METACITY "/window_keybindings/move_to_workspace_10", OptionKey},
1225 {"rotate_to_11_window_key", "rotate", FALSE,
1226 METACITY "/window_keybindings/move_to_workspace_11", OptionKey},
1227 {"rotate_to_12_window_key", "rotate", FALSE,
1228 METACITY "/window_keybindings/move_to_workspace_12", OptionKey},
1229
1230 {"rotate_left_window_key", "rotate", FALSE,
1231 METACITY "/window_keybindings/move_to_workspace_left", OptionKey},
1232 {"rotate_right_window_key", "rotate", FALSE,
1233 METACITY "/window_keybindings/move_to_workspace_right", OptionKey},
1234
1235 {"command_screenshot", "gnomecompat", FALSE,
1236 METACITY "/keybinding_commands/command_screenshot", OptionString},
1237 {"command_window_screenshot", "gnomecompat", FALSE,
1238 METACITY "/keybinding_commands/command_window_screenshot", OptionString},
1239 {"command_terminal", "gnomecompat", FALSE,
1240 "/desktop/gnome/applications/terminal/exec", OptionString},
1241
1242 {"current_viewport", "thumbnail", TRUE,
1243 "/apps/panel/applets/window_list/prefs/display_all_workspaces",
1244 OptionSpecial},
1245
1246 {"autoraise", "core", FALSE,
1247 METACITY "/general/auto_raise", OptionBool},
1248 {"autoraise_delay", "core", FALSE,
1249 METACITY "/general/auto_raise_delay", OptionInt},
1250 {"raise_on_click", "core", FALSE,
1251 METACITY "/general/raise_on_click", OptionBool},
1252 {"click_to_focus", "core", FALSE,
1253 METACITY "/general/focus_mode", OptionSpecial},
1254
1255 {"audible_bell", "core", FALSE,
1256 METACITY "/general/audible_bell", OptionBool},
1257 /*{"hsize", "core", TRUE,
1258 METACITY "/general/num_workspaces", OptionInt},*/
1259};
1260
1261static const char* watchedGConfGnomeDirectories[] = {
1262 METACITY,
1263 "/desktop/gnome/applications/terminal",
1264 "/apps/panel/applets/window_list/prefs"
1265};
1266
1267#define N_SOPTIONS (sizeof (specialOptions) / sizeof (struct _SpecialOptionGConf))
1268
1269static CCSSetting *
1270findDisplaySettingForPlugin (CCSContext *context,
1271 const char *plugin,
1272 const char *setting)
1273{
1274 CCSPlugin *p;
1275 CCSSetting *s;
1276
1277 p = ccsFindPlugin (context, plugin);
1278 if (!p)
1279 return NULL;
1280
1281 s = ccsFindSetting (p, setting);
1282 if (!s)
1283 return NULL;
1284
1285 return s;
1286}
1287
1288Bool
1289isGConfIntegratedOption (CCSSetting *setting,
1290 int *index)
1291{
1292 unsigned int i;
1293
1294 for (i = 0; i < N_SOPTIONS; i++)
1295 {
1296 const SpecialOptionGConf *opt = &specialOptions[i];
1297
1298 if (strcmp (setting->name, opt->settingName) != 0)
1299 continue;
1300
1301 if (setting->parent->name)
1302 {
1303 if (!opt->pluginName)
1304 continue;
1305 if (strcmp (setting->parent->name, opt->pluginName) != 0)
1306 continue;
1307 }
1308 else
1309 {
1310 if (opt->pluginName)
1311 continue;
1312 }
1313
1314 if (index)
1315 *index = i;
1316
1317 return TRUE;
1318 }
1319
1320 return FALSE;
1321}
1322
1323void
1324gnomeGConfValueChanged (GConfClient *client,
1325 guint cnxn_id,
1326 GConfEntry *entry,
1327 gpointer user_data)
1328{
1329 CCSContext *context = (CCSContext *)user_data;
1330 char *keyName = (char*) gconf_entry_get_key (entry);
1331 int i, last = 0, num = 0;
1332 Bool needInit = TRUE;
1333
1334 if (!ccsGetIntegrationEnabled (context))
1335 return;
1336
1337 /* we have to loop multiple times here, because one Gnome
1338 option may be integrated with multiple Compiz options */
1339
1340 while (1)
1341 {
1342 for (i = last, num = -1; i < N_SOPTIONS; i++)
1343 {
1344 if (strcmp (specialOptions[i].gnomeName, keyName) == 0)
1345 {
1346 num = i;
1347 last = i + 1;
1348 break;
1349 }
1350 }
1351
1352 if (num < 0)
1353 break;
1354
1355 if ((strcmp (specialOptions[num].settingName,
1356 "mouse_button_modifier") == 0) ||
1357 (strcmp (specialOptions[num].settingName,
1358 "resize_with_right_button") == 0))
1359 {
1360 CCSSetting *s;
1361
1362 if (needInit)
1363 {
1364 readInit (context);
1365 needInit = FALSE;
1366 }
1367
1368 s = findDisplaySettingForPlugin (context, "core",
1369 "window_menu_button");
1370 if (s)
1371 readSetting (context, s);
1372
1373 s = findDisplaySettingForPlugin (context, "move",
1374 "initiate_button");
1375 if (s)
1376 readSetting (context, s);
1377
1378 s = findDisplaySettingForPlugin (context, "resize",
1379 "initiate_button");
1380 if (s)
1381 readSetting (context, s);
1382 }
1383 else
1384 {
1385 CCSPlugin *plugin = NULL;
1386 CCSSetting *setting;
1387 SpecialOptionGConf *opt = (SpecialOptionGConf *) &specialOptions[num];
1388
1389 plugin = ccsFindPlugin (context, (char*) opt->pluginName);
1390 if (plugin)
1391 {
1392 for (i = 0; i < 1; i++)
1393 {
1394 setting = ccsFindSetting (plugin, (char*) opt->settingName);
1395
1396 if (setting)
1397 {
1398 if (needInit)
1399 {
1400 readInit (context);
1401 needInit = FALSE;
1402 }
1403 readSetting (context, setting);
1404 }
1405
1406 /* do not read display settings multiple
1407 times for multiscreen environments */
1408 }
1409 }
1410 }
1411 }
1412}
1413
1414void
1415initGConfClient (CCSContext *context)
1416{
1417 int i;
1418
1419 client = gconf_client_get_default ();
1420
1421 for (i = 0; i < NUM_WATCHED_DIRS; i++)
1422 {
1423 gnomeGConfNotifyIds[i] = gconf_client_notify_add (client,
1424 watchedGConfGnomeDirectories[i],
1425 gnomeGConfValueChanged, context,
1426 NULL, NULL);
1427 gconf_client_add_dir (client, watchedGConfGnomeDirectories[i],
1428 GCONF_CLIENT_PRELOAD_NONE, NULL);
1429 }
1430}
1431
1432void
1433finiGConfClient (void)
1434{
1435 int i;
1436
1437 for (i = 0; i < NUM_WATCHED_DIRS; i++)
1438 {
1439 if (gnomeGConfNotifyIds[i])
1440 {
1441 gconf_client_notify_remove (client, gnomeGConfNotifyIds[0]);
1442 gnomeGConfNotifyIds[i] = 0;
1443 }
1444 gconf_client_remove_dir (client, watchedGConfGnomeDirectories[i], NULL);
1445 }
1446 gconf_client_suggest_sync (client, NULL);
1447
1448 g_object_unref (client);
1449 client = NULL;
1450}
1451
1452static unsigned int
1453getGnomeMouseButtonModifier(void)
1454{
1455 unsigned int modMask = 0;
1456 GError *err = NULL;
1457 char *value;
1458
1459 value = gconf_client_get_string (client,
1460 METACITY "/general/mouse_button_modifier",
1461 &err);
1462
1463 if (err)
1464 {
1465 g_error_free (err);
1466 return 0;
1467 }
1468
1469 if (!value)
1470 return 0;
1471
1472 modMask = ccsStringToModifiers (value);
1473 g_free (value);
1474
1475 return modMask;
1476}
1477
1478static unsigned int
1479getButtonBindingForSetting (CCSContext *context,
1480 const char *plugin,
1481 const char *setting)
1482{
1483 CCSSetting *s;
1484
1485 s = findDisplaySettingForPlugin (context, plugin, setting);
1486 if (!s)
1487 return 0;
1488
1489 if (s->type != TypeButton)
1490 return 0;
1491
1492 return s->value->value.asButton.button;
1493}
1494
1495Bool
1496readGConfIntegratedOption (CCSContext *context,
1497 CCSSetting *setting,
1498 int index)
1499{
1500 GConfValue *gconfValue;
1501 GError *err = NULL;
1502 Bool ret = FALSE;
1503
1504 ret = readOption (setting);
1505
1506 gconfValue = gconf_client_get (client,
1507 specialOptions[index].gnomeName,
1508 &err);
1509
1510 if (err)
1511 {
1512 g_error_free (err);
1513 return FALSE;
1514 }
1515
1516 if (!gconfValue)
1517 return FALSE;
1518
1519 switch (specialOptions[index].type) {
1520 case OptionInt:
1521 if (gconfValue->type == GCONF_VALUE_INT)
1522 {
1523 guint value;
1524
1525 value = gconf_value_get_int (gconfValue);
1526 ccsSetInt (setting, value, TRUE);
1527 ret = TRUE;
1528 }
1529 break;
1530 case OptionBool:
1531 if (gconfValue->type == GCONF_VALUE_BOOL)
1532 {
1533 gboolean value;
1534
1535 value = gconf_value_get_bool (gconfValue);
1536 ccsSetBool (setting, value ? TRUE : FALSE, FALSE);
1537 ret = TRUE;
1538 }
1539 break;
1540 case OptionString:
1541 if (gconfValue->type == GCONF_VALUE_STRING)
1542 {
1543 const char *value;
1544
1545 value = gconf_value_get_string (gconfValue);
1546 if (value)
1547 {
1548 ccsSetString (setting, value, FALSE);
1549 ret = TRUE;
1550 }
1551 }
1552 break;
1553 case OptionKey:
1554 if (gconfValue->type == GCONF_VALUE_STRING)
1555 {
1556 const char *value;
1557
1558 value = gconf_value_get_string (gconfValue);
1559 if (value)
1560 {
1561 CCSSettingKeyValue key;
1562
1563 memset (&key, 0, sizeof (CCSSettingKeyValue));
1564 ccsGetKey (setting, &key);
1565 if (ccsStringToKeyBinding (value, &key))
1566 {
1567 ccsSetKey (setting, key, TRUE);
1568 ret = TRUE;
1569 }
1570 }
1571 }
1572 break;
1573 case OptionSpecial:
1574 {
1575 const char *settingName = specialOptions[index].settingName;
1576 const char *pluginName = specialOptions[index].pluginName;
1577
1578 if (strcmp (settingName, "current_viewport") == 0)
1579 {
1580 if (gconfValue->type == GCONF_VALUE_BOOL)
1581 {
1582 gboolean showAll;
1583
1584 showAll = gconf_value_get_bool (gconfValue);
1585 ccsSetBool (setting, !showAll, FALSE);
1586 ret = TRUE;
1587 }
1588 }
1589 else if (strcmp (settingName, "fullscreen_visual_bell") == 0)
1590 {
1591 if (gconfValue->type == GCONF_VALUE_STRING)
1592 {
1593 const char *value;
1594
1595 value = gconf_value_get_string (gconfValue);
1596 if (value)
1597 {
1598 Bool fullscreen;
1599
1600 fullscreen = strcmp (value, "fullscreen") == 0;
1601 ccsSetBool (setting, fullscreen, FALSE);
1602 ret = TRUE;
1603 }
1604 }
1605 }
1606 else if (strcmp (settingName, "click_to_focus") == 0)
1607 {
1608 if (gconfValue->type == GCONF_VALUE_STRING)
1609 {
1610 const char *focusMode;
1611
1612 focusMode = gconf_value_get_string (gconfValue);
1613
1614 if (focusMode)
1615 {
1616 Bool clickToFocus = (strcmp (focusMode, "click") == 0);
1617 ccsSetBool (setting, clickToFocus, FALSE);
1618 ret = TRUE;
1619 }
1620 }
1621 }
1622 else if (((strcmp (settingName, "initiate_button") == 0) &&
1623 ((strcmp (pluginName, "move") == 0) ||
1624 (strcmp (pluginName, "resize") == 0))) ||
1625 ((strcmp (settingName, "window_menu_button") == 0) &&
1626 (strcmp (pluginName, "core") == 0)))
1627 {
1628 gboolean resizeWithRightButton;
1629 CCSSettingButtonValue button;
1630
1631 memset (&button, 0, sizeof (CCSSettingButtonValue));
1632 ccsGetButton (setting, &button);
1633
1634 button.buttonModMask = getGnomeMouseButtonModifier ();
1635
1636 resizeWithRightButton =
1637 gconf_client_get_bool (client, METACITY
1638 "/general/resize_with_right_button",
1639 &err);
1640
1641 if (strcmp (settingName, "window_menu_button") == 0)
1642 button.button = resizeWithRightButton ? 2 : 3;
1643 else if (strcmp (pluginName, "resize") == 0)
1644 button.button = resizeWithRightButton ? 3 : 2;
1645 else
1646 button.button = 1;
1647
1648 ccsSetButton (setting, button, FALSE);
1649 ret = TRUE;
1650 }
1651 }
1652 break;
1653 default:
1654 break;
1655 }
1656
1657 gconf_value_free (gconfValue);
1658
1659 return ret;
1660}
1661
1662static Bool
1663setGnomeMouseButtonModifier (unsigned int modMask)
1664{
1665 char *modifiers, *currentValue;
1666 GError *err = NULL;
1667
1668 modifiers = ccsModifiersToString (modMask);
1669 if (!modifiers)
1670 return FALSE;
1671
1672 currentValue = gconf_client_get_string (client,
1673 METACITY
1674 "/general/mouse_button_modifier",
1675 &err);
1676 if (err)
1677 {
1678 free (modifiers);
1679 g_error_free (err);
1680 return FALSE;
1681 }
1682
1683 if (!currentValue || (strcmp (currentValue, modifiers) != 0))
1684 gconf_client_set_string (client,
1685 METACITY "/general/mouse_button_modifier",
1686 modifiers, NULL);
1687 if (currentValue)
1688 g_free (currentValue);
1689
1690 free (modifiers);
1691
1692 return TRUE;
1693}
1694
1695static void
1696setButtonBindingForSetting (CCSContext *context,
1697 const char *plugin,
1698 const char *setting,
1699 unsigned int button,
1700 unsigned int buttonModMask)
1701{
1702 CCSSetting *s;
1703 CCSSettingButtonValue value;
1704
1705 s = findDisplaySettingForPlugin (context, plugin, setting);
1706 if (!s)
1707 return;
1708
1709 if (s->type != TypeButton)
1710 return;
1711
1712 value = s->value->value.asButton;
1713
1714 if ((value.button != button) || (value.buttonModMask != buttonModMask))
1715 {
1716 value.button = button;
1717 value.buttonModMask = buttonModMask;
1718
1719 ccsSetButton (s, value, FALSE);
1720 }
1721}
1722
1723void
1724writeGConfIntegratedOption (CCSContext *context,
1725 CCSSetting *setting,
1726 int index)
1727{
1728 GError *err = NULL;
1729 const char *optionName = specialOptions[index].gnomeName;
1730
1731 switch (specialOptions[index].type)
1732 {
1733 case OptionInt:
1734 {
1735 int newValue, currentValue;
1736 if (!ccsGetInt (setting, &newValue))
1737 break;
1738 currentValue = gconf_client_get_int (client, optionName, &err);
1739
1740 if (!err && (currentValue != newValue))
1741 gconf_client_set_int(client, specialOptions[index].gnomeName,
1742 newValue, NULL);
1743 }
1744 break;
1745 case OptionBool:
1746 {
1747 Bool newValue;
1748 gboolean currentValue;
1749 if (!ccsGetBool (setting, &newValue))
1750 break;
1751 currentValue = gconf_client_get_bool (client, optionName, &err);
1752
1753 if (!err && ((currentValue && !newValue) ||
1754 (!currentValue && newValue)))
1755 gconf_client_set_bool (client, specialOptions[index].gnomeName,
1756 newValue, NULL);
1757 }
1758 break;
1759 case OptionString:
1760 {
1761 char *newValue;
1762 gchar *currentValue;
1763 if (!ccsGetString (setting, &newValue))
1764 break;
1765 currentValue = gconf_client_get_string (client, optionName, &err);
1766
1767 if (!err && currentValue)
1768 {
1769 if (strcmp (currentValue, newValue) != 0)
1770 gconf_client_set_string (client, optionName,
1771 newValue, NULL);
1772 g_free (currentValue);
1773 }
1774 }
1775 break;
1776 case OptionKey:
1777 {
1778 char *newValue;
1779 gchar *currentValue;
1780
1781 newValue = ccsKeyBindingToString (&setting->value->value.asKey);
1782 if (newValue)
1783 {
1784 if (strcmp (newValue, "Disabled") == 0)
1785 {
1786 /* Metacity doesn't like "Disabled", it wants "disabled" */
1787 newValue[0] = 'd';
1788 }
1789
1790 currentValue = gconf_client_get_string (client,
1791 optionName, &err);
1792
1793 if (!err && currentValue)
1794 {
1795 if (strcmp (currentValue, newValue) != 0)
1796 gconf_client_set_string (client, optionName,
1797 newValue, NULL);
1798 g_free (currentValue);
1799 }
1800 free (newValue);
1801 }
1802 }
1803 break;
1804 case OptionSpecial:
1805 {
1806 const char *settingName = specialOptions[index].settingName;
1807 const char *pluginName = specialOptions[index].pluginName;
1808
1809 if (strcmp (settingName, "current_viewport") == 0)
1810 {
1811 Bool currentViewport;
1812
1813 if (!ccsGetBool (setting, &currentViewport))
1814 break;
1815
1816 gconf_client_set_bool (client, optionName,
1817 !currentViewport, NULL);
1818 }
1819 else if (strcmp (settingName, "fullscreen_visual_bell") == 0)
1820 {
1821 Bool fullscreen;
1822 gchar *currentValue, *newValue;
1823 if (!ccsGetBool (setting, &fullscreen))
1824 break;
1825
1826 newValue = fullscreen ? "fullscreen" : "frame_flash";
1827 currentValue = gconf_client_get_string (client,
1828 optionName, &err);
1829 if (!err && currentValue)
1830 {
1831 if (strcmp (currentValue, newValue) != 0)
1832 gconf_client_set_string (client, optionName,
1833 newValue, NULL);
1834 g_free (currentValue);
1835 }
1836 }
1837 else if (strcmp (settingName, "click_to_focus") == 0)
1838 {
1839 Bool clickToFocus;
1840 gchar *newValue, *currentValue;
1841 if (!ccsGetBool (setting, &clickToFocus))
1842 break;
1843
1844 newValue = clickToFocus ? "click" : "sloppy";
1845 currentValue = gconf_client_get_string (client,
1846 optionName, &err);
1847
1848 if (!err && currentValue)
1849 {
1850 if (strcmp (currentValue, newValue) != 0)
1851 gconf_client_set_string (client, optionName,
1852 newValue, NULL);
1853 g_free (currentValue);
1854 }
1855 }
1856 else if (((strcmp (settingName, "initiate_button") == 0) &&
1857 ((strcmp (pluginName, "move") == 0) ||
1858 (strcmp (pluginName, "resize") == 0))) ||
1859 ((strcmp (settingName, "window_menu_button") == 0) &&
1860 (strcmp (pluginName, "core") == 0)))
1861 {
1862 unsigned int modMask;
1863 Bool resizeWithRightButton = FALSE;
1864 gboolean currentValue;
1865
1866 if ((getButtonBindingForSetting (context, "resize",
1867 "initiate_button") == 3) ||
1868 (getButtonBindingForSetting (context, "core",
1869 "window_menu_button") == 2))
1870 {
1871 resizeWithRightButton = TRUE;
1872 }
1873
1874 currentValue =
1875 gconf_client_get_bool (client, METACITY
1876 "/general/resize_with_right_button",
1877 &err);
1878
1879 if (!err && ((currentValue && !resizeWithRightButton) ||
1880 (!currentValue && resizeWithRightButton)))
1881 {
1882 gconf_client_set_bool (client,
1883 METACITY
1884 "/general/resize_with_right_button",
1885 resizeWithRightButton, NULL);
1886 }
1887
1888 modMask = setting->value->value.asButton.buttonModMask;
1889 if (setGnomeMouseButtonModifier (modMask))
1890 {
1891 setButtonBindingForSetting (context, "move",
1892 "initiate_button", 1, modMask);
1893 setButtonBindingForSetting (context, "resize",
1894 "initiate_button",
1895 resizeWithRightButton ? 3 : 2,
1896 modMask);
1897 setButtonBindingForSetting (context, "core",
1898 "window_menu_button",
1899 resizeWithRightButton ? 2 : 3,
1900 modMask);
1901 }
1902 }
1903 }
1904 break;
1905 }
1906
1907 if (err)
1908 g_error_free (err);
1909}
1910#endif
1911>>>>>>> MERGE-SOURCE
9551912
=== modified file 'src/gsettings.c'
--- src/gsettings.c 2011-07-29 15:41:46 +0000
+++ src/gsettings.c 2011-10-15 07:07:06 +0000
@@ -1,3 +1,4 @@
1<<<<<<< TREE
1/**2/**
2 *3 *
3 * GSettings libccs backend4 * GSettings libccs backend
@@ -1255,3 +1256,1297 @@
1255 return &gsettingsVTable;1256 return &gsettingsVTable;
1256}1257}
12571258
1259=======
1260/**
1261 *
1262 * GSettings libccs backend
1263 *
1264 * gsettings.c
1265 *
1266 * Copyright (c) 2011 Canonical Ltd
1267 *
1268 * Based on the original compizconfig-backend-gconf
1269 *
1270 * Copyright (c) 2007 Danny Baumann <maniac@opencompositing.org>
1271 *
1272 * Parts of this code are taken from libberylsettings
1273 * gconf backend, written by:
1274 *
1275 * Copyright (c) 2006 Robert Carr <racarr@opencompositing.org>
1276 * Copyright (c) 2007 Dennis Kasprzyk <onestone@opencompositing.org>
1277 *
1278 * This program is free software; you can redistribute it and/or
1279 * modify it under the terms of the GNU General Public License
1280 * as published by the Free Software Foundation; either version 2
1281 * of the License, or (at your option) any later version.
1282 *
1283 * This program is distributed in the hope that it will be useful,
1284 * but WITHOUT ANY WARRANTY; without even the implied warranty of
1285 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1286 * GNU General Public License for more details.
1287 *
1288 * Authored By:
1289 * Sam Spilsbury <sam.spilsbury@canonical.com>
1290 *
1291 **/
1292
1293#include "gsettings.h"
1294
1295static void
1296valueChanged (GSettings *settings,
1297 gchar *keyname,
1298 gpointer user_data);
1299
1300static void
1301gnomeValueChanged (GSettings *settings,
1302 gchar *keyname,
1303 gpointer user_data);
1304
1305static GList *settingsList = NULL;
1306static GSettings *compizconfigSettings = NULL;
1307static GSettings *currentProfileSettings = NULL;
1308static GList *watchedGnomeSettings = NULL;
1309
1310char *currentProfile = NULL;
1311
1312/* some forward declarations */
1313static void writeIntegratedOption (CCSContext *context,
1314 CCSSetting *setting,
1315 int index);
1316
1317typedef struct _SpecialOptionGSettings {
1318 const char* settingName;
1319 const char* pluginName;
1320 const char* schemaName;
1321 const char* keyName;
1322 const char* type;
1323} SpecialOption;
1324
1325static gchar *
1326getSchemaNameForPlugin (const char *plugin)
1327{
1328 gchar *schemaName = NULL;
1329
1330 schemaName = g_strconcat (COMPIZ_SCHEMA_ID, ".", plugin, NULL);
1331
1332 return schemaName;
1333}
1334
1335static inline gchar *
1336translateKeyForGSettings (char *gsettingName)
1337{
1338 gchar *clean = NULL;
1339 gchar **delimited = NULL;
1340 guint i = 0;
1341
1342 /* Replace underscores with dashes */
1343 delimited = g_strsplit (gsettingName, "_", 0);
1344
1345 clean = g_strjoinv ("-", delimited);
1346
1347 /* It can't be more than 32 chars, warn if that's the case */
1348 gchar *ret = g_strndup (clean, 31);
1349
1350 if (strlen (clean) > 31)
1351 printf ("GSettings Backend: Warning: key name %s is not valid in GSettings, it was changed to %s, this may cause problems!\n", clean, ret);
1352
1353 /* Everything must be lowercase */
1354 for (; i < strlen (ret); i++)
1355 ret[i] = g_ascii_tolower (ret[i]);
1356
1357 g_free (clean);
1358 g_strfreev (delimited);
1359
1360 return ret;
1361}
1362
1363static inline gchar *
1364translateKeyForCCS (char *gsettingName)
1365{
1366 gchar *clean = NULL;
1367 gchar **delimited = NULL;
1368
1369 /* Replace dashes with underscores */
1370 delimited = g_strsplit (gsettingName, "-", 0);
1371
1372 clean = g_strjoinv ("_", delimited);
1373
1374 /* FIXME: Truncated and lowercased settings aren't going to work */
1375
1376 g_strfreev (delimited);
1377
1378 return clean;
1379}
1380
1381static GSettings *
1382getSettingsObjectForPluginWithPath (const char *plugin,
1383 const char *path,
1384 CCSContext *context)
1385{
1386 GSettings *settingsObj = NULL;
1387 GList *l = settingsList;
1388 gchar *schemaName = getSchemaNameForPlugin (plugin);
1389 GVariant *writtenPlugins;
1390 char *plug;
1391 GVariant *newWrittenPlugins;
1392 GVariantBuilder *newWrittenPluginsBuilder;
1393 GVariantIter *iter;
1394 gboolean found = FALSE;
1395
1396 while (l)
1397 {
1398 settingsObj = (GSettings *) l->data;
1399 gchar *name = NULL;
1400
1401 g_object_get (G_OBJECT (settingsObj),
1402 "schema",
1403 &name, NULL);
1404 if (g_strcmp0 (name, schemaName) == 0)
1405 {
1406 g_free (name);
1407 g_free (schemaName);
1408
1409 return settingsObj;
1410 }
1411
1412 l = g_list_next (l);
1413 }
1414
1415 /* No existing settings object found for this schema, create one */
1416
1417 settingsObj = g_settings_new_with_path (schemaName, path);
1418
1419 g_signal_connect (G_OBJECT (settingsObj), "changed", (GCallback) valueChanged, (gpointer) context);
1420
1421 settingsList = g_list_append (settingsList, (void *) settingsObj);
1422
1423 /* Also write the plugin name to the list of modified plugins so
1424 * that when we delete the profile the keys for that profile are also
1425 * unset FIXME: This could be a little more efficient, like we could
1426 * store keys that have changed from their defaults ... though
1427 * gsettings doesn't seem to give you a way to get all of the schemas */
1428
1429 writtenPlugins = g_settings_get_value (currentProfileSettings, "plugins-with-set-keys");
1430
1431 newWrittenPluginsBuilder = g_variant_builder_new (G_VARIANT_TYPE ("as"));
1432
1433 iter = g_variant_iter_new (writtenPlugins);
1434 while (g_variant_iter_next (iter, "s", &plug))
1435 {
1436 g_variant_builder_add (newWrittenPluginsBuilder, "s", plug);
1437
1438 if (!found)
1439 found = (g_strcmp0 (plug, plugin) == 0);
1440
1441 g_free (plug);
1442 }
1443
1444 if (!found)
1445 g_variant_builder_add (newWrittenPluginsBuilder, "s", plugin);
1446
1447 newWrittenPlugins = g_variant_new ("as", newWrittenPluginsBuilder);
1448 g_settings_set_value (currentProfileSettings, "plugins-with-set-keys", newWrittenPlugins);
1449
1450 g_variant_iter_free (iter);
1451 g_variant_unref (newWrittenPlugins);
1452 g_variant_builder_unref (newWrittenPluginsBuilder);
1453
1454 return settingsObj;
1455}
1456
1457static GSettings *
1458getSettingsObjectForCCSSetting (CCSSetting *setting)
1459{
1460 KEYNAME(setting->parent->context->screenNum);
1461 PATHNAME (setting->parent->name, keyName);
1462
1463 return getSettingsObjectForPluginWithPath (setting->parent->name, pathName, setting->parent->context);
1464}
1465
1466static Bool
1467isIntegratedOption (CCSSetting *setting,
1468 int *index)
1469{
1470#ifdef USE_GCONF
1471 return isGConfIntegratedOption (setting, index);
1472#else
1473 return FALSE;
1474#endif
1475}
1476
1477static void
1478gnomeValueChanged (GSettings *settings,
1479 gchar *keyName,
1480 gpointer user_data)
1481{
1482}
1483
1484static void
1485valueChanged (GSettings *settings,
1486 gchar *keyName,
1487 gpointer user_data)
1488{
1489 CCSContext *context = (CCSContext *)user_data;
1490 char *uncleanKeyName;
1491 char *path;
1492 char *token;
1493 int index;
1494 unsigned int screenNum;
1495 CCSPlugin *plugin;
1496 CCSSetting *setting;
1497
1498 g_object_get (G_OBJECT (settings), "path", &path, NULL);
1499
1500 path += strlen (COMPIZ) + 1;
1501
1502 token = strsep (&path, "/"); /* Profile name */
1503 if (!token)
1504 return;
1505
1506 token = strsep (&path, "/"); /* plugins */
1507 if (!token)
1508 return;
1509
1510 token = strsep (&path, "/"); /* plugin */
1511 if (!token)
1512 return;
1513
1514 plugin = ccsFindPlugin (context, token);
1515 if (!plugin)
1516 return;
1517
1518 token = strsep (&path, "/"); /* screen%i */
1519 if (!token)
1520 return;
1521
1522 sscanf (token, "screen%d", &screenNum);
1523
1524 uncleanKeyName = translateKeyForCCS (keyName);
1525
1526 setting = ccsFindSetting (plugin, uncleanKeyName);
1527
1528 /* Try again, this time truncating the settings themselves */
1529 if (!setting)
1530 {
1531 char *cleanKeyName;
1532 CCSSettingList it = ccsGetPluginSettings (plugin);
1533
1534 while (it)
1535 {
1536 cleanKeyName = translateKeyForGSettings (((CCSSetting *) it->data)->name);
1537
1538 if (g_strcmp0 (cleanKeyName, keyName) == 0)
1539 {
1540 free (cleanKeyName);
1541 setting = it->data;
1542 break;
1543 }
1544
1545 free (cleanKeyName);
1546
1547 it = it->next;
1548 }
1549 }
1550
1551 if (!setting)
1552 {
1553 printf ("GSettings Backend: unable to find setting %s, for path %s\n", uncleanKeyName, path);
1554 free (uncleanKeyName);
1555 return;
1556 }
1557
1558 readInit (context);
1559 if (!readOption (setting))
1560 {
1561 ccsResetToDefault (setting, TRUE);
1562 }
1563
1564 if (ccsGetIntegrationEnabled (context) &&
1565 isIntegratedOption (setting, &index))
1566 {
1567 writeInit (context);
1568 writeIntegratedOption (context, setting, index);
1569 }
1570
1571 free (uncleanKeyName);
1572}
1573
1574static Bool
1575readListValue (CCSSetting *setting)
1576{
1577 GSettings *settings = getSettingsObjectForCCSSetting (setting);
1578 gchar *variantType;
1579 unsigned int nItems, i = 0;
1580 CCSSettingValueList list = NULL;
1581 GVariant *value;
1582 GVariantIter *iter;
1583
1584 char *cleanSettingName = translateKeyForGSettings (setting->name);
1585
1586 switch (setting->info.forList.listType)
1587 {
1588 case TypeString:
1589 case TypeMatch:
1590 case TypeColor:
1591 variantType = g_strdup ("s");
1592 break;
1593 case TypeBool:
1594 variantType = g_strdup ("b");
1595 break;
1596 case TypeInt:
1597 variantType = g_strdup ("i");
1598 break;
1599 case TypeFloat:
1600 variantType = g_strdup ("d");
1601 break;
1602 default:
1603 variantType = NULL;
1604 break;
1605 }
1606
1607 if (!variantType)
1608 return FALSE;
1609
1610 value = g_settings_get_value (settings, cleanSettingName);
1611 if (!value)
1612 {
1613 ccsResetToDefault (setting, TRUE);
1614 return TRUE;
1615 }
1616
1617 iter = g_variant_iter_new (value);
1618 nItems = g_variant_iter_n_children (iter);
1619
1620 if (nItems)
1621 {
1622 switch (setting->info.forList.listType)
1623 {
1624 case TypeBool:
1625 {
1626 Bool *array = malloc (nItems * sizeof (Bool));
1627 Bool *arrayCounter = array;
1628 gboolean v;
1629
1630 if (!array)
1631 break;
1632
1633 /* Reads each item from the variant into the position pointed
1634 * at by arrayCounter */
1635 while (g_variant_iter_next (iter, variantType, &v))
1636 {
1637 *arrayCounter++ = v;
1638 }
1639
1640 list = ccsGetValueListFromBoolArray (array, nItems, setting);
1641 free (array);
1642 }
1643 break;
1644 case TypeInt:
1645 {
1646 int *array = malloc (nItems * sizeof (int));
1647 int *arrayCounter = array;
1648
1649 if (!array)
1650 break;
1651
1652 /* Reads each item from the variant into the position pointed
1653 * at by arrayCounter */
1654 while (g_variant_iter_next (iter, variantType, arrayCounter++));
1655
1656 list = ccsGetValueListFromIntArray (array, nItems, setting);
1657 free (array);
1658 }
1659 break;
1660 case TypeFloat:
1661 {
1662 double *array = malloc (nItems * sizeof (double));
1663 double *arrayCounter = array;
1664
1665 if (!array)
1666 break;
1667
1668 /* Reads each item from the variant into the position pointed
1669 * at by arrayCounter */
1670 while (g_variant_iter_next (iter, variantType, arrayCounter++));
1671
1672 list = ccsGetValueListFromFloatArray ((float *) array, nItems, setting);
1673 free (array);
1674 }
1675 break;
1676 case TypeString:
1677 case TypeMatch:
1678 {
1679 char **array = calloc (1, (nItems + 1) * sizeof (char *));
1680 char **arrayCounter = array;
1681
1682 if (!array)
1683 {
1684 break;
1685 }
1686
1687 /* Reads each item from the variant into the position pointed
1688 * at by arrayCounter */
1689 while (g_variant_iter_next (iter, variantType, arrayCounter++));
1690
1691 list = ccsGetValueListFromStringArray (array, nItems, setting);
1692 for (i = 0; i < nItems; i++)
1693 if (array[i])
1694 free (array[i]);
1695 free (array);
1696 }
1697 break;
1698 case TypeColor:
1699 {
1700 CCSSettingColorValue *array;
1701 char *colorValue;
1702 array = malloc (nItems * sizeof (CCSSettingColorValue));
1703 if (!array)
1704 break;
1705
1706 while (g_variant_iter_next (iter, variantType, &colorValue))
1707 {
1708 memset (&array[i], 0, sizeof (CCSSettingColorValue));
1709 ccsStringToColor (colorValue,
1710 &array[i]);
1711 }
1712 list = ccsGetValueListFromColorArray (array, nItems, setting);
1713 free (array);
1714 }
1715 break;
1716 default:
1717 break;
1718 }
1719 }
1720
1721 free (cleanSettingName);
1722 free (variantType);
1723
1724 if (list)
1725 {
1726 ccsSetList (setting, list, TRUE);
1727 ccsSettingValueListFree (list, TRUE);
1728 return TRUE;
1729 }
1730 else
1731 ccsResetToDefault (setting, TRUE);
1732
1733 return FALSE;
1734}
1735
1736static Bool
1737readIntegratedOption (CCSContext *context,
1738 CCSSetting *setting,
1739 int index)
1740{
1741#ifdef USE_GCONF
1742 return readGConfIntegratedOption (context, setting, index);
1743#else
1744 return FALSE;
1745#endif
1746}
1747
1748Bool
1749readOption (CCSSetting * setting)
1750{
1751 GSettings *settings = getSettingsObjectForCCSSetting (setting);
1752 GVariant *gsettingsValue = NULL;
1753 Bool ret = FALSE;
1754 Bool valid = TRUE;
1755
1756 /* It is impossible for certain settings to have a schema,
1757 * such as actions and read only settings, so in that case
1758 * just return FALSE since compizconfig doesn't expect us
1759 * to read them anyways */
1760
1761 if (setting->type == TypeAction ||
1762 ccsSettingIsReadOnly (setting))
1763 {
1764 return FALSE;
1765 }
1766
1767 char *cleanSettingName = translateKeyForGSettings (setting->name);
1768 KEYNAME(setting->parent->context->screenNum);
1769 PATHNAME (setting->parent->name, keyName);
1770
1771 /* first check if the key is set */
1772 gsettingsValue = g_settings_get_value (settings, cleanSettingName);
1773
1774 switch (setting->type)
1775 {
1776 case TypeString:
1777 case TypeMatch:
1778 case TypeColor:
1779 case TypeKey:
1780 case TypeButton:
1781 case TypeEdge:
1782 valid = (g_variant_type_is_subtype_of (G_VARIANT_TYPE_STRING, g_variant_get_type (gsettingsValue)));
1783 break;
1784 case TypeInt:
1785 valid = (g_variant_type_is_subtype_of (G_VARIANT_TYPE_INT32, g_variant_get_type (gsettingsValue)));
1786 break;
1787 case TypeBool:
1788 case TypeBell:
1789 valid = (g_variant_type_is_subtype_of (G_VARIANT_TYPE_BOOLEAN, g_variant_get_type (gsettingsValue)));
1790 break;
1791 case TypeFloat:
1792 valid = (g_variant_type_is_subtype_of (G_VARIANT_TYPE_DOUBLE, g_variant_get_type (gsettingsValue)));
1793 break;
1794 case TypeList:
1795 valid = (g_variant_type_is_array (g_variant_get_type (gsettingsValue)));
1796 break;
1797 default:
1798 break;
1799 }
1800
1801 if (!valid)
1802 {
1803 printf ("GSettings backend: There is an unsupported value at path %s. "
1804 "Settings from this path won't be read. Try to remove "
1805 "that value so that operation can continue properly.\n",
1806 pathName);
1807 free (cleanSettingName);
1808 g_variant_unref (gsettingsValue);
1809 return FALSE;
1810 }
1811
1812 switch (setting->type)
1813 {
1814 case TypeString:
1815 {
1816 const char *value;
1817 value = g_variant_get_string (gsettingsValue, NULL);
1818 if (value)
1819 {
1820 ccsSetString (setting, value, FALSE);
1821 ret = TRUE;
1822 }
1823 }
1824 break;
1825 case TypeMatch:
1826 {
1827 const char * value;
1828 value = g_variant_get_string (gsettingsValue, NULL);
1829 if (value)
1830 {
1831 ccsSetMatch (setting, value, FALSE);
1832 ret = TRUE;
1833 }
1834 }
1835 break;
1836 case TypeInt:
1837 {
1838 int value;
1839 value = g_variant_get_int32 (gsettingsValue);
1840
1841 ccsSetInt (setting, value, FALSE);
1842 ret = TRUE;
1843 }
1844 break;
1845 case TypeBool:
1846 {
1847 gboolean value;
1848 value = g_variant_get_boolean (gsettingsValue);
1849
1850 ccsSetBool (setting, value ? TRUE : FALSE, FALSE);
1851 ret = TRUE;
1852 }
1853 break;
1854 case TypeFloat:
1855 {
1856 double value;
1857 value = g_variant_get_double (gsettingsValue);
1858
1859 ccsSetFloat (setting, (float)value, FALSE);
1860 ret = TRUE;
1861 }
1862 break;
1863 case TypeColor:
1864 {
1865 const char *value;
1866 CCSSettingColorValue color;
1867 value = g_variant_get_string (gsettingsValue, NULL);
1868
1869 if (value && ccsStringToColor (value, &color))
1870 {
1871 ccsSetColor (setting, color, FALSE);
1872 ret = TRUE;
1873 }
1874 }
1875 break;
1876 case TypeKey:
1877 {
1878 const char *value;
1879 CCSSettingKeyValue key;
1880 value = g_variant_get_string (gsettingsValue, NULL);
1881
1882 if (value && ccsStringToKeyBinding (value, &key))
1883 {
1884 ccsSetKey (setting, key, FALSE);
1885 ret = TRUE;
1886 }
1887 }
1888 break;
1889 case TypeButton:
1890 {
1891 const char *value;
1892 CCSSettingButtonValue button;
1893 value = g_variant_get_string (gsettingsValue, NULL);
1894
1895 if (value && ccsStringToButtonBinding (value, &button))
1896 {
1897 ccsSetButton (setting, button, FALSE);
1898 ret = TRUE;
1899 }
1900 }
1901 break;
1902 case TypeEdge:
1903 {
1904 const char *value;
1905 value = g_variant_get_string (gsettingsValue, NULL);
1906
1907 if (value)
1908 {
1909 unsigned int edges;
1910 edges = ccsStringToEdges (value);
1911 ccsSetEdge (setting, edges, FALSE);
1912 ret = TRUE;
1913 }
1914 }
1915 break;
1916 case TypeBell:
1917 {
1918 gboolean value;
1919 value = g_variant_get_boolean (gsettingsValue);
1920
1921 ccsSetBell (setting, value ? TRUE : FALSE, FALSE);
1922 ret = TRUE;
1923 }
1924 break;
1925 case TypeList:
1926 ret = readListValue (setting);
1927 break;
1928 default:
1929 printf("GSettings backend: attempt to read unsupported setting type %d!\n",
1930 setting->type);
1931 break;
1932 }
1933
1934 free (cleanSettingName);
1935 g_variant_unref (gsettingsValue);
1936
1937 return ret;
1938}
1939
1940static void
1941writeListValue (CCSSetting *setting,
1942 char *pathName)
1943{
1944 GSettings *settings = getSettingsObjectForCCSSetting (setting);
1945 GVariant *value;
1946 gchar *variantType = NULL;
1947 CCSSettingValueList list;
1948
1949 char *cleanSettingName = translateKeyForGSettings (setting->name);
1950
1951 if (!ccsGetList (setting, &list))
1952 return;
1953
1954 switch (setting->info.forList.listType)
1955 {
1956 case TypeBool:
1957 {
1958 variantType = "ab";
1959 GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE ("ab"));
1960 while (list)
1961 {
1962 g_variant_builder_add (builder, "b", list->data->value.asBool);
1963 list = list->next;
1964 }
1965 value = g_variant_new ("ab", builder);
1966 g_variant_builder_unref (builder);
1967 }
1968 break;
1969 case TypeInt:
1970 {
1971 variantType = "ai";
1972 GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE ("ai"));
1973 while (list)
1974 {
1975 g_variant_builder_add (builder, "i", list->data->value.asInt);
1976 list = list->next;
1977 }
1978 value = g_variant_new ("ai", builder);
1979 g_variant_builder_unref (builder);
1980 }
1981 break;
1982 case TypeFloat:
1983 {
1984 variantType = "ad";
1985 GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE ("ad"));
1986 while (list)
1987 {
1988 g_variant_builder_add (builder, "d", (gdouble) list->data->value.asFloat);
1989 list = list->next;
1990 }
1991 value = g_variant_new ("ad", builder);
1992 g_variant_builder_unref (builder);
1993 }
1994 break;
1995 case TypeString:
1996 {
1997 variantType = "as";
1998 GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE ("as"));
1999 while (list)
2000 {
2001 g_variant_builder_add (builder, "s", list->data->value.asString);
2002 list = list->next;
2003 }
2004 value = g_variant_new ("as", builder);
2005 g_variant_builder_unref (builder);
2006 }
2007 break;
2008 case TypeMatch:
2009 {
2010 variantType = "as";
2011 GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE ("as"));
2012 while (list)
2013 {
2014 g_variant_builder_add (builder, "s", list->data->value.asMatch);
2015 list = list->next;
2016 }
2017 value = g_variant_new ("as", builder);
2018 g_variant_builder_unref (builder);
2019 }
2020 break;
2021 case TypeColor:
2022 {
2023 variantType = "as";
2024 GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE ("as"));
2025 char *item;
2026 while (list)
2027 {
2028 item = ccsColorToString (&list->data->value.asColor);
2029 g_variant_builder_add (builder, "s", item);
2030 list = list->next;
2031 }
2032 value = g_variant_new ("as", builder);
2033 g_variant_builder_unref (builder);
2034 }
2035 break;
2036 default:
2037 printf("GSettings backend: attempt to write unsupported list type %d!\n",
2038 setting->info.forList.listType);
2039 variantType = NULL;
2040 break;
2041 }
2042
2043 if (variantType != NULL)
2044 {
2045 g_settings_set_value (settings, cleanSettingName, value);
2046 g_variant_unref (value);
2047 }
2048
2049 free (cleanSettingName);
2050}
2051
2052static void
2053writeIntegratedOption (CCSContext *context,
2054 CCSSetting *setting,
2055 int index)
2056{
2057#ifdef USE_GCONF
2058 writeGConfIntegratedOption (context, setting, index);
2059#endif
2060
2061 return;
2062}
2063
2064static void
2065resetOptionToDefault (CCSSetting * setting)
2066{
2067 GSettings *settings = getSettingsObjectForCCSSetting (setting);
2068
2069 char *cleanSettingName = translateKeyForGSettings (setting->name);
2070 KEYNAME (setting->parent->context->screenNum);
2071 PATHNAME (setting->parent->name, keyName);
2072
2073 g_settings_reset (settings, cleanSettingName);
2074
2075 free (cleanSettingName);
2076}
2077
2078void
2079writeOption (CCSSetting * setting)
2080{
2081 GSettings *settings = getSettingsObjectForCCSSetting (setting);
2082 char *cleanSettingName = translateKeyForGSettings (setting->name);
2083 KEYNAME (setting->parent->context->screenNum);
2084 PATHNAME (setting->parent->name, keyName);
2085
2086 switch (setting->type)
2087 {
2088 case TypeString:
2089 {
2090 char *value;
2091 if (ccsGetString (setting, &value))
2092 {
2093 g_settings_set (settings, cleanSettingName, "s", value, NULL);
2094 }
2095 }
2096 break;
2097 case TypeMatch:
2098 {
2099 char *value;
2100 if (ccsGetMatch (setting, &value))
2101 {
2102 g_settings_set (settings, cleanSettingName, "s", value, NULL);
2103 }
2104 }
2105 case TypeFloat:
2106 {
2107 float value;
2108 if (ccsGetFloat (setting, &value))
2109 {
2110 g_settings_set (settings, cleanSettingName, "d", (double) value, NULL);
2111 }
2112 }
2113 break;
2114 case TypeInt:
2115 {
2116 int value;
2117 if (ccsGetInt (setting, &value))
2118 {
2119 g_settings_set (settings, cleanSettingName, "i", value, NULL);
2120 }
2121 }
2122 break;
2123 case TypeBool:
2124 {
2125 Bool value;
2126 if (ccsGetBool (setting, &value))
2127 {
2128 g_settings_set (settings, cleanSettingName, "b", value, NULL);
2129 }
2130 }
2131 break;
2132 case TypeColor:
2133 {
2134 CCSSettingColorValue value;
2135 char *colString;
2136
2137 if (!ccsGetColor (setting, &value))
2138 break;
2139
2140 colString = ccsColorToString (&value);
2141 if (!colString)
2142 break;
2143
2144 g_settings_set (settings, cleanSettingName, "s", colString, NULL);
2145 free (colString);
2146 }
2147 break;
2148 case TypeKey:
2149 {
2150 CCSSettingKeyValue key;
2151 char *keyString;
2152
2153 if (!ccsGetKey (setting, &key))
2154 break;
2155
2156 keyString = ccsKeyBindingToString (&key);
2157 if (!keyString)
2158 break;
2159
2160 g_settings_set (settings, cleanSettingName, "s", keyString, NULL);
2161 free (keyString);
2162 }
2163 break;
2164 case TypeButton:
2165 {
2166 CCSSettingButtonValue button;
2167 char *buttonString;
2168
2169 if (!ccsGetButton (setting, &button))
2170 break;
2171
2172 buttonString = ccsButtonBindingToString (&button);
2173 if (!buttonString)
2174 break;
2175
2176 g_settings_set (settings, cleanSettingName, "s", buttonString, NULL);
2177 free (buttonString);
2178 }
2179 break;
2180 case TypeEdge:
2181 {
2182 unsigned int edges;
2183 char *edgeString;
2184
2185 if (!ccsGetEdge (setting, &edges))
2186 break;
2187
2188 edgeString = ccsEdgesToString (edges);
2189 if (!edgeString)
2190 break;
2191
2192 g_settings_set (settings, cleanSettingName, "s", edgeString, NULL);
2193 free (edgeString);
2194 }
2195 break;
2196 case TypeBell:
2197 {
2198 Bool value;
2199 if (ccsGetBell (setting, &value))
2200 {
2201 g_settings_set (settings, cleanSettingName, "s", value, NULL);
2202 }
2203 }
2204 break;
2205 case TypeList:
2206 writeListValue (setting, pathName);
2207 break;
2208 default:
2209 printf("GSettings backend: attempt to write unsupported setting type %d\n",
2210 setting->type);
2211 break;
2212 }
2213
2214 free (cleanSettingName);
2215}
2216
2217static void
2218updateCurrentProfileName (char *profile)
2219{
2220 GVariant *profiles;
2221 char *prof;
2222 char *profilePath = COMPIZ_PROFILEPATH;
2223 char *currentProfilePath;
2224 GVariant *newProfiles;
2225 GVariantBuilder *newProfilesBuilder;
2226 GVariantIter *iter;
2227 gboolean found = FALSE;
2228
2229 profiles = g_settings_get_value (compizconfigSettings, "existing-profiles");
2230
2231 newProfilesBuilder = g_variant_builder_new (G_VARIANT_TYPE ("as"));
2232
2233 iter = g_variant_iter_new (profiles);
2234 while (g_variant_iter_next (iter, "s", &prof))
2235 {
2236 g_variant_builder_add (newProfilesBuilder, "s", prof);
2237
2238 if (!found)
2239 found = (g_strcmp0 (prof, profile) == 0);
2240 }
2241
2242 if (!found)
2243 g_variant_builder_add (newProfilesBuilder, "s", profile);
2244
2245 newProfiles = g_variant_new ("as", newProfilesBuilder);
2246 g_settings_set_value (compizconfigSettings, "existing-profiles", newProfiles);
2247
2248 g_variant_iter_free (iter);
2249 g_variant_unref (newProfiles);
2250 g_variant_builder_unref (newProfilesBuilder);
2251
2252 /* Change the current profile and current profile settings */
2253 free (currentProfile);
2254
2255 currentProfile = strdup (profile);
2256 currentProfilePath = g_strconcat (profilePath, profile, "/", NULL);
2257 currentProfileSettings = g_settings_new_with_path (PROFILE_SCHEMA_ID, profilePath);
2258
2259 g_free (currentProfilePath);
2260
2261 g_settings_set (compizconfigSettings, "current-profile", "s", profile, NULL);
2262}
2263
2264static gboolean
2265updateProfile (CCSContext *context)
2266{
2267 char *profile = strdup (ccsGetProfile (context));
2268
2269 if (!profile || !strlen (profile))
2270 profile = strdup (DEFAULTPROF);
2271
2272 if (g_strcmp0 (profile, currentProfile))
2273 updateCurrentProfileName (profile);
2274
2275 free (profile);
2276
2277 return TRUE;
2278}
2279
2280static char*
2281getCurrentProfileName (void)
2282{
2283 GVariant *value;
2284 char *ret = NULL;
2285
2286 value = g_settings_get_value (compizconfigSettings, "current-profile");
2287
2288 if (value)
2289 ret = strdup (g_variant_get_string (value, NULL));
2290 else
2291 ret = strdup (DEFAULTPROF);
2292
2293 return ret;
2294}
2295
2296static void
2297processEvents (unsigned int flags)
2298{
2299 if (!(flags & ProcessEventsNoGlibMainLoopMask))
2300 {
2301 while (g_main_context_pending(NULL))
2302 g_main_context_iteration(NULL, FALSE);
2303 }
2304}
2305
2306static Bool
2307initBackend (CCSContext * context)
2308{
2309 const char *profilePath = PROFILEPATH;
2310 char *currentProfilePath;
2311
2312 g_type_init ();
2313
2314 compizconfigSettings = g_settings_new (COMPIZCONFIG_SCHEMA_ID);
2315
2316#ifdef USE_GCONF
2317 initGConfClient (context);
2318#endif
2319
2320 currentProfile = getCurrentProfileName ();
2321 currentProfilePath = g_strconcat (profilePath, currentProfile, "/", NULL);
2322 currentProfileSettings = g_settings_new_with_path (PROFILE_SCHEMA_ID, currentProfilePath);
2323
2324 g_free (currentProfilePath);
2325
2326 return TRUE;
2327}
2328
2329static Bool
2330finiBackend (CCSContext * context)
2331{
2332 GList *l = settingsList;
2333
2334 processEvents (0);
2335
2336#ifdef USE_GCONF
2337 gconf_client_clear_cache (client);
2338 finiGConfClient ();
2339#endif
2340
2341 if (currentProfile)
2342 {
2343 free (currentProfile);
2344 currentProfile = NULL;
2345 }
2346
2347 while (l)
2348 {
2349 g_object_unref (G_OBJECT (l->data));
2350 l = g_list_next (l);
2351 }
2352
2353 g_object_unref (G_OBJECT (compizconfigSettings));
2354
2355 processEvents (0);
2356 return TRUE;
2357}
2358
2359Bool
2360readInit (CCSContext * context)
2361{
2362 return updateProfile (context);
2363}
2364
2365void
2366readSetting (CCSContext *context,
2367 CCSSetting *setting)
2368{
2369 Bool status;
2370 int index;
2371
2372 if (ccsGetIntegrationEnabled (context) &&
2373 isIntegratedOption (setting, &index))
2374 {
2375 status = readIntegratedOption (context, setting, index);
2376 }
2377 else
2378 status = readOption (setting);
2379
2380 if (!status)
2381 ccsResetToDefault (setting, TRUE);
2382}
2383
2384Bool
2385writeInit (CCSContext * context)
2386{
2387 return updateProfile (context);
2388}
2389
2390void
2391writeSetting (CCSContext *context,
2392 CCSSetting *setting)
2393{
2394 int index;
2395
2396 if (ccsGetIntegrationEnabled (context) &&
2397 isIntegratedOption (setting, &index))
2398 {
2399 writeIntegratedOption (context, setting, index);
2400 }
2401 else if (setting->isDefault)
2402 {
2403 resetOptionToDefault (setting);
2404 }
2405 else
2406 writeOption (setting);
2407
2408}
2409
2410static Bool
2411getSettingIsIntegrated (CCSSetting * setting)
2412{
2413 if (!ccsGetIntegrationEnabled (setting->parent->context))
2414 return FALSE;
2415
2416 if (!isIntegratedOption (setting, NULL))
2417 return FALSE;
2418
2419 return TRUE;
2420}
2421
2422static Bool
2423getSettingIsReadOnly (CCSSetting * setting)
2424{
2425 /* FIXME */
2426 return FALSE;
2427}
2428
2429static CCSStringList
2430getExistingProfiles (CCSContext *context)
2431{
2432 GVariant *value;
2433 char *profile;
2434 GVariantIter iter;
2435 CCSStringList ret = NULL;
2436
2437 value = g_settings_get_value (compizconfigSettings, "existing-profiles");
2438 g_variant_iter_init (&iter, value);
2439 while (g_variant_iter_next (&iter, "s", &profile))
2440 {
2441 CCSString *str = malloc (sizeof (CCSString));
2442
2443 str->value = profile;
2444
2445 ret = ccsStringListAppend (ret, str);
2446 }
2447
2448 g_variant_unref (value);
2449
2450 return ret;
2451}
2452
2453static Bool
2454deleteProfile (CCSContext *context,
2455 char *profile)
2456{
2457 GVariant *plugins;
2458 GVariant *profiles;
2459 GVariant *newProfiles;
2460 GVariantBuilder *newProfilesBuilder;
2461 char *plugin, *prof;
2462 GVariantIter *iter;
2463 char *profileSettingsPath = g_strconcat (PROFILEPATH, profile, "/", NULL);
2464 GSettings *profileSettings = g_settings_new_with_path (PROFILE_SCHEMA_ID, profileSettingsPath);
2465
2466 plugins = g_settings_get_value (currentProfileSettings, "plugins-with-set-keys");
2467 profiles = g_settings_get_value (compizconfigSettings, "existing-profiles");
2468
2469 iter = g_variant_iter_new (plugins);
2470 while (g_variant_iter_next (iter, "s", &plugin))
2471 {
2472 GSettings *settings;
2473
2474 KEYNAME (context->screenNum);
2475 PATHNAME (plugin, keyName);
2476
2477 settings = getSettingsObjectForPluginWithPath (plugin, pathName, context);
2478
2479 /* The GSettings documentation says not to use this API
2480 * because we should know our own schema ... though really
2481 * we don't because we autogenerate schemas ... */
2482 if (settings)
2483 {
2484 char **keys = g_settings_list_keys (settings);
2485 char **key_ptr;
2486
2487 /* Unset all the keys */
2488 for (key_ptr = keys; *key_ptr; key_ptr++)
2489 g_settings_reset (settings, *key_ptr);
2490
2491 g_strfreev (keys);
2492 }
2493
2494 g_free (plugin);
2495 }
2496
2497 /* Remove the profile from existing-profiles */
2498 g_variant_iter_free (iter);
2499 g_settings_reset (profileSettings, "plugins-with-set-values");
2500
2501 iter = g_variant_iter_new (profiles);
2502 newProfilesBuilder = g_variant_builder_new (G_VARIANT_TYPE ("as"));
2503
2504 while (g_variant_iter_next (iter, "s", &prof))
2505 {
2506 if (g_strcmp0 (prof, profile))
2507 g_variant_builder_add (newProfilesBuilder, "s", prof);
2508
2509 g_free (prof);
2510 }
2511
2512 newProfiles = g_variant_new ("as", newProfilesBuilder);
2513 g_settings_set_value (compizconfigSettings, "existing-profiles", newProfiles);
2514
2515 g_variant_unref (newProfiles);
2516 g_variant_builder_unref (newProfilesBuilder);
2517
2518 free (profileSettingsPath);
2519
2520 updateProfile (context);
2521
2522 return TRUE;
2523}
2524
2525static CCSBackendVTable gsettingsVTable = {
2526 "gsettings",
2527 "GSettings Configuration Backend",
2528 "GSettings Configuration Backend for libccs",
2529 TRUE,
2530 TRUE,
2531 processEvents,
2532 initBackend,
2533 finiBackend,
2534 readInit,
2535 readSetting,
2536 0,
2537 writeInit,
2538 writeSetting,
2539 0,
2540 getSettingIsIntegrated,
2541 getSettingIsReadOnly,
2542 getExistingProfiles,
2543 deleteProfile
2544};
2545
2546CCSBackendVTable *
2547getBackendInfo (void)
2548{
2549 return &gsettingsVTable;
2550}
2551
2552>>>>>>> MERGE-SOURCE

Subscribers

People subscribed via source and target branches