-
Notifications
You must be signed in to change notification settings - Fork 16
/
installwizard_copy.cpp
133 lines (111 loc) · 4.14 KB
/
installwizard_copy.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
/*
The MIT License (MIT)
Copyright (c) 2013 The ioquake Group
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <QDir>
#include <QMessageBox>
#include <QThread>
#include "installwizard_copy.h"
#include "ui_installwizard_copy.h"
InstallWizard_Copy::InstallWizard_Copy(QWidget *parent) :
QWizardPage(parent),
ui(new Ui::InstallWizard_Copy),
copyWorker(NULL),
isCopyFinished(false)
{
ui->setupUi(this);
}
InstallWizard_Copy::~InstallWizard_Copy()
{
copyThread.quit();
copyThread.wait();
delete ui;
}
void InstallWizard_Copy::initializePage()
{
ui->lblStatus->setText("");
isCopyFinished = false;
copyFilename = QString();
// Try to create the destination directory and baseq3 subdirectory.
const QString quake3Path(((InstallWizard *)wizard())->getQuakePath() + QString("/baseq3"));
QDir dir;
if (!dir.mkpath(quake3Path))
{
ui->lblStatus->setText(QString("Error creating directory '%1'").arg(quake3Path));
return;
}
// Start copy thread.
qRegisterMetaType<QList<FileOperation> >("QList<FileOperation>");
copyWorker = new FileCopyWorker(((InstallWizard *)wizard())->getFileCopyOperations());
copyWorker->moveToThread(©Thread);
connect(©Thread, SIGNAL(finished()), copyWorker, SLOT(deleteLater()));
connect(this, SIGNAL(copy()), copyWorker, SLOT(copy()));
connect(copyWorker, SIGNAL(fileChanged(const QString)), this, SLOT(setCopyFilename(const QString)));
connect(copyWorker, SIGNAL(progressChanged(qint64,qint64)), this, SLOT(setCopyProgress(qint64,qint64)));
connect(copyWorker, SIGNAL(errorMessage(const QString)), this, SLOT(setCopyErrorMessage(const QString)));
connect(copyWorker, SIGNAL(copyFinished(QList<FileOperation>)), this, SLOT(finishCopy(QList<FileOperation>)));
copyThread.start();
emit copy();
}
bool InstallWizard_Copy::isComplete() const
{
return isCopyFinished;
}
int InstallWizard_Copy::nextId() const
{
if (((InstallWizard *)wizard())->getIsQuake3PatchRequired())
{
return InstallWizard::Page_Patch;
}
return InstallWizard::Page_Finished;
}
void InstallWizard_Copy::cancel()
{
if (!isCopyFinished)
{
copyWorker->cancel();
}
}
void InstallWizard_Copy::setCopyFilename(const QString &filename)
{
copyFilename = filename;
}
void InstallWizard_Copy::setCopyProgress(qint64 bytesWritten, qint64 bytesTotal)
{
ui->lblStatus->setText(QString("Copying %1 (%2MB / %3MB)").arg(copyFilename).arg(bytesWritten / 1024.0 / 1024.0, 0, 'f', 2).arg(bytesTotal / 1024.0 / 1024.0, 0, 'f', 2));
ui->pbProgress->setMaximum((int)bytesTotal);
ui->pbProgress->setValue((int)bytesWritten);
}
void InstallWizard_Copy::setCopyErrorMessage(const QString &message)
{
ui->lblStatus->setText(message);
}
void InstallWizard_Copy::finishCopy(QList<FileOperation> renameOperations)
{
copyThread.quit();
copyThread.wait();
// Complete the transaction.
const QString transactionError = FileUtils::completeTransaction(renameOperations);
if (!transactionError.isEmpty())
{
ui->lblStatus->setText(transactionError);
return;
}
isCopyFinished = true;
emit completeChanged();
wizard()->next();
}