-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathsettingswindow.cpp
More file actions
165 lines (140 loc) · 6.1 KB
/
Copy pathsettingswindow.cpp
File metadata and controls
165 lines (140 loc) · 6.1 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
#include "settingswindow.h"
#include "ui_settingswindow.h"
#include "reapplyconfigwindow.h"
#include "utils.h"
#include <QFileDialog>
#include <QStyleHints>
SettingsWindow::SettingsWindow(const Settings &programSettings, QWidget *parent)
: QDialog(parent)
, ui(new Ui::settingswindow)
, tempSettings(programSettings)
{
setModal(true);
ui->setupUi(this);
connect(ui->runonstartupCheckBox, &QCheckBox::clicked, this, &SettingsWindow::setRunOnStartup);
connect(ui->selectstyleComboBox,
&QComboBox::currentTextChanged,
this,
[this](const QString &text) {
this->ui->removestylePushButton->setEnabled(text != "Default");
});
connect(ui->loadstylePushButton, &QPushButton::clicked, this, &SettingsWindow::saveStyle);
connect(ui->removestylePushButton, &QPushButton::clicked, this, &SettingsWindow::removeStyle);
ui->runonstartupCheckBox->setChecked(programSettings.runOnstartup);
ui->terminateOnCloseCheckBox->setChecked(programSettings.terminateOnClose);
ui->headsetdisconnectednotificationCheckBox->setChecked(programSettings.notificationHeadsetDisconnected);
ui->batteryfullnotificationCheckBox->setChecked(programSettings.notificationBatteryFull);
ui->batterylownotificationCheckBox->setChecked(programSettings.notificationBatteryLow);
ui->batterylowtresholdSpinBox->setValue(programSettings.batteryLowThreshold);
ui->enableaudioNotificationCheckBox->setChecked(programSettings.audioNotification);
ui->updateintervaltimeDoubleSpinBox->setValue((double) programSettings.msecUpdateIntervalTime
/ 1000);
loadStyles();
ui->selectstyleComboBox->setCurrentIndex(
ui->selectstyleComboBox->findText(programSettings.styleName));
ui->commandexeLabel->setText(programSettings.commandExe);
connect(ui->commandexePushButton, &QPushButton::clicked, this, &SettingsWindow::setCommandExe);
connect(ui->commandclearPushButton, &QPushButton::clicked, this, &SettingsWindow::clearCommandExe);
ui->commandargumentsValue->setText(programSettings.commandArgs);
ui->commandintervaltimeDoubleSpinBox->setValue((double) programSettings.msecCommandIntervalTime
/ 1000);
ui->updateChannelComboBox->setCurrentText(programSettings.updateChannel);
connect(ui->updateHeadsetControlPushButton, &QPushButton::clicked, this, [this]() {
emit requestUpdate(ui->updateChannelComboBox->currentText());
});
connect(ui->configureReapplyConfigPushButton, &QPushButton::clicked, this, [this]() {
Settings currentSettings = getSettings();
ReapplyConfigWindow diag(currentSettings, this);
if (diag.exec() == QDialog::Accepted) {
tempSettings = diag.getSettings();
}
});
}
Settings SettingsWindow::getSettings()
{
Settings settings;
settings.runOnstartup = ui->runonstartupCheckBox->isChecked();
settings.terminateOnClose = ui->terminateOnCloseCheckBox->isChecked();
settings.notificationHeadsetDisconnected = ui->headsetdisconnectednotificationCheckBox->isChecked();
settings.notificationBatteryFull = ui->batteryfullnotificationCheckBox->isChecked();
settings.notificationBatteryLow = ui->batterylownotificationCheckBox->isChecked();
settings.batteryLowThreshold = ui->batterylowtresholdSpinBox->value();
settings.audioNotification = ui->enableaudioNotificationCheckBox->isChecked();
settings.msecUpdateIntervalTime = ui->updateintervaltimeDoubleSpinBox->value() * 1000;
settings.styleName = ui->selectstyleComboBox->currentText();
settings.commandExe = ui->commandexeLabel->text();
settings.commandArgs = ui->commandargumentsValue->text();
settings.msecCommandIntervalTime = ui->commandintervaltimeDoubleSpinBox->value() * 1000;
settings.updateChannel = ui->updateChannelComboBox->currentText();
settings.reapplyAtInterval = tempSettings.reapplyAtInterval;
settings.reapplyConfigInterval = tempSettings.reapplyConfigInterval;
settings.applyOnConnect = tempSettings.applyOnConnect;
settings.reapplyCapabilities = tempSettings.reapplyCapabilities;
return settings;
}
void SettingsWindow::setRunOnStartup()
{
bool enabled = setOSRunOnStartup(ui->runonstartupCheckBox->isChecked());
ui->runonstartupCheckBox->setChecked(enabled);
}
void SettingsWindow::loadStyles()
{
QString destination = PROGRAM_STYLES_PATH;
QDir directory = QDir(destination);
QStringList list = directory.entryList(QStringList() << "*.qss", QDir::Files);
ui->selectstyleComboBox->clear();
ui->selectstyleComboBox->addItem("Default");
ui->selectstyleComboBox->addItems(list);
}
void SettingsWindow::saveStyle()
{
QFileDialog dialog(this);
dialog.setFileMode(QFileDialog::AnyFile);
dialog.setNameFilter("QStyle (*.qss)");
if (dialog.exec())
{
QStringList fileUrls = dialog.selectedFiles();
QUrl fileUrl = QUrl(fileUrls[0]);
if (fileUrl.isValid()) {
QString source = fileUrl.path().removeFirst();
QString destination = PROGRAM_STYLES_PATH;
QDir().mkpath(destination);
destination += "/" + fileUrl.fileName();
QFile file(destination);
if (file.exists()) {
file.remove();
}
QFile::copy(source, destination);
loadStyles();
}
}
}
void SettingsWindow::removeStyle()
{
QString stylePath = PROGRAM_STYLES_PATH + "/" + ui->selectstyleComboBox->currentText();
QFile file(stylePath);
if (file.exists()) {
file.remove();
}
loadStyles();
}
void SettingsWindow::setCommandExe(){
QFileDialog dialog(this);
dialog.setFileMode(QFileDialog::AnyFile);
if (dialog.exec())
{
QStringList fileUrls = dialog.selectedFiles();
QUrl fileUrl = QUrl(fileUrls[0]);
if (fileUrl.isValid()) {
QString source = fileUrl.toString();
ui->commandexeLabel->setText(source);
}
}
}
void SettingsWindow::clearCommandExe(){
ui->commandexeLabel->setText("");
}
SettingsWindow::~SettingsWindow()
{
delete ui;
}