~aleteoryx/muditaos

ref: 88a9fdedf22428cbfe52f91c8352eae52438e7f1 muditaos/module-apps/application-desktop/windows/UpdateProgress.cpp -rw-r--r-- 6.7 KiB
88a9fded — Kuba [EGD-6883] Change time settings cleanup 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
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include <log.hpp>
#include <source/version.hpp>
#include <boot/bootconfig.hpp>

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

#include <application-desktop/ApplicationDesktop.hpp>
#include <application-desktop/data/DesktopStyle.hpp>
#include <application-desktop/data/DesktopData.hpp>

// services
#include <service-appmgr/model/ApplicationManager.hpp>

#include <Style.hpp>
#include <DialogMetadataMessage.hpp>
#include "UpdateProgress.hpp"

namespace gui
{
    UpdateProgressWindow::UpdateProgressWindow(app::Application *app)
        : AppWindow(app, app::window::name::desktop_update_progress)
    {
        buildInterface();
        preventsAutoLock = true;
    }

    void UpdateProgressWindow::onBeforeShow(ShowMode mode, SwitchData *data)
    {
        if (data == nullptr) {
            LOG_ERROR("Received null pointer");
        }
        else {
            auto *item = dynamic_cast<gui::UpdateSwitchData *>(data);
            if (item != nullptr) {
                const auto &msg = item->getUpdateOsMessage();
                updateFile = msg.updateStats.updateFile;
                auto updateVersion =
                    msg.updateStats.versionInformation[boot::json::os_version][boot::json::version_string]
                        .string_value();
                if (text->getText().empty()) {
                    text->setText(utils::translate("app_desktop_update_preparing") + " " + updateVersion);
                }
                else {
                    text->setText(textInfo);
                }
            }
            percentLabel->setText(std::to_string(progressPercent) + " %");
            updateProgress->setPercentageValue(progressPercent);
        }
        setVisibleState();
    }

    bool UpdateProgressWindow::onInput(const InputEvent & /*inputEvent*/)
    {
        return true;
    }

    void UpdateProgressWindow::setVisibleState()
    {
        percentLabel->setVisible(true);
        updateProgress->setVisible(true);
        updateProgress->setVisible(true);
        text->setVisible(true);
    }

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

    status_bar::Configuration UpdateProgressWindow::configureStatusBar(status_bar::Configuration appConfiguration)
    {
        appConfiguration.enable(status_bar::Indicator::Time);
        appConfiguration.disable(status_bar::Indicator::Lock);
        appConfiguration.disable(status_bar::Indicator::Battery);
        appConfiguration.disable(status_bar::Indicator::Signal);
        appConfiguration.disable(status_bar::Indicator::SimCard);
        return appConfiguration;
    }

    void UpdateProgressWindow::buildInterface()
    {
        AppWindow::buildInterface();

        setTitle(utils::translate("app_desktop_update_muditaos"));

        icon = new Image(this, style::desktop::image::x, style::desktop::image::y, "circle_update");

        text = new Text(this,
                        style::desktop::textupdate::x,
                        style::desktop::textupdate::y,
                        style::desktop::textupdate::w,
                        style::desktop::textupdate::h);
        text->setTextType(TextType::MultiLine);
        text->setEditMode(EditMode::Browse);
        text->setEdges(RectangleEdge::None);
        text->setFont(style::window::font::biglight);
        text->setAlignment(gui::Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Center));

        percentLabel = new gui::Label(this,
                                      style::desktop::percentlabel::x,
                                      style::desktop::percentlabel::y,
                                      style::desktop::percentlabel::w,
                                      style::desktop::percentlabel::h);
        percentLabel->setFilled(false);
        percentLabel->setBorderColor(gui::ColorNoColor);
        percentLabel->setFont(style::window::font::biglight);
        percentLabel->setAlignment(
            gui::Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Center));

        updateProgress = new HBarGraph(this,
                                       style::window::progressBar::x,
                                       style::window::progressBar::y,
                                       style::window::progressBar::range,
                                       BarGraphStyle::Light);
        updateProgress->setSize(style::window::progressBar::w, style::window::progressBar::h);
        updateProgress->setAlignment(
            gui::Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Center));
    }

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

    void UpdateProgressWindow::invalidate() noexcept
    {
        percentLabel   = nullptr;
        updateProgress = nullptr;
        text           = nullptr;
        icon           = nullptr;
    }

    bool UpdateProgressWindow::handleSwitchData(SwitchData *data)
    {
        auto *item = dynamic_cast<gui::UpdateSwitchData *>(data);
        if (item != nullptr) {
            auto status = static_cast<updateos::UpdateState>(item->getUpdateOsMessage().updateStats.status);
            switch (status) {
            case updateos::UpdateState::Initial:
                textInfo        = text->getText();
                progressPercent = 10;
                break;
            case updateos::UpdateState::UpdateFileSet:
                textInfo        = text->getText();
                progressPercent = 20;
                break;
            case updateos::UpdateState::CreatingDirectories:
                textInfo        = text->getText();
                progressPercent = 30;
                break;
            case updateos::UpdateState::ExtractingFiles:
                textInfo        = utils::translate("app_desktop_update_in_progress");
                progressPercent = 40;
                break;
            case updateos::UpdateState::ChecksumVerification:
                textInfo        = text->getText();
                progressPercent = 70;
                break;
            case updateos::UpdateState::VersionVerificiation:
                textInfo        = text->getText();
                progressPercent = 80;
                break;
            case updateos::UpdateState::UpdatingBootloader:
                textInfo        = utils::translate("app_desktop_update_ready_for_reset");
                progressPercent = 99;
                break;
            case updateos::UpdateState::ReadyForReset:
                textInfo        = text->getText();
                progressPercent = 100;
                break;
            }
        }
        return true;
    }
} /* namespace gui */