From 26a98bce1ea5c8c2934af44ead80988745db6ec4 Mon Sep 17 00:00:00 2001 From: Adam Dobrowolski Date: Thu, 2 Jan 2020 13:58:30 +0100 Subject: [PATCH] [AppManagement] Getting through previus windows by list * removed first main window as first window in call app * moved window switching to application from window --- module-apps/Application.cpp | 165 ++++++++++++------ module-apps/Application.hpp | 21 ++- .../application-call/ApplicationCall.cpp | 4 +- .../windows/CallMainWindow.cpp | 9 +- .../ApplicationCallLog.cpp | 11 +- .../data/CallLogInternals.hpp | 11 +- .../ApplicationDesktop.cpp | 4 +- .../windows/DesktopMainWindow.cpp | 5 +- .../windows/MenuWindow.cpp | 34 ++-- .../windows/PinLockWindow.cpp | 24 +-- .../ApplicationMessages.cpp | 10 +- .../windows/MessagesMainWindow.cpp | 11 +- .../application-notes/ApplicationNotes.cpp | 10 +- .../windows/NotesMainWindow.cpp | 11 +- .../ApplicationPhonebook.cpp | 3 +- .../windows/PhonebookDialogs.cpp | 2 +- .../windows/PhonebookMainWindow.cpp | 8 +- .../ApplicationSettings.cpp | 4 +- .../windows/SettingsMainWindow.cpp | 9 +- .../AppSpecialInput.cpp | 2 +- .../AppSpecialInput.hpp | 2 +- .../application-viewer/windows/ViewWindow.cpp | 9 +- module-apps/messages/AppMessage.hpp | 18 +- module-apps/windows/AppWindow.cpp | 8 +- module-apps/windows/AppWindow.hpp | 12 +- .../service-appmgr/ApplicationManager.cpp | 24 +-- 26 files changed, 261 insertions(+), 170 deletions(-) diff --git a/module-apps/Application.cpp b/module-apps/Application.cpp index 3ef6372b9..4fbf2d423 100644 --- a/module-apps/Application.cpp +++ b/module-apps/Application.cpp @@ -29,6 +29,7 @@ #include "messages/AppMessage.hpp" #include "windows/AppWindow.hpp" #include +#include namespace app { @@ -139,16 +140,17 @@ void Application::longPressTimerCallback() } void Application::render( gui::RefreshModes mode ) { - if( currentWindow == nullptr ){ - LOG_ERROR("Current window is not defined"); + if (getCurrentWindow() == nullptr) + { + LOG_ERROR("Current window is not defined"); return; - } + } - //send drawing commands only when if application is in active and visible. + //send drawing commands only when if application is in active and visible. if( state == State::ACTIVE_FORGROUND ) { - std::list commandsList = currentWindow->buildDrawList(); + std::list commandsList = getCurrentWindow()->buildDrawList(); - if( shutdownInProgress ) { + if( shutdownInProgress ) { auto msg = std::make_shared(commandsList, mode, sgui::DrawMessage::DrawCommand::SHUTDOWN ); sys::Bus::SendUnicast(msg, "ServiceGUI", this); } @@ -172,21 +174,20 @@ int Application::switchWindow( const std::string& windowName, gui::ShowMode cmd, std::string window; #ifdef DEBUG_APPLICATION_MANAGEMENT - LOG_INFO("switching [%s] to window: %s", GetName().c_str(), windowName.length() ? windowName.c_str() : "MainWindow"); + LOG_INFO("switching [%s] to window: %s data description: %s", GetName().c_str(), + windowName.length() ? windowName.c_str() : gui::name::window::main_window.c_str(), data ? data->getDescription().c_str() : ""); #endif //case to handle returning to previous application if( windowName == "LastWindow" ) { - window = currentWindow->getName(); - auto ret = dynamic_cast(data.get()); - auto msg = std::make_shared(window, currentWindow->getName(), - ret ? std::move(data) : std::make_unique("LastWindow"), cmd); + window = getCurrentWindow()->getName(); + auto msg = std::make_shared(window, getCurrentWindow()->getName(), std::move(data), cmd); sys::Bus::SendUnicast(msg, this->GetName(), this ); } else { - window = windowName.empty() ? "MainWindow" : windowName; - auto msg = std::make_shared( window, currentWindow->getName(), std::move(data), cmd ); - sys::Bus::SendUnicast(msg, this->GetName(), this ); + window = windowName.empty() ? gui::name::window::main_window : windowName; + auto msg = std::make_shared(window, getCurrentWindow() ? getCurrentWindow()->getName() : "", std::move(data), cmd); + sys::Bus::SendUnicast(msg, this->GetName(), this ); } return 0; @@ -213,23 +214,24 @@ sys::Message_t Application::DataReceivedHandler(sys::DataMessage* msgl) { if( msgl->messageType == static_cast(MessageType::CellularNotification) ) { CellularNotificationMessage *msg = reinterpret_cast(msgl); if( msg->type == CellularNotificationMessage::Type::SignalStrengthUpdate ) { - if( ( state == State::ACTIVE_FORGROUND ) && (currentWindow->updateSignalStrength( msg->signalStrength) ) ) { - //loop and update all widnows + if ((state == State::ACTIVE_FORGROUND) && (getCurrentWindow()->updateSignalStrength(msg->signalStrength))) + { + //loop and update all widnows for ( auto it = windows.begin(); it != windows.end(); it++ ) { it->second->updateSignalStrength( msg->signalStrength); } handled = true; refreshWindow( gui::RefreshModes::GUI_REFRESH_FAST ); - } - } + } + } } if(msgl->messageType == static_cast(MessageType::AppInputEvent) ) { AppInputEventMessage* msg = reinterpret_cast( msgl ); - if( currentWindow != nullptr ) - currentWindow->onInput( msg->getEvent() ); + if (getCurrentWindow() != nullptr) + getCurrentWindow()->onInput(msg->getEvent()); -// LOG_INFO( "Key event :%s", msg->getEvent().to_string().c_str()); + // LOG_INFO( "Key event :%s", msg->getEvent().to_string().c_str()); handled = true; } else if(msgl->messageType == static_cast(MessageType::KBDKeyEvent) ) @@ -246,12 +248,13 @@ sys::Message_t Application::DataReceivedHandler(sys::DataMessage* msgl) { sevm::BatteryLevelMessage* msg = static_cast(msgl); LOG_INFO("Application battery level: %d", msg->levelPercents ); - if( currentWindow ) { - if( currentWindow->updateBatteryLevel( msg->levelPercents ) ) - refreshWindow( gui::RefreshModes::GUI_REFRESH_FAST ); - } + if (getCurrentWindow()) + { + if (getCurrentWindow()->updateBatteryLevel(msg->levelPercents)) + refreshWindow(gui::RefreshModes::GUI_REFRESH_FAST); + } - handled = true; + handled = true; } else if(msgl->messageType == static_cast(MessageType::EVMChargerPlugged) ) { @@ -273,9 +276,9 @@ sys::Message_t Application::DataReceivedHandler(sys::DataMessage* msgl) { sevm::RtcMinuteAlarmMessage* msg = static_cast(msgl); LOG_INFO("Application time updated"); - currentWindow->updateTime( msg->timestamp, !settings.timeFormat12 ); + getCurrentWindow()->updateTime(msg->timestamp, !settings.timeFormat12); - if( state == State::ACTIVE_FORGROUND ) + if( state == State::ACTIVE_FORGROUND ) refreshWindow( gui::RefreshModes::GUI_REFRESH_FAST ); handled = true; @@ -290,6 +293,7 @@ sys::Message_t Application::DataReceivedHandler(sys::DataMessage* msgl) { if( msg->getTargetApplicationName() == this->GetName()) { if( sapm::ApplicationManager::messageConfirmSwitch(this) ) { + LOG_INFO("%s : %s", msg->getTargetWindowName().c_str(), msg->getData() ? msg->getData()->getDescription().c_str() : ""); setState(State::ACTIVE_FORGROUND); switchWindow( msg->getTargetWindowName(), std::move( msg->getData())); @@ -341,20 +345,16 @@ sys::Message_t Application::DataReceivedHandler(sys::DataMessage* msgl) { setActiveWindow( msg->getWindowName() ); - currentWindow->handleSwitchData( msg->getData().get() ); + getCurrentWindow()->handleSwitchData(msg->getData().get()); - if( currentWindow->getPrevWindow().empty() ) { - currentWindow->setPrevWindow( msg->getSenderWindowName() ); - } //check if this is case where application is returning to the last visible window. - if( (msg->getData() != nullptr) && (msg->getData()->getDescription() == "LastWindow") ) { - } - else { - currentWindow->onBeforeShow( msg->getCommand(), msg->getData().get() ); + if ((msg->getData() != nullptr) && (msg->LastSeenWindow)) {} + else { + getCurrentWindow()->onBeforeShow(msg->getCommand(), msg->getData().get()); auto ret = dynamic_cast(msg->getData().get()); if (ret != nullptr && msg->getData() != nullptr) { - auto text = dynamic_cast(currentWindow->getFocusItem()); + auto text = dynamic_cast(getCurrentWindow()->getFocusItem()); if (text) { if (text->handleChar(ret->getDescription()[0])) @@ -407,8 +407,8 @@ sys::Message_t Application::DataReceivedHandler(sys::DataMessage* msgl) { } else if( msgl->messageType == static_cast(MessageType::AppRefresh)) { AppRefreshMessage* msg = reinterpret_cast( msgl ); - //currentWindow->onBeforeShow( gui::ShowMode::GUI_SHOW_RETURN, 0, nullptr ); - render( msg->getMode() ); + // getCurrentWindow()->onBeforeShow( gui::ShowMode::GUI_SHOW_RETURN, 0, nullptr ); + render( msg->getMode() ); handled = true; } @@ -433,16 +433,10 @@ sys::ReturnCodes Application::InitHandler() { return retCode; } -void Application::setActiveWindow( const std::string& windowName ) { - auto it = windows.find(windowName); - - //if there is a window with specified name set it as active window - //and unlock accepting keyboard events - if( it!=windows.end() ) { - previousWindow = currentWindow; - currentWindow = it->second; - acceptInput = true; - } +void Application::setActiveWindow(const std::string &windowName) +{ + pushWindow(windowName); + acceptInput = true; } bool Application::messageSwitchApplication( sys::Service* sender, std::string application, std::string window, std::unique_ptr data ) { @@ -476,6 +470,79 @@ bool Application::messageInputEventApplication( sys::Service* sender, std::strin return true; } +bool Application::popToWindow(const std::string &window) +{ + auto ret = std::find(windowStack.begin(), windowStack.end(), window); + if (ret != windowStack.end()) + { + LOG_INFO("Pop last window(s) : %d! %s", std::distance(ret, windowStack.end()), ret->c_str()); + windowStack.erase(std::next(ret), windowStack.end()); + return true; + } + return false; +} + +void Application::pushWindow(const std::string &newWindow) +{ + // handle if window was already on + if (popToWindow(newWindow)) + { + return; + } + else + { + windowStack.push_back(newWindow); + } +#ifdef DEBUG_APPLICATION_MANAGEMENT + LOG_DEBUG("[%d] newWindow: %s", windowStack.size(), newWindow.c_str()); + for (auto &el : windowStack) + { + LOG_DEBUG("-> %s", el.c_str()); + } + LOG_INFO("\n\n"); +#endif +}; + +const std::string Application::getPrevWindow() const +{ + if (this->windowStack.size() <= 1) + { + return gui::name::window::no_window; + } + return *std::prev(windowStack.end(), 2); +} + +void Application::Application::cleanPrevWindw() +{ + this->windowStack.clear(); +} + +gui::AppWindow *Application::getWindow(const std::string &window) +{ + auto it = windows.find(window); + if (it != windows.end()) + { + return it->second; + } + return nullptr; +} + +gui::AppWindow *Application::getCurrentWindow() +{ + std::string window = ""; + if (windowStack.size() == 0) + { + window = gui::name::window::main_window; + } + else + { + window = windowStack.back(); + } + + return getWindow(window); +} + + AppTimer Application::CreateAppTimer(TickType_t interval, bool isPeriodic, std::function callback, const std::string &name) { auto id = CreateTimer(interval, isPeriodic, name); diff --git a/module-apps/Application.hpp b/module-apps/Application.hpp index 79a425e35..a1e5c6bb9 100644 --- a/module-apps/Application.hpp +++ b/module-apps/Application.hpp @@ -23,6 +23,7 @@ #include "Interface/SettingsRecord.hpp" #include "SwitchData.hpp" +#include "windows/AppWindow.hpp" // #define DEBUG_APPLICATION_MANAGEMENT @@ -189,10 +190,22 @@ protected: /** * Map containing application's windows */ - std::map windows; - gui::AppWindow* currentWindow = nullptr; - gui::AppWindow* previousWindow = nullptr; - /** + std::map windows; + + std::vector windowStack; + + public: + /// get to the first time we entered this &window + bool popToWindow(const std::string &window); + // push window to the top of windows stack + void pushWindow(const std::string &newWindow); + const std::string getPrevWindow() const; + void cleanPrevWindw(); + gui::AppWindow *getWindow(const std::string &window); + gui::AppWindow *getCurrentWindow(); + + protected: + /** * Flag defines whether keyboard input is processed */ bool acceptInput = false; diff --git a/module-apps/application-call/ApplicationCall.cpp b/module-apps/application-call/ApplicationCall.cpp index b909cca98..958900734 100644 --- a/module-apps/application-call/ApplicationCall.cpp +++ b/module-apps/application-call/ApplicationCall.cpp @@ -38,9 +38,9 @@ void ApplicationCall::timerCallCallback() // Invoked when timer ticked, 3 seconds after end call event if user didn't press back button earlier. ++callDuration; auto it = windows.find("CallWindow"); - if (currentWindow == it->second) + if (getCurrentWindow() == it->second) { - gui::CallWindow *callWindow = reinterpret_cast(currentWindow); + gui::CallWindow *callWindow = reinterpret_cast(getCurrentWindow()); if (callWindow->getState() == gui::CallWindow::State::CALL_IN_PROGRESS) { diff --git a/module-apps/application-call/windows/CallMainWindow.cpp b/module-apps/application-call/windows/CallMainWindow.cpp index 7f7dabd11..38db0d6bc 100644 --- a/module-apps/application-call/windows/CallMainWindow.cpp +++ b/module-apps/application-call/windows/CallMainWindow.cpp @@ -13,11 +13,12 @@ namespace gui { -CallMainWindow::CallMainWindow( app::Application* app ) : AppWindow(app,"MainWindow"){ - setSize( 480, 600 ); + CallMainWindow::CallMainWindow(app::Application *app) : AppWindow(app, gui::name::window::main_window) + { + setSize(480, 600); - buildInterface(); -} + buildInterface(); + } void CallMainWindow::rebuild() { } diff --git a/module-apps/application-calllog/ApplicationCallLog.cpp b/module-apps/application-calllog/ApplicationCallLog.cpp index 820cd41cd..5f8da0562 100644 --- a/module-apps/application-calllog/ApplicationCallLog.cpp +++ b/module-apps/application-calllog/ApplicationCallLog.cpp @@ -45,11 +45,12 @@ sys::Message_t ApplicationCallLog::DataReceivedHandler(sys::DataMessage* msgl,sy uint32_t msgType = resp->responseTo; switch( msgType ) { case static_cast(MessageType::DBCalllogGetLimitOffset): { - if( currentWindow->onDatabaseMessage( resp ) ) { - refreshWindow( gui::RefreshModes::GUI_REFRESH_FAST ); - } - break; - } + if (getCurrentWindow()->onDatabaseMessage(resp)) + { + refreshWindow(gui::RefreshModes::GUI_REFRESH_FAST); + } + break; + } } } diff --git a/module-apps/application-calllog/data/CallLogInternals.hpp b/module-apps/application-calllog/data/CallLogInternals.hpp index dbc1231f7..3743c1b61 100644 --- a/module-apps/application-calllog/data/CallLogInternals.hpp +++ b/module-apps/application-calllog/data/CallLogInternals.hpp @@ -8,8 +8,9 @@ */ #pragma once -#include "CalllogRecord.hpp" +#include "AppWindow.hpp" #include "CallLogStyle.hpp" +#include "CalllogRecord.hpp" #include namespace calllog { @@ -31,11 +32,11 @@ namespace calllog { namespace settings { // Windows - const inline std::string MainWindowStr = "MainWindow"; - const inline std::string DetailsWindowStr = "DetailsWindow"; - const inline std::string OptionsWindowStr = "OptionsWindow"; + const inline std::string MainWindowStr = gui::name::window::main_window; + const inline std::string DetailsWindowStr = "DetailsWindow"; + const inline std::string OptionsWindowStr = "OptionsWindow"; const inline std::string CallDeleteWindowStr = "CallDeleteOptionsWindow"; constexpr auto pageSize = 7; } -} \ No newline at end of file +} // namespace calllog diff --git a/module-apps/application-desktop/ApplicationDesktop.cpp b/module-apps/application-desktop/ApplicationDesktop.cpp index 5db934bab..a459b5bdb 100644 --- a/module-apps/application-desktop/ApplicationDesktop.cpp +++ b/module-apps/application-desktop/ApplicationDesktop.cpp @@ -66,9 +66,9 @@ sys::ReturnCodes ApplicationDesktop::InitHandler() { createUserInterface(); - setActiveWindow("MainWindow"); + setActiveWindow(gui::name::window::main_window); - return ret; + return ret; } sys::ReturnCodes ApplicationDesktop::DeinitHandler() { diff --git a/module-apps/application-desktop/windows/DesktopMainWindow.cpp b/module-apps/application-desktop/windows/DesktopMainWindow.cpp index 9e3084ac5..935537801 100644 --- a/module-apps/application-desktop/windows/DesktopMainWindow.cpp +++ b/module-apps/application-desktop/windows/DesktopMainWindow.cpp @@ -88,8 +88,9 @@ void DesktopMainWindow::destroyInterface() { children.clear(); } -DesktopMainWindow::DesktopMainWindow( app::Application* app ) : AppWindow(app,"MainWindow"){ - setSize( 480, 600 ); +DesktopMainWindow::DesktopMainWindow(app::Application *app) : AppWindow(app, gui::name::window::main_window) +{ + setSize( 480, 600 ); buildInterface(); } diff --git a/module-apps/application-desktop/windows/MenuWindow.cpp b/module-apps/application-desktop/windows/MenuWindow.cpp index 3b553a4e5..0245d5d62 100644 --- a/module-apps/application-desktop/windows/MenuWindow.cpp +++ b/module-apps/application-desktop/windows/MenuWindow.cpp @@ -122,16 +122,16 @@ void MenuWindow::buildInterface() { //page1 TileDescription{"menu_phone","app_desktop_menu_phone",[=] (gui::Item& item) { LOG_INFO("page 1 tile 1" ); - sapm::ApplicationManager::messageSwitchApplication( application, "ApplicationCallLog", "MainWindow", nullptr ); - return true; }}, + sapm::ApplicationManager::messageSwitchApplication(application, "ApplicationCallLog", gui::name::window::main_window, nullptr); + return true; }}, TileDescription{"menu_contacts", "app_desktop_menu_contacts",[=] (gui::Item& item){ LOG_INFO("Phonebook"); - sapm::ApplicationManager::messageSwitchApplication( application, "ApplicationPhonebook", "MainWindow",nullptr); + sapm::ApplicationManager::messageSwitchApplication(application, "ApplicationPhonebook", gui::name::window::main_window, nullptr); return true; }}, TileDescription{"menu_messages", "app_desktop_menu_messages",[=] (gui::Item& item){ LOG_INFO("Messages"); - sapm::ApplicationManager::messageSwitchApplication( application, "ApplicationMessages", "MainWindow",nullptr); + sapm::ApplicationManager::messageSwitchApplication(application, "ApplicationMessages", gui::name::window::main_window, nullptr); return true; }}, TileDescription{"menu_calendar", "app_desktop_menu_calendar",[=] (gui::Item& item){ return true; }}, @@ -144,8 +144,8 @@ void MenuWindow::buildInterface() { return true; } },}, TileDescription{"menu_settings","app_desktop_menu_settings",[=] (gui::Item& item){ LOG_INFO("page 1 settings" ); - sapm::ApplicationManager::messageSwitchApplication( application, "ApplicationSettings", "MainWindow", nullptr ); - return true; }}, + sapm::ApplicationManager::messageSwitchApplication(application, "ApplicationSettings", gui::name::window::main_window, nullptr); + return true; }}, }; MenuPage* page1 = new MenuPage( this, 0, 60, 480, 70+128*3+2*17, page1Definitions, MenuPage::PageID::MainPage); @@ -153,15 +153,17 @@ void MenuWindow::buildInterface() { page_name.push_back(utils::localize.get("app_desktop_menu_title")); //PAGE 2 - std::vector page2Definitions { - TileDescription{"menu_tools_notes", "app_desktop_tools_notes",[=] (gui::Item& item){ - sapm::ApplicationManager::messageSwitchApplication( application, "ApplicationNotes", "MainWindow", nullptr ); - return true; }}, - TileDescription{"menu_tools_calculator","app_desktop_tools_calculator",[=] (gui::Item& item){ return true; }}, - TileDescription{"menu_tools_recorder", "app_desktop_tools_recorder",[=] (gui::Item& item){ return true; }}, - }; + std::vector page2Definitions{ + TileDescription{"menu_tools_notes", "app_desktop_tools_notes", + [=](gui::Item &item) { + sapm::ApplicationManager::messageSwitchApplication(application, "ApplicationNotes", gui::name::window::main_window, nullptr); + return true; + }}, + TileDescription{"menu_tools_calculator", "app_desktop_tools_calculator", [=](gui::Item &item) { return true; }}, + TileDescription{"menu_tools_recorder", "app_desktop_tools_recorder", [=](gui::Item &item) { return true; }}, + }; - MenuPage* page2 = new MenuPage( this, 0, 60, 480, 70+128*3+2*17, page2Definitions, MenuPage::PageID::ToolsPage ); + MenuPage* page2 = new MenuPage( this, 0, 60, 480, 70+128*3+2*17, page2Definitions, MenuPage::PageID::ToolsPage ); pages.push_back( page2 ); page_name.push_back(utils::localize.get("app_desktop_tools_title")); @@ -208,8 +210,8 @@ bool MenuWindow::onInput( const InputEvent& inputEvent ) { switchPage(0); } else { - application->switchWindow( "MainWindow" ); - } + application->switchWindow(gui::name::window::main_window); + } return true; } default: diff --git a/module-apps/application-desktop/windows/PinLockWindow.cpp b/module-apps/application-desktop/windows/PinLockWindow.cpp index b13c21b32..98edd229b 100644 --- a/module-apps/application-desktop/windows/PinLockWindow.cpp +++ b/module-apps/application-desktop/windows/PinLockWindow.cpp @@ -189,9 +189,9 @@ bool PinLockWindow::onInput( const InputEvent& inputEvent ) { return true; } else if( inputEvent.keyCode == KeyCode::KEY_RF ) { - application->switchWindow( "MainWindow" ); - return true; - } + application->switchWindow(gui::name::window::main_window); + return true; + } else if( inputEvent.keyCode == KeyCode::KEY_PND ) { if( charCount > 0 ) { pinLabels[charCount-1]->setText(""); @@ -212,9 +212,9 @@ bool PinLockWindow::onInput( const InputEvent& inputEvent ) { //if there is no application to return to simply return to main window if( lockTimeoutApplilcation.empty()) { - application->switchWindow( "MainWindow" ); - } - else { + application->switchWindow(gui::name::window::main_window); + } + else { lockTimeoutApplilcation = ""; sapm::ApplicationManager::messageSwitchPreviousApplication( application ); } @@ -262,14 +262,14 @@ bool PinLockWindow::onInput( const InputEvent& inputEvent ) { } else if( inputEvent.keyCode == KeyCode::KEY_RF ) { state = State::EnteringPin; - application->switchWindow( "MainWindow" ); - } - } + application->switchWindow(gui::name::window::main_window); + } + } else if( state == State::PhoneBlocked) { if( inputEvent.keyCode == KeyCode::KEY_RF ) { - application->switchWindow( "MainWindow" ); - return true; - } + application->switchWindow(gui::name::window::main_window); + return true; + } } } diff --git a/module-apps/application-messages/ApplicationMessages.cpp b/module-apps/application-messages/ApplicationMessages.cpp index 84e22a0b2..cf6fce590 100644 --- a/module-apps/application-messages/ApplicationMessages.cpp +++ b/module-apps/application-messages/ApplicationMessages.cpp @@ -44,9 +44,9 @@ sys::Message_t ApplicationMessages::DataReceivedHandler(sys::DataMessage *msgl, uint32_t msgType = resp->responseTo; switch (msgType) { case static_cast(MessageType::DBThreadGetLimitOffset): { - if (currentWindow->onDatabaseMessage(resp)) - refreshWindow(gui::RefreshModes::GUI_REFRESH_FAST); - } + if (getCurrentWindow()->onDatabaseMessage(resp)) + refreshWindow(gui::RefreshModes::GUI_REFRESH_FAST); + } break; } } @@ -67,9 +67,9 @@ sys::ReturnCodes ApplicationMessages::InitHandler() { createUserInterface(); - setActiveWindow("MainWindow"); + setActiveWindow(gui::name::window::main_window); - return ret; + return ret; } sys::ReturnCodes ApplicationMessages::DeinitHandler() { diff --git a/module-apps/application-messages/windows/MessagesMainWindow.cpp b/module-apps/application-messages/windows/MessagesMainWindow.cpp index 37885e22f..3642e7327 100644 --- a/module-apps/application-messages/windows/MessagesMainWindow.cpp +++ b/module-apps/application-messages/windows/MessagesMainWindow.cpp @@ -29,12 +29,11 @@ namespace gui { -MessagesMainWindow::MessagesMainWindow(app::Application *app) : - AppWindow(app, "MainWindow"), threadModel { new ThreadModel(app) } { - setSize(style::window_width, style::window_height); - buildInterface(); - -} + MessagesMainWindow::MessagesMainWindow(app::Application *app) : AppWindow(app, gui::name::window::main_window), threadModel{new ThreadModel(app)} + { + setSize(style::window_width, style::window_height); + buildInterface(); + } void MessagesMainWindow::rebuild() { destroyInterface(); diff --git a/module-apps/application-notes/ApplicationNotes.cpp b/module-apps/application-notes/ApplicationNotes.cpp index 1cb7895c2..4a5ea1e43 100644 --- a/module-apps/application-notes/ApplicationNotes.cpp +++ b/module-apps/application-notes/ApplicationNotes.cpp @@ -41,9 +41,9 @@ sys::Message_t ApplicationNotes::DataReceivedHandler(sys::DataMessage* msgl,sys: uint32_t msgType = resp->responseTo; switch( msgType ) { case static_cast(MessageType::DBNotesGetLimitOffset): { - if( currentWindow->onDatabaseMessage( resp ) ) - refreshWindow( gui::RefreshModes::GUI_REFRESH_FAST ); - }break; + if (getCurrentWindow()->onDatabaseMessage(resp)) + refreshWindow(gui::RefreshModes::GUI_REFRESH_FAST); + }break; } } @@ -62,9 +62,9 @@ sys::ReturnCodes ApplicationNotes::InitHandler() { createUserInterface(); - setActiveWindow("MainWindow"); + setActiveWindow(gui::name::window::main_window); - return ret; + return ret; } sys::ReturnCodes ApplicationNotes::DeinitHandler() { diff --git a/module-apps/application-notes/windows/NotesMainWindow.cpp b/module-apps/application-notes/windows/NotesMainWindow.cpp index 5c1bf0f5f..00f15d600 100644 --- a/module-apps/application-notes/windows/NotesMainWindow.cpp +++ b/module-apps/application-notes/windows/NotesMainWindow.cpp @@ -23,13 +23,12 @@ namespace gui { -NotesMainWindow::NotesMainWindow( app::Application* app ) : - AppWindow(app,"MainWindow"), - notesModel{ new NotesModel( app ) }{ - setSize( 480, 600 ); + NotesMainWindow::NotesMainWindow(app::Application *app) : AppWindow(app, gui::name::window::main_window), notesModel{new NotesModel(app)} + { + setSize(480, 600); - buildInterface(); -} + buildInterface(); + } void NotesMainWindow::rebuild() { destroyInterface(); diff --git a/module-apps/application-phonebook/ApplicationPhonebook.cpp b/module-apps/application-phonebook/ApplicationPhonebook.cpp index 2df55f881..d8c100cb1 100644 --- a/module-apps/application-phonebook/ApplicationPhonebook.cpp +++ b/module-apps/application-phonebook/ApplicationPhonebook.cpp @@ -44,7 +44,7 @@ sys::Message_t ApplicationPhonebook::DataReceivedHandler(sys::DataMessage *msgl, switch (msgType) { case static_cast(MessageType::DBContactGetLimitOffset): { - if (currentWindow->onDatabaseMessage(resp)) + if (getCurrentWindow()->onDatabaseMessage(resp)) refreshWindow(gui::RefreshModes::GUI_REFRESH_FAST); } break; @@ -67,7 +67,6 @@ sys::ReturnCodes ApplicationPhonebook::InitHandler() createUserInterface(); - setActiveWindow("MainWindow"); return ret; } diff --git a/module-apps/application-phonebook/windows/PhonebookDialogs.cpp b/module-apps/application-phonebook/windows/PhonebookDialogs.cpp index 04f2ea0b3..8f215fafc 100644 --- a/module-apps/application-phonebook/windows/PhonebookDialogs.cpp +++ b/module-apps/application-phonebook/windows/PhonebookDialogs.cpp @@ -127,7 +127,7 @@ void PhonebookDeleteContact::onBeforeShow(ShowMode mode, SwitchData *data) LOG_ERROR("failed to delete contact with id %d", contact->dbID); } - application->switchWindow("MainWindow", gui::ShowMode::GUI_SHOW_INIT, nullptr); + application->switchWindow(gui::name::window::main_window, gui::ShowMode::GUI_SHOW_INIT, nullptr); return (true); } return (false); diff --git a/module-apps/application-phonebook/windows/PhonebookMainWindow.cpp b/module-apps/application-phonebook/windows/PhonebookMainWindow.cpp index 72db0e2b7..a64e9d428 100644 --- a/module-apps/application-phonebook/windows/PhonebookMainWindow.cpp +++ b/module-apps/application-phonebook/windows/PhonebookMainWindow.cpp @@ -16,10 +16,10 @@ namespace gui { -PhonebookMainWindow::PhonebookMainWindow(app::Application *app) : AppWindow(app, "MainWindow"), phonebookModel{new PhonebookModel(app)} -{ - setSize(style::window_width, style::window_height); - buildInterface(); + PhonebookMainWindow::PhonebookMainWindow(app::Application *app) : AppWindow(app, gui::name::window::main_window), phonebookModel{new PhonebookModel(app)} + { + setSize(style::window_width, style::window_height); + buildInterface(); } void PhonebookMainWindow::rebuild() diff --git a/module-apps/application-settings/ApplicationSettings.cpp b/module-apps/application-settings/ApplicationSettings.cpp index 12775e9e6..e1de7dda7 100644 --- a/module-apps/application-settings/ApplicationSettings.cpp +++ b/module-apps/application-settings/ApplicationSettings.cpp @@ -61,9 +61,9 @@ sys::ReturnCodes ApplicationSettings::InitHandler() { createUserInterface(); - setActiveWindow("MainWindow"); + setActiveWindow(gui::name::window::main_window); - return ret; + return ret; } sys::ReturnCodes ApplicationSettings::DeinitHandler() { diff --git a/module-apps/application-settings/windows/SettingsMainWindow.cpp b/module-apps/application-settings/windows/SettingsMainWindow.cpp index ec976f063..66766caf1 100644 --- a/module-apps/application-settings/windows/SettingsMainWindow.cpp +++ b/module-apps/application-settings/windows/SettingsMainWindow.cpp @@ -24,11 +24,12 @@ namespace gui { -SettingsMainWindow::SettingsMainWindow( app::Application* app ) : AppWindow(app,"MainWindow"){ - setSize( 480, 600 ); + SettingsMainWindow::SettingsMainWindow(app::Application *app) : AppWindow(app, gui::name::window::main_window) + { + setSize(480, 600); - buildInterface(); -} + buildInterface(); + } void SettingsMainWindow::rebuild() { destroyInterface(); diff --git a/module-apps/application-special-input/AppSpecialInput.cpp b/module-apps/application-special-input/AppSpecialInput.cpp index 994276c74..15fb54a9a 100644 --- a/module-apps/application-special-input/AppSpecialInput.cpp +++ b/module-apps/application-special-input/AppSpecialInput.cpp @@ -30,6 +30,6 @@ sys::ReturnCodes AppSpecialInput::InitHandler() { LOG_ERROR(""); } - setActiveWindow("MainWindow"); + setActiveWindow(gui::name::window::main_window); return ret; } diff --git a/module-apps/application-special-input/AppSpecialInput.hpp b/module-apps/application-special-input/AppSpecialInput.hpp index 561dd9d53..8f39777cd 100644 --- a/module-apps/application-special-input/AppSpecialInput.hpp +++ b/module-apps/application-special-input/AppSpecialInput.hpp @@ -7,7 +7,7 @@ namespace app { inline const std::string special_input = "AppSpecialInput"; - inline const std::string char_select = "MainWindow"; + inline const std::string char_select = gui::name::window::main_window; // app just to provide input selection on UI class AppSpecialInput : public app::Application diff --git a/module-apps/application-viewer/windows/ViewWindow.cpp b/module-apps/application-viewer/windows/ViewWindow.cpp index 6755ae7b9..9258bf687 100644 --- a/module-apps/application-viewer/windows/ViewWindow.cpp +++ b/module-apps/application-viewer/windows/ViewWindow.cpp @@ -15,11 +15,12 @@ namespace gui { -ViewWindow::ViewWindow( app::Application* app ) : AppWindow(app,"MainWindow"){ - setSize( 480, 600 ); + ViewWindow::ViewWindow(app::Application *app) : AppWindow(app, gui::name::window::main_window) + { + setSize(480, 600); - buildInterface(); -} + buildInterface(); + } void ViewWindow::rebuild() { destroyInterface(); diff --git a/module-apps/messages/AppMessage.hpp b/module-apps/messages/AppMessage.hpp index 5ab3dc9bc..d8fc1d316 100644 --- a/module-apps/messages/AppMessage.hpp +++ b/module-apps/messages/AppMessage.hpp @@ -81,17 +81,17 @@ protected: gui::ShowMode command; std::unique_ptr data; public: - AppSwitchWindowMessage() = delete; + bool LastSeenWindow = false; + AppSwitchWindowMessage() = delete; - AppSwitchWindowMessage( const std::string& window, const std::string senderWindow, std::unique_ptr data, const gui::ShowMode command = gui::ShowMode::GUI_SHOW_INIT) : - AppMessage( MessageType::AppSwitchWindow ), - window{window}, - senderWindow{ senderWindow }, - command{ command }, - data{std::move(data)} {}; - virtual ~AppSwitchWindowMessage() = default; + AppSwitchWindowMessage(const std::string &window, const std::string senderWindow, std::unique_ptr data, + const gui::ShowMode command = gui::ShowMode::GUI_SHOW_INIT) + : AppMessage(MessageType::AppSwitchWindow), window{window}, senderWindow{senderWindow}, command{command}, data{std::move(data)} {}; + virtual ~AppSwitchWindowMessage() = default; - const std::string& getWindowName() const { return window; }; + const std::string &getWindowName() const + { + return window; }; const std::string& getSenderWindowName() const { return senderWindow; }; const gui::ShowMode& getCommand() const { return command; }; std::unique_ptr& getData() { return data; }; diff --git a/module-apps/windows/AppWindow.cpp b/module-apps/windows/AppWindow.cpp index a142a5406..e0a194170 100644 --- a/module-apps/windows/AppWindow.cpp +++ b/module-apps/windows/AppWindow.cpp @@ -140,16 +140,18 @@ bool AppWindow::onInput( const InputEvent& inputEvent) { if (inputEvent.state == InputEvent::State::keyReleasedLong && inputEvent.keyCode == gui::KeyCode::KEY_RF) { LOG_INFO("exit to main menu"); - sapm::ApplicationManager::messageSwitchApplication(application, app::name_desktop, "MainWindow", nullptr); + sapm::ApplicationManager::messageSwitchApplication(application, app::name_desktop, gui::name::window::main_window, nullptr); } //process only if key is released if(( inputEvent.state != InputEvent::State::keyReleasedShort )) return false; if( inputEvent.keyCode == KeyCode::KEY_RF ) { - if (prevWindow == getName() || getName() == "MainWindow") + auto prevWindow = application->getPrevWindow(); + if (prevWindow == gui::name::window::no_window) { LOG_INFO("Back to previous application"); - sapm::ApplicationManager::messageSwitchPreviousApplication(application); + application->cleanPrevWindw(); + sapm::ApplicationManager::messageSwitchPreviousApplication(application); } else { diff --git a/module-apps/windows/AppWindow.hpp b/module-apps/windows/AppWindow.hpp index 18c7ea4f9..73ded1068 100644 --- a/module-apps/windows/AppWindow.hpp +++ b/module-apps/windows/AppWindow.hpp @@ -21,6 +21,14 @@ namespace app { namespace gui { + namespace name + { + namespace window + { + const inline std::string main_window = "MainWindow"; + const inline std::string no_window = ""; + } // namespace window + } // namespace name /* * @brief This is wrapper for gui window used within applications. @@ -44,7 +52,6 @@ protected: app::Application* application = nullptr; uint32_t calculateBatteryLavel( uint32_t percentage ); - std::string prevWindow = ""; public: AppWindow( app::Application* app, std::string name, uint32_t id=GUIWindowID++ ); @@ -68,9 +75,6 @@ public: void destroyInterface() override; bool onInput( const InputEvent& inputEvent ) override; std::list buildDrawList() override; - - void setPrevWindow( const std::string& prevWindow ) { this->prevWindow = prevWindow; }; - const std::string& getPrevWindow() const { return prevWindow; }; }; } /* namespace gui */ diff --git a/module-services/service-appmgr/ApplicationManager.cpp b/module-services/service-appmgr/ApplicationManager.cpp index 52b386670..0ab08fb63 100644 --- a/module-services/service-appmgr/ApplicationManager.cpp +++ b/module-services/service-appmgr/ApplicationManager.cpp @@ -303,9 +303,9 @@ void ApplicationManager::TickHandler(uint32_t id) { if( focusApplicationName == "ApplicationDesktop") { //switch data must contain target window and information about blocking - app::Application::messageSwitchApplication(this, "ApplicationDesktop", "MainWindow", std::make_unique() ); - } - else { + app::Application::messageSwitchApplication(this, "ApplicationDesktop", gui::name::window::main_window, std::make_unique()); + } + else { //get the application description for application that is on top and set blocking flag for it appDescription->blockClosing = true; @@ -313,9 +313,9 @@ void ApplicationManager::TickHandler(uint32_t id) { data->setPrevApplication( focusApplicationName ); //run normal flow of applications change - messageSwitchApplication(this, "ApplicationDesktop", "MainWindow", std::move(data) ); - } - } + messageSwitchApplication(this, "ApplicationDesktop", gui::name::window::main_window, std::move(data)); + } + } #endif } @@ -620,6 +620,7 @@ bool ApplicationManager::handleRegisterApplication( APMRegister* msg ) { else { app->setState(app::Application::State::ACTIVATING); setState(State::WAITING_GET_FOCUS_CONFIRMATION); + LOG_INFO("switchApplication %s %s", launchApplicationName.c_str(), app->switchData ? app->switchData->getDescription().c_str() : ""); app::Application::messageSwitchApplication(this, launchApplicationName, app->switchWindow, std::move(app->switchData)); } } @@ -751,12 +752,11 @@ bool ApplicationManager::handleCloseConfirmation(APMConfirmClose *msg) //Static methods -bool ApplicationManager::messageSwitchApplication( sys::Service* sender, const std::string& applicationName, - const std::string& windowName, std::unique_ptr data) { - - auto msg = std::make_shared( sender->GetName(), applicationName, windowName, std::move(data) ); - sys::Bus::SendUnicast(msg, "ApplicationManager", sender); - return true; +bool ApplicationManager::messageSwitchApplication(sys::Service *sender, const std::string &applicationName, const std::string &windowName, + std::unique_ptr data) +{ + auto msg = std::make_shared(sender->GetName(), applicationName, windowName, std::move(data)); + return sys::Bus::SendUnicast(msg, "ApplicationManager", sender); } bool ApplicationManager::messageSwitchSpecialInput(sys::Service *sender, std::unique_ptr data)