From a4191fa4e8bc0bc31b87ca3686f6b67a5336d709 Mon Sep 17 00:00:00 2001 From: Adam Honse Date: Sun, 8 Feb 2026 00:08:47 -0600 Subject: [PATCH] [next] Active profile tracking --- NetworkClient.cpp | 36 +++-- NetworkClient.h | 26 +-- NetworkProtocol.h | 4 + NetworkServer.cpp | 99 ++++++++++++ NetworkServer.h | 8 +- ProfileManager.cpp | 115 +++++++++++--- ProfileManager.h | 35 +++++ ResourceManager.cpp | 8 + qt/OpenRGBDevicePage/OpenRGBDevicePage.cpp | 35 +++++ qt/OpenRGBDialog/OpenRGBDialog.cpp | 148 +++++++++++++----- qt/OpenRGBDialog/OpenRGBDialog.h | 6 +- qt/OpenRGBDialog/OpenRGBDialog.ui | 55 ++++--- .../OpenRGBProfileListDialog.cpp | 81 ++++++++++ .../OpenRGBProfileListDialog.h} | 12 +- .../OpenRGBProfileListDialog.ui} | 20 +-- .../OpenRGBProfileSaveDialog.cpp | 76 --------- qt/i18n/OpenRGB_be_BY.ts | 2 +- qt/i18n/OpenRGB_de_DE.ts | 2 +- qt/i18n/OpenRGB_el_GR.ts | 2 +- qt/i18n/OpenRGB_en_AU.ts | 2 +- qt/i18n/OpenRGB_en_GB.ts | 2 +- qt/i18n/OpenRGB_en_US.ts | 2 +- qt/i18n/OpenRGB_es_ES.ts | 2 +- qt/i18n/OpenRGB_fr_FR.ts | 2 +- qt/i18n/OpenRGB_hr_HR.ts | 2 +- qt/i18n/OpenRGB_it_IT.ts | 2 +- qt/i18n/OpenRGB_ja_JP.ts | 2 +- qt/i18n/OpenRGB_ko_KR.ts | 2 +- qt/i18n/OpenRGB_ms_MY.ts | 2 +- qt/i18n/OpenRGB_nb_NO.ts | 2 +- qt/i18n/OpenRGB_pl_PL.ts | 2 +- qt/i18n/OpenRGB_pt_BR.ts | 2 +- qt/i18n/OpenRGB_ru_RU.ts | 2 +- qt/i18n/OpenRGB_tr_TR.ts | 2 +- qt/i18n/OpenRGB_uk_UA.ts | 2 +- qt/i18n/OpenRGB_zh_CN.ts | 2 +- qt/i18n/OpenRGB_zh_TW.ts | 2 +- 37 files changed, 582 insertions(+), 224 deletions(-) create mode 100644 qt/OpenRGBProfileListDialog/OpenRGBProfileListDialog.cpp rename qt/{OpenRGBProfileSaveDialog/OpenRGBProfileSaveDialog.h => OpenRGBProfileListDialog/OpenRGBProfileListDialog.h} (67%) rename qt/{OpenRGBProfileSaveDialog/OpenRGBProfileSaveDialog.ui => OpenRGBProfileListDialog/OpenRGBProfileListDialog.ui} (78%) delete mode 100644 qt/OpenRGBProfileSaveDialog/OpenRGBProfileSaveDialog.cpp diff --git a/NetworkClient.cpp b/NetworkClient.cpp index 34c64f462..2743937e7 100644 --- a/NetworkClient.cpp +++ b/NetworkClient.cpp @@ -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 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) diff --git a/NetworkClient.h b/NetworkClient.h index 674d369ba..3c9a3fc37 100644 --- a/NetworkClient.h +++ b/NetworkClient.h @@ -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(); diff --git a/NetworkProtocol.h b/NetworkProtocol.h index c32947421..1561d78b1 100644 --- a/NetworkProtocol.h +++ b/NetworkProtocol.h @@ -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 | diff --git a/NetworkServer.cpp b/NetworkServer.cpp index f641c1b0e..3050fc78a 100644 --- a/NetworkServer.cpp +++ b/NetworkServer.cpp @@ -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; diff --git a/NetworkServer.h b/NetworkServer.h index 10c705d52..6bee8c399 100644 --- a/NetworkServer.h +++ b/NetworkServer.h @@ -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 | diff --git a/ProfileManager.cpp b/ProfileManager.cpp index 7e19f85dd..2e6aeefae 100644 --- a/ProfileManager.cpp +++ b/ProfileManager.cpp @@ -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); } diff --git a/ProfileManager.h b/ProfileManager.h index 16a76ed8d..ae4b7fbaa 100644 --- a/ProfileManager.h +++ b/ProfileManager.h @@ -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 ProfileManagerCallbacks; + std::vector ProfileManagerCallbackArgs; + std::mutex ProfileManagerCallbackMutex; + /*-----------------------------------------------------*\ | Private functions | \*-----------------------------------------------------*/ diff --git a/ResourceManager.cpp b/ResourceManager.cpp index a45d5c5b8..b2bb1f9fa 100644 --- a/ResourceManager.cpp +++ b/ResourceManager.cpp @@ -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; } } diff --git a/qt/OpenRGBDevicePage/OpenRGBDevicePage.cpp b/qt/OpenRGBDevicePage/OpenRGBDevicePage.cpp index 61be1bf0a..0dd32481a 100644 --- a/qt/OpenRGBDevicePage/OpenRGBDevicePage.cpp +++ b/qt/OpenRGBDevicePage/OpenRGBDevicePage.cpp @@ -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 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 | \*-----------------------------------------------------*/ diff --git a/qt/OpenRGBDialog/OpenRGBDialog.cpp b/qt/OpenRGBDialog/OpenRGBDialog.cpp index d279901ff..903ed3235 100644 --- a/qt/OpenRGBDialog/OpenRGBDialog.cpp +++ b/qt/OpenRGBDialog/OpenRGBDialog.cpp @@ -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(); } diff --git a/qt/OpenRGBDialog/OpenRGBDialog.h b/qt/OpenRGBDialog/OpenRGBDialog.h index 04844354e..2d6b2ae07 100644 --- a/qt/OpenRGBDialog/OpenRGBDialog.h +++ b/qt/OpenRGBDialog/OpenRGBDialog.h @@ -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(); }; diff --git a/qt/OpenRGBDialog/OpenRGBDialog.ui b/qt/OpenRGBDialog/OpenRGBDialog.ui index 1cbb28adb..1f995fac2 100644 --- a/qt/OpenRGBDialog/OpenRGBDialog.ui +++ b/qt/OpenRGBDialog/OpenRGBDialog.ui @@ -18,7 +18,7 @@ - QTabWidget::Rounded + QTabWidget::TabShape::Rounded 0 @@ -37,7 +37,7 @@ - QTabWidget::West + QTabWidget::TabPosition::West @@ -51,7 +51,7 @@ - QTabWidget::West + QTabWidget::TabPosition::West -1 @@ -68,7 +68,7 @@ - QTabWidget::West + QTabWidget::TabPosition::West -1 @@ -84,10 +84,10 @@ - QFrame::NoFrame + QFrame::Shape::NoFrame - QFrame::Raised + QFrame::Shadow::Raised @@ -102,6 +102,20 @@ 0 + + + + Rescan Devices + + + + + + + Delete Profile + + + @@ -109,12 +123,8 @@ - - - - Rescan Devices - - + + @@ -128,27 +138,20 @@ Save Profile - QToolButton::MenuButtonPopup - - - - - - - Delete Profile + QToolButton::ToolButtonPopupMode::MenuButtonPopup - + - Load Profile + Active Profile: + + + Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter - - - @@ -162,7 +165,7 @@ OpenRGB is detecting devices... - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter diff --git a/qt/OpenRGBProfileListDialog/OpenRGBProfileListDialog.cpp b/qt/OpenRGBProfileListDialog/OpenRGBProfileListDialog.cpp new file mode 100644 index 000000000..0626404b6 --- /dev/null +++ b/qt/OpenRGBProfileListDialog/OpenRGBProfileListDialog.cpp @@ -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 +#include "ResourceManager.h" +#include "OpenRGBDialog.h" +#include "ProfileManager.h" +#include "OpenRGBProfileListDialog.h" +#include "ui_OpenRGBProfileListDialog.h" + +#ifdef _WIN32 +#include +#endif + +OpenRGBProfileListDialog::OpenRGBProfileListDialog(bool create, QWidget *parent) : + QDialog(parent), ui(new Ui::OpenRGBProfileListDialog) +{ + ui->setupUi(this); + setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); + + std::vector 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); +} diff --git a/qt/OpenRGBProfileSaveDialog/OpenRGBProfileSaveDialog.h b/qt/OpenRGBProfileListDialog/OpenRGBProfileListDialog.h similarity index 67% rename from qt/OpenRGBProfileSaveDialog/OpenRGBProfileSaveDialog.h rename to qt/OpenRGBProfileListDialog/OpenRGBProfileListDialog.h index 766078d17..ab7d589ea 100644 --- a/qt/OpenRGBProfileSaveDialog/OpenRGBProfileSaveDialog.h +++ b/qt/OpenRGBProfileListDialog/OpenRGBProfileListDialog.h @@ -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); diff --git a/qt/OpenRGBProfileSaveDialog/OpenRGBProfileSaveDialog.ui b/qt/OpenRGBProfileListDialog/OpenRGBProfileListDialog.ui similarity index 78% rename from qt/OpenRGBProfileSaveDialog/OpenRGBProfileSaveDialog.ui rename to qt/OpenRGBProfileListDialog/OpenRGBProfileListDialog.ui index 7e27ffe06..c207a1a8b 100644 --- a/qt/OpenRGBProfileSaveDialog/OpenRGBProfileSaveDialog.ui +++ b/qt/OpenRGBProfileListDialog/OpenRGBProfileListDialog.ui @@ -1,7 +1,7 @@ - OpenRGBProfileSaveDialog - + OpenRGBProfileListDialog + 0 @@ -17,28 +17,28 @@ - Profile Name + Profile Selection - + - Save to an existing profile: + Select Profile: - + - + Create a new profile: - + @@ -57,7 +57,7 @@ buttonBox accepted() - OpenRGBProfileSaveDialog + OpenRGBProfileListDialog accept() @@ -73,7 +73,7 @@ buttonBox rejected() - OpenRGBProfileSaveDialog + OpenRGBProfileListDialog reject() diff --git a/qt/OpenRGBProfileSaveDialog/OpenRGBProfileSaveDialog.cpp b/qt/OpenRGBProfileSaveDialog/OpenRGBProfileSaveDialog.cpp deleted file mode 100644 index ec11b0b9b..000000000 --- a/qt/OpenRGBProfileSaveDialog/OpenRGBProfileSaveDialog.cpp +++ /dev/null @@ -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 -#include "ResourceManager.h" -#include "OpenRGBDialog.h" -#include "ProfileManager.h" -#include "OpenRGBProfileSaveDialog.h" -#include "ui_OpenRGBProfileSaveDialog.h" - -#ifdef _WIN32 -#include -#endif - -OpenRGBProfileSaveDialog::OpenRGBProfileSaveDialog(QWidget *parent) : - QDialog(parent), ui(new Ui::OpenRGBProfileSaveDialog) -{ - ui->setupUi(this); - setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); - - std::vector 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); -} diff --git a/qt/i18n/OpenRGB_be_BY.ts b/qt/i18n/OpenRGB_be_BY.ts index 20d58443f..43e4efc28 100644 --- a/qt/i18n/OpenRGB_be_BY.ts +++ b/qt/i18n/OpenRGB_be_BY.ts @@ -996,7 +996,7 @@ - OpenRGBProfileSaveDialog + OpenRGBProfileListDialog Profile Name Назва профілю diff --git a/qt/i18n/OpenRGB_de_DE.ts b/qt/i18n/OpenRGB_de_DE.ts index 69a1bb553..93a47669b 100644 --- a/qt/i18n/OpenRGB_de_DE.ts +++ b/qt/i18n/OpenRGB_de_DE.ts @@ -997,7 +997,7 @@ - OpenRGBProfileSaveDialog + OpenRGBProfileListDialog Profile Name Profil Name diff --git a/qt/i18n/OpenRGB_el_GR.ts b/qt/i18n/OpenRGB_el_GR.ts index d9e99c9ba..96f1b880a 100644 --- a/qt/i18n/OpenRGB_el_GR.ts +++ b/qt/i18n/OpenRGB_el_GR.ts @@ -997,7 +997,7 @@ - OpenRGBProfileSaveDialog + OpenRGBProfileListDialog Profile Name Όνομα προφίλ diff --git a/qt/i18n/OpenRGB_en_AU.ts b/qt/i18n/OpenRGB_en_AU.ts index 91f360818..b7cbb33a4 100644 --- a/qt/i18n/OpenRGB_en_AU.ts +++ b/qt/i18n/OpenRGB_en_AU.ts @@ -813,7 +813,7 @@ - OpenRGBProfileSaveDialog + OpenRGBProfileListDialog Profile Name diff --git a/qt/i18n/OpenRGB_en_GB.ts b/qt/i18n/OpenRGB_en_GB.ts index b66cb61c7..8fa190596 100644 --- a/qt/i18n/OpenRGB_en_GB.ts +++ b/qt/i18n/OpenRGB_en_GB.ts @@ -813,7 +813,7 @@ - OpenRGBProfileSaveDialog + OpenRGBProfileListDialog Profile Name diff --git a/qt/i18n/OpenRGB_en_US.ts b/qt/i18n/OpenRGB_en_US.ts index 119d5a98e..d9948d181 100644 --- a/qt/i18n/OpenRGB_en_US.ts +++ b/qt/i18n/OpenRGB_en_US.ts @@ -813,7 +813,7 @@ - OpenRGBProfileSaveDialog + OpenRGBProfileListDialog Profile Name diff --git a/qt/i18n/OpenRGB_es_ES.ts b/qt/i18n/OpenRGB_es_ES.ts index aa793982a..934fb10a2 100644 --- a/qt/i18n/OpenRGB_es_ES.ts +++ b/qt/i18n/OpenRGB_es_ES.ts @@ -998,7 +998,7 @@ - OpenRGBProfileSaveDialog + OpenRGBProfileListDialog Profile Name Nombre del perfil diff --git a/qt/i18n/OpenRGB_fr_FR.ts b/qt/i18n/OpenRGB_fr_FR.ts index 9c4296887..a8f69fbaa 100644 --- a/qt/i18n/OpenRGB_fr_FR.ts +++ b/qt/i18n/OpenRGB_fr_FR.ts @@ -992,7 +992,7 @@ - OpenRGBProfileSaveDialog + OpenRGBProfileListDialog Profile Name Nom du profil diff --git a/qt/i18n/OpenRGB_hr_HR.ts b/qt/i18n/OpenRGB_hr_HR.ts index 2db541762..aa0230a49 100644 --- a/qt/i18n/OpenRGB_hr_HR.ts +++ b/qt/i18n/OpenRGB_hr_HR.ts @@ -998,7 +998,7 @@ - OpenRGBProfileSaveDialog + OpenRGBProfileListDialog Profile Name Naziv profila diff --git a/qt/i18n/OpenRGB_it_IT.ts b/qt/i18n/OpenRGB_it_IT.ts index 998a53fd9..47b11ebf5 100644 --- a/qt/i18n/OpenRGB_it_IT.ts +++ b/qt/i18n/OpenRGB_it_IT.ts @@ -996,7 +996,7 @@ - OpenRGBProfileSaveDialog + OpenRGBProfileListDialog Profile Name Nome Profilo diff --git a/qt/i18n/OpenRGB_ja_JP.ts b/qt/i18n/OpenRGB_ja_JP.ts index 99c48c8ea..3039a8393 100644 --- a/qt/i18n/OpenRGB_ja_JP.ts +++ b/qt/i18n/OpenRGB_ja_JP.ts @@ -996,7 +996,7 @@ - OpenRGBProfileSaveDialog + OpenRGBProfileListDialog Profile Name プロファイル名 diff --git a/qt/i18n/OpenRGB_ko_KR.ts b/qt/i18n/OpenRGB_ko_KR.ts index b9ac4a5df..f7845a522 100644 --- a/qt/i18n/OpenRGB_ko_KR.ts +++ b/qt/i18n/OpenRGB_ko_KR.ts @@ -996,7 +996,7 @@ - OpenRGBProfileSaveDialog + OpenRGBProfileListDialog Profile Name 프로파일 이름 diff --git a/qt/i18n/OpenRGB_ms_MY.ts b/qt/i18n/OpenRGB_ms_MY.ts index 53853b974..bd0fe6223 100644 --- a/qt/i18n/OpenRGB_ms_MY.ts +++ b/qt/i18n/OpenRGB_ms_MY.ts @@ -996,7 +996,7 @@ - OpenRGBProfileSaveDialog + OpenRGBProfileListDialog Profile Name Nama profil diff --git a/qt/i18n/OpenRGB_nb_NO.ts b/qt/i18n/OpenRGB_nb_NO.ts index 5c9feba97..f632793e1 100644 --- a/qt/i18n/OpenRGB_nb_NO.ts +++ b/qt/i18n/OpenRGB_nb_NO.ts @@ -996,7 +996,7 @@ - OpenRGBProfileSaveDialog + OpenRGBProfileListDialog Profile Name Profilnavn diff --git a/qt/i18n/OpenRGB_pl_PL.ts b/qt/i18n/OpenRGB_pl_PL.ts index 0289180aa..6d5b93812 100644 --- a/qt/i18n/OpenRGB_pl_PL.ts +++ b/qt/i18n/OpenRGB_pl_PL.ts @@ -996,7 +996,7 @@ - OpenRGBProfileSaveDialog + OpenRGBProfileListDialog Profile Name Nazwa profilu diff --git a/qt/i18n/OpenRGB_pt_BR.ts b/qt/i18n/OpenRGB_pt_BR.ts index 10d9747c2..b57aecd97 100644 --- a/qt/i18n/OpenRGB_pt_BR.ts +++ b/qt/i18n/OpenRGB_pt_BR.ts @@ -996,7 +996,7 @@ - OpenRGBProfileSaveDialog + OpenRGBProfileListDialog Profile Name Nome do perfil diff --git a/qt/i18n/OpenRGB_ru_RU.ts b/qt/i18n/OpenRGB_ru_RU.ts index e6b37a359..577b952b2 100644 --- a/qt/i18n/OpenRGB_ru_RU.ts +++ b/qt/i18n/OpenRGB_ru_RU.ts @@ -814,7 +814,7 @@ - OpenRGBProfileSaveDialog + OpenRGBProfileListDialog Profile Name Название профиля diff --git a/qt/i18n/OpenRGB_tr_TR.ts b/qt/i18n/OpenRGB_tr_TR.ts index 6431bdd88..1a63c7c1b 100644 --- a/qt/i18n/OpenRGB_tr_TR.ts +++ b/qt/i18n/OpenRGB_tr_TR.ts @@ -813,7 +813,7 @@ - OpenRGBProfileSaveDialog + OpenRGBProfileListDialog Profile Name Profil Adı diff --git a/qt/i18n/OpenRGB_uk_UA.ts b/qt/i18n/OpenRGB_uk_UA.ts index e624227b5..c03ec842f 100644 --- a/qt/i18n/OpenRGB_uk_UA.ts +++ b/qt/i18n/OpenRGB_uk_UA.ts @@ -996,7 +996,7 @@ - OpenRGBProfileSaveDialog + OpenRGBProfileListDialog Profile Name Назва профілю diff --git a/qt/i18n/OpenRGB_zh_CN.ts b/qt/i18n/OpenRGB_zh_CN.ts index 42ef3f6e0..4f65e2846 100644 --- a/qt/i18n/OpenRGB_zh_CN.ts +++ b/qt/i18n/OpenRGB_zh_CN.ts @@ -996,7 +996,7 @@ - OpenRGBProfileSaveDialog + OpenRGBProfileListDialog Profile Name 配置文件名称 diff --git a/qt/i18n/OpenRGB_zh_TW.ts b/qt/i18n/OpenRGB_zh_TW.ts index da5006024..b1f3523ac 100644 --- a/qt/i18n/OpenRGB_zh_TW.ts +++ b/qt/i18n/OpenRGB_zh_TW.ts @@ -996,7 +996,7 @@ - OpenRGBProfileSaveDialog + OpenRGBProfileListDialog Profile Name 配置檔案名稱