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 <system_settings.h>
23 #include <bundle_internal.h>
25 #include <tzsh_quickpanel_service.h>
27 #include "common_uic.h"
29 #include "quickpanel-ui.h"
31 #include "setting_utils.h"
32 #include "setting_module_api.h"
33 #include "settings_icon_common.h"
35 #define BUTTON_LABEL _("IDS_ST_BUTTON2_MOBILE_NDATA")
36 #define BUTTON_ICON_NORMAL "quick_icon_mobile_data.png"
37 #define BUTTON_ICON_HIGHLIGHT NULL
38 #define BUTTON_ICON_DIM NULL
39 #define PACKAGE_SETTING_MENU "setting-network-efl"
40 #define SYSPOPUP_NAME "mode-syspopup"
42 #ifndef VCONFKEY_SETAPPL_MOBILE_DATA_ON_REMINDER
43 #define VCONFKEY_SETAPPL_MOBILE_DATA_ON_REMINDER "db/setting/network/mobile_data_on_reminder"
45 #ifndef VCONFKEY_SETAPPL_MOBILE_DATA_OFF_REMINDER
46 #define VCONFKEY_SETAPPL_MOBILE_DATA_OFF_REMINDER "db/setting/network/mobile_data_off_reminder"
49 static int _is_simcard_inserted(void);
50 static int _is_in_flightmode(void);
51 static void _mouse_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source);
53 static const char *_label_get(void)
58 static const char *_icon_get(qp_setting_icon_image_type type)
60 if (type == QP_SETTING_ICON_NORMAL) {
61 return BUTTON_ICON_NORMAL;
62 } else if (type == QP_SETTING_ICON_HIGHLIGHT) {
63 return BUTTON_ICON_HIGHLIGHT;
64 } else if (type == QP_SETTING_ICON_DIM) {
65 #ifdef BUTTON_ICON_DIM
66 return BUTTON_ICON_DIM;
73 static void _long_press_cb(void *data)
75 #ifdef PACKAGE_SETTING_MENU
76 struct appdata *ad = quickpanel_get_app_data();
77 retif(ad == NULL, , "invalid data.");
79 if (_is_in_flightmode() == 1) {
80 quickpanel_setting_create_timeout_popup(ad->win, _("IDS_SCP_BODY_UNABLE_TO_CONNECT_TO_MOBILE_NETWORKS_WHILE_FLIGHT_MODE_IS_ENABLED_CONNECT_TO_A_WI_FI_NETWORK_INSTEAD_OR_DISABLE_FLIGHT_MODE_AND_TRY_AGAIN"));
84 if (_is_simcard_inserted() == 0) {
85 quickpanel_setting_create_timeout_popup(ad->win, _("IDS_ST_BODY_INSERT_SIM_CARD_TO_ACCESS_NETWORK_SERVICES"));
89 quickpanel_setting_icon_handler_longpress(PACKAGE_SETTING_MENU, NULL);
93 static int _need_display_popup(int is_on)
99 ret = vconf_get_bool(VCONFKEY_SETAPPL_MOBILE_DATA_ON_REMINDER, &status);
100 msgif(ret != 0, "failed to get VCONFKEY_SETAPPL_MOBILE_DATA_ON_REMINDER %d %d", ret, is_on);
101 if (ret == 0 && status == true) {
105 ret = vconf_get_bool(VCONFKEY_SETAPPL_MOBILE_DATA_OFF_REMINDER, &status);
106 msgif(ret != 0, "failed to get VCONFKEY_SETAPPL_MOBILE_DATA_OFF_REMINDER %d %d", ret, is_on);
107 if (ret == 0 && status == 1) {
115 static void _turn_on(int is_on)
120 ret = system_settings_set_value_bool(SYSTEM_SETTINGS_KEY_3G_DATA_NETWORK_ENABLED, 1);
121 msgif(ret != SYSTEM_SETTINGS_ERROR_NONE, "failed to set SYSTEM_SETTINGS_KEY_3G_DATA_NETWORK_ENABLED %d %d", ret, is_on);
123 ret = system_settings_set_value_bool(SYSTEM_SETTINGS_KEY_3G_DATA_NETWORK_ENABLED, 0);
124 msgif(ret != SYSTEM_SETTINGS_ERROR_NONE,"failed to set SYSTEM_SETTINGS_KEY_3G_DATA_NETWORK_ENABLED: %d %d", ret, is_on);
128 static void _turn_on_with_popup(int is_on)
134 bundle_add(b, "_MODE_SYSTEM_POPUP_TYPE_", "MODE_SYSTEM_MOBILEDATA_ON");
136 bundle_add(b, "_MODE_SYSTEM_POPUP_TYPE_", "MODE_SYSTEM_MOBILEDATA_OFF");
138 syspopup_launch(SYSPOPUP_NAME, b);
141 ERR("failed to create a bundle");
145 static void _view_update(Evas_Object *view, int state, int flag_extra_1, int flag_extra_2)
147 Evas_Object *image = NULL;
148 const char *icon_path = NULL;
150 quickpanel_setting_icon_state_set(view, state);
152 if (state == ICON_VIEW_STATE_ON) {
153 #ifdef BUTTON_ICON_HIGHLIGHT
154 icon_path = BUTTON_ICON_HIGHLIGHT;
156 } else if (state == ICON_VIEW_STATE_DIM) {
157 #ifdef BUTTON_ICON_DIM
158 icon_path = BUTTON_ICON_DIM;
161 icon_path = BUTTON_ICON_NORMAL;
164 if (icon_path == NULL) {
165 icon_path = BUTTON_ICON_NORMAL;
167 image = quickpanel_setting_icon_image_new(view, icon_path);
168 quickpanel_setting_icon_content_set(view, image);
169 quickpanel_setting_icon_text_set(view, BUTTON_LABEL, state);
172 static int _is_simcard_inserted(void)
176 int sim_status_1 = VCONFKEY_TELEPHONY_SIM_UNKNOWN;
177 int sim_status_2 = VCONFKEY_TELEPHONY_SIM_UNKNOWN;
179 ret_1 = vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT, &sim_status_1);
180 msgif(ret_1 != QP_OK, "failed to get the VCONFKEY_TELEPHONY_SIM_SLOT : %d", ret_1);
182 ret_2 = vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT2, &sim_status_2);
183 msgif(ret_2 != QP_OK, "failed to get the VCONFKEY_TELEPHONY_SIM_SLOT2 : %d", ret_2);
185 INFO("MOBILE DATA SIM CARD: %d %d", sim_status_1, sim_status_2);
187 if ((ret_1 == QP_OK && sim_status_1 == VCONFKEY_TELEPHONY_SIM_INSERTED) ||
188 (ret_2 == QP_OK && sim_status_2 == VCONFKEY_TELEPHONY_SIM_INSERTED)) {
195 static int _is_in_flightmode(void)
198 bool flight_mode = false;
200 ret = system_settings_get_value_bool(SYSTEM_SETTINGS_KEY_NETWORK_FLIGHT_MODE, &flight_mode);
201 msgif(ret != SYSTEM_SETTINGS_ERROR_NONE, "failed to get the SYSTEM_SETTINGS_KEY_NETWORK_FLIGHT_MODE : %d", ret);
202 if (ret == QP_OK && flight_mode == true) {
209 static void _status_update(QP_Module_Setting *module, int flag_extra_1, int flag_extra_2)
213 retif(module == NULL, , "Invalid parameter!");
215 quickpanel_setting_module_icon_timer_del(module);
217 if (quickpanel_uic_is_emul() == 1) {
219 } else if (_is_in_flightmode() == 1) {
221 } else if (_is_simcard_inserted() == 0) {
224 ret = system_settings_get_value_bool(SYSTEM_SETTINGS_KEY_3G_DATA_NETWORK_ENABLED, &status);
225 msgif(ret != SYSTEM_SETTINGS_ERROR_NONE, "fail to get SYSTEM_SETTINGS_KEY_3G_DATA_NETWORK_ENABLED:%d", ret);
228 if (status == true) {
229 quickpanel_setting_module_icon_state_set(module, ICON_VIEW_STATE_ON);
231 quickpanel_setting_module_icon_state_set(module, ICON_VIEW_STATE_OFF);
234 quickpanel_setting_module_icon_view_update(module,
235 quickpanel_setting_module_icon_state_get(module),
239 static void _mouse_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
241 QP_Module_Setting *module = (QP_Module_Setting *)data;
242 retif(module == NULL, , "Invalid parameter!");
244 if (quickpanel_setting_module_is_icon_clickable(module) == 0) {
248 struct appdata *ad = quickpanel_get_app_data();
249 retif(ad == NULL, , "invalid data.");
251 if (quickpanel_uic_is_emul() == 1) {
252 quickpanel_setting_create_timeout_popup(ad->win, _NOT_LOCALIZED("Unsupported."));
256 if (_is_in_flightmode() == 1) {
257 quickpanel_setting_create_timeout_popup(ad->win, _("IDS_SCP_BODY_UNABLE_TO_CONNECT_TO_MOBILE_NETWORKS_WHILE_FLIGHT_MODE_IS_ENABLED_CONNECT_TO_A_WI_FI_NETWORK_INSTEAD_OR_DISABLE_FLIGHT_MODE_AND_TRY_AGAIN"));
261 if (_is_simcard_inserted() == 0) {
262 quickpanel_setting_create_timeout_popup(ad->win, _("IDS_ST_BODY_INSERT_SIM_CARD_TO_ACCESS_NETWORK_SERVICES"));
266 if (quickpanel_setting_module_icon_state_get(module) == ICON_VIEW_STATE_ON) {
268 if (_need_display_popup(0) == 1) {
269 _turn_on_with_popup(0);
275 if (_need_display_popup(1) == 1) {
276 _turn_on_with_popup(1);
283 static void _mobiledata_vconf_cb(keynode_t *key, void *data)
285 _status_update(data, FLAG_VALUE_VOID, FLAG_VALUE_VOID);
288 static void _mobiledata_setting_cb(system_settings_key_e key, void *data)
290 _status_update(data, FLAG_VALUE_VOID, FLAG_VALUE_VOID);
293 static int _register_module_event_handler(void *data)
297 ret = system_settings_set_changed_cb(SYSTEM_SETTINGS_KEY_3G_DATA_NETWORK_ENABLED, _mobiledata_setting_cb, data);
298 msgif(ret != SYSTEM_SETTINGS_ERROR_NONE, "failed to notify key(%s) : %d", SYSTEM_SETTINGS_KEY_3G_DATA_NETWORK_ENABLED, ret);
300 ret = vconf_notify_key_changed(VCONFKEY_TELEPHONY_SIM_SLOT, _mobiledata_vconf_cb, data);
301 msgif(ret != 0, "failed to notify key(%s) : %d", VCONFKEY_TELEPHONY_SIM_SLOT, ret);
303 ret = system_settings_set_changed_cb(SYSTEM_SETTINGS_KEY_NETWORK_FLIGHT_MODE, _mobiledata_setting_cb, data);
304 msgif(ret != SYSTEM_SETTINGS_ERROR_NONE, "failed to notify key(%s) : %d", SYSTEM_SETTINGS_KEY_NETWORK_FLIGHT_MODE, ret);
309 static int _unregister_module_event_handler(void *data)
313 ret = system_settings_unset_changed_cb(SYSTEM_SETTINGS_KEY_3G_DATA_NETWORK_ENABLED);
314 msgif(ret != SYSTEM_SETTINGS_ERROR_NONE, "failed to ignore key(%s) : %d", SYSTEM_SETTINGS_KEY_3G_DATA_NETWORK_ENABLED, ret);
316 ret = vconf_ignore_key_changed(VCONFKEY_TELEPHONY_SIM_SLOT, _mobiledata_vconf_cb);
317 msgif(ret != 0, "failed to ignore key(%s) : %d", VCONFKEY_TELEPHONY_SIM_SLOT, ret);
319 ret = system_settings_unset_changed_cb(SYSTEM_SETTINGS_KEY_NETWORK_FLIGHT_MODE);
320 msgif(ret != SYSTEM_SETTINGS_ERROR_NONE, "failed to ignore key(%s) : %d", SYSTEM_SETTINGS_KEY_NETWORK_FLIGHT_MODE, ret);
325 /****************************************************************************
327 * Quickpanel Item functions
329 ****************************************************************************/
331 static int _init(void *data)
335 ret = _register_module_event_handler(data);
340 static int _fini(void *data)
344 ret = _unregister_module_event_handler(data);
349 static void _lang_changed(void *data)
351 QP_Module_Setting *module = (QP_Module_Setting *)data;
352 retif(module == NULL, , "Invalid parameter!");
354 quickpanel_setting_module_icon_view_update_text(module);
357 static void _refresh(void *data)
359 QP_Module_Setting *module = (QP_Module_Setting *)data;
360 retif(module == NULL, , "Invalid parameter!");
362 quickpanel_setting_module_icon_view_update_text(module);
365 static void _reset_icon(QP_Module_Setting *module)
367 retif(module == NULL, , "Invalid parameter!");
369 quickpanel_setting_module_progress_mode_set(module, FLAG_DISABLE, FLAG_VALUE_VOID);
370 _status_update(module, FLAG_VALUE_VOID, FLAG_VALUE_VOID);
373 static void _handler_on(void *data)
376 QP_Module_Setting *module = (QP_Module_Setting *)data;
377 retif(module == NULL, , "Invalid parameter!");
379 quickpanel_setting_module_progress_mode_set(module, FLAG_DISABLE, FLAG_TURN_OFF);
380 quickpanel_setting_module_icon_timer_del(module);
382 if (quickpanel_setting_module_icon_state_get(module) == ICON_VIEW_STATE_OFF) {
383 ret = system_settings_set_value_bool(SYSTEM_SETTINGS_KEY_3G_DATA_NETWORK_ENABLED, 1);
385 if (ret == SYSTEM_SETTINGS_ERROR_NONE) {
386 quickpanel_setting_module_progress_mode_set(module, FLAG_ENABLE, FLAG_TURN_ON);
387 quickpanel_setting_module_icon_timer_add(module);
389 ERR("op failed:%d", ret);
392 ERR("the button is already turned on");
397 static void _handler_off(void *data)
400 QP_Module_Setting *module = (QP_Module_Setting *)data;
401 retif(module == NULL, , "Invalid parameter!");
403 quickpanel_setting_module_progress_mode_set(module, FLAG_DISABLE, FLAG_TURN_OFF);
404 quickpanel_setting_module_icon_timer_del(module);
406 if (quickpanel_setting_module_icon_state_get(module) == ICON_VIEW_STATE_ON) {
407 ret = vconf_set_bool(VCONFKEY_3G_ENABLE, 0);
410 quickpanel_setting_module_progress_mode_set(module, FLAG_ENABLE, FLAG_TURN_OFF);
411 quickpanel_setting_module_icon_timer_add(module);
413 ERR("op failed:%d", ret);
416 ERR("the button is already turned off");
421 static void _handler_progress_on(void *data)
423 QP_Module_Setting *module = (QP_Module_Setting *)data;
424 retif(module == NULL, , "Invalid parameter!");
426 quickpanel_setting_module_progress_mode_set(module, FLAG_ENABLE, FLAG_VALUE_VOID);
429 static void _handler_progress_off(void *data)
431 QP_Module_Setting *module = (QP_Module_Setting *)data;
432 retif(module == NULL, , "Invalid parameter!");
437 static int _handler_ipc(const char *command, void *data)
440 retif(data == NULL, EINA_FALSE, "item data is NULL");
441 retif(command == NULL, EINA_FALSE, "command is NULL");
443 static Setting_Activity_Handler __table_handler[] = {
446 .handler = _handler_on,
450 .handler = _handler_off,
453 .command = "progress_on",
454 .handler = _handler_progress_on,
457 .command = "progress_off",
458 .handler = _handler_progress_off,
466 for (i = 0; __table_handler[i].command; i++) {
467 if (strcasecmp(__table_handler[i].command, command)) {
471 if (__table_handler[i].handler != NULL) {
472 DBG("process:%s", command);
473 __table_handler[i].handler(data);
481 QP_Module_Setting mobile_data = {
482 .name = "mobile_data",
485 .lang_changed = _lang_changed,
487 .icon_get = _icon_get,
488 .label_get = _label_get,
489 .view_update = _view_update,
490 .status_update = _status_update,
491 .handler_longpress = _long_press_cb,
492 .handler_ipc = _handler_ipc,
493 .handler_press = _mouse_clicked_cb,