Merge lp:~ted/ubuntu-app-launch/libual-desktop-file into lp:ubuntu-app-launch/15.10

Proposed by Ted Gould on 2015-08-07
Status: Merged
Approved by: Ted Gould on 2015-08-13
Approved revision: 207
Merged at revision: 207
Proposed branch: lp:~ted/ubuntu-app-launch/libual-desktop-file
Merge into: lp:ubuntu-app-launch/15.10
Prerequisite: lp:~ted/ubuntu-app-launch/libertine-detection
Diff against target: 362 lines (+213/-25)
7 files modified
debian/libubuntu-app-launch2.symbols (+1/-0)
libubuntu-app-launch/app-info.c (+120/-11)
libubuntu-app-launch/app-info.h (+2/-0)
libubuntu-app-launch/desktop-exec.c (+20/-14)
libubuntu-app-launch/ubuntu-app-launch.c (+12/-0)
libubuntu-app-launch/ubuntu-app-launch.h (+16/-0)
tests/libual-test.cc (+42/-0)
To merge this branch: bzr merge lp:~ted/ubuntu-app-launch/libual-desktop-file
Reviewer Review Type Date Requested Status
Renato Araujo Oliveira Filho (community) 2015-08-07 Approve on 2015-08-13
PS Jenkins bot (community) continuous-integration Needs Fixing on 2015-08-12
Review via email: mp+267287@code.launchpad.net

This proposal supersedes a proposal from 2015-04-10.

Commit message

Provide an API to find the desktop file and directory of an AppID

To post a comment you must log in.
PS Jenkins bot (ps-jenkins) wrote :

FAILED: Continuous integration, rev:207
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https://code.launchpad.net/~ted/ubuntu-app-launch/libual-desktop-file/+merge/267287/+edit-commit-message

http://jenkins.qa.ubuntu.com/job/ubuntu-app-launch-ci/17/
Executed test runs:
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-app-launch-wily-amd64-ci/17
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-app-launch-wily-armhf-ci/17
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-app-launch-wily-i386-ci/17

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/ubuntu-app-launch-ci/17/rebuild

review: Needs Fixing (continuous-integration)

