Merge lp:~larryprice/ubuntu-app-launch/recursive-desktop-files into lp:ubuntu-app-launch/16.10

Proposed by Larry Price
Status: Rejected
Rejected by: Ted Gould
Proposed branch: lp:~larryprice/ubuntu-app-launch/recursive-desktop-files
Merge into: lp:ubuntu-app-launch/16.10
Diff against target: 520 lines (+179/-208)
8 files modified
libubuntu-app-launch/app-info.c (+94/-72)
libubuntu-app-launch/application-impl-base.cpp (+26/-0)
libubuntu-app-launch/application-impl-base.h (+2/-0)
libubuntu-app-launch/application-impl-legacy.cpp (+19/-63)
libubuntu-app-launch/application-impl-legacy.h (+0/-4)
libubuntu-app-launch/application-impl-libertine.cpp (+23/-68)
tests/libual-cpp-test.cc (+8/-1)
tests/libual-test.cc (+7/-0)
To merge this branch: bzr merge lp:~larryprice/ubuntu-app-launch/recursive-desktop-files
Reviewer Review Type Date Requested Status
Ted Gould (community) Needs Fixing
Review via email: mp+302029@code.launchpad.net

Commit message

Recursively sweep for desktop files for libertine and legacy applications.

Description of the change

Recursively sweep for desktop files for libertine and legacy applications.

Goes hand-in-hand with an update to liblibertine which finds desktop files recursively https://code.launchpad.net/~larryprice/libertine/recurse-apps-dir.

To post a comment you must log in.
Revision history for this message
Ted Gould (ted) wrote :

So I think this branch is gonna break when it gets merged with:

https://code.launchpad.net/~ted/ubuntu-app-launch/snappy-backend-no-snap/+merge/302025

As it removes the app-info.h file. The goal generally is to have that C code go away and be replaced with C++ code. I think that will restructure things a bunch. Also you forgot to include test-nested.desktop.

review: Needs Fixing
236. By Larry Price

adding nested

Unmerged revisions

236. By Larry Price

adding nested

235. By Larry Price

Quick tests to verify nested keyfiles are now being accepted

234. By Larry Price

moving keyfileFromPath to parent to reduce code dup

233. By Larry Price

Same treatment for legacy apps

232. By Larry Price

Updating Libertine ctor to find correct desktop file

231. By Larry Price

