1 #ifndef _KVI_THEME_H_
2 #define _KVI_THEME_H_
3 //=============================================================================
4 //
5 //   File : KviTheme.h
6 //   Creation date : Mon Jan 08 2007 03:23:00 CEST by Szymon Stefanek
7 //
8 //   This file is part of the KVIrc IRC client distribution
9 //   Copyright (C) 2007-2010 Szymon Stefanek (pragma at kvirc dot net)
10 //
11 //   This program is FREE software. You can redistribute it and/or
12 //   modify it under the terms of the GNU General Public License
13 //   as published by the Free Software Foundation; either version 2
14 //   of the License, or (at your option) any later version.
15 //
16 //   This program is distributed in the HOPE that it will be USEFUL,
17 //   but WITHOUT ANY WARRANTY; without even the implied warranty of
18 //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 //   See the GNU General Public License for more details.
20 //
21 //   You should have received a copy of the GNU General Public License
22 //   along with this program. If not, write to the Free Software Foundation,
23 //   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 //
25 //=============================================================================
26 
27 #include "kvi_settings.h"
28 #include "KviHeapObject.h"
29 #include "kvi_fileextensions.h"
30 #include "KviApplication.h"
31 #include "KviFileUtils.h"
32 
33 #include <QPixmap>
34 #include <QString>
35 
36 #define KVI_THEMEINFO_FILE_NAME "themeinfo" KVI_FILEEXTENSION_CONFIG
37 #define KVI_THEMEDATA_FILE_NAME "themedata" KVI_FILEEXTENSION_CONFIG
38 #define KVI_THEMEINFO_CONFIG_GROUP "ThemeInfo"
39 #define KVI_THEMEDATA_CONFIG_GROUP "ThemeData"
40 
41 ///
42 /// The current theme engine version: bump up if you make INCOMPATIBLE
43 /// changes in the method of saving the theme.
44 ///
45 #define KVI_CURRENT_THEME_ENGINE_VERSION "1.1.0"
46 
47 ///
48 /// \class KviThemeInfo
49 ///
50 /// \brief A set of information about a KVIrc theme
51 ///
52 /// This object contains a set of information about
53 /// a theme that can be read and stored to a standard
54 /// KVIrc configuration file (which is usually named
55 /// themeinfo.kvc but this is not strictly necessary).
56 ///
57 class KVIRC_API KviThemeInfo : public KviHeapObject
58 {
59 public:
60 	KviThemeInfo();
61 	~KviThemeInfo();
62 
63 public:
64 	enum Location
65 	{
66 		///
67 		/// Theme is a builtin theme. The subdirectory is inside the kvirc global theme directory.
68 		///
69 		Builtin = 0,
70 		///
71 		/// Theme is a user theme. The subdirectory is inside the kvirc local theme directory.
72 		///
73 		User = 1,
74 		///
75 		/// Theme is an external theme. The subdirectory is somewhere on the filesystem.
76 		///
77 		External = 3,
78 		///
79 		/// Automatically determine location
80 		///
81 		Auto = 4
82 	};
83 
84 protected:
85 	QString m_szName;    //< name of the theme
86 	QString m_szVersion; //< version of the theme
87 
88 	QString m_szDirectory;    //< the absolute directory of the theme
89 	QString m_szSubdirectory; //< the last component of m_szDirectory (this is needed when the theme is installed)
90 	Location m_eLocation;     //< the location of the theme
91 
92 	QString m_szAuthor;             //< author of the theme
93 	QString m_szDescription;        //< description of the theme
94 	QString m_szDate;               //< theme creation date
95 	QString m_szApplication;        //< theme creation (KVIrc) version
96 	QString m_szThemeEngineVersion; //< the theme engine version that saved this theme
97 
98 	QString m_szLastError; //< reported when some function fails
99 
100 	QPixmap m_pixScreenshotLarge;  //< the large screenshot pixmap
101 	QPixmap m_pixScreenshotMedium; //< the medium screenshot pixmap
102 	QPixmap m_pixScreenshotSmall;  //< the small screenshot pixmap
103 
104 public:
105 	///
106 	/// Load theme data from the specified location.
107 	/// If eLocation is Builtin then szThemeDirectory is assumed to be a subdirectory of the kvirc global theme directory.
108 	/// If eLocation is User then szThemeDirectory is assumed to be a subdirectory of the kvirc local theme directory.
109 	/// If eLocation is External the szThemeDirectory is assumed to be a full path to a theme directory.
110 	///
111 	bool load(const QString & szDirectory, Location eLocation);
112 
113 	///
114 	/// save the currently defined theme configuration in the specified file
115 	///
116 	bool save(const QString & szThemeFileName);
117 
lastError()118 	const QString & lastError() { return m_szLastError; }
setLastError(const QString & szLastError)119 	void setLastError(const QString & szLastError) { m_szLastError = szLastError; }
name()120 	const QString & name() { return m_szName; }
setName(const QString & szName)121 	void setName(const QString & szName) { m_szName = szName; }
version()122 	const QString & version() { return m_szVersion; }
setVersion(const QString & szVersion)123 	void setVersion(const QString & szVersion) { m_szVersion = szVersion; }
124 
directory()125 	const QString & directory() const
126 	{
127 		return m_szDirectory;
128 	}
129 
subdirectory()130 	const QString & subdirectory() const
131 	{
132 		return m_szSubdirectory;
133 	}
134 
location()135 	Location location() const
136 	{
137 		return m_eLocation;
138 	}
139 
140 	void setDirectoryAndLocation(const QString & szDirectory, Location eLocation);
141 
isBuiltin()142 	bool isBuiltin()
143 	{
144 		return m_eLocation == KviThemeInfo::Builtin;
145 	}
146 
author()147 	const QString & author() { return m_szAuthor; }
setAuthor(const QString & szAuthor)148 	void setAuthor(const QString & szAuthor) { m_szAuthor = szAuthor; }
description()149 	const QString & description() { return m_szDescription; }
setDescription(const QString & szDescription)150 	void setDescription(const QString & szDescription) { m_szDescription = szDescription; }
date()151 	const QString & date() { return m_szDate; }
setDate(const QString & szDate)152 	void setDate(const QString & szDate) { m_szDate = szDate; }
application()153 	const QString & application() { return m_szApplication; }
setApplication(const QString & szApplication)154 	void setApplication(const QString & szApplication) { m_szApplication = szApplication; }
themeEngineVersion()155 	const QString & themeEngineVersion() { return m_szThemeEngineVersion; }
setThemeEngineVersion(const QString & szThemeEngineVersion)156 	void setThemeEngineVersion(const QString & szThemeEngineVersion) { m_szThemeEngineVersion = szThemeEngineVersion; }
157 
158 	///
159 	/// Attempt to load the theme screenshot from THEMEDIR/screenshot_*.png
160 	/// This function will work only if the absoluteDirectory() of the theme
161 	/// has been set, otherwise the returned pixmap will be null.
162 	///
163 	const QPixmap & smallScreenshot();
164 	///
165 	/// Attempt to load the theme screenshot from THEMEDIR/screenshot_*.png
166 	/// This function will work only if the absoluteDirectory() of the theme
167 	/// has been set, otherwise the returned pixmap will be null.
168 	///
169 	const QPixmap & mediumScreenshot();
170 	///
171 	/// Attempt to load the theme screenshot from THEMEDIR/screenshot_*.png
172 	/// This function will work only if the absoluteDirectory() of the theme
173 	/// has been set, otherwise the returned pixmap will be null.
174 	///
175 	const QPixmap & largeScreenshot();
176 	///
177 	/// Attempt to load the theme screenshot from THEMEDIR/screenshot_*.png
178 	/// This function will work only if the absoluteDirectory() of the theme
179 	/// has been set, otherwise the returned pixmap will be null.
180 	///
181 	QString smallScreenshotPath();
182 };
183 
184 namespace KviTheme
185 {
186 	///
187 	/// Attempt to load and apply a theme.
188 	/// If eLocation is Builtin then szThemeDirectory is assumed to be a subdirectory of the kvirc global theme directory.
189 	/// If eLocation is User then szThemeDirectory is assumed to be a subdirectory of the kvirc local theme directory.
190 	/// If eLocation is External the szThemeDirectory is assumed to be a full path to a theme directory.
191 	/// Will return true on success and false on failure.
192 	/// On success this function will return the theme information in the buffer.
193 	/// On failure this function will also set buffer.lastError() to a meaningful value
194 	/// Note that for convenience this function is implemented in KviOptions.cpp
195 	///
196 	bool KVIRC_API apply(const QString & szThemeDirectory, KviThemeInfo::Location eLocation, KviThemeInfo & buffer);
197 
198 	///
199 	/// Save a theme given the specified options.
200 	/// Will return true on success and false on failure.
201 	/// On failure this function will also set options.lastError() to a meaningful value
202 	/// This function requires both absoluteDirectory() and subdirectory() to be
203 	/// set to the right values. In theory this function could save a theme
204 	/// in a directory different than $KVIRC_LOCAL_DIR/themes/subdirectory
205 	/// but this feature is actually unused.
206 	/// Note that for convenience this function is implemented in KviOptions.cpp
207 	///
208 	bool KVIRC_API save(KviThemeInfo & options, bool bSaveIcons);
209 
210 	///
211 	/// Save the theme screenshots in the given EXISTING directory and given
212 	/// an existing screenshot on disk (usually in the tmp directory).
213 	///
214 	bool KVIRC_API saveScreenshots(KviThemeInfo & options, const QString & szOriginalScreenshotPath);
215 
216 	///
217 	/// List directory names of installed themes.
218 	///
219 	void KVIRC_API installedThemeDirectories(QStringList & slThemes, KviThemeInfo::Location eLocation);
220 }
221 
222 #endif //_KVI_THEME_H_
223