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 <Elementary.h>
20 #include <bluetooth.h>
22 #include <bluetooth_internal.h>
24 #include <tzsh_quickpanel_service.h>
28 #include "quickpanel-ui.h"
30 #include "setting_utils.h"
31 #include "setting_module_api.h"
32 #include "settings_icon_common.h"
34 #define BUTTON_LABEL _("IDS_ST_BUTTON2_BLUETOOTH_ABB")
35 #define BUTTON_ICON_NORMAL "quick_icon_bluetooth.png"
36 #define BUTTON_ICON_HIGHLIGHT NULL
37 #define BUTTON_ICON_DIM NULL
38 #define PACKAGE_SETTING_MENU "ug-bluetooth-efl"
40 static void _mouse_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source);
42 static const char *_label_get(void)
47 static const char *_icon_get(qp_setting_icon_image_type type)
49 if (type == QP_SETTING_ICON_NORMAL) {
50 return BUTTON_ICON_NORMAL;
51 } else if (type == QP_SETTING_ICON_HIGHLIGHT) {
52 return BUTTON_ICON_HIGHLIGHT;
53 } else if (type == QP_SETTING_ICON_DIM) {
54 #ifdef BUTTON_ICON_DIM
55 return BUTTON_ICON_DIM;
62 static void _long_press_cb(void *data)
64 #ifdef PACKAGE_SETTING_MENU
65 quickpanel_setting_icon_handler_longpress(PACKAGE_SETTING_MENU, NULL);
69 static void _view_update(Evas_Object *view, int state, int flag_extra_1, int flag_extra_2)
71 Evas_Object *image = NULL;
72 const char *icon_path = NULL;
74 quickpanel_setting_icon_state_set(view, state);
76 if (state == ICON_VIEW_STATE_ON) {
77 #ifdef BUTTON_ICON_HIGHLIGHT
78 icon_path = BUTTON_ICON_HIGHLIGHT;
80 } else if (state == ICON_VIEW_STATE_DIM) {
81 #ifdef BUTTON_ICON_DIM
82 icon_path = BUTTON_ICON_DIM;
85 icon_path = BUTTON_ICON_NORMAL;
88 if (icon_path == NULL) {
89 icon_path = BUTTON_ICON_NORMAL;
91 image = quickpanel_setting_icon_image_new(view, icon_path);
92 quickpanel_setting_icon_content_set(view, image);
93 quickpanel_setting_icon_text_set(view, BUTTON_LABEL, state);
96 static void _status_update(QP_Module_Setting *module, int flag_extra_1, int flag_extra_2)
99 bt_adapter_state_e adapter_state = BT_ADAPTER_DISABLED;
100 retif(module == NULL, , "Invalid parameter!");
102 ret = bt_adapter_get_state(&adapter_state);
103 if (ret != BT_ERROR_NONE) {
104 DBG("bt_adapter_get_state failed [%d]", ret);
107 if (adapter_state == BT_ADAPTER_ENABLED) {
108 quickpanel_setting_module_icon_state_set(module, ICON_VIEW_STATE_ON);
110 quickpanel_setting_module_icon_state_set(module, ICON_VIEW_STATE_OFF);
113 quickpanel_setting_module_progress_mode_set(module, FLAG_DISABLE, FLAG_TURN_OFF);
114 quickpanel_setting_module_icon_timer_del(module);
116 quickpanel_setting_module_icon_view_update(module,
117 quickpanel_setting_module_icon_state_get(module),
121 static void _mouse_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
125 QP_Module_Setting *module = (QP_Module_Setting *)data;
126 retif(module == NULL, , "Invalid parameter!");
128 if (quickpanel_setting_module_is_icon_clickable(module) == 0) {
132 if (quickpanel_setting_module_icon_state_get(module) == ICON_VIEW_STATE_ON) {
133 ret = bt_adapter_disable();
134 retif(ret != BT_ERROR_NONE, , "failed to disable BT adapter");
138 ret = bt_adapter_enable();
139 retif(ret != BT_ERROR_NONE, , "failed to enable BT adapter");
145 quickpanel_setting_module_progress_mode_set(module, FLAG_ENABLE, FLAG_TURN_ON);
147 quickpanel_setting_module_progress_mode_set(module, FLAG_ENABLE, FLAG_TURN_OFF);
149 quickpanel_setting_module_icon_timer_add(module);
152 static void _bluetooth_status_changed_cb(int result, bt_adapter_state_e adapter_state, void *user_data)
154 QP_Module_Setting *module = (QP_Module_Setting *)user_data;
155 retif(module == NULL, , "Invalid parameter!");
157 INFO("bluetooth state : %d", adapter_state);
158 quickpanel_setting_module_icon_timer_del(module);
160 if (result != BT_ERROR_NONE) {
161 ERR("BT adapter operation is failed");
162 _status_update(module, FLAG_VALUE_VOID, FLAG_VALUE_VOID);
166 _status_update(module, FLAG_VALUE_VOID, FLAG_VALUE_VOID);
169 static int _register_module_event_handler(void *data)
173 ret = bt_initialize();
174 msgif(ret != BT_ERROR_NONE, "bt_initialize failed");
176 ret = bt_adapter_set_state_changed_cb(_bluetooth_status_changed_cb, data);
177 msgif(ret != BT_ERROR_NONE, "bt_adapter_set_state_changed_cb failed");
182 static int _unregister_module_event_handler(void *data)
186 ret = bt_adapter_unset_state_changed_cb();
187 msgif(ret != BT_ERROR_NONE, "bt_adapter_unset_state_changed_cb failed");
189 ret = bt_deinitialize();
190 msgif(ret != BT_ERROR_NONE, "bt_deinitialize failed");
195 /****************************************************************************
197 * Quickpanel Item functions
199 ****************************************************************************/
200 static int _init(void *data)
204 ret = _register_module_event_handler(data);
209 static int _fini(void *data)
213 ret = _unregister_module_event_handler(data);
218 static void _lang_changed(void *data)
220 QP_Module_Setting *module = (QP_Module_Setting *)data;
221 retif(module == NULL, , "Invalid parameter!");
223 quickpanel_setting_module_icon_view_update_text(module);
226 static void _refresh(void *data)
228 QP_Module_Setting *module = (QP_Module_Setting *)data;
229 retif(module == NULL, , "Invalid parameter!");
231 quickpanel_setting_module_icon_view_update_text(module);
234 QP_Module_Setting bluetooth = {
238 .lang_changed = _lang_changed,
240 .icon_get = _icon_get,
241 .label_get = _label_get,
242 .view_update = _view_update,
243 .status_update = _status_update,
244 .handler_longpress = _long_press_cb,
245 .handler_press = _mouse_clicked_cb,