Merge lp:~kamstrup/libunity/keywords-index into lp:libunity

Proposed by Mikkel Kamstrup Erlandsen
Status: Merged
Approved by: Neil J. Patel
Approved revision: 82
Merged at revision: 82
Proposed branch: lp:~kamstrup/libunity/keywords-index
Merge into: lp:libunity
Diff against target: 259 lines (+109/-22)
5 files modified
configure.ac (+3/-3)
src/unity-appinfo-manager.vala (+83/-19)
test/data/applications/ubuntu-about.desktop (+2/-0)
test/data/test_desktop_file.desktop (+1/-0)
test/vala/test-appinfo-manager.vala (+20/-0)
To merge this branch: bzr merge lp:~kamstrup/libunity/keywords-index
Reviewer Review Type Date Requested Status
Michal Hruby (community) Approve
Neil J. Patel (community) Approve
Review via email: mp+77129@code.launchpad.net

Description of the change

See commit msg and attached bug

To post a comment you must log in.
Revision history for this message
Neil J. Patel (njpatel) wrote :

Looks good, approved.

review: Approve
Revision history for this message
Michal Hruby (mhr3) wrote :

And one more from me.

review: Approve
lp:~kamstrup/libunity/keywords-index updated
83. By Mikkel Kamstrup Erlandsen

