-
Notifications
You must be signed in to change notification settings - Fork 6
/
tufaowizard.cpp
129 lines (102 loc) · 4.66 KB
/
tufaowizard.cpp
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
/* This file is part of the Tufão project
Copyright (C) 2012, 2013 Vinícius dos Santos Oliveira <vini.ipsmaker@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any
later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "tufaowizard.h"
#include "projecttypewizardpage.h"
#include <projectexplorer/customwizard/customwizard.h>
#include <QVariant>
#include <QDir>
#include <QFileInfo>
#include <QFile>
#include "tufaoconstants.h"
namespace Tufao {
TufaoWizardDialog::TufaoWizardDialog(QWidget *parent, const Core::WizardDialogParameters ¶meters) :
ProjectExplorer::BaseProjectWizardDialog(parent, parameters)
{
setWindowTitle(trUtf8("New Tufão Web Server Project"));
setIntroDescription(trUtf8("This wizard generates a"
" Tufão web server project."));
}
TufaoWizard::TufaoWizard(QObject *parent)
{
setWizardKind(ProjectWizard);
setIcon(QIcon(QString::fromUtf8(":/icon.png")));
setDisplayName(QString::fromUtf8("Tufão Web Server"));
setId(QString::fromUtf8(Tufao::Constants::TUFAO_WIZARD_ID));
setDescription(QString::fromUtf8("Creates a Tufão web server project."));
// QLatin1String(ProjectExplorer::Constants::QT_APPLICATION_WIZARD_CATEGORY)
setCategory(QString::fromUtf8(Constants::TUFAO_WIZARD_CATEGORY));
// QLatin1String(ProjectExplorer::Constants::QT_APPLICATION_WIZARD_CATEGORY_DISPLAY)
setDisplayCategory(trUtf8(Constants::TUFAO_WIZARD_TR_CATEGORY));
}
QWizard *TufaoWizard::createWizardDialog(QWidget *parent,
const Core::WizardDialogParameters &
wizardDialogParameters) const
{
TufaoWizardDialog *wizard
= new TufaoWizardDialog(parent, wizardDialogParameters);
wizard->addPage(new ProjectTypeWizardPage);
{
const WizardPageList &
extensionPages(wizardDialogParameters.extensionPages());
foreach (QWizardPage *p, extensionPages)
BaseFileWizard::applyExtensionPageShortTitle(wizard,
wizard->addPage(p));
}
return wizard;
}
Core::GeneratedFiles TufaoWizard::generateFiles(const QWizard *w,
QString *errorMessage) const
{
Q_UNUSED(errorMessage)
const TufaoWizardDialog *wizard = qobject_cast<const TufaoWizardDialog*>(w);
QString projectType = wizard->field(QString::fromUtf8("type")).toString();
QString projectName = wizard->projectName();
QString projectPath = wizard->path() + QString::fromUtf8("/") + projectName
+ QString::fromUtf8("/");
Core::GeneratedFiles ret;
{
QFile t(QString::fromUtf8(":/templates/metadata/") + projectType
+ QString::fromUtf8("/project.pro"));
t.open(QIODevice::ReadOnly);
QString content = QString::fromUtf8(t.readAll().constData())
.arg(projectName);
Core::GeneratedFile f(projectPath + projectName
+ QString::fromUtf8(".pro"));
f.setAttributes(Core::GeneratedFile::OpenProjectAttribute);
f.setContents(content);
ret.push_back(f);
}
QStringList files = QDir(QString::fromUtf8(":/templates/data/")
+ projectType).entryList();
for (QStringList::iterator i = files.begin();i != files.end();++i) {
QFile t(QString::fromUtf8(":/templates/data/") + projectType
+ QString::fromUtf8("/") + *i);
t.open(QIODevice::ReadOnly);
Core::GeneratedFile f(projectPath + *i);
f.setBinaryContents(t.readAll());
if (*i != QString::fromUtf8("main.cpp"))
f.setAttributes(Core::GeneratedFile::OpenEditorAttribute);
ret.push_back(f);
}
return ret;
}
bool TufaoWizard::postGenerateFiles(const QWizard *,
const Core::GeneratedFiles &l,
QString *errorMessage)
{
return ProjectExplorer::CustomProjectWizard::postGenerateOpen(l,
errorMessage);
}
} // namespace Tufao