~aleteoryx/muditaos

ref: cb593f45c32f6a2d5f39489674ef60fa63a7f532 muditaos/module-apps/application-desktop/windows/SimLockBox.cpp -rw-r--r-- 5.2 KiB
cb593f45 — Michał Kamoń [EGD-4367] sim passcodes flow implementation (#1033) 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
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
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "SimLockBox.hpp"

#include "PinLockBaseWindow.hpp"
#include "application-desktop/widgets/PinLock.hpp"
#include "application-desktop/data/AppDesktopStyle.hpp"
#include "gui/widgets/Label.hpp"
#include "RichTextParser.hpp"
#include "FontManager.hpp"

#include <i18/i18.hpp>
#include <Style.hpp>

namespace lock_style = style::window::pin_lock;

namespace gui
{

    void SimLockBox::popChar(unsigned int charNum)
    {
        rebuildPinLabels(charNum);
    }
    void SimLockBox::putChar(unsigned int charNum)
    {
        rebuildPinLabels(++charNum);
    }

    void SimLockBox::buildLockBox(unsigned int pinSize)
    {
        LockWindow->buildImages("pin_lock", "pin_lock_info");
        LockWindow->buildInfoText(lock_style::info_text_h_sim);
        buildPinLabels(0);
    }
    void SimLockBox::buildPinLabels(unsigned int pinSize)
    {
        auto itemBuilder = []() {
            auto label = new gui::Image("dot_12px_hard_alpha_W_G");
            return label;
        };

        LockWindow->buildPinLabels(itemBuilder,
                                   pinSize,
                                   lock_style::pin_label_x,
                                   lock_style::pin_label_y,
                                   style::window_width - 2 * lock_style::pin_label_x);
        LockWindow->pinLabelsBox->setEdges(RectangleEdge::Bottom);
    }

    void SimLockBox::rebuildPinLabels(unsigned int pinSize)
    {
        LockWindow->pinLabelsBox->erase();
        buildPinLabels(pinSize);
    }

    void SimLockBox::setVisibleStateEnterPin(EnterPasscodeType type)
    {
        LockWindow->pinLabelsBox->setVisible(true);
        LockWindow->infoText->clear();

        switch (type) {
        case PinLockBox::EnterPasscodeType::ProvidePasscode:
            LockWindow->infoText->addText(utils::localize.get("app_desktop_sim_to_unlock"));
            LockWindow->infoText->addText(utils::localize.get("app_desktop_sim_card"));
            LockWindow->infoText->addText(utils::localize.get("app_desktop_sim_type_pin"));
            break;
        case PinLockBox::EnterPasscodeType::ProvideNewPasscode:
            LockWindow->infoText->addText(utils::localize.get("app_desktop_sim_enter_pin"));
            break;
        case PinLockBox::EnterPasscodeType::ConfirmNewPasscode:
            LockWindow->infoText->addText(utils::localize.get("app_desktop_sim_confirm_pin"));
            break;
        }
        LockWindow->infoText->setVisible(true);

        LockWindow->setImagesVisible(true, false);
        LockWindow->setBottomBarWidgetsActive(false, false, true);
    }
    void SimLockBox::setVisibleStateVerifiedPin()
    {
        LockWindow->infoText->clear();
        LockWindow->infoText->setVisible(false);
        LockWindow->pinLabelsBox->setVisible(false);
    }
    void SimLockBox::setVisibleStateInvalidPin(PasscodeErrorType type, unsigned int value)
    {
        LockWindow->pinLabelsBox->setVisible(false);

        LockWindow->infoText->clear();

        switch (type) {
        case PinLockBox::PasscodeErrorType::InvalidPasscode:
            LockWindow->infoText->addText(utils::localize.get(utils::localize.get("app_desktop_sim_wrong_pin")));
            LockWindow->infoText->addText("\n");
            LockWindow->infoText->addText(utils::localize.get(utils::localize.get("app_desktop_sim_you_have")));
            LockWindow->infoText->addText(" ");
            LockWindow->infoText->addText(std::to_string(value));
            LockWindow->infoText->addText(" ");
            if (value > 1) {
                LockWindow->infoText->addText(utils::localize.get("app_desktop_sim_attempt_left_plural"));
            }
            else {
                LockWindow->infoText->addText(utils::localize.get("app_desktop_sim_attempt_left_singular"));
            }
            LockWindow->infoText->setVisible(true);

            LockWindow->setImagesVisible(false, true);
            LockWindow->setBottomBarWidgetsActive(true, true, true);
            break;
        case PinLockBox::PasscodeErrorType::NewPasscodeConfirmFailed:
            LockWindow->infoText->setText(utils::localize.get("app_desktop_sim_wrong_pin"));
            break;
        case PinLockBox::PasscodeErrorType::UnhandledError: {
            TextFormat format(FontManager::getInstance().getFont(style::window::font::medium));
            text::RichTextParser rtParser;
            auto parsedText = rtParser.parse(utils::localize.get("app_desktop_sim_cme_error"), &format);
            LockWindow->infoText->setText(std::move(parsedText));
            LockWindow->infoText->addText(std::to_string(value));
            break;
        }
        }
    }
    void SimLockBox::setVisibleStateBlocked()
    {
        LockWindow->pinLabelsBox->setVisible(false);
        LockWindow->infoText->clear();
        LockWindow->infoText->addText(utils::localize.get(utils::localize.get("app_desktop_puk_lock1")));
        LockWindow->infoText->setVisible(true);

        LockWindow->setImagesVisible(false, true);
        LockWindow->setBottomBarWidgetsActive(true, true, true);
    }

    void SimLockBox::clear()
    {
        rebuildPinLabels(0);
    }
} // namespace gui