2 * Copyright (c) 2009-2015 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <bluetooth.h>
22 #include "quickpanel-ui.h"
24 #include "setting_utils.h"
25 #include "setting_module_api.h"
27 #define BUTTON_LABEL _("IDS_ST_BUTTON2_BLUETOOTH_ABB")
28 #define BUTTON_ICON_NORMAL "quick_icon_bluetooth.png"
29 #define BUTTON_ICON_HIGHLIGHT NULL
30 #define BUTTON_ICON_DIM NULL
31 #define PACKAGE_SETTING_MENU "ug-bluetooth-efl-single"
33 static void _mouse_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source);
35 static const char *_label_get(void) {
39 static const char *_icon_get(qp_setting_icon_image_type type) {
40 if (type == QP_SETTING_ICON_NORMAL) {
41 return BUTTON_ICON_NORMAL;
42 } else if (type == QP_SETTING_ICON_NORMAL) {
43 return BUTTON_ICON_HIGHLIGHT;
44 } else if (type == QP_SETTING_ICON_DIM) {
45 #ifdef BUTTON_ICON_DIM
46 return BUTTON_ICON_DIM;
53 static void _long_press_cb(void *data) {
54 #ifdef PACKAGE_SETTING_MENU
55 qp_setting_icon_handler_longpress(PACKAGE_SETTING_MENU, NULL);
59 static void _view_update(Evas_Object *view, int state, int flag_extra_1, int flag_extra_2) {
60 Evas_Object *image = NULL;
61 const char *icon_path = NULL;
63 qp_setting_icon_state_set(view, state);
65 if (state == ICON_VIEW_STATE_ON) {
66 #ifdef BUTTON_ICON_HIGHLIGHT
67 icon_path = BUTTON_ICON_HIGHLIGHT;
69 } else if (state == ICON_VIEW_STATE_DIM) {
70 #ifdef BUTTON_ICON_DIM
71 icon_path = BUTTON_ICON_DIM;
74 icon_path = BUTTON_ICON_NORMAL;
77 if (icon_path == NULL) {
78 icon_path = BUTTON_ICON_NORMAL;
80 image = qp_setting_icon_image_new(view, icon_path);
81 qp_setting_icon_content_set(view, image);
82 qp_setting_icon_text_set(view, BUTTON_LABEL, state);
85 static void _status_update(QP_Module_Setting *module, int flag_extra_1, int flag_extra_2) {
87 bt_adapter_state_e adapter_state = BT_ADAPTER_DISABLED;
88 retif(module == NULL, , "Invalid parameter!");
90 ret = bt_adapter_get_state(&adapter_state);
91 retif(ret != BT_ERROR_NONE, , "bt_adapter_get_state failed");
93 if (adapter_state == BT_ADAPTER_ENABLED) {
94 qp_setting_module_icon_state_set(module, ICON_VIEW_STATE_ON);
96 qp_setting_module_icon_state_set(module, ICON_VIEW_STATE_OFF);
99 qp_setting_module_progress_mode_set(module, FLAG_DISABLE, FLAG_TURN_OFF);
100 qp_setting_module_icon_timer_del(module);
102 qp_setting_module_icon_view_update(module,
103 qp_setting_module_icon_state_get(module),
107 static void _mouse_clicked_cb(void *data,
108 Evas_Object *obj, const char *emission, const char *source) {
111 QP_Module_Setting *module = (QP_Module_Setting *)data;
112 retif(module == NULL, , "Invalid parameter!");
114 if (qp_setting_module_is_icon_clickable(module) == 0) return ;
116 if (qp_setting_module_icon_state_get(module) == ICON_VIEW_STATE_ON) {
117 ret = bt_adapter_disable();
118 retif(ret != BT_ERROR_NONE, , "failed to disable BT adapter");
122 ret = bt_adapter_enable();
123 retif(ret != BT_ERROR_NONE, , "failed to enable BT adapter");
129 qp_setting_module_progress_mode_set(module, FLAG_ENABLE, FLAG_TURN_ON);
131 qp_setting_module_progress_mode_set(module, FLAG_ENABLE, FLAG_TURN_OFF);
133 qp_setting_module_icon_timer_add(module);
136 static void __bluetooth_status_changed_cb(int result,
137 bt_adapter_state_e adapter_state,
140 QP_Module_Setting *module = (QP_Module_Setting *)user_data;
141 retif(module == NULL, , "Invalid parameter!");
143 INFO("bluetooth state : %d", adapter_state);
144 qp_setting_module_icon_timer_del(module);
146 if (result != BT_ERROR_NONE) {
147 ERR("BT adapter operation is failed");
148 _status_update(module, FLAG_VALUE_VOID, FLAG_VALUE_VOID);
152 _status_update(module, FLAG_VALUE_VOID, FLAG_VALUE_VOID);
155 static int _register_module_event_handler(void *data) {
158 ret = bt_initialize();
159 msgif(ret != BT_ERROR_NONE, "bt_initialize failed");
161 ret = bt_adapter_set_state_changed_cb(__bluetooth_status_changed_cb, data);
162 msgif(ret != BT_ERROR_NONE, "bt_adapter_set_state_changed_cb failed");
167 static int _unregister_module_event_handler(void *data) {
170 ret = bt_adapter_unset_state_changed_cb();
171 msgif(ret != BT_ERROR_NONE, "bt_adapter_unset_state_changed_cb failed");
173 ret = bt_deinitialize();
174 msgif(ret != BT_ERROR_NONE, "bt_deinitialize failed");
179 /****************************************************************************
181 * Quickpanel Item functions
183 ****************************************************************************/
184 static int _init(void *data) {
187 ret = _register_module_event_handler(data);
192 static int _fini(void *data) {
195 ret = _unregister_module_event_handler(data);
200 static void _lang_changed(void *data) {
201 QP_Module_Setting *module = (QP_Module_Setting *)data;
202 retif(module == NULL, , "Invalid parameter!");
204 qp_setting_module_icon_view_update_text(module);
207 static void _refresh(void *data) {
208 QP_Module_Setting *module = (QP_Module_Setting *)data;
209 retif(module == NULL, , "Invalid parameter!");
211 qp_setting_module_icon_view_update_text(module);
214 QP_Module_Setting bluetooth = {
218 .lang_changed = _lang_changed,
220 .icon_get = _icon_get,
221 .label_get = _label_get,
222 .view_update = _view_update,
223 .status_update = _status_update,
224 .handler_longpress = _long_press_cb,
225 .handler_press = _mouse_clicked_cb,