Adding ability to load profile on GUI shutdown to resolve #1694

This commit is contained in:
Chris M 2022-07-17 05:48:49 +00:00 committed by Adam Honse
parent f737ef1214
commit 241ea0a8ef
5 changed files with 309 additions and 146 deletions

View file

@ -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<bool>())
{
/*-----------------------------------------------------*\
| Set the profile name from settings and check the |
| profile combobox for a match |
\*-----------------------------------------------------*/
std::string profile = ui_settings[exit_profile][profile_name].get<std::string>();
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()

View file

@ -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();

View file

@ -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<std::string>();
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<std::string>();
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)

View file

@ -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

View file

@ -14,6 +14,13 @@
<string>Settings page</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="1" colspan="6">
<widget class="QPushButton" name="OpenSettingsFolderButton">
<property name="text">
<string>Open Settings Folder</string>
</property>
</widget>
</item>
<item row="0" column="1" colspan="6">
<widget class="QScrollArea" name="scrollArea">
<property name="widgetResizable">
@ -23,12 +30,50 @@
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<y>-204</y>
<width>427</width>
<height>638</height>
<height>670</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="10" column="0">
<widget class="QCheckBox" name="CheckboxLogConsole">
<property name="text">
<string>Enable Log Console (restart required)</string>
</property>
</widget>
</item>
<item row="18" column="0">
<widget class="QCheckBox" name="CheckboxAutoStartMinimized">
<property name="text">
<string>Start Minimized</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QCheckBox" name="CheckboxLoadGeometry">
<property name="text">
<string>Load Window Geometry</string>
</property>
</widget>
</item>
<item row="11" column="0">
<widget class="QLabel" name="DriversSettingsLabel">
<property name="text">
<string>Drivers Settings</string>
</property>
</widget>
</item>
<item row="22" column="1">
<widget class="QLineEdit" name="TextCustomArgs"/>
</item>
<item row="20" column="0">
<widget class="QCheckBox" name="CheckboxAutoStartSetServerPort">
<property name="text">
<string>Set Server Port</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QCheckBox" name="CheckboxMinimizeOnClose">
<property name="text">
@ -36,6 +81,77 @@
</property>
</widget>
</item>
<item row="19" column="0">
<widget class="QCheckBox" name="CheckboxAutoStartServer">
<property name="text">
<string>Start Server</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="UserInterfaceSettingsLabel">
<property name="text">
<string>User Interface Settings:</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QCheckBox" name="CheckboxTrayIconGreyscale">
<property name="text">
<string>Greyscale Tray Icon</string>
</property>
</widget>
</item>
<item row="21" column="1">
<widget class="QLineEdit" name="TextClientHost"/>
</item>
<item row="9" column="0">
<widget class="QLabel" name="LogManagerSettingsLabel">
<property name="text">
<string>Log Manager Settings:</string>
</property>
</widget>
</item>
<item row="22" column="0">
<widget class="QCheckBox" name="CheckboxAutoStartCustom">
<property name="text">
<string>Custom Arguments</string>
</property>
</widget>
</item>
<item row="23" column="0">
<widget class="QCheckBox" name="CheckboxAutoStartProfile">
<property name="text">
<string>Load Profile</string>
</property>
</widget>
</item>
<item row="26" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::MinimumExpanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="1">
<widget class="QComboBox" name="ComboBoxTheme"/>
</item>
<item row="14" column="0">
<widget class="QCheckBox" name="CheckboxAutoStart">
<property name="text">
<string>Start At Login</string>
</property>
</widget>
</item>
<item row="20" column="1">
<widget class="QLineEdit" name="TextServerPort">
<property name="inputMask">
@ -49,57 +165,10 @@
</property>
</widget>
</item>
<item row="19" column="0">
<widget class="QCheckBox" name="CheckboxAutoStartServer">
<item row="12" column="0">
<widget class="QCheckBox" name="CheckboxAMDSMBusReduceCPU">
<property name="text">
<string>Start Server</string>
</property>
</widget>
</item>
<item row="21" column="1">
<widget class="QLineEdit" name="TextClientHost"/>
</item>
<item row="10" column="0">
<widget class="QCheckBox" name="CheckboxLogConsole">
<property name="text">
<string>Enable Log Console (restart required)</string>
</property>
</widget>
</item>
<item row="22" column="0">
<widget class="QCheckBox" name="CheckboxAutoStartCustom">
<property name="text">
<string>Custom Arguments</string>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QCheckBox" name="CheckboxSaveGeometry">
<property name="text">
<string>Save Geometry On Close</string>
</property>
</widget>
</item>
<item row="25" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::MinimumExpanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="6" column="0">
<widget class="QCheckBox" name="CheckboxLoadGeometry">
<property name="text">
<string>Load Window Geometry</string>
<string>AMD SMBus: Reduce CPU Usage (restart required)</string>
</property>
</widget>
</item>
@ -110,6 +179,9 @@
</property>
</widget>
</item>
<item row="23" column="1">
<widget class="QComboBox" name="ComboBoxAutoStartProfile"/>
</item>
<item row="13" column="0">
<widget class="QLabel" name="AutoStartLabel">
<property name="text">
@ -117,10 +189,17 @@
</property>
</widget>
</item>
<item row="9" column="0">
<widget class="QLabel" name="LogManagerSettingsLabel">
<item row="25" column="0">
<widget class="QLabel" name="AutoStartStatusLabel">
<property name="text">
<string>Log Manager Settings:</string>
<string>Start at Login Status</string>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QCheckBox" name="CheckboxSaveGeometry">
<property name="text">
<string>Save Geometry On Close</string>
</property>
</widget>
</item>
@ -131,37 +210,6 @@
</property>
</widget>
</item>
<item row="23" column="1">
<widget class="QComboBox" name="ComboBoxAutoStartProfile"/>
</item>
<item row="24" column="0">
<widget class="QLabel" name="AutoStartStatusLabel">
<property name="text">
<string>Start at Login Status</string>
</property>
</widget>
</item>
<item row="20" column="0">
<widget class="QCheckBox" name="CheckboxAutoStartSetServerPort">
<property name="text">
<string>Set Server Port</string>
</property>
</widget>
</item>
<item row="23" column="0">
<widget class="QCheckBox" name="CheckboxAutoStartProfile">
<property name="text">
<string>Load Profile</string>
</property>
</widget>
</item>
<item row="11" column="0">
<widget class="QLabel" name="DriversSettingsLabel">
<property name="text">
<string>Drivers Settings</string>
</property>
</widget>
</item>
<item row="8" column="0">
<widget class="QCheckBox" name="CheckboxRunZoneChecks">
<property name="text">
@ -169,58 +217,20 @@
</property>
</widget>
</item>
<item row="22" column="1">
<widget class="QLineEdit" name="TextCustomArgs"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="UserInterfaceSettingsLabel">
<item row="24" column="0">
<widget class="QCheckBox" name="CheckboxSetOnExit">
<property name="text">
<string>User Interface Settings:</string>
<string>Set Profile on Exit</string>
</property>
</widget>
</item>
<item row="14" column="0">
<widget class="QCheckBox" name="CheckboxAutoStart">
<property name="text">
<string>Start At Login</string>
</property>
</widget>
</item>
<item row="18" column="0">
<widget class="QCheckBox" name="CheckboxAutoStartMinimized">
<property name="text">
<string>Start Minimized</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QComboBox" name="ComboBoxTheme"/>
</item>
<item row="12" column="0">
<widget class="QCheckBox" name="CheckboxAMDSMBusReduceCPU">
<property name="text">
<string>AMD SMBus: Reduce CPU Usage (restart required)</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QCheckBox" name="CheckboxTrayIconGreyscale">
<property name="text">
<string>Greyscale Tray Icon</string>
</property>
</widget>
<item row="24" column="1">
<widget class="QComboBox" name="ComboBoxExitProfile"/>
</item>
</layout>
</widget>
</widget>
</item>
<item row="1" column="1" colspan="6">
<widget class="QPushButton" name="OpenSettingsFolderButton">
<property name="text">
<string>Open Settings Folder</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>