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 <app_control.h>
23 #include "quickpanel-ui.h"
25 #include "setting_utils.h"
26 #include "setting_module_api.h"
28 #define BUTTON_LABEL _("IDS_QP_BUTTON2_LOCATION_ABB")
29 #define BUTTON_ICON_NORMAL "quick_icon_location.png"
30 #define BUTTON_ICON_HIGHLIGHT NULL
31 #define BUTTON_ICON_DIM NULL
32 #define PACKAGE_SETTING_MENU "org.tizen.setting-location"
33 #define OPERATION_SETTING_MENU "http://tizen.org/appcontrol/operation/configure/location"
34 #define PACKAGE_SYSPOPUP "gps-syspopup"
36 static void _mouse_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source);
38 static const char *_label_get(void) {
42 static const char *_icon_get(qp_setting_icon_image_type type) {
43 if (type == QP_SETTING_ICON_NORMAL) {
44 return BUTTON_ICON_NORMAL;
45 } else if (type == QP_SETTING_ICON_NORMAL) {
46 return BUTTON_ICON_HIGHLIGHT;
47 } else if (type == QP_SETTING_ICON_DIM) {
48 #ifdef BUTTON_ICON_DIM
49 return BUTTON_ICON_DIM;
56 static void _long_press_cb(void *data) {
57 #ifdef PACKAGE_SETTING_MENU
58 // Because operation is not DEFAULT, this function can not be called. Too many changes to add operation param.
59 // qp_setting_icon_handler_longpress(PACKAGE_SETTING_MENU, NULL);
61 app_control_h service;
64 ret = app_control_create(&service);
67 ERR("Failed to create app control");
71 app_control_set_app_id(service, PACKAGE_SETTING_MENU);
72 app_control_set_operation(service, OPERATION_SETTING_MENU);
74 ret = app_control_send_launch_request(service, NULL, NULL);
77 ERR("Failed to launch[%d]", ret);
80 app_control_destroy(service);
85 static void _syspopup_launch(int is_on)
87 syspopup_launch(PACKAGE_SYSPOPUP, NULL);
90 static void _view_update(Evas_Object *view, int state, int flag_extra_1, int flag_extra_2) {
91 Evas_Object *image = NULL;
92 const char *icon_path = NULL;
94 qp_setting_icon_state_set(view, state);
96 if (state == ICON_VIEW_STATE_ON) {
97 #ifdef BUTTON_ICON_HIGHLIGHT
98 icon_path = BUTTON_ICON_HIGHLIGHT;
100 } else if (state == ICON_VIEW_STATE_DIM) {
101 #ifdef BUTTON_ICON_DIM
102 icon_path = BUTTON_ICON_DIM;
105 icon_path = BUTTON_ICON_NORMAL;
108 if (icon_path == NULL) {
109 icon_path = BUTTON_ICON_NORMAL;
111 image = qp_setting_icon_image_new(view, icon_path);
112 qp_setting_icon_content_set(view, image);
113 qp_setting_icon_text_set(view, BUTTON_LABEL, state);
116 static void _status_update(QP_Module_Setting *module, int flag_extra_1, int flag_extra_2) {
119 retif(module == NULL, , "Invalid parameter!");
121 qp_setting_module_progress_mode_set(module, FLAG_DISABLE, FLAG_TURN_OFF);
122 qp_setting_module_icon_timer_del(module);
124 ret = vconf_get_int(VCONFKEY_LOCATION_USE_MY_LOCATION, &status);
125 msgif(ret != 0, "fail to get VCONFKEY_LOCATION_USE_MY_LOCATION:%d", ret);
128 qp_setting_module_icon_state_set(module, ICON_VIEW_STATE_ON);
130 qp_setting_module_icon_state_set(module, ICON_VIEW_STATE_OFF);
133 qp_setting_module_icon_view_update(module,
134 qp_setting_module_icon_state_get(module),
138 static void _mouse_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
142 QP_Module_Setting *module = (QP_Module_Setting *) data;
143 retif(module == NULL, , "Invalid parameter!");
145 if (qp_setting_module_is_icon_clickable(module) == 0)
150 if (qp_setting_module_icon_state_get(module) == ICON_VIEW_STATE_OFF)
152 _syspopup_launch(qp_setting_module_icon_state_get(module));
156 // Use my location off
157 ret = vconf_get_int(VCONFKEY_LOCATION_USE_MY_LOCATION, &enable);
162 vconf_set_int(VCONFKEY_LOCATION_USE_MY_LOCATION, 0);
167 ERR("Failed to get Use my location[%d]", ret);
170 ret = vconf_get_int(VCONFKEY_LOCATION_ENABLED, &enable);
175 vconf_set_int(VCONFKEY_LOCATION_ENABLED, 0);
180 ERR("Failed to get GPS[%d]", ret);
182 // Wireless networks off
183 ret = vconf_get_int(VCONFKEY_LOCATION_NETWORK_ENABLED, &enable);
188 vconf_set_int(VCONFKEY_LOCATION_NETWORK_ENABLED, 0);
193 ERR("Failed to get GPS[%d]", ret);
198 static void _gps_vconf_cb(keynode_t *node,
200 _status_update(data, FLAG_VALUE_VOID, FLAG_VALUE_VOID);
203 static int _register_module_event_handler(void *data) {
206 ret = vconf_notify_key_changed(VCONFKEY_LOCATION_USE_MY_LOCATION,
207 _gps_vconf_cb, data);
208 msgif(ret != 0, "failed to notify key(VCONFKEY_LOCATION_USE_MY_LOCATION) : %d", ret);
213 static int _unregister_module_event_handler(void *data) {
216 ret = vconf_ignore_key_changed(VCONFKEY_LOCATION_USE_MY_LOCATION,
218 msgif(ret != 0, "failed to ignore key(VCONFKEY_LOCATION_USE_MY_LOCATION) : %d", ret);
223 /****************************************************************************
225 * Quickpanel Item functions
227 ****************************************************************************/
228 static int _init(void *data) {
231 ret = _register_module_event_handler(data);
236 static int _fini(void *data) {
239 ret = _unregister_module_event_handler(data);
244 static void _lang_changed(void *data) {
245 QP_Module_Setting *module = (QP_Module_Setting *)data;
246 retif(module == NULL, , "Invalid parameter!");
248 qp_setting_module_icon_view_update_text(module);
251 static void _refresh(void *data) {
252 QP_Module_Setting *module = (QP_Module_Setting *)data;
253 retif(module == NULL, , "Invalid parameter!");
255 qp_setting_module_icon_view_update_text(module);
258 static void _reset_icon(QP_Module_Setting *module) {
259 retif(module == NULL, , "Invalid parameter!");
261 qp_setting_module_progress_mode_set(module, FLAG_DISABLE, FLAG_VALUE_VOID);
262 _status_update(module, FLAG_VALUE_VOID, FLAG_VALUE_VOID);
265 static void _handler_on(void *data) {
266 QP_Module_Setting *module = (QP_Module_Setting *)data;
267 retif(module == NULL, , "Invalid parameter!");
269 qp_setting_module_progress_mode_set(module, FLAG_DISABLE, FLAG_TURN_OFF);
270 qp_setting_module_icon_timer_del(module);
272 if (qp_setting_module_icon_state_get(module) == ICON_VIEW_STATE_OFF)
274 qp_setting_module_progress_mode_set(module, FLAG_ENABLE, FLAG_TURN_ON);
275 qp_setting_module_icon_timer_add(module);
279 ERR("the button is already turned on");
284 static void _handler_off(void *data) {
285 QP_Module_Setting *module = (QP_Module_Setting *)data;
286 retif(module == NULL, , "Invalid parameter!");
288 qp_setting_module_progress_mode_set(module, FLAG_DISABLE, FLAG_TURN_OFF);
289 qp_setting_module_icon_timer_del(module);
291 if (qp_setting_module_icon_state_get(module) == ICON_VIEW_STATE_ON)
293 qp_setting_module_progress_mode_set(module, FLAG_ENABLE, FLAG_TURN_OFF);
294 qp_setting_module_icon_timer_add(module);
298 ERR("the button is already turned off");
303 static void _handler_progress_on(void *data) {
304 QP_Module_Setting *module = (QP_Module_Setting *)data;
305 retif(module == NULL, , "Invalid parameter!");
307 qp_setting_module_progress_mode_set(module, FLAG_ENABLE, FLAG_VALUE_VOID);
310 static void _handler_progress_off(void *data) {
311 QP_Module_Setting *module = (QP_Module_Setting *)data;
312 retif(module == NULL, , "Invalid parameter!");
317 static int _handler_ipc(const char *command, void *data) {
319 retif(data == NULL, EINA_FALSE, "item data is NULL");
320 retif(command == NULL, EINA_FALSE, "command is NULL");
322 static Setting_Activity_Handler __table_handler[] = {
325 .handler = _handler_on,
329 .handler = _handler_off,
332 .command = "progress_on",
333 .handler = _handler_progress_on,
336 .command = "progress_off",
337 .handler = _handler_progress_off,
345 for (i = 0; __table_handler[i].command; i++) {
346 if (strcasecmp(__table_handler[i].command, command)) {
350 if (__table_handler[i].handler != NULL) {
351 DBG("process:%s", command);
352 __table_handler[i].handler(data);
360 QP_Module_Setting gps = {
364 .lang_changed = _lang_changed,
366 .icon_get = _icon_get,
367 .label_get = _label_get,
368 .view_update = _view_update,
369 .status_update = _status_update,
370 .handler_longpress = _long_press_cb,
371 .handler_ipc = _handler_ipc,
372 .handler_press = _mouse_clicked_cb,