2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.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.tizenopensource.org/license
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.
22 #include "indicator.h"
23 #include "indicator_icon_util.h"
25 #include "indicator_ui.h"
27 #define ICON_PRIORITY INDICATOR_PRIORITY_NON_FIXED_5
28 #define MODULE_NAME "gps"
29 #define TIMER_INTERVAL 0.3
31 static int register_gps_module(void *data);
32 static int unregister_gps_module(void);
33 static int hib_enter_gps_module(void);
34 static int hib_leave_gps_module(void *data);
36 Indicator_Icon_Object gps = {
37 .type = INDICATOR_IMG_ICON,
39 .priority = ICON_PRIORITY,
40 .always_top = EINA_TRUE,
41 .exist_in_view = EINA_FALSE,
44 .obj_exist = EINA_FALSE,
46 .init = register_gps_module,
47 .fini = unregister_gps_module,
48 .hib_enter = hib_enter_gps_module,
49 .hib_leave = hib_leave_gps_module
54 LEVEL_GPS_ON = LEVEL_MIN,
59 static const char *icon_path[LEVEL_MAX] = {
60 [LEVEL_GPS_ON] = "Bluetooth_NFC_GPS/B03_GPS_On.png",
61 [LEVEL_GPS_SEARCHING] = "Bluetooth_NFC_GPS/B03_GPS_Searching.png",
64 static void show_image_icon(void *data, int i)
68 else if (i >= LEVEL_MAX)
69 i = LEVEL_GPS_SEARCHING;
71 gps.img_obj.data = icon_path[i];
72 indicator_util_icon_show(&gps);
75 static void hide_image_icon(void)
77 indicator_util_icon_hide(&gps);
80 static int indicator_gps_state_get(void)
83 int status = VCONFKEY_LOCATION_POSITION_OFF;
85 ret = vconf_get_int(VCONFKEY_LOCATION_POSITION_STATE, &status);
87 ERR("fail to get [%s]", VCONFKEY_LOCATION_POSITION_STATE);
89 INFO("GPS STATUS: %d", status);
94 static void indicator_gps_state_icon_set(int status, void *data)
96 INFO("GPS STATUS: %d", status);
99 case VCONFKEY_LOCATION_POSITION_OFF:
102 case VCONFKEY_LOCATION_POSITION_CONNECTED:
103 show_image_icon(data, LEVEL_GPS_ON);
104 indicator_util_icon_animation_set(&gps, ICON_ANI_NONE);
106 case VCONFKEY_LOCATION_POSITION_SEARCHING:
107 show_image_icon(data, LEVEL_GPS_SEARCHING);
108 indicator_util_icon_animation_set(&gps, ICON_ANI_BLINK);
112 ERR("Invalid value!");
119 static void indicator_gps_change_cb(keynode_t *node, void *data)
121 int status = VCONFKEY_LOCATION_POSITION_OFF;
123 retif(data == NULL, , "Invalid parameter!");
124 retif(node == NULL, , "node is NULL");
126 status = vconf_keynode_get_int(node);
128 ERR("fail to get value from node");
129 status = VCONFKEY_LOCATION_POSITION_OFF;
132 indicator_gps_state_icon_set(status, data);
137 static int register_gps_module(void *data)
141 retif(data == NULL, FAIL, "Invalid parameter!");
143 ret = vconf_notify_key_changed(VCONFKEY_LOCATION_POSITION_STATE,
144 indicator_gps_change_cb, data);
146 ERR("Failed to register callback!");
148 indicator_gps_state_icon_set(indicator_gps_state_get(), data);
153 static int unregister_gps_module(void)
157 ret = vconf_ignore_key_changed(VCONFKEY_LOCATION_POSITION_STATE,
158 indicator_gps_change_cb);
160 ERR("Failed to unregister callback!");
167 static int hib_enter_gps_module(void)
171 ret = vconf_ignore_key_changed(VCONFKEY_LOCATION_POSITION_STATE,
172 indicator_gps_change_cb);
174 ERR("Failed to unregister callback!");
179 static int hib_leave_gps_module(void *data)
183 retif(data == NULL, FAIL, "Invalid parameter!");
185 ret = vconf_notify_key_changed(VCONFKEY_LOCATION_POSITION_STATE,
186 indicator_gps_change_cb, data);
187 retif(ret != OK, FAIL, "Failed to register callback!");
189 indicator_gps_state_icon_set(indicator_gps_state_get(), data);