1
//=============================================================================
3
// File : themefunctions.cpp
4
// Creation date : Wed 03 Jan 2007 03:14:07 by Szymon Stefanek
6
// This file is part of the KVIrc IRC Client distribution
7
// Copyright (C) 2007-2008 Szymon Stefanek <pragma at kvirc dot net>
9
// This program is FREE software. You can redistribute it and/or
10
// modify it under the terms of the GNU General Public License
11
// as published by the Free Software Foundation; either version 2
12
// of the License, or (at your opinion) any later version.
14
// This program is distributed in the HOPE that it will be USEFUL,
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17
// See the GNU General Public License for more details.
19
// You should have received a copy of the GNU General Public License
20
// along with this program. If not, write to the Free Software Foundation,
21
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23
//=============================================================================
25
#include "themefunctions.h"
27
#include "kvi_packagefile.h"
28
#include "kvi_locale.h"
29
#include "kvi_msgbox.h"
31
#include "kvi_htmldialog.h"
32
#include "kvi_iconmanager.h"
33
#include "kvi_miscutils.h"
34
#include "kvi_sourcesdate.h"
35
#include "kvi_theme.h"
36
#include "kvi_frame.h"
42
namespace KviThemeFunctions
45
static bool notAValidThemePackage(QString &szError)
47
szError = __tr2qs_ctx("The selected file does not seem to be a valid KVIrc theme package","theme");
51
bool installThemePackage(const QString &szThemePackageFileName,QString &szError,QWidget * pDialogParent)
53
KviPointerHashTable<QString,QString> * pInfoFields;
57
QByteArray * pByteArray;
60
const char * check_fields[] = { "Name", "Version", "Author", "Description", "Date", "Application" };
62
// check if it is a valid theme file
65
if(!r.readHeader(szThemePackageFileName))
67
QString szErr = r.lastError();
68
KviQString::sprintf(szError,__tr2qs_ctx("The selected file does not seem to be a valid KVIrc package: %Q","theme"),&szErr);
72
pInfoFields = r.stringInfoFields();
74
pValue = pInfoFields->find("PackageType");
76
return notAValidThemePackage(szError);
78
if(!KviQString::equalCI(*pValue,"ThemePack"))
79
return notAValidThemePackage(szError);
81
pValue = pInfoFields->find("ThemePackVersion");
84
return notAValidThemePackage(szError);
86
// make sure the default fields exist
89
pValue = pInfoFields->find(check_fields[i]);
90
if(!pValue)return notAValidThemePackage(szError);
93
pValue = pInfoFields->find("ThemeCount");
95
return notAValidThemePackage(szError);
98
int iThemeCount = pValue->toInt(&bOk);
100
return notAValidThemePackage(szError);
103
return notAValidThemePackage(szError);
105
// ok.. it should be really valid at this point
108
pByteArray = r.binaryInfoFields()->find("Image");
110
pix.loadFromData(*pByteArray,0,0);
114
// load the default icon
115
pix = *(g_pIconManager->getBigIcon(KVI_BIGICON_THEME));
118
QString szPackageName;
119
QString szPackageVersion;
120
QString szPackageAuthor;
121
QString szPackageDescription;
122
QString szPackageDate;
123
QString szPackageThemeEngineVersion;
124
QString szPackageApplication;
126
QString szAuthor = __tr2qs_ctx("Author","theme");
127
QString szCreatedAt = __tr2qs_ctx("Created at","theme");
128
QString szCreatedOn = __tr2qs_ctx("Created with","theme");
130
r.getStringInfoField("Name",szPackageName);
131
r.getStringInfoField("Version",szPackageVersion);
132
r.getStringInfoField("Author",szPackageAuthor);
133
r.getStringInfoField("Description",szPackageDescription);
134
r.getStringInfoField("Application",szPackageApplication);
135
r.getStringInfoField("Date",szPackageDate);
138
QString szDetails = "<html><body bgcolor=\"#ffffff\">";
142
int iValidThemeCount = iThemeCount;
144
while(iIdx < iThemeCount)
149
QString szThemeVersion;
150
QString szThemeDescription;
152
QString szThemeSubdirectory;
153
QString szThemeAuthor;
154
QString szThemeEngineVersion;
155
QString szThemeApplication;
157
KviQString::sprintf(szTmp,"Theme%dName",iIdx);
158
r.getStringInfoField(szTmp,szThemeName);
159
KviQString::sprintf(szTmp,"Theme%dVersion",iIdx);
160
r.getStringInfoField(szTmp,szThemeVersion);
161
KviQString::sprintf(szTmp,"Theme%dApplication",iIdx);
162
r.getStringInfoField(szTmp,szThemeApplication);
163
KviQString::sprintf(szTmp,"Theme%dDescription",iIdx);
164
r.getStringInfoField(szTmp,szThemeDescription);
165
KviQString::sprintf(szTmp,"Theme%dDate",iIdx);
166
r.getStringInfoField(szTmp,szThemeDate);
167
KviQString::sprintf(szTmp,"Theme%dSubdirectory",iIdx);
168
r.getStringInfoField(szTmp,szThemeSubdirectory);
169
KviQString::sprintf(szTmp,"Theme%dAuthor",iIdx);
170
r.getStringInfoField(szTmp,szThemeAuthor);
171
KviQString::sprintf(szTmp,"Theme%dThemeEngineVersion",iIdx);
172
r.getStringInfoField(szTmp,szThemeEngineVersion);
173
KviQString::sprintf(szTmp,"Theme%dScreenshot",iIdx);
174
QPixmap pixScreenshot;
175
pByteArray = r.binaryInfoFields()->find(szTmp);
177
pixScreenshot.loadFromData(*pByteArray,0,0);
179
if(szThemeName.isEmpty() || szThemeVersion.isEmpty() || szThemeSubdirectory.isEmpty() || szThemeEngineVersion.isEmpty())
181
if(KviMiscUtils::compareVersions(szThemeEngineVersion,KVI_CURRENT_THEME_ENGINE_VERSION) < 0)
184
QString szDetailsBuffer;
186
getThemeHtmlDescription(
195
szThemeEngineVersion,
203
szDetails += szDetailsBuffer;
207
szDetails += "<p><center><font color=\"#ff0000\"><b>";
208
szDetails += __tr2qs_ctx("Warning: The theme might be incompatible with this version of KVIrc","theme");
209
szDetails += "</b></font></center></p>";
216
szDetails += "<br><p><center><a href=\"theme_dialog_main\">";
217
szDetails += __tr2qs_ctx("Go Back to Package Data","theme");
218
szDetails += "</a></center></p>";
219
szDetails += "</body></html>";
221
if(iValidThemeCount < iThemeCount)
223
szWarnings += "<p><center><font color=\"#ff0000\"><b>";
224
szWarnings += __tr2qs_ctx("Warning: Some of the theme contained in this package might be either corrupted or incompatible with this version of KVIrc","theme");
225
szWarnings += "</b></font></center></p>";
228
QString szShowDetails = __tr2qs_ctx("Show Details","theme");
230
KviQString::sprintf(hd.szHtmlText,
231
"<html bgcolor=\"#ffffff\">" \
232
"<body bgcolor=\"#ffffff\">" \
237
"<img src=\"theme_dialog_pack_image\">" \
243
"%Q: <b>%Q</b><br>" \
244
"%Q: <b>%Q</b><br>" \
247
"<font color=\"#808080\">" \
254
"<a href=\"theme_dialog_details\">%Q</a>" \
260
&szPackageDescription,
266
&szPackageApplication,
271
hd.addImageResource("theme_dialog_pack_image",pix);
272
hd.addHtmlResource("theme_dialog_details",szDetails);
273
hd.addHtmlResource("theme_dialog_main",hd.szHtmlText);
275
QString beginCenter = "<center>";
276
QString endCenter = "</center>";
278
hd.szCaption = __tr2qs_ctx("Install Theme Pack - KVIrc","theme");
279
hd.szUpperLabelText = beginCenter + __tr2qs_ctx("You're about to install the following theme package","theme") + endCenter;
280
hd.szLowerLabelText = beginCenter + __tr2qs_ctx("Do you want to proceed with the installation ?","theme") + endCenter;
281
hd.szButton1Text = __tr2qs_ctx("Do Not Install","theme");
282
hd.szButton2Text = __tr2qs_ctx("Yes, Proceed","theme");
283
hd.iDefaultButton = 2;
284
hd.iCancelButton = 1;
285
hd.pixIcon = *(g_pIconManager->getSmallIcon(KVI_SMALLICON_THEME));
286
hd.iMinimumWidth = 350;
287
hd.iMinimumHeight = 420;
288
hd.iFlags = KviHtmlDialogData::ForceMinimumSize;
290
bInstall = KviHtmlDialog::display(pDialogParent,&hd) == 2;
293
QString szUnpackPath;
294
g_pApp->getLocalKvircDirectory(szUnpackPath,KviApp::Themes);
295
if(!r.unpack(szThemePackageFileName,szUnpackPath))
297
QString szErr2 = r.lastError();
298
KviQString::sprintf(szError,__tr2qs_ctx("Failed to unpack the selected file: %Q","theme"),&szErr2);
307
void getThemeHtmlDescription(
309
const QString &szThemeName,
310
const QString &szThemeVersion,
311
const QString &szThemeDescription,
312
const QString &szThemeSubdirectory,
313
const QString &szThemeApplication,
314
const QString &szThemeAuthor,
315
const QString &szThemeDate,
316
const QString &szThemeThemeEngineVersion,
317
const QPixmap &pixScreenshot,
318
int iUniqueIndexInDocument,
319
KviHtmlDialogData *hd
322
QString szAuthor = __tr2qs_ctx("Author","theme");
323
QString szCreatedAt = __tr2qs_ctx("Created at","theme");
324
QString szCreatedOn = __tr2qs_ctx("Created with","theme");
325
QString szThemeEngineVersion = __tr2qs_ctx("Theme Engine Version","theme");
326
QString szSubdirectory = __tr2qs_ctx("Subdirectory","theme");
328
QString szScreenshot;
329
if(!pixScreenshot.isNull())
331
KviQString::sprintf(szScreenshot,"<p><center><img src=\"theme_shot%d\"></center></p>",iUniqueIndexInDocument);
333
KviQString::sprintf(szTmp,"theme_shot%d",iUniqueIndexInDocument);
336
hd->addImageResource(szTmp,pixScreenshot);
337
else szScreenshot = "";
352
"%Q: <b>%Q</b><br>" \
353
"%Q: <b>%Q</b><br>" \
356
"<font color=\"#808080\">" \
372
&szThemeEngineVersion,
373
&szThemeThemeEngineVersion,
379
bool makeKVIrcScreenshot(const QString &szSavePngFilePath,bool bMaximizeFrame)
383
if(g_pFrame->isMaximized())
384
bMaximizeFrame = false;
388
g_pFrame->showMaximized();
390
QPixmap pix = QPixmap::grabWidget(g_pFrame);
396
if(!pix.save(szSavePngFilePath,"PNG"))
401
g_pFrame->showNormal();