Fcitx
icontheme.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2017-2017 CSSlayer <wengxt@gmail.com>
3  *
4  * SPDX-License-Identifier: LGPL-2.1-or-later
5  *
6  */
7 #ifndef _FCITX_UTILS_ICONTHEME_H_
8 #define _FCITX_UTILS_ICONTHEME_H_
9 
10 #include <filesystem>
11 #include <memory>
12 #include <string>
13 #include <vector>
14 #include <fcitx-config/enum.h>
15 #include <fcitx-config/rawconfig.h>
16 #include <fcitx-utils/i18nstring.h>
17 #include <fcitx-utils/macros.h>
18 #include <fcitx-utils/misc.h>
20 #include <fcitx/fcitxcore_export.h>
21 
22 /// \addtogroup FcitxCore
23 /// \{
24 /// \file
25 /// \brief XDG icon specification helper.
26 
27 namespace fcitx {
28 
29 class IconThemeDirectoryPrivate;
30 class IconThemePrivate;
31 class StandardPath;
32 
33 FCITX_CONFIG_ENUM(IconThemeDirectoryType, Fixed, Scalable, Threshold);
34 
35 class FCITXCORE_EXPORT IconThemeDirectory {
36 public:
37  IconThemeDirectory(const RawConfig &config = RawConfig());
38  FCITX_DECLARE_VIRTUAL_DTOR_COPY_AND_MOVE(IconThemeDirectory);
39 
40  FCITX_DECLARE_READ_ONLY_PROPERTY(std::string, path);
41  FCITX_DECLARE_READ_ONLY_PROPERTY(int, size);
42  FCITX_DECLARE_READ_ONLY_PROPERTY(int, scale);
43  FCITX_DECLARE_READ_ONLY_PROPERTY(std::string, context);
44  FCITX_DECLARE_READ_ONLY_PROPERTY(IconThemeDirectoryType, type);
45  FCITX_DECLARE_READ_ONLY_PROPERTY(int, maxSize);
46  FCITX_DECLARE_READ_ONLY_PROPERTY(int, minSize);
47  FCITX_DECLARE_READ_ONLY_PROPERTY(int, threshold);
48 
49  bool matchesSize(int iconsize, int iconscale) const;
50  int sizeDistance(int iconsize, int iconscale) const;
51 
52 private:
53  std::unique_ptr<IconThemeDirectoryPrivate> d_ptr;
54  FCITX_DECLARE_PRIVATE(IconThemeDirectory);
55 };
56 
57 /// \brief A implementation of freedesktop.org icont specification.
58 class FCITXCORE_EXPORT IconTheme {
59  friend class IconThemePrivate;
60 
61 public:
62  IconTheme(const char *name, const StandardPath &standardPath)
63  : IconTheme(std::string(name), standardPath) {}
64  IconTheme(const std::string &name, const StandardPath &standardPath);
65  IconTheme(const StandardPath &standardPath);
66 
67  IconTheme(const std::string &name,
68  const StandardPaths &standardPath = StandardPaths::global());
69  IconTheme(const StandardPaths &standardPath = StandardPaths::global());
70  FCITX_DECLARE_VIRTUAL_DTOR_MOVE(IconTheme);
71 
72  // FIXME: remove non-const version when we can break ABI.
73  FCITXCORE_DEPRECATED std::string findIcon(
74  const std::string &iconName, unsigned int desiredSize, int scale = 1,
75  const std::vector<std::string> &extensions = {".svg", ".png", ".xpm"});
76  FCITXCORE_DEPRECATED std::string
77  findIcon(const std::string &iconName, unsigned int desiredSize,
78  int scale = 1,
79  const std::vector<std::string> &extensions = {".svg", ".png",
80  ".xpm"}) const;
81 
82  std::filesystem::path
83  findIconPath(const std::string &iconName, unsigned int desiredSize,
84  int scale = 1,
85  const std::vector<std::string> &extensions = {".svg", ".png",
86  ".xpm"}) const;
87  static std::string defaultIconThemeName();
88 
89  FCITX_DECLARE_READ_ONLY_PROPERTY(std::string, internalName);
90  FCITX_DECLARE_READ_ONLY_PROPERTY(I18NString, name);
91  FCITX_DECLARE_READ_ONLY_PROPERTY(I18NString, comment);
92  FCITX_DECLARE_READ_ONLY_PROPERTY(std::vector<IconTheme>, inherits);
93  FCITX_DECLARE_READ_ONLY_PROPERTY(std::vector<IconThemeDirectory>,
94  directories);
95  FCITX_DECLARE_READ_ONLY_PROPERTY(std::vector<IconThemeDirectory>,
96  scaledDirectories);
97  FCITX_DECLARE_READ_ONLY_PROPERTY(std::string, example);
98 
99  /// Rename fcitx-* icon to org.fcitx.Fcitx5.fcitx-* if in flatpak
100  static std::string iconName(const std::string &icon,
101  bool inFlatpak = isInFlatpak());
102 
103 private:
104  IconTheme(const std::string &name, IconTheme *parent,
105  const StandardPath &standardPath);
106  IconTheme(const std::string &name, IconTheme *parent,
107  const StandardPaths &standardPath);
108 
109  std::unique_ptr<IconThemePrivate> d_ptr;
110  FCITX_DECLARE_PRIVATE(IconTheme);
111 };
112 } // namespace fcitx
113 
114 #endif // _FCITX_UTILS_ICONTHEME_H_
static const StandardPaths & global()
Return the global instance of StandardPath.
Definition: action.cpp:17
New Utility classes to handle application specific path.
A implementation of freedesktop.org icont specification.
Definition: icontheme.h:58
Utility class to open, locate, list files based on XDG standard.
Definition: standardpath.h:181