~ubuntu-branches/ubuntu/trusty/kvirc/trusty

« back to all changes in this revision

Viewing changes to src/modules/theme/themefunctions.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Kai Wasserbäch, Kai Wasserbäch, Raúl Sánchez Siles
  • Date: 2011-02-12 10:40:21 UTC
  • mfrom: (14.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20110212104021-5mh4f75jlku20mnt
The combined "Twisted Experiment" and "Nocturnal Raid" release.

[ Kai Wasserbäch ]
* Synced to upstream's SVN revision 5467.
* debian/rules:
  - Added .PHONY line.
  - Resurrect -DMANUAL_REVISION, got lost somewhere and we build SVN
    revisions again.
  - Replace "-DWITH_NO_EMBEDDED_CODE=YES" with "-DWANT_CRYPTOPP=YES".
  - Change the remaining -DWITH/-DWITHOUT to the new -DWANT syntax.
* debian/control:
  - Removed DMUA, I'm a DD now.
  - Changed my e-mail address.
  - Removed unneeded relationships (no upgrades over two releases are
    supported).
  - Fix Suggests for kvirc-dbg.
  - kvirc-data: Make the "Suggests: kvirc" a Recommends, doesn't make much
    sense to install the -data package without the program.
* debian/source/local-options: Added with "unapply-patches".
* debian/kvirc.lintian-overrides: Updated to work for 4.1.1.
* debian/patches/21_make_shared-mime-info_B-D_superfluous.patch: Updated.
* debian/kvirc-data.install: Added .notifyrc.

[ Raúl Sánchez Siles ]
* Stating the right version where kvirc-data break and replace should happen.
* Fixing link to license file.
* Added French and Portuguese man pages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//=============================================================================
2
 
//
3
 
//   File : themefunctions.cpp
4
 
//   Creation date : Wed 03 Jan 2007 03:14:07 by Szymon Stefanek
5
 
//
6
 
//   This file is part of the KVIrc IRC Client distribution
7
 
//   Copyright (C) 2007-2008 Szymon Stefanek <pragma at kvirc dot net>
8
 
//
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.
13
 
//
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.
18
 
//
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.
22
 
//
23
 
//=============================================================================
24
 
 
25
 
#include "themefunctions.h"
26
 
 
27
 
#include "kvi_packagefile.h"
28
 
#include "kvi_locale.h"
29
 
#include "kvi_msgbox.h"
30
 
#include "kvi_app.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"
37
 
 
38
 
 
39
 
//#include <qmime.h>
40
 
 
41
 
 
42
 
namespace KviThemeFunctions
43
 
{
44
 
 
45
 
        static bool notAValidThemePackage(QString &szError)
46
 
        {
47
 
                szError = __tr2qs_ctx("The selected file does not seem to be a valid KVIrc theme package","theme");
48
 
                return false;
49
 
        }
50
 
 
51
 
        bool installThemePackage(const QString &szThemePackageFileName,QString &szError,QWidget * pDialogParent)
52
 
        {
53
 
                KviPointerHashTable<QString,QString> * pInfoFields;
54
 
                QString * pValue;
55
 
                bool bInstall;
56
 
                QPixmap pix;
57
 
                QByteArray * pByteArray;
58
 
                KviHtmlDialogData hd;
59
 
 
60
 
                const char * check_fields[] = { "Name", "Version", "Author", "Description", "Date", "Application" };
61
 
 
62
 
                // check if it is a valid theme file
63
 
                KviPackageReader r;
64
 
 
65
 
                if(!r.readHeader(szThemePackageFileName))
66
 
                {
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);
69
 
                        return false;
70
 
                }
71
 
 
72
 
                pInfoFields = r.stringInfoFields();
73
 
 
74
 
                pValue = pInfoFields->find("PackageType");
75
 
                if(!pValue)
76
 
                        return notAValidThemePackage(szError);
77
 
 
78
 
                if(!KviQString::equalCI(*pValue,"ThemePack"))
79
 
                        return notAValidThemePackage(szError);
80
 
 
81
 
                pValue = pInfoFields->find("ThemePackVersion");
82
 
 
83
 
                if(!pValue)
84
 
                        return notAValidThemePackage(szError);
85
 
 
86
 
                // make sure the default fields exist
87
 
                for(int i=0;i<6;i++)
88
 
                {
89
 
                        pValue = pInfoFields->find(check_fields[i]);
90
 
                        if(!pValue)return notAValidThemePackage(szError);
91
 
                }
92
 
 
93
 
                pValue = pInfoFields->find("ThemeCount");
94
 
                if(!pValue)
95
 
                        return notAValidThemePackage(szError);
96
 
 
97
 
                bool bOk;
98
 
                int iThemeCount = pValue->toInt(&bOk);
99
 
                if(!bOk)
100
 
                        return notAValidThemePackage(szError);
101
 
 
102
 
                if(iThemeCount < 1)
103
 
                        return notAValidThemePackage(szError);
104
 
 
105
 
                // ok.. it should be really valid at this point
106
 
 
107
 
                // load its picture
108
 
                pByteArray = r.binaryInfoFields()->find("Image");
109
 
                if(pByteArray)
110
 
                        pix.loadFromData(*pByteArray,0,0);
111
 
 
112
 
                if(pix.isNull())
113
 
                {
114
 
                        // load the default icon
115
 
                        pix = *(g_pIconManager->getBigIcon(KVI_BIGICON_THEME));
116
 
                }
117
 
 
118
 
                QString szPackageName;
119
 
                QString szPackageVersion;
120
 
                QString szPackageAuthor;
121
 
                QString szPackageDescription;
122
 
                QString szPackageDate;
123
 
                QString szPackageThemeEngineVersion;
124
 
                QString szPackageApplication;
125
 
 
126
 
                QString szAuthor = __tr2qs_ctx("Author","theme");
127
 
                QString szCreatedAt = __tr2qs_ctx("Created at","theme");
128
 
                QString szCreatedOn = __tr2qs_ctx("Created with","theme");
129
 
 
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);
136
 
 
137
 
                QString szWarnings;
138
 
                QString szDetails = "<html><body bgcolor=\"#ffffff\">";
139
 
                QString szTmp;
140
 
 
141
 
                int iIdx = 0;
142
 
                int iValidThemeCount = iThemeCount;
143
 
 
144
 
                while(iIdx < iThemeCount)
145
 
                {
146
 
                        bool bValid = true;
147
 
 
148
 
                        QString szThemeName;
149
 
                        QString szThemeVersion;
150
 
                        QString szThemeDescription;
151
 
                        QString szThemeDate;
152
 
                        QString szThemeSubdirectory;
153
 
                        QString szThemeAuthor;
154
 
                        QString szThemeEngineVersion;
155
 
                        QString szThemeApplication;
156
 
 
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);
176
 
                        if(pByteArray)
177
 
                                pixScreenshot.loadFromData(*pByteArray,0,0);
178
 
 
179
 
                        if(szThemeName.isEmpty() || szThemeVersion.isEmpty() || szThemeSubdirectory.isEmpty() || szThemeEngineVersion.isEmpty())
180
 
                                bValid = false;
181
 
                        if(KviMiscUtils::compareVersions(szThemeEngineVersion,KVI_CURRENT_THEME_ENGINE_VERSION) < 0)
182
 
                                bValid = false;
183
 
 
184
 
                        QString szDetailsBuffer;
185
 
 
186
 
                        getThemeHtmlDescription(
187
 
                                szDetailsBuffer,
188
 
                                szThemeName,
189
 
                                szThemeVersion,
190
 
                                szThemeDescription,
191
 
                                szThemeSubdirectory,
192
 
                                szThemeApplication,
193
 
                                szThemeAuthor,
194
 
                                szThemeDate,
195
 
                                szThemeEngineVersion,
196
 
                                pixScreenshot,
197
 
                                iIdx,&hd
198
 
                        );
199
 
 
200
 
                        if(iIdx > 0)
201
 
                                szDetails += "<hr>";
202
 
 
203
 
                        szDetails += szDetailsBuffer;
204
 
 
205
 
                        if(!bValid)
206
 
                        {
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>";
210
 
                                iValidThemeCount--;
211
 
                        }
212
 
 
213
 
                        iIdx++;
214
 
                }
