Moved common application architecture to apps-common. 07/94507/5
authorEugene Kurzberg <i.kurtsberg@samsung.com>
Mon, 31 Oct 2016 09:42:23 +0000 (11:42 +0200)
committerGerrit Code Review <gerrit@review.vlan103.tizen.org>
Tue, 1 Nov 2016 08:44:11 +0000 (01:44 -0700)
Refactored OperationController.

Change-Id: I9f84e0b49da343fb9e883c5a323db20108b2decd
Signed-off-by: Eugene Kurzberg <i.kurtsberg@samsung.com>
19 files changed:
contacts-app/inc/ContactsApp.h [moved from contacts-app/inc/MainApp.h with 59% similarity, mode: 0644]
contacts-app/inc/OperationController.h [deleted file]
contacts-app/inc/OperationDefaultController.h
contacts-app/inc/OperationEditController.h
contacts-app/inc/OperationPickController.h
contacts-app/inc/OperationViewController.h
contacts-app/src/ContactsApp.cpp [new file with mode: 0644]
contacts-app/src/MainApp.cpp [deleted file]
contacts-app/src/OperationDefaultController.cpp
contacts-app/src/OperationEditController.cpp
contacts-app/src/OperationPickController.cpp
contacts-app/src/OperationViewController.cpp
contacts-app/src/main.cpp
lib-apps-common/inc/App/Application.h
lib-apps-common/inc/App/OperationController.h [new file with mode: 0644]
lib-apps-common/inc/App/Path.h
lib-apps-common/src/App/Application.cpp
lib-apps-common/src/App/OperationController.cpp [moved from contacts-app/src/OperationController.cpp with 55% similarity]
lib-apps-common/src/App/Path.cpp

old mode 100755 (executable)
new mode 100644 (file)
similarity index 59%
rename from contacts-app/inc/MainApp.h
rename to contacts-app/inc/ContactsApp.h
index 9094adf..a69769a
  *
  */
 
-#ifndef MAIN_APP_H
-#define MAIN_APP_H
+#ifndef CONTACTS_APP_H
+#define CONTACTS_APP_H
 
 #include "App/Application.h"
 
-namespace Ui
+class ContactsApp : public App::Application
 {
-       class Naviframe;
-       class Window;
-}
-
-class OperationController;
-
-class MainApp : public App::Application
-{
-public:
-       MainApp();
-
 private:
+       virtual App::OperationController *createController(const char *operation) override;
        virtual bool onCreate() override;
-       virtual void onAppControl(app_control_h request) override;
-       virtual void onPause() override;
-       virtual void onResume() override;
        virtual void onTerminate() override;
-       static void onLanguageChanged(app_event_info_h event, void *data);
-       static void updateLanguage();
-
-       Ui::Window *m_Window;
-       Ui::Naviframe *m_Navigator;
-       OperationController *m_Controller;
 };
 
