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

Proposed by Ted Gould
Status: Merged
Approved by: Ted Gould
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) Approve
PS Jenkins bot (community) continuous-integration Needs Fixing
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.
Revision history for this message
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)
Revision history for this message
Renato Araujo Oliveira Filho (renatofilho) wrote :

looks good to me.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'debian/libubuntu-app-launch2.symbols'
--- debian/libubuntu-app-launch2.symbols 2015-06-04 20:35:57 +0000
+++ debian/libubuntu-app-launch2.symbols 2015-08-12 02:52:44 +0000
@@ -1,5 +1,6 @@
1libubuntu-app-launch.so.2 libubuntu-app-launch2 #MINVER#1libubuntu-app-launch.so.2 libubuntu-app-launch2 #MINVER#
2 ubuntu_app_launch_app_id_parse@Base 0.42 ubuntu_app_launch_app_id_parse@Base 0.4
3 ubuntu_app_launch_application_info@Base 0replaceme
3 ubuntu_app_launch_application_log_path@Base 0.44 ubuntu_app_launch_application_log_path@Base 0.4
4 ubuntu_app_launch_get_primary_pid@Base 0.45 ubuntu_app_launch_get_primary_pid@Base 0.4
5 ubuntu_app_launch_helper_set_exec@Base 0.5+15.10.201506046 ubuntu_app_launch_helper_set_exec@Base 0.5+15.10.20150604
67
=== modified file 'libubuntu-app-launch/app-info.c'
--- libubuntu-app-launch/app-info.c 2015-08-12 02:52:44 +0000
+++ libubuntu-app-launch/app-info.c 2015-08-12 02:52:44 +0000
@@ -24,8 +24,8 @@
24#include "app-info.h"24#include "app-info.h"
2525
26/* Try and get a manifest and do a couple sanity checks on it */26/* Try and get a manifest and do a couple sanity checks on it */
27static JsonObject *27JsonObject *
28get_manifest (const gchar * pkg)28get_manifest (const gchar * pkg, gchar ** pkgpath)
29{29{
30 /* Get the directory from click */30 /* Get the directory from click */
31 GError * error = NULL;31 GError * error = NULL;
@@ -55,6 +55,16 @@
55 g_object_unref(user);55 g_object_unref(user);
56 return NULL;56 return NULL;
57 }57 }
58
59 if (pkgpath != NULL) {
60 *pkgpath = click_user_get_path(user, pkg, &error);
61 if (error != NULL) {
62 g_warning("Unable to get the Click package directory for %s: %s", pkg, error->message);
63 g_error_free(error);
64 g_object_unref(user);
65 return NULL;
66 }
67 }
58 g_object_unref(user);68 g_object_unref(user);
5969
60 if (!json_object_has_member(manifest, "version")) {70 if (!json_object_has_member(manifest, "version")) {
@@ -93,7 +103,7 @@
93 }103 }
94104
95 if (*manifest == NULL) {105 if (*manifest == NULL) {
96 *manifest = get_manifest(pkg);106 *manifest = get_manifest(pkg, NULL);
97 }107 }
98108
99 JsonObject * hooks = json_object_get_object_member(*manifest, "hooks");109 JsonObject * hooks = json_object_get_object_member(*manifest, "hooks");
@@ -138,7 +148,7 @@
138 return original_ver;148 return original_ver;
139 } else {149 } else {
140 if (*manifest == NULL) {150 if (*manifest == NULL) {
141 *manifest = get_manifest(pkg);151 *manifest = get_manifest(pkg, NULL);
142 }152 }
143 g_return_val_if_fail(*manifest != NULL, NULL);153 g_return_val_if_fail(*manifest != NULL, NULL);
144154
@@ -190,6 +200,53 @@
190 }200 }
191}201}
192202
203/* Look to see if the app id results in a desktop file, if so, fill in the params */
204static gboolean
205evaluate_dir (const gchar * dir, const gchar * desktop, gchar ** appdir, gchar ** appdesktop)
206{
207 char * fulldir = g_build_filename(dir, "applications", desktop, NULL);
208 gboolean found = FALSE;
209
210 if (g_file_test(fulldir, G_FILE_TEST_EXISTS)) {
211 if (appdir != NULL) {
212 *appdir = g_strdup(dir);
213 }
214
215 if (appdesktop != NULL) {
216 *appdesktop = g_strdup_printf("applications/%s", desktop);
217 }
218
219 found = TRUE;
220 }
221
222 g_free(fulldir);
223 return found;
224}
225
226/* Handle the legacy case where we look through the data directories */
227gboolean
228app_info_legacy (const gchar * appid, gchar ** appdir, gchar ** appdesktop)
229{
230 gchar * desktop = g_strdup_printf("%s.desktop", appid);
231
232 /* Special case the user's dir */
233 if (evaluate_dir(g_get_user_data_dir(), desktop, appdir, appdesktop)) {
234 g_free(desktop);
235 return TRUE;
236 }
237
238 const char * const * data_dirs = g_get_system_data_dirs();
239 int i;
240 for (i = 0; data_dirs[i] != NULL; i++) {
241 if (evaluate_dir(data_dirs[i], desktop, appdir, appdesktop)) {
242 g_free(desktop);
243 return TRUE;
244 }
245 }
246
247 return FALSE;
248}
249
193/* Handle the libertine case where we look in the container */250/* Handle the libertine case where we look in the container */
194gboolean251gboolean
195app_info_libertine (const gchar * appid, gchar ** appdir, gchar ** appdesktop)252app_info_libertine (const gchar * appid, gchar ** appdir, gchar ** appdesktop)
@@ -225,21 +282,73 @@
225 }282 }
226 }283 }
227284
285 if (appdir != NULL) {
286 *appdir = desktopdir;
287 } else {
288 g_free(desktopdir);
289 }
290
291 if (appdesktop != NULL) {
292 *appdesktop = g_build_filename("applications", desktopname, NULL);
293 }
294
295 g_free(desktopfile);
228 g_free(desktopname);296 g_free(desktopname);
229 g_free(container);297 g_free(container);
230 g_free(app);298 g_free(app);
231299
232 if (appdir != NULL) {300 return TRUE;
233 *appdir = desktopdir;301}
234 } else {302
235 g_free(desktopdir);303/* Get the information on where the desktop file is from libclick */
236 }304gboolean
305app_info_click (const gchar * appid, gchar ** appdir, gchar ** appdesktop)
306{
307 gchar * package = NULL;
308 gchar * application = NULL;
309
310 if (!ubuntu_app_launch_app_id_parse(appid, &package, &application, NULL)) {
311 return FALSE;
312 }
313
314 JsonObject * manifest = get_manifest(package, appdir);
315 if (manifest == NULL) {
316 g_free(package);
317 g_free(application);
318 return FALSE;
319 }
320
321 g_free(package);
237322
238 if (appdesktop != NULL) {323 if (appdesktop != NULL) {
239 *appdesktop = desktopfile;324 JsonObject * hooks = json_object_get_object_member(manifest, "hooks");
325 if (hooks == NULL) {
326 json_object_unref(manifest);
327 g_free(application);
328 return FALSE;
329 }
330
331 JsonObject * appobj = json_object_get_object_member(hooks, application);
332 g_free(application);
333
334 if (appobj == NULL) {
335 json_object_unref(manifest);
336 return FALSE;
337 }
338
339 const gchar * desktop = json_object_get_string_member(appobj, "desktop");
340 if (desktop == NULL) {
341 json_object_unref(manifest);
342 return FALSE;
343 }
344
345 *appdesktop = g_strdup(desktop);
240 } else {346 } else {
241 g_free(desktopfile);347 g_free(application);
242 }348 }
243349
350 json_object_unref(manifest);
351
244 return TRUE;352 return TRUE;
245}353}
354
246355
=== modified file 'libubuntu-app-launch/app-info.h'
--- libubuntu-app-launch/app-info.h 2015-08-12 02:52:44 +0000
+++ libubuntu-app-launch/app-info.h 2015-08-12 02:52:44 +0000
@@ -21,7 +21,9 @@
2121
22#include <glib.h>22#include <glib.h>
2323
24gboolean app_info_legacy (const gchar * appid, gchar ** appdir, gchar ** appdesktop);
24gboolean app_info_libertine (const gchar * appid, gchar ** appdir, gchar ** appdesktop);25gboolean app_info_libertine (const gchar * appid, gchar ** appdir, gchar ** appdesktop);
26gboolean app_info_click (const gchar * appid, gchar ** appdir, gchar ** appdesktop);
2527
26gchar * click_triplet_to_app_id (const gchar * pkg, const gchar * app, const gchar * ver);28gchar * click_triplet_to_app_id (const gchar * pkg, const gchar * app, const gchar * ver);
27gchar * libertine_triplet_to_app_id (const gchar * pkg, const gchar * app, const gchar * ver);29gchar * libertine_triplet_to_app_id (const gchar * pkg, const gchar * app, const gchar * ver);
2830
=== modified file 'libubuntu-app-launch/desktop-exec.c'
--- libubuntu-app-launch/desktop-exec.c 2015-08-12 02:52:44 +0000
+++ libubuntu-app-launch/desktop-exec.c 2015-08-12 02:52:44 +0000
@@ -80,28 +80,34 @@
80keyfile_for_libertine (const gchar * appid, gchar ** outcontainer)80keyfile_for_libertine (const gchar * appid, gchar ** outcontainer)
81{81{
82 gchar * desktopfile = NULL;82 gchar * desktopfile = NULL;
83 gchar * desktopdir = NULL;
8384
84 if (!app_info_libertine(appid, NULL, &desktopfile)) {85 if (!app_info_libertine(appid, &desktopdir, &desktopfile)) {
85 return NULL;86 return NULL;
86 }87 }
8788
89 gchar * desktopfull = g_build_filename(desktopdir, desktopfile, NULL);
90 g_debug("Desktop full: %s", desktopfull);
91 g_free(desktopdir);
92 g_free(desktopfile);
93
88 /* We now think we have a valid 'desktopfile' path */94 /* We now think we have a valid 'desktopfile' path */
89 GKeyFile * keyfile = g_key_file_new();95 GKeyFile * keyfile = g_key_file_new();
90 gboolean loaded = g_key_file_load_from_file(keyfile, desktopfile, G_KEY_FILE_NONE, NULL);96 gboolean loaded = g_key_file_load_from_file(keyfile, desktopfull, G_KEY_FILE_NONE, NULL);
9197
92 if (!loaded) {98 if (!loaded) {
93 g_free(desktopfile);99 g_free(desktopfull);
94 g_key_file_free(keyfile);100 g_key_file_free(keyfile);
95 return NULL;101 return NULL;
96 }102 }
97103
98 if (!verify_keyfile(keyfile, desktopfile)) {104 if (!verify_keyfile(keyfile, desktopfull)) {
99 g_free(desktopfile);105 g_free(desktopfull);
100 g_key_file_free(keyfile);106 g_key_file_free(keyfile);
101 return NULL;107 return NULL;
102 }108 }
103109
104 g_free(desktopfile);110 g_free(desktopfull);
105111
106 if (outcontainer != NULL) {112 if (outcontainer != NULL) {
107 ubuntu_app_launch_app_id_parse(appid, outcontainer, NULL, NULL);113 ubuntu_app_launch_app_id_parse(appid, outcontainer, NULL, NULL);
108114
=== modified file 'libubuntu-app-launch/ubuntu-app-launch.c'
--- libubuntu-app-launch/ubuntu-app-launch.c 2015-08-12 02:52:44 +0000
+++ libubuntu-app-launch/ubuntu-app-launch.c 2015-08-12 02:52:44 +0000
@@ -748,6 +748,18 @@
748 return path;748 return path;
749}749}
750750
751gboolean
752ubuntu_app_launch_application_info (const gchar * appid, gchar ** appdir, gchar ** appdesktop)
753{
754 if (is_click(appid)) {
755 return app_info_click(appid, appdir, appdesktop);
756 } else if (is_libertine(appid)) {
757 return app_info_libertine(appid, appdir, appdesktop);
758 } else {
759 return app_info_legacy(appid, appdir, appdesktop);
760 }
761}
762
751static GDBusConnection *763static GDBusConnection *
752gdbus_upstart_ref (void) {764gdbus_upstart_ref (void) {
753 static GDBusConnection * gdbus_upstart = NULL;765 static GDBusConnection * gdbus_upstart = NULL;
754766
=== modified file 'libubuntu-app-launch/ubuntu-app-launch.h'
--- libubuntu-app-launch/ubuntu-app-launch.h 2015-06-04 20:22:27 +0000
+++ libubuntu-app-launch/ubuntu-app-launch.h 2015-08-12 02:52:44 +0000
@@ -142,6 +142,22 @@
142gchar * ubuntu_app_launch_application_log_path (const gchar * appid);142gchar * ubuntu_app_launch_application_log_path (const gchar * appid);
143143
144/**144/**
145 * ubuntu_app_launch_application_info:
146 * @appid: ID of the application
147 * @appdir: (allow-none) (transfer full): Directory for the application
148 * @appdesktop: (allow-none) (transfer full): Relative path to desktop file
149 *
150 * Finds a location for information on an application and the relative
151 * directory that it was found in. So this should be used to find icons
152 * relating to that desktop file.
153 *
154 * Return value: Path to a log file or NULL if unavailable
155 */
156gboolean ubuntu_app_launch_application_info (const gchar * appid,
157 gchar ** appdir,
158 gchar ** appdesktop);
159
160/**
145 * ubuntu_app_launch_observer_add_app_starting:161 * ubuntu_app_launch_observer_add_app_starting:
146 * @observer: (scope notified): Callback when an application is about to start162 * @observer: (scope notified): Callback when an application is about to start
147 * @user_data: (closure) (allow-none): Data to pass to the observer163 * @user_data: (closure) (allow-none): Data to pass to the observer
148164
=== modified file 'tests/libual-test.cc'
--- tests/libual-test.cc 2015-08-12 02:52:44 +0000
+++ tests/libual-test.cc 2015-08-12 02:52:44 +0000
@@ -1627,3 +1627,45 @@
16271627
1628 ASSERT_TRUE(dbus_test_dbus_mock_object_clear_method_calls(mock, obj, NULL));1628 ASSERT_TRUE(dbus_test_dbus_mock_object_clear_method_calls(mock, obj, NULL));
1629}1629}
1630
1631TEST_F(LibUAL, AppInfo)
1632{
1633 g_setenv("TEST_CLICK_DB", "click-db-dir", TRUE);
1634 g_setenv("TEST_CLICK_USER", "test-user", TRUE);
1635
1636 char * dir = nullptr;
1637 char * file = nullptr;
1638
1639 /* Basics */
1640 EXPECT_TRUE(ubuntu_app_launch_application_info("com.test.good_application_1.2.3", nullptr, nullptr));
1641 EXPECT_FALSE(ubuntu_app_launch_application_info("com.test.bad_not-app_1.3.3.7", nullptr, nullptr));
1642 EXPECT_FALSE(ubuntu_app_launch_application_info(nullptr, nullptr, nullptr));
1643
1644 /* Ensure false doesn't set the values */
1645 EXPECT_FALSE(ubuntu_app_launch_application_info("com.test.bad_not-app_1.3.3.7", &dir, &file));
1646 EXPECT_EQ(nullptr, dir);
1647 EXPECT_EQ(nullptr, file);
1648 g_clear_pointer(&dir, g_free);
1649 g_clear_pointer(&file, g_free);
1650
1651 /* Correct values from a click */
1652 EXPECT_TRUE(ubuntu_app_launch_application_info("com.test.good_application_1.2.3", &dir, &file));
1653 EXPECT_STREQ(CMAKE_SOURCE_DIR "/click-root-dir/.click/users/test-user/com.test.good", dir);
1654 EXPECT_STREQ("application.desktop", file);
1655 g_clear_pointer(&dir, g_free);
1656 g_clear_pointer(&file, g_free);
1657
1658 /* Correct values from a legacy */
1659 EXPECT_TRUE(ubuntu_app_launch_application_info("bar", &dir, &file));
1660 EXPECT_STREQ(CMAKE_SOURCE_DIR, dir);
1661 EXPECT_STREQ("applications/bar.desktop", file);
1662 g_clear_pointer(&dir, g_free);
1663 g_clear_pointer(&file, g_free);
1664
1665 /* Correct values for libertine */
1666 EXPECT_TRUE(ubuntu_app_launch_application_info("container-name_test_0.0", &dir, &file));
1667 EXPECT_STREQ(CMAKE_SOURCE_DIR "/libertine-data/libertine-container/container-name/rootfs/usr/share", dir);
1668 EXPECT_STREQ("applications/test.desktop", file);
1669 g_clear_pointer(&dir, g_free);
1670 g_clear_pointer(&file, g_free);
1671}

Subscribers

People subscribed via source and target branches