Skip to content

Commit

Permalink
Implement backend switch
Browse files Browse the repository at this point in the history
  • Loading branch information
z3ntu committed Apr 23, 2020
1 parent 05e1885 commit 4ca6c02
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
18 changes: 18 additions & 0 deletions src/preferences/preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "preferences.h"

#include <QCheckBox>
#include <QComboBox>
#include <QLabel>
#include <QVBoxLayout>
#include <config.h>
Expand Down Expand Up @@ -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<const QString &>::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);
Expand All @@ -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);
Expand Down
12 changes: 10 additions & 2 deletions src/razergenie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions src/razergenie.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include "ui_razergenie.h"

#include <QSettings>
#include <libopenrazer.h>

class RazerGenie : public QWidget
Expand Down Expand Up @@ -67,6 +68,8 @@ public slots:

QHash<QDBusObjectPath, libopenrazer::Device *> devices;
libopenrazer::Manager *manager;

QSettings settings;
};

#endif

0 comments on commit 4ca6c02

Please sign in to comment.