-#endif /* MAIN_APP_H */
+#endif /* CONTACTS_APP_H */
diff --git a/contacts-app/inc/OperationController.h b/contacts-app/inc/OperationController.h
deleted file mode 100644 (file)
index 3196fa2..0000000
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- * Copyright (c) 2015-2016 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef OPERATION_CONTROLLER_H
-#define OPERATION_CONTROLLER_H
-
-#include <app.h>
-#include <Evas.h>
-#include <string>
-
-namespace Ui
-{
-       class Navigator;
-       class Window;
-}
-
-enum Operation
-{
-       OperationDefault = 1 << 0,
-       OperationDial    = 1 << 1,
-       OperationAdd     = 1 << 2,
-       OperationEdit    = 1 << 3,
-       OperationView    = 1 << 4,
-       OperationPick    = 1 << 5
-};
-
-/**
- * @brief Handles operations requested through App Control
- */
-class OperationController
-{
-public:
-       virtual ~OperationController();
-
-       /**
-        * @brief Create operation controller
-        * @param[in]   window      Main application Window
-        * @param[in]   navigator   Main application Navigator
-        */
-       void create(Ui::Window *window, Ui::Navigator *navigator);
-
-       /**
-        * @brief Request the controller to handle the operation
-        */
-       void request(Operation operation, app_control_h request);
-
-       /**
-        * @brief Called when application receives pause event
-        */
-       virtual void onPause() { }
-
-       /**
-        * @brief Called when application receives resume event
-        */
-       virtual void onResume() { }
-
-       /**
-        * @brief Check if operation is supported by the controller
-        */
-       bool isOperationSupported(Operation operation) const;
-
-       /**
-        * @brief Get operation from string representation
-        * @param[in]   operation   Operation string representation
-        * @return Operation value
-        */
-       static Operation getOperation(const char *operation);
-
-protected:
-       /**
-        * @brief Create operation controller
-        * @param[in]   supportedOperations     Supported operations mask
-        * @param[in]   isMinimizable           Whether application can be minimized
-        * @see Operation
-        */
-       OperationController(int supportedOperations, bool isMinimizable = false);
-
-       /**
-        * @return Main application Window
-        */
-       Ui::Window *getWindow() const;
-
-       /**
-        * @return Main application Navigator
-        */
-       Ui::Navigator *getNavigator() const;
-
-       /**
-        * @return Last received request
-        */
-       app_control_h getRequest() const;
-
-       /**
-        * @brief Get URI without prefix (if present).
-        * @param[in]   scheme  Scheme prefix to remove (e.g. tel: or file://)
-        * @return URI without scheme.
-        */
-       std::string getUrn(const char *scheme) const;
-
-       /**
-        * @brief Send failure reply to the last request
-        */
-       void replyFailure();
-
-       /**
-        * @brief Called after create() is called
-        */
-       virtual void onCreate() { }
-
-       /**
-        * @brief Called when application receives App Control request
-        */
-       virtual void onRequest(Operation operation, app_control_h request) = 0;
-
-private:
-       int m_SupportedOperations;
-       app_control_h m_Request;
-       bool m_IsMinimizable;
-
-       Ui::Window *m_Window;
-       Ui::Navigator *m_Navigator;
-};
-
-#endif /* OPERATION_CONTROLLER_H */
index 5ae37af..b7f3de0 100644 (file)
 #ifndef OPERATION_DEFAULT_CONTROLLER_H
 #define OPERATION_DEFAULT_CONTROLLER_H
 
-#include "OperationController.h"
-#include <string>
+#include "App/OperationController.h"
 
 namespace Ui
 {
        class View;
-       class Navigator;
 }
 
-class OperationDefaultController : public OperationController
+class OperationDefaultController : public App::OperationController
 {
 public:
        OperationDefaultController();
@@ -44,7 +42,7 @@ private:
        };
 
        virtual void onCreate() override;
-       virtual void onRequest(Operation operation, app_control_h request) override;
+       virtual void onRequest(const char *operation, app_control_h request) override;
 
        static unsigned getBadgeCount(const char *package);
 
index d1ebd52..afffe77 100644 (file)
@@ -18,7 +18,7 @@
 #ifndef OPERATION_EDIT_CONTROLLER_H
 #define OPERATION_EDIT_CONTROLLER_H
 
-#include "OperationController.h"
+#include "App/OperationController.h"
 #include "Ux/SelectTypes.h"
 
 namespace Ui
@@ -26,13 +26,10 @@ namespace Ui
        class View;
 }
 
