/
wizard.cpp
240 lines (198 loc) · 6.66 KB
/
wizard.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
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
#include "wizard.h"
#include "ui_wizard.h"
Wizard::Wizard(QWidget *parent) :
QWizard(parent),
m_ui(new Ui::Wizard)
{
m_ui->setupUi(this);
this->setFixedSize(600,500);
this->projectDir = new QDir;
setConnexions();
QFile test("/home/mehdi/testoun");
}
Wizard::~Wizard()
{
delete m_ui;
}
void Wizard::setConnexions()
{
connect(m_ui->bypassCheck,SIGNAL(clicked()),this,SLOT(bypassXML()));
connect(this,SIGNAL(accepted()),this,SLOT(createProject())); // Finish pushButton
connect(m_ui->browseButton,SIGNAL(clicked()),SLOT(setDirectory()));
connect(m_ui->projectNameEdit,SIGNAL(textEdited(QString)),this,SLOT(editText(QString)));
}
void Wizard::changeEvent(QEvent *e)
{
QWizard::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
m_ui->retranslateUi(this);
break;
default:
break;
}
}
void Wizard::setPages()
{
}
void Wizard::sourceFileDefault()
{
QFile *file= new QFile(directory+"/"+projectName+"/"+sourceFile);
if( !file->open(QIODevice::WriteOnly) )
{
return;
}
QTextStream input(file);
/* input<< "#include <stdio.h>"<<endl;
input << "#include \"msg/msg.h\""<<endl;
input << "#include \"xbt/sysdep.h\""<<endl;
input << "// Create a log channel to have nice outputs."<<endl;
input << "#include \"xbt/log.h\""<<endl;
input << "#include \"xbt/asserts.h\""<<endl;
input << "XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,\"Messages specific for this msg example\");"<<endl<<endl<<endl;*/
file->close();
srcFiles.append(file);
return;
}
void Wizard::platformFileDefault()
{
QFile *file = new QFile(directory+"/"+projectName+"/"+platformFile);
if( !file->open(QIODevice::WriteOnly) )
{
return;
}
QTextStream input(file);
input<< "<?xml version='1.0'?>"<<endl;
input<< "<!DOCTYPE platform SYSTEM \"simgrid.dtd\">"<<endl;
input<< "<platform version=\"2\">"<<endl;
input<< "</platform>"<<endl;
file->close();
xmlFiles.append(file);
return;
}
void Wizard::deployFileDefault()
{
QFile *file = new QFile(directory+"/"+projectName+"/"+deployFile);
if( !file->open(QIODevice::WriteOnly) )
{
return;
}
QTextStream input(file);
input<< "<?xml version='1.0'?>"<<endl;
input<< "<!DOCTYPE platform SYSTEM \"simgrid.dtd\">"<<endl;
input<< "<platform version=\"2\">"<<endl;
input<< "</platform>"<<endl;
file->close();
xmlFiles.append(file);
return;
}
void Wizard::setMakeFile()
{
QFile file(directory+"/"+projectName+"/Makefile");
if( !file.open(QIODevice::WriteOnly) )
{
return;
}
QStringList fileSources;
QString main;
foreach(QFile* src,srcFiles)
{
QFileInfo info(*src);
fileSources.append(info.fileName());
}
main = fileSources.at(0);
QTextStream input(&file);
QString headers = "## Variable declarations\n"
"\nPROJECT_NAME= masterslave_mailbox\n"
"\nDISTDIR= "+this->projectName+"\n"
"# Set the GRID_ROOT environment variable to the path under which you installed SimGrid\n"
"# Compilation will fail if you don't do so\n"
"GRID_ROOT?= $(shell if [ -e /usr/local/lib/libsimgrid.so ] ; then echo /usr/local; else echo \"\"<<<< SIMGRID undefined !!! >>>>\\""; fi)\n"
"# You can fiddle the following to make it fit your taste\n"
"INCLUDES = -I$(GRID_ROOT)/include\n"
"CFLAGS ?= -O3 -w -g -Wall\n"
"LIBS_SIM = -lm -L$(GRID_ROOT)/lib/ -lsimgrid\n"
"LIBS =\n";
QString sources = "SRC_FILES = ";
foreach(QString name,fileSources)
{
sources.append(name+"\t");
}
sources += "\nOBJ_FILES = $(patsubst %.c,%.o,$(SRC_FILES))\n"
"BIN_FILES = "+ this->projectName +"\n";
QString rules = "## By default, build all the binaries\n"
"all: $(BIN_FILES)\n"
"## Generate the binaries\n"
+
this->projectName+": "+main.split(".").at(0)+".o $(OBJ_FILES)\n"
+
"\t$(CC) $(INCLUDES) $(DEFS) $(CFLAGS) $^ $(LIBS_SIM) $(LIBS) $(LDADD) -o $@ \n"
"%: %.o\n"
"\t$(CC) $(INCLUDES) $(DEFS) $(CFLAGS) $^ $(LIBS) $(LDADD) -o $@ \n"
"%.o: %.c\n"
"\t$(CC) $(INCLUDES) $(DEFS) $(CFLAGS) -c -o $@ $< \n";
QString cleanups ="## Rules for tarballs and cleaning\n"
"DIST_FILES= $(EXTRA_DIST) $(PRECIOUS_C_FILES) Makefile\n"
"distdir: $(DIST_FILES)\n"
"\trm -rf $(DISTDIR) mkdir -p $(DISTDIR) cp $^ $(DISTDIR)\n"
"\tdist: clean distdir tar c $(DISTDIR) | gzip -c9 > $(DISTDIR).tar.gz\n"
"clean:\n"
"\trm -rf $(DISTDIR) *.o\n"
".SUFFIXES:\n"
".PHONY : clean";
input<< headers << endl;
input<< sources << endl;
input<< rules << endl;
input<< cleanups << endl;
file.close();
return;
}
/**
* SLOTS
*/
void Wizard::bypassXML()
{
if(m_ui->bypassCheck->isChecked())
{
m_ui->platformEdit->setEnabled(false);
m_ui->deployEdit->setEnabled(false);
}
else
{
m_ui->platformEdit->setEnabled(true);
m_ui->deployEdit->setEnabled(true);
}
}
void Wizard::createProject()
{
projectName = m_ui->projectNameEdit->text();
directory = m_ui->directoryEdit->text();
sourceFile = m_ui->sourceFileEdit->text();
if(m_ui->platformEdit->isEnabled() && !(m_ui->platformEdit->text().isEmpty()))
platformFile = m_ui->platformEdit->text();
if(m_ui->deployEdit->isEnabled() && !(m_ui->deployEdit->text().isEmpty()))
deployFile = m_ui->deployEdit->text();
// create directory
if(!directory.isEmpty())
this->projectDir->mkdir(directory+"/"+projectName);
//create associated files
this->sourceFileDefault();
this->platformFileDefault();
this->deployFileDefault();
this->setMakeFile();
//emit projectName Signal to MainWindow
emit this->projectSaved(directory+"/"+projectName);
}
void Wizard::setDirectory()
{
m_ui->directoryEdit->setText(QFileDialog::getExistingDirectory(this));
}
void Wizard::editText(QString text)
{
m_ui->sourceFileEdit->setText(text+"_source.c");
if(m_ui->platformEdit->isEnabled() || m_ui->deployEdit->isEnabled())
{
m_ui->platformEdit->setText(text+"_platform.xml");
m_ui->deployEdit->setText(text+"_deploy.xml");
}
}