Automatically save a sizes.ors profile when resizing a zone, then automatically load zone sizes from sizes.ors on start
This commit is contained in:
parent
01020b50d9
commit
18c18e3999
7 changed files with 110 additions and 36 deletions
|
|
@ -25,15 +25,10 @@ bool ProfileManager::SaveProfile(std::string profile_name)
|
||||||
\*---------------------------------------------------------*/
|
\*---------------------------------------------------------*/
|
||||||
if(profile_name != "")
|
if(profile_name != "")
|
||||||
{
|
{
|
||||||
/*---------------------------------------------------------*\
|
|
||||||
| Extension .orp - OpenRgb Profile |
|
|
||||||
\*---------------------------------------------------------*/
|
|
||||||
std::string filename = profile_name + ".orp";
|
|
||||||
|
|
||||||
/*---------------------------------------------------------*\
|
/*---------------------------------------------------------*\
|
||||||
| Open an output file in binary mode |
|
| Open an output file in binary mode |
|
||||||
\*---------------------------------------------------------*/
|
\*---------------------------------------------------------*/
|
||||||
std::ofstream controller_file(filename, std::ios::out | std::ios::binary);
|
std::ofstream controller_file(profile_name, std::ios::out | std::ios::binary);
|
||||||
|
|
||||||
/*---------------------------------------------------------*\
|
/*---------------------------------------------------------*\
|
||||||
| Write header |
|
| Write header |
|
||||||
|
|
@ -76,6 +71,21 @@ bool ProfileManager::SaveProfile(std::string profile_name)
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ProfileManager::LoadProfile(std::string profile_name)
|
bool ProfileManager::LoadProfile(std::string profile_name)
|
||||||
|
{
|
||||||
|
return(LoadProfileWithOptions(profile_name, false, true));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ProfileManager::LoadSizeFromProfile(std::string profile_name)
|
||||||
|
{
|
||||||
|
return(LoadProfileWithOptions(profile_name, true, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ProfileManager::LoadProfileWithOptions
|
||||||
|
(
|
||||||
|
std::string profile_name,
|
||||||
|
bool load_size,
|
||||||
|
bool load_settings
|
||||||
|
)
|
||||||
{
|
{
|
||||||
std::vector<RGBController*> temp_controllers;
|
std::vector<RGBController*> temp_controllers;
|
||||||
std::vector<bool> temp_controller_used;
|
std::vector<bool> temp_controller_used;
|
||||||
|
|
@ -156,6 +166,32 @@ bool ProfileManager::LoadProfile(std::string profile_name)
|
||||||
&&(temp_controller->version == controller_ptr->version )
|
&&(temp_controller->version == controller_ptr->version )
|
||||||
&&(temp_controller->serial == controller_ptr->serial )
|
&&(temp_controller->serial == controller_ptr->serial )
|
||||||
&&(temp_controller->location == controller_ptr->location ))
|
&&(temp_controller->location == controller_ptr->location ))
|
||||||
|
{
|
||||||
|
/*---------------------------------------------------------*\
|
||||||
|
| Update zone sizes if requested |
|
||||||
|
\*---------------------------------------------------------*/
|
||||||
|
if(load_size)
|
||||||
|
{
|
||||||
|
if(temp_controller->zones.size() == controller_ptr->zones.size())
|
||||||
|
{
|
||||||
|
for(int zone_idx = 0; zone_idx < temp_controller->zones.size(); zone_idx++)
|
||||||
|
{
|
||||||
|
if((temp_controller->zones[zone_idx].name == controller_ptr->zones[zone_idx].name )
|
||||||
|
&&(temp_controller->zones[zone_idx].type == controller_ptr->zones[zone_idx].type )
|
||||||
|
&&(temp_controller->zones[zone_idx].leds_min == controller_ptr->zones[zone_idx].leds_min )
|
||||||
|
&&(temp_controller->zones[zone_idx].leds_max == controller_ptr->zones[zone_idx].leds_max )
|
||||||
|
&&(temp_controller->zones[zone_idx].leds_count != controller_ptr->zones[zone_idx].leds_count))
|
||||||
|
{
|
||||||
|
controller_ptr->ResizeZone(zone_idx, temp_controller->zones[zone_idx].leds_count);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*---------------------------------------------------------*\
|
||||||
|
| Update settings if requested |
|
||||||
|
\*---------------------------------------------------------*/
|
||||||
|
if(load_settings)
|
||||||
{
|
{
|
||||||
/*---------------------------------------------------------*\
|
/*---------------------------------------------------------*\
|
||||||
| Update all modes |
|
| Update all modes |
|
||||||
|
|
@ -208,6 +244,7 @@ bool ProfileManager::LoadProfile(std::string profile_name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return(ret_val);
|
return(ret_val);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ public:
|
||||||
|
|
||||||
bool SaveProfile(std::string profile_name);
|
bool SaveProfile(std::string profile_name);
|
||||||
bool LoadProfile(std::string profile_name);
|
bool LoadProfile(std::string profile_name);
|
||||||
|
bool LoadSizeFromProfile(std::string profile_name);
|
||||||
void DeleteProfile(std::string profile_name);
|
void DeleteProfile(std::string profile_name);
|
||||||
|
|
||||||
std::vector<std::string> profile_list;
|
std::vector<std::string> profile_list;
|
||||||
|
|
@ -19,4 +20,10 @@ protected:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void UpdateProfileList();
|
void UpdateProfileList();
|
||||||
|
bool LoadProfileWithOptions
|
||||||
|
(
|
||||||
|
std::string profile_name,
|
||||||
|
bool load_size,
|
||||||
|
bool load_settings
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
2
main.cpp
2
main.cpp
|
|
@ -42,6 +42,8 @@ int main(int argc, char* argv[])
|
||||||
|
|
||||||
DetectRGBControllers();
|
DetectRGBControllers();
|
||||||
|
|
||||||
|
profile_manager.LoadSizeFromProfile("sizes.ors");
|
||||||
|
|
||||||
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
||||||
QApplication a(argc, argv);
|
QApplication a(argc, argv);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -959,6 +959,11 @@ void Ui::OpenRGBDevicePage::on_ResizeButton_clicked()
|
||||||
| Update color picker with color of first LED |
|
| Update color picker with color of first LED |
|
||||||
\*-----------------------------------------------------*/
|
\*-----------------------------------------------------*/
|
||||||
on_LEDBox_currentIndexChanged(0);
|
on_LEDBox_currentIndexChanged(0);
|
||||||
|
|
||||||
|
/*-----------------------------------------------------*\
|
||||||
|
| Save the size profile |
|
||||||
|
\*-----------------------------------------------------*/
|
||||||
|
SaveSizeProfile();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,7 @@ private:
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void SetAllDevices(unsigned char red, unsigned char green, unsigned char blue);
|
void SetAllDevices(unsigned char red, unsigned char green, unsigned char blue);
|
||||||
|
void SaveSizeProfile();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // OPENRGBDEVICEPAGE_H
|
#endif // OPENRGBDEVICEPAGE_H
|
||||||
|
|
|
||||||
|
|
@ -97,6 +97,14 @@ OpenRGBDialog2::OpenRGBDialog2(std::vector<i2c_smbus_interface *>& bus, std::vec
|
||||||
this,
|
this,
|
||||||
SLOT(on_SetAllDevices(unsigned char, unsigned char, unsigned char)));
|
SLOT(on_SetAllDevices(unsigned char, unsigned char, unsigned char)));
|
||||||
|
|
||||||
|
/*-----------------------------------------------------*\
|
||||||
|
| Connect the page's Resize signal to the Save Size slot|
|
||||||
|
\*-----------------------------------------------------*/
|
||||||
|
connect(NewPage,
|
||||||
|
SIGNAL(SaveSizeProfile()),
|
||||||
|
this,
|
||||||
|
SLOT(on_SaveSizeProfile()));
|
||||||
|
|
||||||
/*-----------------------------------------------------*\
|
/*-----------------------------------------------------*\
|
||||||
| Use Qt's HTML capabilities to display both icon and |
|
| Use Qt's HTML capabilities to display both icon and |
|
||||||
| text in the tab label. Choose icon based on device |
|
| text in the tab label. Choose icon based on device |
|
||||||
|
|
@ -319,6 +327,14 @@ void OpenRGBDialog2::on_SetAllDevices(unsigned char red, unsigned char green, un
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OpenRGBDialog2::on_SaveSizeProfile()
|
||||||
|
{
|
||||||
|
/*---------------------------------------------------------*\
|
||||||
|
| Save the profile |
|
||||||
|
\*---------------------------------------------------------*/
|
||||||
|
profile_manager.SaveProfile("sizes.ors");
|
||||||
|
}
|
||||||
|
|
||||||
void OpenRGBDialog2::on_ShowHide()
|
void OpenRGBDialog2::on_ShowHide()
|
||||||
{
|
{
|
||||||
if(isHidden())
|
if(isHidden())
|
||||||
|
|
@ -359,10 +375,15 @@ void Ui::OpenRGBDialog2::on_ButtonSaveProfile_clicked()
|
||||||
\*---------------------------------------------------------*/
|
\*---------------------------------------------------------*/
|
||||||
std::string profile_name = dialog.show();
|
std::string profile_name = dialog.show();
|
||||||
|
|
||||||
|
/*---------------------------------------------------------*\
|
||||||
|
| Extension .orp - OpenRgb Profile |
|
||||||
|
\*---------------------------------------------------------*/
|
||||||
|
std::string filename = profile_name + ".orp";
|
||||||
|
|
||||||
/*---------------------------------------------------------*\
|
/*---------------------------------------------------------*\
|
||||||
| Save the profile |
|
| Save the profile |
|
||||||
\*---------------------------------------------------------*/
|
\*---------------------------------------------------------*/
|
||||||
if(profile_manager.SaveProfile(profile_name))
|
if(profile_manager.SaveProfile(filename))
|
||||||
{
|
{
|
||||||
RefreshProfileList();
|
RefreshProfileList();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,7 @@ private slots:
|
||||||
void on_QuickMagenta();
|
void on_QuickMagenta();
|
||||||
void on_QuickWhite();
|
void on_QuickWhite();
|
||||||
void on_SetAllDevices(unsigned char red, unsigned char green, unsigned char blue);
|
void on_SetAllDevices(unsigned char red, unsigned char green, unsigned char blue);
|
||||||
|
void on_SaveSizeProfile();
|
||||||
void on_ShowHide();
|
void on_ShowHide();
|
||||||
void on_ProfileSelected();
|
void on_ProfileSelected();
|
||||||
void on_ButtonSaveProfile_clicked();
|
void on_ButtonSaveProfile_clicked();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue