Debian Codegraph @

liblomiri-app-launch/application-icon-finder.h

raw
1 /*
2 * Copyright © 2016 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors:
17 * Larry Price <[email protected]>
18 */
19
20 #pragma once
21
22 #include "application-info-desktop.h"
23 #include <glib.h>
24 #include <list>
25 #include <map>
26 #include <memory>
27
28 namespace lomiri
29 {
30 namespace app_launch
31 {
32 /** \brief Class to search for available application icons and select the best option.
33
34 This object attempts to find the highest resolution icon based on the freedesktop icon
35 theme specification found at:
36 https://standards.freedesktop.org/icon-theme-spec/icon-theme-spec-latest.html
37 It parses the theme file for the hicolor theme and identifies all possible directories
38 in the global scope and the local scope.
39 */
40 class IconFinder
41 {
42 public:
43 /** Create an IconFinder
44
45 \param basePath the root directory to begin searching for themes
46 */
47 explicit IconFinder(std::string basePath);
48 virtual ~IconFinder() = default;
49
50 /** Find the optimal icon for the given icon name.
51
52 \param iconName name of or path to application icon
53 */
54 virtual Application::Info::IconPath find(const std::string& iconName);
55
56 private:
57 /** \private */
58 struct ThemeSubdirectory
59 {
60 std::string path;
61 int size;
62 };
63
64 /** \private */
65 std::list<ThemeSubdirectory> _searchPaths;
66 /** \private */
67 std::string _basePath;
68
69 /** \private */
70 static bool hasImageExtension(const char* filename);
71 /** \private */
72 static std::string findExistingIcon(const std::string& path, const std::string& iconName);
73 /** \private */
74 static std::list<ThemeSubdirectory> validDirectories(const std::string& themePath, gchar* directory, int size);
75 /** \private */
76 static std::list<ThemeSubdirectory> addSubdirectoryByType(std::shared_ptr<GKeyFile> themefile,
77 gchar* directory,
78 const std::string& themePath);
79 /** \private */
80 static std::list<ThemeSubdirectory> searchIconPaths(std::shared_ptr<GKeyFile> themefile,
81 gchar** directories,
82 const std::string& themePath);
83 static std::list<ThemeSubdirectory> themeFileSearchPaths(const std::string& themePath);
84 static std::list<ThemeSubdirectory> themeDirSearchPaths(const std::string& basePath);
85 static std::list<IconFinder::ThemeSubdirectory> iconsFromThemePath(const gchar* themeDir);
86 static std::list<ThemeSubdirectory> getSearchPaths(const std::string& basePath);
87 };
88
89 } // namespace app_launch
90 } // namesapce lomiri