Merge lp:~compiz-team/compiz-libcompizconfig/compiz-libcompizconfig.fix_874830 into lp:compiz-libcompizconfig
- compiz-libcompizconfig.fix_874830
- Merge into 0.9.5
Status: | Superseded |
---|---|
Proposed branch: | lp:~compiz-team/compiz-libcompizconfig/compiz-libcompizconfig.fix_874830 |
Merge into: | lp:compiz-libcompizconfig |
Diff against target: |
583 lines (+428/-13) 4 files modified
backend/src/ini.c (+12/-12) src/CMakeLists.txt (+1/-0) src/ccs-private.h (+7/-0) src/main.c (+408/-1) |
To merge this branch: | bzr merge lp:~compiz-team/compiz-libcompizconfig/compiz-libcompizconfig.fix_874830 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Tim Penhey (community) | Needs Fixing | ||
Review via email: mp+79452@code.launchpad.net |
Commit message
Description of the change
Sam Spilsbury (smspillaz) wrote : | # |
Should I include some sample files in a tests/ directory to demonstrate how the settings upgrade / key renames / default overrides ? They won't be installable at runtime (since we don't want users to accidentally create a profile which will have its key values changed by some testing code), but at least they could be there for example's sake.
> Also another reason why I had boolean parameters:
> - ccsSetString (setting, value, TRUE);
> + ccsSetString (setting, value, FALSE);
> This tells the reviewer exactly nothing.
Yes, that need to be changed to:
enum
{
WriteSetting,
SetTemporary
};
Though in reality, CCSSetting needs to be an abstracted class or something since this code really just abuses the structure into storing some temporary data.
Unmerged revisions
- 425. By Sam Spilsbury
-
Provide a generic method for system administrators and distributions
to handle renamed keys so that user settings will be transitioned to
the new key names and settings will not be lost.Provide a file in DATADIR/
compizconfig/ transitions called your_item. transition
with the following formatoldPluginName oldSettingName newPluginName newSettingName
oldPluginName2 oldSettingName2 newPluginName2 newSettingName2Keys will then be renamed appropriately.
Note that this requires backend support. If your backend does not support
reading from keys that don't have an installed schema, then those settings
will be erased as soon as the user upgrades since the schema data will be
lost. That includes GSettings at the moment.
Preview Diff
1 | === modified file 'backend/src/ini.c' | |||
2 | --- backend/src/ini.c 2011-08-20 19:03:37 +0000 | |||
3 | +++ backend/src/ini.c 2011-10-15 07:05:26 +0000 | |||
4 | @@ -275,7 +275,7 @@ | |||
5 | 275 | if (ccsIniGetString (data->iniFile, setting->parent->name, | 275 | if (ccsIniGetString (data->iniFile, setting->parent->name, |
6 | 276 | keyName, &value)) | 276 | keyName, &value)) |
7 | 277 | { | 277 | { |
9 | 278 | ccsSetString (setting, value, TRUE); | 278 | ccsSetString (setting, value, FALSE); |
10 | 279 | free (value); | 279 | free (value); |
11 | 280 | status = TRUE; | 280 | status = TRUE; |
12 | 281 | } | 281 | } |
13 | @@ -287,7 +287,7 @@ | |||
14 | 287 | if (ccsIniGetString (data->iniFile, setting->parent->name, | 287 | if (ccsIniGetString (data->iniFile, setting->parent->name, |
15 | 288 | keyName, &value)) | 288 | keyName, &value)) |
16 | 289 | { | 289 | { |
18 | 290 | ccsSetMatch (setting, value, TRUE); | 290 | ccsSetMatch (setting, value, FALSE); |
19 | 291 | free (value); | 291 | free (value); |
20 | 292 | status = TRUE; | 292 | status = TRUE; |
21 | 293 | } | 293 | } |
22 | @@ -299,7 +299,7 @@ | |||
23 | 299 | if (ccsIniGetInt (data->iniFile, setting->parent->name, | 299 | if (ccsIniGetInt (data->iniFile, setting->parent->name, |
24 | 300 | keyName, &value)) | 300 | keyName, &value)) |
25 | 301 | { | 301 | { |
27 | 302 | ccsSetInt (setting, value, TRUE); | 302 | ccsSetInt (setting, value, FALSE); |
28 | 303 | status = TRUE; | 303 | status = TRUE; |
29 | 304 | } | 304 | } |
30 | 305 | } | 305 | } |
31 | @@ -310,7 +310,7 @@ | |||
32 | 310 | if (ccsIniGetBool (data->iniFile, setting->parent->name, | 310 | if (ccsIniGetBool (data->iniFile, setting->parent->name, |
33 | 311 | keyName, &value)) | 311 | keyName, &value)) |
34 | 312 | { | 312 | { |
36 | 313 | ccsSetBool (setting, (value != 0), TRUE); | 313 | ccsSetBool (setting, (value != 0), FALSE); |
37 | 314 | status = TRUE; | 314 | status = TRUE; |
38 | 315 | } | 315 | } |
39 | 316 | } | 316 | } |
40 | @@ -321,7 +321,7 @@ | |||
41 | 321 | if (ccsIniGetFloat (data->iniFile, setting->parent->name, | 321 | if (ccsIniGetFloat (data->iniFile, setting->parent->name, |
42 | 322 | keyName, &value)) | 322 | keyName, &value)) |
43 | 323 | { | 323 | { |
45 | 324 | ccsSetFloat (setting, value, TRUE); | 324 | ccsSetFloat (setting, value, FALSE); |
46 | 325 | status = TRUE; | 325 | status = TRUE; |
47 | 326 | } | 326 | } |
48 | 327 | } | 327 | } |
49 | @@ -333,7 +333,7 @@ | |||
50 | 333 | if (ccsIniGetColor (data->iniFile, setting->parent->name, | 333 | if (ccsIniGetColor (data->iniFile, setting->parent->name, |
51 | 334 | keyName, &color)) | 334 | keyName, &color)) |
52 | 335 | { | 335 | { |
54 | 336 | ccsSetColor (setting, color, TRUE); | 336 | ccsSetColor (setting, color, FALSE); |
55 | 337 | status = TRUE; | 337 | status = TRUE; |
56 | 338 | } | 338 | } |
57 | 339 | } | 339 | } |
58 | @@ -344,7 +344,7 @@ | |||
59 | 344 | if (ccsIniGetKey (data->iniFile, setting->parent->name, | 344 | if (ccsIniGetKey (data->iniFile, setting->parent->name, |
60 | 345 | keyName, &key)) | 345 | keyName, &key)) |
61 | 346 | { | 346 | { |
63 | 347 | ccsSetKey (setting, key, TRUE); | 347 | ccsSetKey (setting, key, FALSE); |
64 | 348 | status = TRUE; | 348 | status = TRUE; |
65 | 349 | } | 349 | } |
66 | 350 | } | 350 | } |
67 | @@ -355,7 +355,7 @@ | |||
68 | 355 | if (ccsIniGetButton (data->iniFile, setting->parent->name, | 355 | if (ccsIniGetButton (data->iniFile, setting->parent->name, |
69 | 356 | keyName, &button)) | 356 | keyName, &button)) |
70 | 357 | { | 357 | { |
72 | 358 | ccsSetButton (setting, button, TRUE); | 358 | ccsSetButton (setting, button, FALSE); |
73 | 359 | status = TRUE; | 359 | status = TRUE; |
74 | 360 | } | 360 | } |
75 | 361 | } | 361 | } |
76 | @@ -366,7 +366,7 @@ | |||
77 | 366 | if (ccsIniGetEdge (data->iniFile, setting->parent->name, | 366 | if (ccsIniGetEdge (data->iniFile, setting->parent->name, |
78 | 367 | keyName, &edges)) | 367 | keyName, &edges)) |
79 | 368 | { | 368 | { |
81 | 369 | ccsSetEdge (setting, edges, TRUE); | 369 | ccsSetEdge (setting, edges, FALSE); |
82 | 370 | status = TRUE; | 370 | status = TRUE; |
83 | 371 | } | 371 | } |
84 | 372 | } | 372 | } |
85 | @@ -377,7 +377,7 @@ | |||
86 | 377 | if (ccsIniGetBell (data->iniFile, setting->parent->name, | 377 | if (ccsIniGetBell (data->iniFile, setting->parent->name, |
87 | 378 | keyName, &bell)) | 378 | keyName, &bell)) |
88 | 379 | { | 379 | { |
90 | 380 | ccsSetBell (setting, bell, TRUE); | 380 | ccsSetBell (setting, bell, FALSE); |
91 | 381 | status = TRUE; | 381 | status = TRUE; |
92 | 382 | } | 382 | } |
93 | 383 | } | 383 | } |
94 | @@ -388,7 +388,7 @@ | |||
95 | 388 | if (ccsIniGetList (data->iniFile, setting->parent->name, | 388 | if (ccsIniGetList (data->iniFile, setting->parent->name, |
96 | 389 | keyName, &value, setting)) | 389 | keyName, &value, setting)) |
97 | 390 | { | 390 | { |
99 | 391 | ccsSetList (setting, value, TRUE); | 391 | ccsSetList (setting, value, FALSE); |
100 | 392 | ccsSettingValueListFree (value, TRUE); | 392 | ccsSettingValueListFree (value, TRUE); |
101 | 393 | status = TRUE; | 393 | status = TRUE; |
102 | 394 | } | 394 | } |
103 | @@ -401,7 +401,7 @@ | |||
104 | 401 | if (!status) | 401 | if (!status) |
105 | 402 | { | 402 | { |
106 | 403 | /* reset setting to default if it could not be read */ | 403 | /* reset setting to default if it could not be read */ |
108 | 404 | ccsResetToDefault (setting, TRUE); | 404 | ccsResetToDefault (setting, FALSE); |
109 | 405 | } | 405 | } |
110 | 406 | 406 | ||
111 | 407 | if (keyName) | 407 | if (keyName) |
112 | 408 | 408 | ||
113 | === modified file 'src/CMakeLists.txt' | |||
114 | --- src/CMakeLists.txt 2010-05-21 02:55:08 +0000 | |||
115 | +++ src/CMakeLists.txt 2011-10-15 07:05:26 +0000 | |||
116 | @@ -24,6 +24,7 @@ | |||
117 | 24 | -DIMAGEDIR=\\\"${COMPIZ_IMAGEDIR}\\\" | 24 | -DIMAGEDIR=\\\"${COMPIZ_IMAGEDIR}\\\" |
118 | 25 | -DMETADATADIR=\\\"${COMPIZ_METADATADIR}\\\" | 25 | -DMETADATADIR=\\\"${COMPIZ_METADATADIR}\\\" |
119 | 26 | -DSYSCONFDIR=\\\"${COMPIZ_SYSCONFDIR}\\\" | 26 | -DSYSCONFDIR=\\\"${COMPIZ_SYSCONFDIR}\\\" |
120 | 27 | -DDATADIR=\\\"${COMPIZ_DATADIR}\\\" | ||
121 | 27 | -DLIBDIR=\\\"${COMPIZ_LIBDIR}\\\" | 28 | -DLIBDIR=\\\"${COMPIZ_LIBDIR}\\\" |
122 | 28 | ) | 29 | ) |
123 | 29 | 30 | ||
124 | 30 | 31 | ||
125 | === modified file 'src/ccs-private.h' | |||
126 | --- src/ccs-private.h 2011-08-20 19:03:37 +0000 | |||
127 | +++ src/ccs-private.h 2011-10-15 07:05:26 +0000 | |||
128 | @@ -72,7 +72,14 @@ | |||
129 | 72 | CCSSettingList replaceToValueSettings; | 72 | CCSSettingList replaceToValueSettings; |
130 | 73 | } CCSSettingsUpgrade; | 73 | } CCSSettingsUpgrade; |
131 | 74 | 74 | ||
132 | 75 | typedef struct _CCSSettingsTransition | ||
133 | 76 | { | ||
134 | 77 | char *file; | ||
135 | 78 | char *name; | ||
136 | 79 | } CCSSettingsTransition; | ||
137 | 80 | |||
138 | 75 | Bool ccsCheckForSettingsUpgrade (CCSContext *context); | 81 | Bool ccsCheckForSettingsUpgrade (CCSContext *context); |
139 | 82 | Bool ccsCheckForSettingsTransition (CCSContext *context); | ||
140 | 76 | 83 | ||
141 | 77 | void ccsLoadPlugins (CCSContext * context); | 84 | void ccsLoadPlugins (CCSContext * context); |
142 | 78 | void ccsLoadPluginSettings (CCSPlugin * plugin); | 85 | void ccsLoadPluginSettings (CCSPlugin * plugin); |
143 | 79 | 86 | ||
144 | === modified file 'src/main.c' | |||
145 | --- src/main.c 2011-09-15 13:12:45 +0000 | |||
146 | +++ src/main.c 2011-10-15 07:05:26 +0000 | |||
147 | @@ -169,6 +169,9 @@ | |||
148 | 169 | 169 | ||
149 | 170 | ccsLoadPlugins (context); | 170 | ccsLoadPlugins (context); |
150 | 171 | 171 | ||
151 | 172 | /* Do settings transitions */ | ||
152 | 173 | ccsCheckForSettingsTransition (context); | ||
153 | 174 | |||
154 | 172 | /* Do settings upgrades */ | 175 | /* Do settings upgrades */ |
155 | 173 | ccsCheckForSettingsUpgrade (context); | 176 | ccsCheckForSettingsUpgrade (context); |
156 | 174 | 177 | ||
157 | @@ -3356,7 +3359,21 @@ | |||
158 | 3356 | free (uname); | 3359 | free (uname); |
159 | 3357 | 3360 | ||
160 | 3358 | return 1; | 3361 | return 1; |
162 | 3359 | } | 3362 | } |
163 | 3363 | |||
164 | 3364 | static int | ||
165 | 3365 | transitionNameFilter (const struct dirent *name) | ||
166 | 3366 | { | ||
167 | 3367 | int length = strlen (name->d_name); | ||
168 | 3368 | |||
169 | 3369 | if (length < 12) | ||
170 | 3370 | return 0; | ||
171 | 3371 | |||
172 | 3372 | if (strncmp (name->d_name + length - 11, ".transition", 11)) | ||
173 | 3373 | return 0; | ||
174 | 3374 | |||
175 | 3375 | return 1; | ||
176 | 3376 | } | ||
177 | 3360 | 3377 | ||
178 | 3361 | /* | 3378 | /* |
179 | 3362 | * Process a filename into the properties | 3379 | * Process a filename into the properties |
180 | @@ -3422,6 +3439,22 @@ | |||
181 | 3422 | return upgrade; | 3439 | return upgrade; |
182 | 3423 | } | 3440 | } |
183 | 3424 | 3441 | ||
184 | 3442 | CCSSettingsTransition * | ||
185 | 3443 | ccsSettingsTransitionNew (char *path, char *name) | ||
186 | 3444 | { | ||
187 | 3445 | CCSSettingsTransition *transition = calloc (1, sizeof (CCSSettingsTransition)); | ||
188 | 3446 | unsigned int namelen = strlen (path); | ||
189 | 3447 | unsigned int pathlen = strlen (name); | ||
190 | 3448 | unsigned int fnlen = (pathlen + namelen + 1); | ||
191 | 3449 | |||
192 | 3450 | transition->file = calloc (fnlen, sizeof (char)); | ||
193 | 3451 | snprintf (transition->file, fnlen, "%s%s", path, name); | ||
194 | 3452 | |||
195 | 3453 | transition->name = strndup (name, pathlen - 10); | ||
196 | 3454 | |||
197 | 3455 | return transition; | ||
198 | 3456 | } | ||
199 | 3457 | |||
200 | 3425 | Bool | 3458 | Bool |
201 | 3426 | ccsCheckForSettingsUpgrade (CCSContext *context) | 3459 | ccsCheckForSettingsUpgrade (CCSContext *context) |
202 | 3427 | { | 3460 | { |
203 | @@ -3503,6 +3536,380 @@ | |||
204 | 3503 | } | 3536 | } |
205 | 3504 | 3537 | ||
206 | 3505 | Bool | 3538 | Bool |
207 | 3539 | ccsProcessTransition (CCSContext *context, | ||
208 | 3540 | CCSSettingsTransition *transition) | ||
209 | 3541 | { | ||
210 | 3542 | FILE *fp = fopen (transition->file, "r"); | ||
211 | 3543 | char *ctBuffer; | ||
212 | 3544 | unsigned int ctSize; | ||
213 | 3545 | size_t ctReadSize; | ||
214 | 3546 | unsigned int i, j; | ||
215 | 3547 | char *tok; | ||
216 | 3548 | char *buf; | ||
217 | 3549 | |||
218 | 3550 | if (!fp) | ||
219 | 3551 | { | ||
220 | 3552 | D (D_FULL, "[WARNING] failed to open transition file %s\n", transition->name); | ||
221 | 3553 | return FALSE; | ||
222 | 3554 | } | ||
223 | 3555 | |||
224 | 3556 | fseek (fp, 0, SEEK_END); | ||
225 | 3557 | ctSize = ftell (fp); | ||
226 | 3558 | rewind (fp); | ||
227 | 3559 | ctBuffer = calloc (ctSize + 1, sizeof (char)); | ||
228 | 3560 | |||
229 | 3561 | if (!ctBuffer) | ||
230 | 3562 | { | ||
231 | 3563 | D (D_FULL, "[WARNING] couldn't allocate transition file %s buffer\n", transition->name); | ||
232 | 3564 | fclose (fp); | ||
233 | 3565 | return FALSE; | ||
234 | 3566 | } | ||
235 | 3567 | |||
236 | 3568 | ctReadSize = fread (ctBuffer, sizeof (char), ctSize, fp); | ||
237 | 3569 | |||
238 | 3570 | if (ctReadSize != ctSize) | ||
239 | 3571 | { | ||
240 | 3572 | D (D_FULL, "[WARNING] couldn't read completed buffer for transition %s\n", transition->name); | ||
241 | 3573 | free (ctBuffer); | ||
242 | 3574 | fclose (fp); | ||
243 | 3575 | return FALSE; | ||
244 | 3576 | } | ||
245 | 3577 | ctBuffer[ctSize] ='\0'; | ||
246 | 3578 | |||
247 | 3579 | /* Remove newlines */ | ||
248 | 3580 | i = 0; | ||
249 | 3581 | |||
250 | 3582 | while (i < ctSize) | ||
251 | 3583 | { | ||
252 | 3584 | if (strncmp (&(ctBuffer[i]), "\n", 1) == 0) | ||
253 | 3585 | { | ||
254 | 3586 | (&(ctBuffer[i]))[0] = ' '; | ||
255 | 3587 | } | ||
256 | 3588 | |||
257 | 3589 | i++; | ||
258 | 3590 | } | ||
259 | 3591 | |||
260 | 3592 | /* Now break up the transition file into 4-sized chunks, with | ||
261 | 3593 | * old-plugin old-setting new-plugin new-setting (newline) | ||
262 | 3594 | * but first check to make sure that the number of tokens | ||
263 | 3595 | * we have is a multiple of 4 */ | ||
264 | 3596 | |||
265 | 3597 | buf = strdup (ctBuffer); | ||
266 | 3598 | i = 0; | ||
267 | 3599 | |||
268 | 3600 | tok = strsep (&buf, " "); | ||
269 | 3601 | |||
270 | 3602 | while (tok) | ||
271 | 3603 | { | ||
272 | 3604 | i++; | ||
273 | 3605 | tok = strsep (&buf, " "); | ||
274 | 3606 | } | ||
275 | 3607 | |||
276 | 3608 | free (buf); | ||
277 | 3609 | |||
278 | 3610 | if ((i - 1) % 4 != 0) | ||
279 | 3611 | { | ||
280 | 3612 | D (D_FULL, "[WARNING] provided upgrade file %s format not correct!\n", transition->name); | ||
281 | 3613 | free (ctBuffer); | ||
282 | 3614 | fclose (fp); | ||
283 | 3615 | return FALSE; | ||
284 | 3616 | } | ||
285 | 3617 | |||
286 | 3618 | buf = strdup (ctBuffer); | ||
287 | 3619 | |||
288 | 3620 | for (j = 0; j < (i / 4); j++) | ||
289 | 3621 | { | ||
290 | 3622 | char *oldPlugin; | ||
291 | 3623 | char *newPlugin; | ||
292 | 3624 | char *oldSetting; | ||
293 | 3625 | char *newSetting; | ||
294 | 3626 | CCSPlugin *cOldPlugin, *cNewPlugin; | ||
295 | 3627 | CCSSetting *cOldSetting, *cNewSetting; | ||
296 | 3628 | CCSPluginList p = NULL; | ||
297 | 3629 | CCSSettingList s = NULL; | ||
298 | 3630 | Bool freeOldPlugin = FALSE, freeOldSetting = FALSE; | ||
299 | 3631 | |||
300 | 3632 | CONTEXT_PRIV (context); | ||
301 | 3633 | |||
302 | 3634 | oldPlugin = strsep (&buf, " "); | ||
303 | 3635 | oldSetting = strsep (&buf, " "); | ||
304 | 3636 | newPlugin = strsep (&buf, " "); | ||
305 | 3637 | newSetting = strsep (&buf, " "); | ||
306 | 3638 | |||
307 | 3639 | if (!cPrivate->backend) | ||
308 | 3640 | return FALSE; | ||
309 | 3641 | |||
310 | 3642 | if (!cPrivate->backend->vTable->readSetting) | ||
311 | 3643 | return FALSE; | ||
312 | 3644 | |||
313 | 3645 | if (cPrivate->backend->vTable->readInit) | ||
314 | 3646 | if (!(*cPrivate->backend->vTable->readInit) (context)) | ||
315 | 3647 | return FALSE; | ||
316 | 3648 | |||
317 | 3649 | /* Find the new plugin and new setting, if neither can | ||
318 | 3650 | * be found, error out */ | ||
319 | 3651 | |||
320 | 3652 | p = context->plugins; | ||
321 | 3653 | |||
322 | 3654 | while (p) | ||
323 | 3655 | { | ||
324 | 3656 | if (strcmp (((CCSPlugin *) p->data)->name, newPlugin) == 0) | ||
325 | 3657 | break; | ||
326 | 3658 | |||
327 | 3659 | p = p->next; | ||
328 | 3660 | } | ||
329 | 3661 | |||
330 | 3662 | if (!p) | ||
331 | 3663 | { | ||
332 | 3664 | D (D_FULL, "[WARNING]: Could not find new plugin %s for transition %s\n", newPlugin, transition->name); | ||
333 | 3665 | continue; | ||
334 | 3666 | } | ||
335 | 3667 | else | ||
336 | 3668 | { | ||
337 | 3669 | cNewPlugin = (CCSPlugin *) p->data; | ||
338 | 3670 | |||
339 | 3671 | if (!((CCSPluginPrivate *) cNewPlugin->ccsPrivate)->loaded) | ||
340 | 3672 | ccsLoadPluginSettings (cNewPlugin); | ||
341 | 3673 | |||
342 | 3674 | s = ((CCSPluginPrivate *) cNewPlugin->ccsPrivate)->settings; | ||
343 | 3675 | |||
344 | 3676 | while (s) | ||
345 | 3677 | { | ||
346 | 3678 | if (strcmp (((CCSSetting *) s->data)->name, newSetting) == 0) | ||
347 | 3679 | break; | ||
348 | 3680 | |||
349 | 3681 | s = s->next; | ||
350 | 3682 | } | ||
351 | 3683 | |||
352 | 3684 | if (!s) | ||
353 | 3685 | { | ||
354 | 3686 | D (D_FULL, "[WARNING]: Could not find new setting %s for transition %s\n", newSetting, transition->name); | ||
355 | 3687 | continue; | ||
356 | 3688 | } | ||
357 | 3689 | else | ||
358 | 3690 | cNewSetting = (CCSSetting *) s->data; | ||
359 | 3691 | } | ||
360 | 3692 | |||
361 | 3693 | /* Try and find the old plugin, if not, craft one | ||
362 | 3694 | * for the purposes of this function */ | ||
363 | 3695 | |||
364 | 3696 | p = context->plugins; | ||
365 | 3697 | |||
366 | 3698 | while (p) | ||
367 | 3699 | { | ||
368 | 3700 | if (strcmp (((CCSPlugin *) p->data)->name, oldPlugin) == 0) | ||
369 | 3701 | break; | ||
370 | 3702 | |||
371 | 3703 | p = p->next; | ||
372 | 3704 | } | ||
373 | 3705 | |||
374 | 3706 | if (!p) | ||
375 | 3707 | { | ||
376 | 3708 | cOldPlugin = calloc (1, sizeof (CCSPlugin)); | ||
377 | 3709 | |||
378 | 3710 | cOldPlugin->context = context; | ||
379 | 3711 | cOldPlugin->ccsPrivate = calloc (1, sizeof (CCSPluginPrivate)); | ||
380 | 3712 | if (!cOldPlugin->ccsPrivate ) | ||
381 | 3713 | { | ||
382 | 3714 | free (cOldPlugin); | ||
383 | 3715 | return FALSE; | ||
384 | 3716 | } | ||
385 | 3717 | ((CCSPluginPrivate *) cOldPlugin->ccsPrivate)->loaded = FALSE; | ||
386 | 3718 | |||
387 | 3719 | cOldPlugin->name = strdup (oldPlugin); | ||
388 | 3720 | cOldPlugin->shortDesc = strdup (oldPlugin); | ||
389 | 3721 | cOldPlugin->longDesc = strdup (oldPlugin); | ||
390 | 3722 | cOldPlugin->category = strdup (""); | ||
391 | 3723 | cOldPlugin->refCount = 1; | ||
392 | 3724 | |||
393 | 3725 | freeOldPlugin = TRUE; | ||
394 | 3726 | } | ||
395 | 3727 | else | ||
396 | 3728 | cOldPlugin = (CCSPlugin *) p->data; | ||
397 | 3729 | |||
398 | 3730 | s = NULL; | ||
399 | 3731 | |||
400 | 3732 | if (!freeOldPlugin) | ||
401 | 3733 | { | ||
402 | 3734 | /* Now try and find the old setting to transition from */ | ||
403 | 3735 | |||
404 | 3736 | s = ((CCSPluginPrivate *) cOldPlugin->ccsPrivate)->settings; | ||
405 | 3737 | |||
406 | 3738 | while (s) | ||
407 | 3739 | { | ||
408 | 3740 | if (strcmp (((CCSSetting *) s->data)->name, oldSetting) == 0) | ||
409 | 3741 | break; | ||
410 | 3742 | |||
411 | 3743 | s = s->next; | ||
412 | 3744 | } | ||
413 | 3745 | } | ||
414 | 3746 | |||
415 | 3747 | if (!s) | ||
416 | 3748 | { | ||
417 | 3749 | cOldSetting = calloc (1, sizeof (CCSSetting)); | ||
418 | 3750 | |||
419 | 3751 | cOldSetting = (CCSSetting *) calloc (1, sizeof (CCSSetting)); | ||
420 | 3752 | if (!cOldSetting) | ||
421 | 3753 | return FALSE; | ||
422 | 3754 | |||
423 | 3755 | cOldSetting->parent = cOldPlugin; | ||
424 | 3756 | cOldSetting->isDefault = TRUE; | ||
425 | 3757 | cOldSetting->name = strdup (oldSetting); | ||
426 | 3758 | cOldSetting->refCount = 1; | ||
427 | 3759 | |||
428 | 3760 | cOldSetting->shortDesc = strdup (oldSetting); | ||
429 | 3761 | cOldSetting->longDesc = strdup (""); | ||
430 | 3762 | cOldSetting->hints = strdup (""); | ||
431 | 3763 | cOldSetting->group = strdup (""); | ||
432 | 3764 | cOldSetting->subGroup = strdup (""); | ||
433 | 3765 | |||
434 | 3766 | cOldSetting->value = &cOldSetting->defaultValue; | ||
435 | 3767 | cOldSetting->defaultValue.parent = cOldSetting; | ||
436 | 3768 | cOldSetting->type = cNewSetting->type; | ||
437 | 3769 | |||
438 | 3770 | switch (cOldSetting->type) | ||
439 | 3771 | { | ||
440 | 3772 | case TypeString: | ||
441 | 3773 | cOldSetting->defaultValue.value.asString = strdup (""); | ||
442 | 3774 | break; | ||
443 | 3775 | case TypeMatch: | ||
444 | 3776 | cOldSetting->defaultValue.value.asMatch = strdup (""); | ||
445 | 3777 | break; | ||
446 | 3778 | default: | ||
447 | 3779 | break; | ||
448 | 3780 | } | ||
449 | 3781 | |||
450 | 3782 | freeOldSetting = TRUE; | ||
451 | 3783 | } | ||
452 | 3784 | else | ||
453 | 3785 | cOldSetting = (CCSSetting *) s->data; | ||
454 | 3786 | |||
455 | 3787 | /* Now ask the backend for the value of the old setting */ | ||
456 | 3788 | (*cPrivate->backend->vTable->readSetting) (context, cOldSetting); | ||
457 | 3789 | ccsSetValue (cNewSetting, cOldSetting->value, TRUE); | ||
458 | 3790 | D (D_FULL, "Moved setting %s/%s to %s/%s", oldPlugin, oldSetting, newPlugin, newSetting); | ||
459 | 3791 | |||
460 | 3792 | if (freeOldSetting) | ||
461 | 3793 | { | ||
462 | 3794 | free (cOldSetting->name); | ||
463 | 3795 | free (cOldSetting->shortDesc); | ||
464 | 3796 | free (cOldSetting->longDesc); | ||
465 | 3797 | free (cOldSetting->hints); | ||
466 | 3798 | free (cOldSetting->subGroup); | ||
467 | 3799 | |||
468 | 3800 | switch (cOldSetting->type) | ||
469 | 3801 | { | ||
470 | 3802 | case TypeString: | ||
471 | 3803 | free (cOldSetting->defaultValue.value.asString); | ||
472 | 3804 | break; | ||
473 | 3805 | case TypeMatch: | ||
474 | 3806 | free (cOldSetting->defaultValue.value.asMatch); | ||
475 | 3807 | break; | ||
476 | 3808 | default: | ||
477 | 3809 | break; | ||
478 | 3810 | } | ||
479 | 3811 | |||
480 | 3812 | free (cOldSetting); | ||
481 | 3813 | } | ||
482 | 3814 | |||
483 | 3815 | if (freeOldPlugin) | ||
484 | 3816 | { | ||
485 | 3817 | free (cOldPlugin->ccsPrivate); | ||
486 | 3818 | free (cOldPlugin->name); | ||
487 | 3819 | free (cOldPlugin->shortDesc); | ||
488 | 3820 | free (cOldPlugin->longDesc); | ||
489 | 3821 | free (cOldPlugin->category); | ||
490 | 3822 | free (cOldPlugin); | ||
491 | 3823 | } | ||
492 | 3824 | } | ||
493 | 3825 | |||
494 | 3826 | D (D_FULL, "Completed transition %s\n", transition->name); | ||
495 | 3827 | free (ctBuffer); | ||
496 | 3828 | fclose (fp); | ||
497 | 3829 | |||
498 | 3830 | return TRUE; | ||
499 | 3831 | } | ||
500 | 3832 | |||
501 | 3833 | Bool | ||
502 | 3834 | ccsCheckForSettingsTransition (CCSContext *context) | ||
503 | 3835 | { | ||
504 | 3836 | struct dirent **nameList; | ||
505 | 3837 | int nFile, i; | ||
506 | 3838 | char *path = DATADIR "/compizconfig/transitions/"; | ||
507 | 3839 | char *dupath = NULL; | ||
508 | 3840 | FILE *completedTransitions; | ||
509 | 3841 | char *ctBuffer; | ||
510 | 3842 | unsigned int ctSize; | ||
511 | 3843 | size_t ctReadSize; | ||
512 | 3844 | char *home = getenv ("HOME"); | ||
513 | 3845 | |||
514 | 3846 | if (!home) | ||
515 | 3847 | return FALSE; | ||
516 | 3848 | |||
517 | 3849 | asprintf (&dupath, "%s/.config/compiz-1/compizconfig/done_transitions", home); | ||
518 | 3850 | |||
519 | 3851 | completedTransitions = fopen (dupath, "a+"); | ||
520 | 3852 | |||
521 | 3853 | if (!path) | ||
522 | 3854 | return FALSE; | ||
523 | 3855 | |||
524 | 3856 | nFile = scandir (path, &nameList, transitionNameFilter, alphasort); | ||
525 | 3857 | if (nFile <= 0) | ||
526 | 3858 | return FALSE; | ||
527 | 3859 | |||
528 | 3860 | if (!completedTransitions) | ||
529 | 3861 | { | ||
530 | 3862 | fprintf (stderr, "[WARNING] Error opening done_transitions\n"); | ||
531 | 3863 | return FALSE; | ||
532 | 3864 | } | ||
533 | 3865 | |||
534 | 3866 | fseek (completedTransitions, 0, SEEK_END); | ||
535 | 3867 | ctSize = ftell (completedTransitions); | ||
536 | 3868 | rewind (completedTransitions); | ||
537 | 3869 | |||
538 | 3870 | ctBuffer = calloc (ctSize + 1, sizeof (char)); | ||
539 | 3871 | ctReadSize = fread (ctBuffer, 1, ctSize, completedTransitions); | ||
540 | 3872 | |||
541 | 3873 | if (ctReadSize != ctSize) | ||
542 | 3874 | D (D_FULL, "[WARNING] Couldn't read completed transitions file!\n"); | ||
543 | 3875 | |||
544 | 3876 | ctBuffer[ctSize] = '\0'; | ||
545 | 3877 | |||
546 | 3878 | for (i = 0; i < nFile; i++) | ||
547 | 3879 | { | ||
548 | 3880 | char *matched = strstr (ctBuffer, nameList[i]->d_name); | ||
549 | 3881 | CCSSettingsTransition *transition; | ||
550 | 3882 | |||
551 | 3883 | if (matched) | ||
552 | 3884 | { | ||
553 | 3885 | D (D_FULL, "Skipping transition %s\n", nameList[i]->d_name); | ||
554 | 3886 | continue; | ||
555 | 3887 | } | ||
556 | 3888 | |||
557 | 3889 | transition = ccsSettingsTransitionNew (path, nameList[i]->d_name); | ||
558 | 3890 | |||
559 | 3891 | D (D_FULL, "Processing transition %s\n", nameList[i]->d_name); | ||
560 | 3892 | |||
561 | 3893 | ccsProcessTransition (context, transition); | ||
562 | 3894 | ccsWriteChangedSettings (context); | ||
563 | 3895 | ccsWriteAutoSortedPluginList (context); | ||
564 | 3896 | D (D_FULL, "Completed transition %s\n", nameList[i]->d_name); | ||
565 | 3897 | fprintf (completedTransitions, "%s\n", nameList[i]->d_name); | ||
566 | 3898 | free (transition->file); | ||
567 | 3899 | free (transition->name); | ||
568 | 3900 | free (transition); | ||
569 | 3901 | free (nameList[i]); | ||
570 | 3902 | } | ||
571 | 3903 | |||
572 | 3904 | free (dupath); | ||
573 | 3905 | fclose (completedTransitions); | ||
574 | 3906 | free (ctBuffer); | ||
575 | 3907 | free (nameList); | ||
576 | 3908 | |||
577 | 3909 | return TRUE; | ||
578 | 3910 | } | ||
579 | 3911 | |||
580 | 3912 | Bool | ||
581 | 3506 | ccsImportFromFile (CCSContext *context, | 3913 | ccsImportFromFile (CCSContext *context, |
582 | 3507 | const char *fileName, | 3914 | const char *fileName, |
583 | 3508 | Bool overwriteNonDefault) | 3915 | Bool overwriteNonDefault) |
This is a clear place where we could have tests. There are stand alone methods that have defined behaviour.
Also another reason why I had boolean parameters:
- ccsSetString (setting, value, TRUE);
+ ccsSetString (setting, value, FALSE);
This tells the reviewer exactly nothing.