From 671d7242413a7f710d9e1c9a0e583508e382f139 Mon Sep 17 00:00:00 2001 From: emeric Date: Sat, 6 Aug 2022 14:58:26 +0200 Subject: [PATCH] Share message strings across sessions --- src/lms/ui/LmsApplication.cpp | 79 +++++++++++++++++++++++------------ src/lms/ui/LmsApplication.hpp | 1 + 2 files changed, 54 insertions(+), 26 deletions(-) diff --git a/src/lms/ui/LmsApplication.cpp b/src/lms/ui/LmsApplication.cpp index 9fd4527a..b724204f 100644 --- a/src/lms/ui/LmsApplication.cpp +++ b/src/lms/ui/LmsApplication.cpp @@ -64,6 +64,48 @@ namespace UserInterface { +static +std::shared_ptr +createMessageResourceBundle() +{ + const std::string appRoot {Wt::WApplication::appRoot()}; + + auto res {std::make_shared()}; + res->use(appRoot + "admin-database"); + res->use(appRoot + "admin-initwizard"); + res->use(appRoot + "admin-scannercontroller"); + res->use(appRoot + "admin-user"); + res->use(appRoot + "admin-users"); + res->use(appRoot + "artist"); + res->use(appRoot + "artists"); + res->use(appRoot + "error"); + res->use(appRoot + "explore"); + res->use(appRoot + "login"); + res->use(appRoot + "main"); + res->use(appRoot + "mediaplayer"); + res->use(appRoot + "messages"); + res->use(appRoot + "misc"); + res->use(appRoot + "notifications"); + res->use(appRoot + "playqueue"); + res->use(appRoot + "release"); + res->use(appRoot + "releases"); + res->use(appRoot + "search"); + res->use(appRoot + "settings"); + res->use(appRoot + "tracklist"); + res->use(appRoot + "tracklists"); + res->use(appRoot + "tracks"); + + return res; +} + +static +std::shared_ptr +getOrCreateMessageBundle() +{ + static std::shared_ptr res {createMessageResourceBundle()}; + return res; +} + static constexpr const char* defaultPath {"/releases"}; std::unique_ptr @@ -169,32 +211,8 @@ LmsApplication::init() useStyleSheet("resources/font-awesome/css/font-awesome.min.css"); require("js/mediaplayer.js"); - setTitle("LMS"); - - // Add a resource bundle - messageResourceBundle().use(appRoot() + "admin-database"); - messageResourceBundle().use(appRoot() + "admin-initwizard"); - messageResourceBundle().use(appRoot() + "admin-scannercontroller"); - messageResourceBundle().use(appRoot() + "admin-user"); - messageResourceBundle().use(appRoot() + "admin-users"); - messageResourceBundle().use(appRoot() + "artist"); - messageResourceBundle().use(appRoot() + "artists"); - messageResourceBundle().use(appRoot() + "error"); - messageResourceBundle().use(appRoot() + "explore"); - messageResourceBundle().use(appRoot() + "login"); - messageResourceBundle().use(appRoot() + "main"); - messageResourceBundle().use(appRoot() + "mediaplayer"); - messageResourceBundle().use(appRoot() + "messages"); - messageResourceBundle().use(appRoot() + "misc"); - messageResourceBundle().use(appRoot() + "notifications"); - messageResourceBundle().use(appRoot() + "playqueue"); - messageResourceBundle().use(appRoot() + "release"); - messageResourceBundle().use(appRoot() + "releases"); - messageResourceBundle().use(appRoot() + "search"); - messageResourceBundle().use(appRoot() + "settings"); - messageResourceBundle().use(appRoot() + "tracklist"); - messageResourceBundle().use(appRoot() + "tracklists"); - messageResourceBundle().use(appRoot() + "tracks"); + setTitle(); + setLocalizedStrings(getOrCreateMessageBundle()); // Handle Media Scanner events and other session events enableUpdates(true); @@ -599,6 +617,15 @@ LmsApplication::post(std::function func) Wt::WServer::instance()->post(LmsApp->sessionId(), std::move(func)); } +void +LmsApplication::setTitle(const Wt::WString& title) +{ + if (title.empty()) + WApplication::setTitle("LMS"); + else + WApplication::setTitle(title + " | LMS"); +} + void LmsApplication::notifyMsg(Notification::Type type, const Wt::WString& category, const Wt::WString& message, std::chrono::milliseconds duration) { diff --git a/src/lms/ui/LmsApplication.hpp b/src/lms/ui/LmsApplication.hpp index 17619d40..35a58747 100644 --- a/src/lms/ui/LmsApplication.hpp +++ b/src/lms/ui/LmsApplication.hpp @@ -75,6 +75,7 @@ class LmsApplication : public Wt::WApplication // Utils void post(std::function func); + void setTitle(const Wt::WString& title = ""); // Used to classify the message sent to the user void notifyMsg(Notification::Type type, const Wt::WString& category, const Wt::WString& message, std::chrono::milliseconds duration = std::chrono::milliseconds {5000});