~aleteoryx/muditaos

ref: 7c687fca0d5b978720820d47bfc9c2a71cd8ce62 muditaos/module-apps/application-settings-new/windows/AddDeviceWindow.cpp -rw-r--r-- 1.8 KiB
7c687fca — Mateusz Grzegorzek [EGD-5776] Replace incorrect block contact icon with the correct one 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
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "AddDeviceWindow.hpp"
#include "application-settings-new/ApplicationSettings.hpp"
#include "application-settings-new/data/DeviceData.hpp"

#include "OptionSetting.hpp"

extern "C"
{
#include <module-bluetooth/lib/btstack/src/btstack_util.h>
}

namespace gui
{

    AddDeviceWindow::AddDeviceWindow(app::Application *app) : BaseSettingsWindow(app, window::name::add_device)
    {
        bluetoothSettingsModel = std::make_unique<BluetoothSettingsModel>(application);
    }

    void AddDeviceWindow::onBeforeShow(ShowMode /*mode*/, SwitchData *data)
    {
        const auto newData = dynamic_cast<DeviceData *>(data);
        if (newData != nullptr) {
            devices = newData->getDevices();
        }
        refreshOptionsList();
    }

    void AddDeviceWindow::onClose()
    {
        bluetoothSettingsModel->stopScan();
    }

    auto AddDeviceWindow::buildOptionsList() -> std::list<gui::Option>
    {
        std::list<gui::Option> optionsList;

        for (const auto &device : devices) {
            optionsList.emplace_back(std::make_unique<gui::option::OptionSettings>(
                device.name,
                [=](gui::Item & /*unused*/) {
                    LOG_DEBUG("Device: %s", device.name.c_str());
                    bluetoothSettingsModel->requestDevicePair(bd_addr_to_str(device.address));
                    application->switchWindow(gui::window::name::all_devices);
                    return true;
                },
                nullptr,
                nullptr,
                gui::option::SettingRightItem::Bt));
        }

        bottomBar->setText(BottomBar::Side::CENTER, utils::translate(style::strings::common::add));

        return optionsList;
    }
} // namespace gui