cadMousePro-gui/src/MouseMainWindow.cpp
author František Kučera <franta-hg@frantovo.cz>
Wed, 23 Oct 2019 22:43:29 +0200
branchv_0
changeset 26 fff8e9a86e85
parent 21 642f32f76c9d
child 27 aacd87eddd68
permissions -rw-r--r--
fix license version: GNU GPLv3
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>
21
642f32f76c9d display the battery charge level (from UPower)
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
    19
#include <qt5/QtDBus/qdbuspendingcall.h>
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);
642f32f76c9d display the battery charge level (from UPower)
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
    49
	
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);
17
d37c6dd9aa20 tabs: Status, Configuration, About
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    74
	layout->setWidget(f++, QFormLayout::FieldRole, configureLiftOffDetection);
d37c6dd9aa20 tabs: Status, Configuration, About
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    75
	layout->setWidget(f++, QFormLayout::FieldRole, configureSmartScrolling);
16
2705911938b4 GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    76
	configureFrequency250->setChecked(true);
17
d37c6dd9aa20 tabs: Status, Configuration, About
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    77
	layout->setWidget(f++, QFormLayout::FieldRole, configureFrequency125);
d37c6dd9aa20 tabs: Status, Configuration, About
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    78
	layout->setWidget(f++, QFormLayout::FieldRole, configureFrequency250);
d37c6dd9aa20 tabs: Status, Configuration, About
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    79
	layout->setWidget(f++, QFormLayout::FieldRole, configureFrequency500);
d37c6dd9aa20 tabs: Status, Configuration, About
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    80
	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
    81
17
d37c6dd9aa20 tabs: Status, Configuration, About
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    82
	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
    83
	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
    84
	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
    85
	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
    86
17
d37c6dd9aa20 tabs: Status, Configuration, About
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    87
	message->setReadOnly(true);
d37c6dd9aa20 tabs: Status, Configuration, About
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    88
	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
    89
	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
    90
17
d37c6dd9aa20 tabs: Status, Configuration, About
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    91
	tabs->addTab(panel, "Configuration");
d37c6dd9aa20 tabs: Status, Configuration, About
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    92
}
16
2705911938b4 GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    93
18
7323a89c15e9 clickable links in About panel
František Kučera <franta-hg@frantovo.cz>
parents: 17
diff changeset
    94
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
    95
	QLabel* labelWidget = new QLabel(label, parent);
7323a89c15e9 clickable links in About panel
František Kučera <franta-hg@frantovo.cz>
parents: 17
diff changeset
    96
	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
    97
18
7323a89c15e9 clickable links in About panel
František Kučera <franta-hg@frantovo.cz>
parents: 17
diff changeset
    98
	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
    99
	textWidget->setOpenExternalLinks(true);
21
642f32f76c9d display the battery charge level (from UPower)
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   100
18
7323a89c15e9 clickable links in About panel
František Kučera <franta-hg@frantovo.cz>
parents: 17
diff changeset
   101
	layout->addRow(labelWidget, textWidget);
7323a89c15e9 clickable links in About panel
František Kučera <franta-hg@frantovo.cz>
parents: 17
diff changeset
   102
}
7323a89c15e9 clickable links in About panel
František Kučera <franta-hg@frantovo.cz>
parents: 17
diff changeset
   103
17
d37c6dd9aa20 tabs: Status, Configuration, About
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   104
void MouseMainWindow::initAboutPanel() {
d37c6dd9aa20 tabs: Status, Configuration, About
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   105
	QWidget* panel = new QWidget(this);
d37c6dd9aa20 tabs: Status, Configuration, About
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   106
	QFormLayout* layout = new QFormLayout(panel);
18
7323a89c15e9 clickable links in About panel
František Kučera <franta-hg@frantovo.cz>
parents: 17
diff changeset
   107
7323a89c15e9 clickable links in About panel
František Kučera <franta-hg@frantovo.cz>
parents: 17
diff changeset
   108
	appendAboutLine(layout, "Program name:", "cadMousePro", panel);
7323a89c15e9 clickable links in About panel
František Kučera <franta-hg@frantovo.cz>
parents: 17
diff changeset
   109
	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
   110
	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
   111
	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
   112
	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
   113
	appendAboutLine(layout, "BTC:", "bc1qmt3qgzcf3a0f0tvnm70zjr0vhlchfyrjtnleqm", panel);
7323a89c15e9 clickable links in About panel
František Kučera <franta-hg@frantovo.cz>
parents: 17
diff changeset
   114
17
d37c6dd9aa20 tabs: Status, Configuration, About
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   115
	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
   116
}
2705911938b4 GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   117
21
642f32f76c9d display the battery charge level (from UPower)
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   118
/**
642f32f76c9d display the battery charge level (from UPower)
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   119
 * 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
   120
 * 
642f32f76c9d display the battery charge level (from UPower)
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   121
 * @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
   122
 */
642f32f76c9d display the battery charge level (from UPower)
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   123
int MouseMainWindow::getBatteryLevel() {
642f32f76c9d display the battery charge level (from UPower)
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   124
	auto devices = upowerProxy->EnumerateDevices();
642f32f76c9d display the battery charge level (from UPower)
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   125
	devices.waitForFinished();
642f32f76c9d display the battery charge level (from UPower)
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   126
	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
   127
		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
   128
			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
   129
			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
   130
		}
642f32f76c9d display the battery charge level (from UPower)
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   131
	}
642f32f76c9d display the battery charge level (from UPower)
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   132
	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
   133
}
642f32f76c9d display the battery charge level (from UPower)
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
   134
16
2705911938b4 GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   135
void MouseMainWindow::refresh() {
2705911938b4 GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   136
	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
   137
	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
   138
	statusDevice->setChecked(proxy->devicePresent());
20
cfb5f62ea048 display the USB device name
František Kučera <franta-hg@frantovo.cz>
parents: 18
diff changeset
   139
	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
   140
	statusBattery->setValue(getBatteryLevel());
16
2705911938b4 GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   141
}
2705911938b4 GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   142
2705911938b4 GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   143
void MouseMainWindow::configure() {
17
d37c6dd9aa20 tabs: Status, Configuration, About
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   144
	message->setText("…");
18
7323a89c15e9 clickable links in About panel
František Kučera <franta-hg@frantovo.cz>
parents: 17
diff changeset
   145
16
2705911938b4 GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   146
	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
   147
	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
   148
	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
   149
	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
   150
	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
   151
	else frequency = 250;
17
d37c6dd9aa20 tabs: Status, Configuration, About
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   152
16
2705911938b4 GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   153
	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
   154
2705911938b4 GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   155
	response.waitForFinished();
2705911938b4 GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   156
	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
   157
	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
   158
2705911938b4 GUI for mouse configuration over D-Bus daemon
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   159
}