Avoid potential negative array index access to cached text.
[LibreOffice.git] / vcl / inc / IconThemeSelector.hxx
blob65bfdf006364738330af70793d6371965fcf5fb0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #ifndef INCLUDED_VCL_ICONTHEMESELECTOR_HXX
11 #define INCLUDED_VCL_ICONTHEMESELECTOR_HXX
13 #include <rtl/ustring.hxx>
15 #include <vcl/dllapi.h>
17 #include <vector>
19 // forward declaration of unit test class. Required for friend relationship.
20 class IconThemeSelectorTest;
22 namespace vcl {
23 class IconThemeInfo;
25 /** This class helps to choose an icon theme from a list of installed themes.
27 * The following factors influence the selection:
28 * -# When high contrast mode is enabled, the high contrast icon theme is selected (if it is installed).
29 * -# When a preferred theme has been set (e.g., in the gnome desktop settings), that theme is selected.
31 class VCL_DLLPUBLIC IconThemeSelector {
32 public:
33 IconThemeSelector();
35 /** Select an icon theme from the list of installed themes.
37 * If high contrast mode has been enabled, the highcontrast theme will be selected (if it is available).
39 * @pre
40 * @p installedThemes must not be empty
42 OUString
43 SelectIconTheme(
44 const std::vector<IconThemeInfo>& installedThemes,
45 const OUString& theme
46 ) const;
48 /** Select the standard icon theme for a desktop environment from a list of installed themes.
50 * If a preferred theme has been set, this one will take precedence.
52 * The same logic as in SelectIconTheme() will apply.
54 * @pre
55 * @p installedThemes must not be empty
57 OUString
58 SelectIconThemeForDesktopEnvironment(
59 const std::vector<IconThemeInfo>& installedThemes,
60 const OUString& desktopEnvironment) const;
62 void
63 SetUseHighContrastTheme(bool);
65 /** Returns true if the PreferredIconTheme was changed */
66 bool
67 SetPreferredIconTheme(const OUString&, bool bDarkIconTheme);
69 bool
70 operator==(const vcl::IconThemeSelector&) const;
72 bool
73 operator!=(const vcl::IconThemeSelector&) const;
75 private:
76 /** Return the first element of the themes, or the fallback if the vector is empty */
77 static OUString
78 ReturnFallback(const std::vector<IconThemeInfo>& installedThemes);
80 /** The name of the icon themes which are used as fallbacks */
81 static constexpr OUString FALLBACK_LIGHT_ICON_THEME_ID = u"colibre"_ustr;
82 static constexpr OUString FALLBACK_DARK_ICON_THEME_ID = u"colibre_dark"_ustr;
84 static OUString
85 GetIconThemeForDesktopEnvironment(const OUString& desktopEnvironment, bool bPreferDarkIconTheme);
87 OUString mPreferredIconTheme;
88 bool mUseHighContrastTheme;
89 bool mPreferDarkIconTheme;
91 friend class ::IconThemeSelectorTest;
94 } /* namespace vcl */
96 #endif // INCLUDED_VCL_ICONTHEMESELECTOR_HXX
98 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */