Merge lp:~larryprice/ubuntu-app-launch/humanity-theme-icons into lp:ubuntu-app-launch/16.04

Proposed by Larry Price
Status: Merged
Approved by: Larry Price
Approved revision: 311
Merged at revision: 224
Proposed branch: lp:~larryprice/ubuntu-app-launch/humanity-theme-icons
Merge into: lp:ubuntu-app-launch/16.04
Prerequisite: lp:~larryprice/ubuntu-app-launch/find-theme-icons
Diff against target: 245 lines (+68/-29)
4 files modified
libubuntu-app-launch/application-icon-finder.cpp (+43/-25)
libubuntu-app-launch/application-icon-finder.h (+5/-4)
tests/application-icon-finder.cpp (+7/-0)
tests/data/usr/share/icons/Humanity/index.theme (+13/-0)
To merge this branch: bzr merge lp:~larryprice/ubuntu-app-launch/humanity-theme-icons
Reviewer Review Type Date Requested Status
Ted Gould (community) Approve
Review via email: mp+293818@code.launchpad.net

Commit message

Refactoring IconFinder to include icons from the Humanity theme

Description of the change

Refactoring IconFinder to include icons from the Humanity theme. This will add icons for things like Gedit which don't add icons to hicolor.

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

+1

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 2016-05-04 19:12:07 +0000
3+++ libubuntu-app-launch/application-icon-finder.cpp 2016-05-04 19:12:08 +0000
4@@ -28,7 +28,8 @@
5 {
6 constexpr auto ICONS_DIR = "/icons";
7 constexpr auto HICOLOR_THEME_DIR = "/icons/hicolor";
8-constexpr auto HICOLOR_THEME_FILE = "/icons/hicolor/index.theme";
9+constexpr auto HUMANITY_THEME_DIR = "/icons/Humanity";
10+constexpr auto THEME_INDEX_FILE = "index.theme";
11 constexpr auto APPLICATIONS_TYPE = "Applications";
12 constexpr auto SIZE_PROPERTY = "Size";
13 constexpr auto MAXSIZE_PROPERTY = "MaxSize";
14@@ -126,12 +127,12 @@
15 }
16
17 /** Create a directory item if the directory exists */
18-std::list<IconFinder::ThemeSubdirectory> IconFinder::validDirectories(const std::string& basePath,
19+std::list<IconFinder::ThemeSubdirectory> IconFinder::validDirectories(const std::string& themePath,
20 gchar* directory,
21 int size)
22 {
23 std::list<IconFinder::ThemeSubdirectory> dirs;
24- auto globalHicolorTheme = g_build_filename(basePath.c_str(), HICOLOR_THEME_DIR, directory, nullptr);
25+ auto globalHicolorTheme = g_build_filename(themePath.c_str(), directory, nullptr);
26 if (g_file_test(globalHicolorTheme, G_FILE_TEST_EXISTS))
27 {
28 dirs.emplace_back(ThemeSubdirectory{std::string(globalHicolorTheme), size});
29@@ -144,7 +145,7 @@
30 /** Take the data in a directory stanza and turn it into an actual directory */
31 std::list<IconFinder::ThemeSubdirectory> IconFinder::addSubdirectoryByType(std::shared_ptr<GKeyFile> themefile,
32 gchar* directory,
33- const std::string& basePath)
34+ const std::string& themePath)
35 {
36 GError* error = nullptr;
37 auto gType = g_key_file_get_string(themefile.get(), directory, TYPE_PROPERTY, &error);
38@@ -165,7 +166,7 @@
39 }
40 else
41 {
42- return validDirectories(basePath, directory, size);
43+ return validDirectories(themePath, directory, size);
44 }
45 }
46 else if (type == SCALABLE_CONTEXT)
47@@ -177,7 +178,7 @@
48 }
49 else
50 {
51- return validDirectories(basePath, directory, size);
52+ return validDirectories(themePath, directory, size);
53 }
54 }
55 else if (type == THRESHOLD_CONTEXT)
56@@ -195,7 +196,7 @@
57 threshold = 2; // threshold defaults to 2
58 g_error_free(error);
59 }
60- return validDirectories(basePath, directory, size + threshold);
61+ return validDirectories(themePath, directory, size + threshold);
62 }
63 }
64 return std::list<ThemeSubdirectory>{};
65@@ -204,7 +205,7 @@
66 /** Parse a theme file's various stanzas for each directory */
67 std::list<IconFinder::ThemeSubdirectory> IconFinder::searchIconPaths(std::shared_ptr<GKeyFile> themefile,
68 gchar** directories,
69- const std::string& basePath)
70+ const std::string& themePath)
71 {
72 std::list<ThemeSubdirectory> subdirs;
73 for (auto i = 0; directories[i] != nullptr; ++i)
74@@ -218,7 +219,7 @@
75 }
76 if (g_strcmp0(context, APPLICATIONS_TYPE) == 0)
77 {
78- auto newDirs = addSubdirectoryByType(themefile, directories[i], basePath);
79+ auto newDirs = addSubdirectoryByType(themefile, directories[i], themePath);
80 subdirs.splice(subdirs.end(), newDirs);
81 }
82 g_free(context);
83@@ -226,17 +227,17 @@
84 return subdirs;
85 }
86
87-/** Try to get theme subdirectories using .theme file in the hicolor theme file
88+/** Try to get theme subdirectories using .theme file in the given theme path
89 if it exists */
90-std::list<IconFinder::ThemeSubdirectory> IconFinder::themeFileSearchPaths(const std::string& basePath)
91+std::list<IconFinder::ThemeSubdirectory> IconFinder::themeFileSearchPaths(const std::string& themePath)
92 {
93- std::string themeFilePath = basePath + HICOLOR_THEME_FILE;
94+ auto themeFilePath = g_build_filename(themePath.c_str(), THEME_INDEX_FILE, nullptr);
95 GError* error = nullptr;
96 auto themefile = std::shared_ptr<GKeyFile>(g_key_file_new(), g_key_file_free);
97- g_key_file_load_from_file(themefile.get(), themeFilePath.c_str(), G_KEY_FILE_NONE, &error);
98+ g_key_file_load_from_file(themefile.get(), themeFilePath, G_KEY_FILE_NONE, &error);
99 if (error != nullptr)
100 {
101- g_debug("Unable to find Hicolor theme file: %s", themeFilePath.c_str());
102+ g_debug("Unable to find theme file: %s", themeFilePath);
103 g_error_free(error);
104 return std::list<ThemeSubdirectory>();
105 }
106@@ -246,13 +247,14 @@
107 g_key_file_get_string_list(themefile.get(), ICON_THEME_KEY, DIRECTORIES_PROPERTY, nullptr, &error);
108 if (error != nullptr)
109 {
110- g_debug("Hicolor theme file '%s' didn't have any directories", themeFilePath.c_str());
111+ g_debug("Theme file '%s' didn't have any directories", themeFilePath);
112 g_error_free(error);
113 return std::list<ThemeSubdirectory>();
114 }
115
116- auto iconPaths = searchIconPaths(themefile, directories, basePath);
117+ auto iconPaths = searchIconPaths(themefile, directories, themePath);
118 g_strfreev(directories);
119+ g_free(themeFilePath);
120 return iconPaths;
121 }
122
123@@ -301,20 +303,18 @@
124 return searchPaths;
125 }
126
127-/** Gets all the search paths, from either a theme file or just
128- looking at the directory. And possibly pixmaps as well */
129-std::list<IconFinder::ThemeSubdirectory> IconFinder::getSearchPaths(const std::string& basePath)
130+/** Gets all search paths from a given theme directory via theme file or
131+ manually scanning the directory. */
132+std::list<IconFinder::ThemeSubdirectory> IconFinder::iconsFromThemePath(const gchar* themeDir)
133 {
134 std::list<IconFinder::ThemeSubdirectory> iconPaths;
135-
136- auto hicolorDir = g_build_filename(basePath.c_str(), HICOLOR_THEME_DIR, nullptr);
137- if (g_file_test(hicolorDir, G_FILE_TEST_IS_DIR))
138+ if (g_file_test(themeDir, G_FILE_TEST_IS_DIR))
139 {
140 /* If the directory exists, it could have icons of unknown size */
141- iconPaths.emplace_back(IconFinder::ThemeSubdirectory{hicolorDir, 1});
142+ iconPaths.emplace_back(IconFinder::ThemeSubdirectory{themeDir, 1});
143
144 /* Now see if we can get directories from a theme file */
145- auto themeDirs = themeFileSearchPaths(basePath);
146+ auto themeDirs = themeFileSearchPaths(themeDir);
147 if (themeDirs.size() > 0)
148 {
149 iconPaths.splice(iconPaths.end(), themeDirs);
150@@ -322,12 +322,30 @@
151 else
152 {
153 /* If we didn't get from a theme file, we need to manually scan the directories */
154- auto dirPaths = themeDirSearchPaths(hicolorDir);
155+ auto dirPaths = themeDirSearchPaths(themeDir);
156 iconPaths.splice(iconPaths.end(), dirPaths);
157 }
158 }
159+ return iconPaths;
160+}
161+
162+/** Gets search paths based on common icon directories including themes and pixmaps. */
163+std::list<IconFinder::ThemeSubdirectory> IconFinder::getSearchPaths(const std::string& basePath)
164+{
165+ std::list<IconFinder::ThemeSubdirectory> iconPaths;
166+
167+ /* Icons from the hicolor theme */
168+ auto hicolorDir = g_build_filename(basePath.c_str(), HICOLOR_THEME_DIR, nullptr);
169+ auto hicolorIcons = iconsFromThemePath(hicolorDir);
170+ iconPaths.splice(iconPaths.end(), hicolorIcons);
171 g_free(hicolorDir);
172
173+ /* Icons from the Humanity theme */
174+ auto humanityDir = g_build_filename(basePath.c_str(), HUMANITY_THEME_DIR, nullptr);
175+ auto humanityIcons = iconsFromThemePath(humanityDir);
176+ iconPaths.splice(iconPaths.end(), humanityIcons);
177+ g_free(humanityDir);
178+
179 /* Add root icons directory as potential path */
180 auto iconsPath = g_build_filename(basePath.c_str(), ICONS_DIR, nullptr);
181 if (g_file_test(iconsPath, G_FILE_TEST_IS_DIR))
182
183=== modified file 'libubuntu-app-launch/application-icon-finder.h'
184--- libubuntu-app-launch/application-icon-finder.h 2016-05-04 19:12:07 +0000
185+++ libubuntu-app-launch/application-icon-finder.h 2016-05-04 19:12:08 +0000
186@@ -71,17 +71,18 @@
187 /** \private */
188 static std::string findExistingIcon(const std::string& path, const std::string& iconName);
189 /** \private */
190- static std::list<ThemeSubdirectory> validDirectories(const std::string& basePath, gchar* directory, int size);
191+ static std::list<ThemeSubdirectory> validDirectories(const std::string& themePath, gchar* directory, int size);
192 /** \private */
193 static std::list<ThemeSubdirectory> addSubdirectoryByType(std::shared_ptr<GKeyFile> themefile,
194 gchar* directory,
195- const std::string& basePath);
196+ const std::string& themePath);
197 /** \private */
198 static std::list<ThemeSubdirectory> searchIconPaths(std::shared_ptr<GKeyFile> themefile,
199 gchar** directories,
200- const std::string& basePath);
201- static std::list<ThemeSubdirectory> themeFileSearchPaths(const std::string& basePath);
202+ const std::string& themePath);
203+ static std::list<ThemeSubdirectory> themeFileSearchPaths(const std::string& themePath);
204 static std::list<ThemeSubdirectory> themeDirSearchPaths(const std::string& basePath);
205+ static std::list<IconFinder::ThemeSubdirectory> iconsFromThemePath(const gchar* themeDir);
206 static std::list<ThemeSubdirectory> getSearchPaths(const std::string& basePath);
207 };
208
209
210=== modified file 'tests/application-icon-finder.cpp'
211--- tests/application-icon-finder.cpp 2016-05-04 19:12:07 +0000
212+++ tests/application-icon-finder.cpp 2016-05-04 19:12:08 +0000
213@@ -91,3 +91,10 @@
214 IconFinder finder(basePath);
215 EXPECT_EQ(basePath + "/icons/hicolor/16x16/apps/app3.png", finder.find("app3.png").value());
216 }
217+
218+TEST(ApplicationIconFinder, FindsHumanityIcon)
219+{
220+ auto basePath = std::string(CMAKE_SOURCE_DIR) + "/data/usr/share";
221+ IconFinder finder(basePath);
222+ EXPECT_EQ(basePath + "/icons/Humanity/16x16/apps/gedit.png", finder.find("gedit.png").value());
223+}
224
225=== added directory 'tests/data/usr/share/icons/Humanity'
226=== added directory 'tests/data/usr/share/icons/Humanity/16x16'
227=== added directory 'tests/data/usr/share/icons/Humanity/16x16/apps'
228=== added file 'tests/data/usr/share/icons/Humanity/16x16/apps/gedit.png'
229=== added file 'tests/data/usr/share/icons/Humanity/index.theme'
230--- tests/data/usr/share/icons/Humanity/index.theme 1970-01-01 00:00:00 +0000
231+++ tests/data/usr/share/icons/Humanity/index.theme 2016-05-04 19:12:08 +0000
232@@ -0,0 +1,13 @@
233+[Icon Theme]
234+Directories=16x16/actions,16x16/apps
235+
236+[16x16/actions]
237+Size=16
238+Context=Actions
239+Type=Threshold
240+
241+[16x16/apps]
242+Size=16
243+Context=Applications
244+Type=Threshold
245+

Subscribers

People subscribed via source and target branches