-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
125 lines (108 loc) · 3.47 KB
/
mainwindow.cpp
File metadata and controls
125 lines (108 loc) · 3.47 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
#include "mainwindow.h"
#include "ui_mainwindow.h"
QLabel* currentDirLabel;
IndexatorRunnable indexatorRunnable;
Thread* indexatorThread ;
FilesTableModel model;
MainWindow::MainWindow(QWidget *parent):
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
currentDirLabel = new QLabel();
currentDirLabel->setWordWrap(true);
currentDirLabel->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed);
ui->statusBar->addWidget(currentDirLabel);
ui->statusBar->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
connect(&model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), ui->tableView, SLOT(dataChanged(QModelIndex,QModelIndex)));
connect(&indexatorRunnable, SIGNAL(textChanged(QString)), currentDirLabel, SLOT(setText(QString)));
connect(&indexatorRunnable, SIGNAL(indexationCompleted(bool)), ui->findButton, SLOT(setEnabled(bool)));
connect(&indexatorRunnable, SIGNAL(indexationCompleted(bool)), ui->startButton, SLOT(setEnabled(bool)));
}
MainWindow::~MainWindow()
{
delete currentDirLabel;
delete indexatorThread;
delete ui;
}
void MainWindow::on_startButton_clicked()
{
ui->findButton->setEnabled(false);
ui->startButton->setEnabled(false);
indexatorThread = new Thread(&indexatorRunnable);
indexatorThread->start();
}
void MainWindow::on_pauseButton_clicked()
{
ui->findButton->setEnabled(true);
indexatorThread->suspend();
indexatorRunnable.textChanged("Pasued");
}
void MainWindow::on_stopButton_clicked()
{
ui->findButton->setEnabled(true);
ui->startButton->setEnabled(true);
indexatorRunnable.terminate();
indexatorRunnable.textChanged("Stopped");
}
void MainWindow::on_resumeButton_clicked()
{
ui->findButton->setEnabled(true);
indexatorThread->start();
}
void MainWindow::on_findButton_clicked()
{
ui->tableView->setModel(nullptr);
if(ui->searchLineEdit->text() != "")
{
model.filesList.clear();
QString toFind = ui->searchLineEdit->text();
if(ui->dateRadioButton->isChecked())
{
for (FileInfo i : indexatorRunnable.filesData)
{
if(SystemTimeToQDateTime(i.getDate()).toString() == toFind)
{
model.filesList.push_back(i);
}
}
}
else if(ui->sizeRadioButton->isChecked())
{
for (FileInfo i : indexatorRunnable.filesData)
{
if(i.getSize() == toFind.toUInt())
{
model.filesList.push_back(i);
}
}
}
else if(ui->extensionRadioButton->isChecked())
{
for (FileInfo i : indexatorRunnable.filesData)
{
std::wstring extension = i.getName();
extension.erase(extension.begin(), extension.begin() + extension.find('.'));
if(extension == toFind.toStdWString())
{
model.filesList.push_back(i);
}
}
}
else if(ui->nameRadioButton->isChecked())
{
for (FileInfo i : indexatorRunnable.filesData)
{
if(i.getName().find(toFind.toStdWString().c_str()) != std::string::npos)
{
model.filesList.push_back(i);
}
}
}
ui->tableView->setModel(&model);
}
else
{
currentDirLabel->setText("Specify search criteria");
}
}