cadMousePro-gui/src/MouseMainWindow.cpp
author František Kučera <franta-hg@frantovo.cz>
Sat, 03 Apr 2021 17:39:35 +0200
branchv_0
changeset 33 0dc4e2942840
parent 29 361687fe303a
permissions -rw-r--r--
support also the wired version of CadMouse Pro currently, there is a simple autodetection: we enumerate HID devices and look for the wireless version, if not found, we look for the wired version
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
26
fff8e9a86e85 fix license version: GNU GPLv3
František Kučera <franta-hg@frantovo.cz>
parents: 21
diff changeset
     7
 * the Free Software Foundation, version 3 of the License.
16
2705911938b4 GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     8
 *
2705911938b4 GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     9
 * 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
    10
 * 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
    11
 * 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
    12
 * 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
    13
 *
2705911938b4 GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    14
 * 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
    15
 * 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
    16
 */
2705911938b4 GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    17
#include <QLabel>
2705911938b4 GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    18
#include <QPushButton>
27
aacd87eddd68 fix Qt header include
František Kučera <franta-hg@frantovo.cz>
parents: 26
diff changeset
    19
#include <QtDBus/QDBusPendingCall>
16
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);
21
642f32f76c9d display the battery charge level (from UPower)
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
    25
	upowerProxy = new OrgFreedesktopUPowerInterface("org.freedesktop.UPower", "/org/freedesktop/UPower", connection, this);
16
2705911938b4 GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    26
2705911938b4 GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    27
	setWindowTitle("cadMousePro");
17
d37c6dd9aa20 tabs: Status, Configuration, About
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    28
d37c6dd9aa20 tabs: Status, Configuration, About
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    29
	initStatusPanel();
d37c6dd9aa20 tabs: Status, Configuration, About
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    30
	initConfigurationPanel();
d37c6dd9aa20 tabs: Status, Configuration, About
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    31
	initAboutPanel();
d37c6dd9aa20 tabs: Status, Configuration, About
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    32
d37c6dd9aa20 tabs: Status, Configuration, About
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    33
	setCentralWidget(tabs);
d37c6dd9aa20 tabs: Status, Configuration, About
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    34
	refresh();
d37c6dd9aa20 tabs: Status, Configuration, About
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    35
}
d37c6dd9aa20 tabs: Status, Configuration, About
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    36
d37c6dd9aa20 tabs: Status, Configuration, About
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    37
void MouseMainWindow::initStatusPanel() {
d37c6dd9aa20 tabs: Status, Configuration, About
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    38
	QWidget* panel = new QWidget(this);
d37c6dd9aa20 tabs: Status, Configuration, About
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    39
	QFormLayout* layout = new QFormLayout(panel);
16
2705911938b4 GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    40
2705911938b4 GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    41
	int f = 0;
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
	statusProxy->setEnabled(false);
2705911938b4 GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    44
	statusUPower->setEnabled(false);
2705911938b4 GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    45
	statusDevice->setEnabled(false);
21
642f32f76c9d display the battery charge level (from UPower)
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
    46
	statusBattery->setOrientation(Qt::Orientation::Horizontal);
642f32f76c9d display the battery charge level (from UPower)
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
    47
	statusBattery->setMinimum(0);
642f32f76c9d display the battery charge level (from UPower)
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
    48
	statusBattery->setMaximum(100);
29
361687fe303a add two new options: 1) remap wheel button 2) remap gesture button
František Kučera <franta-hg@frantovo.cz>
parents: 27
diff changeset
    49
21
642f32f76c9d display the battery charge level (from UPower)
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
    50
	statusUPower->setToolTip("UPower interface is used for getting the battery level");
20
cfb5f62ea048 display the USB device name
František Kučera <franta-hg@frantovo.cz>
parents: 18
diff changeset
    51
	statusName->setToolTip("name of the USB device – usually the wireless adaptor");
21
642f32f76c9d display the battery charge level (from UPower)
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
    52
	statusBattery->setToolTip("battery charge level");
16
2705911938b4 GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    53
17
d37c6dd9aa20 tabs: Status, Configuration, About
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    54
	layout->setWidget(f++, QFormLayout::FieldRole, statusProxy);
d37c6dd9aa20 tabs: Status, Configuration, About
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    55
	layout->setWidget(f++, QFormLayout::FieldRole, statusUPower);
d37c6dd9aa20 tabs: Status, Configuration, About
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    56
	layout->setWidget(f++, QFormLayout::FieldRole, statusDevice);
