Merge lp:~didrocks/unity/fix_store_kde4_apps into lp:unity

Proposed by Didier Roche-Tolomelli
Status: Merged
Merged at revision: 1359
Proposed branch: lp:~didrocks/unity/fix_store_kde4_apps
Merge into: lp:unity
Diff against target: 160 lines (+10/-118)
1 file modified
plugins/unityshell/src/FavoriteStoreGSettings.cpp (+10/-118)
To merge this branch: bzr merge lp:~didrocks/unity/fix_store_kde4_apps
Reviewer Review Type Date Requested Status
Neil J. Patel (community) Approve
Review via email: mp+70704@code.launchpad.net

Description of the change

Fix and store in the right way the kde apps:
- don't look at subdirectories for them.
- gio is opening them in subdir-desktopname.desktop format (LP: #741129)
Note that some initialization and replace could be store later in the init()
function to avoid too many replaces (even if this function is not called a lot
and it's still way better than stating each subdir)

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

Approved as discussed.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'plugins/unityshell/src/FavoriteStoreGSettings.cpp'
--- plugins/unityshell/src/FavoriteStoreGSettings.cpp 2011-07-29 03:33:08 +0000
+++ plugins/unityshell/src/FavoriteStoreGSettings.cpp 2011-08-08 08:47:26 +0000
@@ -54,8 +54,6 @@
5454
55std::string get_basename_or_path(std::string const& desktop_path);55std::string get_basename_or_path(std::string const& desktop_path);
5656
57char* exhaustive_desktopfile_lookup(char* desktop_file);
58
59}57}
6058
61FavoriteStoreGSettings::FavoriteStoreGSettings()59FavoriteStoreGSettings::FavoriteStoreGSettings()
@@ -137,19 +135,8 @@
137 }135 }
138 else136 else
139 {137 {
140 LOG_INFO(logger) << "Unable to load GDesktopAppInfo for '"138 LOG_WARNING(logger) << "Unable to load GDesktopAppInfo for '"
141 << favs[i] << "'";139 << favs[i] << "'";
142 glib::String exhaustive_path(exhaustive_desktopfile_lookup(favs[i]));
143 if (exhaustive_path.Value() == NULL)
144 {
145 LOG_WARNING(logger) << "Desktop file '"
146 << favs[i]
147 << "' does not exist anywhere we can find it";
148 }
149 else
150 {
151 favorites_.push_back(exhaustive_path.Str());
152 }
153 }140 }
154 }141 }
155 }142 }
@@ -297,118 +284,23 @@
297 for (int i = 0; dirs[i]; ++i)284 for (int i = 0; dirs[i]; ++i)
298 {285 {
299 std::string dir(dirs[i]);286 std::string dir(dirs[i]);
287 if (dir.at(dir.length()-1) == G_DIR_SEPARATOR)
288 dir.append("applications/");
289 else
290 dir.append("/applications/");
300291
301 if (desktop_path.find(dir) == 0)292 if (desktop_path.find(dir) == 0)
302 {293 {
303 // Would prefer boost::filesystem here.294 // if we are in a subdirectory of system patch, the store name should
304 glib::String basename(g_path_get_basename(desktop_path.c_str()));295 // be subdir-filename.desktop
305 return basename.Str();296 std::string desktop_suffix = desktop_path.substr(dir.size());
297 std::replace(desktop_suffix.begin(), desktop_suffix.end(), G_DIR_SEPARATOR, '-');
298 return desktop_suffix;
306 }299 }
307 }300 }
308 return desktop_path;301 return desktop_path;
309}302}
310303
311/* If the desktop file exists, we *will* find it dang it
312 * Returns null if we failed =(
313 *
314 * Most of this code copied from bamf - its nice to have this
315 * agree with bamf at the very least
316 */
317char* exhaustive_desktopfile_lookup(char* desktop_file)
318{
319 GFile* file;
320 GFileInfo* info;
321 GFileEnumerator* enumerator;
322 GList* dirs = NULL, *l;
323 const char* env;
324 char* path;
325 char* subpath;
326 char** data_dirs = NULL;
327 char** data;
328
329 env = g_getenv("XDG_DATA_DIRS");
330
331 if (env)
332 {
333 data_dirs = g_strsplit(env, ":", 0);
334
335 for (data = data_dirs; *data; data++)
336 {
337 path = g_build_filename(*data, "applications", NULL);
338 if (g_file_test(path, G_FILE_TEST_IS_DIR))
339 dirs = g_list_prepend(dirs, path);
340 else
341 g_free(path);
342 }
343 }
344
345 if (!g_list_find_custom(dirs, "/usr/share/applications", (GCompareFunc) g_strcmp0))
346 dirs = g_list_prepend(dirs, g_strdup("/usr/share/applications"));
347
348 if (!g_list_find_custom(dirs, "/usr/local/share/applications", (GCompareFunc) g_strcmp0))
349 dirs = g_list_prepend(dirs, g_strdup("/usr/local/share/applications"));
350
351 dirs = g_list_prepend(dirs, g_strdup(g_build_filename(g_get_home_dir(), ".share/applications", NULL)));
352
353 if (data_dirs)
354 g_strfreev(data_dirs);
355
356 /* include subdirs */
357 for (l = dirs; l; l = l->next)
358 {
359 path = (char*)l->data;
360
361 file = g_file_new_for_path(path);
362
363 if (!g_file_query_exists(file, NULL))
364 {
365 g_object_unref(file);
366 continue;
367 }
368
369 enumerator = g_file_enumerate_children(file,
370 "standard::*",
371 G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
372 NULL,
373 NULL);
374
375 if (!enumerator)
376 continue;
377
378 info = g_file_enumerator_next_file(enumerator, NULL, NULL);
379 for (; info; info = g_file_enumerator_next_file(enumerator, NULL, NULL))
380 {
381 if (g_file_info_get_file_type(info) != G_FILE_TYPE_DIRECTORY)
382 continue;
383
384 subpath = g_build_filename(path, g_file_info_get_name(info), NULL);
385 /* append for non-recursive recursion love */
386 dirs = g_list_append(dirs, subpath);
387
388 g_object_unref(info);
389 }
390
391 g_object_unref(enumerator);
392 g_object_unref(file);
393 }
394
395 /* dirs now contains a list if lookup directories */
396 /* go through the dir list and stat to check it exists */
397 path = NULL;
398 for (l = dirs; l; l = l->next)
399 {
400 path = g_build_filename((char*)l->data, desktop_file, NULL);
401 if (g_file_test(path, G_FILE_TEST_EXISTS))
402 break;
403
404 g_free(path);
405 path = NULL;
406 }
407
408 g_list_free(dirs);
409
410 return path;
411}
412304
413} // anonymous namespace305} // anonymous namespace
414306