1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
10 #include <comphelper/lok.hxx>
12 #include <vcl/IconThemeSelector.hxx>
14 #include <vcl/IconThemeInfo.hxx>
15 #include <config_mpl.h>
21 /*static*/ const OUStringLiteral
IconThemeSelector::FALLBACK_ICON_THEME_ID("tango");
28 const OUString
& m_rThemeId
;
30 explicit SameTheme(const OUString
&rThemeId
) : m_rThemeId(rThemeId
) {}
31 bool operator()(const vcl::IconThemeInfo
&rInfo
)
33 return m_rThemeId
== rInfo
.GetThemeId();
37 bool icon_theme_is_in_installed_themes(const OUString
& theme
,
38 const std::vector
<IconThemeInfo
>& installedThemes
)
40 return std::any_of(installedThemes
.begin(), installedThemes
.end(),
44 } // end anonymous namespace
46 IconThemeSelector::IconThemeSelector()
47 : mUseHighContrastTheme(false)
48 , mPreferDarkIconTheme(false)
53 IconThemeSelector::GetIconThemeForDesktopEnvironment(const OUString
& desktopEnvironment
)
55 if (comphelper::LibreOfficeKit::isActive())
59 (void)desktopEnvironment
;
63 if ( desktopEnvironment
.equalsIgnoreAsciiCase("plasma5") ||
64 desktopEnvironment
.equalsIgnoreAsciiCase("lxqt") ) {
67 else if ( desktopEnvironment
.equalsIgnoreAsciiCase("macosx") ) {
74 else if ( desktopEnvironment
.equalsIgnoreAsciiCase("gnome") ||
75 desktopEnvironment
.equalsIgnoreAsciiCase("mate") ||
76 desktopEnvironment
.equalsIgnoreAsciiCase("unity") ) {
80 r
= FALLBACK_ICON_THEME_ID
;
87 IconThemeSelector::SelectIconThemeForDesktopEnvironment(
88 const std::vector
<IconThemeInfo
>& installedThemes
,
89 const OUString
& desktopEnvironment
) const
91 if (!mPreferredIconTheme
.isEmpty()) {
92 if (icon_theme_is_in_installed_themes(mPreferredIconTheme
, installedThemes
)) {
93 return mPreferredIconTheme
;
95 //if a dark variant is preferred, and we didn't have an exact match, then try our one and only dark theme
96 if (mPreferDarkIconTheme
&& icon_theme_is_in_installed_themes("breeze_dark", installedThemes
)) {
101 OUString themeForDesktop
= GetIconThemeForDesktopEnvironment(desktopEnvironment
);
102 if (icon_theme_is_in_installed_themes(themeForDesktop
, installedThemes
)) {
103 return themeForDesktop
;
106 return ReturnFallback(installedThemes
);
110 IconThemeSelector::SelectIconTheme(
111 const std::vector
<IconThemeInfo
>& installedThemes
,
112 const OUString
& theme
) const
114 if (mUseHighContrastTheme
) {
115 if (icon_theme_is_in_installed_themes(IconThemeInfo::HIGH_CONTRAST_ID
, installedThemes
)) {
116 return IconThemeInfo::HIGH_CONTRAST_ID
;
120 if (icon_theme_is_in_installed_themes(theme
, installedThemes
)) {
124 return ReturnFallback(installedThemes
);
128 IconThemeSelector::SetUseHighContrastTheme(bool v
)
130 mUseHighContrastTheme
= v
;
134 IconThemeSelector::SetPreferredIconTheme(const OUString
& theme
, bool bDarkIconTheme
)
136 // lower case theme name, and (tdf#120175) replace - with _
137 // see icon-themes/README
138 mPreferredIconTheme
= theme
.toAsciiLowerCase().replace('-','_');
139 mPreferDarkIconTheme
= bDarkIconTheme
;
143 IconThemeSelector::operator==(const vcl::IconThemeSelector
& other
) const
145 if (this == &other
) {
148 if (mPreferredIconTheme
!= other
.mPreferredIconTheme
) {
151 if (mPreferDarkIconTheme
!= other
.mPreferDarkIconTheme
) {
154 if (mUseHighContrastTheme
!= other
.mUseHighContrastTheme
) {
161 IconThemeSelector::operator!=(const vcl::IconThemeSelector
& other
) const
163 return !(*this == other
);
167 IconThemeSelector::ReturnFallback(const std::vector
<IconThemeInfo
>& installedThemes
)
169 if (!installedThemes
.empty()) {
170 return installedThemes
.front().GetThemeId();
173 return FALLBACK_ICON_THEME_ID
;
177 } /* namespace vcl */
179 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */