[next] Active profile tracking

This commit is contained in:
Adam Honse
2026-02-08 00:08:47 -06:00
parent 91cdbe763c
commit a4191fa4e8
37 changed files with 582 additions and 224 deletions

View File

@@ -337,27 +337,15 @@ std::string NetworkClient::DetectionManager_GetDetectionString()
/*---------------------------------------------------------*\
| ProfileManager functions |
\*---------------------------------------------------------*/
char * NetworkClient::ProfileManager_GetProfileList()
void NetworkClient::ProfileManager_GetProfileList()
{
NetPacketHeader reply_hdr;
char * response_data = NULL;
InitNetPacketHeader(&reply_hdr, 0, NET_PACKET_ID_PROFILEMANAGER_GET_PROFILE_LIST, 0);
send_in_progress.lock();
send(client_sock, (char *)&reply_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
send_in_progress.unlock();
std::unique_lock<std::mutex> wait_lock(waiting_on_response_mutex);
waiting_on_response_cv.wait(wait_lock);
if(response_header.pkt_id == NET_PACKET_ID_PROFILEMANAGER_GET_PROFILE_LIST && response_data_ptr != NULL)
{
response_data = response_data_ptr;
response_data_ptr = NULL;
}
return(response_data);
}
void NetworkClient::ProfileManager_LoadProfile(std::string profile_name)
@@ -459,6 +447,17 @@ std::string NetworkClient::ProfileManager_GetActiveProfile()
return(response_string);
}
void NetworkClient::ProfileManager_ClearActiveProfile()
{
NetPacketHeader pkt_hdr;
InitNetPacketHeader(&pkt_hdr, 0, NET_PACKET_ID_PROFILEMANAGER_CLEAR_ACTIVE_PROFILE, 0);
send_in_progress.lock();
send(client_sock, (char *)&pkt_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
send_in_progress.unlock();
}
/*---------------------------------------------------------*\
| SettingsManager functions |
\*---------------------------------------------------------*/
@@ -1089,7 +1088,6 @@ void NetworkClient::ListenThreadFunction()
SignalNetworkClientUpdate(NETWORKCLIENT_UPDATE_REASON_DETECTION_COMPLETE);
break;
case NET_PACKET_ID_PROFILEMANAGER_GET_PROFILE_LIST:
case NET_PACKET_ID_PROFILEMANAGER_DOWNLOAD_PROFILE:
case NET_PACKET_ID_PROFILEMANAGER_GET_ACTIVE_PROFILE:
case NET_PACKET_ID_SETTINGSMANAGER_GET_SETTINGS:
@@ -1117,6 +1115,11 @@ void NetworkClient::ListenThreadFunction()
ProcessRequest_ProfileManager_ProfileAboutToLoad();
break;
case NET_PACKET_ID_PROFILEMANAGER_GET_PROFILE_LIST:
case NET_PACKET_ID_PROFILEMANAGER_PROFILE_LIST_UPDATED:
ProcessRequest_ProfileManager_ProfileListUpdated(header.pkt_size, data);
break;
case NET_PACKET_ID_RGBCONTROLLER_SIGNALUPDATE:
ProcessRequest_RGBController_SignalUpdate(header.pkt_size, data, header.pkt_dev_id);
break;
@@ -1382,6 +1385,11 @@ void NetworkClient::ProcessRequest_ProfileManager_ProfileAboutToLoad()
send_in_progress.unlock();
}
void NetworkClient::ProcessRequest_ProfileManager_ProfileListUpdated(unsigned int data_size, char * data)
{
ResourceManager::get()->GetProfileManager()->SetProfileListFromDescription(data);
}
void NetworkClient::ProcessRequest_ProfileManager_ProfileLoaded(unsigned int data_size, char * data)
{
if(data_size == 0 || data == NULL)

View File

@@ -29,16 +29,18 @@ typedef void (*NetworkClientCallback)(void *, unsigned int);
\*---------------------------------------------------------*/
enum
{
NETWORKCLIENT_UPDATE_REASON_CLIENT_STARTED, /* Client started */
NETWORKCLIENT_UPDATE_REASON_CLIENT_STOPPED, /* Client stopped */
NETWORKCLIENT_UPDATE_REASON_CLIENT_CONNECTED, /* Client connectedd */
NETWORKCLIENT_UPDATE_REASON_CLIENT_DISCONNECTED, /* Client disconnected */
NETWORKCLIENT_UPDATE_REASON_SERVER_STRING_RECEIVED, /* Server string received */
NETWORKCLIENT_UPDATE_REASON_PROTOCOL_NEGOTIATED, /* Protocol version negotiated */
NETWORKCLIENT_UPDATE_REASON_DEVICE_LIST_UPDATED, /* Device list updated */
NETWORKCLIENT_UPDATE_REASON_DETECTION_STARTED, /* Detection started */
NETWORKCLIENT_UPDATE_REASON_DETECTION_PROGRESS_CHANGED, /* Detection progress changed */
NETWORKCLIENT_UPDATE_REASON_DETECTION_COMPLETE, /* Detection completed */
NETWORKCLIENT_UPDATE_REASON_CLIENT_STARTED, /* Client started */
NETWORKCLIENT_UPDATE_REASON_CLIENT_STOPPED, /* Client stopped */
NETWORKCLIENT_UPDATE_REASON_CLIENT_CONNECTED, /* Client connectedd */
NETWORKCLIENT_UPDATE_REASON_CLIENT_DISCONNECTED, /* Client disconnected */
NETWORKCLIENT_UPDATE_REASON_SERVER_STRING_RECEIVED, /* Server string received */
NETWORKCLIENT_UPDATE_REASON_PROTOCOL_NEGOTIATED, /* Protocol version negotiated */
NETWORKCLIENT_UPDATE_REASON_DEVICE_LIST_UPDATED, /* Device list updated */
NETWORKCLIENT_UPDATE_REASON_DETECTION_STARTED, /* Detection started */
NETWORKCLIENT_UPDATE_REASON_DETECTION_PROGRESS_CHANGED, /* Detection progress changed */
NETWORKCLIENT_UPDATE_REASON_DETECTION_COMPLETE, /* Detection completed */
NETWORKCLIENT_UPDATE_REASON_PROFILEMANAGER_PROFILE_LIST_UPDATED, /* Profile list updated */
NETWORKCLIENT_UPDATE_REASON_PROFILEMANAGER_ACTIVE_PROFILE_CHANGED, /* Active profile changed */
};
@@ -94,13 +96,14 @@ public:
/*-----------------------------------------------------*\
| ProfileManager functions |
\*-----------------------------------------------------*/
char * ProfileManager_GetProfileList();
void ProfileManager_GetProfileList();
void ProfileManager_LoadProfile(std::string profile_name);
void ProfileManager_SaveProfile(std::string profile_name);
void ProfileManager_DeleteProfile(std::string profile_name);
void ProfileManager_UploadProfile(std::string profile_json_str);
std::string ProfileManager_DownloadProfile(std::string profile_name);
std::string ProfileManager_GetActiveProfile();
void ProfileManager_ClearActiveProfile();
/*-----------------------------------------------------*\
| SettingsManager functions |
@@ -228,6 +231,7 @@ private:
void ProcessRequest_ProfileManager_ActiveProfileChanged(unsigned int data_size, char * data);
void ProcessRequest_ProfileManager_ProfileAboutToLoad();
void ProcessRequest_ProfileManager_ProfileListUpdated(unsigned int data_size, char * data);
void ProcessRequest_ProfileManager_ProfileLoaded(unsigned int data_size, char * data);
void SendData_ClientFlags();

View File

@@ -112,6 +112,10 @@ enum
/* Forwards loaded profile data */
NET_PACKET_ID_PROFILEMANAGER_PROFILE_ABOUT_TO_LOAD
= 159, /* Indicate to clients profile about to load */
NET_PACKET_ID_PROFILEMANAGER_PROFILE_LIST_UPDATED
= 160, /* Indicate to clients profile list updated */
NET_PACKET_ID_PROFILEMANAGER_CLEAR_ACTIVE_PROFILE
= 161, /* Clear the active profile */
/*----------------------------------------------------------------------------------------------------------*\
| PluginManager functions |

View File

@@ -207,6 +207,24 @@ unsigned int NetworkServer::GetClientProtocolVersion(unsigned int client_num)
/*---------------------------------------------------------*\
| Callback functions |
\*---------------------------------------------------------*/
void NetworkServer::SignalProfileManagerUpdate(unsigned int update_reason)
{
switch(update_reason)
{
case PROFILEMANAGER_UPDATE_REASON_PROFILE_LIST_UPDATED:
SignalProfileListUpdated();
break;
case PROFILEMANAGER_UPDATE_REASON_ACTIVE_PROFILE_CHANGED:
SignalActiveProfileChanged();
break;
case PROFILEMANAGER_UPDATE_REASON_PROFILE_ABOUT_TO_LOAD:
ProfileManager_ProfileAboutToLoad();
break;
}
}
void NetworkServer::SignalResourceManagerUpdate(unsigned int update_reason)
{
switch(update_reason)
@@ -636,6 +654,26 @@ void NetworkServer::SetSettingsManager(SettingsManagerInterface* settings_manage
/*---------------------------------------------------------*\
| Server callback signal functions |
\*---------------------------------------------------------*/
void NetworkServer::SignalActiveProfileChanged()
{
if(profile_manager)
{
std::string active_profile = profile_manager->GetActiveProfile();
/*-------------------------------------------------*\
| Indicate to the clients that the profile list has |
| changed |
\*-------------------------------------------------*/
for(unsigned int client_idx = 0; client_idx < ServerClients.size(); client_idx++)
{
if(ServerClients[client_idx]->client_flags & NET_CLIENT_FLAG_SUPPORTS_PROFILEMANAGER)
{
SendRequest_ProfileManager_ActiveProfileChanged(ServerClients[client_idx]->client_sock, active_profile);
}
}
}
}
void NetworkServer::SignalClientInfoChanged()
{
ClientInfoChangeMutex.lock();
@@ -708,6 +746,25 @@ void NetworkServer::SignalDeviceListUpdated()
}
}
void NetworkServer::SignalProfileListUpdated()
{
if(profile_manager)
{
unsigned char *profile_list_description = profile_manager->GetProfileListDescription();
/*-------------------------------------------------*\
| Indicate to the clients that the profile list has |
| changed |
\*-------------------------------------------------*/
for(unsigned int client_idx = 0; client_idx < ServerClients.size(); client_idx++)
{
SendRequest_ProfileManager_ProfileListChanged(ServerClients[client_idx]->client_sock, profile_list_description);
}
delete[] profile_list_description;
}
}
void NetworkServer::SignalServerListeningChanged()
{
ServerListeningChangeMutex.lock();
@@ -942,6 +999,10 @@ void NetworkServer::ProfileManagerListenThread(NetworkServerControllerThread * t
case NET_PACKET_ID_PROFILEMANAGER_GET_ACTIVE_PROFILE:
ProcessRequest_ProfileManager_GetActiveProfile(queue_entry.client_sock);
break;
case NET_PACKET_ID_PROFILEMANAGER_CLEAR_ACTIVE_PROFILE:
ProcessRequest_ProfileManager_ClearActiveProfile();
break;
}
delete[] queue_entry.data;
@@ -1102,6 +1163,7 @@ void NetworkServer::ListenThreadFunction(NetworkClientInfo * client_info)
case NET_PACKET_ID_PROFILEMANAGER_UPLOAD_PROFILE:
case NET_PACKET_ID_PROFILEMANAGER_DOWNLOAD_PROFILE:
case NET_PACKET_ID_PROFILEMANAGER_GET_ACTIVE_PROFILE:
case NET_PACKET_ID_PROFILEMANAGER_CLEAR_ACTIVE_PROFILE:
{
profilemanager_thread->queue_mutex.lock();
@@ -1468,6 +1530,14 @@ void NetworkServer::ProcessRequest_RescanDevices()
ResourceManager::get()->RescanDevices();
}
void NetworkServer::ProcessRequest_ProfileManager_ClearActiveProfile()
{
if(profile_manager)
{
profile_manager->ClearActiveProfile();
}
}
void NetworkServer::ProcessRequest_ProfileManager_DeleteProfile(unsigned int data_size, char * data)
{
if(data == NULL)
@@ -2273,6 +2343,8 @@ void NetworkServer::SendReply_ProfileList(SOCKET client_sock)
send(client_sock, (const char *)&reply_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
send(client_sock, (const char *)reply_data, reply_size, MSG_NOSIGNAL);
send_in_progress.unlock();
delete[] reply_data;
}
void NetworkServer::SendReply_PluginList(SOCKET client_sock)
@@ -2393,6 +2465,18 @@ void NetworkServer::SendReply_PluginSpecific(SOCKET client_sock, unsigned int pk
delete [] data;
}
void NetworkServer::SendRequest_ProfileManager_ActiveProfileChanged(SOCKET client_sock, std::string active_profile)
{
NetPacketHeader pkt_hdr;
InitNetPacketHeader(&pkt_hdr, 0, NET_PACKET_ID_PROFILEMANAGER_ACTIVE_PROFILE_CHANGED, (unsigned int)strlen(active_profile.c_str()) + 1);
send_in_progress.lock();
send(client_sock, (char *)&pkt_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
send(client_sock, (char *)active_profile.c_str(), pkt_hdr.pkt_size, MSG_NOSIGNAL);
send_in_progress.unlock();
}
void NetworkServer::SendRequest_DetectionCompleted(SOCKET client_sock, unsigned int protocol_version)
{
if(protocol_version >= 6)
@@ -2561,6 +2645,21 @@ void NetworkServer::SendRequest_ProfileManager_ProfileAboutToLoad()
}
}
void NetworkServer::SendRequest_ProfileManager_ProfileListChanged(SOCKET client_sock, unsigned char *profile_list_description)
{
NetPacketHeader pkt_hdr;
unsigned int pkt_size;
memcpy(&pkt_size, profile_list_description, sizeof(pkt_size));
InitNetPacketHeader(&pkt_hdr, 0, NET_PACKET_ID_PROFILEMANAGER_PROFILE_LIST_UPDATED, pkt_size);
send_in_progress.lock();
send(client_sock, (const char *)&pkt_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
send(client_sock, (const char *)profile_list_description, pkt_size, MSG_NOSIGNAL);
send_in_progress.unlock();
}
void NetworkServer::SendRequest_ProfileManager_ProfileLoaded(std::string profile_json_string)
{
NetPacketHeader pkt_hdr;

View File

@@ -104,7 +104,8 @@ public:
/*-----------------------------------------------------*\
| Functions for forwarding callback sigals over network |
\*-----------------------------------------------------*/
void SignalResourceManagerUpdate(unsigned int );
void SignalProfileManagerUpdate(unsigned int update_reason);
void SignalResourceManagerUpdate(unsigned int update_reason);
/*-----------------------------------------------------*\
| Server Configuration functions |
@@ -203,11 +204,13 @@ private:
/*-----------------------------------------------------*\
| Server callback signal functions |
\*-----------------------------------------------------*/
void SignalActiveProfileChanged();
void SignalClientInfoChanged();
void SignalDetectionCompleted();
void SignalDetectionProgress();
void SignalDetectionStarted();
void SignalDeviceListUpdated();
void SignalProfileListUpdated();
void SignalServerListeningChanged();
/*-----------------------------------------------------*\
@@ -226,6 +229,7 @@ private:
void ProcessRequest_ClientString(SOCKET client_sock, unsigned int data_size, char * data);
void ProcessRequest_RescanDevices();
void ProcessRequest_ProfileManager_ClearActiveProfile();
void ProcessRequest_ProfileManager_DeleteProfile(unsigned int data_size, char * data);
void ProcessRequest_ProfileManager_DownloadProfile(SOCKET client_sock, unsigned int data_size, char * data);
void ProcessRequest_ProfileManager_GetActiveProfile(SOCKET client_sock);
@@ -258,7 +262,9 @@ private:
void SendRequest_DetectionStarted(SOCKET client_sock, unsigned int protocol_version);
void SendRequest_DeviceListChanged(SOCKET client_sock);
void SendRequest_ProfileManager_ActiveProfileChanged(SOCKET client_sock, std::string active_profile);
void SendRequest_ProfileManager_ProfileAboutToLoad();
void SendRequest_ProfileManager_ProfileListChanged(SOCKET client_sock, unsigned char *profile_list_description);
/*-----------------------------------------------------*\
| Private helper functions |

View File

@@ -27,6 +27,11 @@
#define OPENRGB_PROFILE_HEADER "OPENRGB_PROFILE"
#define OPENRGB_PROFILE_VERSION OPENRGB_SDK_PROTOCOL_VERSION
/*---------------------------------------------------------*\
| ProfileManager name for log entries |
\*---------------------------------------------------------*/
const char* PROFILEMANAGER = "ProfileManager";
ProfileManager::ProfileManager(const filesystem::path& config_dir)
{
/*-----------------------------------------------------*\
@@ -96,6 +101,16 @@ ProfileManager::~ProfileManager()
}
void ProfileManager::ClearActiveProfile()
{
if(ResourceManager::get()->IsLocalClient() && ResourceManager::get()->GetLocalClient()->GetSupportsProfileManagerAPI())
{
ResourceManager::get()->GetLocalClient()->ProfileManager_ClearActiveProfile();
}
SetActiveProfile("");
}
void ProfileManager::DeleteProfile(std::string profile_name)
{
if(ResourceManager::get()->IsLocalClient() && (ResourceManager::get()->GetLocalClient()->GetSupportsProfileManagerAPI()))
@@ -243,11 +258,6 @@ bool ProfileManager::LoadProfile(std::string profile_name)
success = LoadProfileWithOptions(profile_name, false, true);
if(success)
{
ResourceManager::get()->GetServer()->SendRequest_ProfileManager_ActiveProfileChanged(profile_name);
}
return(success);
}
}
@@ -264,7 +274,7 @@ void ProfileManager::OnProfileAboutToLoad()
plugin_manager->OnProfileAboutToLoad();
}
ResourceManager::get()->GetServer()->ProfileManager_ProfileAboutToLoad();
SignalProfileManagerUpdate(PROFILEMANAGER_UPDATE_REASON_PROFILE_ABOUT_TO_LOAD);
}
void ProfileManager::OnProfileLoaded(std::string profile_json_string)
@@ -284,6 +294,48 @@ void ProfileManager::OnProfileLoaded(std::string profile_json_string)
}
}
void ProfileManager::RegisterProfileManagerCallback(ProfileManagerCallback new_callback, void * new_callback_arg)
{
ProfileManagerCallbackMutex.lock();
for(size_t idx = 0; idx < ProfileManagerCallbacks.size(); idx++)
{
if(ProfileManagerCallbacks[idx] == new_callback && ProfileManagerCallbackArgs[idx] == new_callback_arg)
{
ProfileManagerCallbackMutex.unlock();
LOG_TRACE("[%s] Tried to register an already registered ProfileManager callback, skipping. Total callbacks registered: %d", PROFILEMANAGER, ProfileManagerCallbacks.size());
return;
}
}
ProfileManagerCallbacks.push_back(new_callback);
ProfileManagerCallbackArgs.push_back(new_callback_arg);
ProfileManagerCallbackMutex.unlock();
LOG_TRACE("[%s] Registered ProfileManager callback. Total callbacks registered: %d", PROFILEMANAGER, ProfileManagerCallbacks.size());
}
void ProfileManager::UnregisterProfileManagerCallback(ProfileManagerCallback callback, void * callback_arg)
{
ProfileManagerCallbackMutex.lock();
for(size_t idx = 0; idx < ProfileManagerCallbacks.size(); idx++)
{
if(ProfileManagerCallbacks[idx] == callback && ProfileManagerCallbackArgs[idx] == callback_arg)
{
ProfileManagerCallbacks.erase(ProfileManagerCallbacks.begin() + idx);
ProfileManagerCallbackArgs.erase(ProfileManagerCallbackArgs.begin() + idx);
}
}
ProfileManagerCallbackMutex.unlock();
LOG_TRACE("[%s] Unregistered ProfileManager callback. Total callbacks registered: %d", PROFILEMANAGER, ProfileManagerCallbackArgs.size());
}
nlohmann::json ProfileManager::ReadProfileJSON(std::string profile_name)
{
nlohmann::json profile_json;
@@ -360,11 +412,6 @@ bool ProfileManager::SaveProfile(std::string profile_name)
| Upload the profile to the server |
\*---------------------------------------------*/
ResourceManager::get()->GetLocalClient()->ProfileManager_UploadProfile(profile_json.dump());
/*---------------------------------------------*\
| Update the profile list |
\*---------------------------------------------*/
UpdateProfileList();
}
else
{
@@ -411,6 +458,8 @@ bool ProfileManager::SaveProfileFromJSON(nlohmann::json profile_json)
\*-------------------------------------------------*/
UpdateProfileList();
SetActiveProfile(profile_json["profile_name"]);
return(true);
}
else
@@ -475,6 +524,10 @@ bool ProfileManager::SaveSizes()
void ProfileManager::SetActiveProfile(std::string profile_name)
{
active_profile = profile_name;
ResourceManager::get()->GetServer()->SendRequest_ProfileManager_ActiveProfileChanged(active_profile);
SignalProfileManagerUpdate(PROFILEMANAGER_UPDATE_REASON_ACTIVE_PROFILE_CHANGED);
}
void ProfileManager::SetConfigurationDirectory(const filesystem::path& directory)
@@ -516,24 +569,37 @@ void ProfileManager::SetProfileListFromDescription(char * data_buf)
profile_list.push_back((char *)&data_buf[data_ptr]);
data_ptr += name_len;
}
SignalProfileManagerUpdate(PROFILEMANAGER_UPDATE_REASON_PROFILE_LIST_UPDATED);
}
void ProfileManager::SignalProfileManagerUpdate(unsigned int update_reason)
{
ResourceManager::get()->GetServer()->SignalProfileManagerUpdate(update_reason);
ProfileManagerCallbackMutex.lock();
for(std::size_t callback_idx = 0; callback_idx < ProfileManagerCallbacks.size(); callback_idx++)
{
ProfileManagerCallbacks[callback_idx](ProfileManagerCallbackArgs[callback_idx], update_reason);
}
ProfileManagerCallbackMutex.unlock();
LOG_TRACE("[%s] ProfileManager update signalled: %d", PROFILEMANAGER, update_reason);
}
void ProfileManager::UpdateProfileList()
{
profile_list.clear();
if(ResourceManager::get()->IsLocalClient() && (ResourceManager::get()->GetLocalClient()->GetSupportsProfileManagerAPI()))
{
char * profile_data = ResourceManager::get()->GetLocalClient()->ProfileManager_GetProfileList();
if(profile_data != NULL)
{
SetProfileListFromDescription(profile_data);
delete[] profile_data;
}
ResourceManager::get()->GetLocalClient()->ProfileManager_GetProfileList();
ResourceManager::get()->GetLocalClient()->ProfileManager_GetActiveProfile();
}
else
{
profile_list.clear();
/*-------------------------------------------------*\
| Load profiles by looking for .json files in |
| profile directory |
@@ -560,6 +626,8 @@ void ProfileManager::UpdateProfileList()
}
}
}
SignalProfileManagerUpdate(PROFILEMANAGER_UPDATE_REASON_PROFILE_LIST_UPDATED);
}
}
@@ -877,6 +945,13 @@ bool ProfileManager::LoadProfileWithOptions
\*-------------------------------------------------*/
ResourceManager::get()->GetServer()->SendRequest_ProfileManager_ProfileLoaded(profile_json.dump());
/*-------------------------------------------------*\
| Update active profile |
\*-------------------------------------------------*/
SetActiveProfile(profile_name);
ResourceManager::get()->GetServer()->SendRequest_ProfileManager_ActiveProfileChanged(active_profile);
return(ret_val);
}

View File

@@ -14,9 +14,26 @@
#include "RGBController.h"
#include "filesystem.h"
/*---------------------------------------------------------*\
| Callback Types |
\*---------------------------------------------------------*/
typedef void (*ProfileManagerCallback)(void *, unsigned int);
/*---------------------------------------------------------*\
| ProfileManager Update Reason Codes |
\*---------------------------------------------------------*/
enum
{
PROFILEMANAGER_UPDATE_REASON_PROFILE_LIST_UPDATED, /* Profile list updated */
PROFILEMANAGER_UPDATE_REASON_ACTIVE_PROFILE_CHANGED, /* Active profile changed */
PROFILEMANAGER_UPDATE_REASON_PROFILE_ABOUT_TO_LOAD, /* Profile about to load */
};
class ProfileManagerInterface
{
public:
virtual void ClearActiveProfile() = 0;
virtual void DeleteProfile(std::string profile_name) = 0;
virtual std::string GetActiveProfile() = 0;
@@ -58,6 +75,8 @@ public:
ProfileManager(const filesystem::path& config_dir);
~ProfileManager();
void ClearActiveProfile();
void DeleteProfile(std::string profile_name);
std::string GetActiveProfile();
@@ -85,6 +104,13 @@ public:
void OnProfileAboutToLoad();
void OnProfileLoaded(std::string profile_json_string);
/*-----------------------------------------------------*\
| Callback Registration Functions |
\*-----------------------------------------------------*/
void RegisterProfileManagerCallback(ProfileManagerCallback new_callback, void * new_callback_arg);
void UnregisterProfileManagerCallback(ProfileManagerCallback callback, void * callback_arg);
nlohmann::json ReadProfileJSON(std::string profile_name);
bool SaveProfile(std::string profile_name);
@@ -96,6 +122,8 @@ public:
void SetProfileListFromDescription(char * data_buf);
void SignalProfileManagerUpdate(unsigned int update_reason);
void UpdateProfileList();
private:
@@ -115,6 +143,13 @@ private:
filesystem::path configuration_directory;
filesystem::path profile_directory;
/*-----------------------------------------------------*\
| ProfileManager Callbacks |
\*-----------------------------------------------------*/
std::vector<ProfileManagerCallback> ProfileManagerCallbacks;
std::vector<void *> ProfileManagerCallbackArgs;
std::mutex ProfileManagerCallbackMutex;
/*-----------------------------------------------------*\
| Private functions |
\*-----------------------------------------------------*/

View File

@@ -85,6 +85,14 @@ static void ResourceManagerNetworkClientCallback(void* this_ptr, unsigned int up
case NETWORKCLIENT_UPDATE_REASON_DETECTION_COMPLETE:
this_obj->SignalResourceManagerUpdate(RESOURCEMANAGER_UPDATE_REASON_DETECTION_COMPLETE);
break;
case NETWORKCLIENT_UPDATE_REASON_PROFILEMANAGER_PROFILE_LIST_UPDATED:
this_obj->GetProfileManager()->SignalProfileManagerUpdate(PROFILEMANAGER_UPDATE_REASON_PROFILE_LIST_UPDATED);
break;
case NETWORKCLIENT_UPDATE_REASON_PROFILEMANAGER_ACTIVE_PROFILE_CHANGED:
this_obj->GetProfileManager()->SignalProfileManagerUpdate(PROFILEMANAGER_UPDATE_REASON_ACTIVE_PROFILE_CHANGED);
break;
}
}

View File

@@ -9,6 +9,7 @@
#include "OpenRGBDevicePage.h"
#include "OpenRGBZoneResizeDialog.h"
#include "ProfileManager.h"
#include "ResourceManager.h"
#include "SettingsManager.h"
#include "ui_OpenRGBDevicePage.h"
@@ -2025,11 +2026,15 @@ void OpenRGBDevicePage::changeEvent(QEvent *event)
\*---------------------------------------------------------*/
void OpenRGBDevicePage::on_ApplyColorsButton_clicked()
{
ResourceManager::get()->GetProfileManager()->ClearActiveProfile();
UpdateColor();
}
void OpenRGBDevicePage::on_BlueSpinBox_valueChanged(int blue)
{
ResourceManager::get()->GetProfileManager()->ClearActiveProfile();
/*-----------------------------------------------------*\
| Update the current color QColor blue channel |
\*-----------------------------------------------------*/
@@ -2043,6 +2048,8 @@ void OpenRGBDevicePage::on_BlueSpinBox_valueChanged(int blue)
void OpenRGBDevicePage::on_BrightnessSlider_valueChanged(int /*value*/)
{
ResourceManager::get()->GetProfileManager()->ClearActiveProfile();
/*-----------------------------------------------------*\
| Change device mode |
\*-----------------------------------------------------*/
@@ -2051,6 +2058,8 @@ void OpenRGBDevicePage::on_BrightnessSlider_valueChanged(int /*value*/)
void OpenRGBDevicePage::on_ColorWheelBox_colorChanged(const QColor color)
{
ResourceManager::get()->GetProfileManager()->ClearActiveProfile();
/*-----------------------------------------------------*\
| Store the wheel color to the current color QColor |
\*-----------------------------------------------------*/
@@ -2117,6 +2126,8 @@ void OpenRGBDevicePage::on_DeviceViewBox_selectionChanged(QVector<int> indices)
void OpenRGBDevicePage::on_DirectionBox_currentIndexChanged(int /*index*/)
{
ResourceManager::get()->GetProfileManager()->ClearActiveProfile();
/*-----------------------------------------------------*\
| Change device mode |
\*-----------------------------------------------------*/
@@ -2185,6 +2196,8 @@ void OpenRGBDevicePage::on_EditZoneButton_clicked()
void OpenRGBDevicePage::on_GreenSpinBox_valueChanged(int green)
{
ResourceManager::get()->GetProfileManager()->ClearActiveProfile();
/*-----------------------------------------------------*\
| Update the current color QColor green channel |
\*-----------------------------------------------------*/
@@ -2198,6 +2211,8 @@ void OpenRGBDevicePage::on_GreenSpinBox_valueChanged(int green)
void OpenRGBDevicePage::on_HexLineEdit_textChanged(const QString &arg1)
{
ResourceManager::get()->GetProfileManager()->ClearActiveProfile();
/*-----------------------------------------------------*\
| Make an editable copy of the string |
\*-----------------------------------------------------*/
@@ -2242,6 +2257,8 @@ void OpenRGBDevicePage::on_HexLineEdit_textChanged(const QString &arg1)
void OpenRGBDevicePage::on_HueSpinBox_valueChanged(int hue)
{
ResourceManager::get()->GetProfileManager()->ClearActiveProfile();
/*-----------------------------------------------------*\
| Read the saturation and value box values |
\*-----------------------------------------------------*/
@@ -2269,6 +2286,8 @@ void OpenRGBDevicePage::on_LEDBox_currentIndexChanged(int /*index*/)
void OpenRGBDevicePage::on_ModeBox_currentIndexChanged(int /*index*/)
{
ResourceManager::get()->GetProfileManager()->ClearActiveProfile();
/*-----------------------------------------------------*\
| Update mode user interface elements |
\*-----------------------------------------------------*/
@@ -2292,6 +2311,8 @@ void OpenRGBDevicePage::on_ModeBox_currentIndexChanged(int /*index*/)
void OpenRGBDevicePage::on_ModeSpecificCheck_clicked()
{
ResourceManager::get()->GetProfileManager()->ClearActiveProfile();
/*-----------------------------------------------------*\
| Change device mode |
\*-----------------------------------------------------*/
@@ -2315,6 +2336,8 @@ void OpenRGBDevicePage::on_ModeSpecificCheck_clicked()
void OpenRGBDevicePage::on_PerLEDCheck_clicked()
{
ResourceManager::get()->GetProfileManager()->ClearActiveProfile();
/*-----------------------------------------------------*\
| Change device mode |
\*-----------------------------------------------------*/
@@ -2338,6 +2361,8 @@ void OpenRGBDevicePage::on_PerLEDCheck_clicked()
void OpenRGBDevicePage::on_RandomCheck_clicked()
{
ResourceManager::get()->GetProfileManager()->ClearActiveProfile();
/*-----------------------------------------------------*\
| Change device mode |
\*-----------------------------------------------------*/
@@ -2361,6 +2386,8 @@ void OpenRGBDevicePage::on_RandomCheck_clicked()
void OpenRGBDevicePage::on_RedSpinBox_valueChanged(int red)
{
ResourceManager::get()->GetProfileManager()->ClearActiveProfile();
/*-----------------------------------------------------*\
| Update the current color QColor red channel |
\*-----------------------------------------------------*/
@@ -2374,6 +2401,8 @@ void OpenRGBDevicePage::on_RedSpinBox_valueChanged(int red)
void OpenRGBDevicePage::on_SatSpinBox_valueChanged(int sat)
{
ResourceManager::get()->GetProfileManager()->ClearActiveProfile();
/*-----------------------------------------------------*\
| Read the hue and value box values |
\*-----------------------------------------------------*/
@@ -2443,6 +2472,8 @@ void OpenRGBDevicePage::on_SetAllButton_clicked()
void OpenRGBDevicePage::on_SpeedSlider_valueChanged(int /*value*/)
{
ResourceManager::get()->GetProfileManager()->ClearActiveProfile();
/*-----------------------------------------------------*\
| Change device mode |
\*-----------------------------------------------------*/
@@ -2533,6 +2564,8 @@ void OpenRGBDevicePage::on_SpinBoxModeColors_valueChanged(int count)
void OpenRGBDevicePage::on_SwatchBox_swatchChanged(const QColor color)
{
ResourceManager::get()->GetProfileManager()->ClearActiveProfile();
/*-----------------------------------------------------*\
| Store the swatch color to the current color QColor |
\*-----------------------------------------------------*/
@@ -2546,6 +2579,8 @@ void OpenRGBDevicePage::on_SwatchBox_swatchChanged(const QColor color)
void OpenRGBDevicePage::on_ValSpinBox_valueChanged(int val)
{
ResourceManager::get()->GetProfileManager()->ClearActiveProfile();
/*-----------------------------------------------------*\
| Read the hue and saturation box values |
\*-----------------------------------------------------*/

View File

@@ -15,7 +15,7 @@
#include "OpenRGBServerInfoPage.h"
#include "OpenRGBConsolePage.h"
#include "OpenRGBPluginContainer.h"
#include "OpenRGBProfileSaveDialog.h"
#include "OpenRGBProfileListDialog.h"
#include "ResourceManager.h"
#include "SettingsManager.h"
#include "TabLabel.h"
@@ -122,6 +122,22 @@ static int GetIcon(device_type type)
return icon;
}
static void OpenRGBDialogProfileManagerCallback(void * this_ptr, unsigned int update_reason)
{
OpenRGBDialog * this_obj = (OpenRGBDialog *)this_ptr;
switch(update_reason)
{
case PROFILEMANAGER_UPDATE_REASON_PROFILE_LIST_UPDATED:
QMetaObject::invokeMethod(this_obj, "UpdateProfileList", Qt::QueuedConnection);
break;
case PROFILEMANAGER_UPDATE_REASON_ACTIVE_PROFILE_CHANGED:
QMetaObject::invokeMethod(this_obj, "UpdateActiveProfile", Qt::QueuedConnection);
break;
}
}
static void OpenRGBDialogResourceManagerCallback(void * this_ptr, unsigned int update_reason)
{
OpenRGBDialog * this_obj = (OpenRGBDialog *)this_ptr;
@@ -264,6 +280,11 @@ OpenRGBDialog::OpenRGBDialog(QWidget *parent) : QMainWindow(parent), ui(new Ui::
\*-----------------------------------------------------*/
ResourceManager::get()->RegisterResourceManagerCallback(OpenRGBDialogResourceManagerCallback, this);
/*-----------------------------------------------------*\
| Register profile manager callbacks |
\*-----------------------------------------------------*/
ResourceManager::get()->GetProfileManager()->RegisterProfileManagerCallback(OpenRGBDialogProfileManagerCallback, this);
/*-----------------------------------------------------*\
| Register dialog show callback with log manager |
\*-----------------------------------------------------*/
@@ -501,6 +522,15 @@ OpenRGBDialog::OpenRGBDialog(QWidget *parent) : QMainWindow(parent), ui(new Ui::
OpenRGBDialog::~OpenRGBDialog()
{
/*-----------------------------------------------------*\
| Unregister resource manager callbacks |
\*-----------------------------------------------------*/
ResourceManager::get()->UnregisterResourceManagerCallback(OpenRGBDialogResourceManagerCallback, this);
/*-----------------------------------------------------*\
| Unregister profile manager callbacks |
\*-----------------------------------------------------*/
ResourceManager::get()->GetProfileManager()->UnregisterProfileManagerCallback(OpenRGBDialogProfileManagerCallback, this);
delete ui;
}
@@ -1236,18 +1266,37 @@ void OpenRGBDialog::SetDialogMessage(PLogMessage msg)
dialog_message = QString::fromStdString(msg->buffer);
}
void OpenRGBDialog::UpdateActiveProfile()
{
ProfileManager* profile_manager = ResourceManager::get()->GetProfileManager();
int profile_index = ui->ProfileBox->findText(QString::fromStdString(profile_manager->GetActiveProfile()));
if(profile_index < 1)
{
profile_index = 0;
}
ui->ProfileBox->blockSignals(true);
ui->ProfileBox->setCurrentIndex(profile_index);
ui->ProfileBox->blockSignals(false);
}
void OpenRGBDialog::UpdateProfileList()
{
ProfileManager* profile_manager = ResourceManager::get()->GetProfileManager();
if(profile_manager != NULL)
{
ui->ProfileBox->blockSignals(true);
/*-------------------------------------------------*\
| Clear profile combo box and tray icon menu |
\*-------------------------------------------------*/
ui->ProfileBox->clear();
profileMenu->clear();
ui->ProfileBox->addItem("No Active Profile");
for(std::size_t profile_index = 0; profile_index < profile_manager->GetProfileList().size(); profile_index++)
{
/*---------------------------------------------*\
@@ -1263,8 +1312,12 @@ void OpenRGBDialog::UpdateProfileList()
connect(actionProfileSelected, SIGNAL(triggered()), this, SLOT(on_ProfileSelected()));
profileMenu->addAction(actionProfileSelected);
}
ui->ProfileBox->blockSignals(false);
}
UpdateActiveProfile();
emit ProfileListChanged();
}
@@ -1407,6 +1460,8 @@ void OpenRGBDialog::onDetectionEnded()
void OpenRGBDialog::on_SetAllDevices(unsigned char red, unsigned char green, unsigned char blue)
{
ResourceManager::get()->GetProfileManager()->ClearActiveProfile();
/*-----------------------------------------------------*\
| Send the about to load profile signal to plugins |
\*-----------------------------------------------------*/
@@ -1570,25 +1625,33 @@ void OpenRGBDialog::on_ProfileSelected()
\*-------------------------------------------------*/
profile_manager->LoadProfile(profile_name);
ui->ProfileBox->setCurrentIndex(ui->ProfileBox->findText(QString::fromStdString(profile_name)));
UpdateActiveProfile();
}
}
void OpenRGBDialog::on_ButtonLoadProfile_clicked()
void OpenRGBDialog::on_ProfileBox_currentIndexChanged(int index)
{
ProfileManager* profile_manager = ResourceManager::get()->GetProfileManager();
if(profile_manager != NULL)
{
/*-------------------------------------------------*\
| Get the profile filename from the profiles list |
\*-------------------------------------------------*/
std::string profile_name = ui->ProfileBox->currentText().toStdString();
if(index > 0)
{
/*---------------------------------------------*\
| Get the profile filename from the profiles |
| list |
\*---------------------------------------------*/
std::string profile_name = ui->ProfileBox->currentText().toStdString();
/*-------------------------------------------------*\
| Load the profile |
\*-------------------------------------------------*/
profile_manager->LoadProfile(profile_name);
/*---------------------------------------------*\
| Load the profile |
\*---------------------------------------------*/
profile_manager->LoadProfile(profile_name);
}
else
{
profile_manager->ClearActiveProfile();
}
}
}
@@ -1598,25 +1661,41 @@ void OpenRGBDialog::on_ButtonDeleteProfile_clicked()
if(profile_manager != NULL)
{
/*-------------------------------------------------*\
| Get the profile filename from the profiles list |
\*-------------------------------------------------*/
std::string profile_name = ui->ProfileBox->currentText().toStdString();
std::string profile_name = "";
/*-------------------------------------------------*\
| Confirm we want to delete the profile |
\*-------------------------------------------------*/
QMessageBox::StandardButton reply;
reply = QMessageBox::question(this, tr("Delete Profile"), tr("Do you really want to delete this profile?"), QMessageBox::Yes|QMessageBox::No);
/*-------------------------------------------------*\
| Load the profile |
\*-------------------------------------------------*/
if(reply == QMessageBox::Yes)
if(ui->ProfileBox->currentIndex() == 0)
{
profile_manager->DeleteProfile(profile_name);
OpenRGBProfileListDialog dialog(false);
UpdateProfileList();
/*---------------------------------------------*\
| Open Profile Name Dialog |
\*---------------------------------------------*/
profile_name = dialog.show();
}
else
{
/*---------------------------------------------*\
| Get the profile filename from the profiles |
| list |
\*---------------------------------------------*/
profile_name = ui->ProfileBox->currentText().toStdString();
}
if(profile_name != "")
{
/*---------------------------------------------*\
| Confirm we want to delete the profile |
\*---------------------------------------------*/
QMessageBox::StandardButton reply;
reply = QMessageBox::question(this, tr("Delete Profile"), tr("Do you really want to delete this profile?"), QMessageBox::Yes|QMessageBox::No);
/*---------------------------------------------*\
| Delete the profile |
\*---------------------------------------------*/
if(reply == QMessageBox::Yes)
{
profile_manager->DeleteProfile(profile_name);
}
}
}
}
@@ -1682,9 +1761,9 @@ void OpenRGBDialog::SetDetectionViewState(bool detection_showing)
| Show the detection progress and hide the normal |
| buttons |
\*-------------------------------------------------*/
ui->ActiveProfileLabel->setVisible(false);
ui->ButtonToggleDeviceView->setVisible(false);
ui->ButtonRescan->setVisible(false);
ui->ButtonLoadProfile->setVisible(false);
ui->ButtonSaveProfile->setVisible(false);
ui->ButtonDeleteProfile->setVisible(false);
ui->ProfileBox->setVisible(false);
@@ -1703,9 +1782,9 @@ void OpenRGBDialog::SetDetectionViewState(bool detection_showing)
ui->DetectionProgressLabel->setVisible(false);
ui->ButtonStopDetection->setVisible(false);
ui->ActiveProfileLabel->setVisible(true);
ui->ButtonToggleDeviceView->setVisible(true);
ui->ButtonRescan->setVisible(true);
ui->ButtonLoadProfile->setVisible(true);
ui->ButtonSaveProfile->setVisible(true);
ui->ButtonDeleteProfile->setVisible(true);
ui->ProfileBox->setVisible(true);
@@ -1748,7 +1827,7 @@ void OpenRGBDialog::SaveProfileAs()
if(profile_manager != NULL)
{
OpenRGBProfileSaveDialog dialog;
OpenRGBProfileListDialog dialog;
/*-------------------------------------------------*\
| Open Profile Name Dialog |
@@ -1765,12 +1844,7 @@ void OpenRGBDialog::SaveProfileAs()
/*---------------------------------------------*\
| Save the profile |
\*---------------------------------------------*/
if(profile_manager->SaveProfile(filename))
{
UpdateProfileList();
ui->ProfileBox->setCurrentIndex(ui->ProfileBox->findText(QString::fromStdString(profile_name)));
}
profile_manager->SaveProfile(filename);
}
}
}
@@ -1785,7 +1859,7 @@ void OpenRGBDialog::on_ButtonRescan_clicked()
void OpenRGBDialog::on_ActionSaveProfile_triggered()
{
if(ui->ProfileBox->currentIndex() >= 0)
if(ui->ProfileBox->currentIndex() > 0)
{
SaveProfile();
}

View File

@@ -128,7 +128,6 @@ private:
void ClearDevicesList();
void UpdateDevicesList();
void UpdateProfileList();
void closeEvent(QCloseEvent *event) override;
bool SelectConfigProfile(const std::string name);
@@ -164,7 +163,7 @@ private slots:
void onShowDialogMessage();
void on_ReShow(QSystemTrayIcon::ActivationReason reason);
void on_ProfileSelected();
void on_ButtonLoadProfile_clicked();
void on_ProfileBox_currentIndexChanged(int index);
void on_ButtonDeleteProfile_clicked();
void on_ButtonToggleDeviceView_clicked();
void on_ButtonStopDetection_clicked();
@@ -175,4 +174,7 @@ private slots:
void on_InformationTabBar_currentChanged(int);
void on_DevicesTabBar_currentChanged(int);
void on_SettingsTabBar_currentChanged(int);
void UpdateActiveProfile();
void UpdateProfileList();
};

View File

@@ -18,7 +18,7 @@
<item row="2" column="0" colspan="5">
<widget class="QTabWidget" name="MainTabBar">
<property name="tabShape">
<enum>QTabWidget::Rounded</enum>
<enum>QTabWidget::TabShape::Rounded</enum>
</property>
<property name="currentIndex">
<number>0</number>
@@ -37,7 +37,7 @@
<item row="1" column="0">
<widget class="QTabWidget" name="DevicesTabBar">
<property name="tabPosition">
<enum>QTabWidget::West</enum>
<enum>QTabWidget::TabPosition::West</enum>
</property>
</widget>
</item>
@@ -51,7 +51,7 @@
<item row="0" column="0">
<widget class="QTabWidget" name="InformationTabBar">
<property name="tabPosition">
<enum>QTabWidget::West</enum>
<enum>QTabWidget::TabPosition::West</enum>
</property>
<property name="currentIndex">
<number>-1</number>
@@ -68,7 +68,7 @@
<item row="0" column="0">
<widget class="QTabWidget" name="SettingsTabBar">
<property name="tabPosition">
<enum>QTabWidget::West</enum>
<enum>QTabWidget::TabPosition::West</enum>
</property>
<property name="currentIndex">
<number>-1</number>
@@ -84,10 +84,10 @@
<item>
<widget class="QFrame" name="MainButtonsFrame">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
<enum>QFrame::Shape::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
<enum>QFrame::Shadow::Raised</enum>
</property>
<layout class="QGridLayout" name="gridLayout_5">
<property name="leftMargin">
@@ -102,6 +102,20 @@
<property name="bottomMargin">
<number>0</number>
</property>
<item row="0" column="1">
<widget class="QPushButton" name="ButtonRescan">
<property name="text">
<string>Rescan Devices</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QPushButton" name="ButtonDeleteProfile">
<property name="text">
<string>Delete Profile</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QPushButton" name="ButtonToggleDeviceView">
<property name="text">
@@ -109,12 +123,8 @@
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="ButtonRescan">
<property name="text">
<string>Rescan Devices</string>
</property>
</widget>
<item row="0" column="5">
<widget class="QComboBox" name="ProfileBox"/>
</item>
<item row="0" column="2">
<widget class="QToolButton" name="ButtonSaveProfile">
@@ -128,27 +138,20 @@
<string>Save Profile</string>
</property>
<property name="popupMode">
<enum>QToolButton::MenuButtonPopup</enum>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QPushButton" name="ButtonDeleteProfile">
<property name="text">
<string>Delete Profile</string>
<enum>QToolButton::ToolButtonPopupMode::MenuButtonPopup</enum>
</property>
</widget>
</item>
<item row="0" column="4">
<widget class="QPushButton" name="ButtonLoadProfile">
<widget class="QLabel" name="ActiveProfileLabel">
<property name="text">
<string>Load Profile</string>
<string>Active Profile:</string>
</property>
<property name="alignment">
<set>Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="5">
<widget class="QComboBox" name="ProfileBox"/>
</item>
</layout>
</widget>
</item>
@@ -162,7 +165,7 @@
<string>OpenRGB is detecting devices...</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
<set>Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter</set>
</property>
</widget>
</item>

View File

@@ -0,0 +1,81 @@
/*---------------------------------------------------------*\
| OpenRGBProfileListDialog.cpp |
| |
| User interface entry for OpenRGB profile save dialog |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-or-later |
\*---------------------------------------------------------*/
#include <QCloseEvent>
#include "ResourceManager.h"
#include "OpenRGBDialog.h"
#include "ProfileManager.h"
#include "OpenRGBProfileListDialog.h"
#include "ui_OpenRGBProfileListDialog.h"
#ifdef _WIN32
#include <QSettings>
#endif
OpenRGBProfileListDialog::OpenRGBProfileListDialog(bool create, QWidget *parent) :
QDialog(parent), ui(new Ui::OpenRGBProfileListDialog)
{
ui->setupUi(this);
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
std::vector<std::string> profiles = ResourceManager::get()->GetProfileManager()->GetProfileList();
if(!create)
{
ui->new_label->setVisible(false);
ui->new_edit->setVisible(false);
}
if(profiles.empty())
{
ui->select_label->setVisible(false);
ui->select_list->setVisible(false);
}
else
{
for(const std::string& profile: profiles)
{
ui->select_list->addItem(QString::fromStdString(profile));
}
connect(ui->select_list, &QListWidget::currentItemChanged, [=](){
ui->new_edit->setText(ui->select_list->currentItem()->text());
});
}
}
OpenRGBProfileListDialog::~OpenRGBProfileListDialog()
{
delete ui;
}
void OpenRGBProfileListDialog::changeEvent(QEvent *event)
{
if(event->type() == QEvent::LanguageChange)
{
ui->retranslateUi(this);
}
}
std::string OpenRGBProfileListDialog::show()
{
std::string return_string;
int result = this->exec();
if(result == QDialog::Rejected)
{
return_string = "";
}
else
{
return_string = ui->new_edit->text().toStdString();
}
return(return_string);
}

View File

@@ -1,5 +1,5 @@
/*---------------------------------------------------------*\
| OpenRGBProfileSaveDialog.h |
| OpenRGBProfileListDialog.h |
| |
| User interface entry for OpenRGB profile save dialog |
| |
@@ -14,21 +14,21 @@
namespace Ui
{
class OpenRGBProfileSaveDialog;
class OpenRGBProfileListDialog;
}
class OpenRGBProfileSaveDialog : public QDialog
class OpenRGBProfileListDialog : public QDialog
{
Q_OBJECT
public:
explicit OpenRGBProfileSaveDialog(QWidget *parent = nullptr);
~OpenRGBProfileSaveDialog();
explicit OpenRGBProfileListDialog(bool create = true, QWidget *parent = nullptr);
~OpenRGBProfileListDialog();
std::string show();
private:
Ui::OpenRGBProfileSaveDialog *ui;
Ui::OpenRGBProfileListDialog *ui;
private slots:
void changeEvent(QEvent *event);

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>OpenRGBProfileSaveDialog</class>
<widget class="QDialog" name="OpenRGBProfileSaveDialog">
<class>OpenRGBProfileListDialog</class>
<widget class="QDialog" name="OpenRGBProfileListDialog">
<property name="geometry">
<rect>
<x>0</x>
@@ -17,28 +17,28 @@
</sizepolicy>
</property>
<property name="windowTitle">
<string>Profile Name</string>
<string>Profile Selection</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="existing">
<widget class="QLabel" name="select_label">
<property name="text">
<string>Save to an existing profile:</string>
<string>Select Profile:</string>
</property>
</widget>
</item>
<item>
<widget class="QListWidget" name="list_profile"/>
<widget class="QListWidget" name="select_list"/>
</item>
<item>
<widget class="QLabel" name="new_2">
<widget class="QLabel" name="new_label">
<property name="text">
<string>Create a new profile:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit"/>
<widget class="QLineEdit" name="new_edit"/>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
@@ -57,7 +57,7 @@
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>OpenRGBProfileSaveDialog</receiver>
<receiver>OpenRGBProfileListDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
@@ -73,7 +73,7 @@
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>OpenRGBProfileSaveDialog</receiver>
<receiver>OpenRGBProfileListDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">

View File

@@ -1,76 +0,0 @@
/*---------------------------------------------------------*\
| OpenRGBProfileSaveDialog.cpp |
| |
| User interface entry for OpenRGB profile save dialog |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-or-later |
\*---------------------------------------------------------*/
#include <QCloseEvent>
#include "ResourceManager.h"
#include "OpenRGBDialog.h"
#include "ProfileManager.h"
#include "OpenRGBProfileSaveDialog.h"
#include "ui_OpenRGBProfileSaveDialog.h"
#ifdef _WIN32
#include <QSettings>
#endif
OpenRGBProfileSaveDialog::OpenRGBProfileSaveDialog(QWidget *parent) :
QDialog(parent), ui(new Ui::OpenRGBProfileSaveDialog)
{
ui->setupUi(this);
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
std::vector<std::string> filenames = ResourceManager::get()->GetProfileManager()->GetProfileList();
if(filenames.empty())
{
ui->list_profile->setVisible(false);
ui->existing->setVisible(false);
}
else
{
for(const std::string& f: filenames)
{
ui->list_profile->addItem(QString::fromStdString(f));
}
connect(ui->list_profile, &QListWidget::currentItemChanged, [=](){
ui->lineEdit->setText(ui->list_profile->currentItem()->text());
});
}
}
OpenRGBProfileSaveDialog::~OpenRGBProfileSaveDialog()
{
delete ui;
}
void OpenRGBProfileSaveDialog::changeEvent(QEvent *event)
{
if(event->type() == QEvent::LanguageChange)
{
ui->retranslateUi(this);
}
}
std::string OpenRGBProfileSaveDialog::show()
{
std::string return_string;
int result = this->exec();
if(result == QDialog::Rejected)
{
return_string = "";
}
else
{
return_string = ui->lineEdit->text().toStdString();
}
return(return_string);
}

View File

@@ -996,7 +996,7 @@
</message>
</context>
<context>
<name>OpenRGBProfileSaveDialog</name>
<name>OpenRGBProfileListDialog</name>
<message>
<source>Profile Name</source>
<translation>Назва профілю</translation>

View File

@@ -997,7 +997,7 @@
</message>
</context>
<context>
<name>OpenRGBProfileSaveDialog</name>
<name>OpenRGBProfileListDialog</name>
<message>
<source>Profile Name</source>
<translation>Profil Name</translation>

View File

@@ -997,7 +997,7 @@
</message>
</context>
<context>
<name>OpenRGBProfileSaveDialog</name>
<name>OpenRGBProfileListDialog</name>
<message>
<source>Profile Name</source>
<translation>Όνομα προφίλ</translation>

View File

@@ -813,7 +813,7 @@
</message>
</context>
<context>
<name>OpenRGBProfileSaveDialog</name>
<name>OpenRGBProfileListDialog</name>
<message>
<source>Profile Name</source>
<translation></translation>

View File

@@ -813,7 +813,7 @@
</message>
</context>
<context>
<name>OpenRGBProfileSaveDialog</name>
<name>OpenRGBProfileListDialog</name>
<message>
<source>Profile Name</source>
<translation></translation>

View File

@@ -813,7 +813,7 @@
</message>
</context>
<context>
<name>OpenRGBProfileSaveDialog</name>
<name>OpenRGBProfileListDialog</name>
<message>
<source>Profile Name</source>
<translation type="unfinished"></translation>

View File

@@ -998,7 +998,7 @@
</message>
</context>
<context>
<name>OpenRGBProfileSaveDialog</name>
<name>OpenRGBProfileListDialog</name>
<message>
<source>Profile Name</source>
<translation>Nombre del perfil</translation>

View File

@@ -992,7 +992,7 @@
</message>
</context>
<context>
<name>OpenRGBProfileSaveDialog</name>
<name>OpenRGBProfileListDialog</name>
<message>
<source>Profile Name</source>
<translation>Nom du profil</translation>

View File

@@ -998,7 +998,7 @@
</message>
</context>
<context>
<name>OpenRGBProfileSaveDialog</name>
<name>OpenRGBProfileListDialog</name>
<message>
<source>Profile Name</source>
<translation>Naziv profila</translation>

View File

@@ -996,7 +996,7 @@
</message>
</context>
<context>
<name>OpenRGBProfileSaveDialog</name>
<name>OpenRGBProfileListDialog</name>
<message>
<source>Profile Name</source>
<translation>Nome Profilo</translation>

View File

@@ -996,7 +996,7 @@
</message>
</context>
<context>
<name>OpenRGBProfileSaveDialog</name>
<name>OpenRGBProfileListDialog</name>
<message>
<source>Profile Name</source>
<translation></translation>

View File

@@ -996,7 +996,7 @@
</message>
</context>
<context>
<name>OpenRGBProfileSaveDialog</name>
<name>OpenRGBProfileListDialog</name>
<message>
<source>Profile Name</source>
<translation> </translation>

View File

@@ -996,7 +996,7 @@
</message>
</context>
<context>
<name>OpenRGBProfileSaveDialog</name>
<name>OpenRGBProfileListDialog</name>
<message>
<source>Profile Name</source>
<translation>Nama profil</translation>

View File

@@ -996,7 +996,7 @@
</message>
</context>
<context>
<name>OpenRGBProfileSaveDialog</name>
<name>OpenRGBProfileListDialog</name>
<message>
<source>Profile Name</source>
<translation>Profilnavn</translation>

View File

@@ -996,7 +996,7 @@
</message>
</context>
<context>
<name>OpenRGBProfileSaveDialog</name>
<name>OpenRGBProfileListDialog</name>
<message>
<source>Profile Name</source>
<translation>Nazwa profilu</translation>

View File

@@ -996,7 +996,7 @@
</message>
</context>
<context>
<name>OpenRGBProfileSaveDialog</name>
<name>OpenRGBProfileListDialog</name>
<message>
<source>Profile Name</source>
<translation>Nome do perfil</translation>

View File

@@ -814,7 +814,7 @@
</message>
</context>
<context>
<name>OpenRGBProfileSaveDialog</name>
<name>OpenRGBProfileListDialog</name>
<message>
<source>Profile Name</source>
<translation>Название профиля</translation>

View File

@@ -813,7 +813,7 @@
</message>
</context>
<context>
<name>OpenRGBProfileSaveDialog</name>
<name>OpenRGBProfileListDialog</name>
<message>
<source>Profile Name</source>
<translation>Profil Adı</translation>

View File

@@ -996,7 +996,7 @@
</message>
</context>
<context>
<name>OpenRGBProfileSaveDialog</name>
<name>OpenRGBProfileListDialog</name>
<message>
<source>Profile Name</source>
<translation>Назва профілю</translation>

View File

@@ -996,7 +996,7 @@
</message>
</context>
<context>
<name>OpenRGBProfileSaveDialog</name>
<name>OpenRGBProfileListDialog</name>
<message>
<source>Profile Name</source>
<translation></translation>

View File

@@ -996,7 +996,7 @@
</message>
</context>
<context>
<name>OpenRGBProfileSaveDialog</name>
<name>OpenRGBProfileListDialog</name>
<message>
<source>Profile Name</source>
<translation></translation>