updating app-info to recursively find legacy apps

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'libubuntu-app-launch/app-info.c'
--- libubuntu-app-launch/app-info.c 2015-08-12 02:52:05 +0000
+++ libubuntu-app-launch/app-info.c 2016-08-04 14:10:59 +0000
@@ -200,27 +200,67 @@
200 }200 }
201}201}
202202
203/* Look to see if the app id results in a desktop file, if so, fill in the params */
204static gboolean203static gboolean
205evaluate_dir (const gchar * dir, const gchar * desktop, gchar ** appdir, gchar ** appdesktop)204find_desktop_file (const gchar * base_path, const gchar * rel_path, const gchar * desktop_file, gchar ** appdesktop)
206{205{
207 char * fulldir = g_build_filename(dir, "applications", desktop, NULL);206 gchar* full_path = g_build_filename(base_path, rel_path, NULL);
208 gboolean found = FALSE;207 gchar* full_filename = g_build_filename(full_path, desktop_file, NULL);
209208
210 if (g_file_test(fulldir, G_FILE_TEST_EXISTS)) {209 if (g_file_test(full_filename, G_FILE_TEST_IS_REGULAR)) {
211 if (appdir != NULL) {210 if (appdesktop != NULL) {
212 *appdir = g_strdup(dir);211 *appdesktop = g_build_filename(rel_path, desktop_file, NULL);
213 }212 }
214213
215 if (appdesktop != NULL) {214 g_free(full_filename);
216 *appdesktop = g_strdup_printf("applications/%s", desktop);215 g_free(full_path);
217 }216 return TRUE;
218217 }
219 found = TRUE;218 g_free(full_filename);
220 }219
221220 GError* error = NULL;
222 g_free(fulldir);221 GDir* dir = g_dir_open(full_path, 0, &error);
223 return found;222 if (error != NULL) {
223 g_error_free(error);
224 g_free(full_path);
225 return FALSE;
226 }
227
228 const gchar* files;
229 while ((files = g_dir_read_name(dir)) != NULL)
230 {
231 gchar* file = g_build_filename(full_path, files, NULL);
232 if (g_file_test(file, G_FILE_TEST_IS_DIR))
233 {
234 gchar* file_rel_path = g_build_filename(rel_path, files, NULL);
235 if (find_desktop_file(base_path, file_rel_path, desktop_file, appdesktop))
236 {
237 g_free(file_rel_path);
238 g_free(file);
239 g_free(dir);
240 g_free(full_path);
241 return TRUE;
242 }
243 g_free(file_rel_path);
244 }
245 g_free(file);
246 }
247
248 g_free(dir);
249 g_free(full_path);
250
251 return FALSE;
252}
253
254gboolean
255find_app_info (const gchar * base_path, const gchar * desktop_file, gchar ** appdir, gchar ** appdesktop)
256{
257 if (find_desktop_file(base_path, "applications", desktop_file, appdesktop)) {
258 if (appdir != NULL) {
259 *appdir = g_strdup(base_path);
260 }
261 return TRUE;
262 }
263 return FALSE;
224}264}
225265
226/* Handle the legacy case where we look through the data directories */266/* Handle the legacy case where we look through the data directories */
@@ -228,22 +268,20 @@
228app_info_legacy (const gchar * appid, gchar ** appdir, gchar ** appdesktop)268app_info_legacy (const gchar * appid, gchar ** appdir, gchar ** appdesktop)
229{269{
230 gchar * desktop = g_strdup_printf("%s.desktop", appid);270 gchar * desktop = g_strdup_printf("%s.desktop", appid);
231271 if (find_app_info(g_get_user_data_dir(), desktop, appdir, appdesktop)) {
232 /* Special case the user's dir */272 g_free(desktop);
233 if (evaluate_dir(g_get_user_data_dir(), desktop, appdir, appdesktop)) {273 return TRUE;
234 g_free(desktop);274 }
235 return TRUE;275
236 }276 const char * const * data_dirs = g_get_system_data_dirs();
237277 for (int i = 0; data_dirs[i] != NULL; i++) {
238 const char * const * data_dirs = g_get_system_data_dirs();278 if (find_app_info(data_dirs[i], desktop, appdir, appdesktop)) {
239 int i;279 g_free(desktop);
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;280 return TRUE;
244 }281 }
245 }282 }
246283
284 g_free(desktop);
247 return FALSE;285 return FALSE;
248}286}
249287
@@ -259,45 +297,29 @@
259 }297 }
260298
261 gchar * desktopname = g_strdup_printf("%s.desktop", app);299 gchar * desktopname = g_strdup_printf("%s.desktop", app);
262300 g_free(app);
263 gchar * desktopdir = g_build_filename(g_get_user_cache_dir(), "libertine-container", container, "rootfs", "usr", "share", NULL);301
264 gchar * desktopfile = g_build_filename(desktopdir, "applications", desktopname, NULL);302 gchar * system_dir = g_build_filename(g_get_user_cache_dir(), "libertine-container", container, "rootfs", "usr", "share", NULL);
265303 if (find_app_info(system_dir, desktopname, appdir, appdesktop)) {
266 if (!g_file_test(desktopfile, G_FILE_TEST_EXISTS)) {304 g_free(system_dir);
267 g_free(desktopdir);305 g_free(desktopname);
268 g_free(desktopfile);306 g_free(container);
269307 return TRUE;
270 desktopdir = g_build_filename(g_get_user_data_dir(), "libertine-container", "user-data", container, ".local", "share", NULL);308 }
271 desktopfile = g_build_filename(desktopdir, "applications", desktopname, NULL);309 g_free(system_dir);
272310
273 if (!g_file_test(desktopfile, G_FILE_TEST_EXISTS)) {311 gchar * user_dir = g_build_filename(g_get_user_data_dir(), "libertine-container", "user-data", container, ".local", "share", NULL);
274 g_free(desktopdir);312 if (find_app_info(user_dir, desktopname, appdir, appdesktop)) {
275 g_free(desktopfile);313 g_free(user_dir);
276314 g_free(desktopname);
277 g_free(desktopname);315 g_free(container);
278 g_free(container);316 return TRUE;
279 g_free(app);317 }
280318 g_free(user_dir);
281 return FALSE;319 g_free(desktopname);
282 }320 g_free(container);
283 }321
284322 return FALSE;
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);
296 g_free(desktopname);
297 g_free(container);
298 g_free(app);
299
300 return TRUE;
301}323}
302324
303/* Get the information on where the desktop file is from libclick */325/* Get the information on where the desktop file is from libclick */
304326
=== modified file 'libubuntu-app-launch/application-impl-base.cpp'
--- libubuntu-app-launch/application-impl-base.cpp 2016-02-09 22:12:32 +0000
+++ libubuntu-app-launch/application-impl-base.cpp 2016-08-04 14:10:59 +0000
@@ -157,6 +157,32 @@
157 return std::make_shared<BaseInstance>(appIdStr);157 return std::make_shared<BaseInstance>(appIdStr);
158}158}
159159
160std::shared_ptr<GKeyFile> Base::keyfileFromPath(const gchar* pathname)
161{
162 if (!g_file_test(pathname, G_FILE_TEST_EXISTS))
163 {
164 return {};
165 }
166
167 std::shared_ptr<GKeyFile> keyfile(g_key_file_new(), [](GKeyFile* keyfile) {
168 if (keyfile != nullptr)
169 {
170 g_key_file_free(keyfile);
171 }
172 });
173 GError* error = nullptr;
174
175 g_key_file_load_from_file(keyfile.get(), pathname, G_KEY_FILE_NONE, &error);
176
177 if (error != nullptr)
178 {
179 g_error_free(error);
180 return {};
181 }
182
183 return keyfile;
184}
185
160}; // namespace app_impls186}; // namespace app_impls
161}; // namespace app_launch187}; // namespace app_launch
162}; // namespace ubuntu188}; // namespace ubuntu
163189
=== modified file 'libubuntu-app-launch/application-impl-base.h'
--- libubuntu-app-launch/application-impl-base.h 2016-02-09 22:12:32 +0000
+++ libubuntu-app-launch/application-impl-base.h 2016-08-04 14:10:59 +0000
@@ -45,6 +45,8 @@
4545
46protected:46protected:
47 std::shared_ptr<Registry> _registry;47 std::shared_ptr<Registry> _registry;
48
49 static std::shared_ptr<GKeyFile> keyfileFromPath(const gchar* pathname);
48};50};
4951
50}; // namespace app_impls52}; // namespace app_impls
5153
=== modified file 'libubuntu-app-launch/application-impl-legacy.cpp'
--- libubuntu-app-launch/application-impl-legacy.cpp 2016-05-02 13:59:09 +0000
+++ libubuntu-app-launch/application-impl-legacy.cpp 2016-08-04 14:10:59 +0000
@@ -19,6 +19,10 @@
1919
20#include "application-impl-legacy.h"20#include "application-impl-legacy.h"
21#include "application-info-desktop.h"21#include "application-info-desktop.h"
22extern "C"
23{
24#include "app-info.h"
25}
2226
23namespace ubuntu27namespace ubuntu
24{28{
@@ -27,77 +31,29 @@
27namespace app_impls31namespace app_impls
28{32{
2933
30std::pair<std::string, std::shared_ptr<GKeyFile>> keyfileForApp(const AppID::AppName& name);
31
32void clear_keyfile(GKeyFile* keyfile)
33{
34 if (keyfile != nullptr)
35 {
36 g_key_file_free(keyfile);
37 }
38}
39
40Legacy::Legacy(const AppID::AppName& appname,
41 const std::string& basedir,
42 const std::shared_ptr<GKeyFile>& keyfile,
43 const std::shared_ptr<Registry>& registry)
44 : Base(registry)
45 , _appname(appname)
46 , _basedir(basedir)
47 , _keyfile(keyfile)
48{
49 if (!_keyfile)
50 throw std::runtime_error{"Unable to find keyfile for legacy application: " + appname.value()};
51}
52
53Legacy::Legacy(const AppID::AppName& appname, const std::shared_ptr<Registry>& registry)34Legacy::Legacy(const AppID::AppName& appname, const std::shared_ptr<Registry>& registry)
54 : Base(registry)35 : Base(registry)
55 , _appname(appname)36 , _appname(appname)
56{37{
57 std::tie(_basedir, _keyfile) = keyfileForApp(appname);38 gchar* basedir = NULL;
39 gchar* keyfile = NULL;
40 if (!app_info_legacy(appname.value().c_str(), &basedir, &keyfile))
41 {
42 throw std::runtime_error{"Unable to find keyfile for legacy application: " + appname.value()};
43 }
44
45 _basedir = basedir;
46 gchar* full_filename = g_build_filename(basedir, keyfile, nullptr);
47 _keyfile = keyfileFromPath(full_filename);
48
49 g_free(full_filename);
50 g_free(keyfile);
51 g_free(basedir);
5852
59 if (!_keyfile)53 if (!_keyfile)
54 {
60 throw std::runtime_error{"Unable to find keyfile for legacy application: " + appname.value()};55 throw std::runtime_error{"Unable to find keyfile for legacy application: " + appname.value()};
61}
62
63std::pair<std::string, std::shared_ptr<GKeyFile>> keyfileForApp(const AppID::AppName& name)
64{
65 std::string desktopName = name.value() + ".desktop";
66 auto keyfilecheck = [desktopName](const std::string& dir) -> std::shared_ptr<GKeyFile> {
67 auto fullname = g_build_filename(dir.c_str(), "applications", desktopName.c_str(), nullptr);
68 if (!g_file_test(fullname, G_FILE_TEST_EXISTS))
69 {
70 g_free(fullname);
71 return {};
72 }
73
74 auto keyfile = std::shared_ptr<GKeyFile>(g_key_file_new(), clear_keyfile);
75
76 GError* error = nullptr;
77 g_key_file_load_from_file(keyfile.get(), fullname, G_KEY_FILE_NONE, &error);
78 g_free(fullname);
79
80 if (error != nullptr)
81 {
82 g_debug("Unable to load keyfile '%s' becuase: %s", desktopName.c_str(), error->message);
83 g_error_free(error);
84 return {};
85 }
86
87 return keyfile;
88 };
89
90 std::string basedir = g_get_user_data_dir();
91 auto retval = keyfilecheck(basedir);
92
93 auto systemDirs = g_get_system_data_dirs();
94 for (auto i = 0; !retval && systemDirs[i] != nullptr; i++)
95 {
96 basedir = systemDirs[i];
97 retval = keyfilecheck(basedir);
98 }56 }
99
100 return std::make_pair(basedir, retval);
101}57}
10258
103std::shared_ptr<Application::Info> Legacy::info()59std::shared_ptr<Application::Info> Legacy::info()
10460
=== modified file 'libubuntu-app-launch/application-impl-legacy.h'
--- libubuntu-app-launch/application-impl-legacy.h 2016-05-02 13:47:11 +0000
+++ libubuntu-app-launch/application-impl-legacy.h 2016-08-04 14:10:59 +0000
@@ -34,10 +34,6 @@
34{34{
35public:35public:
36 Legacy(const AppID::AppName& appname, const std::shared_ptr<Registry>& registry);36 Legacy(const AppID::AppName& appname, const std::shared_ptr<Registry>& registry);
37 Legacy(const AppID::AppName& appname,
38 const std::string& basedir,
39 const std::shared_ptr<GKeyFile>& keyfile,
40 const std::shared_ptr<Registry>& registry);
4137
42 AppID appId() override38 AppID appId() override
43 {39 {
4440
=== modified file 'libubuntu-app-launch/application-impl-libertine.cpp'
--- libubuntu-app-launch/application-impl-libertine.cpp 2016-05-02 15:16:29 +0000
+++ libubuntu-app-launch/application-impl-libertine.cpp 2016-08-04 14:10:59 +0000
@@ -19,7 +19,11 @@
1919
20#include "application-impl-libertine.h"20#include "application-impl-libertine.h"
21#include "application-info-desktop.h"21#include "application-info-desktop.h"
22#include "libertine.h"22extern "C"
23{
24#include "app-info.h"
25}
26#include <libertine.h>
2327
24namespace ubuntu28namespace ubuntu
25{29{
@@ -28,8 +32,6 @@
28namespace app_impls32namespace app_impls
29{33{
3034
31std::shared_ptr<GKeyFile> keyfileFromPath(const gchar* pathname);
32
33Libertine::Libertine(const AppID::Package& container,35Libertine::Libertine(const AppID::Package& container,
34 const AppID::AppName& appname,36 const AppID::AppName& appname,
35 const std::shared_ptr<Registry>& registry)37 const std::shared_ptr<Registry>& registry)
@@ -37,73 +39,26 @@
37 , _container(container)39 , _container(container)
38 , _appname(appname)40 , _appname(appname)
39{41{
40 if (!_keyfile)42 gchar* basedir = NULL;
41 {43 gchar* keyfile = NULL;
42 auto container_path = libertine_container_path(container.value().c_str());44 if (!app_info_libertine(ubuntu_app_launch_triplet_to_app_id(container.value().c_str(), appname.value().c_str(), "0.0"), &basedir, &keyfile))
43 auto container_app_path = g_build_filename(container_path, "usr", "share", "applications",45 {
44 (appname.value() + ".desktop").c_str(), nullptr);46 throw std::runtime_error{"Unable to find a keyfile for application '" + appname.value() + "' in container '" +
4547 container.value() + "'"};
46 _keyfile = keyfileFromPath(container_app_path);48 }
4749 _basedir = basedir;
48 if (_keyfile)50 gchar* full_filename = g_build_filename(basedir, keyfile, nullptr);
49 {51 _keyfile = keyfileFromPath(full_filename);
50 auto gbasedir = g_build_filename(container_path, "usr", "share", nullptr);52
51 _basedir = gbasedir;53 g_free(full_filename);
52 g_free(gbasedir);54 g_free(keyfile);
53 }55 g_free(basedir);
5456
55 g_free(container_app_path);57 if (!_keyfile)
56 g_free(container_path);58 {
57 }
58
59 if (!_keyfile)
60 {
61 auto home_path = libertine_container_home_path(container.value().c_str());
62 auto home_app_path = g_build_filename(home_path, ".local", "share", "applications",
63 (appname.value() + ".desktop").c_str(), NULL);
64
65 _keyfile = keyfileFromPath(home_app_path);
66
67 if (_keyfile)
68 {
69 auto gbasedir = g_build_filename(home_path, ".local", "share", nullptr);
70 _basedir = gbasedir;
71 g_free(gbasedir);
72 }
73
74 g_free(home_app_path);
75 g_free(home_path);
76 }
77
78 if (!_keyfile)
79 throw std::runtime_error{"Unable to find a keyfile for application '" + appname.value() + "' in container '" +59 throw std::runtime_error{"Unable to find a keyfile for application '" + appname.value() + "' in container '" +
80 container.value() + "'"};60 container.value() + "'"};
81}61 }
82
83std::shared_ptr<GKeyFile> keyfileFromPath(const gchar* pathname)
84{
85 if (!g_file_test(pathname, G_FILE_TEST_EXISTS))
86 {
87 return {};
88 }
89
90 std::shared_ptr<GKeyFile> keyfile(g_key_file_new(), [](GKeyFile* keyfile) {
91 if (keyfile != nullptr)
92 {
93 g_key_file_free(keyfile);
94 }
95 });
96 GError* error = nullptr;
97
98 g_key_file_load_from_file(keyfile.get(), pathname, G_KEY_FILE_NONE, &error);
99
100 if (error != nullptr)
101 {
102 g_error_free(error);
103 return {};
104 }
105
106 return keyfile;
107}62}
10863
109std::list<std::shared_ptr<Application>> Libertine::list(const std::shared_ptr<Registry>& registry)64std::list<std::shared_ptr<Application>> Libertine::list(const std::shared_ptr<Registry>& registry)
11065
=== modified file 'tests/libual-cpp-test.cc'
--- tests/libual-cpp-test.cc 2016-04-27 14:22:00 +0000
+++ tests/libual-cpp-test.cc 2016-08-04 14:10:59 +0000
@@ -1596,6 +1596,13 @@
15961596
1597 auto info = libertine->info();1597 auto info = libertine->info();
1598 EXPECT_TRUE((bool)info);1598 EXPECT_TRUE((bool)info);
1599
1600 EXPECT_EQ("Test", info->name().value());1599 EXPECT_EQ("Test", info->name().value());
1600
1601 /* Correct values for nested libertine */
1602 auto nestedid = ubuntu::app_launch::AppID::parse("container-name_test-nested_0.0");
1603 auto nested = ubuntu::app_launch::Application::create(libertineid, registry);
1604
1605 auto nestedinfo = nested->info();
1606 EXPECT_TRUE((bool)info);
1607 EXPECT_EQ("Test Nested", info->name().value());
1601}1608}
16021609
=== modified file 'tests/libual-test.cc'
--- tests/libual-test.cc 2015-12-18 17:21:20 +0000
+++ tests/libual-test.cc 2016-08-04 14:10:59 +0000
@@ -1667,4 +1667,11 @@
1667 EXPECT_STREQ("applications/test.desktop", file);1667 EXPECT_STREQ("applications/test.desktop", file);
1668 g_clear_pointer(&dir, g_free);1668 g_clear_pointer(&dir, g_free);
1669 g_clear_pointer(&file, g_free);1669 g_clear_pointer(&file, g_free);
1670
1671 /* Correct values for nested libertine */
1672 EXPECT_TRUE(ubuntu_app_launch_application_info("container-name_test-nested_0.0", &dir, &file));
1673 EXPECT_STREQ(CMAKE_SOURCE_DIR "/libertine-data/libertine-container/container-name/rootfs/usr/share", dir);
1674 EXPECT_STREQ("applications/nested/test-nested.desktop", file);
1675 g_clear_pointer(&dir, g_free);
1676 g_clear_pointer(&file, g_free);
1670}1677}

Subscribers

People subscribed via source and target branches