Merge lp:~mterry/unity/gsettings into lp:unity

Proposed by Michael Terry
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
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.

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.
Revision history for this message
Neil J. Patel (njpatel) wrote :

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 :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'HACKING'
--- HACKING 2010-03-01 14:30:33 +0000
+++ HACKING 2010-10-22 15:19:44 +0000
@@ -40,10 +40,10 @@
4040
41Webapp switching:41Webapp switching:
42 Unity can use two webapp systems, prism and chromium, you can toggle between42 Unity can use two webapp systems, prism and chromium, you can toggle between
43 the two by setting the gconf key "/apps/unity/webapp_use_chromium" on or off43 the two by setting the gsettings key "/apps/unity/webapp-use-chromium" on or off
4444
45Setting unmovable apps:45Setting unmovable apps:
46 To make a launcher unmovable set the desktop_file gconf key of the app to manditory46 To make a launcher unmovable set the desktop-file gsettings key of the app to manditory
4747
48setting bottom fixed apps:48setting bottom fixed apps:
49 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 directory49 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
5050
=== modified file 'configure.ac'
--- configure.ac 2010-09-27 18:41:44 +0000
+++ configure.ac 2010-10-22 15:19:44 +0000
@@ -63,9 +63,7 @@
63 PREFIX="${prefix}"63 PREFIX="${prefix}"
64fi64fi
6565
66dnl GConf schema installation66GLIB_GSETTINGS
67AC_PATH_PROG(GCONFTOOL, gconftool-2)
68AM_GCONF_SOURCE_2
6967
70AC_DEFINE_UNQUOTED(LOCALE_DIR, "${PREFIX}/${DATADIRNAME}/locale",[Locale directory])68AC_DEFINE_UNQUOTED(LOCALE_DIR, "${PREFIX}/${DATADIRNAME}/locale",[Locale directory])
71AC_DEFINE_UNQUOTED(DATADIR, "${PREFIX}/${DATADIRNAME}",[Data directory])69AC_DEFINE_UNQUOTED(DATADIR, "${PREFIX}/${DATADIRNAME}",[Data directory])
@@ -95,7 +93,7 @@
95AC_SUBST(MAINTAINER_VALAFLAGS)93AC_SUBST(MAINTAINER_VALAFLAGS)
9694
97dnl Check for module and library dependancies95dnl Check for module and library dependancies
98GLIB_REQUIRED=2.2296GLIB_REQUIRED=2.26
99GTK_REQUIRED=2.1897GTK_REQUIRED=2.18
100PKG_CHECK_MODULES(BASE,98PKG_CHECK_MODULES(BASE,
101 clutter-1.0 >= 1.099 clutter-1.0 >= 1.0
102100
=== modified file 'data/Makefile.am'
--- data/Makefile.am 2010-09-03 14:04:37 +0000
+++ data/Makefile.am 2010-10-22 15:19:44 +0000
@@ -24,18 +24,13 @@
2424
25defaultdir = $(pkgdatadir)25defaultdir = $(pkgdatadir)
2626
27# Schemas27# Schema
28schemadir = $(sysconfdir)/gconf/schemas28@INTLTOOL_XML_NOMERGE_RULE@
29dist_schema_DATA = unity.schemas29@GSETTINGS_RULES@
3030gsettings_SCHEMAS = com.canonical.Unity.gschema.xml
31if GCONF_SCHEMAS_INSTALL31
32install-data-local:32convertdir = $(datadir)/GConf/gsettings
33 -GCONF_CONFIG_SOURCE=$(GCONF_SCHEMA_CONFIG_SOURCE) \33dist_convert_DATA = unity.convert
34 $(GCONFTOOL) --makefile-install-rule $(dist_schema_DATA)34
35endif35EXTRA_DIST = $(gsettings_SCHEMAS:.xml=.xml.in)
3636DISTCLEANFILES = $(gsettings_SCHEMAS)
37if GCONF_SCHEMAS_INSTALL
38uninstall-local:
39 -GCONF_CONFIG_SOURCE=$(GCONF_SCHEMA_CONFIG_SOURCE) \
40 $(GCONFTOOL) --makefile-uninstall-rule $(dist_schema_DATA)
41endif
4237
=== renamed file 'data/unity.schemas' => 'data/com.canonical.Unity.gschema.xml.in'
--- data/unity.schemas 2010-09-22 13:38:06 +0000
+++ data/com.canonical.Unity.gschema.xml.in 2010-10-22 15:19:44 +0000
@@ -1,57 +1,56 @@
1<gconfschemafile>1<?xml version="1.0" encoding="UTF-8"?>
2 <schemalist>2<schemalist>
33 <schema id="com.canonical.Unity" path="/desktop/unity/">
4<!-- PANEL KEYS -->4 <child name="panel" schema="com.canonical.Unity.Panel"/>
55 <child name="launcher" schema="com.canonical.Unity.Launcher"/>
6 <schema>6 </schema>
7 <key>/schemas/desktop/unity/panel/search_template</key>7 <schema id="com.canonical.Unity.Panel" path="/desktop/unity/panel/">
8 <applyto>/desktop/unity/panel/search_template</applyto>8 <key name="search-template" type="s">
9 <owner>unity</owner>9 <default>'xdg-open http://www.google.com/cse?cx=partner-pub-9300639326172081%3Ad9bbzbtli15&amp;ie=UTF-8&amp;sa=Search&amp;q=%s'</default>
10 <type>string</type>10 <_summary>The search template used for panel search</_summary>
11 <default>xdg-open http://www.google.com/cse?cx=partner-pub-9300639326172081%3Ad9bbzbtli15&amp;ie=UTF-8&amp;sa=Search&amp;q=%s</default>11 <_description>The search template used for panel search. '%s' is substituted with the search string.</_description>
12 <locale name="C">12 </key>
13 <short>The search template used for panel search</short>13 <key name="search-hint" type="s">
14 <long>The search template used for panel search. '%s' is substituted with the search string.</long>14 <default>'Google'</default>
15 </locale>15 <_summary>The search hint used for panel search</_summary>
16 </schema>16 <_description>The search hint used for panel search.</_description>
1717 </key>
18 <schema>18 </schema>
19 <key>/schemas/desktop/unity/panel/search_hint</key>19 <schema id="com.canonical.Unity.Launcher" path="/desktop/unity/launcher/">
20 <applyto>/desktop/unity/panel/search_hint</applyto>20 <key name="webapp-use-chromium" type="b">
21 <owner>unity</owner>21 <default>true</default>
22 <type>string</type>22 <_summary>Whether the launcher should create Chromium-based webapps</_summary>
23 <default>Google</default>23 <_description>Whether the launcher should create Chromium-based webapps. If this is False, Prism-based webapps will be created.</_description>
24 <locale name="C">24 </key>
25 <short>The search hint used for panel search</short>25 <key name="super-key-enable" type="b">
26 <long>The search hint used for panel search.</long>26 <default>true</default>
27 </locale>27 <_summary>Enable super key or not</_summary>
28 </schema>28 <_description>Enable/disable super key. If this is False, super key will not function.</_description>
2929 </key>
30<!-- LAUNCHER KEYS -->30 <child name="favorites" schema="com.canonical.Unity.Launcher.Favorites"/>
3131 </schema>
32 <schema>32 <schema id="com.canonical.Unity.Launcher.Favorites" path="/desktop/unity/launcher/favorites/">
33 <key>/schemas/desktop/unity/launcher/webapp_use_chromium</key>33 <key name="favorites-list" type="as">
34 <applyto>/desktop/unity/launcher/webapp_use_chromium</applyto>34 <default>[]</default>
35 <owner>unity</owner>35 </key>
36 <type>bool</type>36 <key name="migrated" type="b">
37 <default>1</default>37 <default>false</default>
38 <locale name="C">38 <_summary>Whether gconf favorites have been migrated</_summary>
39 <short>Whether the launcher should create Chromium-based webapps</short>39 <_description>If false, the first time Unity is run, old gconf favorites will be moved over.</_description>
40 <long>Whether the launcher should create Chromium-based webapps. If this is False, Prism-based webapps will be created.</long>40 </key>
41 </locale>41 </schema>
42 </schema>42 <schema id="com.canonical.Unity.Launcher.Favorites.Favorite">
4343 <key name="type" type="s">
44 <schema>44 <choices>
45 <key>/schemas/desktop/unity/launcher/super_key_enable</key>45 <choice value='application'/>
46 <applyto>/desktop/unity/launcher/super_key_enable</applyto>46 </choices>
47 <owner>unity</owner>47 <default>'application'</default>
48 <type>bool</type>48 </key>
49 <default>1</default>49 <key name="desktop-file" type="s">
50 <locale name="C">50 <default>''</default>
51 <short>Enable super key or not</short>51 </key>
52 <long>Enable/disable super key. If this is False, super key will not function.</long>52 <key name="priority" type="d">
53 </locale>53 <default>0</default>
54 </schema>54 </key>
5555 </schema>
56 </schemalist>56</schemalist>
57</gconfschemafile>
5857
=== added file 'data/unity.convert'
--- data/unity.convert 1970-01-01 00:00:00 +0000
+++ data/unity.convert 2010-10-22 15:19:44 +0000
@@ -0,0 +1,10 @@
1[com.canonical.Unity.Panel]
2search-template = /desktop/unity/panel/search_template
3search-hint = /desktop/unity/panel/search_hint
4
5[com.canonical.Unity.Launcher]
6webapp-use-chromium = /desktop/unity/launcher/webapp_use_chromium
7super-key-enable = /desktop/unity/launcher/super_key_enable
8
9[com.canonical.Unity.Launcher.Favorites]
10favorites-list = /desktop/unity/launcher/favorites/favorites_list
011
=== modified file 'po/POTFILES.in'
--- po/POTFILES.in 2010-09-14 13:45:42 +0000
+++ po/POTFILES.in 2010-10-22 15:19:44 +0000
@@ -6,4 +6,5 @@
6unity-private/places/places-place-search-entry.vala6unity-private/places/places-place-search-entry.vala
7unity-private/places/places-trash-controller.vala7unity-private/places/places-trash-controller.vala
8unity-private/places/places-volume-child-controller.vala8unity-private/places/places-volume-child-controller.vala
9data/com.canonical.Unity.gschema.xml.in
910
1011
=== modified file 'targets/mutter/Makefile.am'
--- targets/mutter/Makefile.am 2010-09-22 16:30:03 +0000
+++ targets/mutter/Makefile.am 2010-10-22 15:19:44 +0000
@@ -52,7 +52,6 @@
52 --pkg unity-const \52 --pkg unity-const \
53 --pkg unity \53 --pkg unity \
54 --pkg unity-private \54 --pkg unity-private \
55 --pkg gconf-2.0 \
56 $(MAINTAINER_VALAFLAGS)55 $(MAINTAINER_VALAFLAGS)
5756
58libunity_mutter_la_LIBADD = \57libunity_mutter_la_LIBADD = \
5958
=== modified file 'targets/mutter/plugin.vala'
--- targets/mutter/plugin.vala 2010-09-24 13:51:00 +0000
+++ targets/mutter/plugin.vala 2010-10-22 15:19:44 +0000
@@ -17,7 +17,6 @@
17 *17 *
18 */18 */
1919
20using GConf;
21using Unity;20using Unity;
22using Unity.Testing;21using Unity.Testing;
2322
@@ -174,6 +173,8 @@
174 public Gesture.Dispatcher gesture_dispatcher;173 public Gesture.Dispatcher gesture_dispatcher;
175 private Gesture.Type active_gesture_type = Gesture.Type.NONE;174 private Gesture.Type active_gesture_type = Gesture.Type.NONE;
176175
176 private Settings settings;
177
177 /* Pinch info */178 /* Pinch info */
178 /* private float start_pinch_radius = 0.0f; */179 /* private float start_pinch_radius = 0.0f; */
179 private unowned Mutter.Window? resize_window = null;180 private unowned Mutter.Window? resize_window = null;
@@ -204,10 +205,6 @@
204 private ExposeType expose_type = ExposeType.NONE;205 private ExposeType expose_type = ExposeType.NONE;
205 private unowned Mutter.Window? start_pinch_window = null;206 private unowned Mutter.Window? start_pinch_window = null;
206207
207 /* const */
208 private const string GCONF_DIR = "/desktop/unity/launcher";
209 private const string GCONF_SUPER_KEY_ENABLE_KEY = "super_key_enable";
210
211 construct208 construct
212 {209 {
213 is_starting = true;210 is_starting = true;
@@ -293,21 +290,11 @@
293 /* we need to hook into the super key bound by mutter for g-shell.290 /* we need to hook into the super key bound by mutter for g-shell.
294 don't ask me why mutter binds things for g-shell explictly...291 don't ask me why mutter binds things for g-shell explictly...
295 */292 */
296 var gc = GConf.Client.get_default();
297 Mutter.MetaDisplay display = Mutter.MetaScreen.get_display (plugin.get_screen ());293 Mutter.MetaDisplay display = Mutter.MetaScreen.get_display (plugin.get_screen ());
298294
299 try {295 this.settings = new Settings ("com.canonical.Unity.Launcher");
300 super_key_enable = gc.get_bool(GCONF_DIR + "/" + GCONF_SUPER_KEY_ENABLE_KEY);296 super_key_enable = this.settings.get_boolean ("super-key-enable");
301 } catch (GLib.Error e) {297 this.settings.changed["super-key-enable"].connect (this.super_key_enable_cb);
302 super_key_enable = true;
303 warning("Cannot find super_key_enable gconf key");
304 }
305 try {
306 gc.add_dir(GCONF_DIR, GConf.ClientPreloadType.ONELEVEL);
307 gc.notify_add(GCONF_DIR + "/" + GCONF_SUPER_KEY_ENABLE_KEY, this.gconf_super_key_enable_cb);
308 } catch (GLib.Error e) {
309 warning("Cannot set gconf callback function of super_key_enable");
310 }
311298
312 display.overlay_key_down.connect (() => {299 display.overlay_key_down.connect (() => {
313 if (super_key_enable) {300 if (super_key_enable) {
@@ -400,14 +387,8 @@
400 387
401 }388 }
402389
403 private void gconf_super_key_enable_cb(GConf.Client gc, uint cxnid, GConf.Entry entry) {390 private void super_key_enable_cb(Settings settings, string key) {
404 bool new_value = true;391 super_key_enable = settings.get_boolean (key);
405 try {
406 new_value = gc.get_bool(GCONF_DIR + "/" + GCONF_SUPER_KEY_ENABLE_KEY);
407 } catch (GLib.Error e) {
408 new_value = true;
409 }
410 super_key_enable = new_value;
411 }392 }
412393
413 private void on_focus_window_changed ()394 private void on_focus_window_changed ()
414395
=== modified file 'tools/migrate_favorites.py'
--- tools/migrate_favorites.py 2010-10-06 08:37:47 +0000
+++ tools/migrate_favorites.py 2010-10-22 15:19:44 +0000
@@ -12,6 +12,7 @@
12import gobject12import gobject
13import os13import os
14import sys14import sys
15import subprocess
1516
16def get_desktop_dir():17def get_desktop_dir():
17 ''' no python binding from xdg to get the desktop directory? '''18 ''' no python binding from xdg to get the desktop directory? '''
@@ -52,8 +53,9 @@
52 #print priority_position53 #print priority_position
53 return (apps_list, priority_position)54 return (apps_list, priority_position)
5455
55if os.path.exists(os.path.expanduser('~/.gconf/desktop/unity/')):56migrated_call = subprocess.Popen(["gsettings", "get", "com.canonical.Unity.Launcher.Favorites", "migrated"], stdout=subprocess.PIPE)
56 print "migration already done or unity used before migration support"57if migrated_call.communicate()[0].strip() == 'true':
58 print "migration already done"
57 sys.exit(0)59 sys.exit(0)
5860
59client = gconf.client_get_default()61client = gconf.client_get_default()
@@ -62,6 +64,19 @@
62apps_list = client.get_list('/desktop/unity/launcher/favorites/favorites_list', gconf.VALUE_STRING)64apps_list = client.get_list('/desktop/unity/launcher/favorites/favorites_list', gconf.VALUE_STRING)
63priority_position = len(apps_list) + 165priority_position = len(apps_list) + 1
6466
67if os.path.exists(os.path.expanduser('~/.gconf/desktop/unity/')):
68 # Unity has been run before and used gconf. Convert its favorites over.
69 # Other keys are handled by gsettings-data-convert, which we run here just
70 # to be safe (because it normally *should* be run by login)
71 subprocess.call(["gsettings-data-convert"])
72 for app in apps_list:
73 path = '/desktop/unity/launcher/favorites/' + app
74 cmd = ["gsettings", "set", "-p", path, "com.canonical.Unity.Launcher.Favorites.Favorite"]
75 subprocess.call(cmd + ["desktop-file", "'%s'" % client.get_string("%s/desktop_file" % path)])
76 subprocess.call(cmd + ["type", "'%s'" % client.get_string("%s/type" % path)])
77 subprocess.call(cmd + ["priority", "%s" % client.get_float("%s/priority" % path)])
78 sys.exit(0)
79
65# get GNOME panel favorites and convert them80# get GNOME panel favorites and convert them
66panel_list = client.get_list('/apps/panel/general/toplevel_id_list', gconf.VALUE_STRING)81panel_list = client.get_list('/apps/panel/general/toplevel_id_list', gconf.VALUE_STRING)
67candidate_objects = client.get_list('/apps/panel/general/object_id_list', gconf.VALUE_STRING)82candidate_objects = client.get_list('/apps/panel/general/object_id_list', gconf.VALUE_STRING)
6883
=== modified file 'unity-private/launcher/application-controller.vala'
--- unity-private/launcher/application-controller.vala 2010-09-27 16:15:53 +0000
+++ unity-private/launcher/application-controller.vala 2010-10-22 15:19:44 +0000
@@ -107,7 +107,7 @@
107 if (is_sticky)107 if (is_sticky)
108 {108 {
109 favorites.set_string (fav_id, "type", "application");109 favorites.set_string (fav_id, "type", "application");
110 favorites.set_string (fav_id, "desktop_file", desktop_file);110 favorites.set_string (fav_id, "desktop-file", desktop_file);
111 favorites.add_favorite (fav_id);111 favorites.add_favorite (fav_id);
112 }112 }
113 else113 else
114114
=== modified file 'unity-private/launcher/scroller-controller.vala'
--- unity-private/launcher/scroller-controller.vala 2010-09-24 12:37:02 +0000
+++ unity-private/launcher/scroller-controller.vala 2010-10-22 15:19:44 +0000
@@ -218,7 +218,7 @@
218218
219 foreach (string uid in favorites.get_favorites ())219 foreach (string uid in favorites.get_favorites ())
220 {220 {
221 string desktop_file = favorites.get_string (uid, "desktop_file");221 string desktop_file = favorites.get_string (uid, "desktop-file");
222 if (!FileUtils.test (desktop_file, FileTest.EXISTS))222 if (!FileUtils.test (desktop_file, FileTest.EXISTS))
223 {223 {
224 // no desktop file for this favorite or it does not exist224 // no desktop file for this favorite or it does not exist
@@ -249,7 +249,7 @@
249249
250 private void on_favorite_added (string uid)250 private void on_favorite_added (string uid)
251 {251 {
252 var desktop_file = favorites.get_string (uid, "desktop_file");252 var desktop_file = favorites.get_string (uid, "desktop-file");
253 if (!FileUtils.test (desktop_file, FileTest.EXISTS))253 if (!FileUtils.test (desktop_file, FileTest.EXISTS))
254 {254 {
255 // no desktop file for this favorite or it does not exist255 // no desktop file for this favorite or it does not exist
256256
=== modified file 'unity/Makefile.am'
--- unity/Makefile.am 2010-08-23 17:01:29 +0000
+++ unity/Makefile.am 2010-10-22 15:19:44 +0000
@@ -46,7 +46,6 @@
46 --pkg dbus-glib-1 \46 --pkg dbus-glib-1 \
47 --pkg Dbusmenu-Glib-0.2 \47 --pkg Dbusmenu-Glib-0.2 \
48 --pkg dee-1.0 \48 --pkg dee-1.0 \
49 --pkg gconf-2.0 \
50 --pkg gtk+-2.0 \49 --pkg gtk+-2.0 \
51 --pkg gio-2.0 \50 --pkg gio-2.0 \
52 --pkg gio-unix-2.0 \51 --pkg gio-unix-2.0 \
5352
=== modified file 'unity/chrome-handler.vala'
--- unity/chrome-handler.vala 2010-06-10 12:00:50 +0000
+++ unity/chrome-handler.vala 2010-10-22 15:19:44 +0000
@@ -144,7 +144,7 @@
144144
145 // we are not a favorite and we need to be favorited!145 // we are not a favorite and we need to be favorited!
146 favorites.set_string (uid, "type", "application");146 favorites.set_string (uid, "type", "application");
147 favorites.set_string (uid, "desktop_file", desktop_path);147 favorites.set_string (uid, "desktop-file", desktop_path);
148 favorites.set_float (uid, "priority", -100000.0f);148 favorites.set_float (uid, "priority", -100000.0f);
149 favorites.add_favorite (uid);149 favorites.add_favorite (uid);
150 }150 }
@@ -166,7 +166,7 @@
166 if (type != "application")166 if (type != "application")
167 continue;167 continue;
168168
169 string desktop_file = favorites.get_string(uid, "desktop_file");169 string desktop_file = favorites.get_string(uid, "desktop-file");
170 if (desktop_file == my_desktop_path)170 if (desktop_file == my_desktop_path)
171 {171 {
172 myuid = uid;172 myuid = uid;
173173
=== modified file 'unity/prism-handler.vala'
--- unity/prism-handler.vala 2010-06-08 09:43:43 +0000
+++ unity/prism-handler.vala 2010-10-22 15:19:44 +0000
@@ -159,7 +159,7 @@
159159
160 // we are not a favorite and we need to be favorited!160 // we are not a favorite and we need to be favorited!
161 favorites.set_string (uid, "type", "application");161 favorites.set_string (uid, "type", "application");
162 favorites.set_string (uid, "desktop_file", desktop_path);162 favorites.set_string (uid, "desktop-file", desktop_path);
163 favorites.add_favorite (uid);163 favorites.add_favorite (uid);
164 }164 }
165165
@@ -180,7 +180,7 @@
180 if (type != "application")180 if (type != "application")
181 continue;181 continue;
182182
183 string desktop_file = favorites.get_string(uid, "desktop_file");183 string desktop_file = favorites.get_string(uid, "desktop-file");
184 if (desktop_file == my_desktop_path)184 if (desktop_file == my_desktop_path)
185 {185 {
186 myuid = uid;186 myuid = uid;
187187
=== modified file 'unity/unity-favorites.vala'
--- unity/unity-favorites.vala 2010-09-09 10:16:54 +0000
+++ unity/unity-favorites.vala 2010-10-22 15:19:44 +0000
@@ -15,6 +15,7 @@
15 * <http://www.gnu.org/licenses/>.15 * <http://www.gnu.org/licenses/>.
16 *16 *
17 * Authored by Gordon Allott <gord.allott@canonical.com>17 * Authored by Gordon Allott <gord.allott@canonical.com>
18 * Michael Terry <michael.terry@canonical.com>
18 */19 */
19using Gee;20using Gee;
2021
@@ -27,7 +28,7 @@
27 public static Unity.Favorites get_default ()28 public static Unity.Favorites get_default ()
28 {29 {
29 if (!(Unity.favorites_singleton is Unity.Favorites))30 if (!(Unity.favorites_singleton is Unity.Favorites))
30 Unity.favorites_singleton = new Unity.GConfFavorites ();31 Unity.favorites_singleton = new Unity.GSettingsFavorites ();
31 return Unity.favorites_singleton;32 return Unity.favorites_singleton;
32 }33 }
3334
@@ -55,56 +56,40 @@
55 public abstract void set_bool (string uid, string name, bool value);56 public abstract void set_bool (string uid, string name, bool value);
56 }57 }
5758
58 public class GConfFavorites : Favorites59 public class GSettingsFavorites : Favorites
59 {60 {
61 static const string schema = "com.canonical.Unity.Launcher.Favorites.Favorite";
60 static const string path = "/desktop/unity/launcher/favorites/";62 static const string path = "/desktop/unity/launcher/favorites/";
61 private GConf.Client? client;63 private HashMap<string, Settings> settings_map;
62 private SList<string> fav_ids;64 private Settings fav_settings;
63 private HashMap<string, uint> notify_map;65 private string[] fav_ids;
6466
65 construct67 construct
66 {68 {
69 settings_map = new HashMap<string, Settings> (str_hash, str_equal);
70 fav_settings = new Settings ("com.canonical.Unity.Launcher.Favorites");
6771
68 // try to migrate favorites from desktop, old UNE and gnome-panel72 // try to migrate favorites from desktop, old UNE, gnome-panel, and gconf
69 var gconf_custom_dir = Environment.get_home_dir () + "/.gconf/desktop/unity";73 if (!fav_settings.get_boolean ("migrated"))
70 var migration_script = Config.PREFIXDIR + "/lib/unity/migrate_favorites.py";
71 if (!FileUtils.test(gconf_custom_dir, FileTest.IS_DIR) &&
72 FileUtils.test(migration_script, FileTest.IS_EXECUTABLE))
73 {74 {
74 try75 var migration_script = Config.PREFIXDIR + "/lib/unity/migrate_favorites.py";
76 if (FileUtils.test (migration_script, FileTest.IS_EXECUTABLE))
75 {77 {
76 GLib.Process.spawn_command_line_sync(migration_script);78 try
79 {
80 GLib.Process.spawn_command_line_sync (migration_script);
81 }
82 catch (SpawnError e) { } // no migration, don't bother
77 }83 }
78 catch (SpawnError e) { } // no migration, don't bother84 fav_settings.set_boolean ("migrated", true);
79 }85 }
8086
81 client = GConf.Client.get_default ();
82 notify_map = new HashMap<string, uint> ();
83 favorite_added.connect (on_favorite_added);87 favorite_added.connect (on_favorite_added);
84 favorite_removed.connect (on_favorite_removed);88 favorite_removed.connect (on_favorite_removed);
85 try
86 {
87 fav_ids = client.get_list (path + "favorites_list", GConf.ValueType.STRING);
88 }
89 catch (Error e)
90 {
91 warning ("Could not grab favorites from gconf %s", e.message);
92 fav_ids = new SList<string> ();
93 }
9489
95 // set a watch on the favorites list90 // set a watch on the favorites list
96 try91 fav_settings.changed["favorites-list"].connect (notify_on_favorites_list_changed);
97 {92 notify_on_favorites_list_changed (fav_settings, "favorites-list");
98 client.add_dir (path + "favorites_list",
99 GConf.ClientPreloadType.NONE);
100 client.notify_add (path + "favorites_list",
101 notify_on_favorites_list_changed);
102 }
103 catch (Error e)
104 {
105 warning ("Unable to monitor gconf for favorites changes: %s",
106 e.message);
107 }
108 }93 }
10994
110 /* abstract class implimentation */95 /* abstract class implimentation */
@@ -112,11 +97,11 @@
11297
113 public override string find_uid_for_desktop_file (string desktop_file)98 public override string find_uid_for_desktop_file (string desktop_file)
114 {99 {
115 /* goes through the gconf favorites and finds us a desktop file */100 /* goes through the favorites and finds us a desktop file */
116 string uid = "";101 string uid = "";
117 foreach (string id in fav_ids)102 foreach (weak string id in fav_ids)
118 {103 {
119 string fav_desktop_file = get_string (id, "desktop_file");104 string fav_desktop_file = get_string (id, "desktop-file");
120 if (fav_desktop_file == desktop_file)105 if (fav_desktop_file == desktop_file)
121 {106 {
122 uid = id;107 uid = id;
@@ -141,16 +126,14 @@
141 {126 {
142 if (!is_favorite (uid))127 if (!is_favorite (uid))
143 {128 {
144 fav_ids.append (uid);129 string[] new_favs = new string[fav_ids.length + 1];
145 try130 int i = 0;
146 {131 foreach (weak string fav in fav_ids)
147 client.set_list (path + "favorites_list", GConf.ValueType.STRING, fav_ids);132 {
148 }133 new_favs[i++] = fav;
149 catch (Error e)134 }
150 {135 new_favs[i] = uid;
151 warning ("Could not set the favorites list: %s", e.message);136 fav_settings.set_strv ("favorites-list", (string*[])new_favs);
152 }
153 favorite_added (uid);
154 }137 }
155 }138 }
156139
@@ -158,28 +141,18 @@
158 {141 {
159 if (is_favorite (uid))142 if (is_favorite (uid))
160 {143 {
161 unowned SList<string> l = null;144 string[] new_favs = new string[fav_ids.length - 1];
162 for (l = fav_ids; l != null; l = l.next)145 int i = 0;
163 {146 foreach (weak string fav in fav_ids)
164 string id = l.data;147 {
165 if (id == uid)148 if (fav != uid)
166 {149 {
167 fav_ids.remove (l.data);150 new_favs[i++] = fav;
168 break;151 }
169 }152 }
170 }153 new_favs.resize(i); /* just for the bizarre case of more than one match */
171 fav_ids.remove (uid);154
172155 fav_settings.set_strv ("favorites-list", (string*[])new_favs);
173 try
174 {
175 client.set_list (path + "favorites_list", GConf.ValueType.STRING, fav_ids);
176 }
177 catch (Error e)
178 {
179 warning ("Could not set the favorites list: %s", e.message);
180 }
181
182 favorite_removed (uid);
183 }156 }
184 else157 else
185 {158 {
@@ -189,137 +162,73 @@
189162
190 public override bool is_favorite (string uid)163 public override bool is_favorite (string uid)
191 {164 {
192 foreach (string id in fav_ids)165 foreach (weak string id in fav_ids)
193 {166 {
194 if (id == uid)167 if (id == uid)
195 {168 {
196 return true;169 return true;
197 }170 }
198 }171 }
199 return false;172 return false;
200 }173 }
201174
202 public override string? get_string (string uid, string name)175 public override string? get_string (string uid, string name)
203 {176 {
204 string? return_string = null;177 return get_settings (uid).get_string (name);
205 try
206 {
207 return_string = client.get_string (path + uid + "/" + name);
208 }
209 catch (Error e)
210 {
211 warning ("GConf string lookup failed: %s", e.message);
212 }
213 return return_string;
214 }178 }
215179
216 public override void set_string (string uid, string name, string value)180 public override void set_string (string uid, string name, string value)
217 {181 {
218 try182 get_settings (uid).set_string (name, value);
219 {
220 client.set_string (path + uid + "/" + name, value);
221 }
222 catch (Error e)
223 {
224 warning ("GConf string setting failed: %s", e.message);
225 }
226 }183 }
227184
228 public override int? get_int (string uid, string name)185 public override int? get_int (string uid, string name)
229 {186 {
230 int? return_val = null;187 return get_settings (uid).get_int (name);
231 try
232 {
233 return_val = client.get_int (path + uid + "/" + name);
234 }
235 catch (Error e)
236 {
237 warning ("GConf int lookup failed: %s", e.message);
238 }
239 return return_val;
240 }188 }
241189
242 public override void set_int (string uid, string name, int value)190 public override void set_int (string uid, string name, int value)
243 {191 {
244 try192 get_settings (uid).set_int (name, value);
245 {
246 client.set_int (path + uid + "/" + name, value);
247 }
248 catch (Error e)
249 {
250 warning ("GConf int setting failed: %s", e.message);
251 }
252 }193 }
253194
254 public override float? get_float (string uid, string name)195 public override float? get_float (string uid, string name)
255 {196 {
256 float? return_val = null;197 return (float) get_settings (uid).get_double (name);
257 try
258 {
259 return_val = (float)(client.get_float (path + uid + "/" + name));
260 }
261 catch (Error e)
262 {
263 warning ("GConf float lookup failed: %s", e.message);
264 }
265 return return_val;
266 }198 }
267199
268 public override void set_float (string uid, string name, float value)200 public override void set_float (string uid, string name, float value)
269 {201 {
270 try202 get_settings (uid).set_double (name, (double) value);
271 {
272 client.set_float (path + uid + "/" + name, value);
273 }
274 catch (Error e)
275 {
276 warning ("GConf float set failed: %s", e.message);
277 }
278 }203 }
279204
280 public override bool? get_bool (string uid, string name)205 public override bool? get_bool (string uid, string name)
281 {206 {
282 bool? return_val = null;207 return get_settings (uid).get_boolean (name);
283 try
284 {
285 return_val = client.get_bool (path + uid + "/" + name);
286 }
287 catch (Error e)
288 {
289 warning ("GConf bool lookup failed: %s", e.message);
290 }
291 return return_val;
292 }208 }
293209
294 public override void set_bool (string uid, string name, bool value)210 public override void set_bool (string uid, string name, bool value)
295 {211 {
296 try212 get_settings (uid).set_boolean (name, value);
297 {
298 client.set_bool (path + uid + "/" + name, value);
299 }
300 catch (Error e)
301 {
302 warning ("GConf bool setting failed: %s", e.message);
303 }
304 }213 }
305214
306 /* private methods */215 /* private methods */
307 /* Expects a list of strings */216 /* Expects a list of strings */
308 private void compare_string_list (SList<string> old_list, SList<string> new_list,217 private void compare_string_list (string[] old_list, string[] new_list,
309 out SList<string> added, out SList<string> removed)218 out SList<string> added, out SList<string> removed)
310 {219 {
311 SList<string> unchanged = new SList<string> ();220 SList<string> unchanged = new SList<string> ();
312221
313 foreach (string id in new_list)222 foreach (string id in new_list)
314 {223 {
315 string? item = null;224 string? item = null;
316 foreach (string old_item in old_list)225 foreach (string old_item in old_list)
317 {226 {
318 if (id == old_item)227 if (id == old_item)
319 {228 {
320 item = old_item;229 item = old_item;
321 }230 }
322 }231 }
323232
324 if (item != null)233 if (item != null)
325 {234 {
@@ -333,14 +242,14 @@
333242
334 foreach (string id in old_list)243 foreach (string id in old_list)
335 {244 {
336 string? item = null;245 string? item = null;
337 foreach (string unchanged_item in unchanged)246 foreach (string unchanged_item in unchanged)
338 {247 {
339 if (unchanged_item == id)248 if (unchanged_item == id)
340 {249 {
341 item = unchanged_item;250 item = unchanged_item;
342 }251 }
343 }252 }
344253
345 if (item == null)254 if (item == null)
346 {255 {
@@ -349,24 +258,29 @@
349 }258 }
350 }259 }
351260
261 private Settings get_settings (string uid)
262 {
263 var rv = settings_map.get (uid);
264 if (rv == null)
265 {
266 rv = new Settings.with_path (schema, path + uid);
267 settings_map.set (uid, rv);
268 }
269 return rv;
270 }
271
352272
353 /* callbacks */273 /* callbacks */
354 private void notify_on_favorites_list_changed ()274 private void notify_on_favorites_list_changed (Settings settings, string key)
355 {275 {
356 SList<string> items_added = new SList<string> ();276 SList<string> items_added = new SList<string> ();
357 SList<string> items_removed = new SList<string> ();277 SList<string> items_removed = new SList<string> ();
358 SList<string> new_favs;278 string[] new_favs;
359 try
360 {
361 new_favs = client.get_list (path + "favorites_list", GConf.ValueType.STRING);
362 }
363 catch (Error e)
364 {
365 warning ("Could not get favourite list from gconf %s", e.message);
366 return; // we return here because we can't do anything with no working gconf
367 }
368279
280 new_favs = settings.get_strv (key);
369 compare_string_list (fav_ids, new_favs, out items_added, out items_removed);281 compare_string_list (fav_ids, new_favs, out items_added, out items_removed);
282 fav_ids = new_favs;
283
370 foreach (string id in items_added)284 foreach (string id in items_added)
371 {285 {
372 favorite_added (id);286 favorite_added (id);
@@ -379,45 +293,36 @@
379293
380 private void on_favorite_added (string uid)294 private void on_favorite_added (string uid)
381 {295 {
382 // set a watch on the favorite296 get_settings (uid).changed.connect (notify_on_favorite_changed);
383 try
384 {
385 client.add_dir (path + uid + "/",
386 GConf.ClientPreloadType.NONE);
387 uint notify_id = client.notify_add (path + uid + "/",
388 notify_on_favorite_changed);
389 notify_map[uid] = notify_id;
390 }
391 catch (Error e)
392 {
393 warning ("Unable to monitor gconf for favorite changes: %s",
394 e.message);
395 }
396 }297 }
397298
398 private void on_favorite_removed (string uid)299 private void on_favorite_removed (string uid)
399 {300 {
400 uint notify_id = notify_map[uid];301 settings_map.unset (uid);
401 client.notify_remove (notify_id);
402 notify_map.unset (uid);
403
404 fav_ids.remove_all (uid);
405 }302 }
406303
407 private void notify_on_favorite_changed (GConf.Client _client, uint cnxn_id, GConf.Entry entry)304 private void notify_on_favorite_changed (Settings settings, string key)
408 {305 {
409 // we need to figure out our uid306 // We need to figure out our UID.
410 // we expect /desktop/unity/launcher/favorites/uid/foobar so we just use splits307 // Normally, we could just ask for the path of a Settings object and
411 // regex's shouldn't be needed unless we do crazy stuff308 // strip off the last chunk to find the UID. But because of a glib crash
412309 // https://bugzilla.gnome.org/show_bug.cgi?id=632899 we can't do that.
413 string uid = entry.key.split (path, 2)[1].split ("/", 2)[0]; //should split up nicely :)310 // So instead, do a reverse-lookup in our map for the UID.
414 if (is_favorite (uid))311 string uid = null;
312 foreach (Map.Entry<string, Settings> entry in settings_map.entries)
313 {
314 if (entry.value == settings)
315 {
316 uid = entry.key;
317 }
318 }
319 if (uid != null && is_favorite (uid))
415 {320 {
416 favorite_changed (uid);321 favorite_changed (uid);
417 }322 }
418 else323 else
419 {324 {
420 warning ("got strange uid %s: %s", uid, entry.key);325 warning ("got strange uid %s: %s", uid, key);
421 return;326 return;
422 }327 }
423 }328 }