Initial implementation of Manual Devices Page

This commit is contained in:
Dmitry Kychanov committed 2025-06-27 17:45:53 +04:00
1 parent d796fcba8f
commit fd62686e22
23 files changed
+2373 -14

No files matched your search

+3
View File
@@ -149,6 +149,7 @@ INCLUDEPATH +=
dependencies/httplib \
dependencies/json/ \
dependencies/mdns \
dependencies/slidingstackedwidget \
dmiinfo/ \
hidapi_wrapper/ \
i2c_smbus/ \
@@ -172,6 +173,7 @@ HEADERS +=
Colors.h \
dependencies/ColorWheel/ColorWheel.h \
dependencies/json/nlohmann/json.hpp \
dependencies/slidingstackedwidget/slidingstackedwidget.h \
LogManager.h \
NetworkClient.h \
NetworkProtocol.h \
@@ -240,6 +242,7 @@ SOURCES +=
dependencies/hueplusplus-1.2.0/src/UPnP.cpp \
dependencies/hueplusplus-1.2.0/src/Utils.cpp \
dependencies/hueplusplus-1.2.0/src/ZLLSensors.cpp \
dependencies/slidingstackedwidget/slidingstackedwidget.cpp \
main.cpp \
cli.cpp \
dmiinfo/dmiinfo.cpp \
@@ -0,0 +1,209 @@
/*
* MIT License
Copyright (c) 2020 Tim Schneeberger (ThePBone) <tim.schneeberger(at)outlook.de>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*
*/
#include "slidingstackedwidget.h"
#include <QPropertyAnimation>
#include <QParallelAnimationGroup>
#include <QGraphicsOpacityEffect>
SlidingStackedWidget::SlidingStackedWidget(QWidget *parent)
: QStackedWidget(parent)
{
if (parent!=nullptr) {
m_mainwindow=parent;
}
else {
m_mainwindow=this;
}
m_vertical=false;
m_speed=300;
m_animationtype = QEasingCurve::OutQuart;
m_now=0;
m_next=0;
m_wrap=false;
m_pnow=QPoint(0,0);
m_active=false;
}
void SlidingStackedWidget::setVerticalMode(bool vertical) {
m_vertical=vertical;
}
void SlidingStackedWidget::setSpeed(int speed) {
m_speed = speed;
}
void SlidingStackedWidget::setAnimation(enum QEasingCurve::Type animationtype) {
m_animationtype = animationtype;
}
void SlidingStackedWidget::setWrap(bool wrap) {
m_wrap=wrap;
}
bool SlidingStackedWidget::slideInNext() {
int now=currentIndex();
if (m_wrap||(now<count()-1))
slideInIdx(now+1);
else
return false;
return true;
}
bool SlidingStackedWidget::slideInPrev() {
int now=currentIndex();
if (m_wrap||(now>0))
slideInIdx(now-1);
else
return false;
return true;
}
void SlidingStackedWidget::slideInIdx(int idx, enum t_direction direction) {
if (idx>count()-1) {
direction=m_vertical ? TOP2BOTTOM : RIGHT2LEFT;
idx=(idx)%count();
}
else if (idx<0) {
direction= m_vertical ? BOTTOM2TOP: LEFT2RIGHT;
idx=(idx+count())%count();
}
slideInWgt(widget ( idx ),direction);
}
void SlidingStackedWidget::slideInWgt(QWidget * newwidget, enum t_direction direction) {
if (m_active) {
return;
}
else m_active=true;
enum t_direction directionhint;
int now = currentIndex();
int next = indexOf(newwidget);
if (now == next) {
m_active=false;
return;
}
else if (now<next){
directionhint=m_vertical ? TOP2BOTTOM : RIGHT2LEFT;
}
else {
directionhint=m_vertical ? BOTTOM2TOP : LEFT2RIGHT;
}
if (direction == AUTOMATIC) {
direction=directionhint;
}
int offsetx=frameRect().width();
int offsety=frameRect().height();
widget(next)->setGeometry ( 0, 0, offsetx, offsety );
if (direction==BOTTOM2TOP) {
offsetx=0;
offsety=-offsety;
}
else if (direction==TOP2BOTTOM) {
offsetx=0;
}
else if (direction==RIGHT2LEFT) {
offsetx=-offsetx;
offsety=0;
}
else if (direction==LEFT2RIGHT) {
offsety=0;
}
QPoint pnext=widget(next)->pos();
QPoint pnow=widget(now)->pos();
m_pnow=pnow;
widget(next)->move(pnext.x()-offsetx,pnext.y()-offsety);
widget(next)->show();
widget(next)->raise();
QPropertyAnimation *animnow = new QPropertyAnimation(widget(now), "pos");
animnow->setDuration(m_speed);
animnow->setEasingCurve(m_animationtype);
animnow->setStartValue(QPoint(pnow.x(), pnow.y()));
animnow->setEndValue(QPoint(offsetx+pnow.x(), offsety+pnow.y()));
QGraphicsOpacityEffect *animnow_op_eff = new QGraphicsOpacityEffect();
widget(now)->setGraphicsEffect(animnow_op_eff);
QPropertyAnimation *animnow_op = new QPropertyAnimation(animnow_op_eff, "opacity");
animnow_op->setDuration(m_speed/2);
animnow_op->setStartValue(1);
animnow_op->setEndValue(0);
connect(animnow_op,&QPropertyAnimation::finished,[=](){
if(animnow_op_eff != nullptr)
animnow_op_eff->deleteLater();
});
QGraphicsOpacityEffect *animnext_op_eff = new QGraphicsOpacityEffect();
animnext_op_eff->setOpacity(0);
widget(next)->setGraphicsEffect(animnext_op_eff);
QPropertyAnimation *animnext_op = new QPropertyAnimation(animnext_op_eff, "opacity");
animnext_op->setDuration(m_speed/2);
animnext_op->setStartValue(0);
animnext_op->setEndValue(1);
connect(animnext_op,&QPropertyAnimation::finished,[=](){
if(animnext_op_eff != nullptr)
animnext_op_eff->deleteLater();
});
QPropertyAnimation *animnext = new QPropertyAnimation(widget(next), "pos");
animnext->setDuration(m_speed);
animnext->setEasingCurve(m_animationtype);
animnext->setStartValue(QPoint(-offsetx+pnext.x(), offsety+pnext.y()));
animnext->setEndValue(QPoint(pnext.x(), pnext.y()));
animgroup = new QParallelAnimationGroup;
animgroup->addAnimation(animnow);
animgroup->addAnimation(animnext);
animgroup->addAnimation(animnow_op);
animgroup->addAnimation(animnext_op);
QObject::connect(animgroup, SIGNAL(finished()),this,SLOT(animationDoneSlot()));
m_next=next;
m_now=now;
m_active=true;
animgroup->start(QAbstractAnimation::DeleteWhenStopped);
}
void SlidingStackedWidget::animationDoneSlot()
{
setCurrentIndex(m_next);
widget(m_now)->hide();
widget(m_now)->move(m_pnow);
m_active=false;
emit animationFinished();
}
@@ -0,0 +1,80 @@
/*
* MIT License
Copyright (c) 2020 Tim Schneeberger (ThePBone) <tim.schneeberger(at)outlook.de>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*
* Copied from https://github.com/Qt-Widgets/SlidingStackedWidget-1
*/
#ifndef SLIDINGSTACKEDWIDGET_H
#define SLIDINGSTACKEDWIDGET_H
#include <QStackedWidget>
#include <QEasingCurve>
#include <QParallelAnimationGroup>
class SlidingStackedWidget : public QStackedWidget {
Q_OBJECT
public:
//! Animation direction
enum t_direction {
LEFT2RIGHT,
RIGHT2LEFT,
TOP2BOTTOM,
BOTTOM2TOP,
AUTOMATIC
};
SlidingStackedWidget(QWidget *parent);
public slots:
//! Set animation speed
void setSpeed(int speed);
//! Set easing curve
void setAnimation(enum QEasingCurve::Type animationtype);
//! Change positioning mode
void setVerticalMode(bool vertical = true);
//! Enables page wrap for \c slideInNext and \c slideInPrev
void setWrap(bool wrap);
//! Slide to next page
bool slideInNext();
//! Slide to previous page
bool slideInPrev();
//! Slide to page x
void slideInIdx(int idx, enum t_direction direction=AUTOMATIC);
//! Slide to page with widget
void slideInWgt(QWidget * widget, enum t_direction direction=AUTOMATIC);
signals:
//! Animation is finished
void animationFinished(void);
protected slots:
void animationDoneSlot(void);
protected:
QWidget *m_mainwindow;
int m_speed;
enum QEasingCurve::Type m_animationtype;
bool m_vertical;
int m_now;
int m_next;
bool m_wrap;
QPoint m_pnow;
bool m_active;
QList<QWidget*> blockedPageList;
QParallelAnimationGroup *animgroup;
};
#endif // SLIDINGSTACKEDWIDGET_H
@@ -0,0 +1,377 @@
#include "AddDeviceDialog.h"
#include "ui_AddDeviceDialog.h"
#include "RGBController.h"
#include "ResourceManager.h"
#include "SettingsManager.h"
#include "LogManager.h"
// Device entries
#include "OpenRGBDMXSettingsEntry.h"
#include "OpenRGBE131SettingsEntry.h"
#include "OpenRGBElgatoKeyLightSettingsEntry.h"
#include "OpenRGBElgatoLightStripSettingsEntry.h"
#include "OpenRGBKasaSmartSettingsEntry.h"
#include "OpenRGBLIFXSettingsEntry.h"
#include "OpenRGBPhilipsHueSettingsEntry.h"
#include "OpenRGBPhilipsWizSettingsEntry.h"
#include "OpenRGBQMKORGBSettingsEntry.h"
#include "OpenRGBSerialSettingsEntry.h"
#include "OpenRGBYeelightSettingsEntry.h"
#include "OpenRGBGoveeSettingsEntry.h"
#include "NanoleafScanPage.h"
#include <QDesktopServices>
static void DetectionProgressChangedCallback(void* param)
{
AddDeviceDialog* this_obj = (AddDeviceDialog*)(param);
QMetaObject::invokeMethod(this_obj, "onDetectionProgressChanged", Qt::QueuedConnection);
}
static void DetectionEndedCallback(void* param)
{
AddDeviceDialog* this_obj = (AddDeviceDialog*)(param);
QMetaObject::invokeMethod(this_obj, "onDetectionEnded", Qt::QueuedConnection);
}
AddDeviceDialog::AddDeviceDialog(QWidget *parent)
: QDialog(parent)
, ui(new Ui::AddDeviceDialog)
{
ui->setupUi(this);
ResourceManager* rm = ResourceManager::get();
rm->RegisterDetectionEndCallback(&DetectionEndedCallback, this);
rm->RegisterDetectionProgressCallback(&DetectionProgressChangedCallback, this);
home();
}
AddDeviceDialog::~AddDeviceDialog()
{
ResourceManager* rm = ResourceManager::get();
rm->UnregisterDetectionEndCallback(&DetectionEndedCallback, this);
rm->UnregisterDetectionProgressCallback(&DetectionProgressChangedCallback, this);
delete ui;
}
void AddDeviceDialog::setScanButtons(bool scan)
{
ui->progressBar->setVisible(scan);
ui->ButtonScanBack->setVisible(!scan);
ui->ButtonScanRescan->setVisible(!scan);
ui->ButtonScanNotFound->setVisible(!scan);
if(scan)
{
ui->ButtonScanBeginning->hide();
ui->ButtonScanClose->hide();
}
}
void AddDeviceDialog::home()
{
scanFromPage = -1;
helpFromPage = -1;
configureFromPage = -1;
ui->stackedWidget->slideInWgt(ui->PageConnectionType, SlidingStackedWidget::LEFT2RIGHT);
}
void AddDeviceDialog::rescan()
{
if(scanFromPage == -1)
{
// Save the index of the page we came from
scanFromPage = ui->stackedWidget->currentIndex();
// Cache the names of all devices that were found so far
cachedDevices.clear();
std::vector<RGBController*> controllers = ResourceManager::get()->GetRGBControllers();
for(int i = 0; i < (int)controllers.size(); ++i)
{
cachedDevices.push_back(controllers[i]->name);
}
}
ui->LabelScan->setText(tr("<h2>Re-scanning devices...</h2>"));
setScanButtons(true);
ui->stackedWidget->slideInWgt(ui->PageScan, SlidingStackedWidget::RIGHT2LEFT);
ResourceManager::get()->DetectDevices();
}
void AddDeviceDialog::help()
{
if(helpFromPage == -1)
{
helpFromPage = ui->stackedWidget->currentIndex();
}
// Show the "Nothing we can do" page
// The usefulness on it heavily depends on the contents of the "Issue Text" field
// The caller must fill it with appropriate text (device IDs, connection type, manufacturer, etc.)
if(ui->helpIssueText->toPlainText().isEmpty())
{
ui->helpIssueText->hide();
ui->ButtonClipboard->hide();
ui->LabelGitlab->setText(tr("We would really appreciate if you could file an issue on <a href=\"gitlab\">Gitlab</a>, providing the device name and a link to a description on manufacturer's website."));
}
else
{
ui->helpIssueText->show();
ui->ButtonClipboard->show();
ui->LabelGitlab->setText(tr("We would really appreciate if you could send us this info, by filing an issue on Gitlab. "
"You can do that by clicking the button below (you need to be logged in to Gitlab in your "
"default web-browser), or by navigating to the <a href=\"gitlab\">Project's page on Gitlab</a>, "
"then \"Issues\", clicking \"New issue\", and pasting in the text from the field above."));
}
ui->stackedWidget->slideInWgt(ui->PageHelp, SlidingStackedWidget::RIGHT2LEFT);
}
void AddDeviceDialog::configure(QWidget* entry)
{
configureFromPage = ui->stackedWidget->currentIndex();
delete ui->ConfigureEntry;
ui->ConfigureEntry = entry;
ui->PageConfigureLayout->insertWidget(1, entry);
ui->stackedWidget->slideInWgt(ui->PageConfigure, SlidingStackedWidget::RIGHT2LEFT);
}
void AddDeviceDialog::on_ButtonSerial_clicked()
{
configure(new OpenRGBSerialSettingsEntry);
}
void AddDeviceDialog::on_ButtonDMX_clicked()
{
configure(new OpenRGBDMXSettingsEntry);
}
void AddDeviceDialog::on_ButtonQMK_clicked()
{
configure(new OpenRGBQMKORGBSettingsEntry);
}
void AddDeviceDialog::on_ButtonE131_clicked()
{
configure(new OpenRGBE131SettingsEntry);
}
void AddDeviceDialog::on_ButtonKasaSmart_clicked()
{
configure(new OpenRGBKasaSmartSettingsEntry);
}
void AddDeviceDialog::on_ButtonLIFX_clicked()
{
configure(new OpenRGBLIFXSettingsEntry);
}
void AddDeviceDialog::on_ButtonPhilipsHue_clicked()
{
configure(new OpenRGBPhilipsHueSettingsEntry);
}
void AddDeviceDialog::on_ButtonPhilipsWiz_clicked()
{
configure(new OpenRGBPhilipsWizSettingsEntry);
}
void AddDeviceDialog::on_ButtonYeelight_clicked()
{
configure(new OpenRGBYeelightSettingsEntry);
}
void AddDeviceDialog::on_ButtonNanloeaf_clicked()
{
configure(new NanoleafScanPage);
}
void AddDeviceDialog::on_ButtonElgatoKeyLight_clicked()
{
configure(new OpenRGBElgatoKeyLightSettingsEntry);
}
void AddDeviceDialog::on_ButtonElgatoLightStrip_clicked()
{
configure(new OpenRGBElgatoLightStripSettingsEntry);
}
void AddDeviceDialog::on_ButtonGovee_clicked()
{
configure(new OpenRGBGoveeSettingsEntry);
}
// ===== CONFIGURE =====
void AddDeviceDialog::on_ButtonConfigureBack_clicked()
{
ui->stackedWidget->slideInIdx(configureFromPage, SlidingStackedWidget::LEFT2RIGHT);
configureFromPage = -1;
}
void AddDeviceDialog::on_ButtonConfigureScan_clicked()
{
BaseManualDeviceEntry* manualEntry = dynamic_cast<BaseManualDeviceEntry*>(ui->ConfigureEntry);
if(manualEntry)
{
SettingsManager* sm = ResourceManager::get()->GetSettingsManager();
const char* section = manualEntry->settingsSection();
json result = sm->GetSettings(section);
if(!strcmp(section, "NanoleafDevices"))
{
OpenRGBNanoleafSettingsEntry* entry = dynamic_cast<OpenRGBNanoleafSettingsEntry*>(manualEntry);
if(entry)
{
result["devices"][entry->getLocation()] = manualEntry->saveSettings();
}
else
{
LOG_ERROR("[AddDeviceDialog]: nanoleaf entry failed to cast, saving entry aborted");
}
}
else if(!strcmp(section, "PhilipsHueDevices"))
{
result["bridges"].push_back(manualEntry->saveSettings());
}
else
{
result["devices"].push_back(manualEntry->saveSettings());
}
sm->SetSettings(section, result);
sm->SaveSettings();
}
rescan();
}
// ===== SCAN =====
void AddDeviceDialog::on_ButtonScanBack_clicked()
{
ui->stackedWidget->slideInIdx(scanFromPage, SlidingStackedWidget::LEFT2RIGHT);
scanFromPage = -1;
}
void AddDeviceDialog::on_ButtonScanRescan_clicked()
{
rescan();
}
void AddDeviceDialog::on_ButtonScanNotFound_clicked()
{
// TODO: consider planning this stage further
}
void AddDeviceDialog::on_ButtonScanBeginning_clicked()
{
home();
}
void AddDeviceDialog::on_ButtonScanClose_clicked()
{
close();
}
// ===== HELP =====
void AddDeviceDialog::on_ButtonHelpBack_clicked()
{
ui->stackedWidget->slideInIdx(helpFromPage, SlidingStackedWidget::LEFT2RIGHT);
helpFromPage = -1;
}
void AddDeviceDialog::on_ButtonHelpIssue_clicked()
{
QByteArray issueText = ui->helpIssueText->toPlainText().toUtf8();
QString issueUrl("https://gitlab.com/CalcProgrammer1/OpenRGB/-/issues/new");
QByteArray issueTitle = "[New Device][Helper]";
if(!title.empty())
{
issueTitle.append(" ");
issueTitle.append(title.c_str());
}
if(!issueText.isEmpty())
{
issueUrl.append("?issue[title]=");
issueUrl.append(issueTitle.toPercentEncoding());
issueUrl.append("&issue[description]=");
issueUrl.append(issueText.toPercentEncoding());
}
QDesktopServices::openUrl (QUrl(issueUrl));
}
void AddDeviceDialog::on_ButtonHelpBeginning_clicked()
{
home();
}
void AddDeviceDialog::on_LabelGitlab_linkActivated(const QString &link)
{
QString issueUrl("https://gitlab.com/CalcProgrammer1/OpenRGB/-/issues/new");
QDesktopServices::openUrl (QUrl(issueUrl));
}
void AddDeviceDialog::onDetectionProgressChanged()
{
ui->progressBar->setValue(ResourceManager::get()->GetDetectionPercent());
ui->progressBar->setFormat(QString::fromStdString(ResourceManager::get()->GetDetectionString()));
if(ResourceManager::get()->GetDetectionPercent() != 100)
{
setScanButtons(true);
};
}
void AddDeviceDialog::onDetectionEnded()
{
setScanButtons(false);
// Set text
std::vector<RGBController*> controllers = ResourceManager::get()->GetRGBControllers();
if(controllers.empty())
{
ui->LabelScan->setText(tr("<h2>Still nothing O_O</h2>"
"Scan reported no devices"));
}
else
{
QString text = tr("<h2>Scan complete</h2>");
bool foundNew = false;
for(int i = 0; i < (int)controllers.size(); ++i)
{
std::vector<std::string>::iterator it = std::find(cachedDevices.begin(), cachedDevices.end(), controllers[i]->name);
if(it == cachedDevices.end())
{
if(!foundNew)
{
text.append(tr("New devices that were found:<ul>"));
}
foundNew = true;
text.append("<li>");
text.append(controllers[i]->name.c_str());
text.append("</li>");
}
}
if(!foundNew)
{
text.append(tr("No new devices were found. Please go back and check the parameters, or file a new device issue."));
}
else
{
text.append("</ul>");
// Detection has gained results - show buttons to "complete" the hunt
ui->ButtonScanBeginning->show();
ui->ButtonScanClose->show();
}
ui->LabelScan->setText(text);
}
}
@@ -0,0 +1,76 @@
/*---------------------------------------------------------*\
| AddDeviceDialog.h |
| |
| Device adding helper window & troubleshooting wizard |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-only |
\*---------------------------------------------------------*/
#pragma once
#include <QDialog>
#include <QSortFilterProxyModel>
namespace Ui {
class AddDeviceDialog;
}
class AddDeviceDialog : public QDialog
{
Q_OBJECT
public:
explicit AddDeviceDialog(QWidget *parent = nullptr);
~AddDeviceDialog();
private slots:
void on_ButtonSerial_clicked();
void on_ButtonDMX_clicked();
void on_ButtonQMK_clicked();
void on_ButtonE131_clicked();
void on_ButtonElgatoKeyLight_clicked();
void on_ButtonElgatoLightStrip_clicked();
void on_ButtonGovee_clicked();
void on_ButtonKasaSmart_clicked();
void on_ButtonLIFX_clicked();
void on_ButtonPhilipsHue_clicked();
void on_ButtonPhilipsWiz_clicked();
void on_ButtonYeelight_clicked();
void on_ButtonNanloeaf_clicked();
void on_ButtonConfigureBack_clicked();
void on_ButtonConfigureScan_clicked();
void on_ButtonScanBack_clicked();
void on_ButtonScanRescan_clicked();
void on_ButtonScanNotFound_clicked();
void on_ButtonScanBeginning_clicked();
void on_ButtonScanClose_clicked();
void on_ButtonHelpBack_clicked();
void on_ButtonHelpIssue_clicked();
void on_ButtonHelpBeginning_clicked();
void on_LabelGitlab_linkActivated(const QString &link);
void onDetectionProgressChanged();
void onDetectionEnded();
private:
Ui::AddDeviceDialog *ui;
void home();
void rescan();
void help();
void setScanButtons(bool scan);
void configure(QWidget* entry);
int scanFromPage = -1;
int helpFromPage = -1;
int configureFromPage = -1;
//device_type filterDevType;
//connection_type filterConnType;
std::string title; // Cached device name & manufacturer from Hardware IDs
std::vector<std::string> cachedDevices;
};
@@ -0,0 +1,361 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>AddDeviceDialog</class>
<widget class="QWidget" name="AddDeviceDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>645</width>
<height>556</height>
</rect>
</property>
<property name="windowTitle">
<string>Add device</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="SlidingStackedWidget" name="stackedWidget">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="PageConnectionType">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>&lt;h2&gt;What kind of a device is it?&lt;/h2&gt;
Please make sure the device is plugged in (or turned on) before proceeding&lt;br&gt;
Anything not listed here should be detected automatically, if supported</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<property name="margin">
<number>5</number>
</property>
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayout_3">
<item row="1" column="0">
<widget class="QPushButton" name="ButtonDMX">
<property name="text">
<string>DMX</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QPushButton" name="ButtonGovee">
<property name="text">
<string>Govee</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QPushButton" name="ButtonKasaSmart">
<property name="text">
<string>Kasa Smart</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QPushButton" name="ButtonPhilipsWiz">
<property name="text">
<string>Philips Wiz</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QPushButton" name="ButtonQMK">
<property name="text">
<string>QMK Device</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="ButtonNanloeaf">
<property name="text">
<string>Nanoleaf</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QPushButton" name="ButtonElgatoKeyLight">
<property name="text">
<string>Elgato KeyLight</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="ButtonE131">
<property name="text">
<string>E1.31</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QPushButton" name="ButtonLIFX">
<property name="text">
<string>LIFX</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QPushButton" name="ButtonSerial">
<property name="text">
<string>Serial Port Device</string>
</property>
<property name="autoDefault">
<bool>true</bool>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QPushButton" name="ButtonPhilipsHue">
<property name="text">
<string>Philips Hue</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QPushButton" name="ButtonElgatoLightStrip">
<property name="text">
<string>Elgato LightStrip</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QPushButton" name="ButtonYeelight">
<property name="text">
<string>Yeelight</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="PageScan">
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<widget class="QLabel" name="LabelScan">
<property name="text">
<string>&lt;h2&gt;Re-scanning devices...&lt;/h2&gt;</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<property name="margin">
<number>5</number>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_4">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QProgressBar" name="progressBar">
<property name="value">
<number>24</number>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QPushButton" name="ButtonScanBack">
<property name="text">
<string>Back</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="ButtonScanRescan">
<property name="text">
<string>Scan again</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="ButtonScanNotFound">
<property name="text">
<string>Still not found</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="ButtonScanBeginning">
<property name="text">
<string>Add another device</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="ButtonScanClose">
<property name="text">
<string>All good!</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QWidget" name="PageConfigure">
<layout class="QVBoxLayout" name="PageConfigureLayout">
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>&lt;h2&gt;Please configure your device here&lt;/h2&gt;</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<property name="margin">
<number>5</number>
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="ConfigureEntry" native="true"/>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<widget class="QPushButton" name="ButtonConfigureBack">
<property name="text">
<string>Back</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="ButtonConfigureScan">
<property name="text">
<string>Save &amp;&amp; Scan</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QWidget" name="PageHelp">
<layout class="QVBoxLayout" name="verticalLayout_9">
<item>
<widget class="QLabel" name="label_7">
<property name="text">
<string>&lt;h2&gt;Not the end of the world&lt;/h2&gt;
The device seems to be unsupported by OpenRGB - yet! With your help, we can fix that.
First, let's gather some information:</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="margin">
<number>5</number>
</property>
</widget>
</item>
<item>
<widget class="QPlainTextEdit" name="helpIssueText">
<property name="plainText">
<string>Sample text for issue
```
Matching hardware IDs
```</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="ButtonClipboard">
<property name="text">
<string>Copy to Clipboard</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="LabelGitlab">
<property name="text">
<string>We would really appreciate if you could send us this info, by filing an issue on Gitlab. </string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="margin">
<number>5</number>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QPushButton" name="ButtonHelpBack">
<property name="text">
<string>Back</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="ButtonHelpIssue">
<property name="text">
<string>File an issue</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="ButtonHelpBeginning">
<property name="text">
<string>Try another device</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>SlidingStackedWidget</class>
<extends>QStackedWidget</extends>
<header>slidingstackedwidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
@@ -0,0 +1,58 @@
/*---------------------------------------------------------*\
| OpenRGBNanoleafNewDeviceDialog.cpp |
| |
| User interface for OpenRGB Nanoleaf dialog |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-only |
\*---------------------------------------------------------*/
#include <QCloseEvent>
#include "ResourceManager.h"
#include "NanoleafNewDeviceDialog.h"
#include "ui_NanoleafNewDeviceDialog.h"
#ifdef _WIN32
#include <QSettings>
#endif
NanoleafNewDeviceDialog::NanoleafNewDeviceDialog(QWidget *parent) :
QDialog(parent), ui(new Ui::NanoleafNewDeviceDialog)
{
ui->setupUi(this);
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
ui->devicePortEdit->setText("16021");
}
NanoleafNewDeviceDialog::~NanoleafNewDeviceDialog()
{
delete ui;
}
void NanoleafNewDeviceDialog::changeEvent(QEvent *event)
{
if(event->type() == QEvent::LanguageChange)
{
ui->retranslateUi(this);
}
}
NanoleafDevice NanoleafNewDeviceDialog::show()
{
NanoleafDevice return_device;
int result = this->exec();
if(result != QDialog::Rejected)
{
return_device.ip = ui->deviceIPEdit->text().toStdString();
return_device.port = ui->devicePortEdit->text().toInt();
}
else
{
return_device.ip = "";
return_device.port = 0;
}
return(return_device);
}
@@ -0,0 +1,38 @@
/*---------------------------------------------------------*\
| OpenRGBNanoleafNewDeviceDialog.h |
| |
| User interface for OpenRGB Nanoleaf dialog |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-only |
\*---------------------------------------------------------*/
#include <QDialog>
struct NanoleafDevice
{
std::string ip;
unsigned int port;
};
namespace Ui
{
class NanoleafNewDeviceDialog;
}
class NanoleafNewDeviceDialog : public QDialog
{
Q_OBJECT
public:
explicit NanoleafNewDeviceDialog(QWidget *parent = nullptr);
~NanoleafNewDeviceDialog();
NanoleafDevice show();
private:
Ui::NanoleafNewDeviceDialog *ui;
private slots:
void changeEvent(QEvent *event);
};
@@ -0,0 +1,90 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>NanoleafNewDeviceDialog</class>
<widget class="QDialog" name="NanoleafNewDeviceDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>184</width>
<height>186</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>New Nanoleaf device</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="deviceIPLabel">
<property name="text">
<string>IP address:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="deviceIPEdit"/>
</item>
<item>
<widget class="QLabel" name="devicePortLabel">
<property name="text">
<string>Port:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="devicePortEdit"/>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>NanoleafNewDeviceDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>NanoleafNewDeviceDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>
@@ -0,0 +1,138 @@
/*---------------------------------------------------------*\
| NanoleafScanPage.cpp |
| |
| User interface for OpenRGB Nanoleaf scan & pairing page |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-only |
\*---------------------------------------------------------*/
#include "NanoleafScanPage.h"
#include "ui_NanoleafScanPage.h"
#include "NanoleafNewDeviceDialog.h"
#include "ResourceManager.h"
#include "SettingsManager.h"
#include "LogManager.h"
using json = nlohmann::json;
NanoleafScanPage::NanoleafScanPage(QWidget *parent) :
QWidget(parent),
ui(new Ui::NanoleafScanPage)
{
ui->setupUi(this);
}
NanoleafScanPage::~NanoleafScanPage()
{
delete ui;
}
void NanoleafScanPage::changeEvent(QEvent *event)
{
if(event->type() == QEvent::LanguageChange)
{
ui->retranslateUi(this);
}
}
void NanoleafScanPage::on_AddNanoleafDeviceButton_clicked()
{
/*-----------------------------------------------------*\
| Open a popup to manually add a device by setting ip |
| and port |
\*-----------------------------------------------------*/
NanoleafNewDeviceDialog dialog;
NanoleafDevice device = dialog.show();
if(!device.ip.empty())
{
LOG_TRACE("[%s] Add %s:%d", "Nanoleaf", device.ip.c_str(), device.port);
std::string location = device.ip+":"+std::to_string(device.port);
if(entries.find(location) == entries.end())
{
OpenRGBNanoleafSettingsEntry* entry = new OpenRGBNanoleafSettingsEntry(QString::fromUtf8(device.ip.c_str()), device.port);
entries[location] = entry;
QListWidgetItem* item = new QListWidgetItem;
item->setSizeHint(entry->sizeHint());
ui->NanoleafDeviceList->addItem(item);
ui->NanoleafDeviceList->setItemWidget(item, entry);
ui->NanoleafDeviceList->show();
json nanoleaf_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("NanoleafDevices");
nanoleaf_settings["devices"][location]["ip"] = device.ip;
nanoleaf_settings["devices"][location]["port"] = device.port;
ResourceManager::get()->GetSettingsManager()->SetSettings("NanoleafDevices", nanoleaf_settings);
ResourceManager::get()->GetSettingsManager()->SaveSettings();
}
}
}
void NanoleafScanPage::on_RemoveNanoleafDeviceButton_clicked()
{
/*-------------------------------------------------*\
| Remove the selected device |
\*-------------------------------------------------*/
int cur_row = ui->NanoleafDeviceList->currentRow();
if(cur_row < 0)
{
return;
}
QListWidgetItem* item = ui->NanoleafDeviceList->item(cur_row);
OpenRGBNanoleafSettingsEntry* entry = (OpenRGBNanoleafSettingsEntry*) ui->NanoleafDeviceList->itemWidget(item);
ui->NanoleafDeviceList->removeItemWidget(item);
delete item;
std::string location = entry->getLocation();
delete entries[location];
entries.erase(location);
json nanoleaf_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("NanoleafDevices");
nanoleaf_settings["devices"].erase(location);
ResourceManager::get()->GetSettingsManager()->SetSettings("NanoleafDevices", nanoleaf_settings);
ResourceManager::get()->GetSettingsManager()->SaveSettings();
}
void NanoleafScanPage::on_ScanForNanoleafDevicesButton_clicked()
{
/*-----------------------------------------------------*\
| Create a worker thread for the mDNS query and hookup |
| callbacks for when it finds devices |
\*-----------------------------------------------------*/
OpenRGBNanoleafScanningThread *scanThread = new OpenRGBNanoleafScanningThread;
connect(scanThread, SIGNAL(DeviceFound(QString, int)),
SLOT(on_DeviceFound(QString, int)));
connect(scanThread, SIGNAL(finished()),
scanThread, SLOT(deleteLater()));
scanThread->start();
}
void NanoleafScanPage::on_DeviceFound(QString address, int port)
{
std::string location = address.toStdString()+":"+std::to_string(port);
if(entries.find(location) == entries.end())
{
OpenRGBNanoleafSettingsEntry* entry = new OpenRGBNanoleafSettingsEntry(address, port);
entries[location] = entry;
QListWidgetItem* item = new QListWidgetItem;
item->setSizeHint(entry->sizeHint());
ui->NanoleafDeviceList->addItem(item);
ui->NanoleafDeviceList->setItemWidget(item, entry);
ui->NanoleafDeviceList->show();
}
}
@@ -0,0 +1,38 @@
/*---------------------------------------------------------*\
| OpenRGBNanoleafScanPage.h |
| |
| User interface for OpenRGB Nanoleaf scan & pairing page |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-only |
\*---------------------------------------------------------*/
#pragma once
#include <QWidget>
#include "OpenRGBNanoleafSettingsEntry.h"
namespace Ui
{
class NanoleafScanPage;
}
class NanoleafScanPage : public QWidget
{
Q_OBJECT
public:
explicit NanoleafScanPage(QWidget *parent = nullptr);
~NanoleafScanPage();
private slots:
void changeEvent(QEvent *event);
void on_AddNanoleafDeviceButton_clicked();
void on_RemoveNanoleafDeviceButton_clicked();
void on_ScanForNanoleafDevicesButton_clicked();
void on_DeviceFound(QString address, int port);
private:
Ui::NanoleafScanPage *ui;
std::map<std::string, OpenRGBNanoleafSettingsEntry*> entries;
};
@@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>NanoleafScanPage</class>
<widget class="QWidget" name="NanoleafScanPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string notr="true">Nanoleaf Scan Page</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="2" column="0">
<widget class="QPushButton" name="AddNanoleafDeviceButton">
<property name="text">
<string>Add</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QPushButton" name="RemoveNanoleafDeviceButton">
<property name="text">
<string>Remove</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QPushButton" name="ScanForNanoleafDevicesButton">
<property name="text">
<string>Scan</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="3">
<widget class="QListWidget" name="NanoleafDeviceList">
<property name="verticalScrollMode">
<enum>QAbstractItemView::ScrollPerPixel</enum>
</property>
</widget>
</item>
<item row="0" column="0" colspan="3">
<widget class="QLabel" name="SyncLabel">
<property name="text">
<string>To pair, hold the on-off button down for 5-7 seconds until the LED starts flashing in a pattern, then click the &quot;Pair&quot; button within 30 seconds.</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
@@ -0,0 +1,477 @@
/*---------------------------------------------------------*\
| OpenRGBNanoleafScanningThread.cpp |
| |
| OpenRGB Nanoleaf scanning thread |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-only |
\*---------------------------------------------------------*/
#ifdef _WIN32
#define _CRT_SECURE_NO_WARNINGS 1
#endif
#ifdef _WIN32
#include <winsock2.h>
#include <iphlpapi.h>
#else
#include <netdb.h>
#include <ifaddrs.h>
#include <sys/select.h>
#endif
#include "mdns.h"
#include "NanoleafScanningThread.h"
static char namebuffer[256];
static struct sockaddr_in service_address_ipv4;
static struct sockaddr_in6 service_address_ipv6;
static int has_ipv4;
static int has_ipv6;
static mdns_string_t ipv4_address_to_string(char* buffer, size_t capacity, const struct sockaddr_in* addr, size_t addrlen)
{
char host[NI_MAXHOST] = {0};
char service[NI_MAXSERV] = {0};
int ret = getnameinfo((const struct sockaddr*)addr, (socklen_t)addrlen, host, NI_MAXHOST, service, NI_MAXSERV, NI_NUMERICSERV | NI_NUMERICHOST);
int len = 0;
if(ret == 0)
{
len = snprintf(buffer, capacity, "%s", host);
}
if(len >= (int)capacity)
{
len = (int)capacity - 1;
}
mdns_string_t str;
str.str = buffer;
str.length = len;
return str;
}
static mdns_string_t ipv6_address_to_string(char* buffer, size_t capacity, const struct sockaddr_in6* addr, size_t addrlen)
{
char host[NI_MAXHOST] = {0};
char service[NI_MAXSERV] = {0};
int ret = getnameinfo((const struct sockaddr*)addr, (socklen_t)addrlen, host, NI_MAXHOST, service, NI_MAXSERV, NI_NUMERICSERV | NI_NUMERICHOST);
int len = 0;
if(ret == 0)
{
if(addr->sin6_port != 0)
{
len = snprintf(buffer, capacity, "[%s]:%s", host, service);
}
else
{
len = snprintf(buffer, capacity, "%s", host);
}
}
if(len >= (int)capacity)
{
len = (int)capacity - 1;
}
mdns_string_t str;
str.str = buffer;
str.length = len;
return str;
}
/*-----------------------------------------------------*\
| Open sockets for sending one-shot multicast queries |
| from an ephemeral port |
\*-----------------------------------------------------*/
static int open_client_sockets(int* sockets, int max_sockets, int port)
{
/*-----------------------------------------------------*\
| When sending, each socket can only send to one |
| network interface from an ephemeral port, thus we |
| need to open one socket for each interface and |
| address family |
\*-----------------------------------------------------*/
int num_sockets = 0;
#ifdef _WIN32
IP_ADAPTER_ADDRESSES* adapter_address = 0;
ULONG address_size = 8000;
unsigned int ret;
unsigned int num_retries = 4;
do
{
adapter_address = (IP_ADAPTER_ADDRESSES*)malloc(address_size);
ret = GetAdaptersAddresses(AF_UNSPEC, GAA_FLAG_SKIP_MULTICAST | GAA_FLAG_SKIP_ANYCAST, 0, adapter_address, &address_size);
if(ret == ERROR_BUFFER_OVERFLOW)
{
free(adapter_address);
adapter_address = 0;
address_size *= 2;
}
else
{
break;
}
}
while(num_retries-- > 0);
if(!adapter_address || (ret != NO_ERROR))
{
free(adapter_address);
return num_sockets;
}
int first_ipv4 = 1;
int first_ipv6 = 1;
for(PIP_ADAPTER_ADDRESSES adapter = adapter_address; adapter; adapter = adapter->Next)
{
if(adapter->TunnelType == TUNNEL_TYPE_TEREDO)
{
continue;
}
if(adapter->OperStatus != IfOperStatusUp)
{
continue;
}
for(IP_ADAPTER_UNICAST_ADDRESS* unicast = adapter->FirstUnicastAddress; unicast; unicast = unicast->Next)
{
if(unicast->Address.lpSockaddr->sa_family == AF_INET)
{
struct sockaddr_in* saddr = (struct sockaddr_in*)unicast->Address.lpSockaddr;
if((saddr->sin_addr.S_un.S_un_b.s_b1 != 127) ||
(saddr->sin_addr.S_un.S_un_b.s_b2 != 0) ||
(saddr->sin_addr.S_un.S_un_b.s_b3 != 0) ||
(saddr->sin_addr.S_un.S_un_b.s_b4 != 1))
{
int log_addr = 0;
if(first_ipv4)
{
service_address_ipv4 = *saddr;
first_ipv4 = 0;
log_addr = 1;
}
has_ipv4 = 1;
if(num_sockets < max_sockets)
{
saddr->sin_port = htons((unsigned short)port);
int sock = mdns_socket_open_ipv4(saddr);
if(sock >= 0)
{
sockets[num_sockets++] = sock;
log_addr = 1;
}
else
{
log_addr = 0;
}
}
if(log_addr)
{
char buffer[128];
ipv4_address_to_string(buffer, sizeof(buffer), saddr, sizeof(struct sockaddr_in));
}
}
}
else if(unicast->Address.lpSockaddr->sa_family == AF_INET6)
{
struct sockaddr_in6* saddr = (struct sockaddr_in6*)unicast->Address.lpSockaddr;
static const unsigned char localhost[] = {0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 1};
static const unsigned char localhost_mapped[] = {0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0xff, 0xff, 0x7f, 0, 0, 1};
if((unicast->DadState == NldsPreferred) &&
memcmp(saddr->sin6_addr.s6_addr, localhost, 16) &&
memcmp(saddr->sin6_addr.s6_addr, localhost_mapped, 16))
{
int log_addr = 0;
if(first_ipv6)
{
service_address_ipv6 = *saddr;
first_ipv6 = 0;
log_addr = 1;
}
has_ipv6 = 1;
if(num_sockets < max_sockets)
{
saddr->sin6_port = htons((unsigned short)port);
int sock = mdns_socket_open_ipv6(saddr);
if(sock >= 0)
{
sockets[num_sockets++] = sock;
log_addr = 1;
}
else
{
log_addr = 0;
}
}
if(log_addr)
{
char buffer[128];
ipv6_address_to_string(buffer, sizeof(buffer), saddr, sizeof(struct sockaddr_in6));
}
}
}
}
}
free(adapter_address);
#else
struct ifaddrs* ifaddr = 0;
struct ifaddrs* ifa = 0;
getifaddrs(&ifaddr);
int first_ipv4 = 1;
int first_ipv6 = 1;
for(ifa = ifaddr; ifa; ifa = ifa->ifa_next)
{
if(!ifa->ifa_addr)
{
continue;
}
if(ifa->ifa_addr->sa_family == AF_INET)
{
struct sockaddr_in* saddr = (struct sockaddr_in*)ifa->ifa_addr;
if(saddr->sin_addr.s_addr != htonl(INADDR_LOOPBACK))
{
int log_addr = 0;
if(first_ipv4)
{
service_address_ipv4 = *saddr;
first_ipv4 = 0;
log_addr = 1;
}
has_ipv4 = 1;
if(num_sockets < max_sockets)
{
saddr->sin_port = htons(port);
int sock = mdns_socket_open_ipv4(saddr);
if(sock >= 0)
{
sockets[num_sockets++] = sock;
log_addr = 1;
}
else
{
log_addr = 0;
}
}
if(log_addr)
{
char buffer[128];
ipv4_address_to_string(buffer, sizeof(buffer), saddr, sizeof(struct sockaddr_in));
}
}
}
else if(ifa->ifa_addr->sa_family == AF_INET6)
{
struct sockaddr_in6* saddr = (struct sockaddr_in6*)ifa->ifa_addr;
static const unsigned char localhost[] = {0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 1};
static const unsigned char localhost_mapped[] = {0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0xff, 0xff, 0x7f, 0, 0, 1};
if (memcmp(saddr->sin6_addr.s6_addr, localhost, 16) &&
memcmp(saddr->sin6_addr.s6_addr, localhost_mapped, 16))
{
int log_addr = 0;
if(first_ipv6)
{
service_address_ipv6 = *saddr;
first_ipv6 = 0;
log_addr = 1;
}
has_ipv6 = 1;
if(num_sockets < max_sockets)
{
saddr->sin6_port = htons(port);
int sock = mdns_socket_open_ipv6(saddr);
if (sock >= 0)
{
sockets[num_sockets++] = sock;
log_addr = 1;
}
else
{
log_addr = 0;
}
}
if(log_addr)
{
char buffer[128];
ipv6_address_to_string(buffer, sizeof(buffer), saddr, sizeof(struct sockaddr_in6));
}
}
}
}
freeifaddrs(ifaddr);
#endif
return num_sockets;
}
/*-----------------------------------------------------*\
| Callback handling parsing answers to queries sent |
\*-----------------------------------------------------*/
static int query_callback(
int sock,
[[maybe_unused]] const struct sockaddr* from,
[[maybe_unused]] size_t addrlen,
[[maybe_unused]] mdns_entry_type_t entry,
uint16_t query_id,
uint16_t rtype,
[[maybe_unused]] uint16_t rclass,
[[maybe_unused]] uint32_t ttl,
const void* data,
size_t size,
[[maybe_unused]] size_t name_offset,
size_t name_length,
size_t record_offset,
size_t record_length,
void* user_data)
{
(void)sizeof(sock);
(void)sizeof(query_id);
(void)sizeof(name_length);
(void)sizeof(user_data);
if(rtype == MDNS_RECORDTYPE_A)
{
struct sockaddr_in address;
mdns_record_parse_a(data, size, record_offset, record_length, &address);
if(address.sin_port == 0)
{
address.sin_port = 16021; // Default Nanoleaf port.
}
mdns_string_t addrstr = ipv4_address_to_string(namebuffer, sizeof(namebuffer), &address, sizeof(address));
(static_cast<NanoleafScanningThread*>(user_data))->EmitDeviceFound(addrstr.str, address.sin_port);
}
return 0;
}
void NanoleafScanningThread::EmitDeviceFound(QString address, int port)
{
emit DeviceFound(address, port);
}
/*-----------------------------------------------------*\
| Send a mDNS query |
\*-----------------------------------------------------*/
int NanoleafScanningThread::SendMDNSQuery()
{
const char* service = "_nanoleafapi._tcp.local.";
mdns_record_type record = MDNS_RECORDTYPE_PTR;
int sockets[32];
int query_id[32];
int num_sockets = open_client_sockets(sockets, sizeof(sockets) / sizeof(sockets[0]), 0);
if (num_sockets <= 0)
{
return -1;
}
size_t capacity = 2048;
void* buffer = malloc(capacity);
size_t records;
//const char* record_name;
if(record == MDNS_RECORDTYPE_SRV)
{
//record_name = "SRV";
}
else if(record == MDNS_RECORDTYPE_A)
{
//record_name = "A";
}
else if(record == MDNS_RECORDTYPE_AAAA)
{
//record_name = "AAAA";
}
else
{
record = MDNS_RECORDTYPE_PTR;
}
for(int isock = 0; isock < num_sockets; ++isock)
{
query_id[isock] = mdns_query_send(sockets[isock], record, service, strlen(service), buffer, capacity, 0);
}
/*-----------------------------------------------------*\
| This is a simple implementation that loops for |
| 5 seconds or as long as we get replies |
\*-----------------------------------------------------*/
int res;
do
{
struct timeval timeout;
timeout.tv_sec = 5;
timeout.tv_usec = 0;
int nfds = 0;
fd_set readfs;
FD_ZERO(&readfs);
for(int isock = 0; isock < num_sockets; ++isock)
{
if(sockets[isock] >= nfds)
{
nfds = sockets[isock] + 1;
}
FD_SET(sockets[isock], &readfs);
}
records = 0;
res = select(nfds, &readfs, 0, 0, &timeout);
if(res > 0)
{
for(int isock = 0; isock < num_sockets; ++isock)
{
if(FD_ISSET(sockets[isock], &readfs))
{
records += mdns_query_recv(sockets[isock], buffer, capacity, query_callback, this, query_id[isock]);
}
FD_SET(sockets[isock], &readfs);
}
}
}
while (res > 0);
free(buffer);
for(int isock = 0; isock < num_sockets; ++isock)
{
mdns_socket_close(sockets[isock]);
}
return 0;
}
void NanoleafScanningThread::run()
{
SendMDNSQuery();
}
@@ -0,0 +1,25 @@
/*---------------------------------------------------------*\
| NanoleafScanningThread.h |
| |
| OpenRGB Nanoleaf scanning thread |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-only |
\*---------------------------------------------------------*/
#include <QThread>
class NanoleafScanningThread : public QThread
{
Q_OBJECT
void run();
int SendMDNSQuery();
signals:
void DeviceFound(QString address, int port);
public:
void EmitDeviceFound(QString address, int port);
};
@@ -0,0 +1,194 @@
/*-----------------------------------------------------------------*\
| ManualDevicesSettingsPage.cpp |
| |
| User interface for OpenRGB Manually Added Devices settings page |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-only |
\*-----------------------------------------------------------------*/
#include "ManualDevicesSettingsPage.h"
#include "ui_ManualDevicesSettingsPage.h"
#include "OpenRGBDMXSettingsEntry.h"
#include "OpenRGBE131SettingsEntry.h"
#include "OpenRGBElgatoKeyLightSettingsEntry.h"
#include "OpenRGBElgatoLightStripSettingsEntry.h"
#include "OpenRGBKasaSmartSettingsEntry.h"
#include "OpenRGBLIFXSettingsEntry.h"
#include "OpenRGBNanoleafSettingsEntry.h"
#include "OpenRGBPhilipsHueSettingsEntry.h"
#include "OpenRGBPhilipsWizSettingsEntry.h"
#include "OpenRGBQMKORGBSettingsEntry.h"
#include "OpenRGBSerialSettingsEntry.h"
#include "OpenRGBYeelightSettingsEntry.h"
#include "ResourceManager.h"
#include "SettingsManager.h"
#include "AddDeviceDialog.h"
static void ManualDevicesPageReloadCallback(void* this_ptr)
{
ManualDevicesSettingsPage * this_obj = (ManualDevicesSettingsPage *)this_ptr;
QMetaObject::invokeMethod(this_obj, "reloadList", Qt::QueuedConnection);
}
ManualDevicesSettingsPage::ManualDevicesSettingsPage(QWidget *parent) :
QWidget(parent),
ui(new Ui::ManualDevicesSettingsPage)
{
ui->setupUi(this);
ResourceManager::get()->RegisterDetectionEndCallback(&ManualDevicesPageReloadCallback, this);
reloadList();
}
ManualDevicesSettingsPage::~ManualDevicesSettingsPage()
{
ResourceManager::get()->UnregisterDetectionEndCallback(&ManualDevicesPageReloadCallback, this);
clearList();
delete ui;
}
void ManualDevicesSettingsPage::changeEvent(QEvent *event)
{
if(event->type() == QEvent::LanguageChange)
{
ui->retranslateUi(this);
}
}
void ManualDevicesSettingsPage::on_addDeviceButton_clicked()
{
AddDeviceDialog dialog(this);
dialog.exec();
}
void ManualDevicesSettingsPage::on_removeDeviceButton_clicked()
{
int cur_row = ui->deviceList->currentRow();
if(cur_row < 0)
{
return;
}
QListWidgetItem* item = ui->deviceList->takeItem(cur_row);
ui->deviceList->removeItemWidget(item);
delete item;
BaseManualDeviceEntry* entry = entries[cur_row];
entries.erase(entries.begin() + cur_row);
delete entry;
}
void ManualDevicesSettingsPage::on_saveConfigurationButton_clicked()
{
SettingsManager* sm = ResourceManager::get()->GetSettingsManager();
json result;
/*-----------------------------------------------------------------------------*\
| First, cache the data that will be stored as JSON |
| We wrap data into arrays by type (except Nanoleaf) |
| Nanoleaf stores it's data as an object with "location" as key for some reason |
\*-----------------------------------------------------------------------------*/
for(size_t idx = 0; idx < entries.size(); ++idx)
{
std::string section = entries[idx]->settingsSection();
if(section == "NanoleafDevices")
{
OpenRGBNanoleafSettingsEntry* entry = dynamic_cast<OpenRGBNanoleafSettingsEntry*>(entries[idx]);
result[section]["devices"][entry->getLocation()] = entries[idx]->saveSettings();
}
else if(section == "PhilipsHueDevices")
{
result[section]["bridges"].push_back(entries[idx]->saveSettings());
}
else
{
result[section]["devices"].push_back(entries[idx]->saveSettings());
}
}
/*---------------------------------------------------------*\
| Transfer data from the cached object into config sections |
\*---------------------------------------------------------*/
json::iterator it;
for(it = result.begin(); it != result.end(); ++it)
{
sm->SetSettings(it.key(), it.value());
}
sm->SaveSettings();
}
void ManualDevicesSettingsPage::reloadList()
{
clearList();
addEntries("DMXDevices", [](){return new OpenRGBDMXSettingsEntry();});
addEntries("E131Devices", [](){return new OpenRGBE131SettingsEntry();});
addEntries("ElgatoKeyLightDevices", [](){return new OpenRGBElgatoKeyLightSettingsEntry();});
addEntries("ElgatoLightStripDevices", [](){return new OpenRGBElgatoLightStripSettingsEntry();});
addEntries("KasaSmartDevices", [](){return new OpenRGBKasaSmartSettingsEntry();});
addEntries("LIFXDevices", [](){return new OpenRGBLIFXSettingsEntry();});
addEntries("NanoleafDevices", [](){return new OpenRGBNanoleafSettingsEntry();});
addEntries("PhilipsHueDevices", [](){return new OpenRGBPhilipsHueSettingsEntry();});
addEntries("PhilipsWizDevices", [](){return new OpenRGBPhilipsWizSettingsEntry();});
addEntries("QMKOpenRGBDevices", [](){return new OpenRGBQMKORGBSettingsEntry();});
addEntries("LEDStripDevices", [](){return new OpenRGBSerialSettingsEntry();});
addEntries("YeelightDevices", [](){return new OpenRGBYeelightSettingsEntry();});
}
void ManualDevicesSettingsPage::clearList()
{
std::vector<BaseManualDeviceEntry*> entries_copy;
entries_copy.swap(entries);
ui->deviceList->clear();
for(int i = 0; i < entries_copy.size(); ++i)
{
delete entries_copy[i];
}
entries_copy.clear();
}
void ManualDevicesSettingsPage::addEntry(const json& source, EntrySpawnFunction spawn)
{
QListWidgetItem* item = new QListWidgetItem;
BaseManualDeviceEntry* entry = spawn();
entry->loadFromSettings(source);
item->setSizeHint(entry->sizeHint());
ui->deviceList->addItem(item);
ui->deviceList->setItemWidget(item, entry);
ui->deviceList->show();
entries.push_back(entry);
}
void ManualDevicesSettingsPage::addEntries(const std::string& settingsName, EntrySpawnFunction spawn)
{
json settings = ResourceManager::get()->GetSettingsManager()->GetSettings(settingsName);
const char* array_name = "devices";
if(settingsName == "PhilipsHueDevices")
{
array_name = "bridges";
}
if(settings.contains(array_name))
{
json& array_ref = settings[array_name];
if(!array_ref.is_array() && !array_ref.is_object())
{
return;
}
// Nanoleaf stores it's data as objects with location field as "key", everything else is arrays
for(json::const_iterator iter = array_ref.begin(); iter != array_ref.end(); ++iter)
{
addEntry(iter.value(), spawn);
}
}
}
@@ -0,0 +1,49 @@
/*-----------------------------------------------------------------*\
| ManualDevicesSettingsPage.h |
| |
| User interface for OpenRGB Manually Added Devices settings page |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-only |
\*-----------------------------------------------------------------*/
#pragma once
#include "BaseManualDeviceEntry.h"
#include "nlohmann/json.hpp"
#include <QWidget>
using json = nlohmann::json;
namespace Ui
{
class ManualDevicesSettingsPage;
}
typedef std::function<BaseManualDeviceEntry*()> EntrySpawnFunction;
class ManualDevicesSettingsPage : public QWidget
{
Q_OBJECT
public:
explicit ManualDevicesSettingsPage(QWidget *parent = nullptr);
~ManualDevicesSettingsPage();
private slots:
void reloadList();
void changeEvent(QEvent *event);
void on_addDeviceButton_clicked();
void on_removeDeviceButton_clicked();
void on_saveConfigurationButton_clicked();
private:
Ui::ManualDevicesSettingsPage* ui;
std::vector<BaseManualDeviceEntry*> entries;
void addEntry(const json& source, EntrySpawnFunction);
void addEntries(const std::string& settingsName, EntrySpawnFunction);
void clearList();
};
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ManualDevicesSettingsPage</class>
<widget class="QWidget" name="ManualDevicesSettingsPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string notr="true">Manually Added Devices Settings Page</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0">
<widget class="QPushButton" name="addDeviceButton">
<property name="text">
<string>Add</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="removeDeviceButton">
<property name="text">
<string>Remove</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QPushButton" name="saveConfigurationButton">
<property name="text">
<string>Save</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="3">
<widget class="QListWidget" name="deviceList">
<property name="verticalScrollMode">
<enum>QAbstractItemView::ScrollPerPixel</enum>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
+23
View File
@@ -488,6 +488,12 @@ OpenRGBDialog::OpenRGBDialog(QWidget *parent) : QMainWindow(parent), ui(new Ui::
\*-----------------------------------------------------*/
AddPluginsPage();
/*-----------------------------------------------------*\
| Add the Manually Added Devices settings page |
| NOTE: The blocks below are to be removed later |
\*-----------------------------------------------------*/
AddManualDevicesSettingsPage();
/*-----------------------------------------------------*\
| Add the DMX settings page |
\*-----------------------------------------------------*/
@@ -809,6 +815,23 @@ void OpenRGBDialog::AddSettingsPage()
connect(this, SIGNAL(ProfileListChanged()), SettingsPage, SLOT(UpdateProfiles()));
}
void OpenRGBDialog::AddManualDevicesSettingsPage()
{
/*-----------------------------------------------------*\
| Create the Settings page |
\*-----------------------------------------------------*/
manualDevicesPage = new ManualDevicesSettingsPage();
ui->SettingsTabBar->addTab(manualDevicesPage, "");
/*-----------------------------------------------------*\
| Create the tab label |
\*-----------------------------------------------------*/
TabLabel* SettingsTabLabel = new TabLabel(OpenRGBFont::bulb, tr("Manually Added Devices"), (char *)"Manually Added Devices", (char *)context);
ui->SettingsTabBar->tabBar()->setTabButton(ui->SettingsTabBar->tabBar()->count() - 1, QTabBar::LeftSide, SettingsTabLabel);
}
void OpenRGBDialog::AddDMXSettingsPage()
{
/*-----------------------------------------------------*\
+12 -3
View File
@@ -10,7 +10,6 @@
#pragma once
#include <string>
#include <vector>
#include <QMainWindow>
#include <QTimer>
#include <QSystemTrayIcon>
@@ -23,6 +22,9 @@
#include "OpenRGBSystemInfoPage.h"
#include "OpenRGBSupportedDevicesPage.h"
#include "OpenRGBSettingsPage.h"
#include "ManualDevicesSettingsPage/ManualDevicesSettingsPage.h"
// Manual devices pages - to be removed later
#include "OpenRGBDMXSettingsPage/OpenRGBDMXSettingsPage.h"
#include "OpenRGBE131SettingsPage/OpenRGBE131SettingsPage.h"
#include "OpenRGBElgatoKeyLightSettingsPage/OpenRGBElgatoKeyLightSettingsPage.h"
@@ -36,6 +38,7 @@
#include "OpenRGBSerialSettingsPage/OpenRGBSerialSettingsPage.h"
#include "OpenRGBYeelightSettingsPage/OpenRGBYeelightSettingsPage.h"
#include "OpenRGBNanoleafSettingsPage/OpenRGBNanoleafSettingsPage.h"
#include "PluginManager.h"
#include "SuspendResume.h"
@@ -98,6 +101,9 @@ private:
OpenRGBSoftwareInfoPage *SoftInfoPage;
OpenRGBSupportedDevicesPage *SupportedPage;
OpenRGBSettingsPage *SettingsPage;
ManualDevicesSettingsPage *manualDevicesPage;
// Manual devices pages - to be removed later
OpenRGBDMXSettingsPage *DMXSettingsPage;
OpenRGBE131SettingsPage *E131SettingsPage;
OpenRGBElgatoKeyLightSettingsPage *ElgatoKeyLightSettingsPage;
@@ -130,6 +136,11 @@ private:
void AddSoftwareInfoPage();
void AddSupportedDevicesPage();
void AddSettingsPage();
void AddPluginsPage();
void AddConsolePage();
void AddManualDevicesSettingsPage();
// Manual devices pages - to be removed later
void AddDMXSettingsPage();
void AddE131SettingsPage();
void AddElgatoKeyLightSettingsPage();
@@ -143,8 +154,6 @@ private:
void AddSerialSettingsPage();
void AddYeelightSettingsPage();
void AddNanoleafSettingsPage();
void AddPluginsPage();
void AddConsolePage();
void ClearDevicesList();
void UpdateDevicesList();
@@ -27,7 +27,7 @@ OpenRGBNanoleafSettingsEntry::OpenRGBNanoleafSettingsEntry(QString a_address, in
{
address = a_address;
port = a_port;
const std::string location = address.toStdString()+":"+std::to_string(port);
const std::string location = getLocation();
ui->IPValue->setText(address);
ui->PortValue->setText(QString::fromStdString(std::to_string(a_port)));
@@ -69,7 +69,7 @@ void OpenRGBNanoleafSettingsEntry::on_PairButton_clicked()
auth_token = NanoleafController::Pair(address.toStdString(), port);
// Save auth token.
const std::string location = address.toStdString()+":"+std::to_string(port);
std::string location = getLocation();
json nanoleaf_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("NanoleafDevices");
nanoleaf_settings["devices"][location]["ip"] = address.toStdString();
nanoleaf_settings["devices"][location]["port"] = port;
@@ -94,7 +94,7 @@ void OpenRGBNanoleafSettingsEntry::on_UnpairButton_clicked()
{
NanoleafController::Unpair(address.toStdString(), port, auth_token);
const std::string location = address.toStdString()+":"+std::to_string(port);
std::string location = getLocation();
json nanoleaf_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("NanoleafDevices");
nanoleaf_settings["devices"].erase(location);
ResourceManager::get()->GetSettingsManager()->SetSettings("NanoleafDevices", nanoleaf_settings);
@@ -148,3 +148,8 @@ const char* OpenRGBNanoleafSettingsEntry::settingsSection()
{
return "NanoleafDevices";
}
std::string OpenRGBNanoleafSettingsEntry::getLocation()
{
return (address.toStdString() + ":" + std::to_string(port));
}
@@ -28,12 +28,7 @@ public:
void loadFromSettings(const json& data);
json saveSettings();
const char* settingsSection();
QString address;
int port;
private:
Ui::OpenRGBNanoleafSettingsEntry *ui;
std::string getLocation();
private slots:
void changeEvent(QEvent *event);
@@ -41,6 +36,9 @@ private slots:
void on_PairButton_clicked();
private:
Ui::OpenRGBNanoleafSettingsEntry *ui;
QString address;
int port;
std::string auth_token;
bool paired;
};
@@ -112,12 +112,12 @@ void OpenRGBNanoleafSettingsPage::on_RemoveNanoleafDeviceButton_clicked()
QListWidgetItem* item = ui->NanoleafDeviceList->item(cur_row);
OpenRGBNanoleafSettingsEntry* entry = (OpenRGBNanoleafSettingsEntry*) ui->NanoleafDeviceList->itemWidget(item);
LOG_TRACE("[%s] Remove %s:%d", "Nanoleaf", entry->address.toStdString().c_str(), entry->port);
std::string location = entry->getLocation();
LOG_TRACE("[%s] Remove %s", "Nanoleaf", location.c_str());
ui->NanoleafDeviceList->removeItemWidget(item);
delete item;
std::string location = entry->address.toStdString()+":"+std::to_string(entry->port);
delete entries[location];
entries.erase(location);