Refactored OperationController.
Change-Id: I9f84e0b49da343fb9e883c5a323db20108b2decd
Signed-off-by: Eugene Kurzberg <i.kurtsberg@samsung.com>
*
*/
-#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 */
+++ /dev/null
-/*
- * 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 */
#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();
};
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);
#ifndef OPERATION_EDIT_CONTROLLER_H
#define OPERATION_EDIT_CONTROLLER_H
-#include "OperationController.h"
+#include "App/OperationController.h"
#include "Ux/SelectTypes.h"
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);
#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);
#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 */
--- /dev/null
+/*
+ * 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();
+}
+++ /dev/null
-/*
- * 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);
-}
#include "OperationDefaultController.h"
-#include "MainApp.h"
#include "Contacts/List/ListView.h"
#include "Logs/List/LogsView.h"
#include "Phone/Dialer/DialerView.h"
using Phone::Dialer::DialerView;
OperationDefaultController::OperationDefaultController()
- : OperationController(OperationDefault | OperationDial, true),
+ : OperationController(true),
m_Navigator(nullptr), m_Tabs{nullptr}
{
}
}
}
-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;
#include "App/AppControlRequest.h"
#include "Ui/Navigator.h"
-#include <string>
-
using namespace Common::Database;
using namespace Contacts;
using namespace Contacts::Input;
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));
#include "OperationPickController.h"
-#include "MainApp.h"
#include "App/AppControlRequest.h"
#include "Common/Actions.h"
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;
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;
*
*/
-#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);
}
#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()
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;
};
}
--- /dev/null
+/*
+ * 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 */
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 */
*/
#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;
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);
+}
*
*/
-#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)
{
}
OperationController::~OperationController()
{
app_control_destroy(m_Request);
-
- if (!m_IsMinimizable) {
- m_Navigator->unsetLastPageCallback();
- }
}
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;
char *uri = nullptr;
app_control_get_uri(m_Request, &uri);
if (!uri) {
- return "";
+ return { };
}
const char *urn = nullptr;
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);
-}
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;
}