-
Notifications
You must be signed in to change notification settings - Fork 0
/
xmidix_config.cc
78 lines (64 loc) · 2.08 KB
/
xmidix_config.cc
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
#include "xmidix_config.h"
xmidix_config::xmidix_config(QWidget *parent)
: QDialog(parent), ui{} {
ui.setupUi(this);
output_device = ui.output_device;
connect(ui.midi_refresh_button, &QPushButton::clicked,
[this] { emit clients_update(); });
connect(ui.buttonBox, &QDialogButtonBox::accepted,
this, &xmidix_config::accepted_handler);
connect(ui.buttonBox, &QDialogButtonBox::rejected,
this, &xmidix_config::rejected_handler);
}
xmidix_client_info xmidix_config::get_selected_client() {
return clients[output_index];
}
void xmidix_config::reload_settings() {
// ui.systray_check->setChecked(settings.)
}
void xmidix_config::set_selected_client(int client_id, int port_id) {
for (int i = 0; i < clients.size(); i++) {
auto client = clients[i];
if (client.client_id == client_id && client.port_id == port_id) {
output_device->setCurrentIndex(i);
return;
}
}
}
void xmidix_config::clients_updated(const std::vector<xmidix_client_info> &c) {
clients = c;
output_index = output_device->currentIndex();
output_device->clear();
for (const auto &client : clients) {
auto txt = fmt::format("{}:{}\t{} - {}",
client.client_id, client.port_id,
client.client_name, client.port_name);
output_device->addItem(QString::fromStdString(txt));
}
output_device->setCurrentIndex(output_index);
}
void xmidix_config::accepted_handler() {
bool updated = false;
if (output_device->currentIndex() != output_index) {
output_index = output_device->currentIndex();
updated = true;
}
if (ui.systray_check->isChecked() != systray) {
updated = true;
systray = ui.systray_check->isChecked();
}
if (ui.channel_status_check->isChecked() != chanbar) {
updated = true;
chanbar = ui.channel_status_check->isChecked();
}
if (updated) {
emit config_updated();
}
}
void xmidix_config::rejected_handler() {
output_device->setCurrentIndex(output_index);
}
void xmidix_config::showEvent(QShowEvent *event) {
reload_settings();
QDialog::showEvent(event);
}