author | František Kučera <franta-hg@frantovo.cz> |
Fri, 30 Aug 2019 01:22:12 +0200 | |
branch | v_0 |
changeset 16 | 2705911938b4 |
child 17 | d37c6dd9aa20 |
permissions | -rw-r--r-- |
16
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
1 |
/** |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
2 |
* cadMousePro |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
3 |
* Copyright © 2019 František Kučera (Frantovo.cz, GlobalCode.info) |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
4 |
* |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
5 |
* This program is free software: you can redistribute it and/or modify |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
6 |
* it under the terms of the GNU General Public License as published by |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
7 |
* the Free Software Foundation, either version 3 of the License, or |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
8 |
* (at your option) any later version. |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
9 |
* |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
10 |
* This program is distributed in the hope that it will be useful, |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
13 |
* GNU General Public License for more details. |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
14 |
* |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
16 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
17 |
*/ |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
18 |
#include <QLabel> |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
19 |
#include <QPushButton> |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
20 |
|
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
21 |
#include "MouseMainWindow.h" |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
22 |
|
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
23 |
MouseMainWindow::MouseMainWindow() { |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
24 |
proxy = new InfoGlobalcodeMouseCadMouseProInterface("info.globalcode.mouse.cadMousePro", "/info/globalcode/mouse/cadMousePro", connection, this); |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
25 |
|
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
26 |
resize(640, 480); |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
27 |
setWindowTitle("cadMousePro"); |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
28 |
centralwidget = new QWidget(this); |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
29 |
formLayout = new QFormLayout(centralwidget); |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
30 |
|
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
31 |
int f = 0; |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
32 |
|
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
33 |
formLayout->setWidget(f++, QFormLayout::LabelRole, new QLabel("How does the mouse feel:", centralwidget)); |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
34 |
|
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
35 |
statusProxy->setEnabled(false); |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
36 |
statusUPower->setEnabled(false); |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
37 |
statusDevice->setEnabled(false); |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
38 |
|
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
39 |
formLayout->setWidget(f++, QFormLayout::FieldRole, statusProxy); |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
40 |
formLayout->setWidget(f++, QFormLayout::FieldRole, statusUPower); |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
41 |
formLayout->setWidget(f++, QFormLayout::FieldRole, statusDevice); |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
42 |
|
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
43 |
|
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
44 |
|
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
45 |
QPushButton* refreshButton = new QPushButton("Refresh", this); |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
46 |
formLayout->setWidget(f++, QFormLayout::FieldRole, refreshButton); |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
47 |
connect(refreshButton, &QPushButton::clicked, this, &MouseMainWindow::refresh); |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
48 |
|
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
49 |
|
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
50 |
|
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
51 |
formLayout->setWidget(f++, QFormLayout::LabelRole, new QLabel("Talk to your mouse:", centralwidget)); |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
52 |
|
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
53 |
configureLiftOffDetection->setChecked(true); |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
54 |
formLayout->setWidget(f++, QFormLayout::FieldRole, configureLiftOffDetection); |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
55 |
formLayout->setWidget(f++, QFormLayout::FieldRole, configureSmartScrolling); |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
56 |
configureFrequency250->setChecked(true); |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
57 |
formLayout->setWidget(f++, QFormLayout::FieldRole, configureFrequency125); |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
58 |
formLayout->setWidget(f++, QFormLayout::FieldRole, configureFrequency250); |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
59 |
formLayout->setWidget(f++, QFormLayout::FieldRole, configureFrequency500); |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
60 |
formLayout->setWidget(f++, QFormLayout::FieldRole, configureFrequency1000); |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
61 |
|
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
62 |
QPushButton* configureButton = new QPushButton("Configure", this); |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
63 |
configureButton->setToolTip("n.b. current interface is write-only and the controls above just configures the mouse – does not show current configuration"); |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
64 |
formLayout->setWidget(f++, QFormLayout::FieldRole, configureButton); |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
65 |
connect(configureButton, &QPushButton::clicked, this, &MouseMainWindow::configure); |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
66 |
|
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
67 |
|
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
68 |
message->setReadOnly(true); |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
69 |
formLayout->setWidget(f++, QFormLayout::LabelRole, new QLabel("Mouse responds:", this)); |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
70 |
formLayout->setWidget(f++, QFormLayout::FieldRole, message); |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
71 |
|
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
72 |
setCentralWidget(centralwidget); |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
73 |
refresh(); |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
74 |
} |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
75 |
|
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
76 |
void MouseMainWindow::refresh() { |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
77 |
statusProxy->setChecked(proxy->isValid()); |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
78 |
statusDevice->setChecked(proxy->devicePresent()); |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
79 |
|
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
80 |
} |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
81 |
|
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
82 |
void MouseMainWindow::configure() { |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
83 |
int frequency; // TODO: get value from the group |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
84 |
if (configureFrequency125->isChecked()) frequency = 125; |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
85 |
else if (configureFrequency250->isChecked()) frequency = 250; |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
86 |
else if (configureFrequency500->isChecked()) frequency = 500; |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
87 |
else if (configureFrequency1000->isChecked()) frequency = 1000; |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
88 |
else frequency = 250; |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
89 |
|
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
90 |
auto response = proxy->configure(configureLiftOffDetection->isChecked(), configureSmartScrolling->isChecked(), frequency); |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
91 |
|
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
92 |
response.waitForFinished(); |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
93 |
if (response.isError()) message->setText("Error: " + response.error().message()); |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
94 |
else message->setText("mouse configured"); |
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
95 |
|
2705911938b4
GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
96 |
} |