diff --git a/ResourceManager.cpp b/ResourceManager.cpp index 3a4b54ed..82b2e8db 100644 --- a/ResourceManager.cpp +++ b/ResourceManager.cpp @@ -44,6 +44,12 @@ ResourceManager::ResourceManager() | Initialize Server Instance | \*-------------------------------------------------------------------------*/ server = new NetworkServer(rgb_controllers_hw); + + /*-------------------------------------------------------------------------*\ + | Load sizes list from file | + \*-------------------------------------------------------------------------*/ + profile_manager = new ProfileManager(rgb_controllers); + rgb_controllers_sizes = profile_manager->LoadProfileToList("sizes.ors"); } ResourceManager::~ResourceManager() @@ -184,6 +190,11 @@ std::vector& ResourceManager::GetClients() return(clients); } +ProfileManager* ResourceManager::GetProfileManager() +{ + return(profile_manager); +} + unsigned int ResourceManager::GetDetectionPercent() { return (detection_percent.load()); @@ -275,8 +286,17 @@ void ResourceManager::DetectDevices() void ResourceManager::DetectDevicesThreadFunction() { DetectDeviceMutex.lock(); - unsigned int prev_count = 0; - float percent = 0.0f; + + unsigned int prev_count = 0; + float percent = 0.0f; + std::vector size_used; + + size_used.resize(rgb_controllers_sizes.size()); + + for(unsigned int size_idx = 0; size_idx < size_used.size(); size_idx++) + { + size_used[size_idx] = false; + } std::vector disabled_devices_list; @@ -297,8 +317,6 @@ void ResourceManager::DetectDevicesThreadFunction() infile.close(); - ProfileManager profile_manager(rgb_controllers); - /*-------------------------------------------------*\ | Start at 0% detection progress | \*-------------------------------------------------*/ @@ -341,6 +359,14 @@ void ResourceManager::DetectDevicesThreadFunction() \*-------------------------------------------------*/ if(rgb_controllers_hw.size() != prev_count) { + /*-------------------------------------------------*\ + | First, load sizes for the new controllers | + \*-------------------------------------------------*/ + for(unsigned int controller_size_idx = prev_count - 1; controller_size_idx < rgb_controllers_hw.size(); controller_size_idx++) + { + profile_manager->LoadDeviceFromListWithOptions(rgb_controllers_sizes, size_used, rgb_controllers_hw[controller_size_idx], true, false); + } + DeviceListChanged(); } prev_count = rgb_controllers_hw.size(); @@ -379,6 +405,14 @@ void ResourceManager::DetectDevicesThreadFunction() \*-------------------------------------------------*/ if(rgb_controllers_hw.size() != prev_count) { + /*-------------------------------------------------*\ + | First, load sizes for the new controllers | + \*-------------------------------------------------*/ + for(unsigned int controller_size_idx = prev_count - 1; controller_size_idx < rgb_controllers_hw.size(); controller_size_idx++) + { + profile_manager->LoadDeviceFromListWithOptions(rgb_controllers_sizes, size_used, rgb_controllers_hw[controller_size_idx], true, false); + } + DeviceListChanged(); } prev_count = rgb_controllers_hw.size(); @@ -388,8 +422,6 @@ void ResourceManager::DetectDevicesThreadFunction() detection_percent = percent * 100.0f; } - profile_manager.LoadSizeFromProfile("sizes.ors"); - /*-------------------------------------------------*\ | Make sure that when the detection is done, | | progress bar is set to 100% | diff --git a/ResourceManager.h b/ResourceManager.h index c5b33278..6470c979 100644 --- a/ResourceManager.h +++ b/ResourceManager.h @@ -20,6 +20,7 @@ #include "i2c_smbus.h" #include "NetworkClient.h" #include "NetworkServer.h" +#include "ProfileManager.h" #include "RGBController.h" typedef std::function&)> I2CBusDetectorFunction; @@ -56,6 +57,8 @@ public: std::vector& GetClients(); NetworkServer* GetServer(); + ProfileManager* GetProfileManager(); + void DeviceListChanged(); void DetectionProgressChanged(); @@ -72,6 +75,11 @@ public: private: static std::unique_ptr instance; + /*-------------------------------------------------------------------------------------*\ + | Profile Manager | + \*-------------------------------------------------------------------------------------*/ + ProfileManager* profile_manager; + /*-------------------------------------------------------------------------------------*\ | I2C/SMBus Interfaces | \*-------------------------------------------------------------------------------------*/ @@ -80,6 +88,7 @@ private: /*-------------------------------------------------------------------------------------*\ | RGBControllers | \*-------------------------------------------------------------------------------------*/ + std::vector rgb_controllers_sizes; std::vector rgb_controllers_hw; std::vector rgb_controllers; diff --git a/main.cpp b/main.cpp index fbaaa581..503c0b75 100644 --- a/main.cpp +++ b/main.cpp @@ -146,8 +146,6 @@ int main(int argc, char* argv[]) std::vector &busses = ResourceManager::get()->GetI2CBusses(); std::vector &rgb_controllers = ResourceManager::get()->GetRGBControllers(); - - ProfileManager profile_manager(rgb_controllers); if(!AttemptLocalConnection(rgb_controllers)) { @@ -160,7 +158,7 @@ int main(int argc, char* argv[]) unsigned int ret_flags = RET_FLAG_START_GUI; if(argc > 1) { - ret_flags = cli_main(argc, argv, rgb_controllers, &profile_manager); + ret_flags = cli_main(argc, argv, rgb_controllers, ResourceManager::get()->GetProfileManager()); } /*---------------------------------------------------------*\ @@ -173,7 +171,7 @@ int main(int argc, char* argv[]) QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QApplication a(argc, argv); - Ui::OpenRGBDialog2 dlg(busses, rgb_controllers, &profile_manager); + Ui::OpenRGBDialog2 dlg(busses, rgb_controllers); if(ret_flags & RET_FLAG_I2C_TOOLS) { diff --git a/qt/OpenRGBDialog2.cpp b/qt/OpenRGBDialog2.cpp index ef4086ec..f32e49ee 100644 --- a/qt/OpenRGBDialog2.cpp +++ b/qt/OpenRGBDialog2.cpp @@ -76,7 +76,7 @@ static void UpdateDetectionProgressCallback(void * 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) +OpenRGBDialog2::OpenRGBDialog2(std::vector& bus, std::vector& control, QWidget *parent) : QMainWindow(parent), busses(bus), controllers(control), ui(new OpenRGBDialog2Ui) { ui->setupUi(this); @@ -487,6 +487,8 @@ void OpenRGBDialog2::UpdateDevicesList() void OpenRGBDialog2::UpdateProfileList() { + ProfileManager* profile_manager = ResourceManager::get()->GetProfileManager(); + if(profile_manager != NULL) { /*-----------------------------------------------------*\ @@ -594,6 +596,8 @@ void OpenRGBDialog2::on_SetAllDevices(unsigned char red, unsigned char green, un void OpenRGBDialog2::on_SaveSizeProfile() { + ProfileManager* profile_manager = ResourceManager::get()->GetProfileManager(); + if(profile_manager != NULL) { /*---------------------------------------------------------*\ @@ -617,6 +621,8 @@ void OpenRGBDialog2::on_ShowHide() void Ui::OpenRGBDialog2::on_ProfileSelected() { + ProfileManager* profile_manager = ResourceManager::get()->GetProfileManager(); + if(profile_manager != NULL) { /*---------------------------------------------------------*\ @@ -640,6 +646,7 @@ void Ui::OpenRGBDialog2::on_ProfileSelected() void Ui::OpenRGBDialog2::on_ButtonSaveProfile_clicked() { OpenRGBProfileSaveDialog dialog; + ProfileManager* profile_manager = ResourceManager::get()->GetProfileManager(); if(profile_manager != NULL) { @@ -665,6 +672,8 @@ void Ui::OpenRGBDialog2::on_ButtonSaveProfile_clicked() void Ui::OpenRGBDialog2::on_ButtonLoadProfile_clicked() { + ProfileManager* profile_manager = ResourceManager::get()->GetProfileManager(); + if(profile_manager != NULL) { /*---------------------------------------------------------*\ @@ -687,6 +696,8 @@ void Ui::OpenRGBDialog2::on_ButtonLoadProfile_clicked() void Ui::OpenRGBDialog2::on_ButtonDeleteProfile_clicked() { + ProfileManager* profile_manager = ResourceManager::get()->GetProfileManager(); + if(profile_manager != NULL) { /*---------------------------------------------------------*\ diff --git a/qt/OpenRGBDialog2.h b/qt/OpenRGBDialog2.h index 2801e7ba..33a137fb 100644 --- a/qt/OpenRGBDialog2.h +++ b/qt/OpenRGBDialog2.h @@ -29,7 +29,7 @@ class Ui::OpenRGBDialog2 : public QMainWindow Q_OBJECT public: - explicit OpenRGBDialog2(std::vector& bus, std::vector& control, ProfileManager* manager, QWidget *parent = 0); + explicit OpenRGBDialog2(std::vector& bus, std::vector& control, QWidget *parent = 0); ~OpenRGBDialog2(); void AddClient(NetworkClient* new_client); @@ -42,7 +42,6 @@ public: protected: std::vector& busses; std::vector& controllers; - ProfileManager* profile_manager; private: /*-------------------------------------*\