Merge lp:~larryprice/ubuntu-app-launch/better-icon-themes into lp:ubuntu-app-launch

Proposed by Larry Price
Status: Merged
Approved by: Michael Terry
Approved revision: 298
Merged at revision: 298
Proposed branch: lp:~larryprice/ubuntu-app-launch/better-icon-themes
Merge into: lp:ubuntu-app-launch
Diff against target: 156 lines (+62/-39)
1 file modified
libubuntu-app-launch/application-icon-finder.cpp (+62/-39)
To merge this branch: bzr merge lp:~larryprice/ubuntu-app-launch/better-icon-themes
Reviewer Review Type Date Requested Status
Michael Terry Approve
Review via email: mp+319358@code.launchpad.net

Commit message

Add all icon directories to search paths regardless of context.

Description of the change

Add all icon directories to search paths regardless of context. Also add a couple more default themes, and fix the "manual" search method.

To post a comment you must log in.
296. By Larry Price

gnome

297. By Larry Price

format

298. By Larry Price

reorder themes and add suru

Revision history for this message
Michael Terry (mterry) wrote :

Looks good to me. I tested it and it now shows an icon for all apps that declare one! Thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libubuntu-app-launch/application-icon-finder.cpp'
2--- libubuntu-app-launch/application-icon-finder.cpp 2017-01-10 18:41:25 +0000
3+++ libubuntu-app-launch/application-icon-finder.cpp 2017-03-08 18:12:23 +0000
4@@ -27,10 +27,8 @@
5 namespace
6 {
7 constexpr auto ICONS_DIR = "/icons";
8-constexpr auto HICOLOR_THEME_DIR = "/icons/hicolor";
9-constexpr auto HUMANITY_THEME_DIR = "/icons/Humanity";
10+constexpr auto ICON_THEMES = {"suru", "Humanity", "Adwaita", "gnome", "hicolor"};
11 constexpr auto THEME_INDEX_FILE = "index.theme";
12-constexpr auto APPLICATIONS_TYPE = "Applications";
13 constexpr auto SIZE_PROPERTY = "Size";
14 constexpr auto MAXSIZE_PROPERTY = "MaxSize";
15 constexpr auto THRESHOLD_PROPERTY = "Threshold";
16@@ -45,7 +43,8 @@
17 constexpr auto ICON_TYPES = {".png", ".svg", ".xpm"};
18 constexpr auto METAGUI_PATH = "/meta/gui";
19
20-static const std::regex iconSizeDirname = std::regex("^(\\d+)x\\1$");
21+static const std::regex ICON_SIZE_DIRNAME = std::regex("^(\\d+)x\\1$");
22+static const std::regex SCALABLE_WITH_REGEX = std::regex("^scalable-up-to-(\\d+)$");
23 } // anonymous namespace
24
25 IconFinder::IconFinder(std::string basePath)
26@@ -218,11 +217,10 @@
27 g_error_free(error);
28 continue;
29 }
30- if (g_strcmp0(context, APPLICATIONS_TYPE) == 0)
31- {
32- auto newDirs = addSubdirectoryByType(themefile, directories[i], themePath);
33- subdirs.splice(subdirs.end(), newDirs);
34- }
35+
36+ auto newDirs = addSubdirectoryByType(themefile, directories[i], themePath);
37+ subdirs.splice(subdirs.end(), newDirs);
38+
39 g_free(context);
40 }
41 return subdirs;
42@@ -260,7 +258,7 @@
43 }
44
45 /** Look into a theme directory and see if we can use the subdirectories
46- as icon folders. Sadly inefficient. */
47+ as icon folders. This is a fallback, and is sadly inefficient. */
48 std::list<IconFinder::ThemeSubdirectory> IconFinder::themeDirSearchPaths(const std::string& themeDir)
49 {
50 std::list<IconFinder::ThemeSubdirectory> searchPaths;
51@@ -277,27 +275,56 @@
52 const gchar* dirname = nullptr;
53 while ((dirname = g_dir_read_name(gdir)) != nullptr)
54 {
55- auto fullPath = g_build_filename(themeDir.c_str(), dirname, "apps", nullptr);
56- /* Directories only */
57- if (g_file_test(fullPath, G_FILE_TEST_IS_DIR))
58+ /* Iterate over size-based directories */
59+ auto sizePath = g_build_filename(themeDir.c_str(), dirname, nullptr);
60+ if (g_file_test(sizePath, G_FILE_TEST_IS_DIR))
61 {
62- if (g_strcmp0(dirname, "scalable") == 0)
63- {
64- /* We don't really know what to do with scalable here, let's
65- call them 256 images */
66- searchPaths.emplace_back(IconFinder::ThemeSubdirectory{fullPath, 256});
67- continue;
68- }
69-
70 std::smatch match;
71 std::string dirstr(dirname);
72- /* We want it to match and have the same values for the first and second size */
73- if (std::regex_match(dirstr, match, iconSizeDirname))
74- {
75- searchPaths.emplace_back(IconFinder::ThemeSubdirectory{fullPath, std::atoi(match[1].str().c_str())});
76- }
77+ int size;
78+ if (std::regex_match(dirstr, match, ICON_SIZE_DIRNAME))
79+ {
80+ size = std::atoi(match[1].str().c_str());
81+ }
82+ else if (g_strcmp0(dirname, "scalable") == 0)
83+ {
84+ /* We don't really know what to do with scalable icons, let's
85+ call them 256 images */
86+ size = 256;
87+ }
88+ else
89+ {
90+ /* Some directories are "scalable with", meaning that they
91+ are meant to be used up to a certain size */
92+ std::smatch scalablewith;
93+ if (std::regex_match(dirstr, scalablewith, SCALABLE_WITH_REGEX))
94+ {
95+ size = std::atoi(scalablewith[1].str().c_str());
96+ }
97+ else
98+ {
99+ /* Otherwise we don't know what to do with this dir,
100+ ignore for now */
101+ g_free(sizePath);
102+ continue;
103+ }
104+ }
105+
106+ auto subdir = g_dir_open(sizePath, 0, &error);
107+ const gchar* subdirname = nullptr;
108+ while ((subdirname = g_dir_read_name(subdir)) != nullptr)
109+ {
110+ auto fullPath = g_build_filename(sizePath, subdirname, nullptr);
111+ if (g_file_test(fullPath, G_FILE_TEST_IS_DIR))
112+ {
113+ searchPaths.emplace_back(IconFinder::ThemeSubdirectory{fullPath, size});
114+ }
115+
116+ g_free(fullPath);
117+ }
118+ g_dir_close(subdir);
119 }
120- g_free(fullPath);
121+ g_free(sizePath);
122 }
123
124 g_dir_close(gdir);
125@@ -335,17 +362,13 @@
126 {
127 std::list<IconFinder::ThemeSubdirectory> iconPaths;
128
129- /* Icons from the hicolor theme */
130- auto hicolorDir = g_build_filename(basePath.c_str(), HICOLOR_THEME_DIR, nullptr);
131- auto hicolorIcons = iconsFromThemePath(hicolorDir);
132- iconPaths.splice(iconPaths.end(), hicolorIcons);
133- g_free(hicolorDir);
134-
135- /* Icons from the Humanity theme */
136- auto humanityDir = g_build_filename(basePath.c_str(), HUMANITY_THEME_DIR, nullptr);
137- auto humanityIcons = iconsFromThemePath(humanityDir);
138- iconPaths.splice(iconPaths.end(), humanityIcons);
139- g_free(humanityDir);
140+ for (const auto& theme : ICON_THEMES)
141+ {
142+ auto dir = g_build_filename(basePath.c_str(), ICONS_DIR, theme, nullptr);
143+ auto icons = iconsFromThemePath(dir);
144+ iconPaths.splice(iconPaths.end(), icons);
145+ g_free(dir);
146+ }
147
148 /* Add root icons directory as potential path */
149 auto iconsPath = g_build_filename(basePath.c_str(), ICONS_DIR, nullptr);
150@@ -379,5 +402,5 @@
151 return iconPaths;
152 }
153
154-} // namesapce app_launch
155+} // namespace app_launch
156 } // namespace ubuntu

Subscribers

People subscribed via source and target branches