GUI for mouse configuration over D-Bus daemon v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Fri, 30 Aug 2019 01:22:12 +0200
branchv_0
changeset 16 2705911938b4
parent 15 00783e323e66
child 17 d37c6dd9aa20
GUI for mouse configuration over D-Bus daemon
cadMousePro-gui/nbproject/configurations.xml
cadMousePro-gui/src/CMakeLists.txt
cadMousePro-gui/src/MouseMainWindow.cpp
cadMousePro-gui/src/MouseMainWindow.h
cadMousePro-gui/src/cadMouseProGUI.cpp
--- a/cadMousePro-gui/nbproject/configurations.xml	Thu Aug 29 22:20:18 2019 +0200
+++ b/cadMousePro-gui/nbproject/configurations.xml	Fri Aug 30 01:22:12 2019 +0200
@@ -61,6 +61,7 @@
         </df>
       </df>
       <df name="src">
+        <in>MouseMainWindow.cpp</in>
         <in>MouseMainWindow.h</in>
         <in>cadMouseProGUI.cpp</in>
       </df>
@@ -69,6 +70,9 @@
                    displayName="cadMousePro-gui_autogen"
                    projectFiles="true"
                    root="build/Debug/src/cadMousePro-gui_autogen">
+      <logicalFolder name="EWIEGA46WW" displayName="EWIEGA46WW" projectFiles="true">
+        <itemPath>build/Debug/src/cadMousePro-gui_autogen/EWIEGA46WW/moc_MouseMainWindow.cpp</itemPath>
+      </logicalFolder>
       <logicalFolder name="S5VNLJ26FI" displayName="S5VNLJ26FI" projectFiles="true">
         <itemPath>build/Debug/src/cadMousePro-gui_autogen/S5VNLJ26FI/moc_Proxy.cpp</itemPath>
       </logicalFolder>
@@ -131,6 +135,11 @@
         <ccTool flags="1">
         </ccTool>
       </item>
+      <item path="build/Debug/src/cadMousePro-gui_autogen/EWIEGA46WW/moc_MouseMainWindow.cpp"
+            ex="true"
+            tool="3"
+            flavor2="0">
+      </item>
       <item path="build/Debug/src/cadMousePro-gui_autogen/S5VNLJ26FI/moc_Proxy.cpp"
             ex="true"
             tool="3"
@@ -188,6 +197,10 @@
             <pElem>/usr/include/x86_64-linux-gnu/qt5/QtDBus</pElem>
             <pElem>build/qt/src/generated-sources</pElem>
             <pElem>build/qt/src/cadMousePro-gui_autogen/S5VNLJ26FI</pElem>
+            <pElem>src</pElem>
+            <pElem>build/qt/src/cadMousePro-gui_autogen/EWIEGA46WW</pElem>
+            <pElem>/usr/include/x86_64-linux-gnu/qt5/QtGui</pElem>
+            <pElem>/usr/include/x86_64-linux-gnu/qt5/QtWidgets</pElem>
             <pElem>build/qt/src/cadMousePro-gui_autogen</pElem>
             <pElem>/usr/include/x86_64-linux-gnu/qt5</pElem>
             <pElem>build/qt/src</pElem>
@@ -205,20 +218,6 @@
           </incDir>
         </ccTool>
       </folder>
-      <folder path="0/src">
-        <ccTool>
-          <incDir>
-            <pElem>/usr/include/x86_64-linux-gnu/qt5/QtCore</pElem>
-            <pElem>/usr/include/x86_64-linux-gnu/qt5/QtDBus</pElem>
-            <pElem>build/Debug/src/generated-sources</pElem>
-            <pElem>/usr/include/x86_64-linux-gnu/qt5/QtWidgets</pElem>
-            <pElem>src</pElem>
-            <pElem>/usr/include/x86_64-linux-gnu/qt5/QtGui</pElem>
-            <pElem>build/Debug/src</pElem>
-            <pElem>/usr/include/x86_64-linux-gnu/qt5</pElem>
-          </incDir>
-        </ccTool>
-      </folder>
       <folder path="Modules">
         <ccTool>
           <incDir>
@@ -251,14 +250,38 @@
             <pElem>src</pElem>
             <pElem>build/Debug/src/cadMousePro-gui_autogen/EWIEGA46WW</pElem>
             <pElem>/usr/include/x86_64-linux-gnu/qt5/QtGui</pElem>
+            <pElem>/usr/include/x86_64-linux-gnu/qt5/QtWidgets</pElem>
             <pElem>build/Debug/src/cadMousePro-gui_autogen</pElem>
             <pElem>/usr/include/x86_64-linux-gnu/qt5</pElem>
             <pElem>build/Debug/src</pElem>
           </incDir>
         </ccTool>
       </folder>
