Remove the devider of genlist for IOT profile
[apps/native/ug-bluetooth-efl.git] / standard / bt-widget.c
1 /*
2 * ug-bluetooth-efl
3 *
4 * Copyright 2012 Samsung Electronics Co., Ltd
5 *
6 * Contact: Hocheol Seo <hocheol.seo@samsung.com>
7 *           GirishAshok Joshi <girish.joshi@samsung.com>
8 *           DoHyun Pyun <dh79.pyun@samsung.com>
9 *
10 * Licensed under the Flora License, Version 1.1 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
13 *
14 * http://www.tizenopensource.org/license
15 *
16 * Unless required by applicable law or agreed to in writing,
17 * software distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
21 *
22 */
23
24 #include "bt-debug.h"
25 #include "bt-widget.h"
26 #include "bt-main-ug.h"
27 #include "bt-type-define.h"
28 #include "bt-string-define.h"
29
30 Evas_Object *_bt_create_naviframe(Evas_Object *parent)
31 {
32         FN_START;
33
34         Evas_Object *nf;
35
36         retvm_if(parent == NULL, NULL, "Invalid argument: parent is NULL");
37
38         nf = elm_naviframe_add(parent);
39         elm_object_part_content_set(parent, "elm.swallow.content", nf);
40         evas_object_show(nf);
41
42         FN_END;
43
44         return nf;
45 }
46
47 Evas_Object *_bt_create_icon(Evas_Object *parent, char *img)
48 {
49         Evas_Object *ic;
50
51         retvm_if(parent == NULL, NULL, "Invalid argument: parent is NULL");
52         retvm_if(img == NULL, NULL, "Invalid argument: img is NULL");
53         retvm_if(strlen(img) >= BT_IMG_PATH_MAX, NULL, "image path is wrong [%s]", img);
54
55         ic = elm_image_add(parent);
56
57         elm_image_file_set(ic, BT_ICON_EDJ, img);
58         evas_object_size_hint_align_set(ic, EVAS_HINT_FILL, EVAS_HINT_FILL);
59         evas_object_size_hint_weight_set(ic, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
60 /*
61         evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL,
62                                          1, 1);
63         elm_image_resizable_set(ic, 1, 1);
64 */
65         evas_object_show(ic);
66
67         return ic;
68 }
69
70 Evas_Object *_bt_create_progressbar(Evas_Object *parent, const char *style)
71 {
72         FN_START;
73
74         Evas_Object *progress_bar = NULL;
75
76         retvm_if(parent == NULL, NULL, "Invalid argument: parent is NULL");
77
78         progress_bar = elm_progressbar_add(parent);
79
80         if (style)
81                 elm_object_style_set(progress_bar, style);
82         else
83                 elm_object_style_set(progress_bar, "process_large");
84
85         elm_progressbar_horizontal_set(progress_bar, EINA_TRUE);
86         evas_object_propagate_events_set(progress_bar, EINA_FALSE);
87         evas_object_show(progress_bar);
88         elm_progressbar_pulse(progress_bar, EINA_TRUE);
89
90         FN_END;
91
92         return progress_bar;
93 }
94
95 void _bt_update_genlist_item(Elm_Object_Item *item)
96 {
97         ret_if(!item);
98         elm_genlist_item_fields_update(item, "*",
99                                         ELM_GENLIST_ITEM_FIELD_TEXT);
100         elm_genlist_item_fields_update(item, "*",
101                                         ELM_GENLIST_ITEM_FIELD_CONTENT);
102 }
103
104 static Evas_Object *__bt_create_bg(Evas_Object *parent, char *style)
105 {
106         FN_START;
107
108         Evas_Object *bg;
109
110         retvm_if(!parent, NULL, "Invalid argument: parent is NULL");
111
112         bg = elm_bg_add(parent);
113         retv_if(!bg, NULL);
114
115         if (style)
116                 elm_object_style_set(bg, style);
117
118         evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND,
119                                 EVAS_HINT_EXPAND);
120         evas_object_show(bg);
121
122         FN_END;
123
124         return bg;
125 }
126
127 Evas_Object *_bt_main_base_layout_create(Evas_Object *parent, void *data)
128 {
129         FN_START;
130
131         Evas_Object *layout = NULL;
132
133         layout = elm_layout_add(parent);
134         retv_if(!layout, NULL);
135
136         if (TIZEN_COMMON) {
137                 elm_layout_file_set(layout, BT_COMMON_MAIN_LAYOUT_EDJ, "main_layout");
138         } else {
139                 Evas_Object *bg = NULL;
140
141                 elm_layout_theme_set(layout, "layout", "application", "default");
142
143                 bg = __bt_create_bg(layout, "default");
144                 elm_object_part_content_set(layout, "elm.swallow.bg", bg);
145                 evas_object_show(layout);
146         }
147
148         FN_END;
149         return layout;
150 }
151
152 void _bt_set_popup_text(void *data, Evas_Object *popup)
153 {
154         FN_START;
155         ret_if(!data);
156         ret_if(!popup);
157         bt_ug_data *ugd = (bt_ug_data *)data;
158
159         char temp[BT_POPUP_STR_MAX_LEN] = { 0 };
160         char *markup_text = NULL;
161         char *popup_text = NULL;
162         switch (ugd->popup_data.type) {
163         case BT_POPUP_PAIRING_ERROR:
164                 if (ugd->popup_data.data) {
165                         popup_text = BT_STR_UNABLE_TO_PAIR_WITH_PS;
166                         snprintf(temp, BT_POPUP_STR_MAX_LEN, popup_text, (char *)ugd->popup_data.data);
167                 }
168                 break;
169         case BT_POPUP_CONNECTION_ERROR:
170                 if (ugd->popup_data.data) {
171                         popup_text = BT_STR_UNABLE_TO_CONNECT_TO_PS;
172                         snprintf(temp, BT_POPUP_STR_MAX_LEN, popup_text, (char *)ugd->popup_data.data);
173                 }
174                 break;
175         case BT_POPUP_DISCONNECT:
176                 if (ugd->popup_data.data) {
177                         popup_text = BT_STR_END_CONNECTION;
178                         snprintf(temp, BT_POPUP_STR_MAX_LEN, popup_text, (char *)ugd->popup_data.data);
179                 }
180                 break;
181         case BT_POPUP_GET_SERVICE_LIST_ERROR:
182         case BT_POPUP_GETTING_SERVICE_LIST:
183         case BT_POPUP_ENTER_DEVICE_NAME:
184         case BT_POPUP_LOW_BATTERY:
185         default:
186                 break;
187         }
188
189         markup_text = elm_entry_utf8_to_markup(temp);
190         elm_object_text_set(popup, markup_text);
191         free(markup_text);
192 }
193
194 Evas_Object *_bt_create_popup(void *data, void *cb,
195                                         void *cb_data, int timer_val)
196 {
197         FN_START;
198         retvm_if(!data, NULL, "Invalid argument: ugd is NULL");
199         bt_ug_data *ugd = (bt_ug_data *)data;
200         retvm_if(!ugd->win_main, NULL, "Invalid argument: win_main is NULL");
201
202         Evas_Object *popup = NULL;
203
204         popup = elm_popup_add(ugd->win_main);
205         retvm_if(!popup, NULL, "fail to create popup");
206
207         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND,
208                                          EVAS_HINT_EXPAND);
209         elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
210         /* Set title text */
211         switch (ugd->popup_data.type) {
212         case BT_POPUP_PAIRING_ERROR:
213         case BT_POPUP_GET_SERVICE_LIST_ERROR:
214         case BT_POPUP_CONNECTION_ERROR:
215         case BT_POPUP_ENTER_DEVICE_NAME:
216         case BT_POPUP_LOW_BATTERY:
217                 elm_object_domain_translatable_part_text_set(
218                         popup, "title,text",
219                         PKGNAME, "IDS_BT_HEADER_BLUETOOTH_ERROR_ABB");
220                 break;
221
222         case BT_POPUP_GETTING_SERVICE_LIST:
223                 elm_object_domain_translatable_part_text_set(
224                         popup, "title,text",
225                         PKGNAME, "IDS_BT_HEADER_BLUETOOTH");
226                 break;
227         case BT_POPUP_DISCONNECT:
228                 elm_object_domain_translatable_part_text_set(
229                         popup, "title,text",
230                         PKGNAME, "IDS_BT_HEADER_DISCONNECT_DEVICE_ABB");
231                 break;
232         }
233
234         /* Set content text */
235         if (ugd->popup_data.type == BT_POPUP_GET_SERVICE_LIST_ERROR)
236                 elm_object_domain_translatable_text_set(
237                         ugd->popup, PKGNAME,
238                         "IDS_BT_POP_UNABLE_TO_GET_SERVICE_LIST");
239         else if (ugd->popup_data.type == BT_POPUP_GETTING_SERVICE_LIST)
240                 elm_object_domain_translatable_text_set(
241                         ugd->popup, PKGNAME,
242                         "IDS_BT_POP_GETTINGSERVICELIST");
243         else if (ugd->popup_data.type == BT_POPUP_ENTER_DEVICE_NAME)
244                 elm_object_domain_translatable_text_set(
245                         ugd->popup, PKGNAME,
246                         "IDS_ST_POP_ENTER_DEVICE_NAME");
247         else if (ugd->popup_data.type == BT_POPUP_LOW_BATTERY)
248                 elm_object_domain_translatable_text_set(
249                         ugd->popup, PKGNAME,
250                         "IDS_ST_BODY_LEDOT_LOW_BATTERY");
251         else
252                 _bt_set_popup_text(ugd, popup);
253
254         /* Set callback */
255         if (cb != NULL)
256                 evas_object_smart_callback_add(popup, "block,clicked",
257                                                (Evas_Smart_Cb) cb, cb_data);
258
259         /* Set timer value */
260         if (timer_val != 0)
261                 elm_popup_timeout_set(popup, (double)timer_val);
262
263         FN_END;
264         return popup;
265 }