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.
20 #include <syspopup_caller.h>
21 #include <tapi_common.h>
23 #include <ITapiModem.h>
24 #include <TapiUtility.h>
27 #include "quickpanel-ui.h"
29 #include "setting_utils.h"
30 #include "setting_module_api.h"
32 #define BUTTON_LABEL _("IDS_ST_BUTTON2_FLIGHT_NMODE")
33 #define BUTTON_ICON_NORMAL "quick_icon_flightmode.png"
34 #define BUTTON_ICON_HIGHLIGHT NULL
35 #define BUTTON_ICON_DIM NULL
36 #define PACKAGE_SETTING_MENU "setting-flightmode-efl"
37 #define SYSPOPUP_NAME "mode-syspopup"
39 static Eina_Bool fly_icon_is_locked = EINA_FALSE;
40 static Ecore_Timer *timer = NULL;
42 static void _mouse_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source);
44 static const char *_label_get(void) {
48 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_NORMAL) {
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 Eina_Bool _unlock_fly_icon(void *data)
64 fly_icon_is_locked = EINA_FALSE;
65 ecore_timer_del(timer);
68 return ECORE_CALLBACK_CANCEL;
71 static void _long_press_cb(void *data) {
72 #ifdef PACKAGE_SETTING_MENU
73 if(fly_icon_is_locked == EINA_TRUE)
75 LOGD("Fly icon is locked");
78 qp_setting_icon_handler_longpress(PACKAGE_SETTING_MENU, NULL);
82 static void _view_update(Evas_Object *view, int state, int flag_extra_1, int flag_extra_2) {
83 Evas_Object *image = NULL;
84 const char *icon_path = NULL;
86 qp_setting_icon_state_set(view, state);
88 if (state == ICON_VIEW_STATE_ON) {
89 #ifdef BUTTON_ICON_HIGHLIGHT
90 icon_path = BUTTON_ICON_HIGHLIGHT;
92 } else if (state == ICON_VIEW_STATE_DIM) {
93 #ifdef BUTTON_ICON_DIM
94 icon_path = BUTTON_ICON_DIM;
97 icon_path = BUTTON_ICON_NORMAL;
100 if (icon_path == NULL) {
101 icon_path = BUTTON_ICON_NORMAL;
103 image = qp_setting_icon_image_new(view, icon_path);
104 qp_setting_icon_content_set(view, image);
105 qp_setting_icon_text_set(view, BUTTON_LABEL, state);
108 static void _status_update(QP_Module_Setting *module, int flag_extra_1, int flag_extra_2) {
112 retif(module == NULL, , "Invalid parameter!");
114 ret = vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &status);
115 msgif(ret != 0, "fail to get VCONFKEY_TELEPHONY_FLIGHT_MODE:%d", ret);
118 qp_setting_module_icon_state_set(module, ICON_VIEW_STATE_ON);
120 qp_setting_module_icon_state_set(module, ICON_VIEW_STATE_OFF);
123 qp_setting_module_progress_mode_set(module, FLAG_DISABLE, FLAG_TURN_OFF);
124 qp_setting_module_icon_timer_del(module);
126 qp_setting_module_icon_view_update(module,
127 qp_setting_module_icon_state_get(module),
131 static void _tapi_flight_mode_cb(TapiHandle *handle, int result, void *data, void *user_data)
133 ERR("flight mode result:%d", result);
134 _status_update(user_data, FLAG_VALUE_VOID, FLAG_VALUE_VOID);
137 static int _tapi_flight_mode_set(int on, void *data)
141 int ret_t = TAPI_API_SUCCESS;
142 TapiHandle *tapi_handle = NULL;
143 QP_Module_Setting *module = (QP_Module_Setting *)data;
144 retif(module == NULL, QP_FAIL, "Invalid parameter!");
146 tapi_handle = tel_init(NULL);
147 retif(tapi_handle == NULL, QP_FAIL, "failed to initialized tapi handler");
150 ret_t = tel_set_flight_mode(tapi_handle,
151 TAPI_POWER_FLIGHT_MODE_ENTER, _tapi_flight_mode_cb, data);
152 if (ret_t != TAPI_API_SUCCESS) {
154 ERR("tel_set_flight_mode enter error:%d", ret_t);
157 ret_t = tel_set_flight_mode(tapi_handle,
158 TAPI_POWER_FLIGHT_MODE_LEAVE, _tapi_flight_mode_cb, data);
159 if (ret_t != TAPI_API_SUCCESS) {
161 ERR("tel_set_flight_mode leave error:%d", ret_t);
165 if ((ret_t = tel_deinit(tapi_handle)) != TAPI_API_SUCCESS) {
166 ERR("failed to deinitialized tapi handler:%d", ret_t);
172 static void _turn_on(int is_on)
179 bundle_add(b, "_MODE_SYSTEM_POPUP_TYPE_", "MODE_SYSTEM_FLIGHTMODE_ON");
181 bundle_add(b, "_MODE_SYSTEM_POPUP_TYPE_", "MODE_SYSTEM_FLIGHTMODE_OFF");
183 syspopup_launch(SYSPOPUP_NAME, b);
186 ERR("failed to create a bundle");
189 timer = ecore_timer_add(1.0, _unlock_fly_icon, NULL);
192 static void _mouse_clicked_cb(void *data,
193 Evas_Object *obj, const char *emission, const char *source) {
194 QP_Module_Setting *module = (QP_Module_Setting *)data;
196 retif(module == NULL, , "Invalid parameter!");
198 if(fly_icon_is_locked == EINA_TRUE)
200 LOGD("Fly icon is locked");
204 if (qp_setting_module_is_icon_clickable(module) == 0)
206 LOGD("Fly icon is not clickable");
210 fly_icon_is_locked = EINA_TRUE;
212 if (qp_setting_module_icon_state_get(module) == ICON_VIEW_STATE_OFF)
222 static void _tapi_flight_mode_vconf_cb(keynode_t *node, void *data)
224 _status_update(data, FLAG_VALUE_VOID, FLAG_VALUE_VOID);
227 static int _register_module_event_handler(void *data) {
230 ret = vconf_notify_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE,
231 _tapi_flight_mode_vconf_cb, data);
232 msgif(ret != 0, "failed to notify key(VCONFKEY_TELEPHONY_FLIGHT_MODE) : %d", ret);
237 static int _unregister_module_event_handler(void *data) {
240 ret = vconf_ignore_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE,
241 _tapi_flight_mode_vconf_cb);
242 msgif(ret != 0, "failed to ignore key(VCONFKEY_TELEPHONY_FLIGHT_MODE) : %d", ret);
247 /****************************************************************************
249 * Quickpanel Item functions
251 ****************************************************************************/
253 static int _init(void *data) {
256 ret = _register_module_event_handler(data);
261 static int _fini(void *data) {
264 ret = _unregister_module_event_handler(data);
269 static void _lang_changed(void *data) {
270 QP_Module_Setting *module = (QP_Module_Setting *)data;
271 retif(module == NULL, , "Invalid parameter!");
273 qp_setting_module_icon_view_update_text(module);
276 static void _refresh(void *data) {
277 QP_Module_Setting *module = (QP_Module_Setting *)data;
278 retif(module == NULL, , "Invalid parameter!");
280 qp_setting_module_icon_view_update_text(module);
283 static void _reset_icon(QP_Module_Setting *module) {
284 retif(module == NULL, , "Invalid parameter!");
286 qp_setting_module_progress_mode_set(module, FLAG_DISABLE, FLAG_VALUE_VOID);
287 _status_update(module, FLAG_VALUE_VOID, FLAG_VALUE_VOID);
290 static void _handler_on(void *data) {
292 QP_Module_Setting *module = (QP_Module_Setting *)data;
293 retif(module == NULL, , "Invalid parameter!");
295 qp_setting_module_progress_mode_set(module, FLAG_DISABLE, FLAG_TURN_OFF);
296 qp_setting_module_icon_timer_del(module);
298 if (qp_setting_module_icon_state_get(module) == ICON_VIEW_STATE_OFF) {
299 ret = _tapi_flight_mode_set(1, module);
302 qp_setting_module_progress_mode_set(module, FLAG_ENABLE, FLAG_TURN_ON);
303 qp_setting_module_icon_timer_add(module);
305 ERR("op failed:%d", ret);
308 ERR("the button is already turned on");
313 static void _handler_off(void *data) {
315 QP_Module_Setting *module = (QP_Module_Setting *)data;
316 retif(module == NULL, , "Invalid parameter!");
318 qp_setting_module_progress_mode_set(module, FLAG_DISABLE, FLAG_TURN_OFF);
319 qp_setting_module_icon_timer_del(module);
321 if (qp_setting_module_icon_state_get(module) == ICON_VIEW_STATE_ON) {
322 ret = _tapi_flight_mode_set(0, module);
325 qp_setting_module_progress_mode_set(module, FLAG_ENABLE, FLAG_TURN_OFF);
326 qp_setting_module_icon_timer_add(module);
328 ERR("op failed:%d", ret);
331 ERR("the button is already turned off");
336 static void _handler_progress_on(void *data) {
337 QP_Module_Setting *module = (QP_Module_Setting *)data;
338 retif(module == NULL, , "Invalid parameter!");
340 qp_setting_module_progress_mode_set(module, FLAG_ENABLE, FLAG_VALUE_VOID);
343 static void _handler_progress_off(void *data) {
344 QP_Module_Setting *module = (QP_Module_Setting *)data;
345 retif(module == NULL, , "Invalid parameter!");
350 static int _handler_ipc(const char *command, void *data) {
352 retif(data == NULL, EINA_FALSE, "item data is NULL");
353 retif(command == NULL, EINA_FALSE, "command is NULL");
355 static Setting_Activity_Handler __table_handler[] = {
358 .handler = _handler_on,
362 .handler = _handler_off,
365 .command = "progress_on",
366 .handler = _handler_progress_on,
369 .command = "progress_off",
370 .handler = _handler_progress_off,
378 for (i = 0; __table_handler[i].command; i++) {
379 if (strcmp(__table_handler[i].command, command)) {
383 if (__table_handler[i].handler != NULL) {
384 DBG("process:%s", command);
385 __table_handler[i].handler(data);
393 QP_Module_Setting flightmode = {
394 .name = "flightmode",
397 .lang_changed = _lang_changed,
399 .icon_get = _icon_get,
400 .label_get = _label_get,
401 .view_update = _view_update,
402 .status_update = _status_update,
403 .handler_longpress = _long_press_cb,
404 .handler_ipc = _handler_ipc,
405 .handler_press = _mouse_clicked_cb,