From 4ca6c029e2ab175377de1f09f75afbe0ebb06acb Mon Sep 17 00:00:00 2001 From: Luca Weiss Date: Sun, 15 Mar 2020 23:24:59 +0100 Subject: [PATCH] Implement backend switch --- src/preferences/preferences.cpp | 18 ++++++++++++++++++ src/razergenie.cpp | 12 ++++++++++-- src/razergenie.h | 3 +++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/preferences/preferences.cpp b/src/preferences/preferences.cpp index 74f19d0..a28f88d 100644 --- a/src/preferences/preferences.cpp +++ b/src/preferences/preferences.cpp @@ -19,6 +19,7 @@ #include "preferences.h" #include +#include #include #include #include @@ -64,6 +65,22 @@ Preferences::Preferences(libopenrazer::Manager *manager, QWidget *parent) settings.setValue("downloadImages", checked); }); + auto backendHbox = new QHBoxLayout(); + + auto backendLabel = new QLabel(this); + backendLabel->setText(tr("Daemon backend to use:")); + + auto *backendComboBox = new QComboBox(this); + backendComboBox->addItem("OpenRazer"); + backendComboBox->addItem("razer_test"); + backendComboBox->setCurrentText(settings.value("backend").toString()); + connect(backendComboBox, QOverload::of(&QComboBox::currentIndexChanged), [=](const QString &text) { + settings.setValue("backend", text); + }); + + backendHbox->addWidget(backendLabel); + backendHbox->addWidget(backendComboBox); + auto *spacer = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding); vbox->addWidget(aboutLabel); @@ -72,6 +89,7 @@ Preferences::Preferences(libopenrazer::Manager *manager, QWidget *parent) vbox->addWidget(generalLabel); vbox->addWidget(downloadText); vbox->addWidget(downloadCheckBox); + vbox->addLayout(backendHbox); vbox->addItem(spacer); this->resize(600, 400); diff --git a/src/razergenie.cpp b/src/razergenie.cpp index 1936e37..45fb39b 100644 --- a/src/razergenie.cpp +++ b/src/razergenie.cpp @@ -39,7 +39,15 @@ RazerGenie::RazerGenie(QWidget *parent) // Set the directory of the application to where the application is located. Needed for the custom editor and relative paths. QDir::setCurrent(QCoreApplication::applicationDirPath()); - manager = new libopenrazer::Manager(); + QString backend = settings.value("backend").toString(); + if (backend == "OpenRazer") { + manager = new libopenrazer::openrazer::Manager(); + } else if (backend == "razer_test") { + manager = new libopenrazer::razer_test::Manager(); + } else { + qWarning() << "Invalid backend value. Using openrazer backend."; + manager = new libopenrazer::openrazer::Manager(); + } // What to do: // If disabled, popup to enable : "The daemon service is not auto-started. Press this button to use the full potential of the daemon right after login." => DONE @@ -278,7 +286,7 @@ void RazerGenie::clearDeviceList() void RazerGenie::addDeviceToGui(const QDBusObjectPath &devicePath) { // Create device instance with current serial - libopenrazer::Device *currentDevice = new libopenrazer::Device(devicePath); + libopenrazer::Device *currentDevice = manager->getDevice(devicePath); // Setup variables for easy access QString type = currentDevice->getDeviceType(); diff --git a/src/razergenie.h b/src/razergenie.h index 4fb7a6a..9271dad 100644 --- a/src/razergenie.h +++ b/src/razergenie.h @@ -21,6 +21,7 @@ #include "ui_razergenie.h" +#include #include class RazerGenie : public QWidget @@ -67,6 +68,8 @@ public slots: QHash devices; libopenrazer::Manager *manager; + + QSettings settings; }; #endif