1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
|
//=============================================================================
//
// File : savethemedialog.cpp
// Created on Wed 03 Jan 2007 03:01:34 by Szymon Stefanek
//
// This file is part of the KVIrc IRC Client distribution
// Copyright (C) 2007 Szymon Stefanek <pragma at kvirc dot net>
//
// This program is FREE software. You can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your opinion) any later version.
//
// This program is distributed in the HOPE that it will be USEFUL,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, write to the Free Software Foundation,
// Inc. ,51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
//=============================================================================
#include "savethemedialog.h"
#include "themefunctions.h"
#include <qlayout.h>
#include <qpushbutton.h>
#include <qlineedit.h>
#include <qregexp.h>
#include <qmessagebox.h>
#include <qdir.h>
#include <qcombobox.h>
#include <qpainter.h>
#include <qtooltip.h>
#include <qimage.h>
#include <kvi_tal_textedit.h>
#ifdef COMPILE_USE_QT4
#include <q3multilineedit.h>
#include <QDateTime>
#else
#include <qmultilineedit.h>
#endif
#include <qbuffer.h>
#include <qlabel.h>
#include "kvi_options.h"
#include "kvi_locale.h"
#include "kvi_config.h"
#include "kvi_fileutils.h"
#include "kvi_app.h"
#include "kvi_frame.h"
#include "kvi_iconmanager.h"
#include "kvi_styled_controls.h"
#include "kvi_packagefile.h"
#include "kvi_fileextensions.h"
#include "kvi_filedialog.h"
#include "kvi_msgbox.h"
#include "kvi_selectors.h"
#include "kvi_miscutils.h"
#include "kvi_sourcesdate.h"
KviSaveThemeDialog::KviSaveThemeDialog(QWidget * pParent)
: KviTalWizard(pParent)
{
setCaption(__tr2qs_ctx("Save Current Theme - KVIrc","theme"));
setMinimumSize(400,350);
// welcome page ==================================================================================
QWidget * pPage = new QWidget(this);
QGridLayout * pLayout = new QGridLayout(pPage,2,1,4,4);
QLabel * pLabel = new QLabel(pPage);
QString szText = "<p>";
szText += __tr2qs_ctx("This procedure allows you to save the current theme settings to a single directory. It is useful if you want to apply other themes or play with the theme settings and later come back to this theme with a single click. It will also allow you to manually modify the theme settings and later export them to a distributable package.","theme");
szText += "</p><p>";
szText += __tr2qs_ctx("You will be asked to provide a theme name, a description and, if you want, a screenshot.","theme");
szText += "</p><p>";
szText += __tr2qs_ctx("Hit the \"Next\" button to begin.","theme");
szText += "<p>";
pLabel->setText(szText);
pLayout->addWidget(pLabel,0,0);
pLayout->setRowStretch(1,1);
addPage(pPage,__tr2qs_ctx("Welcome","theme"));
setBackEnabled(pPage,false);
setNextEnabled(pPage,true);
setHelpEnabled(pPage,false);
setFinishEnabled(pPage,false);
// packager informations ================================================================================
pPage = new QWidget(this);
pLayout = new QGridLayout(pPage,5,2,4,4);
pLabel = new QLabel(pPage);
pLabel->setText(__tr2qs_ctx("Here you need to provide informations about you (the author) and a short description of the theme you're creating.","theme"));
pLabel->setTextFormat(Qt::RichText);
pLayout->addMultiCellWidget(pLabel,0,0,0,1);
pLabel = new QLabel(pPage);
pLabel->setText(__tr2qs_ctx("Theme Name:","theme"));
pLayout->addWidget(pLabel,1,0);
m_pThemeNameEdit = new QLineEdit(pPage);
//m_pThemeNameEdit->setText(szThemeName);
pLayout->addWidget(m_pThemeNameEdit,1,1);
pLabel = new QLabel(pPage);
pLabel->setText(__tr2qs_ctx("Version:","theme"));
pLayout->addWidget(pLabel,2,0);
m_pThemeVersionEdit = new QLineEdit(pPage);
//m_pThemeVersionEdit->setText(szThemeVersion);
pLayout->addWidget(m_pThemeVersionEdit,2,1);
pLabel = new QLabel(pPage);
pLabel->setText(__tr2qs_ctx("Description:","theme"));
pLayout->addWidget(pLabel,3,0);
m_pThemeDescriptionEdit = new KviTalTextEdit(pPage);
//m_pThemeDescriptionEdit->setText(szThemeDescription);
pLayout->addWidget(m_pThemeDescriptionEdit,3,1);
pLabel = new QLabel(pPage);
pLabel->setText(__tr2qs_ctx("Theme Author:","theme"));
pLayout->addWidget(pLabel,4,0);
m_pAuthorNameEdit = new QLineEdit(pPage);
//m_pAuthorNameEdit->setText(szThemeAuthor);
pLayout->addWidget(m_pAuthorNameEdit,4,1);
pLayout->setRowStretch(3,1);
pLayout->setColStretch(1,1);
addPage(pPage,__tr2qs_ctx("Theme Informations","theme"));
setBackEnabled(pPage,true);
setHelpEnabled(pPage,false);
setNextEnabled(pPage,true);
setFinishEnabled(pPage,false);
// screenshot/logo/icon ================================================================================
pPage = new QWidget(this);
pLayout = new QGridLayout(pPage,4,1,4,4);
pLabel = new QLabel(pPage);
pLabel->setText(__tr2qs_ctx("Here you can either choose a screenshot image from disk or make one now. The screenshot will be displayed in the tooltips of the theme management dialog and will be also visible in the package installation dialog if you will export the theme to a distributable package.","theme"));
pLabel->setTextFormat(Qt::RichText);
pLayout->addWidget(pLabel,0,0);
m_pImageLabel = new QLabel(pPage);
m_pImageLabel->setFrameStyle(QFrame::Sunken | QFrame::Panel);
m_pImageLabel->setMinimumSize(300,225);
m_pImageLabel->setAlignment(Qt::AlignCenter | Qt::AlignVCenter);
pLayout->addWidget(m_pImageLabel,1,0);
QString szFilter = "*.png *.jpg *.xpm";
m_pImageSelector = new KviFileSelector(pPage,"",&m_szScreenshotPath,true,0,szFilter);
connect(m_pImageSelector,SIGNAL(selectionChanged(const QString &)),this,SLOT(imageSelectionChanged(const QString &)));
pLayout->addWidget(m_pImageSelector,2,0);
QPushButton * pButton = new QPushButton(pPage);
pButton->setText(__tr2qs_ctx("Make Screenshot Now","theme"));
connect(pButton,SIGNAL(clicked()),this,SLOT(makeScreenshot()));
pLayout->addWidget(pButton,3,0);
pLayout->setRowStretch(1,1);
m_pImageSelectionPage = pPage;
addPage(pPage,__tr2qs_ctx("Screenshot","theme"));
setBackEnabled(pPage,true);
setHelpEnabled(pPage,false);
setNextEnabled(pPage,true);
setFinishEnabled(pPage,true);
}
KviSaveThemeDialog::~KviSaveThemeDialog()
{
}
void KviSaveThemeDialog::imageSelectionChanged(const QString &szImagePath)
{
QImage pix(szImagePath);
if(!pix.isNull())
{
QPixmap out;
if(pix.width() > 300 || pix.height() > 225)
#ifdef COMPILE_USE_QT4
out.convertFromImage(pix.scaled(300,225,Qt::KeepAspectRatio));
#else
out.convertFromImage(pix.smoothScale(300,225,QImage::ScaleMin));
#endif
else
out.convertFromImage(pix);
m_pImageLabel->setPixmap(out);
return;
}
QMessageBox::critical(this,__tr2qs_ctx("Save Current Theme - KVIrc","theme"),__tr2qs_ctx("Failed to load the selected image","theme"),
QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton);
m_pImageSelector->setSelection("");
m_pImageLabel->setPixmap(QPixmap());
}
void KviSaveThemeDialog::accept()
{
if(!saveTheme())return;
KviTalWizard::accept();
}
void KviSaveThemeDialog::makeScreenshot()
{
QString szFileName;
g_pApp->getTmpFileName(szFileName,"screenshot.png");
if(!KviThemeFunctions::makeKVIrcScreenshot(szFileName))
{
QMessageBox::critical(this,__tr2qs_ctx("Acquire Screenshot - KVIrc","theme"),__tr2qs_ctx("Failed to make screenshot","theme"),
QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton);
return;
}
m_pImageSelector->setSelection(szFileName);
imageSelectionChanged(szFileName);
}
bool KviSaveThemeDialog::saveTheme()
{
m_pImageSelector->commit();
KviThemeInfo sto;
sto.setName(m_pThemeNameEdit->text());
if(sto.name().isEmpty())
{
QMessageBox::critical(this,__tr2qs_ctx("Save Current Theme - KVIrc","theme"),__tr2qs_ctx("You must choose a theme name!","theme"),QMessageBox::Ok,
QMessageBox::NoButton,QMessageBox::NoButton);
return false;
}
sto.setAuthor(m_pAuthorNameEdit->text());
sto.setDescription(m_pThemeDescriptionEdit->text());
sto.setDate(QDateTime::currentDateTime().toString());
sto.setVersion(m_pThemeVersionEdit->text());
sto.setApplication("KVIrc " KVI_VERSION "." KVI_SOURCES_DATE);
if(sto.version().isEmpty())sto.setVersion("1.0.0");
QString szSubdir = sto.name() + QString("-") + sto.version();
szSubdir.replace(QRegExp("[ \\\\/:][ \\\\/:]*"),"_");
sto.setSubdirectory(szSubdir);
QString szAbsDir;
g_pApp->getLocalKvircDirectory(szAbsDir,KviApp::Themes,sto.subdirectory(),true);
if(!KviFileUtils::makeDir(szAbsDir))
{
QMessageBox::critical(this,__tr2qs_ctx("Save Current Theme - KVIrc","theme"),__tr2qs_ctx("Unable to create theme directory.","theme"),
QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton);
return false;
}
sto.setAbsoluteDirectory(szAbsDir);
if(!KviTheme::save(sto))
{
QString szMsg2;
QString szErr = sto.lastError();
KviQString::sprintf(szMsg2,__tr2qs_ctx("Unable to save theme: %Q","theme"),&szErr);
QMessageBox::critical(this,__tr2qs_ctx("Save Current Theme - KVIrc","theme"),szMsg2,
QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton);
return false;
}
// write down the screenshot, if needed
if(!m_szScreenshotPath.isEmpty())
{
if(!KviTheme::saveScreenshots(sto,m_szScreenshotPath))
{
QMessageBox::critical(this,__tr2qs_ctx("Save Current Theme - KVIrc","theme"),__tr2qs_ctx("Failed to load the selected screenshot image: please fix it","theme"),
QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton);
setCurrentPage(m_pImageSelectionPage);
return false;
}
}
QString szMsg = __tr2qs_ctx("Theme saved successfully to ","theme");
szMsg += sto.absoluteDirectory();
QMessageBox::information(this,__tr2qs_ctx("Save Theme - KVIrc","theme"),szMsg,QMessageBox::Ok,
QMessageBox::NoButton,QMessageBox::NoButton);
return true;
}
|