diff --git a/qt/OpenRGBDialog2.cpp b/qt/OpenRGBDialog2.cpp index 8da11ed6..6bca416c 100644 --- a/qt/OpenRGBDialog2.cpp +++ b/qt/OpenRGBDialog2.cpp @@ -62,11 +62,18 @@ static QString GetIconString(device_type type, bool dark) return filename; } -static void UpdateInfoCallback(void * this_ptr) +static void UpdateDeviceListCallback(void * this_ptr) { OpenRGBDialog2 * this_obj = (OpenRGBDialog2 *)this_ptr; - QMetaObject::invokeMethod(this_obj, "on_ClientListUpdated", Qt::QueuedConnection); + QMetaObject::invokeMethod(this_obj, "onDeviceListUpdated", Qt::QueuedConnection); +} + +static void UpdateDetectionProgressCallback(void * this_ptr) +{ + OpenRGBDialog2 * this_obj = (OpenRGBDialog2 *)this_ptr; + + QMetaObject::invokeMethod(this_obj, "onDetectionProgressUpdated", Qt::QueuedConnection); } OpenRGBDialog2::OpenRGBDialog2(std::vector& bus, std::vector& control, ProfileManager* manager, QWidget *parent) : QMainWindow(parent), busses(bus), controllers(control), profile_manager(manager), ui(new OpenRGBDialog2Ui) @@ -79,6 +86,13 @@ OpenRGBDialog2::OpenRGBDialog2(std::vector& bus, std::vec QIcon logo(":OpenRGB.png"); setWindowIcon(logo); + /*-----------------------------------------------------*\ + | Register detection progress callback with resource | + | manager | + \*-----------------------------------------------------*/ + ResourceManager::get()->RegisterDetectionProgressCallback(UpdateDetectionProgressCallback, this); + ResourceManager::get()->RegisterDeviceListChangeCallback(UpdateDeviceListCallback, this); + /*-----------------------------------------------------*\ | Initialize page pointers | \*-----------------------------------------------------*/ @@ -86,11 +100,7 @@ OpenRGBDialog2::OpenRGBDialog2(std::vector& bus, std::vec SMBusToolsPage = NULL; SoftInfoPage = NULL; - ui->ButtonToggleDeviceView->setVisible(false); - ui->ButtonLoadProfile->setVisible(false); - ui->ButtonSaveProfile->setVisible(false); - ui->ButtonDeleteProfile->setVisible(false); - ui->ProfileBox->setVisible(false); + onDetectionProgressUpdated(); ui->DetectionProgressBar->setRange(0, 100); ui->DetectionProgressBar->setValue(0); @@ -98,8 +108,6 @@ OpenRGBDialog2::OpenRGBDialog2(std::vector& bus, std::vec ui->DetectionProgressBar->setFormat(""); ui->DetectionProgressBar->setAlignment(Qt::AlignCenter); - ResourceManager::get()->RegisterDeviceListChangeCallback(UpdateInfoCallback, this); - /*-----------------------------------------------------*\ | Set up tray icon menu | \*-----------------------------------------------------*/ @@ -466,21 +474,25 @@ void OpenRGBDialog2::on_QuickWhite() void OpenRGBDialog2::on_ClientListUpdated() { UpdateDevicesList(); +} +void OpenRGBDialog2::onDeviceListUpdated() +{ + UpdateDevicesList(); +} + +void OpenRGBDialog2::onDetectionProgressUpdated() +{ ui->DetectionProgressBar->setValue(ResourceManager::get()->GetDetectionPercent()); ui->DetectionProgressBar->setFormat(QString::fromStdString(ResourceManager::get()->GetDetectionString())); if(ResourceManager::get()->GetDetectionPercent() == 100) { - ui->DetectionProgressBar->setVisible(false); - ui->DetectionProgressLabel->setVisible(false); - ui->ButtonStopDetection->setVisible(false); - - ui->ButtonToggleDeviceView->setVisible(true); - ui->ButtonLoadProfile->setVisible(true); - ui->ButtonSaveProfile->setVisible(true); - ui->ButtonDeleteProfile->setVisible(true); - ui->ProfileBox->setVisible(true); + SetDetectionViewState(false); + } + else + { + SetDetectionViewState(true); } } @@ -642,12 +654,47 @@ void Ui::OpenRGBDialog2::on_ButtonStopDetection_clicked() /*---------------------------------------------------------*\ | Pretend we're done already by hiding the progress bar | \*---------------------------------------------------------*/ - ui->DetectionProgressBar->setVisible(false); - ui->DetectionProgressLabel->setVisible(false); - ui->ButtonStopDetection->setVisible(false); - - ui->ButtonLoadProfile->setVisible(true); - ui->ButtonSaveProfile->setVisible(true); - ui->ButtonDeleteProfile->setVisible(true); - ui->ProfileBox->setVisible(true); + SetDetectionViewState(false); +} + +void Ui::OpenRGBDialog2::SetDetectionViewState(bool detection_showing) +{ + if(detection_showing) + { + /*---------------------------------------------------------*\ + | Show the detection progress and hide the normal buttons | + \*---------------------------------------------------------*/ + ui->DetectionProgressBar->setVisible(true); + ui->DetectionProgressLabel->setVisible(true); + ui->ButtonStopDetection->setVisible(true); + + ui->ButtonToggleDeviceView->setVisible(false); + ui->ButtonRescan->setVisible(false); + ui->ButtonLoadProfile->setVisible(false); + ui->ButtonSaveProfile->setVisible(false); + ui->ButtonDeleteProfile->setVisible(false); + ui->ProfileBox->setVisible(false); + } + else + { + /*---------------------------------------------------------*\ + | Hide the detection progress and show the normal buttons | + \*---------------------------------------------------------*/ + ui->DetectionProgressBar->setVisible(false); + ui->DetectionProgressLabel->setVisible(false); + ui->ButtonStopDetection->setVisible(false); + + ui->ButtonToggleDeviceView->setVisible(true); + ui->ButtonRescan->setVisible(true); + ui->ButtonLoadProfile->setVisible(true); + ui->ButtonSaveProfile->setVisible(true); + ui->ButtonDeleteProfile->setVisible(true); + ui->ProfileBox->setVisible(true); + } +} +void Ui::OpenRGBDialog2::on_ButtonRescan_clicked() +{ + SetDetectionViewState(true); + + ResourceManager::get()->DetectDevices(); } diff --git a/qt/OpenRGBDialog2.h b/qt/OpenRGBDialog2.h index 670ec332..2801e7ba 100644 --- a/qt/OpenRGBDialog2.h +++ b/qt/OpenRGBDialog2.h @@ -72,6 +72,8 @@ private: void UpdateProfileList(); void closeEvent(QCloseEvent *event); + void SetDetectionViewState(bool detection_showing); + bool device_view_showing = false; bool darkTheme = false; @@ -86,6 +88,8 @@ private slots: void on_QuickMagenta(); void on_QuickWhite(); void on_ClientListUpdated(); + void onDeviceListUpdated(); + void onDetectionProgressUpdated(); void on_SetAllDevices(unsigned char red, unsigned char green, unsigned char blue); void on_SaveSizeProfile(); void on_ShowHide(); @@ -95,6 +99,7 @@ private slots: void on_ButtonDeleteProfile_clicked(); void on_ButtonToggleDeviceView_clicked(); void on_ButtonStopDetection_clicked(); + void on_ButtonRescan_clicked(); }; #endif // OPENRGBDIALOG2_H diff --git a/qt/OpenRGBDialog2.ui b/qt/OpenRGBDialog2.ui index 7ae9bac9..c5b982d6 100644 --- a/qt/OpenRGBDialog2.ui +++ b/qt/OpenRGBDialog2.ui @@ -71,6 +71,13 @@ + + + + Rescan Devices + + +