/* * Copyright 2012 Samsung Electronics Co., Ltd * * Licensed under the Flora License, Version 1.1 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://floralicense.org/license * * 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 "message-dialog.h" #include "app_service.h" static void __msg_ui_dialog_always_ask_left_btn_cb(void *data, Evas_Object *obj, void *event_info); static void __msg_ui_dialog_always_ask_right_btn_cb(void *data, Evas_Object *obj, void *event_info); static int __msg_ui_dialog_create_always_ask_popup(void *data); static void __msg_ui_dialog_rotation_changed_cb(void *data, Evas_Object *obj, void *event); static void __msg_ui_dialog_win_del(void *data, Evas_Object *obj, void *event); static Evas_Object *__msg_ui_dialog_create_win(const char *name); static int parse_opt(int argc, char **argv, struct appdata *ad); void msg_ui_dialog_exit(void *data) { struct appdata *ad = data; MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, " "); if (ad->msg) { g_free(ad->msg); ad->msg = NULL; } if (ad->url) { g_free(ad->url); ad->url = NULL; } if (ad->popup != NULL) { evas_object_del(ad->popup); ad->popup = NULL; } if (ad->main_window != NULL) { evas_object_del(ad->main_window); ad->main_window = NULL; } elm_exit(); } static void __msg_ui_dialog_always_ask_left_btn_cb(void *data, Evas_Object *obj, void *event_info) { MSG_UI_ENTER(MSG_UI_LEVEL_DEBUG); MSG_UI_RET_IF(MSG_UI_LEVEL_ERR, !data); struct appdata *ad = data; service_h svc_h; int ret = SERVICE_ERROR_NONE; ret = service_create(&svc_h); if (ret != SERVICE_ERROR_NONE) { MSG_UI_DEBUG(MSG_UI_LEVEL_ERR, "service_create() is failed : %d", ret); return; } ret = service_set_operation(svc_h, SERVICE_OPERATION_VIEW); if (ret != SERVICE_ERROR_NONE) { MSG_UI_DEBUG(MSG_UI_LEVEL_ERR, "service_set_operation() is failed : %d", ret); goto DESTROY; } ret = service_set_uri(svc_h, ad->url); if (ret != SERVICE_ERROR_NONE) { MSG_UI_DEBUG(MSG_UI_LEVEL_ERR, "service_set_uri() is failed : %d", ret); goto DESTROY; } ret = service_send_launch_request(svc_h, NULL, NULL); if (ret != SERVICE_ERROR_NONE) { MSG_UI_DEBUG(MSG_UI_LEVEL_ERR, "service_send_launch_request() is failed : %d", ret); } DESTROY: ret = service_destroy(svc_h); MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, "service_destroy() returns : %d", ret); msg_ui_dialog_exit(ad); } static void __msg_ui_dialog_always_ask_right_btn_cb(void *data, Evas_Object *obj, void *event_info) { MSG_UI_ENTER(MSG_UI_LEVEL_DEBUG); MSG_UI_RET_IF(MSG_UI_LEVEL_ERR, !data); struct appdata *ad = data; msg_ui_dialog_exit(ad); } static int __msg_ui_dialog_create_always_ask_popup(void *data) { MSG_UI_ENTER(MSG_UI_LEVEL_DEBUG); struct appdata *ad = data; char display_msg[100] = { 0, }; Evas_Object *btn1; Evas_Object *btn2; const char *str = dgettext(MESSAGE_PKGNAME, "IDS_MSGF_POP_ABOUT_TO_GO_ONLINE_CONTINUE_Q"); snprintf(display_msg, sizeof(display_msg), str, ad->url); ad->popup = elm_popup_add(ad->main_window); if (ad->popup == NULL) { MSG_UI_DEBUG(MSG_UI_LEVEL_ERR, "Cannot add popup object !!"); return MSG_UI_RET_ERR; } evas_object_size_hint_weight_set(ad->popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); elm_object_text_set(ad->popup, display_msg); elm_popup_orient_set(ad->popup, ELM_POPUP_ORIENT_CENTER); btn1 = elm_button_add(ad->popup); elm_object_text_set(btn1, dgettext("sys_string", "IDS_COM_SK_YES")); elm_object_part_content_set(ad->popup, "button1", btn1); evas_object_smart_callback_add(btn1, "clicked", __msg_ui_dialog_always_ask_left_btn_cb, ad); btn2 = elm_button_add(ad->popup); elm_object_text_set(btn2, dgettext("sys_string", "IDS_COM_SK_NO")); elm_object_part_content_set(ad->popup, "button2", btn2); evas_object_smart_callback_add(btn2, "clicked", __msg_ui_dialog_always_ask_right_btn_cb, ad); evas_object_show(ad->popup); MSG_UI_LEAVE(MSG_UI_LEVEL_DEBUG); return MSG_UI_RET_SUCCESS; } static void __msg_ui_dialog_rotation_changed_cb(void *data, Evas_Object *obj, void *event) { struct appdata *ad = data; if (ad == NULL || ad->main_window == NULL) return; int changed_rotation = elm_win_rotation_get(obj); if(changed_rotation != ad->cur_rotation) { D_MSG("current rotation [%d], changed rotation [%d]", ad->cur_rotation, changed_rotation); ad->cur_rotation = changed_rotation; } } static void __msg_ui_dialog_win_del(void *data, Evas_Object *obj, void *event) { MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, " "); elm_exit(); } static Evas_Object *__msg_ui_dialog_create_win(const char *name) { Evas_Object *eo = NULL; int w, h; eo = elm_win_add(NULL, name, ELM_WIN_DIALOG_BASIC); if (eo) { elm_win_alpha_set(eo, EINA_TRUE); elm_win_title_set(eo, name); elm_win_raise(eo); evas_object_smart_callback_add(eo, "delete,request", __msg_ui_dialog_win_del, NULL); ecore_x_window_size_get(ecore_x_window_root_first_get(), &w, &h); evas_object_resize(eo, w, h); evas_object_show(eo); } return eo; } static bool app_create(void *data) { MSG_UI_ENTER(MSG_UI_LEVEL_DEBUG); struct appdata *ad = data; if (ad->dialog_mode != MSG_UI_DIALOG_MODE_PUSH_MSG_ALWAYS_ASK) { MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, "Invalid mode !!"); return FALSE; } /* init internationalization */ if (bindtextdomain(MESSAGE_PKGNAME, LOCALEDIR) == NULL) { MSG_UI_DEBUG(MSG_UI_LEVEL_ASSERT, "bindtextdomain() is failed !!"); return FALSE; } if (textdomain(MESSAGE_PKGNAME) == NULL) { MSG_UI_DEBUG(MSG_UI_LEVEL_ASSERT, "textdomain() is failed !!"); return FALSE; } /* Create main window */ ad->main_window = __msg_ui_dialog_create_win(PACKAGE); if (ad->main_window == NULL) { MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, "__msg_ui_dialog_create_win() is failed !!"); return FALSE; } if (__msg_ui_dialog_create_always_ask_popup(ad) < 0) { MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, "__msg_ui_dialog_create_always_ask_popup() is failed !!"); return FALSE; } if(elm_win_wm_rotation_supported_get(ad->main_window)) { int rotation[4] = {0, 90, 180, 270}; elm_win_wm_rotation_available_rotations_set(ad->main_window, rotation, 4); ad->cur_rotation = elm_win_rotation_get(ad->main_window); D_MSG("current rotation %d", ad->cur_rotation); evas_object_smart_callback_add(ad->main_window, "wm,rotation,changed", __msg_ui_dialog_rotation_changed_cb, ad); } return TRUE; } static void app_terminate(void *data) { MSG_UI_ENTER(MSG_UI_LEVEL_DEBUG); } static void app_pause(void *data) { MSG_UI_ENTER(MSG_UI_LEVEL_DEBUG); } static void app_resume(void *data) { MSG_UI_ENTER(MSG_UI_LEVEL_DEBUG); } static void app_service(service_h service, void *data) { MSG_UI_ENTER(MSG_UI_LEVEL_DEBUG); } static int parse_opt(int argc, char **argv, struct appdata *ad) { MSG_UI_ENTER(MSG_UI_LEVEL_DEBUG); int opt; if (ad == NULL) { MSG_UI_DEBUG(MSG_UI_LEVEL_ERR, "Invalid argument: application data is NULL"); return MSG_UI_RET_ERR; } while ((opt = getopt(argc, argv, "m:o:u:h")) != -1) { switch (opt) { case 'o': ad->msg = strdup(optarg); MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, "optarg = %s", ad->msg); break; case 'm': MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, "m = %s", optarg); if (g_strcmp0(optarg, "PUSH_MSG_ALWAYS_ASK") == 0) { ad->dialog_mode = MSG_UI_DIALOG_MODE_PUSH_MSG_ALWAYS_ASK; } else { MSG_UI_DEBUG(MSG_UI_LEVEL_ERR, "Invalid mode: %s", optarg); return MSG_UI_RET_ERR; } break; case 'u': ad->url = strdup(optarg); MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, " ad->url = %s", ad->url); break; case 'h': default: fprintf(stderr, "Usage: %s [-h] [-m PUSH_MSG_ALWAYS_ASK] [-u LaunchURL] \n", argv[0]); fprintf(stderr, "ex) %s -m PUSH_MSG_ALWAYS_ASK -u www.google.com \n", argv[0]); return MSG_UI_RET_ERR; } } return MSG_UI_RET_SUCCESS; } int main(int argc, char **argv) { MSG_UI_ENTER(MSG_UI_LEVEL_DEBUG); struct appdata ad; memset(&ad, 0x0, sizeof(struct appdata)); app_event_callback_s event_callback; event_callback.create = app_create; event_callback.terminate = app_terminate; event_callback.pause = app_pause; event_callback.resume = app_resume; event_callback.service = app_service; event_callback.low_memory = NULL; event_callback.low_battery = NULL; event_callback.device_orientation = NULL; event_callback.language_changed = NULL; event_callback.region_format_changed = NULL; if (parse_opt(argc, argv, &ad) == -1) { MSG_UI_DEBUG(MSG_UI_LEVEL_ASSERT, "parse_opt() is failed !!"); return MSG_UI_RET_ERR; } return app_efl_main(&argc, &argv, &event_callback, &ad); }