-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwindow.cpp
87 lines (77 loc) · 2.4 KB
/
mainwindow.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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
#include <iostream>
#include <QThreadPool>
using namespace std;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
init();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::init()
{
//toCopy = false;
myThread = new MyThread();
connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(copyClicked()));
connect(ui->pushButton_2, SIGNAL(clicked()), this, SLOT(clearSelections()));
connect(ui->treeView, SIGNAL(clicked(QModelIndex)), this, SLOT(selectionChanged()));
connect(ui->pushButton_3, SIGNAL(clicked()), this, SLOT(cancelCopying()));
connect(myThread, SIGNAL(finished()), this, SLOT(copyThreadFinished()));
//ui->label->setVisible(false);
fileSystem = new QFileSystemModel(this);
fileSystem->setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot | QDir::Hidden | QDir::Drives);
fileSystem->setRootPath("/");
ui->treeView->setModel(fileSystem);
ui->treeView->setRootIndex(fileSystem->index("/"));//Users/thiagolacerda/Music/iTunes/iTunes Music/Music"));
ui->treeView->setSelectionMode(QAbstractItemView::MultiSelection);
ui->treeView->setSelectionBehavior(QAbstractItemView::SelectRows);
ui->treeView_2->setModel(fileSystem);
ui->pushButton_3->setEnabled(false);
myThread->srcTree = ui->treeView;
myThread->destTree = ui->treeView_2;
myThread->fileSystem = fileSystem;
myThread->sizeLabel = ui->label;
}
void MainWindow::copyClicked()
{
myThread->toCopy = true;
ui->pushButton->setEnabled(false);
ui->pushButton_2->setEnabled(false);
ui->pushButton_3->setEnabled(true);
myThread->start();
}
void MainWindow::selectionChanged()
{
myThread->toCopy = false;
if (!myThread->isRunning()) {
ui->pushButton->setEnabled(false);
ui->pushButton_2->setEnabled(false);
myThread->start();
}
}
void MainWindow::clearSelections()
{
ui->treeView->clearSelection();
ui->label->setText("");
}
void MainWindow::cancelCopying()
{
if (myThread->isRunning()) {
myThread->terminate();
//ui->pushButton->setEnabled(true);
}
ui->pushButton_3->setEnabled(false);
}
void MainWindow::copyThreadFinished()
{
ui->pushButton->setEnabled(true);
ui->pushButton_3->setEnabled(false);
ui->pushButton_2->setEnabled(true);
}