-class OperationEditController : public OperationController
+class OperationEditController : public App::OperationController
 {
-public:
-       OperationEditController();
-
 private:
-       virtual void onRequest(Operation operation, app_control_h request);
+       virtual void onRequest(const char *operation, app_control_h request) override;
 
        Ui::View *createInputView(int personId);
 
index f5b35fa..5c18079 100644 (file)
 #ifndef OPERATION_PICK_CONTROLLER_H
 #define OPERATION_PICK_CONTROLLER_H
 
-#include "OperationController.h"
+#include "App/OperationController.h"
 #include "Contacts/Chooser/ChooserView.h"
 
 using namespace Contacts;
 
-class OperationPickController : public OperationController
+class OperationPickController : public App::OperationController
 {
 public:
        OperationPickController();
 
 private:
-       virtual void onRequest(Operation operation, app_control_h request) override;
+       virtual void onRequest(const char *operation, app_control_h request) override;
        bool onSelected(Ux::SelectResults results);
 
        void replyIds(Ux::SelectResults results);
index ed8479c..ebde115 100644 (file)
 #ifndef OPERATION_VIEW_CONTROLLER_H
 #define OPERATION_VIEW_CONTROLLER_H
 
-#include "OperationController.h"
+#include "App/OperationController.h"
 
-class OperationViewController : public OperationController
+class OperationViewController : public App::OperationController
 {
-public:
-       OperationViewController();
-
 private:
-       virtual void onRequest(Operation operation, app_control_h request);
+       virtual void onRequest(const char *operation, app_control_h request) override;
 };
 
 #endif /* OPERATION_VIEW_CONTROLLER_H */
diff --git a/contacts-app/src/ContactsApp.cpp b/contacts-app/src/ContactsApp.cpp
new file mode 100644 (file)
index 0000000..1253a87
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2015-2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "ContactsApp.h"
+#include "App/Path.h"
+#include "Ui/Naviframe.h"
+#include "Utils/Logger.h"
+
+#include "OperationDefaultController.h"
+#include "OperationEditController.h"
+#include "OperationPickController.h"
+#include "OperationViewController.h"
+
+#include <contacts.h>
+
+App::OperationController *ContactsApp::createController(const char *operation)
+{
+       if (strcmp(operation, APP_CONTROL_OPERATION_DEFAULT) == 0
+                       || strcmp(operation, APP_CONTROL_OPERATION_DIAL) == 0) {
+               return new OperationDefaultController();
+       } else if (strcmp(operation, APP_CONTROL_OPERATION_ADD) == 0
+                       || strcmp(operation, APP_CONTROL_OPERATION_EDIT) == 0) {
+               return new OperationEditController();
+       } else if (strcmp(operation, APP_CONTROL_OPERATION_VIEW) == 0) {
+               return new OperationViewController();
+       } else if (strcmp(operation, APP_CONTROL_OPERATION_PICK) == 0) {
+               return new OperationPickController();
+       }
+
+       return nullptr;
+}
+
+bool ContactsApp::onCreate()
+{
+       int err = contacts_connect();
+       RETVM_IF_ERR(err, false, "contacts_connect() failed.");
+
+       bindtextdomain(TEXT_DOMAIN, App::getLocaleDir().c_str());
+       textdomain(TEXT_DOMAIN);
+
+       elm_config_focus_autoscroll_mode_set(ELM_FOCUS_AUTOSCROLL_MODE_NONE);
+       Application::onCreate();
+       getNavigator()->setFirstPagePrevButton(true);
+
+       return true;
+}
+
+void ContactsApp::onTerminate()
+{
+       Application::onTerminate();
+       contacts_disconnect();
+}
diff --git a/contacts-app/src/MainApp.cpp b/contacts-app/src/MainApp.cpp
deleted file mode 100755 (executable)
index 293ef05..0000000
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- * Copyright (c) 2015-2016 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include "MainApp.h"
-#include "App/Path.h"
-#include "Ui/Naviframe.h"
-#include "Ui/Scale.h"
-#include "Ui/Window.h"
-#include "Utils/Logger.h"
-
-#include "OperationDefaultController.h"
-#include "OperationEditController.h"
-#include "OperationPickController.h"
-#include "OperationViewController.h"
-
-#include <contacts.h>
-#include <system_settings.h>
-#include <utils_i18n_ulocale.h>
-
-MainApp::MainApp()
-       : m_Window(nullptr), m_Navigator(nullptr), m_Controller(nullptr)
-{
-}
-
-bool MainApp::onCreate()
-{
-       int err = contacts_connect();
-       RETVM_IF_ERR(err, false, "contacts_connect() failed.");
-
-       bindtextdomain(TEXT_DOMAIN, App::getLocaleDir().c_str());
-       textdomain(TEXT_DOMAIN);
-       updateLanguage();
-
-       app_event_handler_h handle = nullptr;
-       ui_app_add_event_handler(&handle, APP_EVENT_LANGUAGE_CHANGED,
-                       &MainApp::onLanguageChanged, this);
-
-       elm_config_focus_autoscroll_mode_set(ELM_FOCUS_AUTOSCROLL_MODE_NONE);
-       elm_app_base_scale_set(UI_BASE_SCALE);
-
-       m_Window = new Ui::Window();
-       m_Window->create(nullptr);
-
-       m_Navigator = new Ui::Naviframe();
-       m_Navigator->setFirstPagePrevButton(true);
-       m_Window->attachView(m_Navigator);
-
-       return true;
-}
-
-void MainApp::onAppControl(app_control_h request)
-{
-       char *operationStr = nullptr;
-       app_control_get_operation(request, &operationStr);
-
-       Operation operation = OperationController::getOperation(operationStr);
-       if (!m_Controller || !m_Controller->isOperationSupported(operation)) {
-               delete m_Controller;
-               m_Controller = nullptr;
-
-               switch (operation) {
-                       case OperationDefault:
-                       case OperationDial:
-                               m_Controller = new OperationDefaultController();
-                               break;
-                       case OperationAdd:
-                       case OperationEdit:
-                               m_Controller = new OperationEditController();
-                               break;
-                       case OperationView:
-                               m_Controller = new OperationViewController();
-                               break;
-                       case OperationPick:
-                               m_Controller = new OperationPickController();
-                               break;
-               }
-
-               if (m_Controller) {
-                       m_Controller->create(m_Window, m_Navigator);
-               }
-       }
-
-       if (m_Controller) {
-               m_Controller->request(operation, request);
-       }
-
-       free(operationStr);
-}
-
-void MainApp::onPause()
-{
-       if (m_Controller) {
-               m_Controller->onPause();
-       }
-}
-
-void MainApp::onResume()
-{
-       if (m_Controller) {
-               m_Controller->onResume();
-       }
-}
-
-void MainApp::onTerminate()
-{
-       delete m_Controller;
-       m_Controller = nullptr;
-
-       contacts_disconnect();
-}
-
-void MainApp::onLanguageChanged(app_event_info_h event, void *data)
-{
-       updateLanguage();
-}
-
-void MainApp::updateLanguage()
-{
-       char *lang = nullptr;
-       system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &lang);
-
-       i18n_ulocale_layout_type_e layout = I18N_ULOCALE_LAYOUT_UNKNOWN;
-       i18n_ulocale_get_character_orientation(lang, &layout);
-
-       elm_language_set(lang);
-       elm_config_mirrored_set(layout == I18N_ULOCALE_LAYOUT_RTL);
-       free(lang);
-}
index dfa51a8..9e833ce 100644 (file)
@@ -17,7 +17,6 @@
 
 #include "OperationDefaultController.h"
 
-#include "MainApp.h"
 #include "Contacts/List/ListView.h"
 #include "Logs/List/LogsView.h"
 #include "Phone/Dialer/DialerView.h"
@@ -41,7 +40,7 @@ using Logs::List::LogsView;
 using Phone::Dialer::DialerView;
 
 OperationDefaultController::OperationDefaultController()
-       : OperationController(OperationDefault | OperationDial, true),
+       : OperationController(true),
          m_Navigator(nullptr), m_Tabs{nullptr}
 {
 }
@@ -67,13 +66,13 @@ void OperationDefaultController::onCreate()
        }
 }
 