+      <item path="src/MouseMainWindow.cpp" ex="false" tool="1" flavor2="8">
+        <ccTool flags="0">
+          <incDir>
+            <pElem>/usr/include/x86_64-linux-gnu/qt5/QtCore</pElem>
+            <pElem>/usr/include/x86_64-linux-gnu/qt5/QtWidgets</pElem>
+            <pElem>/usr/include/x86_64-linux-gnu/qt5/QtDBus</pElem>
+            <pElem>build/Debug/src/generated-sources</pElem>
+            <pElem>src</pElem>
+            <pElem>/usr/include/x86_64-linux-gnu/qt5/QtGui</pElem>
+            <pElem>/usr/include/x86_64-linux-gnu/qt5</pElem>
+            <pElem>build/Debug/src</pElem>
+          </incDir>
+        </ccTool>
+      </item>
       <item path="src/cadMouseProGUI.cpp" ex="false" tool="1" flavor2="8">
         <ccTool flags="0">
+          <incDir>
+            <pElem>src</pElem>
+            <pElem>/usr/include/x86_64-linux-gnu/qt5/QtCore</pElem>
+            <pElem>/usr/include/x86_64-linux-gnu/qt5/QtGui</pElem>
+            <pElem>/usr/include/x86_64-linux-gnu/qt5/QtWidgets</pElem>
+            <pElem>/usr/include/x86_64-linux-gnu/qt5/QtDBus</pElem>
+            <pElem>/usr/include/x86_64-linux-gnu/qt5</pElem>
+            <pElem>build/qt/src</pElem>
+          </incDir>
         </ccTool>
       </item>
     </conf>
@@ -291,6 +314,8 @@
           <preBuildFirst>true</preBuildFirst>
         </preBuild>
       </makefileType>
+      <item path="src/MouseMainWindow.cpp" ex="false" tool="1" flavor2="0">
+      </item>
       <item path="src/MouseMainWindow.h" ex="false" tool="3" flavor2="0">
       </item>
     </conf>
--- a/cadMousePro-gui/src/CMakeLists.txt	Thu Aug 29 22:20:18 2019 +0200
+++ b/cadMousePro-gui/src/CMakeLists.txt	Fri Aug 30 01:22:12 2019 +0200
@@ -30,6 +30,7 @@
 	${CMAKE_CURRENT_BINARY_DIR}/generated-sources/Proxy.h
 	${CMAKE_CURRENT_BINARY_DIR}/generated-sources/Proxy.cpp
 	MouseMainWindow.h