20
cfb5f62ea048 display the USB device name
František Kučera <franta-hg@frantovo.cz>
parents: 18
diff changeset
    57
	layout->setWidget(f++, QFormLayout::FieldRole, statusName);
21
642f32f76c9d display the battery charge level (from UPower)
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
    58
	layout->setWidget(f++, QFormLayout::FieldRole, statusBattery);
16
2705911938b4 GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    59
17
d37c6dd9aa20 tabs: Status, Configuration, About
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    60
	QPushButton* refreshButton = new QPushButton("Refresh", panel);
d37c6dd9aa20 tabs: Status, Configuration, About
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    61
	layout->setWidget(f++, QFormLayout::FieldRole, refreshButton);
16
2705911938b4 GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    62
	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
    63
17
d37c6dd9aa20 tabs: Status, Configuration, About
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    64
	tabs->addTab(panel, "Status");
d37c6dd9aa20 tabs: Status, Configuration, About
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    65
}
16
2705911938b4 GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    66
17
d37c6dd9aa20 tabs: Status, Configuration, About
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    67
void MouseMainWindow::initConfigurationPanel() {
d37c6dd9aa20 tabs: Status, Configuration, About
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    68
	QWidget* panel = new QWidget(this);
d37c6dd9aa20 tabs: Status, Configuration, About
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    69
	QFormLayout* layout = new QFormLayout(panel);
d37c6dd9aa20 tabs: Status, Configuration, About
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    70
d37c6dd9aa20 tabs: Status, Configuration, About
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    71
	int f = 0;
16
2705911938b4 GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    72
2705911938b4 GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    73
	configureLiftOffDetection->setChecked(true);
29
361687fe303a add two new options: 1) remap wheel button 2) remap gesture button
František Kučera <franta-hg@frantovo.cz>
parents: 27
diff changeset
    74
	configureRemapWheelPressed->setChecked(true);
361687fe303a add two new options: 1) remap wheel button 2) remap gesture button
František Kučera <franta-hg@frantovo.cz>
parents: 27
diff changeset
    75
	configureRemapGestureButton->setChecked(true);
17
d37c6dd9aa20 tabs: Status, Configuration, About
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    76
	layout->setWidget(f++, QFormLayout::FieldRole, configureLiftOffDetection);
d37c6dd9aa20 tabs: Status, Configuration, About
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    77
	layout->setWidget(f++, QFormLayout::FieldRole, configureSmartScrolling);
29
361687fe303a add two new options: 1) remap wheel button 2) remap gesture button
František Kučera <franta-hg@frantovo.cz>
parents: 27
diff changeset
    78
	layout->setWidget(f++, QFormLayout::FieldRole, configureRemapWheelPressed);
361687fe303a add two new options: 1) remap wheel button 2) remap gesture button
František Kučera <franta-hg@frantovo.cz>
parents: 27
diff changeset
    79
	layout->setWidget(f++, QFormLayout::FieldRole, configureRemapGestureButton);
16
2705911938b4 GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    80
	configureFrequency250->setChecked(true);
17
d37c6dd9aa20 tabs: Status, Configuration, About
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    81
	layout->setWidget(f++, QFormLayout::FieldRole, configureFrequency125);
d37c6dd9aa20 tabs: Status, Configuration, About
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    82
	layout->setWidget(f++, QFormLayout::FieldRole, configureFrequency250);
d37c6dd9aa20 tabs: Status, Configuration, About
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    83
	layout->setWidget(f++, QFormLayout::FieldRole, configureFrequency500);
d37c6dd9aa20 tabs: Status, Configuration, About
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    84
	layout->setWidget(f++, QFormLayout::FieldRole, configureFrequency1000);
16
2705911938b4 GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    85
17
d37c6dd9aa20 tabs: Status, Configuration, About
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    86
	QPushButton* configureButton = new QPushButton("Configure", panel);
16
2705911938b4 GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    87
	configureButton->setToolTip("n.b. current interface is write-only and the controls above just configures the mouse – does not show current configuration");
17
d37c6dd9aa20 tabs: Status, Configuration, About
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    88
	layout->setWidget(f++, QFormLayout::FieldRole, configureButton);
16
2705911938b4 GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    89
	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
    90
17
d37c6dd9aa20 tabs: Status, Configuration, About
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    91
	message->setReadOnly(true);
d37c6dd9aa20 tabs: Status, Configuration, About
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    92
	layout->setWidget(f++, QFormLayout::FieldRole, new QLabel("Result:", panel));
d37c6dd9aa20 tabs: Status, Configuration, About
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    93
	layout->setWidget(f++, QFormLayout::FieldRole, message);
