From ed5640d8b587fbcfed7dd7967f3de04b37a76f26 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:06:44 +0200 Subject: Adding upstream version 4:7.4.7. Signed-off-by: Daniel Baumann --- include/vcl/IconThemeInfo.hxx | 98 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 include/vcl/IconThemeInfo.hxx (limited to 'include/vcl/IconThemeInfo.hxx') diff --git a/include/vcl/IconThemeInfo.hxx b/include/vcl/IconThemeInfo.hxx new file mode 100644 index 000000000..0ac2b7dc2 --- /dev/null +++ b/include/vcl/IconThemeInfo.hxx @@ -0,0 +1,98 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef INCLUDED_VCL_ICONTHEMEINFO_HXX +#define INCLUDED_VCL_ICONTHEMEINFO_HXX + +#include +#include +#include + +#include + +// forward declaration of unit test classes. Required for friend relationship. +class IconThemeInfoTest; +class IconThemeSelectorTest; +class IconThemeScannerTest; + +namespace vcl +{ +/** This class provides information about an icon theme. + */ +class VCL_DLLPUBLIC IconThemeInfo +{ +public: + /** The name of the icon theme to use for high contrast mode */ + static constexpr OUStringLiteral HIGH_CONTRAST_ID_BRIGHT = u"sifr"; + static constexpr OUStringLiteral HIGH_CONTRAST_ID_DARK = u"sifr_dark"; + + /** Construct an IconThemeInfo from the URL to a file. + * This method will throw a std::runtime_error if the URL cannot be properly parsed. + * Check the URL with UrlCanBeParsed() first. + */ + IconThemeInfo(const OUString& urlToFile); + + const OUString& GetDisplayName() const { return mDisplayName; } + + const OUString& GetThemeId() const { return mThemeId; } + + const OUString& GetUrlToFile() const { return mUrlToFile; } + + /** Obtain the icon size by theme name. + * @internal + * It is not clear where this information belongs to. The sizes were hard-coded before they moved here. + * Maybe there is a way to determine the sizes from the icon theme packages. + */ + static Size SizeByThemeName(std::u16string_view); + + /** Check whether an IconThemeInfo can be constructed from a URL */ + static bool UrlCanBeParsed(std::u16string_view url); + + /** Find an icon theme by its id in a vector. + * Throws a runtime_error if the theme is not contained in the vector + */ + static const vcl::IconThemeInfo& + FindIconThemeById(const std::vector& themes, const OUString& themeId); + + /** Check whether a theme with a specified id is in a vector of IconThemeInfo */ + static bool IconThemeIsInVector(const std::vector& themes, + const OUString& themeId); + +private: + /** private constructor for testing purposes only */ + IconThemeInfo(); + + /** Determine the icon theme name from the filename + * If the name has an underscore, the name is taken from the first underscore to the last dot, + * e.g., images_oxygen.zip becomes oxygen + * If the name does not have an underscore in it, the whole name until the last dot is returned, + * e.g. default.zip becomes default + */ + static OUString FileNameToThemeId(std::u16string_view); + + /** Creates the display name for the given id of a file. + * Currently, we only uppercase the id. + */ + static OUString ThemeIdToDisplayName(const OUString&); + + /** The name which is presented to the user */ + OUString mDisplayName; + /** The theme id. This id is used in ... to determine the file name */ + OUString mThemeId; + /** The url to the icon theme package */ + OUString mUrlToFile; + + friend class ::IconThemeInfoTest; + friend class ::IconThemeScannerTest; + friend class ::IconThemeSelectorTest; +}; + +} // namespace vcl + +#endif // INCLUDED_VCL_ICONTHEMEINFO_HXX -- cgit v1.2.3