// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "ApplicationNotes.hpp" #include "MessageType.hpp" #include "windows/NoteMainWindow.hpp" #include "windows/NotePreviewWindow.hpp" #include "windows/NoteEditWindow.hpp" #include "windows/SearchEngineWindow.hpp" #include "windows/SearchResultsWindow.hpp" #include #include #include #include #include #include #include #include namespace app { namespace { constexpr auto NotesStackSize = 4096U; } // namespace ApplicationNotes::ApplicationNotes(std::string name, std::string parent, sys::phone_modes::PhoneMode mode, StartInBackground startInBackground) : Application(std::move(name), std::move(parent), mode, startInBackground, NotesStackSize) { bus.channels.push_back(sys::BusChannel::ServiceDBNotifications); } // Invoked upon receiving data message sys::MessagePointer ApplicationNotes::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 (static_cast(retMsg.get())->retCode == sys::ReturnCodes::Success) { return retMsg; } if (msgl->messageType == MessageType::DBServiceNotification) { if (auto msg = dynamic_cast(msgl); msg != nullptr) { // window-specific actions if (msg->interface == db::Interface::Name::Notes) { for (auto &[name, window] : windowsStack) { window->onDatabaseMessage(msg); } } return std::make_shared(); } } if (resp != nullptr) { if (auto command = callbackStorage->getCallback(resp); command->execute()) { refreshWindow(gui::RefreshModes::GUI_REFRESH_FAST); } return sys::msgHandled(); } return sys::msgNotHandled(); } sys::ReturnCodes ApplicationNotes::InitHandler() { const auto ret = Application::InitHandler(); if (ret != sys::ReturnCodes::Success) { return ret; } createUserInterface(); return ret; } sys::ReturnCodes ApplicationNotes::DeinitHandler() { return sys::ReturnCodes::Success; } sys::ReturnCodes ApplicationNotes::SwitchPowerModeHandler(const sys::ServicePowerMode mode) { return sys::ReturnCodes::Success; } void ApplicationNotes::createUserInterface() { windowsFactory.attach(gui::name::window::main_window, [](Application *app, const std::string &name) { auto notesRepository = std::make_unique(app); auto notesProvider = std::make_shared(app, std::move(notesRepository)); auto presenter = std::make_unique(notesProvider); return std::make_unique(app, std::move(presenter)); }); windowsFactory.attach(gui::name::window::note_preview, [](Application *app, const std::string &name) { auto notesRepository = std::make_unique(app); auto presenter = std::make_unique(std::move(notesRepository)); return std::make_unique(app, std::move(presenter)); }); windowsFactory.attach(gui::name::window::note_edit, [](Application *app, const std::string &name) { auto notesRepository = std::make_unique(app); auto presenter = std::make_unique(std::move(notesRepository)); return std::make_unique(app, std::move(presenter)); }); windowsFactory.attach(gui::name::window::notes_search, [](Application *app, const std::string &name) { auto notesRepository = std::make_unique(app); auto presenter = std::make_unique(std::move(notesRepository)); return std::make_unique(app, std::move(presenter)); }); windowsFactory.attach(gui::name::window::notes_search_result, [](Application *app, const std::string &name) { return std::make_unique(app); }); windowsFactory.attach(gui::name::window::note_dialog, [](Application *app, const std::string &name) { return std::make_unique(app, name); }); windowsFactory.attach(gui::name::window::note_confirm_dialog, [](Application *app, const std::string &name) { return std::make_unique(app, name); }); windowsFactory.attach( utils::localize.get("app_phonebook_options_title"), [](Application *app, const std::string &name) { return std::make_unique(app, name); }); attachPopups({gui::popup::ID::Volume, gui::popup::ID::Tethering, gui::popup::ID::TetheringPhoneModeChangeProhibited, gui::popup::ID::PhoneModes}); } void ApplicationNotes::destroyUserInterface() {} } // namespace app