Merge lp:~mhr3/libunity/no-string-array-copies: Don't copy string arrays all over the place when registering keywords

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'configure.ac'
2--- configure.ac 2011-09-15 11:14:02 +0000
3+++ configure.ac 2011-09-27 10:55:34 +0000
4@@ -1,5 +1,5 @@
5 # When releasing also remember to update the soname as instructed below
6-AC_INIT(libunity, 4.0.4)
7+AC_INIT(libunity, 4.0.5)
8
9 AM_INIT_AUTOMAKE(AC_PACKAGE_NAME, AC_PACKAGE_VERSION)
10 AM_CONFIG_HEADER(config.h)
11@@ -16,9 +16,9 @@
12 # - If binary compatibility has been broken (eg removed or changed interfaces)
13 # change to C+1:0:0
14 # - If the interface is the same as the previous version, change to C:R+1:A
15-LIBUNITY_LT_CURRENT=7
16+LIBUNITY_LT_CURRENT=8
17 LIBUNITY_LT_REV=0
18-LIBUNITY_LT_AGE=1
19+LIBUNITY_LT_AGE=2
20 LIBUNITY_LT_VERSION="$LIBUNITY_LT_CURRENT:$LIBUNITY_LT_REV:$LIBUNITY_LT_AGE"
21 LIBUNITY_LT_LDFLAGS="-version-info $LIBUNITY_LT_VERSION -export-symbols-regex '^unity_.*'"
22
23
24=== modified file 'src/unity-appinfo-manager.vala'
25--- src/unity-appinfo-manager.vala 2011-09-15 09:09:46 +0000
26+++ src/unity-appinfo-manager.vala 2011-09-27 10:55:34 +0000
27@@ -37,6 +37,11 @@
28 private class StringArrayWrapper
29 {
30 public string[] strings;
31+
32+ public void take_strings (owned string[] str_arr)
33+ {
34+ strings = (owned) str_arr;
35+ }
36 }
37
38 /**
39@@ -54,12 +59,14 @@
40 private HashTable<string,AppInfo?> appinfo_by_id; /* id or path -> AppInfo */
41 private HashTable<string,FileMonitor> monitors; /* parent uri -> monitor */
42 private HashTable<string, StringArrayWrapper> categories_by_id; /* desktop id or path -> xdg cats */
43+ private HashTable<string, StringArrayWrapper> keywords_by_id; /* desktop id or path -> X-GNOME-Keywords and X-AppInstall-Keywords */
44 private HashTable<string,string?> paths_by_id; /* desktop id -> full path to desktop file */
45
46 private AppInfoManager ()
47 {
48 appinfo_by_id = new HashTable<string,AppInfo?> (str_hash, str_equal);
49 categories_by_id = new HashTable<string,StringArrayWrapper> (str_hash, str_equal);
50+ keywords_by_id = new HashTable<string,StringArrayWrapper> (str_hash, str_equal);
51 paths_by_id = new HashTable<string,string?> (str_hash, str_equal);
52
53 monitors = new HashTable<string,FileMonitor> (str_hash, str_equal);
54@@ -187,16 +194,9 @@
55 if (keyfile != null)
56 {
57 appinfo = new DesktopAppInfo.from_keyfile (keyfile);
58- try {
59- string[] categories = keyfile.get_string_list ("Desktop Entry",
60- "Categories");
61-
62- var wrapper = new StringArrayWrapper();
63- wrapper.strings = categories;
64- categories_by_id.insert (id, wrapper);
65- } catch (KeyFileError e) {
66- /* Unknown key or group. This app has no XDG Catories */
67- }
68+
69+ register_categories (id, keyfile);
70+ register_keywords (id, keyfile);
71 }
72 else
73 appinfo = null;
74@@ -227,6 +227,28 @@
75 var result = categories_by_id.lookup (id);
76 return result != null ? result.strings : null;
77 }
78+
79+ /**
80+ * Look up keywords for for desktop id or file path @id. The keywords will
81+ * be an amalgamation of the X-GNOME-Keywords and X-AppInstall-Keywords
82+ * fields from the .desktopfile.
83+ * Returns null if id is not found.
84+ * This method will do sync IO if the desktop file for @id is not
85+ * already cached. So if you are living in an async world you must first
86+ * do an async call to lookup_async(id) before calling this method, in which
87+ * case no sync io will be done.
88+ */
89+ public unowned string[]? get_keywords (string id)
90+ {
91+ /* Make sure we have loaded the relevant .desktop file: */
92+ AppInfo? appinfo = lookup (id);
93+
94+ if (appinfo == null)
95+ return null;
96+
97+ var result = keywords_by_id.lookup (id);
98+ return result != null ? result.strings : null;
99+ }
100
101 /**
102 * Look up the full path to the desktop file for desktop id @id.
103@@ -327,27 +349,69 @@
104 /* Create the appinfo and cache it */
105 var appinfo = new DesktopAppInfo.from_keyfile (keyfile);
106 appinfo_by_id.insert (id, appinfo);
107+ register_categories (id, keyfile);
108+ register_keywords (id, keyfile);
109+
110+ return appinfo;
111+ }
112+
113+ /* Clear all cached AppInfos */
114+ public void clear ()
115+ {
116+ appinfo_by_id.remove_all ();
117+ categories_by_id.remove_all ();
118+ keywords_by_id.remove_all ();
119+ paths_by_id.remove_all ();
120+ // We don't tear down fs monitors... Dunno if we should...
121+ }
122+
123+ private void register_categories (string id, KeyFile keyfile)
124+ {
125 try {
126 string[] categories = keyfile.get_string_list ("Desktop Entry",
127 "Categories");
128
129 var wrapper = new StringArrayWrapper();
130- wrapper.strings = categories;
131+ wrapper.take_strings ((owned) categories);
132 categories_by_id.insert (id, wrapper);
133 } catch (KeyFileError eee) {
134 /* Unknown key or group. This app has no XDG Catories */
135 }
136-
137- return appinfo;
138 }
139
140- /* Clear all cached AppInfos */
141- public void clear ()
142+ private void register_keywords (string id, KeyFile keyfile)
143 {
144- appinfo_by_id.remove_all ();
145- categories_by_id.remove_all ();
146- paths_by_id.remove_all ();
147- // We don't tear down fs monitors... Dunno if we should...
148+ string[] gkeywords;
149+ string[] akeywords;
150+ try {
151+ gkeywords = keyfile.get_locale_string_list ("Desktop Entry",
152+ "X-GNOME-Keywords");
153+ } catch (KeyFileError e) {
154+ /* Unknown key or group. This app has no X-GNOME-Keywords */
155+ gkeywords = new string[0];
156+ }
157+ try {
158+ akeywords = keyfile.get_locale_string_list ("Desktop Entry",
159+ "X-AppInstall-Keywords");
160+ } catch (KeyFileError e) {
161+ /* Unknown key or group. This app has no X-GNOME-Keywords */
162+ akeywords = new string[0];
163+ }
164+
165+ /* Copy the two keyword types into one 'keyword' array */
166+ string[] keywords = new string[gkeywords.length + akeywords.length];
167+ for (int i = 0; i < gkeywords.length; i++)
168+ {
169+ keywords[i] = gkeywords[i];
170+ }
171+ for (int i = 0; i < akeywords.length; i++)
172+ {
173+ keywords[gkeywords.length + i] = akeywords[i];
174+ }
175+
176+ var wrapper = new StringArrayWrapper();
177+ wrapper.take_strings ((owned) keywords);
178+ keywords_by_id.insert (id, wrapper);
179 }
180
181 } /* class AppInfoManager */
182
183=== modified file 'test/data/applications/ubuntu-about.desktop'
184--- test/data/applications/ubuntu-about.desktop 2011-01-11 21:37:07 +0000
185+++ test/data/applications/ubuntu-about.desktop 2011-09-27 10:55:34 +0000
186@@ -9,3 +9,5 @@
187 Categories=GNOME;Application;Core;
188 StartupNotify=true
189 X-Ubuntu-Gettext-Domain=gnome-panel-2.0
190+X-GNOME-Keywords=about;ubuntu;help
191+X-AppInstall-Keywords=testkeyword
192
193=== modified file 'test/data/test_desktop_file.desktop'
194--- test/data/test_desktop_file.desktop 2011-01-11 21:37:07 +0000
195+++ test/data/test_desktop_file.desktop 2011-09-27 10:55:34 +0000
196@@ -6,3 +6,4 @@
197 Type=Application
198 StartupNotify=false
199 Icon=test_desktop_icon.png
200+
201
202=== modified file 'test/vala/test-appinfo-manager.vala'
203--- test/vala/test-appinfo-manager.vala 2011-09-09 16:00:28 +0000
204+++ test/vala/test-appinfo-manager.vala 2011-09-27 10:55:34 +0000
205@@ -61,6 +61,7 @@
206 var manager = AppInfoManager.get_instance();
207 assert (manager.lookup ("_foobar.desktop") == null);
208 assert (manager.get_categories ("_foobar.desktop") == null);
209+ assert (manager.get_keywords ("_foobar.desktop") == null);
210 assert (manager.get_path ("_foobar.desktop") == null);
211 }
212
213@@ -79,6 +80,7 @@
214 AppInfo? appinfo = yield manager.lookup_async ("_foobar.desktop");
215 assert (appinfo == null);
216 assert (manager.get_categories ("_foobar.desktop") == null);
217+ assert (manager.get_keywords ("_foobar.desktop") == null);
218 assert (manager.get_path ("_foobar.desktop") == null);
219 } catch (Error e) {
220 error ("Error reading desktop file: %s", e.message);
221@@ -99,10 +101,19 @@
222
223 string[]? categories = manager.get_categories ("ubuntu-about.desktop");
224 assert (categories != null);
225+ assert (categories.length == 3);
226 assert (categories[0] == "GNOME");
227 assert (categories[1] == "Application");
228 assert (categories[2] == "Core");
229
230+ string[]? keywords = manager.get_keywords ("ubuntu-about.desktop");
231+ assert (keywords != null);
232+ assert (keywords.length == 4);
233+ assert (keywords[0] == "about");
234+ assert (keywords[1] == "ubuntu");
235+ assert (keywords[2] == "help");
236+ assert (keywords[3] == "testkeyword");
237+
238 string path = manager.get_path ("ubuntu-about.desktop");
239 string abs_path = File.new_for_path(Config.TESTDIR).resolve_relative_path("data/applications/ubuntu-about.desktop").get_path();
240 assert (path == abs_path);
241@@ -129,9 +140,18 @@
242
243 string[]? categories = manager.get_categories ("ubuntu-about.desktop");
244 assert (categories != null);
245+ assert (categories.length == 3);
246 assert (categories[0] == "GNOME");
247 assert (categories[1] == "Application");
248 assert (categories[2] == "Core");
249+
250+ string[]? keywords = manager.get_keywords ("ubuntu-about.desktop");
251+ assert (keywords != null);
252+ assert (keywords[0] == "about");
253+ assert (keywords[1] == "ubuntu");
254+ assert (keywords[2] == "help");
255+ assert (keywords[3] == "testkeyword");
256+ assert (keywords.length == 4);
257
258 string path = manager.get_path ("ubuntu-about.desktop");
259 string abs_path = File.new_for_path(Config.TESTDIR).resolve_relative_path("data/applications/ubuntu-about.desktop").get_path();

Subscribers

People subscribed via source and target branches