TizenRefApp-5831 Implement app control termination after last view destruction 86/61986/2
authorEugene Kurzberg <i.kurtsberg@samsung.com>
Fri, 11 Mar 2016 15:23:40 +0000 (17:23 +0200)
committerEugene Kurzberg <i.kurtsberg@samsung.com>
Mon, 14 Mar 2016 07:33:24 +0000 (09:33 +0200)
Change-Id: I33a4f5e6bb5fb2a860b00f4b29e487ea671ed764
Signed-off-by: Eugene Kurzberg <i.kurtsberg@samsung.com>
15 files changed:
lib-apps-common/inc/Ui/Navigator.h
lib-apps-common/inc/Ui/Window.h
lib-apps-common/src/Ui/Navigator.cpp
lib-apps-common/src/Ui/Window.cpp
main-app/inc/MainApp.h
main-app/inc/OperationController.h
main-app/inc/OperationEditController.h
main-app/inc/OperationPickController.h
main-app/inc/OperationViewController.h
main-app/src/MainApp.cpp
main-app/src/OperationController.cpp
main-app/src/OperationDefaultController.cpp
main-app/src/OperationEditController.cpp
main-app/src/OperationPickController.cpp
main-app/src/OperationViewController.cpp

index 905a326..4c17bd0 100644 (file)
@@ -32,6 +32,13 @@ namespace Ui
        {
        public:
                /**
+                * @brief Called when the navigator is about to navigate away
+                *        from it's last remaining page.
+                * @return Whether to navigate from the last page.
+                */
+               typedef std::function<bool()> LastPageCallback;
+
+               /**
                 * @return Currently displayed page.
                 */
                virtual NavigatorPage *getCurrentPage() const = 0;
@@ -54,6 +61,17 @@ namespace Ui
                 */
                bool navigateFrom(View *view);
 
+               /**
+                * @brief Set last page callback.
+                * @param[in]   callback    Last page navigation callback.
+                */
+               void setLastPageCallback(LastPageCallback callback);
+
+               /**
+                * @brief Unset last page callback.
+                */
+               void unsetLastPageCallback();
+
        protected:
                Navigator(NavigatorType type);
 
@@ -104,6 +122,7 @@ namespace Ui
 
                NavigatorType m_Type;
                size_t m_PageCount;
+               LastPageCallback m_OnLastPage;
        };
 }
 
index dfea817..d7039ab 100644 (file)
@@ -31,12 +31,6 @@ namespace Ui
        class EXPORT_API Window : public Control
        {
        public:
-               /**
-                * @brief Called when "back" button was pressed and wasn't handled by any view.
-                * @return true to lower the window, otherwise false.
-                */
-               typedef std::function<bool()> BackCallback;
-
                Window();
 
                /**
@@ -50,17 +44,6 @@ namespace Ui
                Evas_Object *getBaseLayout() const;
 
                /**
-                * @brief Set "back" button callback.
-                * @param[in]   callback    "back" button callback
-                */
-               void setBackCallback(BackCallback callback);
-
-               /**
-                * @brief Unset "back" button callback.
-                */
-               void unsetBackCallback();
-
-               /**
                 * @brief Attach main View to be displayed in the Window.
                 * @param[in]   view    Window main View
                 */
@@ -74,7 +57,6 @@ namespace Ui
                Evas_Object *m_Conform;
                Evas_Object *m_Layout;
                View *m_MainView;
-               BackCallback m_OnBackPressed;
        };
 }
 