+	MouseMainWindow.cpp
 	cadMouseProGUI.cpp
 )
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cadMousePro-gui/src/MouseMainWindow.cpp	Fri Aug 30 01:22:12 2019 +0200
@@ -0,0 +1,96 @@
+/**
+ * cadMousePro
+ * Copyright © 2019 František Kučera (Frantovo.cz, GlobalCode.info)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#include <QLabel>
+#include <QPushButton>
+
+#include "MouseMainWindow.h"
+
+MouseMainWindow::MouseMainWindow() {
+	proxy = new InfoGlobalcodeMouseCadMouseProInterface("info.globalcode.mouse.cadMousePro", "/info/globalcode/mouse/cadMousePro", connection, this);
+
+	resize(640, 480);
+	setWindowTitle("cadMousePro");
+	centralwidget = new QWidget(this);
+	formLayout = new QFormLayout(centralwidget);
+
+	int f = 0;
+
+	formLayout->setWidget(f++, QFormLayout::LabelRole, new QLabel("How does the mouse feel:", centralwidget));
+
+	statusProxy->setEnabled(false);
+	statusUPower->setEnabled(false);
+	statusDevice->setEnabled(false);
+
+	formLayout->setWidget(f++, QFormLayout::FieldRole, statusProxy);
+	formLayout->setWidget(f++, QFormLayout::FieldRole, statusUPower);
+	formLayout->setWidget(f++, QFormLayout::FieldRole, statusDevice);
+
+
+
+	QPushButton* refreshButton = new QPushButton("Refresh", this);
+	formLayout->setWidget(f++, QFormLayout::FieldRole, refreshButton);
+	connect(refreshButton, &QPushButton::clicked, this, &MouseMainWindow::refresh);
+
+
+
+	formLayout->setWidget(f++, QFormLayout::LabelRole, new QLabel("Talk to your mouse:", centralwidget));
+
+	configureLiftOffDetection->setChecked(true);
+	formLayout->setWidget(f++, QFormLayout::FieldRole, configureLiftOffDetection);
+	formLayout->setWidget(f++, QFormLayout::FieldRole, configureSmartScrolling);
+	configureFrequency250->setChecked(true);
+	formLayout->setWidget(f++, QFormLayout::FieldRole, configureFrequency125);
+	formLayout->setWidget(f++, QFormLayout::FieldRole, configureFrequency250);
+	formLayout->setWidget(f++, QFormLayout::FieldRole, configureFrequency500);
+	formLayout->setWidget(f++, QFormLayout::FieldRole, configureFrequency1000);
+
+	QPushButton* configureButton = new QPushButton("Configure", this);
+	configureButton->setToolTip("n.b. current interface is write-only and the controls above just configures the mouse – does not show current configuration");
+	formLayout->setWidget(f++, QFormLayout::FieldRole, configureButton);
+	connect(configureButton, &QPushButton::clicked, this, &MouseMainWindow::configure);
+
+
+	message->setReadOnly(true);
+	formLayout->setWidget(f++, QFormLayout::LabelRole, new QLabel("Mouse responds:", this));
+	formLayout->setWidget(f++, QFormLayout::FieldRole, message);
+
+	setCentralWidget(centralwidget);
+	refresh();
+}
+
+void MouseMainWindow::refresh() {
+	statusProxy->setChecked(proxy->isValid());
+	statusDevice->setChecked(proxy->devicePresent());
+
+}
+
+void MouseMainWindow::configure() {
+	int frequency; // TODO: get value from the group
+	if (configureFrequency125->isChecked()) frequency = 125;
+	else if (configureFrequency250->isChecked()) frequency = 250;
+	else if (configureFrequency500->isChecked()) frequency = 500;
+	else if (configureFrequency1000->isChecked()) frequency = 1000;
+	else frequency = 250;
+	
+	auto response = proxy->configure(configureLiftOffDetection->isChecked(), configureSmartScrolling->isChecked(), frequency);
+
+	response.waitForFinished();
+	if (response.isError()) message->setText("Error: " + response.error().message());
+	else message->setText("mouse configured");
+
+}
--- a/cadMousePro-gui/src/MouseMainWindow.h	Thu Aug 29 22:20:18 2019 +0200
+++ b/cadMousePro-gui/src/MouseMainWindow.h	Fri Aug 30 01:22:12 2019 +0200
@@ -18,18 +18,43 @@
 #pragma once
 
 #include <QMainWindow>
+#include <QFormLayout>
+#include <QCheckBox>
+#include <QRadioButton>
+#include <QButtonGroup>
+#include <QLineEdit>
+#include <QtDBus/QDBusConnection>
+
+#include "generated-sources/Proxy.h"
 
 class MouseMainWindow : public QMainWindow {
-
 	Q_OBJECT
 public:
-	MouseMainWindow() {
-		resize(640, 480);
-		setWindowTitle("cadMousePro");
-		
-	}
+	MouseMainWindow();
 
 	virtual ~MouseMainWindow() {
 	}
 
+private:
+	QWidget* centralwidget;
+	QFormLayout* formLayout;
+	QCheckBox* statusProxy = new QCheckBox("connected to Daemon", this);
+	QCheckBox* statusUPower = new QCheckBox("connected to UPower", this);
+	QCheckBox* statusDevice = new QCheckBox("present", this);
+	
+	QCheckBox* configureSmartScrolling = new QCheckBox("smart scrolling (free wheel)", this);
+	QCheckBox* configureLiftOffDetection = new QCheckBox("lift-off detection", this);
+	QRadioButton* configureFrequency125 = new QRadioButton("125 Hz", this);
+	QRadioButton* configureFrequency250 = new QRadioButton("250 Hz", this);
+	QRadioButton* configureFrequency500 = new QRadioButton("500 Hz", this);
+	QRadioButton* configureFrequency1000 = new QRadioButton("1000 Hz", this);
+	
+	QLineEdit* message = new QLineEdit(this);
+	
+	QDBusConnection connection = QDBusConnection::systemBus();
+	InfoGlobalcodeMouseCadMouseProInterface* proxy;
+
+private slots:
+	void refresh();
+	void configure();
 };
\ No newline at end of file
--- a/cadMousePro-gui/src/cadMouseProGUI.cpp	Thu Aug 29 22:20:18 2019 +0200
+++ b/cadMousePro-gui/src/cadMouseProGUI.cpp	Fri Aug 30 01:22:12 2019 +0200
@@ -15,34 +15,15 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
-#include <iostream>
+#include <QApplication>
 
-#include <QApplication>
-#include <QtDBus/QDBusConnection>
-
-#include "generated-sources/Proxy.h"
 #include "MouseMainWindow.h"
 
 int main(int argc, char** argv) {
-
-	std::wcout << L"cadMousePro GUI" << std::endl;
+	QApplication qtApplication(argc, argv);
 
-
-	QApplication qtApplication(argc, argv);
-	
 	MouseMainWindow window;
 	window.show();
-	
-
-	QDBusConnection connection = QDBusConnection::systemBus();
-	
-	InfoGlobalcodeMouseCadMouseProInterface* proxy = new InfoGlobalcodeMouseCadMouseProInterface("info.globalcode.mouse.cadMousePro", "/info/globalcode/mouse/cadMousePro", connection, &qtApplication);
-
-	std::wcout << (proxy->isValid() ? L"connected" : L"disconnected") << std::endl;
-	std::wcout << (proxy->devicePresent() ? L"mouse found" : L"mouse not found") << std::endl;
-	std::wcout << L"mouse name: " << proxy->deviceName().toStdWString() << std::endl;
-	std::wcout << connection.lastError().message().toStdWString() << std::endl;
 
 	return qtApplication.exec();
-
 }