From fd62686e22d8430fb525fef15a38ff3e5dd64321 Mon Sep 17 00:00:00 2001 From: Dmitry Kychanov Date: Thu, 19 Jun 2025 16:37:21 +0400 Subject: [PATCH] Initial implementation of Manual Devices Page --- OpenRGB.pro | 3 + .../slidingstackedwidget.cpp | 209 ++++++++ .../slidingstackedwidget.h | 80 +++ .../AddDeviceDialog/AddDeviceDialog.cpp | 377 ++++++++++++++ .../AddDeviceDialog/AddDeviceDialog.h | 76 +++ .../AddDeviceDialog/AddDeviceDialog.ui | 361 +++++++++++++ .../NanoleafNewDeviceDialog.cpp | 58 +++ .../AddDeviceDialog/NanoleafNewDeviceDialog.h | 38 ++ .../NanoleafNewDeviceDialog.ui | 90 ++++ .../AddDeviceDialog/NanoleafScanPage.cpp | 138 +++++ .../AddDeviceDialog/NanoleafScanPage.h | 38 ++ .../AddDeviceDialog/NanoleafScanPage.ui | 62 +++ .../NanoleafScanningThread.cpp | 477 ++++++++++++++++++ .../AddDeviceDialog/NanoleafScanningThread.h | 25 + .../BaseManualDeviceEntry.h | 0 .../ManualDevicesSettingsPage.cpp | 194 +++++++ .../ManualDevicesSettingsPage.h | 49 ++ .../ManualDevicesSettingsPage.ui | 49 ++ qt/OpenRGBDialog/OpenRGBDialog.cpp | 23 + qt/OpenRGBDialog/OpenRGBDialog.h | 15 +- .../OpenRGBNanoleafSettingsEntry.cpp | 11 +- .../OpenRGBNanoleafSettingsEntry.h | 10 +- .../OpenRGBNanoleafSettingsPage.cpp | 4 +- 23 files changed, 2373 insertions(+), 14 deletions(-) create mode 100644 dependencies/slidingstackedwidget/slidingstackedwidget.cpp create mode 100644 dependencies/slidingstackedwidget/slidingstackedwidget.h create mode 100644 qt/ManualDevicesSettingsPage/AddDeviceDialog/AddDeviceDialog.cpp create mode 100644 qt/ManualDevicesSettingsPage/AddDeviceDialog/AddDeviceDialog.h create mode 100644 qt/ManualDevicesSettingsPage/AddDeviceDialog/AddDeviceDialog.ui create mode 100644 qt/ManualDevicesSettingsPage/AddDeviceDialog/NanoleafNewDeviceDialog.cpp create mode 100644 qt/ManualDevicesSettingsPage/AddDeviceDialog/NanoleafNewDeviceDialog.h create mode 100644 qt/ManualDevicesSettingsPage/AddDeviceDialog/NanoleafNewDeviceDialog.ui create mode 100644 qt/ManualDevicesSettingsPage/AddDeviceDialog/NanoleafScanPage.cpp create mode 100644 qt/ManualDevicesSettingsPage/AddDeviceDialog/NanoleafScanPage.h create mode 100644 qt/ManualDevicesSettingsPage/AddDeviceDialog/NanoleafScanPage.ui create mode 100644 qt/ManualDevicesSettingsPage/AddDeviceDialog/NanoleafScanningThread.cpp create mode 100644 qt/ManualDevicesSettingsPage/AddDeviceDialog/NanoleafScanningThread.h rename qt/{ => ManualDevicesSettingsPage}/BaseManualDeviceEntry.h (100%) create mode 100644 qt/ManualDevicesSettingsPage/ManualDevicesSettingsPage.cpp create mode 100644 qt/ManualDevicesSettingsPage/ManualDevicesSettingsPage.h create mode 100644 qt/ManualDevicesSettingsPage/ManualDevicesSettingsPage.ui diff --git a/OpenRGB.pro b/OpenRGB.pro index 0f235a25..ec79bf23 100644 --- a/OpenRGB.pro +++ b/OpenRGB.pro @@ -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 \ diff --git a/dependencies/slidingstackedwidget/slidingstackedwidget.cpp b/dependencies/slidingstackedwidget/slidingstackedwidget.cpp new file mode 100644 index 00000000..b646e06e --- /dev/null +++ b/dependencies/slidingstackedwidget/slidingstackedwidget.cpp @@ -0,0 +1,209 @@ +/* + * MIT License + Copyright (c) 2020 Tim Schneeberger (ThePBone) + 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 +#include +#include + +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||(now0)) + 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 (nowsetGeometry ( 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(); +} + + diff --git a/dependencies/slidingstackedwidget/slidingstackedwidget.h b/dependencies/slidingstackedwidget/slidingstackedwidget.h new file mode 100644 index 00000000..da9b557e --- /dev/null +++ b/dependencies/slidingstackedwidget/slidingstackedwidget.h @@ -0,0 +1,80 @@ +/* + * MIT License + Copyright (c) 2020 Tim Schneeberger (ThePBone) + 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 +#include +#include + +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 blockedPageList; + QParallelAnimationGroup *animgroup; +}; +#endif // SLIDINGSTACKEDWIDGET_H diff --git a/qt/ManualDevicesSettingsPage/AddDeviceDialog/AddDeviceDialog.cpp b/qt/ManualDevicesSettingsPage/AddDeviceDialog/AddDeviceDialog.cpp new file mode 100644 index 00000000..eb1aa0f8 --- /dev/null +++ b/qt/ManualDevicesSettingsPage/AddDeviceDialog/AddDeviceDialog.cpp @@ -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 + +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 controllers = ResourceManager::get()->GetRGBControllers(); + for(int i = 0; i < (int)controllers.size(); ++i) + { + cachedDevices.push_back(controllers[i]->name); + } + } + ui->LabelScan->setText(tr("

Re-scanning devices...

")); + 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 Gitlab, 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 Project's page on Gitlab, " + "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(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(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 controllers = ResourceManager::get()->GetRGBControllers(); + if(controllers.empty()) + { + ui->LabelScan->setText(tr("

Still nothing O_O

" + "Scan reported no devices")); + } + else + { + QString text = tr("

Scan complete

"); + bool foundNew = false; + for(int i = 0; i < (int)controllers.size(); ++i) + { + std::vector::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:
    ")); + } + foundNew = true; + + text.append("
  • "); + text.append(controllers[i]->name.c_str()); + text.append("
  • "); + } + } + 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("
"); + + // Detection has gained results - show buttons to "complete" the hunt + ui->ButtonScanBeginning->show(); + ui->ButtonScanClose->show(); + } + ui->LabelScan->setText(text); + } +} diff --git a/qt/ManualDevicesSettingsPage/AddDeviceDialog/AddDeviceDialog.h b/qt/ManualDevicesSettingsPage/AddDeviceDialog/AddDeviceDialog.h new file mode 100644 index 00000000..c080a6bf --- /dev/null +++ b/qt/ManualDevicesSettingsPage/AddDeviceDialog/AddDeviceDialog.h @@ -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 +#include + +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 cachedDevices; +}; diff --git a/qt/ManualDevicesSettingsPage/AddDeviceDialog/AddDeviceDialog.ui b/qt/ManualDevicesSettingsPage/AddDeviceDialog/AddDeviceDialog.ui new file mode 100644 index 00000000..b84cbb5c --- /dev/null +++ b/qt/ManualDevicesSettingsPage/AddDeviceDialog/AddDeviceDialog.ui @@ -0,0 +1,361 @@ + + + AddDeviceDialog + + + + 0 + 0 + 645 + 556 + + + + Add device + + + + + + 0 + + + + + + + <h2>What kind of a device is it?</h2> +Please make sure the device is plugged in (or turned on) before proceeding<br> +Anything not listed here should be detected automatically, if supported + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + 5 + + + + + + + + + DMX + + + + + + + Govee + + + + + + + Kasa Smart + + + + + + + Philips Wiz + + + + + + + QMK Device + + + + + + + Nanoleaf + + + + + + + Elgato KeyLight + + + + + + + E1.31 + + + + + + + LIFX + + + + + + + Serial Port Device + + + true + + + + + + + Philips Hue + + + + + + + Elgato LightStrip + + + + + + + Yeelight + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + <h2>Re-scanning devices...</h2> + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + 5 + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + 24 + + + + + + + + + Back + + + + + + + Scan again + + + + + + + Still not found + + + + + + + Add another device + + + + + + + All good! + + + + + + + + + + + + + <h2>Please configure your device here</h2> + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + 5 + + + + + + + + + + + + Back + + + + + + + Save && Scan + + + + + + + + + + + + + <h2>Not the end of the world</h2> +The device seems to be unsupported by OpenRGB - yet! With your help, we can fix that. +First, let's gather some information: + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + true + + + 5 + + + + + + + Sample text for issue + +``` +Matching hardware IDs +``` + + + + + + + Copy to Clipboard + + + + + + + We would really appreciate if you could send us this info, by filing an issue on Gitlab. + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + true + + + 5 + + + + + + + + + Back + + + + + + + File an issue + + + + + + + Try another device + + + + + + + + + + + + + + SlidingStackedWidget + QStackedWidget +
slidingstackedwidget.h
+ 1 +
+
+ + +
diff --git a/qt/ManualDevicesSettingsPage/AddDeviceDialog/NanoleafNewDeviceDialog.cpp b/qt/ManualDevicesSettingsPage/AddDeviceDialog/NanoleafNewDeviceDialog.cpp new file mode 100644 index 00000000..ceb16566 --- /dev/null +++ b/qt/ManualDevicesSettingsPage/AddDeviceDialog/NanoleafNewDeviceDialog.cpp @@ -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 +#include "ResourceManager.h" +#include "NanoleafNewDeviceDialog.h" +#include "ui_NanoleafNewDeviceDialog.h" + +#ifdef _WIN32 +#include +#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); +} diff --git a/qt/ManualDevicesSettingsPage/AddDeviceDialog/NanoleafNewDeviceDialog.h b/qt/ManualDevicesSettingsPage/AddDeviceDialog/NanoleafNewDeviceDialog.h new file mode 100644 index 00000000..761d30af --- /dev/null +++ b/qt/ManualDevicesSettingsPage/AddDeviceDialog/NanoleafNewDeviceDialog.h @@ -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 + +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); +}; diff --git a/qt/ManualDevicesSettingsPage/AddDeviceDialog/NanoleafNewDeviceDialog.ui b/qt/ManualDevicesSettingsPage/AddDeviceDialog/NanoleafNewDeviceDialog.ui new file mode 100644 index 00000000..2feacbe8 --- /dev/null +++ b/qt/ManualDevicesSettingsPage/AddDeviceDialog/NanoleafNewDeviceDialog.ui @@ -0,0 +1,90 @@ + + + NanoleafNewDeviceDialog + + + + 0 + 0 + 184 + 186 + + + + + 0 + 0 + + + + New Nanoleaf device + + + + + + IP address: + + + + + + + + + + Port: + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + NanoleafNewDeviceDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + NanoleafNewDeviceDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/qt/ManualDevicesSettingsPage/AddDeviceDialog/NanoleafScanPage.cpp b/qt/ManualDevicesSettingsPage/AddDeviceDialog/NanoleafScanPage.cpp new file mode 100644 index 00000000..289ded79 --- /dev/null +++ b/qt/ManualDevicesSettingsPage/AddDeviceDialog/NanoleafScanPage.cpp @@ -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(); + } +} diff --git a/qt/ManualDevicesSettingsPage/AddDeviceDialog/NanoleafScanPage.h b/qt/ManualDevicesSettingsPage/AddDeviceDialog/NanoleafScanPage.h new file mode 100644 index 00000000..feea7fa3 --- /dev/null +++ b/qt/ManualDevicesSettingsPage/AddDeviceDialog/NanoleafScanPage.h @@ -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 +#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 entries; +}; diff --git a/qt/ManualDevicesSettingsPage/AddDeviceDialog/NanoleafScanPage.ui b/qt/ManualDevicesSettingsPage/AddDeviceDialog/NanoleafScanPage.ui new file mode 100644 index 00000000..962bed56 --- /dev/null +++ b/qt/ManualDevicesSettingsPage/AddDeviceDialog/NanoleafScanPage.ui @@ -0,0 +1,62 @@ + + + NanoleafScanPage + + + + 0 + 0 + 400 + 300 + + + + Nanoleaf Scan Page + + + + + + Add + + + + + + + Remove + + + + + + + Scan + + + + + + + QAbstractItemView::ScrollPerPixel + + + + + + + To pair, hold the on-off button down for 5-7 seconds until the LED starts flashing in a pattern, then click the "Pair" button within 30 seconds. + + + Qt::AlignCenter + + + true + + + + + + + + diff --git a/qt/ManualDevicesSettingsPage/AddDeviceDialog/NanoleafScanningThread.cpp b/qt/ManualDevicesSettingsPage/AddDeviceDialog/NanoleafScanningThread.cpp new file mode 100644 index 00000000..3efb6f42 --- /dev/null +++ b/qt/ManualDevicesSettingsPage/AddDeviceDialog/NanoleafScanningThread.cpp @@ -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 +#include +#else +#include +#include +#include +#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(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(); +} diff --git a/qt/ManualDevicesSettingsPage/AddDeviceDialog/NanoleafScanningThread.h b/qt/ManualDevicesSettingsPage/AddDeviceDialog/NanoleafScanningThread.h new file mode 100644 index 00000000..b5be220e --- /dev/null +++ b/qt/ManualDevicesSettingsPage/AddDeviceDialog/NanoleafScanningThread.h @@ -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 + +class NanoleafScanningThread : public QThread +{ + Q_OBJECT + + void run(); + + int SendMDNSQuery(); + +signals: + void DeviceFound(QString address, int port); + +public: + void EmitDeviceFound(QString address, int port); +}; diff --git a/qt/BaseManualDeviceEntry.h b/qt/ManualDevicesSettingsPage/BaseManualDeviceEntry.h similarity index 100% rename from qt/BaseManualDeviceEntry.h rename to qt/ManualDevicesSettingsPage/BaseManualDeviceEntry.h diff --git a/qt/ManualDevicesSettingsPage/ManualDevicesSettingsPage.cpp b/qt/ManualDevicesSettingsPage/ManualDevicesSettingsPage.cpp new file mode 100644 index 00000000..66a5317e --- /dev/null +++ b/qt/ManualDevicesSettingsPage/ManualDevicesSettingsPage.cpp @@ -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(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 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); + } + } +} diff --git a/qt/ManualDevicesSettingsPage/ManualDevicesSettingsPage.h b/qt/ManualDevicesSettingsPage/ManualDevicesSettingsPage.h new file mode 100644 index 00000000..c397dae7 --- /dev/null +++ b/qt/ManualDevicesSettingsPage/ManualDevicesSettingsPage.h @@ -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 + +using json = nlohmann::json; + +namespace Ui +{ + class ManualDevicesSettingsPage; +} + +typedef std::function 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 entries; + + void addEntry(const json& source, EntrySpawnFunction); + void addEntries(const std::string& settingsName, EntrySpawnFunction); + void clearList(); +}; diff --git a/qt/ManualDevicesSettingsPage/ManualDevicesSettingsPage.ui b/qt/ManualDevicesSettingsPage/ManualDevicesSettingsPage.ui new file mode 100644 index 00000000..32888b52 --- /dev/null +++ b/qt/ManualDevicesSettingsPage/ManualDevicesSettingsPage.ui @@ -0,0 +1,49 @@ + + + ManualDevicesSettingsPage + + + + 0 + 0 + 400 + 300 + + + + Manually Added Devices Settings Page + + + + + + Add + + + + + + + Remove + + + + + + + Save + + + + + + + QAbstractItemView::ScrollPerPixel + + + + + + + + diff --git a/qt/OpenRGBDialog/OpenRGBDialog.cpp b/qt/OpenRGBDialog/OpenRGBDialog.cpp index 12859ac7..ff998855 100644 --- a/qt/OpenRGBDialog/OpenRGBDialog.cpp +++ b/qt/OpenRGBDialog/OpenRGBDialog.cpp @@ -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() { /*-----------------------------------------------------*\ diff --git a/qt/OpenRGBDialog/OpenRGBDialog.h b/qt/OpenRGBDialog/OpenRGBDialog.h index 400a37f9..64c706d6 100644 --- a/qt/OpenRGBDialog/OpenRGBDialog.h +++ b/qt/OpenRGBDialog/OpenRGBDialog.h @@ -10,7 +10,6 @@ #pragma once #include -#include #include #include #include @@ -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(); diff --git a/qt/OpenRGBNanoleafSettingsPage/OpenRGBNanoleafSettingsEntry.cpp b/qt/OpenRGBNanoleafSettingsPage/OpenRGBNanoleafSettingsEntry.cpp index 3cf49a68..beac4998 100644 --- a/qt/OpenRGBNanoleafSettingsPage/OpenRGBNanoleafSettingsEntry.cpp +++ b/qt/OpenRGBNanoleafSettingsPage/OpenRGBNanoleafSettingsEntry.cpp @@ -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)); +} diff --git a/qt/OpenRGBNanoleafSettingsPage/OpenRGBNanoleafSettingsEntry.h b/qt/OpenRGBNanoleafSettingsPage/OpenRGBNanoleafSettingsEntry.h index 8391aff3..730204b7 100644 --- a/qt/OpenRGBNanoleafSettingsPage/OpenRGBNanoleafSettingsEntry.h +++ b/qt/OpenRGBNanoleafSettingsPage/OpenRGBNanoleafSettingsEntry.h @@ -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; }; diff --git a/qt/OpenRGBNanoleafSettingsPage/OpenRGBNanoleafSettingsPage.cpp b/qt/OpenRGBNanoleafSettingsPage/OpenRGBNanoleafSettingsPage.cpp index fff4c27c..07c0b27d 100644 --- a/qt/OpenRGBNanoleafSettingsPage/OpenRGBNanoleafSettingsPage.cpp +++ b/qt/OpenRGBNanoleafSettingsPage/OpenRGBNanoleafSettingsPage.cpp @@ -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);