16
2705911938b4 GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    94
17
d37c6dd9aa20 tabs: Status, Configuration, About
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    95
	tabs->addTab(panel, "Configuration");
d37c6dd9aa20 tabs: Status, Configuration, About
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    96
}
16
2705911938b4 GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    97
18
7323a89c15e9 clickable links in About panel
František Kučera <franta-hg@frantovo.cz>
parents: 17
diff changeset
    98
void MouseMainWindow::appendAboutLine(QFormLayout* layout, const QString& label, const QString& value, QWidget* parent) {
7323a89c15e9 clickable links in About panel
František Kučera <franta-hg@frantovo.cz>
parents: 17
diff changeset
    99
	QLabel* labelWidget = new QLabel(label, parent);
7323a89c15e9 clickable links in About panel
František Kučera <franta-hg@frantovo.cz>
parents: 17
diff changeset
   100
	QLabel* textWidget = new QLabel(value, parent);
21
642f32f76c9d display the battery charge level (from UPower)
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   101
18
7323a89c15e9 clickable links in About panel
František Kučera <franta-hg@frantovo.cz>
parents: 17
diff changeset
   102
	textWidget->setTextInteractionFlags(Qt::TextInteractionFlag::TextSelectableByMouse | Qt::TextInteractionFlag::TextBrowserInteraction);
7323a89c15e9 clickable links in About panel
František Kučera <franta-hg@frantovo.cz>
parents: 17
diff changeset
   103
	textWidget->setOpenExternalLinks(true);
21
642f32f76c9d display the battery charge level (from UPower)
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   104
18
7323a89c15e9 clickable links in About panel
František Kučera <franta-hg@frantovo.cz>
parents: 17
diff changeset
   105
	layout->addRow(labelWidget, textWidget);
7323a89c15e9 clickable links in About panel
František Kučera <franta-hg@frantovo.cz>
parents: 17
diff changeset
   106
}
7323a89c15e9 clickable links in About panel
František Kučera <franta-hg@frantovo.cz>
parents: 17
diff changeset
   107
17
d37c6dd9aa20 tabs: Status, Configuration, About
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   108
void MouseMainWindow::initAboutPanel() {
d37c6dd9aa20 tabs: Status, Configuration, About
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   109
	QWidget* panel = new QWidget(this);
d37c6dd9aa20 tabs: Status, Configuration, About
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   110
	QFormLayout* layout = new QFormLayout(panel);
18
7323a89c15e9 clickable links in About panel
František Kučera <franta-hg@frantovo.cz>
parents: 17
diff changeset
   111
7323a89c15e9 clickable links in About panel
František Kučera <franta-hg@frantovo.cz>
parents: 17
diff changeset
   112
	appendAboutLine(layout, "Program name:", "cadMousePro", panel);
7323a89c15e9 clickable links in About panel
František Kučera <franta-hg@frantovo.cz>
parents: 17
diff changeset
   113
	appendAboutLine(layout, "Description:", "configuration tool for 3DConnexion CadMouse Pro Wireless", panel);
7323a89c15e9 clickable links in About panel
František Kučera <franta-hg@frantovo.cz>
parents: 17
diff changeset
   114
	appendAboutLine(layout, "Author:", "Ing. František Kučera (Frantovo.cz, GlobalCode.info)", panel);
7323a89c15e9 clickable links in About panel
František Kučera <franta-hg@frantovo.cz>
parents: 17
diff changeset
   115
	appendAboutLine(layout, "License:", "<a href='https://www.gnu.org/licenses/gpl-3.0.html'>GNU GPLv3+</a>", panel);
7323a89c15e9 clickable links in About panel
František Kučera <franta-hg@frantovo.cz>
parents: 17
diff changeset
   116
	appendAboutLine(layout, "Contact and support:", "<a href='https://mouse.globalcode.info/'>https://mouse.globalcode.info/</a>", panel);
7323a89c15e9 clickable links in About panel
František Kučera <franta-hg@frantovo.cz>
parents: 17
diff changeset
   117
	appendAboutLine(layout, "BTC:", "bc1qmt3qgzcf3a0f0tvnm70zjr0vhlchfyrjtnleqm", panel);
7323a89c15e9 clickable links in About panel
František Kučera <franta-hg@frantovo.cz>
parents: 17
diff changeset
   118
17
d37c6dd9aa20 tabs: Status, Configuration, About
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   119
	tabs->addTab(panel, "About");
16
2705911938b4 GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   120
}
2705911938b4 GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   121
21
642f32f76c9d display the battery charge level (from UPower)
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   122
/**
642f32f76c9d display the battery charge level (from UPower)
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   123
 * Finds the first HID mouse managed by UPower and returns its battery level.
642f32f76c9d display the battery charge level (from UPower)
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   124
 * 
642f32f76c9d display the battery charge level (from UPower)
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   125
 * @return percentage of the current battery charge or 0 if no suitable mouse was found
642f32f76c9d display the battery charge level (from UPower)
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   126
 */
