~aleteoryx/muditaos

ref: d403db410172588d80e7f926cb63d29afc97b966 muditaos/module-apps/apps-common/popups/BluetoothInfoPopup.cpp -rw-r--r-- 2.8 KiB
d403db41 — Lefucjusz [MOS-1027] Fix lack of tethering icon on 'Tethering is on' popup 2 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
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "BluetoothInfoPopup.hpp"
#include "data/PopupRequestParams.hpp"

#include <service-appmgr/Controller.hpp>
#include <ApplicationCommon.hpp>
#include <i18n/i18n.hpp>

using namespace gui;

BluetoothInfoPopup::BluetoothInfoPopup(app::ApplicationCommon *app, const std::string &name)
    : WindowWithTimer(app, name)
{
    buildInterface();
}

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

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

    navBar->setText(nav_bar::Side::Center, utils::translate(style::strings::common::ok));

    infoIcon = new gui::Icon(this,
                             style::window::default_left_margin,
                             style::window::default_vertical_pos,
                             style::window::default_body_width,
                             style::window::default_body_height,
                             "",
                             utils::translate(""));
    infoIcon->setAlignment(Alignment::Horizontal::Center);
}

void BluetoothInfoPopup::onBeforeShow(ShowMode mode, SwitchData *data)
{
    auto infoData = dynamic_cast<BluetoothInfoParams *>(data);

    if (infoData == nullptr) {
        LOG_ERROR("No info data received");
        return;
    }

    if (infoData->isSucceed()) {
        infoIcon->image->set("success_128px_W_G");
        infoIcon->text->setRichText(utils::translate("bluetooth_info_popup_success"),
                                    {{"$DEVICE", std::string(infoData->getDevice().name.data())}});

        timerCallback = [this](Item &, sys::Timer &timer) {
            closePopups();
            return true;
        };
        resetTimer();
    }
    else {
        infoIcon->image->set("fail_128px_W_G");
        infoIcon->text->setRichText(utils::translate("bluetooth_info_popup_error"),
                                    {{"$DEVICE", std::string(infoData->getDevice().name.data())},
                                     {"$ERROR", std::string(infoData->getErrorCode())}});
    }
}

bool BluetoothInfoPopup::onInput(const InputEvent &inputEvent)
{
    if (inputEvent.isShortRelease(KeyCode::KEY_ENTER)) {
        closePopups();
        return true;
    }
    return false;
}

void BluetoothInfoPopup::closePopups()
{
    app::manager::Controller::sendAction(
        application,
        app::manager::actions::AbortPopup,
        std::make_unique<gui::PopupRequestParams>(gui::popup::ID::BluetoothAuthenticate));
    app::manager::Controller::sendAction(application,
                                         app::manager::actions::AbortPopup,
                                         std::make_unique<gui::PopupRequestParams>(gui::popup::ID::BluetoothInfo));
}