1 // Copyright 2005-2019 The Mumble Developers. All rights reserved.
2 // Use of this source code is governed by a BSD-style license
3 // that can be found in the LICENSE file at the root of the
4 // Mumble source tree or at <https://www.mumble.info/LICENSE>.
5 
6 #ifndef MUMBLE_MUMBLE_THEMEINFO_H_
7 #define MUMBLE_MUMBLE_THEMEINFO_H_
8 
9 #include <QtCore/QString>
10 #include <QtCore/QFileInfo>
11 #include <QtCore/QMap>
12 #include <QMetaType>
13 #ifndef Q_MOC_RUN
14 #include <boost/optional.hpp>
15 #endif
16 
17 class QSettings;
18 class QDir;
19 
20 class ThemeInfo;
21 typedef QMap<QString, ThemeInfo> ThemeMap;
22 
23 /// Description of a Mumble theme with multiple styles
24 class ThemeInfo {
25 public:
26 	/// A specific style of a Mumble theme
27 	///
28 	/// Multiple styles can for example be used to differentiate light/dark
29 	/// variants of a theme.
30 	///
31 	/// A single style can refer to multiple run-time platform specific qss
32 	/// theme files.
33 	class StyleInfo {
34 	public:
35 		/// Name of the theme containing this style
36 		QString themeName;
37 		/// Name for the style
38 		QString name;
39 
40 		/// @return Returns platform specific qss or defaultQss if none available
41 		QFileInfo getPlatformQss() const;
42 
43 		/// Default QSS file for the style
44 		QFileInfo defaultQss;
45 		/// Platform specific QSS files available
46 		QMap<QString, QFileInfo> qssFiles;
47 	};
48 
49 	typedef QMap<QString, StyleInfo> StylesMap;
50 
51 	/// Takes stock of all mumble themes in the given folders.
52 	///
53 	/// If a theme with the same name is available in multiple directories
54 	/// only the last occurance will be returned.
55 	///
56 	/// @param themesDirectories List of directories to search for theme directories.
57 	/// @return Map of theme name to Theme
58 	static ThemeMap scanDirectories(const QVector<QDir> &themesDirectories);
59 
60 	/// Takes stock of all mumble themes in the given folder
61 	///
62 	/// Uses loadThemeInfoFromDirectory on each directory in the folder
63 	/// to find themes. Themes with the same names will override each other.
64 	///
65 	/// @param themesDirectory Directory to scan for theme directories
66 	/// @return Map of theme name to Theme
67 	static ThemeMap scanDirectory(const QDir &themesDirectory);
68 
69 	/// Loads the theme description from a given directory
70 	///
71 	/// @param themeDirectory
72 	/// @return Theme if description was correctly loaded. boost::none if not.
73 	static boost::optional<ThemeInfo> load(const QDir &themeDirectory);
74 
75 	/// @return Style with given name or default
76 	StyleInfo getStyle(QString name_) const;
77 
78 	/// Ideally unique theme name. A theme with identical name can override.
79 	QString name;
80 	/// Style name to style mapping.
81 	StylesMap styles;
82 	/// Default style
83 	QString defaultStyle;
84 };
85 
86 Q_DECLARE_METATYPE(ThemeInfo);
87 Q_DECLARE_METATYPE(ThemeInfo::StyleInfo);
88 
89 #endif // MUMBLE_MUMBLE_THEMEINFO_H_
90