642f32f76c9d display the battery charge level (from UPower)
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   127
int MouseMainWindow::getBatteryLevel() {
642f32f76c9d display the battery charge level (from UPower)
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   128
	auto devices = upowerProxy->EnumerateDevices();
642f32f76c9d display the battery charge level (from UPower)
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   129
	devices.waitForFinished();
642f32f76c9d display the battery charge level (from UPower)
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   130
	for (auto device : devices.value()) {
642f32f76c9d display the battery charge level (from UPower)
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   131
		if (device.path().startsWith(upowerProxy->path() + "/devices/mouse_hid_") && device.path().endsWith("_battery")) {
642f32f76c9d display the battery charge level (from UPower)
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   132
			OrgFreedesktopUPowerDeviceInterface battery(upowerProxy->service(), device.path(), connection, this);
642f32f76c9d display the battery charge level (from UPower)
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   133
			if (battery.isValid()) return battery.percentage();
642f32f76c9d display the battery charge level (from UPower)
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   134
		}
642f32f76c9d display the battery charge level (from UPower)
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   135
	}
642f32f76c9d display the battery charge level (from UPower)
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   136
	return 0; // mouse with battery not found
642f32f76c9d display the battery charge level (from UPower)
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   137
}
642f32f76c9d display the battery charge level (from UPower)
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   138
16
2705911938b4 GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   139
void MouseMainWindow::refresh() {
2705911938b4 GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   140
	statusProxy->setChecked(proxy->isValid());
21
642f32f76c9d display the battery charge level (from UPower)
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   141
	statusUPower->setChecked(upowerProxy->isValid());
16
2705911938b4 GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   142
	statusDevice->setChecked(proxy->devicePresent());
20
cfb5f62ea048 display the USB device name
František Kučera <franta-hg@frantovo.cz>
parents: 18
diff changeset
   143
	statusName->setText(proxy->deviceName());
21
642f32f76c9d display the battery charge level (from UPower)
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   144
	statusBattery->setValue(getBatteryLevel());
16
2705911938b4 GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   145
}
2705911938b4 GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   146
2705911938b4 GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   147
void MouseMainWindow::configure() {
17
d37c6dd9aa20 tabs: Status, Configuration, About
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   148
	message->setText("…");
18
7323a89c15e9 clickable links in About panel
František Kučera <franta-hg@frantovo.cz>
parents: 17
diff changeset
   149
16
2705911938b4 GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   150
	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
   151
	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
   152
	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
   153
	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
   154
	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
   155
	else frequency = 250;
17
d37c6dd9aa20 tabs: Status, Configuration, About
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   156
29
361687fe303a add two new options: 1) remap wheel button 2) remap gesture button
František Kučera <franta-hg@frantovo.cz>
parents: 27
diff changeset
   157
	auto response = proxy->configure(
361687fe303a add two new options: 1) remap wheel button 2) remap gesture button
František Kučera <franta-hg@frantovo.cz>
parents: 27
diff changeset
   158
			configureLiftOffDetection->isChecked(),
361687fe303a add two new options: 1) remap wheel button 2) remap gesture button
František Kučera <franta-hg@frantovo.cz>
parents: 27
diff changeset
   159
			configureSmartScrolling->isChecked(),
361687fe303a add two new options: 1) remap wheel button 2) remap gesture button
František Kučera <franta-hg@frantovo.cz>
parents: 27
diff changeset
   160
			configureRemapWheelPressed->isChecked(),
361687fe303a add two new options: 1) remap wheel button 2) remap gesture button
František Kučera <franta-hg@frantovo.cz>
parents: 27
diff changeset
   161
			configureRemapGestureButton->isChecked(),
361687fe303a add two new options: 1) remap wheel button 2) remap gesture button
František Kučera <franta-hg@frantovo.cz>
parents: 27
diff changeset
   162
			frequency);
16
2705911938b4 GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   163
2705911938b4 GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   164
	response.waitForFinished();
2705911938b4 GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   165
	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
   166
	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
   167
2705911938b4 GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   168
}