Update license file
[apps/native/ug-nfc-efl.git] / ug-nfc-share-efl / src / ug-nfc-share-popup.c
1 /*
2   * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
3   *
4   * Licensed under the Flora License, Version 1.1 (the "License");
5   * you may not use this file except in compliance with the License.
6   * You may obtain a copy of the License at
7
8   *     http://floralicense.org/license/
9   *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16
17
18 #include "ug-nfc-share-popup.h"
19
20
21 #define NFC_POPUP_AUTO_TIMEOUT_SEC 3.0
22
23
24 static Evas_Object *_popup = NULL;
25 static UG_NFC_POPUP_USER_RESP_CB _user_response_cb;
26 static void *_user_data = NULL;
27
28
29 static void _ug_nfc_share_popup_response_cb(void *data, Evas_Object *obj, void *event_info)
30 {
31         UG_NFC_SHARE_BEGIN();
32
33         int btn_type = (int)data;
34         UG_NFC_POPUP_USER_RESP_CB temp_cb = _user_response_cb;
35         void *temp_data = _user_data;
36
37         UG_NFC_SHARE_DEBUG("btn_type: %d", (int)btn_type);
38         UG_NFC_SHARE_DEBUG("Popup is removed: [%p]", obj);
39         evas_object_del(_popup);
40
41         _popup = NULL;
42         _user_response_cb = NULL;
43         _user_data = NULL;
44
45         if (temp_cb)
46                 temp_cb(temp_data, obj, (void*)btn_type);
47
48         UG_NFC_SHARE_END();
49 }
50
51 static Eina_Bool _ug_nfc_share_popup_show_cb(void *data)
52 {
53         UG_NFC_SHARE_BEGIN();;
54
55         if (_popup)
56                 evas_object_show(_popup);
57
58         UG_NFC_SHARE_END();
59
60         return ECORE_CALLBACK_CANCEL;
61 }
62
63 static void _ug_nfc_share_popup_block_clicked_cb(void *data, Evas_Object *obj, void *event_info)
64 {
65         UG_NFC_SHARE_BEGIN();
66
67         _ug_nfc_share_popup_response_cb((void*)UG_NFC_POPUP_RESP_CLOSE, _popup, NULL);
68
69         UG_NFC_SHARE_END();
70 }
71
72 Evas_Object *ug_nfc_share_create_popup(void *data,
73                                     Evas_Object *parent_layout,
74                                     const char *description,
75                                     const char *btn1_text,
76                                     int btn1_type,
77                                     const char *btn2_text,
78                                     int btn2_type,
79                                     const char *btn3_text,
80                                     int btn3_type,
81                                     bool is_alert_type,
82                                     bool enable_timeout,
83                                     UG_NFC_POPUP_USER_RESP_CB response_cb)
84 {
85         UG_NFC_SHARE_BEGIN();
86
87         Evas_Object *btn = NULL;
88
89         retv_if(NULL == data, NULL);
90
91         if (_popup) {
92                 ug_nfc_share_close_popup(_popup);
93                 _popup = NULL;
94         }
95
96         _popup = elm_popup_add(parent_layout);
97         UG_NFC_SHARE_DEBUG("Popup is created: [%p]", _popup);
98         evas_object_size_hint_weight_set(_popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
99
100         elm_object_text_set(_popup, description);
101
102         if(btn1_text) {
103                 btn = elm_button_add(_popup);
104                 elm_object_style_set (btn, "popup_button/default");
105                 elm_object_text_set(btn, btn1_text);
106                 elm_object_part_content_set(_popup, "button1", btn);
107                 evas_object_smart_callback_add(btn, "clicked", _ug_nfc_share_popup_response_cb, (void*)btn1_type);
108         }
109         if (btn2_text) {
110                 btn = elm_button_add(_popup);
111                 elm_object_style_set (btn, "popup_button/default");
112                 elm_object_text_set(btn, btn2_text);
113                 elm_object_part_content_set(_popup, "button2", btn);
114                 evas_object_smart_callback_add(btn, "clicked", _ug_nfc_share_popup_response_cb, (void*)btn2_type);
115         }
116         if (btn3_text) {
117                 btn = elm_button_add(_popup);
118                 elm_object_style_set (btn, "popup_button/default");
119                 elm_object_text_set(btn, btn3_text);
120                 elm_object_part_content_set(_popup, "button3", btn);
121                 evas_object_smart_callback_add(btn, "clicked", _ug_nfc_share_popup_response_cb, (void*)btn3_type);
122         }
123
124         _user_response_cb = response_cb;
125         _user_data = data;
126
127         if (is_alert_type) {
128                 evas_object_smart_callback_add(_popup, "block,clicked", _ug_nfc_share_popup_block_clicked_cb, NULL);
129         }
130
131         if (enable_timeout)
132         {
133                 elm_popup_timeout_set(_popup, NFC_POPUP_AUTO_TIMEOUT_SEC);
134                 evas_object_smart_callback_add(_popup, "timeout", _ug_nfc_share_popup_response_cb, NULL);
135         }
136
137         _ug_nfc_share_popup_show_cb(NULL);
138
139         UG_NFC_SHARE_END();
140
141         return _popup;
142 }
143
144
145 void ug_nfc_share_close_popup(Evas_Object* popup)
146 {
147         UG_NFC_SHARE_BEGIN();
148
149         if (NULL == popup || NULL == _popup || _popup != popup) {
150                 UG_NFC_SHARE_DEBUG_ERR("NULL == popup || NULL == _popup || _popup != popup");
151         }
152
153         _ug_nfc_share_popup_response_cb((void*)UG_NFC_POPUP_RESP_CLOSE, _popup, NULL);
154
155         UG_NFC_SHARE_END();
156 }
157
158