looks good to me.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/libubuntu-app-launch2.symbols'
2--- debian/libubuntu-app-launch2.symbols 2015-06-04 20:35:57 +0000
3+++ debian/libubuntu-app-launch2.symbols 2015-08-12 02:52:44 +0000
4@@ -1,5 +1,6 @@
5 libubuntu-app-launch.so.2 libubuntu-app-launch2 #MINVER#
6 ubuntu_app_launch_app_id_parse@Base 0.4
7+ ubuntu_app_launch_application_info@Base 0replaceme
8 ubuntu_app_launch_application_log_path@Base 0.4
9 ubuntu_app_launch_get_primary_pid@Base 0.4
10 ubuntu_app_launch_helper_set_exec@Base 0.5+15.10.20150604
11
12=== modified file 'libubuntu-app-launch/app-info.c'
13--- libubuntu-app-launch/app-info.c 2015-08-12 02:52:44 +0000
14+++ libubuntu-app-launch/app-info.c 2015-08-12 02:52:44 +0000
15@@ -24,8 +24,8 @@
16 #include "app-info.h"
17
18 /* Try and get a manifest and do a couple sanity checks on it */
19-static JsonObject *
20-get_manifest (const gchar * pkg)
21+JsonObject *
22+get_manifest (const gchar * pkg, gchar ** pkgpath)
23 {
24 /* Get the directory from click */
25 GError * error = NULL;
26@@ -55,6 +55,16 @@
27 g_object_unref(user);
28 return NULL;
29 }
30+
31+ if (pkgpath != NULL) {
32+ *pkgpath = click_user_get_path(user, pkg, &error);
33+ if (error != NULL) {
34+ g_warning("Unable to get the Click package directory for %s: %s", pkg, error->message);
35+ g_error_free(error);
36+ g_object_unref(user);
37+ return NULL;
38+ }
39+ }
40 g_object_unref(user);
41
42 if (!json_object_has_member(manifest, "version")) {
43@@ -93,7 +103,7 @@
44 }
45
46 if (*manifest == NULL) {
47- *manifest = get_manifest(pkg);
48+ *manifest = get_manifest(pkg, NULL);
49 }
50
51 JsonObject * hooks = json_object_get_object_member(*manifest, "hooks");
52@@ -138,7 +148,7 @@
53 return original_ver;
54 } else {
55 if (*manifest == NULL) {
56- *manifest = get_manifest(pkg);
57+ *manifest = get_manifest(pkg, NULL);
58 }
59 g_return_val_if_fail(*manifest != NULL, NULL);
60
61@@ -190,6 +200,53 @@
62 }
63 }
64
65+/* Look to see if the app id results in a desktop file, if so, fill in the params */
66+static gboolean
67+evaluate_dir (const gchar * dir, const gchar * desktop, gchar ** appdir, gchar ** appdesktop)
68+{
69+ char * fulldir = g_build_filename(dir, "applications", desktop, NULL);
70+ gboolean found = FALSE;
71+
72+ if (g_file_test(fulldir, G_FILE_TEST_EXISTS)) {
73+ if (appdir != NULL) {
74+ *appdir = g_strdup(dir);
75+ }
76+
77+ if (appdesktop != NULL) {
78+ *appdesktop = g_strdup_printf("applications/%s", desktop);
79+ }
80+
81+ found = TRUE;
82+ }
83+
84+ g_free(fulldir);
85+ return found;
86+}
87+
88+/* Handle the legacy case where we look through the data directories */
89+gboolean
90+app_info_legacy (const gchar * appid, gchar ** appdir, gchar ** appdesktop)
91+{
92+ gchar * desktop = g_strdup_printf("%s.desktop", appid);
93+
94+ /* Special case the user's dir */
95+ if (evaluate_dir(g_get_user_data_dir(), desktop, appdir, appdesktop)) {
96+ g_free(desktop);
97+ return TRUE;
98+ }
99+
100+ const char * const * data_dirs = g_get_system_data_dirs();
101+ int i;
102+ for (i = 0; data_dirs[i] != NULL; i++) {
103+ if (evaluate_dir(data_dirs[i], desktop, appdir, appdesktop)) {
104+ g_free(desktop);
105+ return TRUE;
106+ }
107+ }
108+
109+ return FALSE;
110+}
111+
112 /* Handle the libertine case where we look in the container */
113 gboolean
114 app_info_libertine (const gchar * appid, gchar ** appdir, gchar ** appdesktop)
115@@ -225,21 +282,73 @@
116 }
117 }
118
119+ if (appdir != NULL) {
120+ *appdir = desktopdir;
121+ } else {
122+ g_free(desktopdir);
123+ }
124+
125+ if (appdesktop != NULL) {
126+ *appdesktop = g_build_filename("applications", desktopname, NULL);
127+ }
128+
129+ g_free(desktopfile);
130 g_free(desktopname);
131 g_free(container);
132 g_free(app);
133
134- if (appdir != NULL) {
135- *appdir = desktopdir;
136- } else {
137- g_free(desktopdir);
138- }
139+ return TRUE;
140+}
141+
142+/* Get the information on where the desktop file is from libclick */
143+gboolean
144+app_info_click (const gchar * appid, gchar ** appdir, gchar ** appdesktop)
145+{
146+ gchar * package = NULL;
147+ gchar * application = NULL;
148+
149+ if (!ubuntu_app_launch_app_id_parse(appid, &package, &application, NULL)) {
150+ return FALSE;
151+ }
152+
153+ JsonObject * manifest = get_manifest(package, appdir);
154+ if (manifest == NULL) {
155+ g_free(package);
156+ g_free(application);
157+ return FALSE;
158+ }
159+
160+ g_free(package);
161
162 if (appdesktop != NULL) {
163- *appdesktop = desktopfile;
164+ JsonObject * hooks = json_object_get_object_member(manifest, "hooks");
165+ if (hooks == NULL) {
166+ json_object_unref(manifest);
167+ g_free(application);
168+ return FALSE;
169+ }
170+
171+ JsonObject * appobj = json_object_get_object_member(hooks, application);
172+ g_free(application);
173+
174+ if (appobj == NULL) {
175+ json_object_unref(manifest);
176+ return FALSE;
177+ }
178+
179+ const gchar * desktop = json_object_get_string_member(appobj, "desktop");
180+ if (desktop == NULL) {
181+ json_object_unref(manifest);
182+ return FALSE;
183+ }
184+
185+ *appdesktop = g_strdup(desktop);
186 } else {
187- g_free(desktopfile);
188+ g_free(application);
189 }
190
191+ json_object_unref(manifest);
192+
193 return TRUE;
194 }
195+
196
197=== modified file 'libubuntu-app-launch/app-info.h'
198--- libubuntu-app-launch/app-info.h 2015-08-12 02:52:44 +0000
199+++ libubuntu-app-launch/app-info.h 2015-08-12 02:52:44 +0000
200@@ -21,7 +21,9 @@
201
202 #include <glib.h>
203
204+gboolean app_info_legacy (const gchar * appid, gchar ** appdir, gchar ** appdesktop);
205 gboolean app_info_libertine (const gchar * appid, gchar ** appdir, gchar ** appdesktop);
206+gboolean app_info_click (const gchar * appid, gchar ** appdir, gchar ** appdesktop);
207
208 gchar * click_triplet_to_app_id (const gchar * pkg, const gchar * app, const gchar * ver);
209 gchar * libertine_triplet_to_app_id (const gchar * pkg, const gchar * app, const gchar * ver);
210
211=== modified file 'libubuntu-app-launch/desktop-exec.c'
212--- libubuntu-app-launch/desktop-exec.c 2015-08-12 02:52:44 +0000
213+++ libubuntu-app-launch/desktop-exec.c 2015-08-12 02:52:44 +0000
214@@ -80,28 +80,34 @@
215 keyfile_for_libertine (const gchar * appid, gchar ** outcontainer)
216 {
217 gchar * desktopfile = NULL;
218+ gchar * desktopdir = NULL;
219
220- if (!app_info_libertine(appid, NULL, &desktopfile)) {
221+ if (!app_info_libertine(appid, &desktopdir, &desktopfile)) {
222 return NULL;
223 }
224
225+ gchar * desktopfull = g_build_filename(desktopdir, desktopfile, NULL);
226+ g_debug("Desktop full: %s", desktopfull);
227+ g_free(desktopdir);
228+ g_free(desktopfile);
229+
230 /* We now think we have a valid 'desktopfile' path */
231 GKeyFile * keyfile = g_key_file_new();
232- gboolean loaded = g_key_file_load_from_file(keyfile, desktopfile, G_KEY_FILE_NONE, NULL);
233+ gboolean loaded = g_key_file_load_from_file(keyfile, desktopfull, G_KEY_FILE_NONE, NULL);
234
235 if (!loaded) {
236- g_free(desktopfile);
237- g_key_file_free(keyfile);
238- return NULL;
239- }
240-
241- if (!verify_keyfile(keyfile, desktopfile)) {
242- g_free(desktopfile);
243- g_key_file_free(keyfile);
244- return NULL;
245- }
246-
247- g_free(desktopfile);
248+ g_free(desktopfull);
249+ g_key_file_free(keyfile);
250+ return NULL;
251+ }
252+
253+ if (!verify_keyfile(keyfile, desktopfull)) {
254+ g_free(desktopfull);
255+ g_key_file_free(keyfile);
256+ return NULL;
257+ }
258+
259+ g_free(desktopfull);
260
261 if (outcontainer != NULL) {
262 ubuntu_app_launch_app_id_parse(appid, outcontainer, NULL, NULL);
263
264=== modified file 'libubuntu-app-launch/ubuntu-app-launch.c'
265--- libubuntu-app-launch/ubuntu-app-launch.c 2015-08-12 02:52:44 +0000
266+++ libubuntu-app-launch/ubuntu-app-launch.c 2015-08-12 02:52:44 +0000
267@@ -748,6 +748,18 @@
268 return path;
269 }
270
271+gboolean
272+ubuntu_app_launch_application_info (const gchar * appid, gchar ** appdir, gchar ** appdesktop)
273+{
274+ if (is_click(appid)) {
275+ return app_info_click(appid, appdir, appdesktop);
276+ } else if (is_libertine(appid)) {
277+ return app_info_libertine(appid, appdir, appdesktop);
278+ } else {
279+ return app_info_legacy(appid, appdir, appdesktop);
280+ }
281+}
282+
283 static GDBusConnection *
284 gdbus_upstart_ref (void) {
285 static GDBusConnection * gdbus_upstart = NULL;
286
287=== modified file 'libubuntu-app-launch/ubuntu-app-launch.h'
288--- libubuntu-app-launch/ubuntu-app-launch.h 2015-06-04 20:22:27 +0000
289+++ libubuntu-app-launch/ubuntu-app-launch.h 2015-08-12 02:52:44 +0000
290@@ -142,6 +142,22 @@
291 gchar * ubuntu_app_launch_application_log_path (const gchar * appid);
292
293 /**
294+ * ubuntu_app_launch_application_info:
295+ * @appid: ID of the application
296+ * @appdir: (allow-none) (transfer full): Directory for the application
297+ * @appdesktop: (allow-none) (transfer full): Relative path to desktop file
298+ *
299+ * Finds a location for information on an application and the relative
300+ * directory that it was found in. So this should be used to find icons
301+ * relating to that desktop file.
302+ *
303+ * Return value: Path to a log file or NULL if unavailable
304+ */
305+gboolean ubuntu_app_launch_application_info (const gchar * appid,
306+ gchar ** appdir,
307+ gchar ** appdesktop);
308+
309+/**
310 * ubuntu_app_launch_observer_add_app_starting:
311 * @observer: (scope notified): Callback when an application is about to start
312 * @user_data: (closure) (allow-none): Data to pass to the observer
313
314=== modified file 'tests/libual-test.cc'
315--- tests/libual-test.cc 2015-08-12 02:52:44 +0000
316+++ tests/libual-test.cc 2015-08-12 02:52:44 +0000
317@@ -1627,3 +1627,45 @@
318
319 ASSERT_TRUE(dbus_test_dbus_mock_object_clear_method_calls(mock, obj, NULL));
320 }
321+
322+TEST_F(LibUAL, AppInfo)
323+{
324+ g_setenv("TEST_CLICK_DB", "click-db-dir", TRUE);
325+ g_setenv("TEST_CLICK_USER", "test-user", TRUE);
326+
327+ char * dir = nullptr;
328+ char * file = nullptr;
329+
330+ /* Basics */
331+ EXPECT_TRUE(ubuntu_app_launch_application_info("com.test.good_application_1.2.3", nullptr, nullptr));
332+ EXPECT_FALSE(ubuntu_app_launch_application_info("com.test.bad_not-app_1.3.3.7", nullptr, nullptr));
333+ EXPECT_FALSE(ubuntu_app_launch_application_info(nullptr, nullptr, nullptr));
334+
335+ /* Ensure false doesn't set the values */
336+ EXPECT_FALSE(ubuntu_app_launch_application_info("com.test.bad_not-app_1.3.3.7", &dir, &file));
337+ EXPECT_EQ(nullptr, dir);
338+ EXPECT_EQ(nullptr, file);
339+ g_clear_pointer(&dir, g_free);
340+ g_clear_pointer(&file, g_free);
341+
342+ /* Correct values from a click */
343+ EXPECT_TRUE(ubuntu_app_launch_application_info("com.test.good_application_1.2.3", &dir, &file));
344+ EXPECT_STREQ(CMAKE_SOURCE_DIR "/click-root-dir/.click/users/test-user/com.test.good", dir);
345+ EXPECT_STREQ("application.desktop", file);
346+ g_clear_pointer(&dir, g_free);
347+ g_clear_pointer(&file, g_free);
348+
349+ /* Correct values from a legacy */
350+ EXPECT_TRUE(ubuntu_app_launch_application_info("bar", &dir, &file));
351+ EXPECT_STREQ(CMAKE_SOURCE_DIR, dir);
352+ EXPECT_STREQ("applications/bar.desktop", file);
353+ g_clear_pointer(&dir, g_free);
354+ g_clear_pointer(&file, g_free);
355+
356+ /* Correct values for libertine */
357+ EXPECT_TRUE(ubuntu_app_launch_application_info("container-name_test_0.0", &dir, &file));
358+ EXPECT_STREQ(CMAKE_SOURCE_DIR "/libertine-data/libertine-container/container-name/rootfs/usr/share", dir);
359+ EXPECT_STREQ("applications/test.desktop", file);
360+ g_clear_pointer(&dir, g_free);
361+ g_clear_pointer(&file, g_free);
362+}

Subscribers

People subscribed via source and target branches