-void OperationDefaultController::onRequest(Operation operation, app_control_h request)
+void OperationDefaultController::onRequest(const char *operation, app_control_h request)
 {
        char *appId = nullptr;
        app_control_get_app_id(request, &appId);
 
        TabId selectedTab = TabContacts;
-       if (operation == OperationDial) {
+       if (strcmp(operation, APP_CONTROL_OPERATION_DIAL) == 0) {
                auto dialer = static_cast<DialerView *>(m_Tabs[TabDialer]);
                dialer->setNumber(getUrn(APP_CONTROL_URI_DIAL));
                selectedTab = TabDialer;
index e98f886..d2fa0f8 100644 (file)
@@ -24,8 +24,6 @@
 #include "App/AppControlRequest.h"
 #include "Ui/Navigator.h"
 
-#include <string>
-
 using namespace Common::Database;
 using namespace Contacts;
 using namespace Contacts::Input;
@@ -33,17 +31,12 @@ using namespace Contacts::List;
 using namespace Contacts::Model;
 using namespace std::placeholders;
 
-OperationEditController::OperationEditController()
-       : OperationController(OperationAdd | OperationEdit)
-{
-}
-
-void OperationEditController::onRequest(Operation operation, app_control_h request)
+void OperationEditController::onRequest(const char *operation, app_control_h request)
 {
        Ui::View *view = nullptr;
        int personId = App::getIntExtraData(request, APP_CONTROL_DATA_ID);
 
-       if (personId == 0 && operation == OperationEdit) {
+       if (personId == 0 && strcmp(operation, APP_CONTROL_OPERATION_EDIT) == 0) {
                auto *listView = new ListView();
                listView->setSelectMode(Ux::SelectSingle);
                listView->setSelectCallback(std::bind(&OperationEditController::onSelectResult, this, _1));
index 654edd1..fc63d79 100644 (file)
@@ -17,7 +17,6 @@
 
 #include "OperationPickController.h"
 
-#include "MainApp.h"
 #include "App/AppControlRequest.h"
 #include "Common/Actions.h"
 
@@ -30,12 +29,11 @@ using namespace Ux;
 using namespace std::placeholders;
 
 OperationPickController::OperationPickController()
-       : OperationController(OperationPick),
-         m_ResultType(ResultPersonId), m_IsMultiType(true)
+       : m_ResultType(ResultPersonId), m_IsMultiType(true)
 {
 }
 
-void OperationPickController::onRequest(Operation operation, app_control_h request)
+void OperationPickController::onRequest(const char *operation, app_control_h request)
 {
        char *dataType = nullptr;
        char **dataTypes = &dataType;
index 97588ba..b94b878 100644 (file)
@@ -33,12 +33,7 @@ using namespace Contacts;
 using namespace Contacts::Details;
 using namespace Contacts::List;
 
-OperationViewController::OperationViewController()
-       : OperationController(OperationView)
-{
-}
-
-void OperationViewController::onRequest(Operation operation, app_control_h request)
+void OperationViewController::onRequest(const char *operation, app_control_h request)
 {
        Ui::View *view = nullptr;
        char *mime = nullptr;
index 30fd50c..f873cef 100644 (file)
  *
  */
 
-#include "MainApp.h"
+#include "ContactsApp.h"
 #include "Utils/Logger.h"
 
 int main(int argc, char *argv[])
 {
        Utils::setLogTag("CONTACTS_APP");
-       return MainApp().run(argc, argv);
+       return ContactsApp().run(argc, argv);
 }
index d2159b6..54edfcd 100644 (file)
 
 #include <app.h>
 
+namespace Ui
+{
+       class Naviframe;
+       class Window;
+}
+
 namespace App
 {
+       class OperationController;
+
        /**
-        * @brief Application lifecycle controller.
+        * @brief UI Application lifecycle controller.
         */
        class EXPORT_API Application
        {
        public:
+               Application();
+               virtual ~Application() { }
+
                /**
                 * @brief Run application main loop.
                 * @param[in]   argc    argc parameter received in main()
@@ -36,34 +47,57 @@ namespace App
                int run(int argc, char **argv);
 
        protected:
-               virtual ~Application() { }
+               /**
+                * @brief Create corresponding controller for requested operation.
+                * @param[in]   operation   Requested operation
+                * @return Controller to handle the operation.
+                */
+               virtual OperationController *createController(const char *operation) = 0;
 
                /**
-                * @brief Called when application is created
-                * @return true on success, otherwise false
+                * @brief Called when application is created.
+                * @return true on success, otherwise false.
                 */
-               virtual bool onCreate() { return true; }
+               virtual bool onCreate();
 
                /**
-                * @brief Called when application is terminated
+                * @brief Called when application is terminated.
                 */
-               virtual void onTerminate() { }
+               virtual void onTerminate();
 
                /**
-                * @brief Called when application is paused
+                * @brief Called when application is paused.
                 */
-               virtual void onPause() { }
+               virtual void onPause();
 
                /**
-                * @brief Called when application is resumed
+                * @brief Called when application is resumed.
                 */
-               virtual void onResume() { }
+               virtual void onResume();
 
                /**
-                * @brief Called when application receives App Control request
+                * @brief Called when application receives App Control request.
                 * @param   request     App Control request
                 */
-               virtual void onAppControl(app_control_h request) { }
+               virtual void onAppControl(app_control_h request);
+
+               /**
+                * @return Main application Window.
+                */
+               Ui::Window *getWindow() const;
+
+               /**
+                * @return Main application Navigator.
+                */
+               Ui::Naviframe *getNavigator() const;
+
+       private:
+               static void onLanguageChanged(app_event_info_h event, void *data);
+               static void updateLanguage();
+
+               Ui::Window *m_Window;
+               Ui::Naviframe *m_Navigator;
+               OperationController *m_Controller;
        };
 }
 
diff --git a/lib-apps-common/inc/App/OperationController.h b/lib-apps-common/inc/App/OperationController.h
new file mode 100644 (file)
index 0000000..5e57532
--- /dev/null
@@ -0,0 +1,113 @@
+/*
+ * Copyright (c) 2015-2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef APP_OPERATION_CONTROLLER_H
+#define APP_OPERATION_CONTROLLER_H
+
+#include <app.h>
+#include <string>
+
+namespace Ui
+{
+       class Navigator;
+       class Window;
+}
+
+namespace App
+{
+       /**
+        * @brief Handles operations requested through App Control.
+        */
+       class EXPORT_API OperationController
+       {
+       public:
+               /**
+                * @brief Create operation controller.
+                * @param[in]   isMinimizable   Whether application can be minimized
+                */
+               OperationController(bool isMinimizable = false);
+               virtual ~OperationController();
+
+               /**
+                * @brief Create operation controller.
+                * @param[in]   window      Main application Window
+                * @param[in]   navigator   Main application Navigator
+                */
+               void create(Ui::Window *window, Ui::Navigator *navigator);
+
+               /**
+                * @brief Request the controller to handle the operation.
+                * @param[in]   operation   Requested operation
+                * @param[in]   request     App Control request
+                */
+               void request(const char *operation, app_control_h request);
+
+       protected:
+               /**
+                * @brief Called after create() is called.
+                */
+               virtual void onCreate() { }
+
+               /**
+                * @brief Called when application receives pause event.
+                */
+               virtual void onPause() { }
+
+               /**
+                * @brief Called when application receives resume event.
+                */
+               virtual void onResume() { }
+
+               /**
+                * @brief Called after request() is called.
+                */
+               virtual void onRequest(const char *operation, app_control_h request) = 0;
+
+               /**
+                * @return Main application Window.
+                */
+               Ui::Window *getWindow() const;
+
+               /**
+                * @return Main application Navigator.
+                */
+               Ui::Navigator *getNavigator() const;
+
+               /**
+                * @return Last received request.
+                */
+               app_control_h getRequest() const;
+
+               /**
+                * @brief Get URI without prefix (if present).
+                * @param[in]   scheme  Scheme prefix to remove (e.g. tel: or file://)
+                * @return URI without scheme.
+                */
+               std::string getUrn(const char *scheme) const;
+
+       private:
+               friend class Application;
+
+               app_control_h m_Request;
+               bool m_IsMinimizable;
+
+               Ui::Window *m_Window;
+               Ui::Navigator *m_Navigator;
+       };
+}
+
+#endif /* APP_OPERATION_CONTROLLER_H */
index a42d8d7..b9b13cc 100644 (file)
 namespace App
 {
        /**
-        * @return Resource directory path
+        * @return Localization files directory path.
         */
-       EXPORT_API const std::string &getResourceDir();
+       EXPORT_API const std::string &getLocaleDir();
 
        /**
-        * @return Data directory path
+        * @return Data directory path.
         */
        EXPORT_API const std::string &getDataDir();
 
        /**
-        * @return Localization files directory path
+        * @return Resource directory path.
         */
-       EXPORT_API const std::string &getLocaleDir();
+       EXPORT_API const std::string &getResourceDir();
 
        /**
         * @brief Get resource file path.
         * @param[in]   relativePath    File path relative to resource directory
-        * @return Full file path
+        * @return Absolute file path.
         */
-       EXPORT_API std::string getResourcePath(const std::string &relativePath);
+       EXPORT_API std::string getResourcePath(const char *relativePath);
 }
 
 #endif /* APP_PATH_H */
index 40c3ff8..8d8fedc 100644 (file)
  */
 
 #include "App/Application.h"
+#include "App/OperationController.h"
+#include "Ui/Naviframe.h"
+#include "Ui/Scale.h"
+#include "Ui/Window.h"
 #include "Utils/Callback.h"
 
+#include <system_settings.h>
+#include <utils_i18n_ulocale.h>
+
 using namespace App;
 
+Application::Application()
+       : m_Window(nullptr), m_Navigator(nullptr), m_Controller(nullptr)
+{
+}
+
 int Application::run(int argc, char **argv)
 {
        ui_app_lifecycle_callback_s cbs;
@@ -31,3 +43,88 @@ int Application::run(int argc, char **argv)
 
        return ui_app_main(argc, argv, &cbs, this);
 }
+
+bool Application::onCreate()
+{
+       updateLanguage();
+
+       app_event_handler_h handle = nullptr;
+       ui_app_add_event_handler(&handle, APP_EVENT_LANGUAGE_CHANGED,
+                       &Application::onLanguageChanged, this);
+       elm_app_base_scale_set(UI_BASE_SCALE);
+
+       m_Window = new Ui::Window();
+       m_Window->create(nullptr);
+
+       m_Navigator = new Ui::Naviframe();
+       m_Window->attachView(m_Navigator);
+
+       return true;
+}
+
+void Application::onTerminate()
+{
+       delete m_Controller;
+       m_Controller = nullptr;
+}
+
+void Application::onPause()
+{
+       if (m_Controller) {
+               m_Controller->onPause();
+       }
+}
+
+void Application::onResume()
+{
+       if (m_Controller) {
+               m_Controller->onResume();
+       }
+}
+
+void Application::onAppControl(app_control_h request)
+{
+       char *operation = nullptr;
+       app_control_get_operation(request, &operation);
+
+       if (!m_Controller) {
+               m_Controller = createController(operation);
+               if (m_Controller) {
+                       m_Controller->create(m_Window, m_Navigator);
+               }
+       }
+
+       if (m_Controller) {
+               m_Controller->request(operation, request);
+       }
+
+       free(operation);
+}
+
+Ui::Window *Application::getWindow() const
+{
+       return m_Window;
+}
+
+Ui::Naviframe *Application::getNavigator() const
+{
+       return m_Navigator;
+}
+
+void Application::onLanguageChanged(app_event_info_h event, void *data)
+{
+       updateLanguage();
+}
+
+void Application::updateLanguage()
+{
+       char *lang = nullptr;
+       system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &lang);
+
+       i18n_ulocale_layout_type_e layout = I18N_ULOCALE_LAYOUT_UNKNOWN;
+       i18n_ulocale_get_character_orientation(lang, &layout);
+
+       elm_language_set(lang);
+       elm_config_mirrored_set(layout == I18N_ULOCALE_LAYOUT_RTL);
+       free(lang);
+}
similarity index 55%
rename from contacts-app/src/OperationController.cpp
rename to lib-apps-common/src/App/OperationController.cpp
index 60c01e7..5b96e8b 100644 (file)
  *
  */
 
-#include "OperationController.h"
+#include "App/OperationController.h"
 #include "Ui/Navigator.h"
 #include "Ui/Window.h"
 
-#include <app.h>
-#include <string.h>
+using namespace App;
 
-OperationController::OperationController(int supportedOperations, bool isMinimizable)
-       : m_SupportedOperations(supportedOperations), m_Request(nullptr), m_IsMinimizable(isMinimizable),
+OperationController::OperationController(bool isMinimizable)
+       : m_Request(nullptr), m_IsMinimizable(isMinimizable),
          m_Window(nullptr), m_Navigator(nullptr)
 {
 }
@@ -31,10 +30,6 @@ OperationController::OperationController(int supportedOperations, bool isMinimiz
 OperationController::~OperationController()
 {
        app_control_destroy(m_Request);
-
-       if (!m_IsMinimizable) {
-               m_Navigator->unsetLastPageCallback();
-       }
 }
 
 void OperationController::create(Ui::Window *window, Ui::Navigator *navigator)
@@ -45,52 +40,20 @@ void OperationController::create(Ui::Window *window, Ui::Navigator *navigator)
        if (!m_IsMinimizable) {
                m_Navigator->setLastPageCallback([] {
                        ui_app_exit();
-                       return true;
+                       return false;
                });
        }
 
        onCreate();
 }
 
-void OperationController::request(Operation operation, app_control_h request)
+void OperationController::request(const char *operation, app_control_h request)
 {
        app_control_destroy(m_Request);
        app_control_clone(&m_Request, request);
        onRequest(operation, m_Request);
 }
 
-bool OperationController::isOperationSupported(Operation operation) const
-{
-       return (m_SupportedOperations & operation) != 0;
-}
-
-Operation OperationController::getOperation(const char *operation)
-{
-       if (!operation) {
-               return OperationDefault;
-       }
-       if (strcmp(operation, APP_CONTROL_OPERATION_DEFAULT) == 0) {
-               return OperationDefault;
-       }
-       if (strcmp(operation, APP_CONTROL_OPERATION_DIAL) == 0) {
-               return OperationDial;
-       }
-       if (strcmp(operation, APP_CONTROL_OPERATION_ADD) == 0) {
-               return OperationAdd;
-       }
-       if (strcmp(operation, APP_CONTROL_OPERATION_EDIT) == 0) {
-               return OperationEdit;
-       }
-       if (strcmp(operation, APP_CONTROL_OPERATION_VIEW) == 0) {
-               return OperationView;
-       }
-       if (strcmp(operation, APP_CONTROL_OPERATION_PICK) == 0) {
-               return OperationPick;
-       }
-
-       return OperationDefault;
-}
-
 Ui::Window *OperationController::getWindow() const
 {
        return m_Window;
@@ -111,7 +74,7 @@ std::string OperationController::getUrn(const char *scheme) const
        char *uri = nullptr;
        app_control_get_uri(m_Request, &uri);
        if (!uri) {
-               return "";
+               return { };
        }
 
        const char *urn = nullptr;
@@ -126,11 +89,3 @@ std::string OperationController::getUrn(const char *scheme) const
        free(uri);
        return path;
 }
-
-void OperationController::replyFailure()
-{
-       app_control_h reply;
-       app_control_create(&reply);
-       app_control_reply_to_launch_request(reply, m_Request, APP_CONTROL_RESULT_FAILED);
-       app_control_destroy(reply);
-}
index 11c0bef..64967dc 100644 (file)
@@ -69,7 +69,11 @@ const std::string &App::getResourceDir()
        return resDir;
 }
 
-std::string App::getResourcePath(const std::string &relativePath)
+std::string App::getResourcePath(const char *relativePath)
 {
-       return std::string(getResourceDir()).append(relativePath);
+       std::string path = getResourceDir();
+       if (relativePath) {
+               path.append(relativePath);
+       }
+       return path;
 }