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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
|
//============================================================================
//
// File : packaddondialog.cpp
// Creation date : Sat 03 May 2008 01:40:44 by Elvio Basello
//
// This file is part of the KVIrc IRC Client distribution
// Copyright (C) 2008 Elvio Basello <hellvis69 at netsons dot org>
// Copyright (C) 2008 Alessandro Carbone <elfonol at gmail dot com>
//
// 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 "packaddondialog.h"
#include "addonfunctions.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_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"
#include "kvi_tal_textedit.h"
#include <QLayout>
#include <QPushButton>
#include <QLineEdit>
#include <QRegExp>
#include <QMessageBox>
#include <QDir>
#include <QComboBox>
#include <QPainter>
#include <QToolTip>
#include <QImage>
#include <QDateTime>
#include <QBuffer>
#include <QLabel>
#include <QString>
KviPackAddonDialog::KviPackAddonDialog(QWidget * pParent)
: KviTalWizard(pParent)
{
setWindowTitle(__tr2qs_ctx("Create Addon Package - KVIrc","addon"));
setMinimumSize(400,350);
// Welcome page
QWidget * pPage = new QWidget(this);
QGridLayout * pLayout = new QGridLayout(pPage);
QLabel * pLabel = new QLabel(pPage);
QString szText = "<p>";
szText += __tr2qs_ctx("This procedure allows you to export the selected addon to a single package. It is useful when you want to distribute your addon to the public.","addon");
szText += "</p><p>";
szText += __tr2qs_ctx("You will be asked to provide a package name, a version and a description.","addon");
szText += "</p><p>";
szText += __tr2qs_ctx("Hit the \"Next\" button to begin.","addon");
szText += "<p>";
pLabel->setText(szText);
pLayout->addWidget(pLabel,0,0);
pLayout->setRowStretch(1,1);
addPage(pPage,__tr2qs_ctx("Welcome","addon"));
setBackEnabled(pPage,false);
setNextEnabled(pPage,true);
setHelpEnabled(pPage,false);
setFinishEnabled(pPage,false);
// Packager informations
m_pPackAddonInfoCreateWidget=new KviPackAddonCreateInfoPackageWidget(this);
addPage(m_pPackAddonInfoCreateWidget,__tr2qs_ctx("Package Informations","addon"));
setBackEnabled(m_pPackAddonInfoCreateWidget,true);
setHelpEnabled(m_pPackAddonInfoCreateWidget,false);
setNextEnabled(m_pPackAddonInfoCreateWidget,true);
setFinishEnabled(m_pPackAddonInfoCreateWidget,false);
// File selection
m_pPackAddonFileSelectionWidget = new KviPackAddonFileSelectionWidget(this);
addPage(m_pPackAddonFileSelectionWidget,__tr2qs_ctx("Package Files","addon"));
setBackEnabled(m_pPackAddonFileSelectionWidget,true);
setHelpEnabled(m_pPackAddonFileSelectionWidget,false);
setNextEnabled(m_pPackAddonFileSelectionWidget,true);
setFinishEnabled(m_pPackAddonFileSelectionWidget,false);
// Save selection
m_pPackAddonSaveSelectionWidget = new KviPackAddonSaveSelectionWidget(this);
addPage(m_pPackAddonSaveSelectionWidget,__tr2qs_ctx("Save Package","addon"));
setBackEnabled(m_pPackAddonFileSelectionWidget,true);
setHelpEnabled(m_pPackAddonFileSelectionWidget,false);
setNextEnabled(m_pPackAddonFileSelectionWidget,true);
setFinishEnabled(m_pPackAddonFileSelectionWidget,false);
// Final results
m_pPackAddonInfoWidget=new KviPackAddonInfoWidget(this);
addPage(m_pPackAddonInfoWidget,__tr2qs_ctx("Final Informations","addon"));
setBackEnabled(m_pPackAddonInfoWidget,true);
setHelpEnabled(m_pPackAddonInfoWidget,false);
setNextEnabled(m_pPackAddonInfoWidget,false);
setFinishEnabled(m_pPackAddonInfoWidget,true);
}
void KviPackAddonDialog::accept()
{
if(!packAddon())return;
KviTalWizard::accept();
}
bool KviPackAddonDialog::packAddon()
{
// Let's create the addon package
QString szPackageAuthor = m_pPackAddonInfoCreateWidget->authorName();
QString szPackageName = m_pPackAddonInfoCreateWidget->packageName();
QString szPackageVersion = m_pPackAddonInfoCreateWidget->packageVersion();
QString szPackageDescription = m_pPackAddonInfoCreateWidget->packageDescription();
QString szSourcePath = m_pPackAddonFileSelectionWidget->sourcePath();
QString szConfigPath = m_pPackAddonFileSelectionWidget->configPath();
QString szImagePath = m_pPackAddonFileSelectionWidget->imagePath();
QString szLocalePath = m_pPackAddonFileSelectionWidget->localePath();
QString szHelpPath = m_pPackAddonFileSelectionWidget->helpPath();
QString szSoundPath = m_pPackAddonFileSelectionWidget->soundPath();
QString szInstallPath = m_pPackAddonFileSelectionWidget->installerPath();
QString szPackagePath = m_pPackAddonSaveSelectionWidget->savePath();
// We need mandatory unix like path separator
szSourcePath.replace('\\',"/");
szConfigPath.replace('\\',"/");
szImagePath.replace('\\',"/");
szLocalePath.replace('\\',"/");
szHelpPath.replace('\\',"/");
szSoundPath.replace('\\',"/");
szInstallPath.replace('\\',"/");
szPackagePath.replace('\\',"/");
QString szTmp = QDateTime::currentDateTime().toString();
KviPackageWriter pw;
pw.addInfoField("PackageType","AddonPack");
pw.addInfoField("AddonPackVersion",KVI_CURRENT_ADDONS_ENGINE_VERSION);
pw.addInfoField("Name",szPackageName);
pw.addInfoField("Version",szPackageVersion);
pw.addInfoField("Author",szPackageAuthor);
pw.addInfoField("Description",szPackageDescription);
pw.addInfoField("Date",szTmp);
pw.addInfoField("Application","KVIrc " KVI_VERSION "." KVI_SOURCES_DATE);
// Add source dir
if(!pw.addDirectory(szSourcePath,"src/"))
{
szTmp = __tr2qs_ctx("Packaging failed","addon");
szTmp += ": ";
szTmp += pw.lastError();
QMessageBox::critical(this,__tr2qs_ctx("Export Addon - KVIrc","addon"),szTmp,QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton);
}
// Add config dir
if(!pw.addDirectory(szConfigPath,"config/scripts/"))
{
szTmp = __tr2qs_ctx("Packaging failed","addon");
szTmp += ": ";
szTmp += pw.lastError();
QMessageBox::critical(this,__tr2qs_ctx("Export Addon - KVIrc","addon"),szTmp,QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton);
}
// Add image dir
if(!pw.addDirectory(szImagePath,"pics/"))
{
szTmp = __tr2qs_ctx("Packaging failed","addon");
szTmp += ": ";
szTmp += pw.lastError();
QMessageBox::critical(this,__tr2qs_ctx("Export Addon - KVIrc","addon"),szTmp,QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton);
}
// Add localization dir
if(!pw.addDirectory(szLocalePath,"locale/"))
{
szTmp = __tr2qs_ctx("Packaging failed","addon");
szTmp += ": ";
szTmp += pw.lastError();
QMessageBox::critical(this,__tr2qs_ctx("Export Addon - KVIrc","addon"),szTmp,QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton);
}
// Add help dir
if(!pw.addDirectory(szImagePath,"help/en/"))
{
szTmp = __tr2qs_ctx("Packaging failed","addon");
szTmp += ": ";
szTmp += pw.lastError();
QMessageBox::critical(this,__tr2qs_ctx("Export Addon - KVIrc","addon"),szTmp,QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton);
}
// Add sound dir
if(!pw.addDirectory(szImagePath,"audio/"))
{
szTmp = __tr2qs_ctx("Packaging failed","addon");
szTmp += ": ";
szTmp += pw.lastError();
QMessageBox::critical(this,__tr2qs_ctx("Export Addon - KVIrc","addon"),szTmp,QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton);
}
// Add installer script
if(!pw.addFile(szInstallPath,"install.kvs"))
{
szTmp = __tr2qs_ctx("Packaging failed","addon");
szTmp += ": ";
szTmp += pw.lastError();
QMessageBox::critical(this,__tr2qs_ctx("Export Addon - KVIrc","addon"),szTmp,QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton);
}
// Create the addon package
if(szPackagePath.isEmpty())
{
szPackagePath = QDir::homePath();
KviQString::ensureLastCharIs(szPackagePath,QChar(KVI_PATH_SEPARATOR_CHAR));
szPackagePath += szPackageName;
szPackagePath += "-";
szPackagePath += szPackageVersion;
szPackagePath += ".";
szPackagePath += KVI_FILEEXTENSION_ADDONPACKAGE;
qDebug("Addon name used: %s",szPackagePath.toUtf8().data());
}
if(!pw.pack(szPackagePath))
{
szTmp = __tr2qs_ctx("Packaging failed","addon");
szTmp += ": ";
szTmp += pw.lastError();
QMessageBox::critical(this,__tr2qs_ctx("Export Addon - KVIrc","addon"),szTmp,QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton);
return false;
}
QMessageBox::information(this,__tr2qs_ctx("Export Addon - KVIrc","addon"),__tr2qs("Package saved successfully in ") + szPackagePath,QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton);
return true;
}
KviPackAddonCreateInfoPackageWidget::KviPackAddonCreateInfoPackageWidget(KviPackAddonDialog *pParent)
:QWidget(pParent)
{
QString szPackageName = "MyAddon";
QString szPackageAuthor = __tr2qs_ctx("Your name here","addon");
QString szPackageDescription = __tr2qs_ctx("Put a package description here...","addon");
QString szPackageVersion = "1.0.0";
QGridLayout *pLayout = new QGridLayout(this);
QLabel *pLabel = new QLabel(this);
pLabel->setText(__tr2qs_ctx("Here you need to provide informations about you (the packager) and a short description of the package you're creating.","addon"));
pLabel->setWordWrap(true);
pLabel->setTextFormat(Qt::RichText);
pLayout->addWidget(pLabel,0,0,1,2);
pLabel = new QLabel(this);
pLabel->setText(__tr2qs_ctx("Package Author:","addon"));
pLayout->addWidget(pLabel,1,0);
m_pAuthorNameEdit = new QLineEdit(this);
m_pAuthorNameEdit->setText(szPackageAuthor);
pLayout->addWidget(m_pAuthorNameEdit,1,1);
pLabel = new QLabel(this);
pLabel->setText(__tr2qs_ctx("Package Name:","addon"));
pLayout->addWidget(pLabel,2,0);
m_pPackageNameEdit = new QLineEdit(this);
m_pPackageNameEdit->setText(szPackageName);
pLayout->addWidget(m_pPackageNameEdit,2,1);
pLabel = new QLabel(this);
pLabel->setText(__tr2qs_ctx("Package Version:","addon"));
pLayout->addWidget(pLabel,3,0);
m_pPackageVersionEdit = new QLineEdit(this);
m_pPackageVersionEdit->setText(szPackageVersion);
pLayout->addWidget(m_pPackageVersionEdit,3,1);
pLabel = new QLabel(this);
pLabel->setText(__tr2qs_ctx("Package Description:","addon"));
pLayout->addWidget(pLabel,4,0);
m_pPackageDescriptionEdit = new KviTalTextEdit(this);
m_pPackageDescriptionEdit->setBackgroundRole(QPalette::Window);
m_pPackageDescriptionEdit->setText(szPackageDescription);
pLayout->addWidget(m_pPackageDescriptionEdit,4,1,1,2);
pLayout->setRowStretch(1,1);
}
KviPackAddonFileSelectionWidget::KviPackAddonFileSelectionWidget(KviPackAddonDialog *pParent)
: QWidget(pParent)
{
QGridLayout * pLayout = new QGridLayout(this);
QLabel * pLabel = new QLabel(this);
pLabel->setText(__tr2qs_ctx("Here you need to provide the real informations for the addon.","addon"));
pLayout->addWidget(pLabel,0,0);
// Select installer script
m_pInstallPathSelector = new KviFileSelector(this,__tr2qs_ctx("Select installer script:","addon"),&szInstallPath,true,0,"*.kvs");
pLayout->addWidget(m_pInstallPathSelector,1,0);
// Select script dir
m_pSourcePathSelector = new KviDirectorySelector(this,__tr2qs_ctx("Select scripts directory:","addon"),&szSourcePath,true);
pLayout->addWidget(m_pSourcePathSelector,2,0);
// Select config dir
m_pConfigPathSelector = new KviDirectorySelector(this,__tr2qs_ctx("Select config directory:","addon"),&szConfigPath,true);
pLayout->addWidget(m_pConfigPathSelector,3,0);
// Select image dir
m_pImagePathSelector = new KviDirectorySelector(this,__tr2qs_ctx("Select images directory:","addon"),&szImagePath,true);
pLayout->addWidget(m_pImagePathSelector,4,0);
// Select localization dir
m_pLocalePathSelector = new KviDirectorySelector(this,__tr2qs_ctx("Select localization directory:","addon"),&szLocalePath,true);
pLayout->addWidget(m_pLocalePathSelector,5,0);
// Select help dir
m_pHelpPathSelector = new KviDirectorySelector(this,__tr2qs_ctx("Select help directory:","addon"),&szHelpPath,true);
pLayout->addWidget(m_pHelpPathSelector,6,0);
// Select sound dir
m_pSoundPathSelector = new KviDirectorySelector(this,__tr2qs_ctx("Select sounds directory:","addon"),&szSoundPath,true);
pLayout->addWidget(m_pSoundPathSelector,7,0);
}
KviPackAddonSaveSelectionWidget::KviPackAddonSaveSelectionWidget(KviPackAddonDialog *pParent)
: QWidget(pParent)
{
QGridLayout * pLayout = new QGridLayout(this);
QLabel * pLabel = new QLabel(this);
pLabel->setText(__tr2qs_ctx("Here you need to provide the path where to save the addon package","addon"));
pLayout->addWidget(pLabel,0,0);
// Create addon name
KviPackAddonCreateInfoPackageWidget * pCreateWidget=pParent->m_pPackAddonInfoCreateWidget;
szSavePath = QDir::homePath();
KviQString::ensureLastCharIs(szSavePath,QChar(KVI_PATH_SEPARATOR_CHAR));
szSavePath += pCreateWidget->packageName();
szSavePath += "-";
szSavePath += pCreateWidget->packageVersion();
szSavePath += ".";
szSavePath += KVI_FILEEXTENSION_ADDONPACKAGE;
qDebug("Addon name selected: %s",szSavePath.toUtf8().data());
// Setting dialog filter
QString szFilter = "*.";
szFilter += KVI_FILEEXTENSION_ADDONPACKAGE;
// Select save path
m_pSavePathSelector = new KviFileSelector(this,__tr2qs_ctx("Select save path:","addon"),&szSavePath,true,KviFileSelector::ChooseSaveFileName,szFilter);
pLayout->addWidget(m_pSavePathSelector,1,0);
}
KviPackAddonInfoWidget::KviPackAddonInfoWidget(KviPackAddonDialog *pParent)
:QWidget(pParent)
{
m_pParent=pParent;
QGridLayout *pLayout = new QGridLayout(this);
QLabel *pLabel = new QLabel(this);
pLabel->setText(__tr2qs_ctx("Here there are the informations you provided. If they are correct, hit the \"Finish\" button to complete the packaging operations.","addon"));
pLabel->setWordWrap(true);
pLayout->addWidget(pLabel,0,0);
m_pLabelInfo = new QLabel(this);
pLayout->addWidget(m_pLabelInfo,1,0);
}
void KviPackAddonInfoWidget::showEvent(QShowEvent *)
{
KviPackAddonCreateInfoPackageWidget * pCreateWidget=m_pParent->m_pPackAddonInfoCreateWidget;
KviPackAddonFileSelectionWidget * pFileWidget = m_pParent->m_pPackAddonFileSelectionWidget;
KviPackAddonSaveSelectionWidget * pSaveWidget = m_pParent->m_pPackAddonSaveSelectionWidget;
QString szText = __tr2qs_ctx("This is what I will check for","addon") + "<br>";
szText += "<b>" + __tr2qs_ctx("Package Author","addon") + ":</b> " + pCreateWidget->authorName() + "<br>";
szText += "<b>" + __tr2qs_ctx("Package Name","addon") + ":</b> " + pCreateWidget->packageName() + "<br>";
szText += "<b>" + __tr2qs_ctx("Package Version","addon") + ":</b> " + pCreateWidget->packageVersion() + "<br>";
szText += "<b>" + __tr2qs_ctx("Package Description","addon") + ":</b> " + pCreateWidget->packageDescription() + "<br><br>";
szText += "<b>" + __tr2qs_ctx("Installer Script","addon") + ":</b> " + pFileWidget->installerPath() + "<br>";
szText += "<b>" + __tr2qs_ctx("Source Directory","addon") + ":</b> " + pFileWidget->sourcePath() + "<br>";
szText += "<b>" + __tr2qs_ctx("Configuration Directory","addon") + ":</b> " + pFileWidget->configPath() + "<br>";
szText += "<b>" + __tr2qs_ctx("Image Directory","addon") + ":</b> " + pFileWidget->imagePath() + "<br>";
szText += "<b>" + __tr2qs_ctx("Localization Directory","addon") + ":</b> " + pFileWidget->localePath() + "<br>";
szText += "<b>" + __tr2qs_ctx("Help Directory","addon") + ":</b> " + pFileWidget->helpPath() + "<br>";
szText += "<b>" + __tr2qs_ctx("Sound Directory","addon") + ":</b> " + pFileWidget->soundPath() + "<br>";
szText += "<b>" + __tr2qs_ctx("Save Path","addon") + ":</b> " + pSaveWidget->savePath();
m_pLabelInfo->setText(szText);
}
|