mirror of
https://github.com/mudita/MuditaOS.git
synced 2026-02-06 20:33:00 -05:00
70 lines
2.2 KiB
C++
70 lines
2.2 KiB
C++
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
|
|
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
|
|
|
|
#include "PhoneNameWindow.hpp"
|
|
#include "application-settings-new/ApplicationSettings.hpp"
|
|
#include "application-settings-new/data/PhoneNameData.hpp"
|
|
#include "widgets/InputBox.hpp"
|
|
|
|
#include <Utils.hpp>
|
|
|
|
namespace gui
|
|
{
|
|
PhoneNameWindow::PhoneNameWindow(app::Application *app) : AppWindow(app, gui::window::name::phone_name)
|
|
{
|
|
bluetoothSettingsModel = std::make_unique<BluetoothSettingsModel>(application);
|
|
bluetoothSettingsModel->requestDeviceName();
|
|
buildInterface();
|
|
}
|
|
|
|
void PhoneNameWindow::buildInterface()
|
|
{
|
|
AppWindow::buildInterface();
|
|
|
|
setTitle(utils::localize.get("app_settings_bluetooth_phone_name"));
|
|
|
|
inputField = inputBox(this, utils::localize.get("app_settings_bluetooth_phone_name"));
|
|
bottomBar->setActive(BottomBar::Side::LEFT, false);
|
|
bottomBar->setActive(BottomBar::Side::CENTER, true);
|
|
bottomBar->setActive(BottomBar::Side::RIGHT, true);
|
|
|
|
bottomBar->setText(BottomBar::Side::CENTER, utils::localize.get(style::strings::common::save));
|
|
bottomBar->setText(BottomBar::Side::RIGHT, utils::localize.get(style::strings::common::back));
|
|
|
|
setFocusItem(inputField);
|
|
}
|
|
|
|
void PhoneNameWindow::destroyInterface()
|
|
{
|
|
AppWindow::destroyInterface();
|
|
erase(inputField);
|
|
inputField = nullptr;
|
|
}
|
|
|
|
void PhoneNameWindow::onBeforeShow(ShowMode /*mode*/, SwitchData *data)
|
|
{
|
|
inputField->clear();
|
|
if (const auto newData = dynamic_cast<PhoneNameData *>(data); data != nullptr) {
|
|
inputField->setText(newData->getName());
|
|
}
|
|
}
|
|
|
|
auto PhoneNameWindow::onInput(const InputEvent &inputEvent) -> bool
|
|
{
|
|
if (AppWindow::onInput(inputEvent)) {
|
|
return true;
|
|
}
|
|
|
|
if (!inputEvent.isShortPress()) {
|
|
return false;
|
|
}
|
|
|
|
if (inputEvent.is(gui::KeyCode::KEY_ENTER) && !inputField->isEmpty()) {
|
|
bluetoothSettingsModel->setDeviceName(inputField->getText());
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
} // namespace gui
|