// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "AllDevicesWindow.hpp" #include #include #include #include #include #include #include
namespace gui { AllDevicesWindow::AllDevicesWindow(app::ApplicationCommon *app, std::shared_ptr bluetoothSettingsModel) : BaseSettingsWindow(app, window::name::all_devices), bluetoothSettingsModel(bluetoothSettingsModel) { buildInterface(); } void AllDevicesWindow::buildInterface() { setTitle(utils::translate("app_settings_bluetooth_all_devices")); optionsList = new gui::ListView(this, option::window::optionsListX, option::window::optionsListY, option::window::optionsListW, option::window::optionsListH, optionsModel, listview::ScrollBarType::Proportional); optionsList->prepareRebuildCallback = [this]() { recreateOptions(); }; optionsModel->createData(options); setFocusItem(optionsList); header->navigationIndicatorAdd(new gui::header::AddElementAction(), gui::header::BoxSelection::Left); } void AllDevicesWindow::onBeforeShow(ShowMode mode, SwitchData *data) { if (mode == ShowMode::GUI_SHOW_RETURN) { bluetoothSettingsModel->stopScan(); } if (const auto bondedDevicesData = dynamic_cast(data); bondedDevicesData != nullptr) { bluetoothSettingsModel->replaceDevicesList(bondedDevicesData->getDevices()); } refreshOptionsList(); } auto AllDevicesWindow::onInput(const InputEvent &inputEvent) -> bool { if (!inputEvent.isShortRelease()) { return AppWindow::onInput(inputEvent); } if (inputEvent.is(KeyCode::KEY_LEFT)) { bluetoothSettingsModel->requestScan(); application->switchWindow(gui::window::name::dialog_settings, gui::ShowMode::GUI_SHOW_INIT, std::make_unique(gui::DialogMetadata{ utils::translate("app_settings_bluetooth_add_device"), "search_big", utils::translate("app_settings_bluetooth_searching_devices")})); return true; } if (inputEvent.is(KeyCode::KEY_LF)) { navBar->setActive(nav_bar::Side::Left, false); navBar->setActive(nav_bar::Side::Center, false); auto selectedDevice = bluetoothSettingsModel->getSelectedDevice(); if (selectedDevice.has_value()) { bluetoothSettingsModel->requestDeviceUnpair(selectedDevice.value().get()); } refreshOptionsList(); return true; } return AppWindow::onInput(inputEvent); } auto AllDevicesWindow::buildOptionsList() -> std::list