summaryrefslogtreecommitdiff
path: root/ug-nfc-share-efl/src/ug-nfc-share-popup.c
blob: 8ce79db75c1bd67ab88df16adbb03fd82f564818 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*
  * Copyright (c) 2012, 2013 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 "ug-nfc-share-popup.h"


#define NFC_POPUP_AUTO_TIMEOUT_SEC 3.0


static Evas_Object *_popup = NULL;
static UG_NFC_POPUP_USER_RESP_CB _user_response_cb;
static void *_user_data = NULL;


static void _ug_nfc_share_popup_response_cb(void *data, Evas_Object *obj, void *event_info)
{
	UG_NFC_SHARE_BEGIN();

	int btn_type = (int)data;
	UG_NFC_POPUP_USER_RESP_CB temp_cb = _user_response_cb;
	void *temp_data = _user_data;

	UG_NFC_SHARE_DEBUG("btn_type: %d", (int)btn_type);
	UG_NFC_SHARE_DEBUG("Popup is removed: [%p]", obj);
	evas_object_del(_popup);

	_popup = NULL;
	_user_response_cb = NULL;
	_user_data = NULL;

	if (temp_cb)
		temp_cb(temp_data, obj, (void*)btn_type);

	UG_NFC_SHARE_END();
}

static Eina_Bool _ug_nfc_share_popup_show_cb(void *data)
{
	UG_NFC_SHARE_BEGIN();;

	if (_popup)
		evas_object_show(_popup);

	UG_NFC_SHARE_END();

	return ECORE_CALLBACK_CANCEL;
}

static void _ug_nfc_share_popup_block_clicked_cb(void *data, Evas_Object *obj, void *event_info)
{
	UG_NFC_SHARE_BEGIN();

	_ug_nfc_share_popup_response_cb((void*)UG_NFC_POPUP_RESP_CLOSE, _popup, NULL);

	UG_NFC_SHARE_END();
}

Evas_Object *ug_nfc_share_create_popup(void *data,
                                    Evas_Object *parent_layout,
                                    const char *description,
                                    const char *btn1_text,
                                    int btn1_type,
                                    const char *btn2_text,
                                    int btn2_type,
                                    const char *btn3_text,
                                    int btn3_type,
                                    bool is_alert_type,
                                    bool enable_timeout,
                                    UG_NFC_POPUP_USER_RESP_CB response_cb)
{
	UG_NFC_SHARE_BEGIN();

	Evas_Object *btn = NULL;

	retv_if(NULL == data, NULL);

	if (_popup) {
		ug_nfc_share_close_popup(_popup);
		_popup = NULL;
	}

	_popup = elm_popup_add(parent_layout);
	UG_NFC_SHARE_DEBUG("Popup is created: [%p]", _popup);
	evas_object_size_hint_weight_set(_popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);

	elm_object_text_set(_popup, description);

	if(btn1_text) {
		btn = elm_button_add(_popup);
		elm_object_style_set (btn, "popup_button/default");
		elm_object_text_set(btn, btn1_text);
		elm_object_part_content_set(_popup, "button1", btn);
		evas_object_smart_callback_add(btn, "clicked", _ug_nfc_share_popup_response_cb, (void*)btn1_type);
	}
	if (btn2_text) {
		btn = elm_button_add(_popup);
		elm_object_style_set (btn, "popup_button/default");
		elm_object_text_set(btn, btn2_text);
		elm_object_part_content_set(_popup, "button2", btn);
		evas_object_smart_callback_add(btn, "clicked", _ug_nfc_share_popup_response_cb, (void*)btn2_type);
	}
	if (btn3_text) {
		btn = elm_button_add(_popup);
		elm_object_style_set (btn, "popup_button/default");
		elm_object_text_set(btn, btn3_text);
		elm_object_part_content_set(_popup, "button3", btn);
		evas_object_smart_callback_add(btn, "clicked", _ug_nfc_share_popup_response_cb, (void*)btn3_type);
	}

	_user_response_cb = response_cb;
	_user_data = data;

	if (is_alert_type) {
		evas_object_smart_callback_add(_popup, "block,clicked", _ug_nfc_share_popup_block_clicked_cb, NULL);
	}

	if (enable_timeout)
	{
		elm_popup_timeout_set(_popup, NFC_POPUP_AUTO_TIMEOUT_SEC);
		evas_object_smart_callback_add(_popup, "timeout", _ug_nfc_share_popup_response_cb, NULL);
	}

	_ug_nfc_share_popup_show_cb(NULL);

	UG_NFC_SHARE_END();

	return _popup;
}


void ug_nfc_share_close_popup(Evas_Object* popup)
{
	UG_NFC_SHARE_BEGIN();

	if (NULL == popup || NULL == _popup || _popup != popup) {
		UG_NFC_SHARE_DEBUG_ERR("NULL == popup || NULL == _popup || _popup != popup");
	}

	_ug_nfc_share_popup_response_cb((void*)UG_NFC_POPUP_RESP_CLOSE, _popup, NULL);

	UG_NFC_SHARE_END();
}