215
 
 
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>";
220
 
 
221
 
                if(iValidThemeCount < iThemeCount)
222
 
                {
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>";
226
 
                }
227
 
 
228
 
                QString szShowDetails = __tr2qs_ctx("Show Details","theme");
229
 
 
230
 
                KviQString::sprintf(hd.szHtmlText,
231
 
                        "<html bgcolor=\"#ffffff\">" \
232
 
                                "<body bgcolor=\"#ffffff\">" \
233
 
                                        "<p><center>" \
234
 
                                                "<h2>%Q %Q</h2>" \
235
 
                                        "</center></p>" \
236
 
                                        "<p><center>" \
237
 
                                                "<img src=\"theme_dialog_pack_image\">" \
238
 
                                        "</center></p>" \
239
 
                                        "<p><center>" \
240
 
                                                "<i>%Q</i>" \
241
 
                                        "</center></p>" \
242
 
                                        "<p><center>" \
243
 
                                                "%Q: <b>%Q</b><br>" \
244
 
                                                "%Q: <b>%Q</b><br>" \
245
 
                                        "</center></p>" \
246
 
                                        "<p><center>" \
247
 
                                                "<font color=\"#808080\">" \
248
 
                                                        "%Q: %Q<br>" \
249
 
                                                "</font>" \
250
 
                                        "</center></p>" \
251
 
                                        "%Q" \
252
 
                                        "<br>" \
253
 
                                        "<p><center>" \
254
 
                                                "<a href=\"theme_dialog_details\">%Q</a>" \
255
 
                                        "</center></p>" \
256
 
                                "</body>" \
257
 
                        "</html>",
258
 
                        &szPackageName,
259
 
                        &szPackageVersion,
260
 
                        &szPackageDescription,
261
 
                        &szAuthor,
262
 
                        &szPackageAuthor,
263
 
                        &szCreatedAt,
264
 
                        &szPackageDate,
265
 
                        &szCreatedOn,
266
 
                        &szPackageApplication,
267
 
                        &szWarnings,
268
 
                        &szShowDetails
269
 
                );
