Move "keyboard disconnected" popup window to a separate executable 44/171544/8
authorPaweł Stawicki <p.stawicki@samsung.com>
Mon, 12 Mar 2018 12:32:36 +0000 (13:32 +0100)
committerPaweł Stawicki <p.stawicki@samsung.com>
Mon, 12 Mar 2018 12:32:36 +0000 (13:32 +0100)
Change-Id: I6f712fb03d10df7c2519ef475822279e83bbbcb4

CMakeLists.txt
org.tizen.universal-switch.xml
packaging/org.tizen.universal-switch.spec
src/CMakeLists.txt
src/SwitchManager.cpp
src/popup/CMakeLists.txt [new file with mode: 0644]
src/popup/main.cpp [new file with mode: 0644]

index 9fc7bab..d6f5909 100644 (file)
@@ -23,6 +23,7 @@ pkg_check_modules(pkgs REQUIRED
     ecore
     eldbus
     elementary
+    efl-extension
     gobject-2.0
     sqlite3
     tts
index 3557641..586c7c4 100644 (file)
@@ -9,6 +9,10 @@
         </app-control>
         <background-category value="system"/>
     </ui-application>
+    <ui-application appid="org.tizen.universal-switch-popup" exec="universal-switch-popup" type="capp" multiple="false" taskmanage="false" nodisplay="true">
+        <icon>universal-switch.png</icon>
+        <label>universal-switch-popup</label>
+       </ui-application>
     <privileges>
         <privilege>http://tizen.org/privilege/window.priority.set</privilege>
         <privilege>http://tizen.org/privilege/telephony</privilege>
@@ -21,5 +25,4 @@
         <privilege>http://tizen.org/privilege/mediastorage</privilege>
         <privilege>http://tizen.org/privilege/display</privilege>
     </privileges>
-
 </manifest>
index 6c599d3..3402950 100644 (file)
@@ -22,6 +22,7 @@ BuildRequires:  pkgconfig(capi-telephony)
 BuildRequires:  pkgconfig(capi-system-device)
 BuildRequires:  pkgconfig(ecore)
 BuildRequires:  pkgconfig(elementary)
+BuildRequires:  pkgconfig(efl-extension)
 BuildRequires:  pkgconfig(sqlite3)
 BuildRequires:  pkgconfig(libtzplatform-config)
 BuildRequires:  pkgconfig(capi-ui-efl-util)
@@ -86,6 +87,7 @@ tpk-backend -y %{name} --preload
 
 %license LICENSE
 %{AppDir}/bin/universal-switch
+%{AppDir}/bin/universal-switch-popup
 %{DataDir}/packages/%{name}.xml
 %{AppDir}/scripts/setVconfKeys.sh
 
index ab81a39..3fc32d3 100644 (file)
@@ -7,3 +7,5 @@ INCLUDE_DIRECTORIES(${pkgs_INCLUDE_DIRS})
 ADD_EXECUTABLE(${PROJECT_NAME}  $<TARGET_OBJECTS:universal-switch-obj>)
 TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LIBRARIES})
 INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin)
+
+ADD_SUBDIRECTORY(popup)
\ No newline at end of file
index a79fa0e..df442cb 100644 (file)
 
 #include "SwitchManager.hpp"
 
-#include <Elementary.h>
-
 #include "ConditionAll.hpp"
 #include "ConditionEqual.hpp"
 #include "UIActivity.hpp"
 #include "Window.hpp"
