0
|
1 |
#include "mainwindow.h"
|
|
2 |
#include "ui_mainwindow.h"
|
|
3 |
|
|
4 |
#include "widgetcreator.h"
|
|
5 |
#include "renderercreator.h"
|
|
6 |
#include "publishercreator.h"
|
|
7 |
|
|
8 |
#include <QMessageBox>
|
|
9 |
#include <QDir>
|
|
10 |
#include <QTextStream>
|
|
11 |
#include <QTimer>
|
|
12 |
|
|
13 |
|
|
14 |
MainWindow::MainWindow(QWidget *parent) :
|
|
15 |
QMainWindow(parent), ui(new Ui::MainWindow), iLayoutIndex( 0 ), iLayoutCount( -1 )
|
|
16 |
{
|
|
17 |
ui->setupUi(this);
|
|
18 |
iTimer = new QTimer(this);
|
|
19 |
connect(iTimer, SIGNAL(timeout()), this, SLOT(updateLayout()));
|
|
20 |
}
|
|
21 |
|
|
22 |
MainWindow::~MainWindow()
|
|
23 |
{
|
|
24 |
delete ui;
|
|
25 |
}
|
|
26 |
|
|
27 |
void MainWindow::changeEvent(QEvent *e)
|
|
28 |
{
|
|
29 |
QMainWindow::changeEvent(e);
|
|
30 |
switch (e->type()) {
|
|
31 |
case QEvent::LanguageChange:
|
|
32 |
ui->retranslateUi(this);
|
|
33 |
break;
|
|
34 |
default:
|
|
35 |
break;
|
|
36 |
}
|
|
37 |
}
|
|
38 |
|
|
39 |
QString MainWindow::widgetName()
|
|
40 |
{
|
|
41 |
return ui->widgetName->text().toLower();
|
|
42 |
}
|
|
43 |
|
|
44 |
QString MainWindow::widgetUid()
|
|
45 |
{
|
|
46 |
return ui->widgetUid->text().toLower();
|
|
47 |
}
|
|
48 |
|
|
49 |
QCheckBox& MainWindow::rendererCheckBox()
|
|
50 |
{
|
|
51 |
return *ui->renderingCheckBox;
|
|
52 |
}
|
|
53 |
|
|
54 |
QString MainWindow::rendererName()
|
|
55 |
{
|
|
56 |
return ui->rendererName->text();
|
|
57 |
}
|
|
58 |
|
|
59 |
QString MainWindow::rendererUid()
|
|
60 |
{
|
|
61 |
return ui->rendererUid->text();
|
|
62 |
}
|
|
63 |
|
|
64 |
void MainWindow::on_pushButton_clicked()
|
|
65 |
{
|
|
66 |
if( widgetName().isEmpty() || widgetUid().isEmpty() )
|
|
67 |
{
|
|
68 |
QMessageBox msgBox;
|
|
69 |
msgBox.setText("Widget name and UID must be given.");
|
|
70 |
msgBox.exec();
|
|
71 |
return;
|
|
72 |
}
|
|
73 |
|
|
74 |
bool ok;
|
|
75 |
uint uidVal = widgetUid().toUInt(&ok, 16 );
|
|
76 |
if( widgetUid().length() != 10 || !widgetUid().startsWith( "0x",Qt::CaseInsensitive ) || !ok )
|
|
77 |
{
|
|
78 |
QMessageBox msgBox;
|
|
79 |
msgBox.setText("UID must be in 4 byte hexadecimal format\n 0x11223344.");
|
|
80 |
msgBox.exec();
|
|
81 |
return;
|
|
82 |
}
|
|
83 |
|
|
84 |
if( uidVal >= 2147483648 ) //0x80000000
|
|
85 |
{
|
|
86 |
QMessageBox msgBox;
|
|
87 |
msgBox.setText("UID must be less than\n 0x80000000.");
|
|
88 |
msgBox.exec();
|
|
89 |
return;
|
|
90 |
}
|
|
91 |
|
|
92 |
generateMainBuildFile();
|
|
93 |
|
|
94 |
PublisherCreator* publisherCreator = new PublisherCreator(*this);
|
|
95 |
delete publisherCreator;
|
|
96 |
|
|
97 |
WidgetCreator* widgetCreator = new WidgetCreator(*this);
|
|
98 |
delete widgetCreator;
|
|
99 |
|
|
100 |
if( ui->renderingCheckBox->isChecked() )
|
|
101 |
{
|
|
102 |
if( rendererName().isEmpty() || rendererUid().isEmpty() )
|
|
103 |
{
|
|
104 |
QMessageBox msgBox;
|
|
105 |
msgBox.setText("Renderer name and UID must be given.");
|
|
106 |
msgBox.exec();
|
|
107 |
return;
|
|
108 |
}
|
|
109 |
if( rendererUid().length() != 10 || !rendererUid().startsWith( "0x",Qt::CaseInsensitive ))
|
|
110 |
{
|
|
111 |
QMessageBox msgBox;
|
|
112 |
msgBox.setText("UID must be in hexadecimal format\n 0x11223344.");
|
|
113 |
msgBox.exec();
|
|
114 |
return;
|
|
115 |
}
|
|
116 |
RendererCreator * renderer = new RendererCreator(*this);
|
|
117 |
delete renderer;
|
|
118 |
}
|
|
119 |
/*
|
|
120 |
QMessageBox msgBox;
|
|
121 |
msgBox.setText("Widget created.");
|
|
122 |
msgBox.exec();
|
|
123 |
return;*/
|
|
124 |
}
|
|
125 |
|
|
126 |
void MainWindow::generateMainBuildFile()
|
|
127 |
{
|
|
128 |
QDir dir;
|
|
129 |
dir.mkpath( widgetName() + "/group");
|
|
130 |
dir.setPath( widgetName() + "/group");
|
|
131 |
QFile file( dir.filePath("bld.inf"));
|
|
132 |
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
|
|
133 |
return;
|
|
134 |
|
|
135 |
QTextStream out(&file);
|
|
136 |
generateLicense( out );
|
|
137 |
|
|
138 |
//out << "#include \"../publisherif/group/bld.inf\"\n";
|
|
139 |
out << "#include \"../testpublisher/group/bld.inf\"\n";
|
|
140 |
out << "#include \"../widget/group/bld.inf\"\n";
|
|
141 |
if( ui->renderingCheckBox->isChecked() )
|
|
142 |
{
|
|
143 |
out << "#include \"../renderingplugin/group/bld.inf\"\n\n";
|
|
144 |
}
|
|
145 |
out << "// End of File\n";
|
|
146 |
}
|
|
147 |
|
|
148 |
void MainWindow::generateLicense( QTextStream& aStream )
|
|
149 |
{
|
|
150 |
aStream << "/*\n";
|
|
151 |
aStream << "* Copyright (c) {Year(s)} {Copyright owner}.\n";
|
|
152 |
aStream << "* All rights reserved.\n";
|
|
153 |
aStream << "* This component and the accompanying materials are made available\n";
|
|
154 |
aStream << "* under the terms of the \"Eclipse Public License v1.0\"\n";
|
|
155 |
aStream << "* which accompanies this distribution, and is available\n";
|
|
156 |
aStream << "* at the URL \"http://www.symbianfoundation.org/legal/sfl-v10.html\".\n";
|
|
157 |
aStream << "*\n";
|
|
158 |
aStream << "* Initial Contributors:\n";
|
|
159 |
aStream << "* {Name} {Company} – Initial contribution\n";
|
|
160 |
aStream << "*\n";
|
|
161 |
aStream << "* Contributors:\n";
|
|
162 |
aStream << "* {Name} {Company} – {{Description of contribution}}\n";
|
|
163 |
aStream << "*\n";
|
|
164 |
aStream << "* Description:\n";
|
|
165 |
aStream << "* {{Description of the file}}\n";
|
|
166 |
aStream << "*\n";
|
|
167 |
aStream << "*/\n\n";
|
|
168 |
}
|
|
169 |
|
|
170 |
QString MainWindow::widgetUidNoHex()
|
|
171 |
{
|
|
172 |
QString uid( widgetUid() );
|
|
173 |
if( uid.startsWith( "0x",Qt::CaseInsensitive ))
|
|
174 |
{
|
|
175 |
return uid.right(8);
|
|
176 |
}
|
|
177 |
else
|
|
178 |
{
|
|
179 |
return uid;
|
|
180 |
}
|
|
181 |
|
|
182 |
}
|
|
183 |
|
|
184 |
void MainWindow::replaceData( QString sourceFile, QString destFile, bool noHexUid )
|
|
185 |
{
|
|
186 |
QString path = QDir::currentPath();
|
|
187 |
QFile infile(sourceFile);
|
|
188 |
if (!infile.open(QIODevice::ReadWrite | QIODevice::Text))
|
|
189 |
return;
|
|
190 |
|
|
191 |
QTextStream in(&infile);
|
|
192 |
|
|
193 |
QFile outfile(destFile);
|
|
194 |
if (!outfile.open(QIODevice::ReadWrite | QIODevice::Text))
|
|
195 |
return;
|
|
196 |
|
|
197 |
QTextStream out(&outfile);
|
|
198 |
|
|
199 |
while (!in.atEnd())
|
|
200 |
{
|
|
201 |
QString line = in.readLine();
|
|
202 |
line.replace(QString("#replace#"), widgetName());
|
|
203 |
if( noHexUid )
|
|
204 |
{
|
|
205 |
line.replace(QString("#replaceuid#"), widgetUidNoHex());
|
|
206 |
}
|
|
207 |
else
|
|
208 |
{
|
|
209 |
line.replace(QString("#replaceuid#"), widgetUid());
|
|
210 |
}
|
|
211 |
out << line << "\n";
|
|
212 |
}
|
|
213 |
}
|
|
214 |
|
|
215 |
void MainWindow::on_renderingCheckBox_stateChanged(int state )
|
|
216 |
{
|
|
217 |
if( state == Qt::Unchecked )
|
|
218 |
{
|
|
219 |
ui->rendererName->setEnabled( false );
|
|
220 |
ui->rendererUid->setEnabled( false );
|
|
221 |
}
|
|
222 |
else if ( state == Qt::Checked)
|
|
223 |
{
|
|
224 |
ui->rendererName->setEnabled( true );
|
|
225 |
ui->rendererUid->setEnabled( true);
|
|
226 |
}
|
|
227 |
|
|
228 |
}
|
|
229 |
|
|
230 |
QString MainWindow::widgetLayout()
|
|
231 |
{
|
|
232 |
switch (iLayoutIndex)
|
|
233 |
{
|
|
234 |
case 0:
|
|
235 |
{
|
|
236 |
return QString( "feed" );
|
|
237 |
}
|
|
238 |
break;
|
|
239 |
case 1:
|
|
240 |
{
|
|
241 |
return QString( "text" );
|
|
242 |
}
|
|
243 |
break;
|
|
244 |
case 2:
|
|
245 |
{
|
|
246 |
return QString( "iconstext" );
|
|
247 |
}
|
|
248 |
break;
|
|
249 |
case 3:
|
|
250 |
{
|
|
251 |
return QString( "graphictext" );
|
|
252 |
}
|
|
253 |
break;
|
|
254 |
};
|
|
255 |
}
|
|
256 |
|
|
257 |
void MainWindow::on_comboBox_currentIndexChanged(int index)
|
|
258 |
{
|
|
259 |
iLayoutIndex = index;
|
|
260 |
iLayoutCount = 3;
|
|
261 |
updateLayout();
|
|
262 |
|
|
263 |
|
|
264 |
}
|
|
265 |
|
|
266 |
void MainWindow::updateLayout()
|
|
267 |
{
|
|
268 |
switch (iLayoutIndex)
|
|
269 |
{
|
|
270 |
case 0:
|
|
271 |
{
|
|
272 |
iTimer->stop();
|
|
273 |
showFeedsLayout();
|
|
274 |
}
|
|
275 |
break;
|
|
276 |
case 1:
|
|
277 |
{
|
|
278 |
showTextLayout();
|
|
279 |
iTimer->start(2000);
|
|
280 |
}
|
|
281 |
break;
|
|
282 |
case 2:
|
|
283 |
{
|
|
284 |
showIconsTextLayout();
|
|
285 |
iTimer->start(2000);
|
|
286 |
}
|
|
287 |
break;
|
|
288 |
case 3:
|
|
289 |
{
|
|
290 |
showGraphicTextLayout();
|
|
291 |
iTimer->start(2000);
|
|
292 |
}
|
|
293 |
break;
|
|
294 |
};
|
|
295 |
|
|
296 |
if( iLayoutCount > 1)
|
|
297 |
{
|
|
298 |
iLayoutCount--;
|
|
299 |
}
|
|
300 |
else
|
|
301 |
{
|
|
302 |
iLayoutCount = 3;
|
|
303 |
}
|
|
304 |
}
|
|
305 |
|
|
306 |
void MainWindow::showFeedsLayout()
|
|
307 |
{
|
|
308 |
ui->layoutGraphics->setPixmap(QPixmap(QString::fromUtf8(":/widgets/images/feeds_layout.jpg")));
|
|
309 |
}
|
|
310 |
|
|
311 |
void MainWindow::showTextLayout()
|
|
312 |
{
|
|
313 |
QString imagePath(":/widgets/images/text_layout_");
|
|
314 |
QString cnt;
|
|
315 |
cnt.setNum( iLayoutCount );
|
|
316 |
imagePath.append( cnt );
|
|
317 |
imagePath.append( ".jpg" );
|
|
318 |
ui->layoutGraphics->setPixmap(QPixmap(imagePath));
|
|
319 |
}
|
|
320 |
|
|
321 |
void MainWindow::showIconsTextLayout()
|
|
322 |
{
|
|
323 |
QString imagePath(":/widgets/images/iconstext_layout_");
|
|
324 |
QString cnt;
|
|
325 |
cnt.setNum( iLayoutCount );
|
|
326 |
imagePath.append( cnt );
|
|
327 |
imagePath.append( ".jpg" );
|
|
328 |
ui->layoutGraphics->setPixmap(QPixmap(imagePath));
|
|
329 |
}
|
|
330 |
|
|
331 |
void MainWindow::showGraphicTextLayout()
|
|
332 |
{
|
|
333 |
QString imagePath(":/widgets/images/graphictext_layout_");
|
|
334 |
QString cnt;
|
|
335 |
cnt.setNum( iLayoutCount );
|
|
336 |
imagePath.append( cnt );
|
|
337 |
imagePath.append( ".jpg" );
|
|
338 |
ui->layoutGraphics->setPixmap(QPixmap(imagePath));
|
|
339 |
}
|