~aleteoryx/muditaos

muditaos/module-apps/application-desktop/windows/MmiPullWindow.cpp -rw-r--r-- 3.5 KiB
a405cad6Aleteoryx trim readme 6 days 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
// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/blob/master/LICENSE.md

#include "DesktopInputWidget.hpp"
#include "Mmi.hpp"
#include "MmiPullWindow.hpp"
#include "Names.hpp"

#include <i18n/i18n.hpp>
#include <service-appmgr/data/MmiActionsParams.hpp>
#include <service-cellular/CellularServiceAPI.hpp>

#include <string>

using namespace gui;

// move to style
namespace style::desktop
{
    namespace text
    {
        constexpr std::uint32_t x = 30;
        constexpr std::uint32_t y = 120;
        constexpr std::uint32_t w = 440;
        constexpr std::uint32_t h = 320;
    } // namespace text

    namespace inputWidget
    {
        constexpr std::uint32_t x = 30;
        constexpr std::uint32_t y = 450;
        constexpr std::uint32_t w = 450;
        constexpr std::uint32_t h = 50;
    } // namespace inputWidget

} // namespace style::desktop

MmiPullWindow::MmiPullWindow(app::ApplicationCommon *app, const std::string &name) : gui::AppWindow(app, name)
{
    AppWindow::buildInterface();

    navBar->setText(nav_bar::Side::Center, utils::translate("app_desktop_replay"));
    navBar->setText(nav_bar::Side::Right, utils::translate(style::strings::common::back));
    text = new Text(
        this, style::desktop::text::x, style::desktop::text::y, style::desktop::text::w, style::desktop::text::h);
    text->setTextType(TextType::MultiLine);
    text->setEditMode(EditMode::Browse);
    text->setEdges(RectangleEdge::None);
    text->setFont(style::window::font::medium);
    text->setAlignment(gui::Alignment(gui::Alignment::Horizontal::Left, gui::Alignment::Vertical::Top));
    setTitle(utils::translate("app_desktop_info"));

    InputBox = new DesktopInputWidget(application,
                                      this,
                                      style::desktop::inputWidget::x,
                                      style::desktop::inputWidget::y,
                                      style::desktop::inputWidget::w,
                                      style::desktop::inputWidget::h);

    InputBox->inputText->setInputMode(new InputMode(
        {InputMode::digit, InputMode::Abc, InputMode::ABC, InputMode::abc},
        [=](const UTF8 &text1) { navBarTemporaryMode(text1); },
        [=]() { navBarRestoreFromTemporaryMode(); },
        [=]() { selectSpecialCharacter(); },
        [=](std::function<void()> restoreFunction) {
            application->getCurrentWindow()->startInputModeRestoreTimer(std::move(restoreFunction));
        }));

    addWidget(InputBox);
}

void MmiPullWindow::onBeforeShow(ShowMode mode, SwitchData *data)
{
    auto metadata = dynamic_cast<app::manager::actions::MMIParams *>(data);
    if (metadata != nullptr) {
        text->setText(mmi::removePhrase(metadata->getData(), "\r"));
    }
    InputBox->setVisible(true);
    setFocusItem(InputBox->inputText);
}

bool MmiPullWindow::onInput(const InputEvent &inputEvent)
{
    if (inputEvent.isShortRelease()) {
        switch (inputEvent.getKeyCode()) {
        case KeyCode::KEY_RF: {
            CellularServiceAPI::USSDRequest(this->application, cellular::USSDMessage::RequestType::abortSession, "");
            application->switchWindow(app::window::name::desktop_main_window);
            return true;
        }
        default:
            break;
        }
    }
    return AppWindow::onInput(inputEvent);
}

void MmiPullWindow::destroyInterface()
{
    erase();
}

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