+#include <app.h>
+
+#define UNIVERSAL_SWITCH_POPUP_EXEC "org.tizen.universal-switch-popup"
 
 SwitchManager::SwitchManager(const std::shared_ptr<SwitchProvider> &provider,
                                                         const std::shared_ptr<Configuration> &configuration,
@@ -146,56 +147,27 @@ void SwitchManager::setActivityFactory(const std::shared_ptr<ActivityFactory> &f
        activityFactory = factory;
 }
 
-static void windowDeleterCb(void *data, Evas_Object *obj, void *event_info)
-{
-       evas_object_smart_callback_del(obj, "dismissed", windowDeleterCb);
-       evas_object_smart_callback_del(obj, "block,clicked", windowDeleterCb);
-       evas_object_del(obj);
-}
-
-static void onButtonClickCb(void *data, Evas_Object *obj, void *event_info)
+static void launchKeyboardDisappearedPopup()
 {
-       auto window = static_cast<Evas_Object *>(data);
-       evas_object_del(window);
+       DEBUG("Launching " UNIVERSAL_SWITCH_POPUP_EXEC);
+       app_control_h app_control;
+       app_control_create(&app_control);
+       app_control_set_operation(app_control, APP_CONTROL_OPERATION_DEFAULT);
+       app_control_set_app_id(app_control, UNIVERSAL_SWITCH_POPUP_EXEC);
+       app_control_send_launch_request(app_control, NULL, NULL);
+       app_control_destroy(app_control);
 }
 
 void SwitchManager::onDisconnection()
 {
-       DEBUG("adding window");
-       auto windowHandler = elm_win_add(NULL, "universal-switch-popup", ELM_WIN_NOTIFICATION);
-       if (!windowHandler) {
-               ERROR("Window cannot be created");
-               exit(1);
+       DEBUG("Clearing stack");
+       while (!activities.empty()) {
+               DEBUG("Pop from stack: %s", activities.top()->getType().c_str());
+               activities.top()->detach(this, (ActivityChangeRequest *) nullptr);
+               activities.pop();
        }
 
-       // TODO: name setter should be removed after reaching full functionality by navigation interface
-       elm_atspi_accessible_name_set(windowHandler, "UniversalSwitch Main Window");
-       efl_util_set_notification_window_level(windowHandler, EFL_UTIL_NOTIFICATION_LEVEL_2);
-       elm_win_override_set(windowHandler, EINA_TRUE);
-       elm_win_alpha_set(windowHandler, EINA_TRUE);
-
-       int screenWidth = 0;
-       int screenHeight = 0;
-
-       elm_win_screen_size_get(windowHandler, NULL, NULL, &screenWidth, &screenHeight);
-       evas_object_resize(windowHandler, screenWidth, screenHeight);
-       evas_object_show(windowHandler);
-
-       auto popup = elm_popup_add(windowHandler);
-       elm_popup_orient_set(popup, ELM_POPUP_ORIENT_CENTER);
-       evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
-       elm_object_part_text_set(popup, "title,text", _("IDS_SWITCH_PROVIDER_AccessoryDisconnected_Header"));
-       elm_object_text_set(popup, _("IDS_SWITCH_PROVIDER_AccessoryDisconnected_Content"));
-
-       evas_object_smart_callback_add(popup, "dismissed", windowDeleterCb, NULL);
-       evas_object_smart_callback_add(popup, "block,clicked", windowDeleterCb, NULL);
-
-       auto btn = elm_button_add(popup);
-       elm_object_style_set(btn, "bottom");
-       elm_object_text_set(btn, "OK");
-       elm_object_part_content_set(popup, "button1", btn);
-       evas_object_smart_callback_add(btn, "clicked", onButtonClickCb, windowHandler);
-       evas_object_show(popup);
+       launchKeyboardDisappearedPopup();
 }
 
 void SwitchManager::changeActivity(const std::shared_ptr<ActivityChangeRequest> &request)
diff --git a/src/popup/CMakeLists.txt b/src/popup/CMakeLists.txt
new file mode 100644 (file)
index 0000000..603cffa
--- /dev/null
@@ -0,0 +1,11 @@
+FILE(GLOB SRCS *.cpp)
+
+INCLUDE_DIRECTORIES(${pkgs_INCLUDE_DIRS})
+
+SET(UNIVERSAL_SWITCH_POPUP_EXEC "${PROJECT_NAME}-popup")
+ADD_DEFINITIONS("-DUNIVERSAL_SWITCH_POPUP_EXEC=\"${UNIVERSAL_SWITCH_POPUP_EXEC}\"")
+
+
+ADD_EXECUTABLE(${UNIVERSAL_SWITCH_POPUP_EXEC}  ${SRCS})
+TARGET_LINK_LIBRARIES(${UNIVERSAL_SWITCH_POPUP_EXEC} ${pkgs_LIBRARIES})
+INSTALL(TARGETS ${UNIVERSAL_SWITCH_POPUP_EXEC} DESTINATION bin)
diff --git a/src/popup/main.cpp b/src/popup/main.cpp
new file mode 100644 (file)
index 0000000..a2bfb1a
--- /dev/null
@@ -0,0 +1,119 @@
+/*
+ * Copyright 2018  Samsung Electronics Co., Ltd
+ *
+ * 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 <app.h>
+#include <Elementary.h>
+#include <efl_extension.h>
+#include <ui/efl_util.h>
+#include "../UniversalSwitchLog.hpp"
+#include <libintl.h>
+
+void initializeGetText()
+{
+       //manually initialize GNU gettext utilities,
+       //this is necessary because we are sharing en_US.po file with universal-switch
+       DEBUG(UNIVERSAL_SWITCH_POPUP_EXEC " init gnu gettext");
+       bindtextdomain(PROJECT_NAME, LOCALE_DIR);
+       textdomain(PROJECT_NAME);
+}
+
+static void windowCloseCb(void *data, Evas_Object *obj, void *event_info)
+{
+       ui_app_exit();
+}
+
+bool app_create(void *data)
+{
+       DEBUG(UNIVERSAL_SWITCH_POPUP_EXEC " create");
+       initializeGetText();
+       auto win = elm_win_add(NULL, UNIVERSAL_SWITCH_POPUP_EXEC, ELM_WIN_NOTIFICATION);
+       if (!win) {
+               ERROR("Window cannot be created");
+               exit(1);
+       }
+       elm_win_autodel_set(win, EINA_TRUE);
+
+       /* Rotation setting */
+       if (elm_win_wm_rotation_supported_get(win)) {
+               int rots[4] = { 0, 90, 180, 270 };
+               elm_win_wm_rotation_available_rotations_set(win, (const int *)(&rots), 4);
+       }
+
+       // TODO: name setter should be removed after reaching full functionality by navigation interface
+       elm_atspi_accessible_name_set(win, "UniversalSwitch Popup Window");
+       elm_win_override_set(win, EINA_TRUE);
+       elm_win_alpha_set(win, EINA_TRUE);
+
+       int screenWidth = 0;
+       int screenHeight = 0;
+
+       elm_win_screen_size_get(win, NULL, NULL, &screenWidth, &screenHeight);
+       evas_object_resize(win, screenWidth, screenHeight);
+       evas_object_show(win);
+
+       auto popup = elm_popup_add(win);
+       elm_popup_orient_set(popup, ELM_POPUP_ORIENT_CENTER);
+       evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+       elm_object_part_text_set(popup, "title,text", _("IDS_SWITCH_PROVIDER_AccessoryDisconnected_Header"));
+       elm_object_text_set(popup, _("IDS_SWITCH_PROVIDER_AccessoryDisconnected_Content"));
+
+       evas_object_smart_callback_add(popup, "dismissed", windowCloseCb, NULL);
+       evas_object_smart_callback_add(popup, "block,clicked", windowCloseCb, NULL);
+       eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, windowCloseCb, NULL);
+
+       auto btn = elm_button_add(popup);
+       elm_object_style_set(btn, "bottom");
+       elm_object_text_set(btn, "OK");
+       elm_object_part_content_set(popup, "button1", btn);
+       evas_object_smart_callback_add(btn, "clicked", windowCloseCb, win);
+       evas_object_show(popup);
+       return true;
+}
+
+void app_terminate(void *data)
+{
+       DEBUG(UNIVERSAL_SWITCH_POPUP_EXEC " termination procedure");
+}
+
+static void _setting_time_lang_changed(app_event_info_h event_info, void *data)
+{
+       char *lang = NULL;
+       if (app_event_get_language(event_info, &lang) == APP_ERROR_NONE) {
+               DEBUG("Language is changed : %s", lang);
+               elm_language_set(lang);
+               free(lang);
+       } else {
+               ERROR("Cannot get language from event_info");
+       }
+}
+
+int main(int argc, char *argv[])
+{
+       DEBUG(UNIVERSAL_SWITCH_POPUP_EXEC " main function called");
+
+       ui_app_lifecycle_callback_s event_callback = {
+               .create = app_create,
+               .terminate = app_terminate,
+               .pause = NULL,
+               .resume = NULL,
+               .app_control = NULL
+       };
+
+       app_event_handler_h handler;
+       ui_app_add_event_handler(&handler, APP_EVENT_LANGUAGE_CHANGED, _setting_time_lang_changed, NULL);
+
+       return ui_app_main(argc, argv, &event_callback, NULL);
+}