270
 
 
271
 
                hd.addImageResource("theme_dialog_pack_image",pix);
272
 
                hd.addHtmlResource("theme_dialog_details",szDetails);
273
 
                hd.addHtmlResource("theme_dialog_main",hd.szHtmlText);
274
 
 
275
 
                QString beginCenter = "<center>";
276
 
                QString endCenter = "</center>";
277
 
 
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;
289
 
 
290
 
                bInstall = KviHtmlDialog::display(pDialogParent,&hd) == 2;
291
 
                if(bInstall)
292
 
                {
293
 
                        QString szUnpackPath;
294
 
                        g_pApp->getLocalKvircDirectory(szUnpackPath,KviApp::Themes);
295
 
                        if(!r.unpack(szThemePackageFileName,szUnpackPath))
296
 
                        {
297
 
                                QString szErr2 = r.lastError();
298
 
                                KviQString::sprintf(szError,__tr2qs_ctx("Failed to unpack the selected file: %Q","theme"),&szErr2);
299
 
                                return false;
300
 
                        }
301
 
                }
302
 
 
303
 
                return true;
304
 
        }
305
 
 
306
 
 
307
 
        void getThemeHtmlDescription(
308
 
                QString &szBuffer,
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
320
 
        )
321
 
        {
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");
327
 
 
328
 
                QString szScreenshot;
329
 
                if(!pixScreenshot.isNull())
330
 
                {
331
 
                        KviQString::sprintf(szScreenshot,"<p><center><img src=\"theme_shot%d\"></center></p>",iUniqueIndexInDocument);
332
 
                        QString szTmp;
333
 
                        KviQString::sprintf(szTmp,"theme_shot%d",iUniqueIndexInDocument);
334
 
                        //FIXME in tooltip
335
 
                        if (hd)
336
 
                                hd->addImageResource(szTmp,pixScreenshot);
337
 
                        else szScreenshot = "";
338
 
                } else {
339
 
                        szScreenshot = "";
340
 
                }
341
 
 
342
 
                KviQString::sprintf(
343
 
                        szBuffer,
344
 
                        "<p><center>" \
345
 
                                "<h2>%Q %Q</h2>" \
346
 
                        "</center></p>" \
347
 
                        "%Q" \
348
 
                        "<p><center>" \
349
 
                                "<i>%Q</i>" \
350
 
                        "</center></p>" \
351
 
                        "<p><center>" \
352
 
                                "%Q: <b>%Q</b><br>" \
353
 
                                "%Q: <b>%Q</b><br>" \
354
 
                        "</center></p>" \
355
 
                        "<p><center>" \
356
 
                                "<font color=\"#808080\">" \
357
 
                                        "%Q: %Q<br>" \
358
 
                                        "%Q: %Q<br>" \
359
 
                                        "%Q: %Q<br>" \
360
 
                                "</font>" \
361
 
                        "</center></p>",
362
 
                        &szThemeName,
363
 
                        &szThemeVersion,
364
 
                        &szScreenshot,
365
 
                        &szThemeDescription,
366
 
                        &szAuthor,
367
 
                        &szThemeAuthor,
368
 
                        &szCreatedAt,
369
 
                        &szThemeDate,
370
 
                        &szCreatedOn,
371
 
                        &szThemeApplication,
372
 
                        &szThemeEngineVersion,
373
 
                        &szThemeThemeEngineVersion,
374
 
                        &szSubdirectory,
375
 
                        &szThemeSubdirectory
376
 
                );
377
 
        }
378
 
 
379
 
        bool makeKVIrcScreenshot(const QString &szSavePngFilePath,bool bMaximizeFrame)
380
 
        {
381
 
                if(bMaximizeFrame)
382
 
                {
383
 
                        if(g_pFrame->isMaximized())
384
 
                                bMaximizeFrame = false;
385
 
                }
386
 
 
387
 
                if(bMaximizeFrame)
388
 
                        g_pFrame->showMaximized();
389
 
 
390
 
                QPixmap pix = QPixmap::grabWidget(g_pFrame);
391
 
                bool bResult = true;
392
 
 
393
 
                if(pix.isNull())
394
 
                        bResult = false;
395
 
                else {
396
 
                        if(!pix.save(szSavePngFilePath,"PNG"))
397
 
                                bResult = false;
398
 
                }
399
 
 
400
 
                if(bMaximizeFrame)
401
 
                        g_pFrame->showNormal();
402
 
                return bResult;
403
 
        }
404
 
}
405