index 38d43e6..9f0c0d4 100644 (file)
@@ -67,10 +67,12 @@ bool Navigator::navigateFrom(View *view)
        }
 
        if (getPageCount() == 1) {
-               NavigatorPage *page = getPage();
-               if (page) {
-                       page->close();
-                       return true;
+               if (!m_OnLastPage || m_OnLastPage()) {
+                       NavigatorPage *page = getPage();
+                       if (page) {
+                               page->close();
+                               return true;
+                       }
                }
 
                return false;
@@ -80,6 +82,16 @@ bool Navigator::navigateFrom(View *view)
        return true;
 }
 
+void Navigator::setLastPageCallback(LastPageCallback callback)
+{
+       m_OnLastPage = std::move(callback);
+}
+
+void Navigator::unsetLastPageCallback()
+{
+       m_OnLastPage = nullptr;
+}
+
 void Navigator::notifyNavigation(NavigatorPage *page, bool isCurrent)
 {
        if (page) {
index 0fba71f..b110e73 100644 (file)
@@ -69,16 +69,6 @@ Evas_Object *Window::getBaseLayout() const
        return m_Layout;
 }
 
-void Window::setBackCallback(BackCallback callback)
-{
-       m_OnBackPressed = std::move(callback);
-}
-
-void Window::unsetBackCallback()
-{
-       m_OnBackPressed = nullptr;
-}
-
 void Window::attachView(View *view)
 {
        m_MainView = view;
@@ -88,9 +78,7 @@ void Window::attachView(View *view)
 void Window::onBackPressed(Evas_Object *obj, void *eventInfo)
 {
        if (!m_MainView || m_MainView->onBackPressed()) {
-               if (!m_OnBackPressed || m_OnBackPressed()) {
-                       elm_win_lower(getEvasObject());
-               }
+               elm_win_lower(getEvasObject());
        }
 }
 
index 470016e..f7d1026 100755 (executable)
@@ -33,16 +33,6 @@ class MainApp : public App::Application
 public:
        MainApp();
 
-       /**
-        * @return Application main Window
-        */
-       Ui::Window *getWindow() const;
-
-       /**
-        * @return Application main Navigator
-        */
-       Ui::Navigator *getNavigator() const;
-
 private:
        virtual bool onCreate() override;
        virtual void onAppControl(app_control_h request) override;
index 393d7f2..7a86238 100644 (file)
 #define OPERATION_CONTROLLER_H
 
 #include <app_control.h>
+#include <Evas.h>
+
+namespace Ui
+{
+       class Navigator;
+       class Window;
+}
 
 enum Operation
 {
@@ -30,8 +37,6 @@ enum Operation
        OperationPick    = 1 << 5
 };
 
-class MainApp;
-
 /**
  * @brief Handles operations requested through App Control
  */
@@ -42,9 +47,10 @@ public:
 
        /**
         * @brief Create operation controller
-        * @param[in]   application     Main application instance
+        * @param[in]   window      Main application Window
+        * @param[in]   navigator   Main application Navigator
         */
-       void create(MainApp *application);
+       void create(Ui::Window *window, Ui::Navigator *navigator);
 
        /**
         * @brief Request the controller to handle the operation
@@ -77,14 +83,20 @@ protected:
        /**
         * @brief Create operation controller
         * @param[in]   supportedOperations     Supported operations mask
+        * @param[in]   isMinimizable           Whether application can be minimized
         * @see Operation
         */
-       OperationController(int supportedOperations);
+       OperationController(int supportedOperations, bool isMinimizable = false);
+
+       /**
+        * @return Main application Window
+        */
+       Ui::Window *getWindow() const;
 
        /**
-        * @return Main application instance
+        * @return Main application Navigator
         */
-       MainApp *getApplication() const;
+       Ui::Navigator *getNavigator() const;
 
        /**
         * @return Last received request
@@ -107,9 +119,14 @@ protected:
        virtual void onRequest(Operation operation, app_control_h request) = 0;
 
 private:
+       static void onWindowLowered(void *data, Evas_Object *obj, void *eventInfo);
+
        int m_SupportedOperations;
-       MainApp *m_Application;
        app_control_h m_Request;
+       bool m_IsMinimizable;
+
+       Ui::Window *m_Window;
+       Ui::Navigator *m_Navigator;
 };
 
 #endif /* OPERATION_CONTROLLER_H */
index 8f26b2b..ef7e335 100644 (file)
@@ -30,11 +30,9 @@ class OperationEditController : public OperationController
 {
 public:
        OperationEditController();
-       virtual ~OperationEditController() override;
 
 private:
        virtual void onRequest(Operation operation, app_control_h request);
-       virtual void onCreate() override;
 
        Ui::View *createInputView(int personId);
 
index 9890373..6e6f8ee 100644 (file)
@@ -32,10 +32,8 @@ class OperationPickController : public OperationController
 {
 public:
        OperationPickController();
-       virtual ~OperationPickController();
 
 private:
-       virtual void onCreate() override;
        virtual void onRequest(Operation operation, app_control_h request) override;
        bool onSelected(Contacts::SelectResults results);
 
@@ -43,7 +41,6 @@ private:
        static Contacts::ResultType getResultType(app_control_h request);
        static const char *getResultTypeString(Contacts::ResultType resultType);
 
-       Ui::Navigator *m_Navigator;
        Contacts::SelectMode m_SelectMode;
        Contacts::ResultType m_ResultType;
 };
index f51a284..074b5d5 100644 (file)
@@ -24,10 +24,8 @@ class OperationViewController : public OperationController
 {
 public:
        OperationViewController();
-       virtual ~OperationViewController();
 
 private:
-       virtual void onCreate();
        virtual void onRequest(Operation operation, app_control_h request);
 };
 
index 6a66b9a..c0bdfbc 100755 (executable)
@@ -34,16 +34,6 @@ MainApp::MainApp()
 {
 }
 
-Ui::Window *MainApp::getWindow() const
-{
-       return m_Window;
-}
-
-Ui::Navigator *MainApp::getNavigator() const
-{
-       return m_Navigator;
-}
-
 bool MainApp::onCreate()
 {
        int err = contacts_connect();
@@ -95,7 +85,7 @@ void MainApp::onAppControl(app_control_h request)
                }
 
                if (m_Controller) {
-                       m_Controller->create(this);
+                       m_Controller->create(m_Window, m_Navigator);
                }
        }
 
index 24fb407..5a54f63 100644 (file)
  */
 
 #include "OperationController.h"
+#include "Ui/Navigator.h"
+#include "Ui/Window.h"
 
+#include <app.h>
 #include <string.h>
 
-OperationController::OperationController(int supportedOperations)
-       : m_SupportedOperations(supportedOperations), m_Application(nullptr), m_Request(nullptr)
+OperationController::OperationController(int supportedOperations, bool isMinimizable)
+       : m_SupportedOperations(supportedOperations), m_Request(nullptr), m_IsMinimizable(isMinimizable),
+         m_Window(nullptr), m_Navigator(nullptr)
 {
 }
 
 OperationController::~OperationController()
 {
        app_control_destroy(m_Request);
+
+       if (!m_IsMinimizable) {
+               m_Navigator->unsetLastPageCallback();
+               evas_object_smart_callback_del_full(m_Window->getEvasObject(),
+                               "iconified", &OperationController::onWindowLowered, this);
+       }
 }
 
-void OperationController::create(MainApp *application)
+void OperationController::create(Ui::Window *window, Ui::Navigator *navigator)
 {
-       m_Application = application;
+       m_Window = window;
+       m_Navigator = navigator;
+
+       if (!m_IsMinimizable) {
+               m_Navigator->setLastPageCallback([] {
+                       ui_app_exit();
+                       return true;
+               });
+       }
+
        onCreate();
 }
 
@@ -39,6 +58,17 @@ void OperationController::request(Operation operation, app_control_h request)
 {
        app_control_destroy(m_Request);
        app_control_clone(&m_Request, request);
+
+       if (!m_IsMinimizable) {
+               app_control_launch_mode_e launchMode = APP_CONTROL_LAUNCH_MODE_SINGLE;
+               app_control_get_launch_mode(m_Request, &launchMode);
+
+               if (launchMode == APP_CONTROL_LAUNCH_MODE_SINGLE) {
+                       evas_object_smart_callback_add(m_Window->getEvasObject(),
+                                       "iconified", &OperationController::onWindowLowered, this);
+               }
+       }
+
        onRequest(operation, m_Request);
 }
 
@@ -74,9 +104,14 @@ Operation OperationController::getOperation(const char *operation)
        return OperationDefault;
 }
 
-MainApp *OperationController::getApplication() const
+Ui::Window *OperationController::getWindow() const
+{
+       return m_Window;
+}
+
+Ui::Navigator *OperationController::getNavigator() const
 {
-       return m_Application;
+       return m_Navigator;
 }
 
 app_control_h OperationController::getRequest() const
@@ -91,3 +126,8 @@ void OperationController::replyFailure()
        app_control_reply_to_launch_request(reply, m_Request, APP_CONTROL_RESULT_FAILED);
        app_control_destroy(reply);
 }
+
+void OperationController::onWindowLowered(void *data, Evas_Object *obj, void *eventInfo)
+{
+       ui_app_exit();
+}
index 78f4c30..c89e2f3 100644 (file)
@@ -32,7 +32,7 @@
 #define PREFERENCE_KEY_LAST_TAB "last_tab"
 
 OperationDefaultController::OperationDefaultController()
-       : OperationController(OperationDefault | OperationDial),
+       : OperationController(OperationDefault | OperationDial, true),
          m_Navigator(nullptr), m_Tabs{nullptr}
 {
 }
@@ -44,9 +44,8 @@ OperationDefaultController::~OperationDefaultController()
 
 void OperationDefaultController::onCreate()
 {
-       Ui::Navigator *mainNavigator = getApplication()->getNavigator();
        m_Navigator = new Ui::TabView();
-       mainNavigator->navigateTo(m_Navigator);
+       getNavigator()->navigateTo(m_Navigator);
 
        m_Tabs[TabDialer] = new Phone::Dialer::DialerView();
        m_Tabs[TabLogs] = new Logs::List::LogsView();
index 8465a3c..45ca19a 100644 (file)
@@ -24,7 +24,6 @@
 
 #include "App/AppControlRequest.h"
 #include "Ui/Navigator.h"
-#include "Ui/Window.h"
 
 #include <string>
 
@@ -39,19 +38,6 @@ OperationEditController::OperationEditController()
 {
 }
 
-OperationEditController::~OperationEditController()
-{
-       getApplication()->getWindow()->unsetBackCallback();
-}
-
-void OperationEditController::onCreate()
-{
-       getApplication()->getWindow()->setBackCallback([] {
-               ui_app_exit();
-               return true;
-       });
-}
-
 void OperationEditController::onRequest(Operation operation, app_control_h request)
 {
        Ui::View *view = nullptr;
@@ -66,7 +52,7 @@ void OperationEditController::onRequest(Operation operation, app_control_h reque
                view = createInputView(personId);
        }
 
-       getApplication()->getNavigator()->navigateTo(view);
+       getNavigator()->navigateTo(view);
 }
 
 Ui::View *OperationEditController::createInputView(int personId)
@@ -100,7 +86,7 @@ Ui::View *OperationEditController::createInputView(int personId)
 bool OperationEditController::onSelectResult(SelectResults results)
 {
        Ui::View *view = createInputView(results.begin()->value.id);
-       getApplication()->getNavigator()->navigateTo(view);
+       getNavigator()->navigateTo(view);
        return true;
 }
 
@@ -113,6 +99,4 @@ void OperationEditController::onInputResult(int contactId)
        app_control_add_extra_data(reply, APP_CONTROL_DATA_ID, std::to_string(personId).c_str());
        app_control_reply_to_launch_request(reply, getRequest(), APP_CONTROL_RESULT_SUCCEEDED);
        app_control_destroy(reply);
-
-       ui_app_exit();
 }
index 0742faa..a84a181 100644 (file)
@@ -22,7 +22,6 @@
 
 #include "App/AppControlRequest.h"
 #include "Ui/Navigator.h"
-#include "Ui/Window.h"
 
 #include <vector>
 
@@ -34,25 +33,10 @@ using namespace std::placeholders;
 
 OperationPickController::OperationPickController()
        : OperationController(OperationPick),
-         m_Navigator(nullptr),
          m_SelectMode(SelectSingle), m_ResultType(ResultPerson)
 {
 }
 
-OperationPickController::~OperationPickController()
-{
-       getApplication()->getWindow()->unsetBackCallback();
-}
-
-void OperationPickController::onCreate()
-{
-       m_Navigator = getApplication()->getNavigator();
-       getApplication()->getWindow()->setBackCallback([] {
-               ui_app_exit();
-               return true;
-       });
-}
-
 void OperationPickController::onRequest(Operation operation, app_control_h request)
 {
        m_SelectMode = getSelectMode(request);
@@ -61,7 +45,7 @@ void OperationPickController::onRequest(Operation operation, app_control_h reque
        int limit = App::getIntExtraData(request, APP_CONTROL_DATA_TOTAL_COUNT);
        Chooser *chooser = new Chooser(m_SelectMode, m_ResultType, limit);
        chooser->setSelectCallback(std::bind(&OperationPickController::onSelected, this, _1));
-       m_Navigator->navigateTo(chooser);
+       getNavigator()->navigateTo(chooser);
 }
 
 bool OperationPickController::onSelected(SelectResults results)
@@ -84,7 +68,6 @@ bool OperationPickController::onSelected(SelectResults results)
        app_control_reply_to_launch_request(reply, getRequest(), APP_CONTROL_RESULT_SUCCEEDED);
        app_control_destroy(reply);
 
-       ui_app_exit();
        return true;
 }
 
index 59d871c..724f3d8 100644 (file)
@@ -24,7 +24,6 @@
 
 #include "App/AppControlRequest.h"
 #include "Ui/Navigator.h"
-#include "Ui/Window.h"
 
 #include <string.h>
 
@@ -37,19 +36,6 @@ OperationViewController::OperationViewController()
 {
 }
 
-OperationViewController::~OperationViewController()
-{
-       getApplication()->getWindow()->unsetBackCallback();
-}
-
-void OperationViewController::onCreate()
-{
-       getApplication()->getWindow()->setBackCallback([] {
-               ui_app_exit();
-               return true;
-       });
-}
-
 void OperationViewController::onRequest(Operation operation, app_control_h request)
 {
        Ui::View *view = nullptr;
@@ -74,7 +60,7 @@ void OperationViewController::onRequest(Operation operation, app_control_h reque
        free(mime);
 
        if (view) {
-               getApplication()->getNavigator()->navigateTo(view);
+               getNavigator()->navigateTo(view);
        } else {
                ui_app_exit();
        }