M module-apps/application-settings-new/ApplicationSettings.cpp => module-apps/application-settings-new/ApplicationSettings.cpp +10 -8
@@ 107,14 107,6 @@ namespace app
currentWindow->rebuild();
}
}
- else if (auto responseStatusMsg = dynamic_cast<::message::bluetooth::ResponseStatus *>(msgl);
- nullptr != responseStatusMsg) {
- if (gui::window::name::bluetooth == getCurrentWindow()->getName()) {
- const auto status = responseStatusMsg->getStatus();
- auto btStatusData = std::make_unique<gui::BluetoothStatusData>(status.state, status.visibility);
- switchWindow(gui::window::name::bluetooth, std::move(btStatusData));
- }
- }
return sys::MessageNone{};
}
@@ 129,6 121,16 @@ namespace app
return ret;
}
+ connect(typeid(::message::bluetooth::ResponseStatus), [&](sys::Message *msg) {
+ auto responseStatusMsg = static_cast<::message::bluetooth::ResponseStatus *>(msg);
+ if (gui::window::name::bluetooth == getCurrentWindow()->getName()) {
+ const auto status = responseStatusMsg->getStatus();
+ auto btStatusData = std::make_unique<gui::BluetoothStatusData>(status.state, status.visibility);
+ switchWindow(gui::window::name::bluetooth, std::move(btStatusData));
+ }
+ return sys::MessageNone{};
+ });
+
connect(typeid(::message::bluetooth::ResponseDeviceName), [&](sys::Message *msg) {
auto responseDeviceNameMsg = static_cast<::message::bluetooth::ResponseDeviceName *>(msg);
if (gui::window::name::phone_name == getCurrentWindow()->getName()) {
M module-apps/application-settings-new/models/BluetoothSettingsModel.cpp => module-apps/application-settings-new/models/BluetoothSettingsModel.cpp +29 -1
@@ 4,8 4,11 @@
#include "BluetoothSettingsModel.hpp"
#include <Constants.hpp>
+#include <service-bluetooth/messages/BondedDevices.hpp>
+#include <service-bluetooth/messages/DeviceName.hpp>
#include <service-bluetooth/messages/Status.hpp>
#include <service-bluetooth/messages/SetStatus.hpp>
+#include <service-bluetooth/messages/SetDeviceName.hpp>
BluetoothSettingsModel::BluetoothSettingsModel(app::Application *application) : application{application}
{}
@@ 14,7 17,8 @@ void BluetoothSettingsModel::requestStatus()
{
application->bus.sendUnicast(std::make_shared<::message::bluetooth::RequestStatus>(), service::name::bluetooth);
}
-void BluetoothSettingsModel::setStatus(bool desiredBluetoothState, bool desiredVisibility)
+
+void BluetoothSettingsModel::setStatus(const bool desiredBluetoothState, const bool desiredVisibility)
{
BluetoothStatus status{.state = desiredBluetoothState ? BluetoothStatus::State::On : BluetoothStatus::State::Off,
.visibility = desiredVisibility};
@@ 22,6 26,30 @@ void BluetoothSettingsModel::setStatus(bool desiredBluetoothState, bool desiredV
application->bus.sendUnicast(std::make_shared<::message::bluetooth::SetStatus>(std::move(setStatus)),
service::name::bluetooth);
}
+
+void BluetoothSettingsModel::requestDeviceName()
+{
+ application->bus.sendUnicast(std::make_shared<::message::bluetooth::RequestDeviceName>(), service::name::bluetooth);
+}
+
+void BluetoothSettingsModel::setDeviceName(const UTF8 &deviceName)
+{
+ application->bus.sendUnicast(std::make_shared<message::bluetooth::SetDeviceName>(deviceName),
+ service::name::bluetooth);
+}
+
+void BluetoothSettingsModel::requestBondedDevices()
+{
+ application->bus.sendUnicast(std::make_shared<::message::bluetooth::RequestBondedDevices>(),
+ service::name::bluetooth);
+}
+
+void BluetoothSettingsModel::requestScan()
+{
+ application->bus.sendUnicast(std::make_shared<BluetoothMessage>(BluetoothMessage::Request::Scan),
+ service::name::bluetooth);
+}
+
void BluetoothSettingsModel::stopScan()
{
application->bus.sendUnicast(std::make_shared<BluetoothMessage>(BluetoothMessage::Request::StopScan),
M module-apps/application-settings-new/models/BluetoothSettingsModel.hpp => module-apps/application-settings-new/models/BluetoothSettingsModel.hpp +4 -0
@@ 17,6 17,10 @@ class BluetoothSettingsModel
void requestStatus();
void setStatus(bool desiredBluetoothState, bool desiredVisibility);
+ void requestDeviceName();
+ void setDeviceName(const UTF8 &deviceName);
+ void requestBondedDevices();
+ void requestScan();
void stopScan();
void setAddrForAudioProfiles(std::string addr);
M module-apps/application-settings-new/windows/AddDeviceWindow.cpp => module-apps/application-settings-new/windows/AddDeviceWindow.cpp +1 -1
@@ 15,7 15,7 @@ extern "C"
namespace gui
{
- AddDeviceWindow::AddDeviceWindow(app::Application *app, std::string name) : BaseSettingsWindow(app, std::move(name))
+ AddDeviceWindow::AddDeviceWindow(app::Application *app) : BaseSettingsWindow(app, window::name::add_device)
{
bluetoothSettingsModel = std::make_unique<BluetoothSettingsModel>(application);
}
M module-apps/application-settings-new/windows/AddDeviceWindow.hpp => module-apps/application-settings-new/windows/AddDeviceWindow.hpp +1 -2
@@ 4,7 4,6 @@
#pragma once
#include "BaseSettingsWindow.hpp"
-#include "application-settings-new/ApplicationSettings.hpp"
#include "application-settings-new/models/BluetoothSettingsModel.hpp"
#include <Device.hpp>
@@ 14,7 13,7 @@ namespace gui
class AddDeviceWindow : public BaseSettingsWindow
{
public:
- explicit AddDeviceWindow(app::Application *app, std::string name = window::name::add_device);
+ explicit AddDeviceWindow(app::Application *app);
private:
void onBeforeShow(ShowMode mode, SwitchData *data) override;
M module-apps/application-settings-new/windows/AllDevicesWindow.cpp => module-apps/application-settings-new/windows/AllDevicesWindow.cpp +40 -48
@@ 3,67 3,73 @@
#include "AllDevicesWindow.hpp"
#include "application-settings-new/ApplicationSettings.hpp"
+#include "application-settings-new/data/BondedDevicesData.hpp"
#include "application-settings-new/widgets/SettingsStyle.hpp"
-#include "OptionSetting.hpp"
-#include "DialogMetadata.hpp"
#include "DialogMetadataMessage.hpp"
-#include <Constants.hpp>
+#include "OptionSetting.hpp"
#include <InputEvent.hpp>
-#include <i18n/i18n.hpp>
-#include <service-bluetooth/BluetoothMessage.hpp>
-#include <service-bluetooth/messages/BondedDevices.hpp>
-#include "application-settings-new/data/BondedDevicesData.hpp"
namespace gui
{
- AllDevicesWindow::AllDevicesWindow(app::Application *app) : OptionWindow(app, gui::window::name::all_devices)
+ AllDevicesWindow::AllDevicesWindow(app::Application *app) : BaseSettingsWindow(app, window::name::all_devices)
+ {
+ bluetoothSettingsModel = std::make_unique<BluetoothSettingsModel>(application);
+ bluetoothSettingsModel->requestBondedDevices();
+ buildInterface();
+ }
+
+ void AllDevicesWindow::buildInterface()
{
setTitle(utils::localize.get("app_settings_bluetooth_all_devices"));
- application->bus.sendUnicast(std::make_shared<::message::bluetooth::RequestBondedDevices>(),
- service::name::bluetooth);
+ 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");
}
- void AllDevicesWindow::onBeforeShow(ShowMode mode, SwitchData *data)
+ void AllDevicesWindow::onBeforeShow(ShowMode /*mode*/, SwitchData *data)
{
- clearOptions();
- application->bus.sendUnicast(std::make_shared<BluetoothMessage>(BluetoothMessage::Request::StopScan),
- "ServiceBluetooth");
- if (const auto newData = dynamic_cast<BondedDevicesData *>(data); newData != nullptr) {
- addOptions(allDevicesOptionsList(newData->getDevices()));
+ const auto newData = dynamic_cast<BondedDevicesData *>(data);
+ if (newData != nullptr) {
+ devices = newData->getDevices();
}
+ refreshOptionsList();
}
auto AllDevicesWindow::onInput(const InputEvent &inputEvent) -> bool
{
-
- if (inputEvent.state == InputEvent::State::keyReleasedShort) {
- if (inputEvent.keyCode == KeyCode::KEY_LEFT) {
- application->bus.sendUnicast(std::make_shared<BluetoothMessage>(BluetoothMessage::Request::Scan),
- "ServiceBluetooth");
- 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);
- application->switchWindow(gui::window::name::dialog_settings, std::move(data));
- return true;
- }
+ if (inputEvent.isShortPress() && inputEvent.is(KeyCode::KEY_LEFT)) {
+ bluetoothSettingsModel->requestScan();
+ gui::DialogMetadata meta;
+ application->switchWindow(gui::window::name::dialog_settings,
+ gui::ShowMode::GUI_SHOW_INIT,
+ std::make_unique<gui::DialogMetadataMessage>(gui::DialogMetadata{
+ utils::localize.get("app_settings_bluetooth_add_device"),
+ "search_big",
+ utils::localize.get("app_settings_bluetooth_searching_devices")}));
+ return true;
}
-
return AppWindow::onInput(inputEvent);
}
- auto AllDevicesWindow::allDevicesOptionsList(const std::vector<Devicei> &devicesList) -> std::list<Option>
+ auto AllDevicesWindow::buildOptionsList() -> std::list<Option>
{
std::list<gui::Option> optionsList;
-
- for (const auto &device : devicesList) {
+ for (const auto &device : devices) {
optionsList.emplace_back(std::make_unique<gui::option::OptionSettings>(
device.name,
- [=](gui::Item &item) {
+ [=](gui::Item & /*item*/) {
LOG_DEBUG("Device: %s", device.name.c_str());
return true;
},
@@ 71,20 77,6 @@ namespace gui
nullptr,
gui::option::SettingRightItem::Bt));
}
-
- 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
M module-apps/application-settings-new/windows/AllDevicesWindow.hpp => module-apps/application-settings-new/windows/AllDevicesWindow.hpp +11 -4
@@ 1,22 1,29 @@
-// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
+// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#pragma once
-#include "OptionWindow.hpp"
+#include "application-settings-new/models/BluetoothSettingsModel.hpp"
+#include "BaseSettingsWindow.hpp"
+
#include <Device.hpp>
+
namespace gui
{
- class AllDevicesWindow : public OptionWindow
+ class AllDevicesWindow : public BaseSettingsWindow
{
public:
explicit AllDevicesWindow(app::Application *app);
private:
- auto allDevicesOptionsList(const std::vector<Devicei> &vector) -> std::list<Option>;
+ void buildInterface() override;
+ auto buildOptionsList() -> std::list<Option> override;
void onBeforeShow(ShowMode mode, SwitchData *data) override;
auto onInput(const InputEvent &inputEvent) -> bool override;
+
Image *leftArrowImage = nullptr;
Image *crossImage = nullptr;
+ std::vector<Devicei> devices;
+ std::unique_ptr<BluetoothSettingsModel> bluetoothSettingsModel;
};
} // namespace gui
M module-apps/application-settings-new/windows/BluetoothWindow.cpp => module-apps/application-settings-new/windows/BluetoothWindow.cpp +2 -1
@@ 2,6 2,7 @@
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#include "BluetoothWindow.hpp"
+#include "application-settings-new/ApplicationSettings.hpp"
#include "application-settings-new/data/BluetoothStatusData.hpp"
#include "OptionSetting.hpp"
@@ 9,7 10,7 @@
namespace gui
{
- BluetoothWindow::BluetoothWindow(app::Application *app, std::string name) : BaseSettingsWindow(app, std::move(name))
+ BluetoothWindow::BluetoothWindow(app::Application *app) : BaseSettingsWindow(app, window::name::bluetooth)
{
bluetoothSettingsModel = std::make_unique<BluetoothSettingsModel>(application);
bluetoothSettingsModel->requestStatus();
M module-apps/application-settings-new/windows/BluetoothWindow.hpp => module-apps/application-settings-new/windows/BluetoothWindow.hpp +1 -2
@@ 3,7 3,6 @@
#pragma once
-#include "application-settings-new/ApplicationSettings.hpp"
#include "application-settings-new/models/BluetoothSettingsModel.hpp"
#include "BaseSettingsWindow.hpp"
@@ 12,7 11,7 @@ namespace gui
class BluetoothWindow : public BaseSettingsWindow
{
public:
- explicit BluetoothWindow(app::Application *app, std::string name = window::name::bluetooth);
+ explicit BluetoothWindow(app::Application *app);
private:
void onBeforeShow(ShowMode mode, SwitchData *data) override;
M module-apps/application-settings-new/windows/PhoneNameWindow.cpp => module-apps/application-settings-new/windows/PhoneNameWindow.cpp +13 -12
@@ 1,21 1,19 @@
-// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
+// 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 <service-bluetooth/Constants.hpp>
-#include <service-bluetooth/messages/DeviceName.hpp>
-#include <service-bluetooth/messages/SetDeviceName.hpp>
-
#include <Utils.hpp>
-#include <application-settings-new/data/PhoneNameData.hpp>
namespace gui
{
PhoneNameWindow::PhoneNameWindow(app::Application *app) : AppWindow(app, gui::window::name::phone_name)
{
+ bluetoothSettingsModel = std::make_unique<BluetoothSettingsModel>(application);
+ bluetoothSettingsModel->requestDeviceName();
buildInterface();
}
@@ 33,13 31,17 @@ namespace gui
bottomBar->setText(BottomBar::Side::CENTER, utils::localize.get(style::strings::common::save));
bottomBar->setText(BottomBar::Side::RIGHT, utils::localize.get(style::strings::common::back));
- application->bus.sendUnicast(std::make_shared<::message::bluetooth::RequestDeviceName>(),
- service::name::bluetooth);
-
setFocusItem(inputField);
}
- void PhoneNameWindow::onBeforeShow(ShowMode mode, SwitchData *data)
+ 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) {
@@ 58,8 60,7 @@ namespace gui
}
if (inputEvent.is(gui::KeyCode::KEY_ENTER) && !inputField->isEmpty()) {
- auto result = std::make_shared<::message::bluetooth::SetDeviceName>(inputField->getText());
- application->bus.sendUnicast(std::move(result), service::name::bluetooth);
+ bluetoothSettingsModel->setDeviceName(inputField->getText());
return true;
}
M module-apps/application-settings-new/windows/PhoneNameWindow.hpp => module-apps/application-settings-new/windows/PhoneNameWindow.hpp +6 -1
@@ 1,6 1,8 @@
-// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
+// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#pragma once
+
+#include "application-settings-new/models/BluetoothSettingsModel.hpp"
#include "AppWindow.hpp"
#include <Text.hpp>
@@ 13,9 15,12 @@ namespace gui
private:
void buildInterface() override;
+ void destroyInterface() override;
void onBeforeShow(ShowMode mode, SwitchData *data) override;
auto onInput(const InputEvent &inputEvent) -> bool override;
+
Text *inputField = nullptr;
+ std::unique_ptr<BluetoothSettingsModel> bluetoothSettingsModel;
};
} /* namespace gui */