// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "ApplicationAlarmClock.hpp" #include "application-alarm-clock/windows/AlarmClockMainWindow.hpp" #include "application-alarm-clock/windows/NewEditAlarmWindow.hpp" #include "application-alarm-clock/windows/CustomRepeatWindow.hpp" #include "application-alarm-clock/widgets/AlarmClockStyle.hpp" #include "application-alarm-clock/presenter/AlarmClockMainWindowPresenter.hpp" #include "application-alarm-clock/presenter/CustomRepeatWindowPresenter.hpp" #include "windows/Dialog.hpp" #include "windows/AppWindow.hpp" #include "windows/OptionWindow.hpp" #include #include #include #include namespace app { ApplicationAlarmClock::ApplicationAlarmClock(std::string name, std::string parent, StatusIndicators statusIndicators, uint32_t stackDepth, sys::ServicePriority priority) : Application(name, parent, statusIndicators, false, stackDepth, priority), soundsPlayer{std::make_shared(this)} { bus.channels.push_back(sys::BusChannel::ServiceDBNotifications); bus.channels.push_back(sys::BusChannel::ServiceAudioNotifications); } sys::MessagePointer ApplicationAlarmClock::DataReceivedHandler(sys::DataMessage *msgl, sys::ResponseMessage *resp) { auto retMsg = Application::DataReceivedHandler(msgl); // if message was handled by application's template there is no need to process further. if (retMsg && (static_cast(retMsg.get())->retCode == sys::ReturnCodes::Success)) { return retMsg; } auto msg = dynamic_cast(msgl); if (msg != nullptr) { userInterfaceDBNotification(msg, [](sys::Message *m, [[maybe_unused]] const std::string &) { auto msg = dynamic_cast(m); return (msg != nullptr) && msg->interface == db::Interface::Name::AlarmEvents; }); return std::make_shared(); } return handleAsyncResponse(resp); } sys::ReturnCodes ApplicationAlarmClock::InitHandler() { auto ret = Application::InitHandler(); if (ret != sys::ReturnCodes::Success) { return ret; } connect(typeid(AudioStopNotification), [&](sys::Message *msg) -> sys::MessagePointer { auto notification = static_cast(msg); return handleAudioStop(notification); }); connect(typeid(AudioEOFNotification), [&](sys::Message *msg) -> sys::MessagePointer { auto notification = static_cast(msg); return handleAudioStop(notification); }); createUserInterface(); return ret; } void ApplicationAlarmClock::createUserInterface() { windowsFactory.attach(gui::name::window::main_window, [](ApplicationCommon *app, const std::string &name) { auto alarmsRepository = std::make_unique(app); auto alarmsProvider = std::make_shared(app, std::move(alarmsRepository)); auto presenter = std::make_unique(alarmsProvider); return std::make_unique(app, std::move(presenter)); }); auto rRulePresenter = std::make_shared(); windowsFactory.attach(style::alarmClock::window::name::newEditAlarm, [this, rRulePresenter](ApplicationCommon *app, const std::string &name) { auto alarmsRepository = std::make_unique(app); auto alarmsProvider = std::make_shared( app, soundsPlayer, rRulePresenter, std::move(alarmsRepository)); auto presenter = std::make_unique(alarmsProvider); return std::make_unique(app, std::move(presenter)); }); windowsFactory.attach(style::alarmClock::window::name::customRepeat, [rRulePresenter](ApplicationCommon *app, const std::string &name) { auto alarmsProvider = std::make_shared(app, rRulePresenter); auto presenter = std::make_unique(alarmsProvider); return std::make_unique(app, std::move(presenter)); }); windowsFactory.attach(window::name::option_window, [](ApplicationCommon *app, const std::string &name) { return std::make_unique(app, name); }); windowsFactory.attach(style::alarmClock::window::name::dialogYesNo, [](ApplicationCommon *app, const std::string &name) { return std::make_unique(app, name); }); attachPopups({gui::popup::ID::Volume, gui::popup::ID::Tethering, gui::popup::ID::BluetoothAuthenticate, gui::popup::ID::PhoneModes, gui::popup::ID::PhoneLock, gui::popup::ID::Alarm}); } void ApplicationAlarmClock::destroyUserInterface() {} sys::MessagePointer ApplicationAlarmClock::handleAudioStop(AudioStopNotification *notification) { soundsPlayer->stop(notification->token); return sys::MessageNone{}; } } /* namespace app */