~aleteoryx/muditaos

3fb041cb4175f1a9daa1b59a24d46b5cd2dd88a4 — Mateusz Grzegorzek 5 years ago cceb5b0
[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.
M image/assets/lang/English.json => image/assets/lang/English.json +1 -0
@@ 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",

M module-apps/application-settings-new/ApplicationSettings.cpp => module-apps/application-settings-new/ApplicationSettings.cpp +16 -0
@@ 34,6 34,7 @@
#include "windows/DateAndTimeMainWindow.hpp"
#include "windows/ChangeTimeZone.hpp"
#include "windows/ChangeDateAndTimeWindow.hpp"
#include <application-settings-new/models/QuotesRepository.hpp>

#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<QuotesModel>
        {
            auto repo = std::make_unique<QuotesJsonRepository>(settings::quotesPath);
            return std::make_unique<QuotesModel>(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<gui::DialogRetry>(app, name);
        });
        windowsFactory.attach(gui::window::name::quotes, [](Application *app, const std::string &name) {
            return std::make_unique<gui::QuotesMainWindow>(app, std::move(settings::getQuotesModel(app)));
        });
        windowsFactory.attach(gui::window::name::new_quote, [](Application *app, const std::string &name) {
            return std::make_unique<gui::QuoteAddEditWindow>(app, std::move(settings::getQuotesModel(app)));
        });
        windowsFactory.attach(gui::window::name::options_quote, [](Application *app, const std::string &name) {
            return std::make_unique<gui::QuotesOptionsWindow>(app, std::move(settings::getQuotesModel(app)));
        });
    }

    void ApplicationSettingsNew::destroyUserInterface()

M module-apps/application-settings-new/CMakeLists.txt => module-apps/application-settings-new/CMakeLists.txt +3 -0
@@ 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

M module-apps/application-settings-new/models/QuotesRepository.cpp => module-apps/application-settings-new/models/QuotesRepository.cpp +4 -4
@@ 48,7 48,7 @@ namespace app
        writeQuotes(repositoryPath);
    }

    void QuotesJsonRepository::writeQuotes(const fs::path &quotesFilename)
    void QuotesJsonRepository::writeQuotes(const std::filesystem::path &quotesFilename)
    {
        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 &quotesFilename)
    void QuotesJsonRepository::readQuotes(const std::filesystem::path &quotesFilename)
    {
        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<unsigned int>(length));
        auto buffer = std::make_unique<char[]>(length + 1);
        std::fread(buffer.get(), 1, length, file);
        return std::string(buffer.get());

M module-apps/application-settings-new/windows/WallpaperWindow.cpp => module-apps/application-settings-new/windows/WallpaperWindow.cpp +1 -1
@@ 43,7 43,7 @@ namespace gui

        if (isWallpaperQuotesSwitchOn) {
            optionsList.emplace_back(std::make_unique<gui::option::OptionSettings>(
                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;