From e84cb98055b10ef86ccc03f6c732574b863c6d06 Mon Sep 17 00:00:00 2001 From: Adam Honse Date: Thu, 6 Aug 2020 10:55:10 -0500 Subject: [PATCH] Add detection progress bar to the user interface --- ResourceManager.cpp | 19 +++++++++++++++++++ ResourceManager.h | 4 ++++ qt/OpenRGBDialog2.cpp | 19 +++++++++++++++++++ qt/OpenRGBDialog2.ui | 29 +++++++++++++++++++++++------ 4 files changed, 65 insertions(+), 6 deletions(-) diff --git a/ResourceManager.cpp b/ResourceManager.cpp index 5753eeee..a775d813 100644 --- a/ResourceManager.cpp +++ b/ResourceManager.cpp @@ -84,6 +84,11 @@ void ResourceManager::DeviceListChanged() DeviceListChangeMutex.unlock(); } +unsigned int ResourceManager::GetDetectionPercent() +{ + return(detection_percent); +} + void ResourceManager::DetectDevices() { /*-------------------------------------------------*\ @@ -95,6 +100,12 @@ void ResourceManager::DetectDevices() void ResourceManager::DetectDevicesThreadFunction() { unsigned int prev_count = 0; + float percent = 0.0f; + + /*-------------------------------------------------*\ + | Start at 0% detection progress | + \*-------------------------------------------------*/ + detection_percent = 0; /*-------------------------------------------------*\ | Detect i2c busses | @@ -120,6 +131,10 @@ void ResourceManager::DetectDevicesThreadFunction() DeviceListChanged(); } prev_count = rgb_controllers.size(); + + percent = (i2c_detector_idx + 1.0f) / (i2c_device_detectors.size() + device_detectors.size()); + + detection_percent = percent * 100.0f; } /*-------------------------------------------------*\ @@ -138,5 +153,9 @@ void ResourceManager::DetectDevicesThreadFunction() DeviceListChanged(); } prev_count = rgb_controllers.size(); + + percent = (detector_idx + 1.0f + i2c_device_detectors.size()) / (i2c_device_detectors.size() + device_detectors.size()); + + detection_percent = percent * 100.0f; } } diff --git a/ResourceManager.h b/ResourceManager.h index 63d469b1..d19ccc7f 100644 --- a/ResourceManager.h +++ b/ResourceManager.h @@ -34,6 +34,8 @@ public: void RegisterDeviceListChangeCallback(ResourceManagerCallback new_callback, void * new_callback_arg); + unsigned int GetDetectionPercent(); + void DeviceListChanged(); void DetectDevices(); @@ -43,6 +45,8 @@ public: private: static std::unique_ptr instance; + unsigned int detection_percent; + std::vector busses; std::vector rgb_controllers; std::vector device_detectors; diff --git a/qt/OpenRGBDialog2.cpp b/qt/OpenRGBDialog2.cpp index 683e860b..2a2ff787 100644 --- a/qt/OpenRGBDialog2.cpp +++ b/qt/OpenRGBDialog2.cpp @@ -78,6 +78,11 @@ OpenRGBDialog2::OpenRGBDialog2(std::vector& bus, std::vec SMBusToolsPage = NULL; SoftInfoPage = NULL; + ui->ButtonLoadProfile->setVisible(false); + ui->ButtonSaveProfile->setVisible(false); + ui->ButtonDeleteProfile->setVisible(false); + ui->ProfileBox->setVisible(false); + ResourceManager::get()->RegisterDeviceListChangeCallback(UpdateInfoCallback, this); /*-----------------------------------------------------*\ @@ -409,6 +414,20 @@ void OpenRGBDialog2::on_ClientListUpdated() { ClearDevicesList(); UpdateDevicesList(); + + ui->DetectionProgressBar->setRange(0, 100); + ui->DetectionProgressBar->setValue(ResourceManager::get()->GetDetectionPercent()); + + if(ResourceManager::get()->GetDetectionPercent() == 100) + { + ui->DetectionProgressBar->setVisible(false); + ui->DetectionProgressLabel->setVisible(false); + + ui->ButtonLoadProfile->setVisible(true); + ui->ButtonSaveProfile->setVisible(true); + ui->ButtonDeleteProfile->setVisible(true); + ui->ProfileBox->setVisible(true); + } } void OpenRGBDialog2::on_SetAllDevices(unsigned char red, unsigned char green, unsigned char blue) diff --git a/qt/OpenRGBDialog2.ui b/qt/OpenRGBDialog2.ui index 5c9cfbec..719ed297 100644 --- a/qt/OpenRGBDialog2.ui +++ b/qt/OpenRGBDialog2.ui @@ -62,27 +62,44 @@ - + + + + Delete Profile + + + + - + Load Profile - + Save Profile - - + + - Delete Profile + OpenRGB is detecting devices... + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + 24