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>
21 #include <syspopup_caller.h>
22 #include <tapi_common.h>
24 #include <ITapiModem.h>
25 #include <TapiUtility.h>
26 #include <system_settings.h>
27 #include <bundle_internal.h>
29 #include <tzsh_quickpanel_service.h>
32 #include "quickpanel-ui.h"
34 #include "setting_utils.h"
35 #include "setting_module_api.h"
36 #include "settings_icon_common.h"
38 #define BUTTON_LABEL _("IDS_ST_BUTTON2_FLIGHT_NMODE")
39 #define BUTTON_ICON_NORMAL "quick_icon_flightmode.png"
40 #define BUTTON_ICON_HIGHLIGHT NULL
41 #define BUTTON_ICON_DIM NULL
42 #define PACKAGE_SETTING_MENU "setting-flightmode-efl"
43 #define SYSPOPUP_NAME "mode-syspopup"
45 static Eina_Bool fly_icon_is_locked = EINA_FALSE;
46 static Ecore_Timer *timer = NULL;
48 static void _mouse_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source);
50 static const char *_label_get(void)
55 static const char *_icon_get(qp_setting_icon_image_type type)
57 if (type == QP_SETTING_ICON_NORMAL) {
58 return BUTTON_ICON_NORMAL;
59 } else if (type == QP_SETTING_ICON_HIGHLIGHT) {
60 return BUTTON_ICON_HIGHLIGHT;
61 } else if (type == QP_SETTING_ICON_DIM) {
62 #ifdef BUTTON_ICON_DIM
63 return BUTTON_ICON_DIM;
70 static Eina_Bool _unlock_fly_icon(void *data)
72 fly_icon_is_locked = EINA_FALSE;
73 ecore_timer_del(timer);
76 return ECORE_CALLBACK_CANCEL;
79 static void _long_press_cb(void *data)
81 #ifdef PACKAGE_SETTING_MENU
82 if (fly_icon_is_locked == EINA_TRUE) {
83 LOGD("Fly icon is locked");
86 quickpanel_setting_icon_handler_longpress(PACKAGE_SETTING_MENU, NULL);
90 static void _view_update(Evas_Object *view, int state, int flag_extra_1, int flag_extra_2)
92 Evas_Object *image = NULL;
93 const char *icon_path = NULL;
95 quickpanel_setting_icon_state_set(view, state);
97 if (state == ICON_VIEW_STATE_ON) {
98 #ifdef BUTTON_ICON_HIGHLIGHT
99 icon_path = BUTTON_ICON_HIGHLIGHT;
101 } else if (state == ICON_VIEW_STATE_DIM) {
102 #ifdef BUTTON_ICON_DIM
103 icon_path = BUTTON_ICON_DIM;
106 icon_path = BUTTON_ICON_NORMAL;
109 if (icon_path == NULL) {
110 icon_path = BUTTON_ICON_NORMAL;
112 image = quickpanel_setting_icon_image_new(view, icon_path);
113 quickpanel_setting_icon_content_set(view, image);
114 quickpanel_setting_icon_text_set(view, BUTTON_LABEL, state);
117 static void _status_update(QP_Module_Setting *module, int flag_extra_1, int flag_extra_2)
122 retif(module == NULL, , "Invalid parameter!");
124 ret = system_settings_get_value_bool(SYSTEM_SETTINGS_KEY_NETWORK_FLIGHT_MODE, &status);
125 msgif(ret != SYSTEM_SETTINGS_ERROR_NONE, "fail to get VCONFKEY_TELEPHONY_FLIGHT_MODE:%d", ret);
127 if (status == true) {
128 quickpanel_setting_module_icon_state_set(module, ICON_VIEW_STATE_ON);
130 quickpanel_setting_module_icon_state_set(module, ICON_VIEW_STATE_OFF);
133 quickpanel_setting_module_progress_mode_set(module, FLAG_DISABLE, FLAG_TURN_OFF);
134 quickpanel_setting_module_icon_timer_del(module);
136 quickpanel_setting_module_icon_view_update(module, quickpanel_setting_module_icon_state_get(module), FLAG_VALUE_VOID);
139 static void _tapi_flight_mode_cb(TapiHandle *handle, int result, void *data, void *user_data)
141 ERR("flight mode result:%d", result);
142 _status_update(user_data, FLAG_VALUE_VOID, FLAG_VALUE_VOID);
145 static int _tapi_flight_mode_set(int on, void *data)
149 int ret_t = TAPI_API_SUCCESS;
150 TapiHandle *tapi_handle = NULL;
151 QP_Module_Setting *module = (QP_Module_Setting *)data;
152 retif(module == NULL, QP_FAIL, "Invalid parameter!");
154 tapi_handle = tel_init(NULL);
155 retif(tapi_handle == NULL, QP_FAIL, "failed to initialized tapi handler");
158 ret_t = tel_set_flight_mode(tapi_handle,
159 TAPI_POWER_FLIGHT_MODE_ENTER, _tapi_flight_mode_cb, data);
160 if (ret_t != TAPI_API_SUCCESS) {
162 ERR("tel_set_flight_mode enter error:%d", ret_t);
165 ret_t = tel_set_flight_mode(tapi_handle,
166 TAPI_POWER_FLIGHT_MODE_LEAVE, _tapi_flight_mode_cb, data);
167 if (ret_t != TAPI_API_SUCCESS) {
169 ERR("tel_set_flight_mode leave error:%d", ret_t);
173 if ((ret_t = tel_deinit(tapi_handle)) != TAPI_API_SUCCESS) {
174 ERR("failed to deinitialized tapi handler:%d", ret_t);
180 static void _turn_on(int is_on)
187 bundle_add(b, "_MODE_SYSTEM_POPUP_TYPE_", "MODE_SYSTEM_FLIGHTMODE_ON");
189 bundle_add(b, "_MODE_SYSTEM_POPUP_TYPE_", "MODE_SYSTEM_FLIGHTMODE_OFF");
191 syspopup_launch(SYSPOPUP_NAME, b);
194 ERR("failed to create a bundle");
197 timer = ecore_timer_add(1.0, _unlock_fly_icon, NULL);
200 static void _mouse_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
202 QP_Module_Setting *module = (QP_Module_Setting *)data;
204 retif(module == NULL, , "Invalid parameter!");
206 if (fly_icon_is_locked == EINA_TRUE) {
207 LOGD("Fly icon is locked");
211 if (quickpanel_setting_module_is_icon_clickable(module) == 0) {
212 LOGD("Fly icon is not clickable");
216 fly_icon_is_locked = EINA_TRUE;
218 if (quickpanel_setting_module_icon_state_get(module) == ICON_VIEW_STATE_OFF) {
225 static void _tapi_flight_mode_vconf_cb(system_settings_key_e key, void *data)
227 _status_update(data, FLAG_VALUE_VOID, FLAG_VALUE_VOID);
230 static int _register_module_event_handler(void *data)
234 ret = system_settings_set_changed_cb(SYSTEM_SETTINGS_KEY_NETWORK_FLIGHT_MODE, _tapi_flight_mode_vconf_cb, data);
235 msgif(ret != SYSTEM_SETTINGS_ERROR_NONE, "failed to notify key(SYSTEM_SETTINGS_KEY_NETWORK_FLIGHT_MODE) : %d", ret);
240 static int _unregister_module_event_handler(void *data)
244 ret = system_settings_unset_changed_cb(SYSTEM_SETTINGS_KEY_NETWORK_FLIGHT_MODE);
245 msgif(ret != SYSTEM_SETTINGS_ERROR_NONE, "failed to ignore key(SYSTEM_SETTINGS_KEY_NETWORK_FLIGHT_MODE) : %d", ret);
250 /****************************************************************************
252 * Quickpanel Item functions
254 ****************************************************************************/
256 static int _init(void *data)
260 ret = _register_module_event_handler(data);
265 static int _fini(void *data)
269 ret = _unregister_module_event_handler(data);
274 static void _lang_changed(void *data)
276 QP_Module_Setting *module = (QP_Module_Setting *)data;
277 retif(module == NULL, , "Invalid parameter!");
279 quickpanel_setting_module_icon_view_update_text(module);
282 static void _refresh(void *data)
284 QP_Module_Setting *module = (QP_Module_Setting *)data;
285 retif(module == NULL, , "Invalid parameter!");
287 quickpanel_setting_module_icon_view_update_text(module);
290 static void _reset_icon(QP_Module_Setting *module)
292 retif(module == NULL, , "Invalid parameter!");
294 quickpanel_setting_module_progress_mode_set(module, FLAG_DISABLE, FLAG_VALUE_VOID);
295 _status_update(module, FLAG_VALUE_VOID, FLAG_VALUE_VOID);
298 static void _handler_on(void *data)
301 QP_Module_Setting *module = (QP_Module_Setting *)data;
302 retif(module == NULL, , "Invalid parameter!");
304 quickpanel_setting_module_progress_mode_set(module, FLAG_DISABLE, FLAG_TURN_OFF);
305 quickpanel_setting_module_icon_timer_del(module);
307 if (quickpanel_setting_module_icon_state_get(module) == ICON_VIEW_STATE_OFF) {
308 ret = _tapi_flight_mode_set(1, module);
311 quickpanel_setting_module_progress_mode_set(module, FLAG_ENABLE, FLAG_TURN_ON);
312 quickpanel_setting_module_icon_timer_add(module);
314 ERR("op failed:%d", ret);
317 ERR("the button is already turned on");
322 static void _handler_off(void *data)
325 QP_Module_Setting *module = (QP_Module_Setting *)data;
326 retif(module == NULL, , "Invalid parameter!");
328 quickpanel_setting_module_progress_mode_set(module, FLAG_DISABLE, FLAG_TURN_OFF);
329 quickpanel_setting_module_icon_timer_del(module);
331 if (quickpanel_setting_module_icon_state_get(module) == ICON_VIEW_STATE_ON) {
332 ret = _tapi_flight_mode_set(0, module);
335 quickpanel_setting_module_progress_mode_set(module, FLAG_ENABLE, FLAG_TURN_OFF);
336 quickpanel_setting_module_icon_timer_add(module);
338 ERR("op failed:%d", ret);
341 ERR("the button is already turned off");
346 static void _handler_progress_on(void *data)
348 QP_Module_Setting *module = (QP_Module_Setting *)data;
349 retif(module == NULL, , "Invalid parameter!");
351 quickpanel_setting_module_progress_mode_set(module, FLAG_ENABLE, FLAG_VALUE_VOID);
354 static void _handler_progress_off(void *data)
356 QP_Module_Setting *module = (QP_Module_Setting *)data;
357 retif(module == NULL, , "Invalid parameter!");
362 static int _handler_ipc(const char *command, void *data)
365 retif(data == NULL, EINA_FALSE, "item data is NULL");
366 retif(command == NULL, EINA_FALSE, "command is NULL");
368 static Setting_Activity_Handler __table_handler[] = {
371 .handler = _handler_on,
375 .handler = _handler_off,
378 .command = "progress_on",
379 .handler = _handler_progress_on,
382 .command = "progress_off",
383 .handler = _handler_progress_off,
391 for (i = 0; __table_handler[i].command; i++) {
392 if (strcmp(__table_handler[i].command, command)) {
396 if (__table_handler[i].handler != NULL) {
397 DBG("process:%s", command);
398 __table_handler[i].handler(data);
406 QP_Module_Setting flightmode = {
407 .name = "flightmode",
410 .lang_changed = _lang_changed,
412 .icon_get = _icon_get,
413 .label_get = _label_get,
414 .view_update = _view_update,
415 .status_update = _status_update,
416 .handler_longpress = _long_press_cb,
417 .handler_ipc = _handler_ipc,
418 .handler_press = _mouse_clicked_cb,