-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcopyingstatuswindow.cpp
More file actions
175 lines (163 loc) · 5.54 KB
/
copyingstatuswindow.cpp
File metadata and controls
175 lines (163 loc) · 5.54 KB
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
#include "copyingstatuswindow.h"
#include "ui_copyingstatuswindow.h"
CopyingStatusWindow::CopyingStatusWindow(const QString &source, const QString &destination, const bool cutFlag, QWidget *parent) :
QDialog(parent),
ui(new Ui::CopyingStatusWindow)
{
ui->setupUi(this);
setWindowFlags(Qt::MSWindowsFixedSizeDialogHint);
CutFlag = cutFlag;
if (!source.isEmpty() && !destination.isEmpty()){
ui->lineEdit->setText(source);
ui->lineEdit_2->setText(destination);
ui->progressBar->setFormat("");
if (cutFlag){
windowTitle = "Moving files...";
}
worker = new CopyWorker(source, destination, this);
thread = new QThread(this);
worker->moveToThread(thread);
connect(worker, &CopyWorker::askForCopyOptionsMergeFolders, this, &CopyingStatusWindow::askForCopyOptionsMergeFolders);
connect(worker, &CopyWorker::askForCopyOptionsOverwriteFile, this, &CopyingStatusWindow::askForCopyOptionsOverwriteFile);
connect(worker, &CopyWorker::PauseChanged, this, &CopyingStatusWindow::on_PauseChanged);
connect(thread, &QThread::finished, worker, &CopyWorker::deleteLater);
this->setWindowTitle(windowTitle);
if(cutFlag){
connect(thread, &QThread::started, worker, &CopyWorker::start_moving);
}
else{
connect(thread, &QThread::started, worker, &CopyWorker::start_copying);
}
connect(worker, &CopyWorker::copying_finished, this, &CopyingStatusWindow::copying_finished_slot);
worker->setStop(false);
worker->setPause(false);
//worker->setOptions(askForCopyOptions());
ui->progressBar->setMinimum(0);
ui->progressBar->setMaximum(0);
thread->start();
}
else{
emit ArgumentIsInvalid("Invalid source or destination for copying files.");
copyingFinished = true;
this->close();
}
}
CopyingStatusWindow::~CopyingStatusWindow()
{
if(!copyingFinished){
worker->setStop(true);
worker->setPause(false);
thread->quit();
thread->wait();
}
else{
thread->quit();
}
delete ui;
}
bool CopyingStatusWindow::skip() const
{
return m_skip;
}
void CopyingStatusWindow::closeEvent(QCloseEvent *e)
{
if(thread->isRunning()){
worker->setPause(false);
worker->setStop(true);
if(CutFlag){
QApplication::beep();
QMessageBox::warning(this, windowTitle, "UnderCommander is moving files at the moment. \n"
"Stoping it can lead to errors and file corrupting.");
}
else{
QApplication::beep();
QMessageBox::warning(this, windowTitle, "UnderCommander is copying files at the moment. \n"
"Stoping it can lead to errors and file corrupting.");
}
e->ignore();
}
else{
e->accept();
}
}
void CopyingStatusWindow::askForCopyOptionsOverwriteFile(const QString &source, const QString &destination)
{
copy_options options = copy_options::copy_symlinks | copy_options::overwrite_existing;
QMessageBox::StandardButton reply;
reply = QMessageBox::question(this, windowTitle, "Overwrite " + source +"\nwith " + destination + " ?",
QMessageBox::Yes | QMessageBox::No);
if (reply == QMessageBox::Yes){
options = options | copy_options::overwrite_existing;
}
else{
reply = QMessageBox::question(this, windowTitle, "Update existing files"
"(replace the existing file only"
" if it is older than the file being copied)?",
QMessageBox::Yes | QMessageBox::No);
if (reply == QMessageBox::Yes){
options = options | copy_options::update_existing;
}
else{
options = options | copy_options::skip_existing;
}
}
worker->setOptions(options);
worker->setPause(false);
}
void CopyingStatusWindow::askForCopyOptionsMergeFolders(const QString &source, const QString &destination)
{
QString message = "Merge " + source + "\nand " + destination + " ?";
worker->setMergeFolders(QMessageBox::question(this, windowTitle, message, QMessageBox::Yes | QMessageBox::No));
worker->setPause(false);
}
void CopyingStatusWindow::on_PauseChanged(bool value)
{
if(value){
pauseOperation();
}
else{
unPauseOperation();
}
}
void CopyingStatusWindow::pauseOperation()
{
ui->pauseResume->setIcon(QIcon(":/icons/resume.png"));
ui->progressBar->setMinimum(0);
ui->progressBar->setMaximum(100);
ui->progressBar->setValue(100);
pause = true;
}
void CopyingStatusWindow::unPauseOperation()
{
ui->pauseResume->setIcon(QIcon(":/icons/pause.png"));
ui->progressBar->setMinimum(0);
ui->progressBar->setMaximum(0);
ui->progressBar->setValue(0);
pause = false;
}
void CopyingStatusWindow::copying_finished_slot()
{
copyingFinished = true;
ui->progressBar->setMinimum(0);
ui->progressBar->setMaximum(100);
ui->progressBar->setValue(100);
thread->quit();
thread->wait();
this->close();
}
void CopyingStatusWindow::setSkip(bool skip)
{
if (m_skip == skip)
return;
m_skip = skip;
emit skipChanged(m_skip);
}
void CopyingStatusWindow::on_pauseResume_clicked()
{
if (pause){
worker->setPause(false);
}
else{
worker->setPause(true);
}
}