~aleteoryx/muditaos

ref: 7fbaf735ed99f5b0d26adb686cfa6ed2bb4267d5 muditaos/module-apps/apps-common/windows/OptionWindow.cpp -rw-r--r-- 2.5 KiB
7fbaf735 — Przemyslaw Brudny [EGD-7813] Option Window titles localizations fix 4 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
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "OptionWindow.hpp"
#include <messages/OptionsWindow.hpp>

namespace gui
{
    OptionWindow::OptionWindow(app::ApplicationCommon *app, const std::string &name, const std::string &windowTitle)
        : AppWindow(app, name), OptionsList(std::make_shared<OptionsModel>(app)), windowTitle(windowTitle)
    {
        buildInterface();
    }

    OptionWindow::OptionWindow(app::ApplicationCommon *app,
                               const std::string &name,
                               std::list<Option> options,
                               const std::string &windowTitle)
        : AppWindow(app, name), OptionsList(std::make_shared<OptionsModel>(app), std::move(options)),
          windowTitle(windowTitle)
    {
        buildInterface();
    }

    void OptionWindow::rebuild()
    {
        recreateOptions();
    }

    void OptionWindow::buildInterface()
    {
        AppWindow::buildInterface();
        bottomBar->setActive(BottomBar::Side::CENTER, true);
        bottomBar->setActive(BottomBar::Side::RIGHT, true);
        bottomBar->setText(BottomBar::Side::CENTER, utils::translate(style::strings::common::select));
        bottomBar->setText(BottomBar::Side::RIGHT, utils::translate(style::strings::common::back));
        setTitle(windowTitle.empty() ? utils::translate("common_options_title") : windowTitle);

        optionsList = new gui::ListView(this,
                                        option::window::optionsListX,
                                        option::window::optionsListY,
                                        option::window::optionsListW,
                                        option::window::optionsListH,
                                        optionsModel,
                                        listview::ScrollBarType::None);

        optionsList->prepareRebuildCallback = [this]() { recreateOptions(); };

        optionsModel->createData(options);

        setFocusItem(optionsList);
    }

    void OptionWindow::onClose([[maybe_unused]] CloseReason reason)
    {
        if (optionsList != nullptr) {
            optionsList->onClose();
        }
    }

    void OptionWindow::onBeforeShow(ShowMode mode, SwitchData *data)
    {
        if (auto message = dynamic_cast<gui::OptionsWindowOptions *>(data)) {
            LOG_DEBUG("Options load!");
            options = message->takeOptions();
        }

        optionsList->rebuildList(listview::RebuildType::InPlace);
    }

} /* namespace gui */