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

Proposed by Didier Roche on 2011-08-08
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) 2011-08-08 Approve on 2011-08-10
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.
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
1=== modified file 'plugins/unityshell/src/FavoriteStoreGSettings.cpp'
2--- plugins/unityshell/src/FavoriteStoreGSettings.cpp 2011-07-29 03:33:08 +0000
3+++ plugins/unityshell/src/FavoriteStoreGSettings.cpp 2011-08-08 08:47:26 +0000
4@@ -54,8 +54,6 @@
5
6 std::string get_basename_or_path(std::string const& desktop_path);
7
8-char* exhaustive_desktopfile_lookup(char* desktop_file);
9-
10 }
11
12 FavoriteStoreGSettings::FavoriteStoreGSettings()
13@@ -137,19 +135,8 @@
14 }
15 else
16 {
17- LOG_INFO(logger) << "Unable to load GDesktopAppInfo for '"
18+ LOG_WARNING(logger) << "Unable to load GDesktopAppInfo for '"
19 << favs[i] << "'";
20- glib::String exhaustive_path(exhaustive_desktopfile_lookup(favs[i]));
21- if (exhaustive_path.Value() == NULL)
22- {
23- LOG_WARNING(logger) << "Desktop file '"
24- << favs[i]
25- << "' does not exist anywhere we can find it";
26- }
27- else
28- {
29- favorites_.push_back(exhaustive_path.Str());
30- }
31 }
32 }
33 }
34@@ -297,118 +284,23 @@
35 for (int i = 0; dirs[i]; ++i)
36 {
37 std::string dir(dirs[i]);
38+ if (dir.at(dir.length()-1) == G_DIR_SEPARATOR)
39+ dir.append("applications/");
40+ else
41+ dir.append("/applications/");
42
43 if (desktop_path.find(dir) == 0)
44 {
45- // Would prefer boost::filesystem here.
46- glib::String basename(g_path_get_basename(desktop_path.c_str()));
47- return basename.Str();
48+ // if we are in a subdirectory of system patch, the store name should
49+ // be subdir-filename.desktop
50+ std::string desktop_suffix = desktop_path.substr(dir.size());
51+ std::replace(desktop_suffix.begin(), desktop_suffix.end(), G_DIR_SEPARATOR, '-');
52+ return desktop_suffix;
53 }
54 }
55 return desktop_path;
56 }
57
58-/* If the desktop file exists, we *will* find it dang it
59- * Returns null if we failed =(
60- *
61- * Most of this code copied from bamf - its nice to have this
62- * agree with bamf at the very least
63- */
64-char* exhaustive_desktopfile_lookup(char* desktop_file)
65-{
66- GFile* file;
67- GFileInfo* info;
68- GFileEnumerator* enumerator;
69- GList* dirs = NULL, *l;
70- const char* env;
71- char* path;
72- char* subpath;
73- char** data_dirs = NULL;
74- char** data;
75-
76- env = g_getenv("XDG_DATA_DIRS");
77-
78- if (env)
79- {
80- data_dirs = g_strsplit(env, ":", 0);
81-
82- for (data = data_dirs; *data; data++)
83- {
84- path = g_build_filename(*data, "applications", NULL);
85- if (g_file_test(path, G_FILE_TEST_IS_DIR))
86- dirs = g_list_prepend(dirs, path);
87- else
88- g_free(path);
89- }
90- }
91-
92- if (!g_list_find_custom(dirs, "/usr/share/applications", (GCompareFunc) g_strcmp0))
93- dirs = g_list_prepend(dirs, g_strdup("/usr/share/applications"));
94-
95- if (!g_list_find_custom(dirs, "/usr/local/share/applications", (GCompareFunc) g_strcmp0))
96- dirs = g_list_prepend(dirs, g_strdup("/usr/local/share/applications"));
97-
98- dirs = g_list_prepend(dirs, g_strdup(g_build_filename(g_get_home_dir(), ".share/applications", NULL)));
99-
100- if (data_dirs)
101- g_strfreev(data_dirs);
102-
103- /* include subdirs */
104- for (l = dirs; l; l = l->next)
105- {
106- path = (char*)l->data;
107-
108- file = g_file_new_for_path(path);
109-
110- if (!g_file_query_exists(file, NULL))
111- {
112- g_object_unref(file);
113- continue;
114- }
115-
116- enumerator = g_file_enumerate_children(file,
117- "standard::*",
118- G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
119- NULL,
120- NULL);
121-
122- if (!enumerator)
123- continue;
124-
125- info = g_file_enumerator_next_file(enumerator, NULL, NULL);
126- for (; info; info = g_file_enumerator_next_file(enumerator, NULL, NULL))
127- {
128- if (g_file_info_get_file_type(info) != G_FILE_TYPE_DIRECTORY)
129- continue;
130-
131- subpath = g_build_filename(path, g_file_info_get_name(info), NULL);
132- /* append for non-recursive recursion love */
133- dirs = g_list_append(dirs, subpath);
134-
135- g_object_unref(info);
136- }
137-
138- g_object_unref(enumerator);
139- g_object_unref(file);
140- }
141-
142- /* dirs now contains a list if lookup directories */
143- /* go through the dir list and stat to check it exists */
144- path = NULL;
145- for (l = dirs; l; l = l->next)
146- {
147- path = g_build_filename((char*)l->data, desktop_file, NULL);
148- if (g_file_test(path, G_FILE_TEST_EXISTS))
149- break;
150-
151- g_free(path);
152- path = NULL;
153- }
154-
155- g_list_free(dirs);
156-
157- return path;
158-}
159
160 } // anonymous namespace
161