-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtabmain.cpp
More file actions
173 lines (148 loc) · 4.28 KB
/
tabmain.cpp
File metadata and controls
173 lines (148 loc) · 4.28 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
#include "tabmain.h"
#include "ui_tabmain.h"
#include "setting.h"
#include <QFileDialog>
TabMain::TabMain(QWidget *parent) :
QWidget(parent), ui(new Ui::TabMain), m_scanning(false), m_scanLockFile(nullptr)
{
ui->setupUi(this);
ui->listWidget->addItems(Setting::getWatchFolders());
connect(ui->buttonAdd, &QAbstractButton::clicked, this, &TabMain::onAdd);
connect(ui->buttonDelete, &QAbstractButton::clicked, this, &TabMain::onDelete);
connect(ui->buttonStart, &QAbstractButton::clicked, this, &TabMain::onStart);
connect(ui->buttonScan, &QAbstractButton::clicked, this, &TabMain::onScan);
connect(ui->listWidget, &QListWidget::itemSelectionChanged, this, &TabMain::onPantherSiteListIndexChanged);
}
TabMain::~TabMain()
{
delete ui;
}
bool TabMain::scanning() const
{
return m_scanning;
}
void TabMain::showEvent(QShowEvent *event)
{
QWidget::showEvent(event);
onPantherSiteListIndexChanged();
}
void TabMain::updateButtonStart(const bool started)
{
if (started)
{
ui->buttonStart->setText("Stop");
ui->buttonStart->setToolTip("Stop Hunter");
}
else
{
ui->buttonStart->setText("Start");
ui->buttonStart->setToolTip("Start Hunter");
}
}
void TabMain::updateButtonDelete()
{
ui->buttonDelete->setEnabled(!ui->listWidget->selectedItems().empty());
}
void TabMain::updateButtonScan()
{
ui->buttonScan->setEnabled(!Setting::getWatchFolders().empty() && !Setting::getLockFiles().empty());
if (m_scanning)
{
ui->buttonScan->setText("Cancel");
ui->buttonScan->setToolTip("Cancel scanning");
}
else
{
ui->buttonScan->setText("Scan");
ui->buttonScan->setToolTip("Scan and delete the lock files in Panther sites");
}
}
void TabMain::onUpdateButtonStart(const bool started)
{
updateButtonStart(started);
}
void TabMain::onUpdateButtonScan()
{
updateButtonScan();
}
void TabMain::onAdd()
{
QString lastPath = Setting::getLastPath();
QString dir = QFileDialog::getExistingDirectory(this, "Select Panther Site", lastPath,
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
if (!dir.isEmpty())
{
Setting::setLastPath(dir);
dir = QDir::toNativeSeparators(dir);
if (ui->listWidget->findItems(dir, Qt::MatchFixedString).empty())
{
ui->listWidget->addItem(dir);
// Update the watch folder list
QStringList folders;
for (int i = 0; i < ui->listWidget->count(); i++)
{
folders << ui->listWidget->item(i)->text();
}
Setting::setWatchFolders(folders);
emit addWatch(dir);
emit pantherSiteListChanged();
}
}
onPantherSiteListIndexChanged();
}
void TabMain::onDelete()
{
auto items = ui->listWidget->selectedItems();
QStringList listDir;
foreach (auto item, items)
{
listDir.append(item->text() + QDir::separator());
delete ui->listWidget->takeItem(ui->listWidget->row(item));
}
if (!listDir.empty())
{
// Update the watch folder list
QStringList folders;
for (int i = 0; i < ui->listWidget->count(); i++)
{
folders << ui->listWidget->item(i)->text();
}
Setting::setWatchFolders(folders);
emit deleteWatch(listDir);
emit pantherSiteListChanged();
}
onPantherSiteListIndexChanged();
}
void TabMain::onStart()
{
emit startWatcher();
}
void TabMain::onScan()
{
if (!m_scanning)
{
m_scanning = true;
m_scanLockFile = new ScanLockFile(this);
connect(m_scanLockFile, &ScanLockFile::scanDone, this, [&](int numberDeletedFiles, const QStringList &filePaths)
{
m_scanning = false;
updateButtonScan();
emit scanDone(numberDeletedFiles, filePaths);
});
connect(m_scanLockFile, &ScanLockFile::finished, m_scanLockFile, &QObject::deleteLater);
m_scanLockFile->start();
emit startScan();
}
else
{
m_scanning = false;
m_scanLockFile->cancel();
m_scanLockFile->wait();
}
updateButtonScan();
}
void TabMain::onPantherSiteListIndexChanged()
{
updateButtonDelete();
updateButtonScan();
}