diff --git a/qt/OpenRGBDialog2.cpp b/qt/OpenRGBDialog2.cpp index 2abbd85e..946ad6ab 100644 --- a/qt/OpenRGBDialog2.cpp +++ b/qt/OpenRGBDialog2.cpp @@ -227,6 +227,22 @@ OpenRGBDialog2::OpenRGBDialog2(QWidget *parent) : QMainWindow(parent), ui(new Op setGeometry(set_window); } + /*-----------------------------------------------------*\ + | If set_on_exit doesn't exist, write it to config | + \*-----------------------------------------------------*/ + if(!ui_settings.contains("exit_profile")) + { + json on_exit_settings; + + on_exit_settings["set_on_exit"] = false; + on_exit_settings["profile_name"] = ""; + + ui_settings["exit_profile"] = on_exit_settings; + + settings_manager->SetSettings(ui_string, ui_settings); + settings_manager->SaveSettings(); + } + /*-----------------------------------------------------*\ | Register detection progress callback with resource | | manager | @@ -527,11 +543,50 @@ void OpenRGBDialog2::closeEvent(QCloseEvent *event) else { plugin_manager->UnloadPlugins(); + LoadExitProfile(); event->accept(); QApplication::exit(0); } } +void OpenRGBDialog2::LoadExitProfile() +{ + /*-----------------------------------------------------*\ + | Set Exit Profile (if enabled and valid) | + \*-----------------------------------------------------*/ + const std::string exit_profile = "exit_profile"; + const std::string set_on_exit = "set_on_exit"; + const std::string profile_name = "profile_name"; + json ui_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("UserInterface"); + + if(ui_settings.contains(exit_profile)) + { + if( ui_settings[exit_profile].contains(set_on_exit) + && ui_settings[exit_profile].contains(profile_name) ) + { + if(ui_settings[exit_profile][set_on_exit].get()) + { + /*-----------------------------------------------------*\ + | Set the profile name from settings and check the | + | profile combobox for a match | + \*-----------------------------------------------------*/ + std::string profile = ui_settings[exit_profile][profile_name].get(); + int profile_index = ui->ProfileBox->findText(QString::fromStdString(profile)); + + if(profile_index > -1) + { + ui->ProfileBox->setCurrentIndex(profile_index); + on_ButtonLoadProfile_clicked(); + /*-----------------------------------------------------*\ + | Pause briefly to ensure that all profiles are loaded. | + \*-----------------------------------------------------*/ + std::this_thread::sleep_for(std::chrono::milliseconds(250)); + } + } + } + } +} + void OpenRGBDialog2::AddPluginsPage() { /*-----------------------------------------------------*\ @@ -648,6 +703,7 @@ void OpenRGBDialog2::AddSettingsPage() | Connect signals to slots | \*-----------------------------------------------------*/ connect(SettingsPage, SIGNAL(TrayIconChanged(bool)), this, SLOT(SetTrayIcon(bool))); + connect(this, SIGNAL(ProfileListChanged()), SettingsPage, SLOT(UpdateProfiles())); } void OpenRGBDialog2::AddE131SettingsPage() @@ -1343,6 +1399,8 @@ void OpenRGBDialog2::UpdateProfileList() profileMenu->addAction(actionProfileSelected); } } + + emit ProfileListChanged(); } void OpenRGBDialog2::on_Exit() diff --git a/qt/OpenRGBDialog2.h b/qt/OpenRGBDialog2.h index 0d05f3e0..da57d6ae 100644 --- a/qt/OpenRGBDialog2.h +++ b/qt/OpenRGBDialog2.h @@ -62,6 +62,9 @@ public: bool DontShowAgain; +signals: + void ProfileListChanged(); + public slots: void SetTrayIcon(bool tray_icon); @@ -116,6 +119,7 @@ private: void UpdateDevicesList(); void UpdateProfileList(); void closeEvent(QCloseEvent *event); + void LoadExitProfile(); void SetDetectionViewState(bool detection_showing); void SaveProfile(); diff --git a/qt/OpenRGBSettingsPage.cpp b/qt/OpenRGBSettingsPage.cpp index c3d9a4a7..8b9e7d5b 100644 --- a/qt/OpenRGBSettingsPage.cpp +++ b/qt/OpenRGBSettingsPage.cpp @@ -97,23 +97,7 @@ OpenRGBSettingsPage::OpenRGBSettingsPage(QWidget *parent) : ui->CheckboxAMDSMBusReduceCPU->hide(); #endif - /*---------------------------------------------------------*\ - | Load AutoStart settings | - \*---------------------------------------------------------*/ - ProfileManager* profile_manager = ResourceManager::get()->GetProfileManager(); - - /*---------------------------------------------------------*\ - | Load profiles into combo box | - \*---------------------------------------------------------*/ - if(profile_manager != NULL) - { - ui->ComboBoxAutoStartProfile->clear(); - - for(std::size_t profile_index = 0; profile_index < profile_manager->profile_list.size(); profile_index++) - { - ui->ComboBoxAutoStartProfile->addItem(profile_manager->profile_list[profile_index].c_str()); - } - } + UpdateProfiles(); /*---------------------------------------------------------*\ | Make sure autostart settings exist | @@ -160,6 +144,88 @@ OpenRGBSettingsPage::~OpenRGBSettingsPage() delete ui; } +void OpenRGBSettingsPage::UpdateProfiles() +{ + /*---------------------------------------------------------*\ + | Load AutoStart settings | + \*---------------------------------------------------------*/ + ProfileManager* profile_manager = ResourceManager::get()->GetProfileManager(); + + /*---------------------------------------------------------*\ + | Load profiles into combo box | + \*---------------------------------------------------------*/ + if(profile_manager != NULL) + { + ui->ComboBoxAutoStartProfile->blockSignals(true); + ui->ComboBoxExitProfile->blockSignals(true); + + ui->ComboBoxAutoStartProfile->clear(); + ui->ComboBoxExitProfile->clear(); + + for(std::size_t profile_index = 0; profile_index < profile_manager->profile_list.size(); profile_index++) + { + QString new_profile = QString(profile_manager->profile_list[profile_index].c_str()); + + ui->ComboBoxAutoStartProfile->addItem(new_profile); + ui->ComboBoxExitProfile->addItem(new_profile); + } + + ui->ComboBoxAutoStartProfile->blockSignals(false); + ui->ComboBoxExitProfile->blockSignals(false); + } + + /*---------------------------------------------------------*\ + | Load user interface settings | + \*---------------------------------------------------------*/ + json autostart_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("AutoStart"); + + if(autostart_settings.contains("profile")) + { + /*-----------------------------------------------------*\ + | Set the profile name from settings and check the | + | profile combobox for a match | + \*-----------------------------------------------------*/ + std::string profile_name = autostart_settings["profile"].get(); + int profile_index = ui->ComboBoxAutoStartProfile->findText(QString::fromStdString(profile_name)); + + if(profile_index > -1) + { + ui->ComboBoxAutoStartProfile->setCurrentIndex(profile_index); + } + } + + /*---------------------------------------------------------*\ + | Load user interface settings | + \*---------------------------------------------------------*/ + json ui_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("UserInterface"); + + if(ui_settings.contains("exit_profile")) + { + if(ui_settings["exit_profile"].contains("set_on_exit")) + { + bool is_set_on_exit = ui_settings["exit_profile"]["set_on_exit"]; + + ui->CheckboxSetOnExit->setChecked(is_set_on_exit); + ui->ComboBoxExitProfile->setEnabled(is_set_on_exit); + } + + if(ui_settings["exit_profile"].contains("profile_name")) + { + /*-----------------------------------------------------*\ + | Set the profile name from settings and check the | + | profile combobox for a match | + \*-----------------------------------------------------*/ + std::string profile_name = ui_settings["exit_profile"]["profile_name"].get(); + int profile_index = ui->ComboBoxExitProfile->findText(QString::fromStdString(profile_name)); + + if(profile_index > -1) + { + ui->ComboBoxExitProfile->setCurrentIndex(profile_index); + } + } + } +} + void OpenRGBSettingsPage::on_ComboBoxTheme_currentTextChanged(const QString theme) { if(theme_initialized) @@ -215,6 +281,25 @@ void Ui::OpenRGBSettingsPage::on_CheckboxRunZoneChecks_clicked() SaveSettings(); } +void Ui::OpenRGBSettingsPage::on_CheckboxSetOnExit_clicked(bool checked) +{ + json ui_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("UserInterface"); + ui_settings["exit_profile"]["set_on_exit"] = checked; + ui_settings["exit_profile"]["profile_name"] = ui->ComboBoxExitProfile->currentText().toStdString(); + ResourceManager::get()->GetSettingsManager()->SetSettings("UserInterface", ui_settings); + SaveSettings(); + + ui->ComboBoxExitProfile->setEnabled(checked); +} + +void Ui::OpenRGBSettingsPage::on_ComboBoxExitProfile_currentTextChanged(const QString exit_profile_name) +{ + json ui_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("UserInterface"); + ui_settings["exit_profile"]["profile_name"] = exit_profile_name.toStdString(); + ResourceManager::get()->GetSettingsManager()->SetSettings("UserInterface", ui_settings); + SaveSettings(); +} + void Ui::OpenRGBSettingsPage::on_CheckboxAutoStart_clicked() { if(autostart_initialized) diff --git a/qt/OpenRGBSettingsPage.h b/qt/OpenRGBSettingsPage.h index c7da3844..a8fe6751 100644 --- a/qt/OpenRGBSettingsPage.h +++ b/qt/OpenRGBSettingsPage.h @@ -20,6 +20,9 @@ public: signals: void TrayIconChanged(bool tray_icon); +public slots: + void UpdateProfiles(); + private: Ui::OpenRGBSettingsPageUi *ui; void SaveSettings(); @@ -55,6 +58,9 @@ private slots: void on_OpenSettingsFolderButton_clicked(); void on_CheckboxLogConsole_clicked(); void on_CheckboxAMDSMBusReduceCPU_clicked(); + + void on_CheckboxSetOnExit_clicked(bool checked); + void on_ComboBoxExitProfile_currentTextChanged(const QString exit_profile_name); }; #endif // OPENRGBSETTINGSPAGE_H diff --git a/qt/OpenRGBSettingsPage.ui b/qt/OpenRGBSettingsPage.ui index db3b27ec..0192d84c 100644 --- a/qt/OpenRGBSettingsPage.ui +++ b/qt/OpenRGBSettingsPage.ui @@ -14,6 +14,13 @@ Settings page + + + + Open Settings Folder + + + @@ -23,12 +30,50 @@ 0 - 0 + -204 427 - 638 + 670 + + + + Enable Log Console (restart required) + + + + + + + Start Minimized + + + + + + + Load Window Geometry + + + + + + + Drivers Settings + + + + + + + + + + Set Server Port + + + @@ -36,6 +81,77 @@ + + + + Start Server + + + + + + + User Interface Settings: + + + + + + + Greyscale Tray Icon + + + + + + + + + + Log Manager Settings: + + + + + + + Custom Arguments + + + + + + + Load Profile + + + + + + + Qt::Vertical + + + QSizePolicy::MinimumExpanding + + + + 20 + 40 + + + + + + + + + + + Start At Login + + + @@ -49,57 +165,10 @@ - - + + - Start Server - - - - - - - - - - Enable Log Console (restart required) - - - - - - - Custom Arguments - - - - - - - Save Geometry On Close - - - - - - - Qt::Vertical - - - QSizePolicy::MinimumExpanding - - - - 20 - 40 - - - - - - - - Load Window Geometry + AMD SMBus: Reduce CPU Usage (restart required) @@ -110,6 +179,9 @@ + + + @@ -117,10 +189,17 @@ - - + + - Log Manager Settings: + Start at Login Status + + + + + + + Save Geometry On Close @@ -131,37 +210,6 @@ - - - - - - - Start at Login Status - - - - - - - Set Server Port - - - - - - - Load Profile - - - - - - - Drivers Settings - - - @@ -169,58 +217,20 @@ - - - - - + + - User Interface Settings: + Set Profile on Exit - - - - Start At Login - - - - - - - Start Minimized - - - - - - - - - - AMD SMBus: Reduce CPU Usage (restart required) - - - - - - - Greyscale Tray Icon - - + + - - - - Open Settings Folder - - -