~aleteoryx/muditaos

ref: c1c7c0771fc547a5d3b484842421f82ce0b5fd60 muditaos/module-apps/application-settings/windows/display-keypad/WallpaperWindow.cpp -rw-r--r-- 2.9 KiB
c1c7c077 — Lucjan Bryndza [MOS-98] Fix message regression functionality in drafts 3 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "WallpaperWindow.hpp"

#include <application-settings/windows/WindowNames.hpp>

#include <OptionSetting.hpp>

namespace gui
{

    namespace
    {
        const std::vector<std::pair<std::string, WallpaperOption>> wallpaperOptions = {
            {"app_settings_display_wallpaper_logo", WallpaperOption::Logo},
            {"app_settings_display_wallpaper_clock", WallpaperOption::Clock},
            {"app_settings_display_wallpaper_quotes", WallpaperOption::Quote}};
    } // namespace

    WallpaperWindow::WallpaperWindow(app::ApplicationCommon *app, app::settingsInterface::WallpaperSettings *settings)
        : BaseSettingsWindow(app, window::name::wallpaper), optionModel{
                                                                std::make_unique<WallpaperOptionModel>(settings)}
    {
        setTitle(utils::translate("app_settings_display_wallpaper"));
    }

    auto WallpaperWindow::buildOptionsList() -> std::list<gui::Option>
    {
        std::list<gui::Option> optionsList;

        for (const auto &[text, option] : wallpaperOptions) {
            optionsList.emplace_back(std::make_unique<gui::option::OptionSettings>(
                utils::translate(text),
                [&](gui::Item &item) mutable {
                    optionModel->saveValue(option);
                    refreshOptionsList();
                    return true;
                },
                [=](gui::Item &item) {
                    if (item.focus) {
                        this->setNavBarText(utils::translate(style::strings::common::Switch), nav_bar::Side::Center);
                    }
                    return true;
                },
                this,
                optionModel->isCurrentOption(option) ? gui::option::SettingRightItem::Checked
                                                     : gui::option::SettingRightItem::Disabled));
        }

        if (optionModel->isQuoteOptionSelected()) {
            optionsList.emplace_back(std::make_unique<gui::option::OptionSettings>(
                utils::translate("app_settings_display_wallpaper_edit_quotes"),
                [=](gui::Item &item) {
                    application->switchWindow(gui::window::name::edit_quotes, nullptr);
                    return true;
                },
                [=](gui::Item &item) {
                    if (item.focus) {
                        this->setNavBarText(utils::translate(style::strings::common::select), nav_bar::Side::Center);
                    }
                    return true;
                },
                this,
                gui::option::SettingRightItem::ArrowWhite,
                true));
        }

        return optionsList;
    }

    void WallpaperWindow::onBeforeShow(ShowMode mode, SwitchData *data)
    {
        optionModel->update();
        refreshOptionsList();
    }
} // namespace gui