Add net.stc-popup application with syspopup_launch and PO files
[platform/core/connectivity/stc-manager.git] / plugin / net.stc-popup / src / stc-popup-ui.c
old mode 100644 (file)
new mode 100755 (executable)
index 87ece6c..694fe4b
@@ -1,5 +1,13 @@
-#include <stc-popup-ui.h>
-#include <stc-popup-util.h>
+#include <glib.h>
+
+#include <syspopup.h>
+#include <syspopup_caller.h>
+#include <bundle.h>
+#include <bundle_internal.h>
+#include <app_control_internal.h>
+
+#include "stc-popup-ui.h"
+#include "stc-popup-util.h"
 
 static void win_delete_request_cb(void *data, Evas_Object *obj,
                                  void *event_info)
@@ -16,18 +24,26 @@ static void win_back_cb(void *data, Evas_Object *obj, void *event_info)
 
 static void _response_button1_cb(void *data, Evas_Object *obj, void *event_info)
 {
-       if (!data)
-               return;
-       elm_popup_dismiss(data);
-       /* Button 1 action */
+       Evas_Object *popup = (Evas_Object *)data;
+
+       if (popup)
+               evas_object_del(popup);
+       if (obj)
+               evas_object_del(obj);
+
+       elm_exit();
 }
 
 static void _response_button2_cb(void *data, Evas_Object *obj, void *event_info)
 {
-       if (!data)
-               return;
-       elm_popup_dismiss(data);
-       /* Button 2 action */
+       Evas_Object *popup = (Evas_Object *)data;
+
+       if (popup)
+               evas_object_del(popup);
+       if (obj)
+               evas_object_del(obj);
+
+       elm_exit();
 }
 
 static void _popup_hide_cb(void *data, Evas_Object *obj, void *event_info)
@@ -95,7 +111,7 @@ static void _popup_title_text_2button(appdata_s *ad, const char *title,
        evas_object_show(popup);
 }
 
-void create_window(appdata_s *ad)
+static void create_window(appdata_s *ad)
 {
        /*
         * Widget Tree
@@ -134,6 +150,24 @@ void create_window(appdata_s *ad)
        evas_object_show(ad->win);
 }
 
+static void remove_window(appdata_s *ad)
+{
+       if (ad->layout) {
+               evas_object_del(ad->layout);
+               ad->layout = NULL;
+       }
+
+       if (ad->conform) {
+               evas_object_del(ad->conform);
+               ad->conform = NULL;
+       }
+
+       if (ad->win) {
+               evas_object_del(ad->win);
+               ad->win = NULL;
+       }
+}
+
 void create_popup(appdata_s *ad, popup_type_e type, const char *app_id)
 {
        if (ad->win != NULL)
@@ -163,7 +197,74 @@ static bool app_create(void *data)
 
 static void app_control(app_control_h app_control, void *data)
 {
+       __STC_LOG_FUNC_ENTER__;
        /* Handle the launch request. */
+       const char *syspopup_content = NULL;
+       const char *syspopup_type = NULL;
+       const char *app_id = NULL;
+       const char *if_type = NULL;
+       const char *limit = NULL;
+
+       appdata_s *ad = data;
+       bundle *b = NULL;
+
+       /* Start Main UI */
+       app_control_to_bundle(app_control, &b);
+
+       if (syspopup_has_popup(b)) {
+               /* Destroy the existing popup*/
+               STC_LOGE("A popup is already present!");
+               remove_window(ad);
+       }
+
+       syspopup_content = bundle_get_val(b, "_SYSPOPUP_CONTENT_");
+       if (syspopup_content == NULL) {
+               STC_LOGE("syspopup_content is NULL!");
+               return;
+       }
+
+       syspopup_type = bundle_get_val(b, "_SYSPOPUP_TYPE_");
+       if (syspopup_type == NULL) {
+               STC_LOGE("syspopup_type is NULL!");
+               return;
+       }
+
+       app_id = bundle_get_val(b, "_APP_ID_");
+       if (app_id == NULL) {
+               STC_LOGE("app_id is NULL!");
+               return;
+       }
+
+       if_type = bundle_get_val(b, "_IF_TYPE_");
+       if (if_type == NULL) {
+               STC_LOGE("if_type is NULL!");
+               return;
+       }
+
+       if (g_strcmp0(syspopup_type, "restriction_noti") == 0) {
+
+               limit = bundle_get_val(b, "_RESTRICTION_LIMIT_");
+               if (limit == NULL) {
+                       STC_LOGE("limit is NULL!");
+                       return;
+               }
+
+               create_popup(ad, POPUP_TYPE_RSTN, app_id); //, limit);
+
+       } else if (g_strcmp0(syspopup_type, "warning_noti") == 0) {
+
+               limit = bundle_get_val(b, "_WARN_LIMIT_");
+               if (limit == NULL) {
+                       STC_LOGE("limit is NULL!");
+                       return;
+               }
+
+               create_popup(ad, POPUP_TYPE_WARN, app_id); //, limit);
+
+       } else {
+               STC_LOGE("Unknown event");
+       }
+       __STC_LOG_FUNC_EXIT__;
 }
 
 static void app_pause(void *data)
@@ -238,3 +339,12 @@ int stc_popup_app_init(int argc, char *argv[], appdata_s *ad)
 
        return ret;
 }
+
+int main(int argc, char *argv[])
+{
+       appdata_s ad = {0,};
+
+       STC_LOGI("Smart Traffic Control Popup");
+
+       return stc_popup_app_init(argc, argv, &ad);
+}