-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtabsetting.cpp
More file actions
174 lines (141 loc) · 4.96 KB
/
tabsetting.cpp
File metadata and controls
174 lines (141 loc) · 4.96 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
#include "tabsetting.h"
#include "ui_tabsetting.h"
#include "setting.h"
#include <QFileDialog>
#include <QDebug>
TabSetting::TabSetting(QWidget *parent) :
QWidget(parent), ui(new Ui::TabSetting)
{
ui->setupUi(this);
initData();
connect(ui->checkBoxRunOnSystemStartup, &QCheckBox::stateChanged, this, &TabSetting::onRunOnSystemStartup);
connect(ui->checkBoxHideWindowAtLaunch, &QCheckBox::stateChanged, this, &TabSetting::onHideMainWindowWhenOpen);
connect(ui->checkBoxAutoStartHunter, &QCheckBox::stateChanged, this, &TabSetting::onAutoStartHunter);
connect(ui->checkBoxMoveToTrash, &QCheckBox::stateChanged, this, &TabSetting::onMoveToTrash);
connect(ui->checkBoxAutoClearLog, &QCheckBox::stateChanged, this, &TabSetting::onAutoClearLog);
connect(ui->comboBoxHours, &QComboBox::currentIndexChanged, this, &TabSetting::onHoursIndexChanged);
connect(ui->listWidget, &QListWidget::itemSelectionChanged, this, &TabSetting::onLockFileListIndexChanged);
connect(ui->buttonAdd, &QAbstractButton::clicked, this, &TabSetting::onAdd);
connect(ui->buttonDelete, &QAbstractButton::clicked, this, &TabSetting::onDelete);
connect(ui->buttonDefault, &QAbstractButton::clicked, this, &TabSetting::onDefault);
}
TabSetting::~TabSetting()
{
delete ui;
}
void TabSetting::showEvent(QShowEvent *event)
{
QWidget::showEvent(event);
updateButton();
}
void TabSetting::initData()
{
bool isCheck = Setting::getRunOnSystemStartup();
ui->checkBoxRunOnSystemStartup->setCheckState(isCheck ? Qt::Checked : Qt::Unchecked);
isCheck = Setting::getHideWindowAtLaunch();
ui->checkBoxHideWindowAtLaunch->setCheckState(isCheck ? Qt::Checked : Qt::Unchecked);
isCheck = Setting::getAutoStartHunter();
ui->checkBoxAutoStartHunter->setCheckState(isCheck ? Qt::Checked : Qt::Unchecked);
isCheck = Setting::getMoveToTrash();
ui->checkBoxMoveToTrash->setCheckState(isCheck ? Qt::Checked : Qt::Unchecked);
isCheck = Setting::getAutoClearLog();
ui->checkBoxAutoClearLog->setCheckState(isCheck ? Qt::Checked : Qt::Unchecked);
int hours = Setting::getClearLogHours();
ui->comboBoxHours->setCurrentIndex(hours - 1);
ui->listWidget->addItems(Setting::getLockFiles());
}
void TabSetting::updateButton()
{
ui->buttonDelete->setEnabled(!ui->listWidget->selectedItems().empty());
}
void TabSetting::onRunOnSystemStartup(const int state)
{
Setting::setRunOnSystemStartup(state != 0);
bool isCheck = Setting::getRunOnSystemStartup();
ui->checkBoxRunOnSystemStartup->setCheckState(isCheck ? Qt::Checked : Qt::Unchecked);
}
void TabSetting::onHideMainWindowWhenOpen(const int state)
{
Setting::setHideWindowAtLaunch(state != 0);
}
void TabSetting::onAutoStartHunter(const int state)
{
Setting::setAutoStartHunter(state != 0);
}
void TabSetting::onMoveToTrash(const int state)
{
Setting::setMoveToTrash(state != 0);
emit moveLockFileToTrash();
}
void TabSetting::onAutoClearLog(const int state)
{
Setting::setAutoClearLog(state != 0);
emit updateTimerClearLog();
}
void TabSetting::onHoursIndexChanged(const int index)
{
Setting::setClearLogHours(index + 1);
if (Setting::getAutoClearLog())
{
emit updateTimerClearLog();
}
}
void TabSetting::onLockFileListIndexChanged()
{
updateButton();
}
void TabSetting::onAdd()
{
QString lastPath = Setting::getLastPath();
QString filePath = QFileDialog::getOpenFileName(this, "Select Lock File", lastPath);
if (!filePath.isEmpty())
{
auto fInfo = QFileInfo(filePath);
QString fileName = fInfo.fileName();
lastPath = QDir::toNativeSeparators(fInfo.absolutePath());
Setting::setLastPath(lastPath);
if (ui->listWidget->findItems(fileName, Qt::MatchFixedString).empty())
{
qDebug() << "Add lock file: " + fileName;
ui->listWidget->addItem(fileName);
QStringList files;
for (int i = 0; i < ui->listWidget->count(); i++)
{
files << ui->listWidget->item(i)->text();
}
Setting::setLockFiles(files);
emit lockFileListChanged();
}
}
updateButton();
}
void TabSetting::onDelete()
{
auto items = ui->listWidget->selectedItems();
foreach (auto item, items)
{
qDebug() << "Delete lock file: " + item->text();
delete ui->listWidget->takeItem(ui->listWidget->row(item));
}
if (!items.empty())
{
// Update the lock file list
QStringList files;
for (int i = 0; i < ui->listWidget->count(); i++)
{
files << ui->listWidget->item(i)->text();
}
Setting::setLockFiles(files);
emit lockFileListChanged();
}
updateButton();
}
void TabSetting::onDefault()
{
ui->listWidget->clear();
ui->listWidget->addItems(Setting::getDefaultLockFiles());
qDebug() << "Default lock file";
Setting::setLockFiles(Setting::getDefaultLockFiles());
emit lockFileListChanged();
updateButton();
}