~aleteoryx/muditaos

ref: 0ef0d615f34e275f088890a1244dd480dd467920 muditaos/module-apps/application-settings-new/windows/AllDevicesWindow.cpp -rw-r--r-- 3.7 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
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "AllDevicesWindow.hpp"
#include "application-settings-new/ApplicationSettings.hpp"
#include "application-settings-new/widgets/SettingsStyle.hpp"

#include "OptionSetting.hpp"
#include "DialogMetadata.hpp"
#include "DialogMetadataMessage.hpp"

#include <InputEvent.hpp>
#include <module-utils/i18n/i18n.hpp>
#include <service-bluetooth/BluetoothMessage.hpp>

namespace gui
{

    AllDevicesWindow::AllDevicesWindow(app::Application *app) : OptionWindow(app, gui::window::name::all_devices)
    {
        setTitle(utils::localize.get("app_settings_bluetooth_all_devices"));
        addOptions(allDevicesOptionsList());
    }

    auto AllDevicesWindow::onInput(const InputEvent &inputEvent) -> bool
    {

        if (inputEvent.state == InputEvent::State::keyReleasedShort) {
            if (inputEvent.keyCode == KeyCode::KEY_LEFT) {
                sys::Bus::SendUnicast(std::make_shared<BluetoothMessage>(BluetoothMessage::Request::Scan),
                                      "ServiceBluetooth",
                                      application);
                gui::DialogMetadata meta;
                meta.icon                        = "search_big";
                meta.text                        = utils::localize.get("app_settings_bluetooth_searching_devices");
                meta.title                       = utils::localize.get("app_settings_bluetooth_add_device");
                auto data                        = std::make_unique<gui::DialogMetadataMessage>(meta);
                data->ignoreCurrentWindowOnStack = true;
                application->switchWindow(gui::window::name::dialog_settings, std::move(data));
                return true;
            }
        }

        return AppWindow::onInput(inputEvent);
    }

    auto AllDevicesWindow::allDevicesOptionsList() -> std::list<Option>
    {
        std::list<gui::Option> optionsList;

        std::vector<Devicei> devices{Devicei("Paired_device1"),
                                     Devicei("Paired_device2"),
                                     Devicei("Paired_device3"),
                                     Devicei("Paired_device4"),
                                     Devicei("Paired_device5")};

        for (const auto &device : devices) {
            optionsList.emplace_back(std::make_unique<gui::OptionSettings>(
                device.name,
                [=](gui::Item &item) {
                    LOG_DEBUG("Device: %s", device.name.c_str());
                    return true;
                },
                nullptr,
                nullptr,
                RightItem::Bt));
        }

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

        leftArrowImage = new gui::Image(this,
                                        style::settings::window::leftArrowImage::x,
                                        style::settings::window::leftArrowImage::y,
                                        style::settings::window::leftArrowImage::w,
                                        style::settings::window::leftArrowImage::h,
                                        "arrow_left");
        crossImage     = new gui::Image(this,
                                    style::settings::window::crossImage::x,
                                    style::settings::window::crossImage::y,
                                    style::settings::window::crossImage::w,
                                    style::settings::window::crossImage::h,
                                    "cross");

        return optionsList;
    }
} // namespace gui