~aleteoryx/muditaos

ref: 0ef0d615f34e275f088890a1244dd480dd467920 muditaos/module-apps/application-settings/windows/FotaWindow.cpp -rw-r--r-- 3.6 KiB
0ef0d615 — Krzysztof Mozdzynski [EGD-4150] Change filename i18 to i18n (#1108) 5 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "FotaWindow.hpp"

#include "Fota.hpp"

#include <module-utils/i18n/i18n.hpp>

namespace gui
{

    FotaWindow::FotaWindow(app::Application *app) : AppWindow(app, window::name::fota_window)
    {
        buildInterface();
        fotaUpdater = std::make_unique<Fota>(this);
        currentFirmwareLabel->setText(fotaUpdater->getCurrentFirmwareVersion());
    }

    FotaWindow::~FotaWindow()
    {
        destroyInterface();
    }

    void FotaWindow::onBeforeShow(ShowMode /*mode*/, SwitchData * /*data*/)
    {}

    void FotaWindow::rebuild()
    {
        destroyInterface();
        buildInterface();
    }

    void FotaWindow::buildInterface()
    {
        LOG_INFO("Build Fota Window");
        AppWindow::buildInterface();
        setTitle("Modem Firmware update (FOTA)");

        topBar->setActive(TopBar::Elements::SIGNAL, true);
        topBar->setActive(TopBar::Elements::BATTERY, true);

        bottomBar->setActive(BottomBar::Side::CENTER, true);
        bottomBar->setActive(BottomBar::Side::RIGHT, true);
        bottomBar->setText(BottomBar::Side::CENTER, utils::localize.get("Go"));
        bottomBar->setText(BottomBar::Side::RIGHT, utils::localize.get("common_back"));

        mainBox = new gui::VBox(this, 0, title->offset_h(), style::window_width, style::window_height);
        mainBox->setPenWidth(style::window::default_border_no_focus_w);

        addBoxLabel(mainBox, "FOTA Status:");
        statusLabel = new Label(mainBox, 0, 0, style::window_width, style::window::label::default_h);
        statusLabel->setFocus(true);

        addBoxLabel(mainBox, "Current Firmware:");
        currentFirmwareLabel = new Label(mainBox, 0, 0, style::window_width, style::window::label::default_h);

        setFocusItem(statusLabel);

        newFirmwareLabelText = addBoxLabel(mainBox, "New Firmware:");
        newFirmwareLabel     = new Label(mainBox, 0, 0, style::window_width, style::window::label::default_h);
        newFirmwareLabel->setText("");

        const unsigned char progressLow(0);
        const unsigned char progressMax(100);
        downloadProgress = new ProgressBar(mainBox, 0, 0, style::window_width, style::window::label::default_h);
        downloadProgress->setMaximum(progressMax);
        downloadProgress->setValue(progressLow);

        statusLabel->activatedCallback = [&](Item &) -> bool {
            if (bottomBar->isActive(gui::BottomBar::Side::CENTER)) {
                fotaUpdater->next();
            }
            return true;
        };
        newFirmwareLabelText->setVisible(false);
        newFirmwareLabel->setVisible(false);
        downloadProgress->setVisible(false);
        getApplication()->refreshWindow(gui::RefreshModes::GUI_REFRESH_FAST);
    }

    void FotaWindow::destroyInterface()
    {
        erase();
        invalidate();
    }

    void FotaWindow::invalidate() noexcept
    {
        currentFirmwareLabel = nullptr;
        statusLabel          = nullptr;
        newFirmwareLabelText = nullptr;
        newFirmwareLabel     = nullptr;
        downloadProgress     = nullptr;
        mainBox              = nullptr;
    }

    BottomBar *FotaWindow::getBottomBar()
    {
        return bottomBar;
    }

    gui::Label *FotaWindow::addBoxLabel(BoxLayout *layout, const std::string &text)
    {
        auto el = new gui::Label(layout, 0, 0, style::window_width, style::window::label::default_h);
        style::window::decorateOption(el);
        el->setText(text);
        return el;
    }

} // namespace gui