This repository has been archived by the owner on Aug 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
UBUpgradeToOef.cpp
342 lines (264 loc) · 11.4 KB
/
UBUpgradeToOef.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
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
/*
* Copyright (C) 2013-2014 Open Education Foundation
*
*
* This file is part of OpenBoard.
*
* OpenBoard 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, version 3 of the License,
* with a specific linking exception for the OpenSSL project's
* "OpenSSL" library (or with modified versions of it that use the
* same license as the "OpenSSL" library).
*
* OpenBoard 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 OpenBoard. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QVBoxLayout>
#include <QLabel>
#include <QApplication>
#include <QDesktopWidget>
#include <QPushButton>
#include <QRadioButton>
#include <QButtonGroup>
#include <QCheckBox>
#include <QThread>
#include <QDebug>
#include <QPainter>
#include <QBitmap>
#include <QFont>
#include <QFileDialog>
#include "UBUpgradeToOef.h"
UBUpgradeToOEF::UBUpgradeToOEF(QWidget *parent, UBUpgradeToOefDelegate* delegate) :
QStackedWidget(parent)
, mDelegate(delegate)
{
setAcceptDrops(false);
setObjectName("OEFUpgradeControlWidget");
setLayout(new QHBoxLayout());
//setWindowModality(Qt::WindowModal);
#ifdef Q_OS_MACX
setWindowFlags(Qt::FramelessWindowHint);
#else
//setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
#endif
setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed);
setStyleSheet(QString("QWidget#OEFUpgradeControlWidget {border-width: 10px; border-style : solid; border-color: lightgrey; background: white;}"));
init();
setMinimumSize(600,480);
move(QApplication::desktop()->availableGeometry().center() - rect().center());
show();
QBitmap objBitmap(size());
QPainter painter(&objBitmap);
painter.fillRect(rect(),Qt::white);
painter.setBrush(QColor(0,0,0));
painter.drawRoundedRect(rect(),9,9);
setMask(objBitmap);
connect(mImportingWidget,SIGNAL(actionTrig()),this,SLOT(onShowImportingWidget()));
}
void UBUpgradeToOEF::init()
{
int i=0;
insertWidget(i++,initialWidget());
mDelegate->initSizeCalculationThread();
connect(mDelegate->calculator(), SIGNAL(returnNecessarySize(qint64)),
this, SLOT(onNecessarySizeCalculated(qint64)));
mDelegate->calculatorThread()->start();
insertWidget(i++,chooseImportsWidget());
mImportingWidget = loggerWidget(tr("Importing ..."), &mImportingLogger);
insertWidget(i++,mImportingWidget);
insertWidget(i++,finalWidget());
setCurrentWidget(mInitialWidget);
}
QWidget* UBUpgradeToOEF::initialWidget()
{
mInitialWidget = new QWidget(this);
mInitialWidget->setObjectName("InitialWidget");
QVBoxLayout* vBoxLayout = new QVBoxLayout(mInitialWidget);
mInitialWidget->setLayout(vBoxLayout);
QLabel* title = new QLabel(mInitialWidget);
title->setText(tr("OpenBoard Document Importer"));
title->setStyleSheet("font-size : 24px; font-weight : bold;");
vBoxLayout->addWidget(title);
QTextEdit* description = new QTextEdit(mInitialWidget);
description->setStyleSheet("border-style : none; font-size : 14px;");
description->setReadOnly(true);
description->setText(tr("Please choose Open-Sankore documents you want to import to OpenBoard."));
vBoxLayout->addWidget(description);
mButtonGroup = new QButtonGroup(this);
QRadioButton* mPerformBasicImport = new QRadioButton(mInitialWidget);
mPerformBasicImport->setStyleSheet("border-style : none; font-size : 14px;");
mPerformBasicImport->setText(tr("Basic importation.\nImport all your data to OpenBoard."));
QRadioButton* mPerformAdvancedImport = new QRadioButton(mInitialWidget);
mPerformAdvancedImport->setStyleSheet("border-style : none; font-size : 14px;");
mPerformAdvancedImport->setText(tr("Advanced importation.\nChoose the documents you want to import to OpenBoard."));
mButtonGroup->addButton(mPerformBasicImport, 0);
mButtonGroup->addButton(mPerformAdvancedImport, 1);
mPerformBasicImport->setChecked(true);
vBoxLayout->addWidget(mPerformBasicImport);
vBoxLayout->addWidget(mPerformAdvancedImport);
vBoxLayout->addStretch();
mNecessaryDiskSpaceInfo = new QTextEdit(mInitialWidget);
mNecessaryDiskSpaceInfo->setStyleSheet("border-style : none; font-size : 14px;");
mNecessaryDiskSpaceInfo->setText(QString(tr("Importing your documents will require at least 0 MB of disk space, make sure this space is available on your hard drive.")));
mNecessaryDiskSpaceInfo->setReadOnly(true);
vBoxLayout->addWidget(mNecessaryDiskSpaceInfo);
vBoxLayout->addStretch();
QHBoxLayout* buttonLayout = new QHBoxLayout();
QPushButton* cancelButton = new QPushButton(mInitialWidget);
cancelButton->setText(tr("Cancel"));
connect(cancelButton,SIGNAL(clicked()),qApp,SLOT(quit()));
QPushButton* continueButton = new QPushButton(mInitialWidget);
continueButton->setText(tr("Continue"));
connect(continueButton,SIGNAL(clicked()),this,SLOT(onContinueClick()));
buttonLayout->addWidget(cancelButton);
buttonLayout->addStretch();
buttonLayout->addWidget(continueButton);
vBoxLayout->addLayout(buttonLayout);
return mInitialWidget;
}
void UBUpgradeToOEF::onNecessarySizeCalculated(qint64 size)
{
qint64 totalSize = size;
totalSize /= (1024 * 1024);
QString text = QString(tr("Importing your documents will require at least %1 MB of disk space, make sure this space is available on your hard drive.")).arg(totalSize);
mNecessaryDiskSpaceInfo->setText(text);
}
void UBUpgradeToOEF::onFileChooserClicked()
{
QString fileName = QFileDialog::getExistingDirectory(this, tr("Backup directory"),UBDirectories::homePath());
if(fileName.length())
mCurrentPath->setText(fileName);
}
QCheckBox* UBUpgradeToOEF::createCheckBox(PossiblesImport id, QString label)
{
QCheckBox* checkBox = new QCheckBox(mChooseImportsWidget);
int numberOfItemToImport = mDelegate->getNumberOfItemToImport(id);
if(numberOfItemToImport)
checkBox->setChecked(true);
else
checkBox->setDisabled(true);
checkBox->setStyleSheet("border-style : none; font-size : 14px;");
checkBox->setText(label);
return checkBox;
}
QWidget* UBUpgradeToOEF::chooseImportsWidget()
{
mChooseImportsWidget = new UBActionWidget(this);
mChooseImportsWidget->setObjectName("ChooseImportsWidget");
QVBoxLayout* vBoxLayout = new QVBoxLayout(mChooseImportsWidget);
mChooseImportsWidget->setLayout(vBoxLayout);
QLabel* title = new QLabel(mChooseImportsWidget);
title->setText(tr("Select the Items to Import"));
title->setStyleSheet("font-size : 24px; font-weight : bold;");
vBoxLayout->addWidget(title);
vBoxLayout->addStretch();
QGridLayout* gridLayout = new QGridLayout(0);
checkBoxes.insert(Documents,createCheckBox(Documents,tr("Documents")));
checkBoxes.insert(AnimationUserDirectory, createCheckBox(AnimationUserDirectory,tr("Flash")));
checkBoxes.insert(Applications, createCheckBox(Applications,tr("Application")));
checkBoxes.insert(InteractiveContents, createCheckBox(InteractiveContents,tr("Interactivities")));
checkBoxes.insert(InteractiveFavorites, createCheckBox(InteractiveFavorites,tr("Interactive Favorites")));
checkBoxes.insert(Library, createCheckBox(Library,tr("Library")));
checkBoxes.insert(UniboardUserConfig, createCheckBox(UniboardUserConfig,tr("User Configuration")));
checkBoxes.insert(Audios, createCheckBox(Audios,tr("Audios")));
checkBoxes.insert(Movies, createCheckBox(Movies,tr("Movies")));
checkBoxes.insert(Pictures, createCheckBox(Pictures,tr("Pictures")));
int counter = 0;
foreach(QCheckBox* eachBox, checkBoxes.values()){
gridLayout->addWidget(eachBox, counter/2,counter%2);
counter += 1;
}
vBoxLayout->addLayout(gridLayout);
vBoxLayout->addStretch();
QHBoxLayout* buttonLayout = new QHBoxLayout();
QPushButton* cancelButton = new QPushButton(mInitialWidget);
cancelButton->setText(tr("Cancel"));
connect(cancelButton,SIGNAL(clicked()),qApp,SLOT(quit()));
QPushButton* importButton = new QPushButton(mInitialWidget);
importButton->setText(tr("Import"));
connect(importButton,SIGNAL(clicked()),this,SLOT(nextWidgetInStack()));
buttonLayout->addWidget(cancelButton);
buttonLayout->addStretch();
buttonLayout->addWidget(importButton);
vBoxLayout->addLayout(buttonLayout);
return mChooseImportsWidget;
}
UBActionWidget *UBUpgradeToOEF::loggerWidget(QString loggerTitle, QTextEdit** logger)
{
UBActionWidget* result = new UBActionWidget(this);
result->setObjectName(loggerTitle);
QVBoxLayout* vBoxLayout = new QVBoxLayout(result);
result->setLayout(vBoxLayout);
QLabel* title = new QLabel(result);
title->setText(loggerTitle);
title->setStyleSheet("font-size : 24px; font-weight : bold;");
vBoxLayout->addWidget(title);
*logger = new QTextEdit(result);
(*logger)->setAcceptDrops(false);
(*logger)->ensureCursorVisible();
(*logger)->setContextMenuPolicy(Qt::NoContextMenu);
(*logger)->setCursorWidth(0);
(*logger)->setReadOnly(true);
(*logger)->setStyleSheet("border-style : none; font-size : 14px;");
vBoxLayout->addWidget(*logger);
return result;
}
QWidget* UBUpgradeToOEF::finalWidget()
{
mFinalWidget = new QWidget(this);
mFinalWidget->setObjectName("FinalWidget");
QVBoxLayout* vBoxLayout = new QVBoxLayout(mFinalWidget);
mFinalWidget->setLayout(vBoxLayout);
QLabel* title = new QLabel(mFinalWidget);
title->setStyleSheet("font-size : 24px; font-weight : bold;");
title->setText(tr("Import Finished"));
vBoxLayout->addWidget(title);
QTextEdit* description = new QTextEdit(mFinalWidget);
description->setReadOnly(true);
description->setStyleSheet("border-style : none; font-size : 14px;");
description->setText(tr("All the documents have been imported. You can now launch OpenBoard to access your documents."));
vBoxLayout->addWidget(description);
QHBoxLayout* buttonLayout = new QHBoxLayout();
QPushButton* finishedButton = new QPushButton(mFinalWidget);
finishedButton->setText(tr("Finished"));
connect(finishedButton ,SIGNAL(clicked()),qApp,SLOT(quit()));
buttonLayout->addStretch();
buttonLayout->addWidget(finishedButton);
vBoxLayout->addLayout(buttonLayout);
return mFinalWidget;
}
void UBUpgradeToOEF::onShowImportingWidget()
{
mDelegate->initImportThread();
connect(mDelegate->thread(),SIGNAL(finished()),this,SLOT(nextWidgetInStack()));
connect(mDelegate->worker(),SIGNAL(log(QString)),this,SLOT(appendImportingLog(QString)));
QList<PossiblesImport> ids;
foreach(PossiblesImport id, checkBoxes.keys()){
if(checkBoxes.value(id)->isEnabled() && checkBoxes.value(id)->isChecked())
ids.append(id);
}
mDelegate->worker()->setDelegate(mDelegate);
mDelegate->worker()->setIdsToImport(ids);
mDelegate->thread()->start();
}
void UBUpgradeToOEF::appendImportingLog(QString log)
{
mImportingLogger->append(log);
}
void UBUpgradeToOEF::onContinueClick()
{
if(mButtonGroup->checkedId() == 0)
setCurrentWidget(mImportingWidget);
else
nextWidgetInStack();
}
void UBUpgradeToOEF::nextWidgetInStack()
{
setCurrentIndex(currentIndex()+1);
}