-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
150 lines (126 loc) · 3.86 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
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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QTableWidgetItem>
#include <QHeaderView>
#include <QProcess>
#include <QThread>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->progressBar->setHidden(true);
ui->label_3->setHidden(true);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_BrowseSource_clicked()
{
_sourceDirectory = QFileDialog::getExistingDirectory(this, tr("Choose catalog"), QDir::homePath(), QFileDialog::ReadOnly);
ui->lineEdit_SourcePath->setText(_sourceDirectory.path());
}
void MainWindow::on_pushButton_BrowseOutput_clicked()
{
_outputDirectory = QFileDialog::getExistingDirectory(this, tr("Choose catalog"), QDir::homePath(), QFileDialog::ReadOnly);
ui->lineEdit_output->setText(_outputDirectory.path());
}
void MainWindow::on_pushButton_start_clicked()
{
FileCollerctor fc(_sourceDirectory);
fc.run();
ui->progressBar->setValue(0);
ui->progressBar->setHidden(false);
Librarian lb(_sourceDirectory,_outputDirectory,fc.fileNames());
int count = fc.fileNames().count();
ui->progressBar->setMaximum(count);
connect(&lb, &Librarian::beeingCopy,[this](const QString &value, int index)
{
ui->label_3->setHidden(false);
ui->label_3->setText(value);
ui->progressBar->setValue(index);
this->update();
});
if(ui->radioButton_day->isChecked())
{
lb.run(day);
}
else if (ui->radioButton_month->isChecked())
{
lb.run(month);
}
else if (ui->radioButton_year->isChecked())
{
lb.run(year);
}
else
{
lb.run();
}
QThread::sleep(1);
nextPage();
}
void MainWindow::cellClicked(int row, int column)
{
if(column == 1)
{
QString command = QString("explorer \"%1\\%2\"")
.arg(QDir::toNativeSeparators(_outputDirectory.path()))
.arg(ui->tableWidget->item(row,0)->text());
QProcess::execute(command);
}
if(column == 0)
{
_oldCatalogName = ui->tableWidget->item(row,0)->text();
}
}
void MainWindow::cellChanged(QTableWidgetItem *item)
{
if(item->column() == 0)
{
if(ui->tableWidget->item(item->row(),0)->text().isEmpty())
{
ui->tableWidget->item(item->row(),0)->setText(_oldCatalogName);
}
else {
QDir directory(_outputDirectory.path()+"/"+_oldCatalogName);
directory.rename(directory.path(),QString("../%1").arg(ui->tableWidget->item(item->row(),0)->text()));
}
}
}
void MainWindow::nextPage()
{
QStringList _catalogs = _outputDirectory.entryList();
QStringList headers;
headers << tr("Catalog Name") << tr("P");
ui->tableWidget->setColumnCount(2);
//ui->tableWidget->insertColumn(1);
ui->tableWidget->setHorizontalHeaderLabels(headers);
ui->tableWidget->horizontalHeader()->update();
QIcon icon(QPixmap(":/folder.png").scaled(25,25));
for(int i = 2; i < _catalogs.count(); ++i)
{
int row = ui->tableWidget->rowCount();
ui->tableWidget->insertRow(row);
ui->tableWidget->setItem(row,0,new QTableWidgetItem(_catalogs.value(i)));
ui->tableWidget->setItem(row,1,new QTableWidgetItem(icon,""));
}
connect(ui->tableWidget,SIGNAL(cellClicked(int,int)),this,SLOT(cellClicked(int,int)));
connect(ui->tableWidget,SIGNAL(itemChanged(QTableWidgetItem*)),this,SLOT(cellChanged(QTableWidgetItem*)));
update();
ui->stackedWidget->setCurrentIndex(1);
}
void MainWindow::on_pushButton_back_clicked()
{
ui->tableWidget->clearContents();
ui->tableWidget->clear();
ui->tableWidget->setRowCount(0);
ui->progressBar->setHidden(true);
ui->label_3->setHidden(true);
ui->stackedWidget->setCurrentIndex(0);
}
void MainWindow::on_pushButton_exit_clicked()
{
exit(0);
}