From 3fb041cb4175f1a9daa1b59a24d46b5cd2dd88a4 Mon Sep 17 00:00:00 2001 From: Mateusz Grzegorzek Date: Fri, 26 Feb 2021 09:57:24 +0100 Subject: [PATCH] [EGD-5899] Restore Quotes Windows Due to mistakes probably during rebase Quotes Windows weren't correctly merged by this PR: https://github.com/mudita/MuditaOS/pull/1252 This PR fixes it. --- image/assets/lang/English.json | 1 + .../ApplicationSettings.cpp | 16 ++++++++++++++++ .../application-settings-new/CMakeLists.txt | 3 +++ .../models/QuotesRepository.cpp | 8 ++++---- .../windows/WallpaperWindow.cpp | 2 +- 5 files changed, 25 insertions(+), 5 deletions(-) diff --git a/image/assets/lang/English.json b/image/assets/lang/English.json index 28db5d9c5200d0867edf75247922556186564c94..c6217eed6b35f7f2f5accbafcb18b269c91c9301 100644 --- a/image/assets/lang/English.json +++ b/image/assets/lang/English.json @@ -344,6 +344,7 @@ "app_settings_display_wallpaper_logo": "Mudita logo", "app_settings_display_wallpaper_clock": "Clock", "app_settings_display_wallpaper_quotes": "Quotes", + "app_settings_display_wallpaper_edit_quotes": "Edit quotes", "app_settings_display_wallpaper_quotes_options": "Options", "app_settings_display_wallpaper_quotes_edit": "Edit quote", "app_settings_display_wallpaper_quotes_delete": "Delete quote", diff --git a/module-apps/application-settings-new/ApplicationSettings.cpp b/module-apps/application-settings-new/ApplicationSettings.cpp index 1ae309c68a117b8a6c84041f7cb23f274cf768b8..6c2fb806f12151c69830cf728286a56ac85037b6 100644 --- a/module-apps/application-settings-new/ApplicationSettings.cpp +++ b/module-apps/application-settings-new/ApplicationSettings.cpp @@ -34,6 +34,7 @@ #include "windows/DateAndTimeMainWindow.hpp" #include "windows/ChangeTimeZone.hpp" #include "windows/ChangeDateAndTimeWindow.hpp" +#include #include "Dialog.hpp" #include "DialogMetadataMessage.hpp" @@ -74,6 +75,12 @@ namespace app constexpr inline auto operators_on = "operators_on"; const std::string quotesPath = purefs::createPath(purefs::dir::getUserDiskPath(), "data/applications/settings/quotes.json"); + + auto getQuotesModel(Application *app) -> std::unique_ptr + { + auto repo = std::make_unique(settings::quotesPath); + return std::make_unique(app, std::move(repo)); + } } // namespace settings ApplicationSettingsNew::ApplicationSettingsNew(std::string name, @@ -394,6 +401,15 @@ namespace app windowsFactory.attach(gui::window::name::dialog_retry, [](Application *app, const std::string &name) { return std::make_unique(app, name); }); + windowsFactory.attach(gui::window::name::quotes, [](Application *app, const std::string &name) { + return std::make_unique(app, std::move(settings::getQuotesModel(app))); + }); + windowsFactory.attach(gui::window::name::new_quote, [](Application *app, const std::string &name) { + return std::make_unique(app, std::move(settings::getQuotesModel(app))); + }); + windowsFactory.attach(gui::window::name::options_quote, [](Application *app, const std::string &name) { + return std::make_unique(app, std::move(settings::getQuotesModel(app))); + }); } void ApplicationSettingsNew::destroyUserInterface() diff --git a/module-apps/application-settings-new/CMakeLists.txt b/module-apps/application-settings-new/CMakeLists.txt index e679e5ea825dce3177c0049dbe7d3ba103213ab8..5a2f22ad846153b9fa211db95190ee0a13125c8a 100644 --- a/module-apps/application-settings-new/CMakeLists.txt +++ b/module-apps/application-settings-new/CMakeLists.txt @@ -20,6 +20,8 @@ target_sources( ${PROJECT_NAME} models/NewApnModel.cpp models/DateAndTimeModel.cpp models/FromTimeToTimeModel.cpp + models/QuotesModel.cpp + models/QuotesRepository.cpp widgets/ChangePasscodeLockHandler.cpp widgets/QuoteWidget.cpp widgets/ApnInputWidget.cpp @@ -48,6 +50,7 @@ target_sources( ${PROJECT_NAME} windows/WallpaperWindow.cpp windows/QuotesMainWindow.cpp windows/QuotesAddWindow.cpp + windows/QuotesOptionsWindow.cpp windows/SecurityMainWindow.cpp windows/ChangePasscodeWindow.cpp windows/NewApnWindow.cpp diff --git a/module-apps/application-settings-new/models/QuotesRepository.cpp b/module-apps/application-settings-new/models/QuotesRepository.cpp index 4c0726413fb2b631434cf2a83d73906fb218d1c0..2259736163336a4a528908c5c517edd3656a365d 100644 --- a/module-apps/application-settings-new/models/QuotesRepository.cpp +++ b/module-apps/application-settings-new/models/QuotesRepository.cpp @@ -48,7 +48,7 @@ namespace app writeQuotes(repositoryPath); } - void QuotesJsonRepository::writeQuotes(const fs::path "esFilename) + void QuotesJsonRepository::writeQuotes(const std::filesystem::path "esFilename) { if (auto file = std::fopen(repositoryPath.c_str(), "w"); file != nullptr) { auto _ = gsl::finally([file] { std::fclose(file); }); @@ -58,7 +58,7 @@ namespace app } } - void QuotesJsonRepository::readQuotes(const fs::path "esFilename) + void QuotesJsonRepository::readQuotes(const std::filesystem::path "esFilename) { std::string err; @@ -78,7 +78,7 @@ namespace app }); } - auto QuotesJsonRepository::readFileToString(const fs::path &filename) -> std::string + auto QuotesJsonRepository::readFileToString(const std::filesystem::path &filename) -> std::string { constexpr auto tar_buf = 8192 * 4; auto file = std::fopen(filename.c_str(), "r"); @@ -92,7 +92,7 @@ namespace app LOG_ERROR("File %s length is too high!", filename.c_str()); return {}; } - LOG_INFO("file length: %ld", length); + LOG_INFO("file length: %u", static_cast(length)); auto buffer = std::make_unique(length + 1); std::fread(buffer.get(), 1, length, file); return std::string(buffer.get()); diff --git a/module-apps/application-settings-new/windows/WallpaperWindow.cpp b/module-apps/application-settings-new/windows/WallpaperWindow.cpp index af285b2e2a13466a963b2e86e799465a034caae3..d668a147430053eb9ef0fae5d4bbe511da3f5c22 100644 --- a/module-apps/application-settings-new/windows/WallpaperWindow.cpp +++ b/module-apps/application-settings-new/windows/WallpaperWindow.cpp @@ -43,7 +43,7 @@ namespace gui if (isWallpaperQuotesSwitchOn) { optionsList.emplace_back(std::make_unique( - utils::translateI18("app_settings_display_wallpaper_select_quotes"), + utils::translateI18("app_settings_display_wallpaper_edit_quotes"), [=](gui::Item &item) { application->switchWindow(gui::window::name::quotes, nullptr); return true;