2 * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 * Licensed under the Flora License, Version 1.0 (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
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing,
11 * software 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.
19 #include <vconf-internal-setting-keys.h>
22 #include <dbus/dbus.h>
23 #include <dbus/dbus-glib-bindings.h>
25 #include "bt-main-ug.h"
27 #include "bt-widget.h"
28 #include "bt-main-view.h"
29 #include "bt-ipc-handler.h"
31 #include "bt-resource.h"
32 #include "bt-callback.h"
33 #include "bt-string-define.h"
34 #include "bt-net-connection.h"
36 static void __on_destroy(ui_gadget_h ug, service_h service, void *priv);
39 /**********************************************************************
41 ***********************************************************************/
43 static void bt_ug_change_language(bt_ug_data *ugd)
49 if (ugd->profile_vd) {
50 if (ugd->profile_vd->genlist)
51 elm_genlist_realized_items_update(
52 ugd->profile_vd->genlist);
54 if (ugd->profile_vd->navi_it)
55 elm_object_item_text_set(ugd->profile_vd->navi_it,
59 if (ugd->main_genlist)
60 elm_genlist_realized_items_update(ugd->main_genlist);
63 elm_object_item_text_set(ugd->navi_it, BT_STR_BLUETOOTH);
68 static Evas_Object *__bt_create_fullview(Evas_Object * parent, bt_ug_data *ugd)
72 Evas_Object *base = NULL;
74 base = elm_layout_add(parent);
78 elm_layout_theme_set(base, "layout", "application", "default");
79 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND,
81 evas_object_size_hint_align_set(base, EVAS_HINT_FILL, EVAS_HINT_FILL);
87 static Evas_Object *__bt_create_frameview(Evas_Object * parent,
92 Evas_Object *base = NULL;
94 base = elm_layout_add(parent);
98 elm_layout_theme_set(base, "layout", "application", "default");
99 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND,
101 evas_object_size_hint_align_set(base, EVAS_HINT_FILL, EVAS_HINT_FILL);
107 static void __bt_ug_release_memory(bt_ug_data *ugd)
111 bt_dev_t *dev = NULL;
113 Eina_List *l_next = NULL;
117 /* Release profile view data */
118 if (ugd->profile_vd) {
119 if (ugd->profile_vd->genlist)
120 elm_genlist_clear(ugd->profile_vd->genlist);
122 if (ugd->profile_vd->name_itc) {
123 elm_genlist_item_class_free(ugd->profile_vd->name_itc);
124 ugd->profile_vd->name_itc = NULL;
127 if (ugd->profile_vd->unpair_itc) {
128 elm_genlist_item_class_free(ugd->profile_vd->unpair_itc);
129 ugd->profile_vd->unpair_itc = NULL;
132 if (ugd->profile_vd->title_itc) {
133 elm_genlist_item_class_free(ugd->profile_vd->title_itc);
134 ugd->profile_vd->title_itc = NULL;
137 if (ugd->profile_vd->call_itc) {
138 elm_genlist_item_class_free(ugd->profile_vd->call_itc);
139 ugd->profile_vd->call_itc = NULL;
142 if (ugd->profile_vd->media_itc) {
143 elm_genlist_item_class_free(ugd->profile_vd->media_itc);
144 ugd->profile_vd->media_itc = NULL;
147 if (ugd->profile_vd->hid_itc) {
148 elm_genlist_item_class_free(ugd->profile_vd->hid_itc);
149 ugd->profile_vd->hid_itc = NULL;
152 free(ugd->profile_vd);
153 ugd->profile_vd = NULL;
156 /* Release paired device items */
157 EINA_LIST_FOREACH_SAFE(ugd->paired_device, l, l_next, dev) {
159 eina_list_remove_list(ugd->paired_device, l);
160 _bt_util_free_device_item(dev);
163 /* Release searched device items */
164 EINA_LIST_FOREACH_SAFE(ugd->searched_device, l, l_next, dev) {
165 ugd->searched_device =
166 eina_list_remove_list(ugd->searched_device, l);
167 _bt_util_free_device_item(dev);
170 /* Release genlist item class */
172 elm_genlist_item_class_free(ugd->sp_itc);
176 if (ugd->status_itc) {
177 elm_genlist_item_class_free(ugd->status_itc);
178 ugd->status_itc = NULL;
181 if (ugd->visible_itc) {
182 elm_genlist_item_class_free(ugd->visible_itc);
183 ugd->visible_itc = NULL;
186 if (ugd->timeout_value_itc) {
187 elm_genlist_item_class_free(ugd->timeout_value_itc);
188 ugd->timeout_value_itc = NULL;
191 if (ugd->paired_title_itc) {
192 elm_genlist_item_class_free(ugd->paired_title_itc);
193 ugd->paired_title_itc = NULL;
196 if (ugd->searched_title_itc) {
197 elm_genlist_item_class_free(ugd->searched_title_itc);
198 ugd->searched_title_itc = NULL;
201 if (ugd->device_itc) {
202 elm_genlist_item_class_free(ugd->device_itc);
203 ugd->device_itc = NULL;
206 if (ugd->searched_itc) {
207 elm_genlist_item_class_free(ugd->searched_itc);
208 ugd->searched_itc = NULL;
211 if (ugd->no_device_itc) {
212 elm_genlist_item_class_free(ugd->no_device_itc);
213 ugd->no_device_itc = NULL;
216 if (ugd->main_genlist)
217 elm_genlist_clear(ugd->main_genlist);
219 /* Unref the Dbus connections */
221 dbus_g_connection_unref(ugd->conn);
223 if (ugd->popup_bundle) {
224 free(ugd->popup_bundle);
225 ugd->popup_bundle = NULL;
228 if (ugd->popup_timer) {
229 g_source_remove(ugd->popup_timer);
230 ugd->popup_timer = 0;
236 static void *__on_create(ui_gadget_h ug, enum ug_mode mode, service_h service,
241 bt_ug_data *ugd = NULL;
242 Evas_Object *bg = NULL;
247 ugd = (bt_ug_data *)priv;
250 bindtextdomain(PKGNAME, LOCALEDIR);
252 ugd->win_main = ug_get_parent_layout(ug);
257 if (mode == UG_MODE_FULLVIEW) {
258 ugd->base = __bt_create_fullview(ugd->win_main, ugd);
259 bg = _bt_create_bg(ugd->win_main, "group_list");
260 elm_object_part_content_set(ugd->base, "elm.swallow.bg", bg);
262 ugd->base = __bt_create_frameview(ugd->win_main, ugd);
263 bg = _bt_create_bg(ugd->win_main, "transparent");
264 elm_object_part_content_set(ugd->base, "elm.swallow.bg", bg);
267 _bt_main_init_status(ugd, service);
268 _bt_ipc_init_event_signal((void *)ugd);
270 ugd->service = service;
272 if (ugd->bt_launch_mode != BT_LAUNCH_VISIBILITY) {
273 _bt_main_draw_list_view(ugd);
275 _bt_main_draw_visibility_view(ugd);
278 evas_object_show(ugd->base);
280 ugd->ug_status = BT_UG_CREATE;
286 static void __on_start(ui_gadget_h ug, service_h service, void *priv)
291 bt_ug_data *ugd = NULL;
293 retm_if(priv == NULL, "Invalid argument: priv is NULL\n");
297 g_angle = elm_win_rotation_get(ugd->win_main);
298 ugd->rotation = (int)(g_angle / 90);
300 BT_DBG("rotation: %d", ugd->rotation);
302 ugd->ug_status = BT_UG_START;
307 static void __on_pause(ui_gadget_h ug, service_h service, void *priv)
310 bt_ug_data *ugd = NULL;
312 retm_if(priv == NULL, "Invalid argument: priv is NULL\n");
314 ugd = (bt_ug_data *)priv;
316 if (ugd->op_status == BT_SEARCHING)
317 bt_adapter_stop_device_discovery();
319 ugd->ug_status = BT_UG_PAUSE;
324 static void __on_resume(ui_gadget_h ug, service_h service, void *priv)
328 bt_ug_data *ugd = NULL;
330 retm_if(priv == NULL, "Invalid argument: priv is NULL\n");
332 ugd = (bt_ug_data *)priv;
334 ugd->ug_status = BT_UG_RESUME;
336 if (ugd->visible_item)
337 elm_genlist_item_update(ugd->visible_item);
342 static void __on_destroy(ui_gadget_h ug, service_h service, void *priv)
346 bt_ug_data *ugd = NULL;
354 ugd->ug_status = BT_UG_DESTORY;
356 if (ugd->request_timer) {
357 ecore_timer_del(ugd->request_timer);
358 ugd->request_timer = NULL;
361 if (ugd->timeout_id) {
362 g_source_remove(ugd->timeout_id);
366 if (ugd->op_status == BT_SEARCHING)
367 bt_adapter_stop_device_discovery();
369 if (ugd->selectioninfo) {
370 evas_object_del(ugd->selectioninfo);
371 ugd->selectioninfo = NULL;
374 bt_adapter_unset_state_changed_cb();
375 bt_adapter_unset_device_discovery_state_changed_cb();
376 bt_device_unset_bond_created_cb();
377 bt_device_unset_bond_destroyed_cb();
378 bt_device_unset_service_searched_cb();
379 bt_audio_unset_connection_state_changed_cb();
380 bt_hid_host_deinitialize();
381 bt_audio_deinitialize();
385 _bt_destroy_net_connection(ugd->connection);
387 _bt_ipc_unregister_popup_event_signal(ugd->EDBusHandle, (void *)ugd);
388 _bt_ipc_deinit_event_signal((void *)ugd);
390 __bt_ug_release_memory(ugd);
393 evas_object_del(ugd->base);
400 static void __on_message(ui_gadget_h ug, service_h msg, service_h service,
407 static void __on_event(ui_gadget_h ug, enum ug_event event, service_h service,
412 bt_ug_data *ugd = NULL;
414 ret_if(priv == NULL);
416 ugd = (bt_ug_data *)priv;
418 BT_DBG("event: %d", event);
421 case UG_EVENT_LOW_MEMORY:
423 case UG_EVENT_LOW_BATTERY:
424 if (_bt_util_is_battery_low() == FALSE)
427 if (ugd->op_status == BT_SEARCHING)
428 bt_adapter_stop_device_discovery();
430 _bt_main_create_information_popup(ugd, BT_STR_LOW_BATTERY);
432 case UG_EVENT_LANG_CHANGE:
433 bt_ug_change_language(ugd);
435 case UG_EVENT_ROTATE_PORTRAIT:
436 ugd->rotation = BT_ROTATE_PORTRAIT;
438 case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
439 ugd->rotation = BT_ROTATE_PORTRAIT_UPSIDEDOWN;
441 case UG_EVENT_ROTATE_LANDSCAPE:
442 ugd->rotation = BT_ROTATE_LANDSCAPE;
444 case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
445 ugd->rotation = BT_ROTATE_LANDSCAPE_UPSIDEDOWN;
451 if (event == UG_EVENT_ROTATE_PORTRAIT ||
452 event == UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN ||
453 event == UG_EVENT_ROTATE_LANDSCAPE ||
454 event == UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN) {
455 _bt_rotate_selectioninfo(ugd->selectioninfo, ugd->rotation);
456 _bt_main_change_rotate_mode((void *)ugd);
462 static void __on_key_event(ui_gadget_h ug, enum ug_key_event event,
463 service_h service, void *priv)
467 bt_ug_data *ugd = NULL;
469 BT_DBG("event: %d\n", event);
471 ugd = (bt_ug_data *)priv;
474 case UG_KEY_EVENT_END:
475 _bt_ug_destroy(ugd, NULL);
483 /**********************************************************************
485 ***********************************************************************/
487 UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops)
491 bt_ug_data *ugd = NULL;
496 ugd = calloc(1, sizeof(bt_ug_data));
500 ops->create = __on_create;
501 ops->start = __on_start;
502 ops->pause = __on_pause;
503 ops->resume = __on_resume;
504 ops->destroy = __on_destroy;
505 ops->message = __on_message;
506 ops->event = __on_event;
507 ops->key_event = __on_key_event;
509 ops->opt = UG_OPT_INDICATOR_ENABLE;
512 return BT_UG_ERROR_NONE;
515 UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops)
531 UG_MODULE_API int setting_plugin_reset(service_h service, void *priv)
535 _bt_reset_environment();
541 void _bt_ug_destroy(void *data, void *result)
545 bt_ug_data *ugd = NULL;
547 ret_if(data == NULL);
549 ugd = (bt_ug_data *)data;
551 if (result != NULL) {
552 ug_send_result(ugd->ug, result);
556 ret = ug_destroy_me(ugd->ug);
559 BT_DBG("Fail to destroy me");