diff options
author | Tobias Lippert <drtl@fastmail.fm> | 2014-02-09 00:53:28 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2014-02-21 17:23:50 +0000 |
commit | 076a7eacca48f203f0a8b9aa537e88fea9a88409 (patch) | |
tree | cd95446ac0b80b29658fa2a44030dacb5304a63d /include/vcl | |
parent | 1ec263e25d8606c70ac2089d5ceea22750d25daf (diff) |
Bug #63962 Dynamically scan the config directory for icon themes
The hard-coded icon themes have been replaced by a dynamic list
which is filled by scanning the config directory
Conflicts:
include/vcl/settings.hxx
vcl/source/app/settings.cxx
vcl/source/window/window.cxx
Change-Id: Ie3680ffe27d06e375acf22753e036cb6ddabc4ed
Reviewed-on: https://gerrit.libreoffice.org/7935
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'include/vcl')
-rw-r--r-- | include/vcl/IconThemeInfo.hxx | 97 | ||||
-rw-r--r-- | include/vcl/IconThemeScanner.hxx | 103 | ||||
-rw-r--r-- | include/vcl/IconThemeSelector.hxx | 101 | ||||
-rw-r--r-- | include/vcl/settings.hxx | 116 | ||||
-rw-r--r-- | include/vcl/toolbox.hxx | 4 |
5 files changed, 358 insertions, 63 deletions
diff --git a/include/vcl/IconThemeInfo.hxx b/include/vcl/IconThemeInfo.hxx new file mode 100644 index 000000000000..f745884e8cdc --- /dev/null +++ b/include/vcl/IconThemeInfo.hxx @@ -0,0 +1,97 @@ +/* -*- 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 VCL_ICONTHEMEINFO_HXX_ +#define VCL_ICONTHEMEINFO_HXX_ + +#include <vcl/dllapi.h> +// for Size +#include <tools/gen.hxx> +#include <rtl/ustring.hxx> + +#include <vector> + +// 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 SAL_DLLPUBLIC_EXPORT IconThemeInfo { + +public: + + /** 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(const OUString&); + + /** Check whether a IconThemeInfo can be constructed from an URL */ + static bool UrlCanBeParsed(const OUString& 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<vcl::IconThemeInfo>& themes, const OUString& themeId); + + /** Check whether a theme with a specified id is in a vector of IconThemeInfo */ + static bool + IconThemeIsInVector(const std::vector<vcl::IconThemeInfo>& 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(const OUString&); + + /** 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 /* VCL_ICONTHEMEINFO_HXX_ */ diff --git a/include/vcl/IconThemeScanner.hxx b/include/vcl/IconThemeScanner.hxx new file mode 100644 index 000000000000..3f6ad25a0a7a --- /dev/null +++ b/include/vcl/IconThemeScanner.hxx @@ -0,0 +1,103 @@ +/* -*- 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 VCL_ICONTHEMESCANNER_HXX_ +#define VCL_ICONTHEMESCANNER_HXX_ + +#include <vcl/dllapi.h> +#include <tools/solar.h> + +#include <rtl/ustring.hxx> + +#include <boost/shared_ptr.hpp> +#include <vector> + +// forward declaration of unit test class. Required for friend relationship. +class IconThemeScannerTest; + +namespace osl { +class Directory; +class DirectoryItem; +} + +namespace vcl { +class IconThemeInfo; + +/** This class scans a folder for icon themes and provides the results. + */ +class SAL_DLLPUBLIC_EXPORT IconThemeScanner +{ +public: + ~IconThemeScanner(); + + /** Factory method to create the object. + * Provide a path to search for IconThemes. + */ + static boost::shared_ptr<IconThemeScanner> + Create(const OUString &path); + + /** This method will return the standard path where icon themes are located. + */ + static OUString + GetStandardIconThemePath(); + + const std::vector<IconThemeInfo>& + GetFoundIconThemes() const {return mFoundIconThemes;} + + /** Get the IconThemeInfo for a theme. + * If the theme id is not among the found themes, a std::runtime_error will be thrown. + * Use IconThemeIsInstalled() to check whether it is available. + */ + const IconThemeInfo& GetIconThemeInfo(const OUString& themeId); + + /** Checks whether the theme with the provided name has been found in the + * scanned directory. + */ + bool + IconThemeIsInstalled(const OUString& themeId) const; + +private: + IconThemeScanner(); + + /** Scan a directory for icon themes. + * + * @return + * This method will return true on success. + * There are several cases when this method will fail: + * - The directory does not exist + * - There are no files which which match the pattern images_xxx.zip + */ + bool + ScanDirectoryForIconThemes(const OUString &path); + + /** Adds the provided icon theme by path. + */ + bool + AddIconThemeByPath(const OUString &path); + + /** Scans the provided directory for icon themes. + * The returned strings will contain the URLs to the icon themes. + */ + static std::vector<OUString> + ReadIconThemesFromPath(const OUString& dir); + + /** Check whether a single file is valid */ + static bool + FileIsValidIconTheme(const OUString&); + + std::vector<IconThemeInfo> mFoundIconThemes; + + friend class ::IconThemeScannerTest; +}; + +} // end namespace vcl + +#endif /* VCL_ICONTHEMESCANNER_HXX_ */ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vcl/IconThemeSelector.hxx b/include/vcl/IconThemeSelector.hxx new file mode 100644 index 000000000000..35bde9e510f6 --- /dev/null +++ b/include/vcl/IconThemeSelector.hxx @@ -0,0 +1,101 @@ +/* -*- 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 VCL_ICONTHEMESELECTOR_HXX_ +#define VCL_ICONTHEMESELECTOR_HXX_ + +#include <rtl/ustring.hxx> + +#include <vcl/dllapi.h> + +#include <vector> + +// forward declaration of unit test class. Required for friend relationship. +class IconThemeSelectorTest; + +namespace vcl { +struct IconThemeInfo; + +/** This class helps to choose an icon theme from a list of installed themes. + * + * The following factors influence the selection: + * -# When high contrast mode is enabled, the high contrast icon theme is selected (if it is installed). + * -# When a preferred theme has been set (e.g., in the gnome desktop settings), that theme is selected. + */ +class SAL_DLLPUBLIC_EXPORT IconThemeSelector { +public: + IconThemeSelector(); + + /** Select an icon theme from the list of installed themes. + * + * If high contrast mode has been enabled, the highcontrast theme will be selected (if it is available). + * + * @pre + * @p installedThemes must not be empty + */ + OUString + SelectIconTheme( + const std::vector<IconThemeInfo>& installedThemes, + const OUString& theme + ) const; + + /** Select the standard icon theme for a desktop environment from a list of installed themes. + * + * If a preferred theme has been set, this one will take precedence. + * + * The same logic as in SelectIconTheme() will apply. + * + * @pre + * @p installedThemes must not be empty + */ + OUString + SelectIconThemeForDesktopEnvironment( + const std::vector<IconThemeInfo>& installedThemes, + const OUString& desktopEnvironment) const; + + void + SetUseHighContrastTheme(bool); + + void + SetPreferredIconTheme(const OUString&); + + bool + operator==(const vcl::IconThemeSelector&) const; + + bool + operator!=(const vcl::IconThemeSelector&) const; + +private: + /** Return the first element of the themes, or the fallback if the vector is empty */ + static OUString + ReturnFallback(const std::vector<IconThemeInfo>& installedThemes); + + /** The name of the icon theme to use for high contrast mode */ + static const OUString + HIGH_CONTRAST_ICON_THEME_ID; + + /** The name of the icon theme which is used as fallback */ + static const OUString + FALLBACK_ICON_THEME_ID; + + + static OUString + GetIconThemeForDesktopEnvironment(const OUString& desktopEnvironment); + + OUString mPreferredIconTheme; + bool mUseHighContrastTheme; + + friend class ::IconThemeSelectorTest; +}; + +} /* namespace vcl */ + +#endif /* VCL_ICONTHEMESELECTOR_HXX_ */ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vcl/settings.hxx b/include/vcl/settings.hxx index 828c7a1105ff..ee50d38b1ae8 100644 --- a/include/vcl/settings.hxx +++ b/include/vcl/settings.hxx @@ -37,6 +37,9 @@ class LocaleDataWrapper; namespace vcl { class I18nHelper; + class IconThemeScanner; + class IconThemeSelector; + class IconThemeInfo; } // ----------------- @@ -248,6 +251,7 @@ public: private: void SetStandardStyles(); + Color maActiveBorderColor; Color maActiveColor; Color maActiveColor2; @@ -330,21 +334,25 @@ private: sal_uLong mnDisplayOptions; sal_uLong mnToolbarIconSize; bool mnUseFlatMenus; - sal_uLong mnOptions; - sal_uInt16 mnScreenZoom; - sal_uInt16 mnScreenFontZoom; - bool mnHighContrast; - bool mnUseSystemUIFonts; - sal_uInt16 mnAutoMnemonic; - AutoState mnUseImagesInMenus; + sal_uLong mnOptions; + sal_uInt16 mnScreenZoom; + sal_uInt16 mnScreenFontZoom; + bool mbHighContrast; + bool mbUseSystemUIFonts; + sal_uInt16 mnAutoMnemonic; + AutoState mnUseImagesInMenus; bool mnUseFlatBorders; - bool mbPreferredUseImagesInMenus; - long mnMinThumbSize; - sal_uLong mnSymbolsStyle; - sal_uLong mnPreferredSymbolsStyle; - bool mnSkipDisabledInMenus; - bool mbHideDisabledMenuItems; - bool mbAcceleratorsInContextMenus; + bool mbPreferredUseImagesInMenus; + long mnMinThumbSize; + boost::shared_ptr<vcl::IconThemeScanner> + mIconThemeScanner; + boost::shared_ptr<vcl::IconThemeSelector> + mIconThemeSelector; + + OUString mIconTheme; + bool mbSkipDisabledInMenus; + bool mbHideDisabledMenuItems; + bool mbAcceleratorsInContextMenus; //mbPrimaryButtonWarpsSlider == true for "jump to here" behavior for primary button, otherwise //primary means scroll by single page. Secondary button takes the alternative behaviour bool mbPrimaryButtonWarpsSlider; @@ -414,19 +422,6 @@ private: #define STYLE_TOOLBAR_ICONSIZE_SMALL ((sal_uLong)1) #define STYLE_TOOLBAR_ICONSIZE_LARGE ((sal_uLong)2) -#define STYLE_SYMBOLS_AUTO ((sal_uLong)0) -#define STYLE_SYMBOLS_DEFAULT ((sal_uLong)1) -#define STYLE_SYMBOLS_HICONTRAST ((sal_uLong)2) -#define STYLE_SYMBOLS_INDUSTRIAL ((sal_uLong)3) -#define STYLE_SYMBOLS_CRYSTAL ((sal_uLong)4) -#define STYLE_SYMBOLS_TANGO ((sal_uLong)5) -#define STYLE_SYMBOLS_OXYGEN ((sal_uLong)6) -#define STYLE_SYMBOLS_CLASSIC ((sal_uLong)7) -#define STYLE_SYMBOLS_HUMAN ((sal_uLong)8) -#define STYLE_SYMBOLS_SIFR ((sal_uLong)9) -#define STYLE_SYMBOLS_TANGO_TESTING ((sal_uLong)10) -#define STYLE_SYMBOLS_THEMES_MAX ((sal_uLong)11) - #define STYLE_CURSOR_NOBLINKTIME ((sal_uLong)0xFFFFFFFF) class VCL_DLLPUBLIC StyleSettings @@ -640,14 +635,13 @@ public: const Color& GetInactiveTabColor() const { return mpData->maInactiveTabColor; } - void SetHighContrastMode( bool bHighContrast ) - { CopyData(); mpData->mnHighContrast = bHighContrast; } - bool GetHighContrastMode() const - { return mpData->mnHighContrast; } + void SetHighContrastMode(bool bHighContrast ); + bool GetHighContrastMode() const; + void SetUseSystemUIFonts( bool bUseSystemUIFonts ) - { CopyData(); mpData->mnUseSystemUIFonts = bUseSystemUIFonts; } + { CopyData(); mpData->mbUseSystemUIFonts = bUseSystemUIFonts; } bool GetUseSystemUIFonts() const - { return mpData->mnUseSystemUIFonts; } + { return mpData->mbUseSystemUIFonts; } void SetUseFlatBorders( bool bUseFlatBorders ) { CopyData(); mpData->mnUseFlatBorders = bUseFlatBorders; } bool GetUseFlatBorders() const @@ -664,9 +658,9 @@ public: bool GetPreferredUseImagesInMenus() const { return mpData->mbPreferredUseImagesInMenus; } void SetSkipDisabledInMenus( bool bSkipDisabledInMenus ) - { CopyData(); mpData->mnSkipDisabledInMenus = bSkipDisabledInMenus; } + { CopyData(); mpData->mbSkipDisabledInMenus = bSkipDisabledInMenus; } bool GetSkipDisabledInMenus() const - { return mpData->mnSkipDisabledInMenus; } + { return mpData->mbSkipDisabledInMenus; } void SetHideDisabledMenuItems( bool bHideDisabledMenuItems ) { CopyData(); mpData->mbHideDisabledMenuItems = bHideDisabledMenuItems; } bool GetHideDisabledMenuItems() const @@ -850,28 +844,32 @@ public: sal_uLong GetToolbarIconSize() const { return mpData->mnToolbarIconSize; } - void SetSymbolsStyle( sal_uLong nStyle ) - { CopyData(); mpData->mnSymbolsStyle = nStyle; } - sal_uLong GetSymbolsStyle() const - { return mpData->mnSymbolsStyle; } - - void SetPreferredSymbolsStyle( sal_uLong nStyle ) - { CopyData(); mpData->mnPreferredSymbolsStyle = nStyle; } - void SetPreferredSymbolsStyleName( const OUString &rName ); - sal_uLong GetPreferredSymbolsStyle() const - { return mpData->mnPreferredSymbolsStyle; } - // check whether the symbols style is supported (icons are installed) - bool CheckSymbolStyle( sal_uLong nStyle ) const; - sal_uLong GetAutoSymbolsStyle() const; - - sal_uLong GetCurrentSymbolsStyle() const; - - void SetSymbolsStyleName( const OUString &rName ) - { return SetSymbolsStyle( ImplNameToSymbolsStyle( rName ) ); } - OUString GetSymbolsStyleName() const - { return ImplSymbolsStyleToName( GetSymbolsStyle() ); } - OUString GetCurrentSymbolsStyleName() const - { return ImplSymbolsStyleToName( GetCurrentSymbolsStyle() ); } + /** Set the icon theme to use. */ + void SetIconTheme(const OUString&); + + /** Determine which icon theme should be used. + * + * This might not be the same as the one which has been set with SetIconTheme(), + * e.g., if high contrast mode is enabled. + * + * (for the detailed logic @see vcl::IconThemeSelector) + */ + OUString DetermineIconTheme() const; + + /** Obtain the list of icon themes which were found in the config folder + * @see vcl::IconThemeScanner for more details. + */ + std::vector<vcl::IconThemeInfo> GetInstalledIconThemes() const; + + /** Obtain the name of the icon theme which will be chosen automatically for the desktop environment. + * This method will only return icon themes which were actually found on the system. + */ + OUString GetAutomaticallyChosenIconTheme() const; + + /** Set a preferred icon theme. + * This theme will be preferred in GetAutomaticallyChosenIconTheme() + */ + void SetPreferredIconTheme(const OUString&); const Wallpaper& GetWorkspaceGradient() const { return mpData->maWorkspaceGradient; } @@ -945,10 +943,6 @@ public: bool operator ==( const StyleSettings& rSet ) const; bool operator !=( const StyleSettings& rSet ) const { return !(*this == rSet); } - -protected: - OUString ImplSymbolsStyleToName( sal_uLong nStyle ) const; - sal_uLong ImplNameToSymbolsStyle( const OUString &rName ) const; }; // ---------------- diff --git a/include/vcl/toolbox.hxx b/include/vcl/toolbox.hxx index d595191c9d32..4ca253f9df0b 100644 --- a/include/vcl/toolbox.hxx +++ b/include/vcl/toolbox.hxx @@ -569,8 +569,8 @@ public: // if an index is found the corresponding item id is filled in (else 0) long GetIndexForPoint( const Point& rPoint, sal_uInt16& rItemID ) const; - static const Size& GetDefaultImageSize(bool bLarge); - const Size& GetDefaultImageSize() const; + static Size GetDefaultImageSize(bool bLarge); + Size GetDefaultImageSize() const; void ChangeHighlight( sal_uInt16 nPos ); void SetImageListProvider(vcl::IImageListProvider* _pProvider); |