/* * Copyright (c) 2000-2014 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 "bt-main.h" #include "bt-main-view.h" #include "bt-string.h" #include "bt-handler.h" #include "bt-popup.h" #include "bt-util.h" #include "bt-resource.h" static void __bt_popup_hide_cb(void *data, Evas_Object *obj, void *event_info) { FN_START; ret_if(!obj); elm_popup_dismiss(obj); FN_END; } static void __bt_popup_hide_finished_cb(void *data, Evas_Object *obj, void *event_info) { FN_START; bt_app_data_t *ad = (bt_app_data_t *)data; ret_if(!ad); if (ad->popup) { evas_object_del(ad->popup); ad->popup = NULL; } FN_END; } static void __bt_toast_popup_hide_finished_cb(void *data, Evas_Object *obj, void *event_info) { FN_START; bt_app_data_t *ad = (bt_app_data_t *)data; ret_if(!ad); if (ad->toast_popup) { evas_object_del(ad->toast_popup); ad->toast_popup = NULL; } if ((ad->launch_mode == BT_LAUNCH_CONNECT_HEADSET || ad->launch_mode == BT_LAUNCH_CALL) && ad->navi == NULL) { DBG("user press back key to exit. terminate app"); elm_exit(); return; } FN_END; } static void __bt_toast_popup_block_clicked_cb(void *data, Evas_Object *obj, void *event_info) { FN_START; ret_if(!obj); elm_popup_dismiss(obj); FN_END; } void _bt_draw_toast_popup(bt_app_data_t *ad, char *toast_text) { FN_START; Evas_Object *popup = NULL; if (ad->toast_popup) { evas_object_del(ad->toast_popup); ad->toast_popup = NULL; } popup = elm_popup_add(ad->window); elm_object_style_set(popup, "toast/circle"); elm_popup_orient_set(popup, ELM_POPUP_ORIENT_BOTTOM); evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, __bt_popup_hide_cb, ad); evas_object_smart_callback_add(popup, "dismissed", __bt_toast_popup_hide_finished_cb, ad); evas_object_smart_callback_add(ad->popup, "block,clicked", __bt_toast_popup_block_clicked_cb, NULL); elm_object_part_text_set(popup, "elm.text", toast_text); evas_object_show(popup); elm_object_focus_set(popup, EINA_TRUE); ad->toast_popup = popup; FN_END; } static void __bt_draw_popup(bt_app_data_t *ad, const char *title, const char *msg, void (*func) (void *data, Evas_Object *obj, void *event_info), void *data) { FN_START; Evas_Object *btn; Evas_Object *icon; Evas_Object *layout; char *txt = NULL; ad->popup = elm_popup_add(ad->window); elm_object_style_set(ad->popup, "circle"); evas_object_size_hint_weight_set(ad->popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); eext_object_event_callback_add(ad->popup, EEXT_CALLBACK_BACK, __bt_popup_hide_cb, ad); evas_object_smart_callback_add(ad->popup, "dismissed", __bt_popup_hide_finished_cb, ad); layout = elm_layout_add(ad->popup); elm_layout_theme_set(layout, "layout", "popup", "content/circle/buttons2"); if (title != NULL) elm_object_part_text_set(layout, "elm.text.title", title); if (msg != NULL) { txt = elm_entry_utf8_to_markup(msg); elm_object_part_text_set(layout, "elm.text", txt); g_free(txt); } elm_object_content_set(ad->popup, layout); btn = elm_button_add(ad->popup); elm_object_style_set(btn , "popup/circle/left"); elm_atspi_accessible_description_set(btn, BT_STR_CANCEL); elm_atspi_accessible_translation_domain_set(btn, BT_COMMON_PKG); elm_object_part_content_set(ad->popup, "button1", btn); evas_object_smart_callback_add(btn , "clicked", func, data); icon = elm_image_add(btn); elm_image_file_set(icon, BT_IMAGE_EDJ, BT_ICON_DELETE); evas_object_size_hint_weight_set(icon, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); elm_object_part_content_set(btn, "elm.swallow.content", icon); evas_object_show(icon); btn = elm_button_add(ad->popup); elm_object_style_set(btn , "popup/circle/right"); elm_atspi_accessible_description_set(btn, BT_STR_OK); elm_atspi_accessible_translation_domain_set(btn, BT_COMMON_PKG); elm_object_part_content_set(ad->popup, "button2", btn); evas_object_smart_callback_add(btn , "clicked", func, data); icon = elm_image_add(btn); elm_image_file_set(icon, BT_IMAGE_EDJ, BT_ICON_CHECK); evas_object_size_hint_weight_set(icon, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); elm_object_part_content_set(btn, "elm.swallow.content", icon); evas_object_show(icon); evas_object_show(ad->popup); elm_object_focus_set(ad->popup, EINA_TRUE); FN_END; } static void __bt_disconnection_confirm_cb(void *data, Evas_Object *obj, void *event_info) { FN_START; if (obj == NULL || data == NULL) return; bt_app_data_t *ad = NULL; bt_dev_t *dev = (bt_dev_t *)data; ret_if(dev->ad == NULL); ad = dev->ad; const char *style = elm_object_style_get(obj); if (!g_strcmp0(style, "popup/circle/right")) { DBG("+ OK"); INFO("Request all disconnection"); _bt_disconnect_device(ad, dev); } else { DBG("+ Cancel"); } _bt_destroy_popup(ad); FN_END; } void _bt_create_disconnection_query_popup(bt_dev_t *dev) { FN_START; bt_app_data_t *ad = NULL; char message[BT_POPUP_TEXT_LENGTH] = { 0 }; char *stms_str = NULL; ret_if(dev->ad == NULL); ad = dev->ad; _bt_destroy_popup(ad); stms_str = BT_STR_DISCONNECT_DEV_Q; snprintf(message, sizeof(message), stms_str, dev->name); __bt_draw_popup(ad, NULL, message, __bt_disconnection_confirm_cb, dev); FN_END; } void _bt_destroy_popup(bt_app_data_t *ad) { FN_START; ret_if(ad == NULL); if (ad->popup) __bt_popup_hide_cb(NULL, ad->popup, NULL); FN_END; }