Status: | Superseded | ||||
---|---|---|---|---|---|
Proposed branch: | lp:~mterry/unity/gsettings | ||||
Merge into: | lp:unity | ||||
Diff against target: |
908 lines (+225/-323) 15 files modified
HACKING (+3/-3) configure.ac (+2/-4) data/Makefile.am (+10/-15) data/com.canonical.Unity.gschema.xml.in (+56/-57) data/unity.convert (+10/-0) po/POTFILES.in (+1/-0) targets/mutter/Makefile.am (+0/-1) targets/mutter/plugin.vala (+7/-26) tools/migrate_favorites.py (+17/-2) unity-private/launcher/application-controller.vala (+1/-1) unity-private/launcher/scroller-controller.vala (+2/-2) unity/Makefile.am (+0/-1) unity/chrome-handler.vala (+2/-2) unity/prism-handler.vala (+2/-2) unity/unity-favorites.vala (+112/-207) |
||||
To merge this branch: | bzr merge lp:~mterry/unity/gsettings | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Neil J. Patel (community) | Approve | ||
Review via email: mp+39154@code.launchpad.net |
This proposal has been superseded by a proposal from 2011-01-06.
Commit message
Description of the change
This is to convert from gconf to gsettings (bug 656326). I've tested it and it seems to work, but would obviously benefit from more testing.
There are a few keys that seem to no longer be used? Maybe now would be a good time to drop them from the schema and the new convert file. I'm thinking of the search_template, search_hint, and webapp_use_chromium keys.
This isn't a *complete* port either, since a few gconf uses reference global desktop keys that are in the process of moving to gsettings. Once they get moved, you can remove gconf altogether. But with this branch, all the unity internal usage is gsettings.
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'HACKING' |
2 | --- HACKING 2010-03-01 14:30:33 +0000 |
3 | +++ HACKING 2010-10-22 15:19:44 +0000 |
4 | @@ -40,10 +40,10 @@ |
5 | |
6 | Webapp switching: |
7 | Unity can use two webapp systems, prism and chromium, you can toggle between |
8 | - the two by setting the gconf key "/apps/unity/webapp_use_chromium" on or off |
9 | + the two by setting the gsettings key "/apps/unity/webapp-use-chromium" on or off |
10 | |
11 | Setting unmovable apps: |
12 | - To make a launcher unmovable set the desktop_file gconf key of the app to manditory |
13 | + To make a launcher unmovable set the desktop-file gsettings key of the app to manditory |
14 | |
15 | setting bottom fixed apps: |
16 | - To make a launcher appear at the bottom of the launchers and fixed in place, set the key "fixed" (bool) to true in the launchers gconf directory |
17 | + To make a launcher appear at the bottom of the launchers and fixed in place, set the key "fixed" (bool) to true in the launchers gsettings directory |
18 | |
19 | === modified file 'configure.ac' |
20 | --- configure.ac 2010-09-27 18:41:44 +0000 |
21 | +++ configure.ac 2010-10-22 15:19:44 +0000 |
22 | @@ -63,9 +63,7 @@ |
23 | PREFIX="${prefix}" |
24 | fi |
25 | |
26 | -dnl GConf schema installation |
27 | -AC_PATH_PROG(GCONFTOOL, gconftool-2) |
28 | -AM_GCONF_SOURCE_2 |
29 | +GLIB_GSETTINGS |
30 | |
31 | AC_DEFINE_UNQUOTED(LOCALE_DIR, "${PREFIX}/${DATADIRNAME}/locale",[Locale directory]) |
32 | AC_DEFINE_UNQUOTED(DATADIR, "${PREFIX}/${DATADIRNAME}",[Data directory]) |
33 | @@ -95,7 +93,7 @@ |
34 | AC_SUBST(MAINTAINER_VALAFLAGS) |
35 | |
36 | dnl Check for module and library dependancies |
37 | -GLIB_REQUIRED=2.22 |
38 | +GLIB_REQUIRED=2.26 |
39 | GTK_REQUIRED=2.18 |
40 | PKG_CHECK_MODULES(BASE, |
41 | clutter-1.0 >= 1.0 |
42 | |
43 | === modified file 'data/Makefile.am' |
44 | --- data/Makefile.am 2010-09-03 14:04:37 +0000 |
45 | +++ data/Makefile.am 2010-10-22 15:19:44 +0000 |
46 | @@ -24,18 +24,13 @@ |
47 | |
48 | defaultdir = $(pkgdatadir) |
49 | |
50 | -# Schemas |
51 | -schemadir = $(sysconfdir)/gconf/schemas |
52 | -dist_schema_DATA = unity.schemas |
53 | - |
54 | -if GCONF_SCHEMAS_INSTALL |
55 | -install-data-local: |
56 | - -GCONF_CONFIG_SOURCE=$(GCONF_SCHEMA_CONFIG_SOURCE) \ |
57 | - $(GCONFTOOL) --makefile-install-rule $(dist_schema_DATA) |
58 | -endif |
59 | - |
60 | -if GCONF_SCHEMAS_INSTALL |
61 | -uninstall-local: |
62 | - -GCONF_CONFIG_SOURCE=$(GCONF_SCHEMA_CONFIG_SOURCE) \ |
63 | - $(GCONFTOOL) --makefile-uninstall-rule $(dist_schema_DATA) |
64 | -endif |
65 | +# Schema |
66 | +@INTLTOOL_XML_NOMERGE_RULE@ |
67 | +@GSETTINGS_RULES@ |
68 | +gsettings_SCHEMAS = com.canonical.Unity.gschema.xml |
69 | + |
70 | +convertdir = $(datadir)/GConf/gsettings |
71 | +dist_convert_DATA = unity.convert |
72 | + |
73 | +EXTRA_DIST = $(gsettings_SCHEMAS:.xml=.xml.in) |
74 | +DISTCLEANFILES = $(gsettings_SCHEMAS) |
75 | |
76 | === renamed file 'data/unity.schemas' => 'data/com.canonical.Unity.gschema.xml.in' |
77 | --- data/unity.schemas 2010-09-22 13:38:06 +0000 |
78 | +++ data/com.canonical.Unity.gschema.xml.in 2010-10-22 15:19:44 +0000 |
79 | @@ -1,57 +1,56 @@ |
80 | -<gconfschemafile> |
81 | - <schemalist> |
82 | - |
83 | -<!-- PANEL KEYS --> |
84 | - |
85 | - <schema> |
86 | - <key>/schemas/desktop/unity/panel/search_template</key> |
87 | - <applyto>/desktop/unity/panel/search_template</applyto> |
88 | - <owner>unity</owner> |
89 | - <type>string</type> |
90 | - <default>xdg-open http://www.google.com/cse?cx=partner-pub-9300639326172081%3Ad9bbzbtli15&ie=UTF-8&sa=Search&q=%s</default> |
91 | - <locale name="C"> |
92 | - <short>The search template used for panel search</short> |
93 | - <long>The search template used for panel search. '%s' is substituted with the search string.</long> |
94 | - </locale> |
95 | - </schema> |
96 | - |
97 | - <schema> |
98 | - <key>/schemas/desktop/unity/panel/search_hint</key> |
99 | - <applyto>/desktop/unity/panel/search_hint</applyto> |
100 | - <owner>unity</owner> |
101 | - <type>string</type> |
102 | - <default>Google</default> |
103 | - <locale name="C"> |
104 | - <short>The search hint used for panel search</short> |
105 | - <long>The search hint used for panel search.</long> |
106 | - </locale> |
107 | - </schema> |
108 | - |
109 | -<!-- LAUNCHER KEYS --> |
110 | - |
111 | - <schema> |
112 | - <key>/schemas/desktop/unity/launcher/webapp_use_chromium</key> |
113 | - <applyto>/desktop/unity/launcher/webapp_use_chromium</applyto> |
114 | - <owner>unity</owner> |
115 | - <type>bool</type> |
116 | - <default>1</default> |
117 | - <locale name="C"> |
118 | - <short>Whether the launcher should create Chromium-based webapps</short> |
119 | - <long>Whether the launcher should create Chromium-based webapps. If this is False, Prism-based webapps will be created.</long> |
120 | - </locale> |
121 | - </schema> |
122 | - |
123 | - <schema> |
124 | - <key>/schemas/desktop/unity/launcher/super_key_enable</key> |
125 | - <applyto>/desktop/unity/launcher/super_key_enable</applyto> |
126 | - <owner>unity</owner> |
127 | - <type>bool</type> |
128 | - <default>1</default> |
129 | - <locale name="C"> |
130 | - <short>Enable super key or not</short> |
131 | - <long>Enable/disable super key. If this is False, super key will not function.</long> |
132 | - </locale> |
133 | - </schema> |
134 | - |
135 | - </schemalist> |
136 | -</gconfschemafile> |
137 | +<?xml version="1.0" encoding="UTF-8"?> |
138 | +<schemalist> |
139 | + <schema id="com.canonical.Unity" path="/desktop/unity/"> |
140 | + <child name="panel" schema="com.canonical.Unity.Panel"/> |
141 | + <child name="launcher" schema="com.canonical.Unity.Launcher"/> |
142 | + </schema> |
143 | + <schema id="com.canonical.Unity.Panel" path="/desktop/unity/panel/"> |
144 | + <key name="search-template" type="s"> |
145 | + <default>'xdg-open http://www.google.com/cse?cx=partner-pub-9300639326172081%3Ad9bbzbtli15&ie=UTF-8&sa=Search&q=%s'</default> |
146 | + <_summary>The search template used for panel search</_summary> |
147 | + <_description>The search template used for panel search. '%s' is substituted with the search string.</_description> |
148 | + </key> |
149 | + <key name="search-hint" type="s"> |
150 | + <default>'Google'</default> |
151 | + <_summary>The search hint used for panel search</_summary> |
152 | + <_description>The search hint used for panel search.</_description> |
153 | + </key> |
154 | + </schema> |
155 | + <schema id="com.canonical.Unity.Launcher" path="/desktop/unity/launcher/"> |
156 | + <key name="webapp-use-chromium" type="b"> |
157 | + <default>true</default> |
158 | + <_summary>Whether the launcher should create Chromium-based webapps</_summary> |
159 | + <_description>Whether the launcher should create Chromium-based webapps. If this is False, Prism-based webapps will be created.</_description> |
160 | + </key> |
161 | + <key name="super-key-enable" type="b"> |
162 | + <default>true</default> |
163 | + <_summary>Enable super key or not</_summary> |
164 | + <_description>Enable/disable super key. If this is False, super key will not function.</_description> |
165 | + </key> |
166 | + <child name="favorites" schema="com.canonical.Unity.Launcher.Favorites"/> |
167 | + </schema> |
168 | + <schema id="com.canonical.Unity.Launcher.Favorites" path="/desktop/unity/launcher/favorites/"> |
169 | + <key name="favorites-list" type="as"> |
170 | + <default>[]</default> |
171 | + </key> |
172 | + <key name="migrated" type="b"> |
173 | + <default>false</default> |
174 | + <_summary>Whether gconf favorites have been migrated</_summary> |
175 | + <_description>If false, the first time Unity is run, old gconf favorites will be moved over.</_description> |
176 | + </key> |
177 | + </schema> |
178 | + <schema id="com.canonical.Unity.Launcher.Favorites.Favorite"> |
179 | + <key name="type" type="s"> |
180 | + <choices> |
181 | + <choice value='application'/> |
182 | + </choices> |
183 | + <default>'application'</default> |
184 | + </key> |
185 | + <key name="desktop-file" type="s"> |
186 | + <default>''</default> |
187 | + </key> |
188 | + <key name="priority" type="d"> |
189 | + <default>0</default> |
190 | + </key> |
191 | + </schema> |
192 | +</schemalist> |
193 | |
194 | === added file 'data/unity.convert' |
195 | --- data/unity.convert 1970-01-01 00:00:00 +0000 |
196 | +++ data/unity.convert 2010-10-22 15:19:44 +0000 |
197 | @@ -0,0 +1,10 @@ |
198 | +[com.canonical.Unity.Panel] |
199 | +search-template = /desktop/unity/panel/search_template |
200 | +search-hint = /desktop/unity/panel/search_hint |
201 | + |
202 | +[com.canonical.Unity.Launcher] |
203 | +webapp-use-chromium = /desktop/unity/launcher/webapp_use_chromium |
204 | +super-key-enable = /desktop/unity/launcher/super_key_enable |
205 | + |
206 | +[com.canonical.Unity.Launcher.Favorites] |
207 | +favorites-list = /desktop/unity/launcher/favorites/favorites_list |
208 | |
209 | === modified file 'po/POTFILES.in' |
210 | --- po/POTFILES.in 2010-09-14 13:45:42 +0000 |
211 | +++ po/POTFILES.in 2010-10-22 15:19:44 +0000 |
212 | @@ -6,4 +6,5 @@ |
213 | unity-private/places/places-place-search-entry.vala |
214 | unity-private/places/places-trash-controller.vala |
215 | unity-private/places/places-volume-child-controller.vala |
216 | +data/com.canonical.Unity.gschema.xml.in |
217 | |
218 | |
219 | === modified file 'targets/mutter/Makefile.am' |
220 | --- targets/mutter/Makefile.am 2010-09-22 16:30:03 +0000 |
221 | +++ targets/mutter/Makefile.am 2010-10-22 15:19:44 +0000 |
222 | @@ -52,7 +52,6 @@ |
223 | --pkg unity-const \ |
224 | --pkg unity \ |
225 | --pkg unity-private \ |
226 | - --pkg gconf-2.0 \ |
227 | $(MAINTAINER_VALAFLAGS) |
228 | |
229 | libunity_mutter_la_LIBADD = \ |
230 | |
231 | === modified file 'targets/mutter/plugin.vala' |
232 | --- targets/mutter/plugin.vala 2010-09-24 13:51:00 +0000 |
233 | +++ targets/mutter/plugin.vala 2010-10-22 15:19:44 +0000 |
234 | @@ -17,7 +17,6 @@ |
235 | * |
236 | */ |
237 | |
238 | -using GConf; |
239 | using Unity; |
240 | using Unity.Testing; |
241 | |
242 | @@ -174,6 +173,8 @@ |
243 | public Gesture.Dispatcher gesture_dispatcher; |
244 | private Gesture.Type active_gesture_type = Gesture.Type.NONE; |
245 | |
246 | + private Settings settings; |
247 | + |
248 | /* Pinch info */ |
249 | /* private float start_pinch_radius = 0.0f; */ |
250 | private unowned Mutter.Window? resize_window = null; |
251 | @@ -204,10 +205,6 @@ |
252 | private ExposeType expose_type = ExposeType.NONE; |
253 | private unowned Mutter.Window? start_pinch_window = null; |
254 | |
255 | - /* const */ |
256 | - private const string GCONF_DIR = "/desktop/unity/launcher"; |
257 | - private const string GCONF_SUPER_KEY_ENABLE_KEY = "super_key_enable"; |
258 | - |
259 | construct |
260 | { |
261 | is_starting = true; |
262 | @@ -293,21 +290,11 @@ |
263 | /* we need to hook into the super key bound by mutter for g-shell. |
264 | don't ask me why mutter binds things for g-shell explictly... |
265 | */ |
266 | - var gc = GConf.Client.get_default(); |
267 | Mutter.MetaDisplay display = Mutter.MetaScreen.get_display (plugin.get_screen ()); |
268 | |
269 | - try { |
270 | - super_key_enable = gc.get_bool(GCONF_DIR + "/" + GCONF_SUPER_KEY_ENABLE_KEY); |
271 | - } catch (GLib.Error e) { |
272 | - super_key_enable = true; |
273 | - warning("Cannot find super_key_enable gconf key"); |
274 | - } |
275 | - try { |
276 | - gc.add_dir(GCONF_DIR, GConf.ClientPreloadType.ONELEVEL); |
277 | - gc.notify_add(GCONF_DIR + "/" + GCONF_SUPER_KEY_ENABLE_KEY, this.gconf_super_key_enable_cb); |
278 | - } catch (GLib.Error e) { |
279 | - warning("Cannot set gconf callback function of super_key_enable"); |
280 | - } |
281 | + this.settings = new Settings ("com.canonical.Unity.Launcher"); |
282 | + super_key_enable = this.settings.get_boolean ("super-key-enable"); |
283 | + this.settings.changed["super-key-enable"].connect (this.super_key_enable_cb); |
284 | |
285 | display.overlay_key_down.connect (() => { |
286 | if (super_key_enable) { |
287 | @@ -400,14 +387,8 @@ |
288 | |
289 | } |
290 | |
291 | - private void gconf_super_key_enable_cb(GConf.Client gc, uint cxnid, GConf.Entry entry) { |
292 | - bool new_value = true; |
293 | - try { |
294 | - new_value = gc.get_bool(GCONF_DIR + "/" + GCONF_SUPER_KEY_ENABLE_KEY); |
295 | - } catch (GLib.Error e) { |
296 | - new_value = true; |
297 | - } |
298 | - super_key_enable = new_value; |
299 | + private void super_key_enable_cb(Settings settings, string key) { |
300 | + super_key_enable = settings.get_boolean (key); |
301 | } |
302 | |
303 | private void on_focus_window_changed () |
304 | |
305 | === modified file 'tools/migrate_favorites.py' |
306 | --- tools/migrate_favorites.py 2010-10-06 08:37:47 +0000 |
307 | +++ tools/migrate_favorites.py 2010-10-22 15:19:44 +0000 |
308 | @@ -12,6 +12,7 @@ |
309 | import gobject |
310 | import os |
311 | import sys |
312 | +import subprocess |
313 | |
314 | def get_desktop_dir(): |
315 | ''' no python binding from xdg to get the desktop directory? ''' |
316 | @@ -52,8 +53,9 @@ |
317 | #print priority_position |
318 | return (apps_list, priority_position) |
319 | |
320 | -if os.path.exists(os.path.expanduser('~/.gconf/desktop/unity/')): |
321 | - print "migration already done or unity used before migration support" |
322 | +migrated_call = subprocess.Popen(["gsettings", "get", "com.canonical.Unity.Launcher.Favorites", "migrated"], stdout=subprocess.PIPE) |
323 | +if migrated_call.communicate()[0].strip() == 'true': |
324 | + print "migration already done" |
325 | sys.exit(0) |
326 | |
327 | client = gconf.client_get_default() |
328 | @@ -62,6 +64,19 @@ |
329 | apps_list = client.get_list('/desktop/unity/launcher/favorites/favorites_list', gconf.VALUE_STRING) |
330 | priority_position = len(apps_list) + 1 |
331 | |
332 | +if os.path.exists(os.path.expanduser('~/.gconf/desktop/unity/')): |
333 | + # Unity has been run before and used gconf. Convert its favorites over. |
334 | + # Other keys are handled by gsettings-data-convert, which we run here just |
335 | + # to be safe (because it normally *should* be run by login) |
336 | + subprocess.call(["gsettings-data-convert"]) |
337 | + for app in apps_list: |
338 | + path = '/desktop/unity/launcher/favorites/' + app |
339 | + cmd = ["gsettings", "set", "-p", path, "com.canonical.Unity.Launcher.Favorites.Favorite"] |
340 | + subprocess.call(cmd + ["desktop-file", "'%s'" % client.get_string("%s/desktop_file" % path)]) |
341 | + subprocess.call(cmd + ["type", "'%s'" % client.get_string("%s/type" % path)]) |
342 | + subprocess.call(cmd + ["priority", "%s" % client.get_float("%s/priority" % path)]) |
343 | + sys.exit(0) |
344 | + |
345 | # get GNOME panel favorites and convert them |
346 | panel_list = client.get_list('/apps/panel/general/toplevel_id_list', gconf.VALUE_STRING) |
347 | candidate_objects = client.get_list('/apps/panel/general/object_id_list', gconf.VALUE_STRING) |
348 | |
349 | === modified file 'unity-private/launcher/application-controller.vala' |
350 | --- unity-private/launcher/application-controller.vala 2010-09-27 16:15:53 +0000 |
351 | +++ unity-private/launcher/application-controller.vala 2010-10-22 15:19:44 +0000 |
352 | @@ -107,7 +107,7 @@ |
353 | if (is_sticky) |
354 | { |
355 | favorites.set_string (fav_id, "type", "application"); |
356 | - favorites.set_string (fav_id, "desktop_file", desktop_file); |
357 | + favorites.set_string (fav_id, "desktop-file", desktop_file); |
358 | favorites.add_favorite (fav_id); |
359 | } |
360 | else |
361 | |
362 | === modified file 'unity-private/launcher/scroller-controller.vala' |
363 | --- unity-private/launcher/scroller-controller.vala 2010-09-24 12:37:02 +0000 |
364 | +++ unity-private/launcher/scroller-controller.vala 2010-10-22 15:19:44 +0000 |
365 | @@ -218,7 +218,7 @@ |
366 | |
367 | foreach (string uid in favorites.get_favorites ()) |
368 | { |
369 | - string desktop_file = favorites.get_string (uid, "desktop_file"); |
370 | + string desktop_file = favorites.get_string (uid, "desktop-file"); |
371 | if (!FileUtils.test (desktop_file, FileTest.EXISTS)) |
372 | { |
373 | // no desktop file for this favorite or it does not exist |
374 | @@ -249,7 +249,7 @@ |
375 | |
376 | private void on_favorite_added (string uid) |
377 | { |
378 | - var desktop_file = favorites.get_string (uid, "desktop_file"); |
379 | + var desktop_file = favorites.get_string (uid, "desktop-file"); |
380 | if (!FileUtils.test (desktop_file, FileTest.EXISTS)) |
381 | { |
382 | // no desktop file for this favorite or it does not exist |
383 | |
384 | === modified file 'unity/Makefile.am' |
385 | --- unity/Makefile.am 2010-08-23 17:01:29 +0000 |
386 | +++ unity/Makefile.am 2010-10-22 15:19:44 +0000 |
387 | @@ -46,7 +46,6 @@ |
388 | --pkg dbus-glib-1 \ |
389 | --pkg Dbusmenu-Glib-0.2 \ |
390 | --pkg dee-1.0 \ |
391 | - --pkg gconf-2.0 \ |
392 | --pkg gtk+-2.0 \ |
393 | --pkg gio-2.0 \ |
394 | --pkg gio-unix-2.0 \ |
395 | |
396 | === modified file 'unity/chrome-handler.vala' |
397 | --- unity/chrome-handler.vala 2010-06-10 12:00:50 +0000 |
398 | +++ unity/chrome-handler.vala 2010-10-22 15:19:44 +0000 |
399 | @@ -144,7 +144,7 @@ |
400 | |
401 | // we are not a favorite and we need to be favorited! |
402 | favorites.set_string (uid, "type", "application"); |
403 | - favorites.set_string (uid, "desktop_file", desktop_path); |
404 | + favorites.set_string (uid, "desktop-file", desktop_path); |
405 | favorites.set_float (uid, "priority", -100000.0f); |
406 | favorites.add_favorite (uid); |
407 | } |
408 | @@ -166,7 +166,7 @@ |
409 | if (type != "application") |
410 | continue; |
411 | |
412 | - string desktop_file = favorites.get_string(uid, "desktop_file"); |
413 | + string desktop_file = favorites.get_string(uid, "desktop-file"); |
414 | if (desktop_file == my_desktop_path) |
415 | { |
416 | myuid = uid; |
417 | |
418 | === modified file 'unity/prism-handler.vala' |
419 | --- unity/prism-handler.vala 2010-06-08 09:43:43 +0000 |
420 | +++ unity/prism-handler.vala 2010-10-22 15:19:44 +0000 |
421 | @@ -159,7 +159,7 @@ |
422 | |
423 | // we are not a favorite and we need to be favorited! |
424 | favorites.set_string (uid, "type", "application"); |
425 | - favorites.set_string (uid, "desktop_file", desktop_path); |
426 | + favorites.set_string (uid, "desktop-file", desktop_path); |
427 | favorites.add_favorite (uid); |
428 | } |
429 | |
430 | @@ -180,7 +180,7 @@ |
431 | if (type != "application") |
432 | continue; |
433 | |
434 | - string desktop_file = favorites.get_string(uid, "desktop_file"); |
435 | + string desktop_file = favorites.get_string(uid, "desktop-file"); |
436 | if (desktop_file == my_desktop_path) |
437 | { |
438 | myuid = uid; |
439 | |
440 | === modified file 'unity/unity-favorites.vala' |
441 | --- unity/unity-favorites.vala 2010-09-09 10:16:54 +0000 |
442 | +++ unity/unity-favorites.vala 2010-10-22 15:19:44 +0000 |
443 | @@ -15,6 +15,7 @@ |
444 | * <http://www.gnu.org/licenses/>. |
445 | * |
446 | * Authored by Gordon Allott <gord.allott@canonical.com> |
447 | + * Michael Terry <michael.terry@canonical.com> |
448 | */ |
449 | using Gee; |
450 | |
451 | @@ -27,7 +28,7 @@ |
452 | public static Unity.Favorites get_default () |
453 | { |
454 | if (!(Unity.favorites_singleton is Unity.Favorites)) |
455 | - Unity.favorites_singleton = new Unity.GConfFavorites (); |
456 | + Unity.favorites_singleton = new Unity.GSettingsFavorites (); |
457 | return Unity.favorites_singleton; |
458 | } |
459 | |
460 | @@ -55,56 +56,40 @@ |
461 | public abstract void set_bool (string uid, string name, bool value); |
462 | } |
463 | |
464 | - public class GConfFavorites : Favorites |
465 | + public class GSettingsFavorites : Favorites |
466 | { |
467 | + static const string schema = "com.canonical.Unity.Launcher.Favorites.Favorite"; |
468 | static const string path = "/desktop/unity/launcher/favorites/"; |
469 | - private GConf.Client? client; |
470 | - private SList<string> fav_ids; |
471 | - private HashMap<string, uint> notify_map; |
472 | + private HashMap<string, Settings> settings_map; |
473 | + private Settings fav_settings; |
474 | + private string[] fav_ids; |
475 | |
476 | construct |
477 | { |
478 | + settings_map = new HashMap<string, Settings> (str_hash, str_equal); |
479 | + fav_settings = new Settings ("com.canonical.Unity.Launcher.Favorites"); |
480 | |
481 | - // try to migrate favorites from desktop, old UNE and gnome-panel |
482 | - var gconf_custom_dir = Environment.get_home_dir () + "/.gconf/desktop/unity"; |
483 | - var migration_script = Config.PREFIXDIR + "/lib/unity/migrate_favorites.py"; |
484 | - if (!FileUtils.test(gconf_custom_dir, FileTest.IS_DIR) && |
485 | - FileUtils.test(migration_script, FileTest.IS_EXECUTABLE)) |
486 | + // try to migrate favorites from desktop, old UNE, gnome-panel, and gconf |
487 | + if (!fav_settings.get_boolean ("migrated")) |
488 | { |
489 | - try |
490 | + var migration_script = Config.PREFIXDIR + "/lib/unity/migrate_favorites.py"; |
491 | + if (FileUtils.test (migration_script, FileTest.IS_EXECUTABLE)) |
492 | { |
493 | - GLib.Process.spawn_command_line_sync(migration_script); |
494 | + try |
495 | + { |
496 | + GLib.Process.spawn_command_line_sync (migration_script); |
497 | + } |
498 | + catch (SpawnError e) { } // no migration, don't bother |
499 | } |
500 | - catch (SpawnError e) { } // no migration, don't bother |
501 | + fav_settings.set_boolean ("migrated", true); |
502 | } |
503 | |
504 | - client = GConf.Client.get_default (); |
505 | - notify_map = new HashMap<string, uint> (); |
506 | favorite_added.connect (on_favorite_added); |
507 | favorite_removed.connect (on_favorite_removed); |
508 | - try |
509 | - { |
510 | - fav_ids = client.get_list (path + "favorites_list", GConf.ValueType.STRING); |
511 | - } |
512 | - catch (Error e) |
513 | - { |
514 | - warning ("Could not grab favorites from gconf %s", e.message); |
515 | - fav_ids = new SList<string> (); |
516 | - } |
517 | |
518 | // set a watch on the favorites list |
519 | - try |
520 | - { |
521 | - client.add_dir (path + "favorites_list", |
522 | - GConf.ClientPreloadType.NONE); |
523 | - client.notify_add (path + "favorites_list", |
524 | - notify_on_favorites_list_changed); |
525 | - } |
526 | - catch (Error e) |
527 | - { |
528 | - warning ("Unable to monitor gconf for favorites changes: %s", |
529 | - e.message); |
530 | - } |
531 | + fav_settings.changed["favorites-list"].connect (notify_on_favorites_list_changed); |
532 | + notify_on_favorites_list_changed (fav_settings, "favorites-list"); |
533 | } |
534 | |
535 | /* abstract class implimentation */ |
536 | @@ -112,11 +97,11 @@ |
537 | |
538 | public override string find_uid_for_desktop_file (string desktop_file) |
539 | { |
540 | - /* goes through the gconf favorites and finds us a desktop file */ |
541 | + /* goes through the favorites and finds us a desktop file */ |
542 | string uid = ""; |
543 | - foreach (string id in fav_ids) |
544 | + foreach (weak string id in fav_ids) |
545 | { |
546 | - string fav_desktop_file = get_string (id, "desktop_file"); |
547 | + string fav_desktop_file = get_string (id, "desktop-file"); |
548 | if (fav_desktop_file == desktop_file) |
549 | { |
550 | uid = id; |
551 | @@ -141,16 +126,14 @@ |
552 | { |
553 | if (!is_favorite (uid)) |
554 | { |
555 | - fav_ids.append (uid); |
556 | - try |
557 | - { |
558 | - client.set_list (path + "favorites_list", GConf.ValueType.STRING, fav_ids); |
559 | - } |
560 | - catch (Error e) |
561 | - { |
562 | - warning ("Could not set the favorites list: %s", e.message); |
563 | - } |
564 | - favorite_added (uid); |
565 | + string[] new_favs = new string[fav_ids.length + 1]; |
566 | + int i = 0; |
567 | + foreach (weak string fav in fav_ids) |
568 | + { |
569 | + new_favs[i++] = fav; |
570 | + } |
571 | + new_favs[i] = uid; |
572 | + fav_settings.set_strv ("favorites-list", (string*[])new_favs); |
573 | } |
574 | } |
575 | |
576 | @@ -158,28 +141,18 @@ |
577 | { |
578 | if (is_favorite (uid)) |
579 | { |
580 | - unowned SList<string> l = null; |
581 | - for (l = fav_ids; l != null; l = l.next) |
582 | - { |
583 | - string id = l.data; |
584 | - if (id == uid) |
585 | - { |
586 | - fav_ids.remove (l.data); |
587 | - break; |
588 | - } |
589 | - } |
590 | - fav_ids.remove (uid); |
591 | - |
592 | - try |
593 | - { |
594 | - client.set_list (path + "favorites_list", GConf.ValueType.STRING, fav_ids); |
595 | - } |
596 | - catch (Error e) |
597 | - { |
598 | - warning ("Could not set the favorites list: %s", e.message); |
599 | - } |
600 | - |
601 | - favorite_removed (uid); |
602 | + string[] new_favs = new string[fav_ids.length - 1]; |
603 | + int i = 0; |
604 | + foreach (weak string fav in fav_ids) |
605 | + { |
606 | + if (fav != uid) |
607 | + { |
608 | + new_favs[i++] = fav; |
609 | + } |
610 | + } |
611 | + new_favs.resize(i); /* just for the bizarre case of more than one match */ |
612 | + |
613 | + fav_settings.set_strv ("favorites-list", (string*[])new_favs); |
614 | } |
615 | else |
616 | { |
617 | @@ -189,137 +162,73 @@ |
618 | |
619 | public override bool is_favorite (string uid) |
620 | { |
621 | - foreach (string id in fav_ids) |
622 | - { |
623 | - if (id == uid) |
624 | - { |
625 | - return true; |
626 | - } |
627 | - } |
628 | - return false; |
629 | - } |
630 | + foreach (weak string id in fav_ids) |
631 | + { |
632 | + if (id == uid) |
633 | + { |
634 | + return true; |
635 | + } |
636 | + } |
637 | + return false; |
638 | + } |
639 | |
640 | public override string? get_string (string uid, string name) |
641 | { |
642 | - string? return_string = null; |
643 | - try |
644 | - { |
645 | - return_string = client.get_string (path + uid + "/" + name); |
646 | - } |
647 | - catch (Error e) |
648 | - { |
649 | - warning ("GConf string lookup failed: %s", e.message); |
650 | - } |
651 | - return return_string; |
652 | + return get_settings (uid).get_string (name); |
653 | } |
654 | |
655 | public override void set_string (string uid, string name, string value) |
656 | { |
657 | - try |
658 | - { |
659 | - client.set_string (path + uid + "/" + name, value); |
660 | - } |
661 | - catch (Error e) |
662 | - { |
663 | - warning ("GConf string setting failed: %s", e.message); |
664 | - } |
665 | + get_settings (uid).set_string (name, value); |
666 | } |
667 | |
668 | public override int? get_int (string uid, string name) |
669 | { |
670 | - int? return_val = null; |
671 | - try |
672 | - { |
673 | - return_val = client.get_int (path + uid + "/" + name); |
674 | - } |
675 | - catch (Error e) |
676 | - { |
677 | - warning ("GConf int lookup failed: %s", e.message); |
678 | - } |
679 | - return return_val; |
680 | + return get_settings (uid).get_int (name); |
681 | } |
682 | |
683 | public override void set_int (string uid, string name, int value) |
684 | { |
685 | - try |
686 | - { |
687 | - client.set_int (path + uid + "/" + name, value); |
688 | - } |
689 | - catch (Error e) |
690 | - { |
691 | - warning ("GConf int setting failed: %s", e.message); |
692 | - } |
693 | + get_settings (uid).set_int (name, value); |
694 | } |
695 | |
696 | public override float? get_float (string uid, string name) |
697 | { |
698 | - float? return_val = null; |
699 | - try |
700 | - { |
701 | - return_val = (float)(client.get_float (path + uid + "/" + name)); |
702 | - } |
703 | - catch (Error e) |
704 | - { |
705 | - warning ("GConf float lookup failed: %s", e.message); |
706 | - } |
707 | - return return_val; |
708 | + return (float) get_settings (uid).get_double (name); |
709 | } |
710 | |
711 | public override void set_float (string uid, string name, float value) |
712 | { |
713 | - try |
714 | - { |
715 | - client.set_float (path + uid + "/" + name, value); |
716 | - } |
717 | - catch (Error e) |
718 | - { |
719 | - warning ("GConf float set failed: %s", e.message); |
720 | - } |
721 | + get_settings (uid).set_double (name, (double) value); |
722 | } |
723 | |
724 | public override bool? get_bool (string uid, string name) |
725 | { |
726 | - bool? return_val = null; |
727 | - try |
728 | - { |
729 | - return_val = client.get_bool (path + uid + "/" + name); |
730 | - } |
731 | - catch (Error e) |
732 | - { |
733 | - warning ("GConf bool lookup failed: %s", e.message); |
734 | - } |
735 | - return return_val; |
736 | + return get_settings (uid).get_boolean (name); |
737 | } |
738 | |
739 | public override void set_bool (string uid, string name, bool value) |
740 | { |
741 | - try |
742 | - { |
743 | - client.set_bool (path + uid + "/" + name, value); |
744 | - } |
745 | - catch (Error e) |
746 | - { |
747 | - warning ("GConf bool setting failed: %s", e.message); |
748 | - } |
749 | + get_settings (uid).set_boolean (name, value); |
750 | } |
751 | |
752 | /* private methods */ |
753 | /* Expects a list of strings */ |
754 | - private void compare_string_list (SList<string> old_list, SList<string> new_list, |
755 | + private void compare_string_list (string[] old_list, string[] new_list, |
756 | out SList<string> added, out SList<string> removed) |
757 | { |
758 | SList<string> unchanged = new SList<string> (); |
759 | |
760 | foreach (string id in new_list) |
761 | { |
762 | - string? item = null; |
763 | - foreach (string old_item in old_list) |
764 | - { |
765 | - if (id == old_item) |
766 | - { |
767 | - item = old_item; |
768 | - } |
769 | - } |
770 | + string? item = null; |
771 | + foreach (string old_item in old_list) |
772 | + { |
773 | + if (id == old_item) |
774 | + { |
775 | + item = old_item; |
776 | + } |
777 | + } |
778 | |
779 | if (item != null) |
780 | { |
781 | @@ -333,14 +242,14 @@ |
782 | |
783 | foreach (string id in old_list) |
784 | { |
785 | - string? item = null; |
786 | - foreach (string unchanged_item in unchanged) |
787 | - { |
788 | - if (unchanged_item == id) |
789 | - { |
790 | - item = unchanged_item; |
791 | - } |
792 | - } |
793 | + string? item = null; |
794 | + foreach (string unchanged_item in unchanged) |
795 | + { |
796 | + if (unchanged_item == id) |
797 | + { |
798 | + item = unchanged_item; |
799 | + } |
800 | + } |
801 | |
802 | if (item == null) |
803 | { |
804 | @@ -349,24 +258,29 @@ |
805 | } |
806 | } |
807 | |
808 | + private Settings get_settings (string uid) |
809 | + { |
810 | + var rv = settings_map.get (uid); |
811 | + if (rv == null) |
812 | + { |
813 | + rv = new Settings.with_path (schema, path + uid); |
814 | + settings_map.set (uid, rv); |
815 | + } |
816 | + return rv; |
817 | + } |
818 | + |
819 | |
820 | /* callbacks */ |
821 | - private void notify_on_favorites_list_changed () |
822 | + private void notify_on_favorites_list_changed (Settings settings, string key) |
823 | { |
824 | SList<string> items_added = new SList<string> (); |
825 | SList<string> items_removed = new SList<string> (); |
826 | - SList<string> new_favs; |
827 | - try |
828 | - { |
829 | - new_favs = client.get_list (path + "favorites_list", GConf.ValueType.STRING); |
830 | - } |
831 | - catch (Error e) |
832 | - { |
833 | - warning ("Could not get favourite list from gconf %s", e.message); |
834 | - return; // we return here because we can't do anything with no working gconf |
835 | - } |
836 | + string[] new_favs; |
837 | |
838 | + new_favs = settings.get_strv (key); |
839 | compare_string_list (fav_ids, new_favs, out items_added, out items_removed); |
840 | + fav_ids = new_favs; |
841 | + |
842 | foreach (string id in items_added) |
843 | { |
844 | favorite_added (id); |
845 | @@ -379,45 +293,36 @@ |
846 | |
847 | private void on_favorite_added (string uid) |
848 | { |
849 | - // set a watch on the favorite |
850 | - try |
851 | - { |
852 | - client.add_dir (path + uid + "/", |
853 | - GConf.ClientPreloadType.NONE); |
854 | - uint notify_id = client.notify_add (path + uid + "/", |
855 | - notify_on_favorite_changed); |
856 | - notify_map[uid] = notify_id; |
857 | - } |
858 | - catch (Error e) |
859 | - { |
860 | - warning ("Unable to monitor gconf for favorite changes: %s", |
861 | - e.message); |
862 | - } |
863 | + get_settings (uid).changed.connect (notify_on_favorite_changed); |
864 | } |
865 | |
866 | private void on_favorite_removed (string uid) |
867 | { |
868 | - uint notify_id = notify_map[uid]; |
869 | - client.notify_remove (notify_id); |
870 | - notify_map.unset (uid); |
871 | - |
872 | - fav_ids.remove_all (uid); |
873 | + settings_map.unset (uid); |
874 | } |
875 | |
876 | - private void notify_on_favorite_changed (GConf.Client _client, uint cnxn_id, GConf.Entry entry) |
877 | + private void notify_on_favorite_changed (Settings settings, string key) |
878 | { |
879 | - // we need to figure out our uid |
880 | - // we expect /desktop/unity/launcher/favorites/uid/foobar so we just use splits |
881 | - // regex's shouldn't be needed unless we do crazy stuff |
882 | - |
883 | - string uid = entry.key.split (path, 2)[1].split ("/", 2)[0]; //should split up nicely :) |
884 | - if (is_favorite (uid)) |
885 | + // We need to figure out our UID. |
886 | + // Normally, we could just ask for the path of a Settings object and |
887 | + // strip off the last chunk to find the UID. But because of a glib crash |
888 | + // https://bugzilla.gnome.org/show_bug.cgi?id=632899 we can't do that. |
889 | + // So instead, do a reverse-lookup in our map for the UID. |
890 | + string uid = null; |
891 | + foreach (Map.Entry<string, Settings> entry in settings_map.entries) |
892 | + { |
893 | + if (entry.value == settings) |
894 | + { |
895 | + uid = entry.key; |
896 | + } |
897 | + } |
898 | + if (uid != null && is_favorite (uid)) |
899 | { |
900 | favorite_changed (uid); |
901 | } |
902 | else |
903 | { |
904 | - warning ("got strange uid %s: %s", uid, entry.key); |
905 | + warning ("got strange uid %s: %s", uid, key); |
906 | return; |
907 | } |
908 | } |
This doesn't really apply to Unity trunk, but might not be a bad thing to land in Unity 0.2 series if people are picking it up for whatever reason to use on maverick/natty.
Everything looks good, approved. Thanks :)