SVACE[1379] fix.
[apps/core/preloaded/indicator-win.git] / src / modules / processing / downloading.c
1 /*
2  *  Indicator
3  *
4  * Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <vconf.h>
24 #include "common.h"
25 #include "indicator.h"
26 #include "main.h"
27 #include "modules.h"
28 #include "icon.h"
29 #include "log.h"
30
31 #define ICON_PRIORITY   INDICATOR_PRIORITY_NOTI_1
32 #define MODULE_NAME             "downloading"
33 #define TIMER_INTERVAL  0.3
34 #define ICON_NUM 7
35
36 static int register_downloading_module(void *data);
37 static int unregister_downloading_module(void);
38 static int wake_up_cb(void *data);
39
40 icon_s downloading = {
41         .type = INDICATOR_IMG_ICON,
42         .name = MODULE_NAME,
43         .priority = ICON_PRIORITY,
44         .always_top = EINA_FALSE,
45         .exist_in_view = EINA_FALSE,
46         .img_obj = {0,},
47         .obj_exist = EINA_FALSE,
48         .area = INDICATOR_ICON_AREA_NOTI,
49         .init = register_downloading_module,
50         .fini = unregister_downloading_module,
51         .wake_up = wake_up_cb
52 };
53
54 static const char *icon_path[] = {
55         "Processing/B03_Processing_download_ani_00.png",
56         "Processing/B03_Processing_download_ani_01.png",
57         "Processing/B03_Processing_download_ani_02.png",
58         "Processing/B03_Processing_download_ani_03.png",
59         "Processing/B03_Processing_download_ani_04.png",
60         "Processing/B03_Processing_download_ani_05.png",
61         "Processing/B03_Processing_download_ani_06.png",
62         NULL
63 };
64
65 static Ecore_Timer *timer;
66 static int icon_index = 0;
67 static int updated_while_lcd_off = 0;
68
69 static void set_app_state(void* data)
70 {
71         downloading.ad = data;
72 }
73
74 static void show_image_icon(void* data, int index)
75 {
76         downloading.img_obj.data = icon_path[index];
77         icon_show(&downloading);
78 }
79
80 static void hide_image_icon(void)
81 {
82         icon_hide(&downloading);
83 }
84
85 static Eina_Bool show_downloading_icon_cb(void* data)
86 {
87
88         show_image_icon(data,icon_index);
89         icon_index++;
90         icon_index = (icon_index % ICON_NUM) ? icon_index : 0;
91
92         return ECORE_CALLBACK_RENEW;
93 }
94
95 static void show_downloading_icon(void* data)
96 {
97         if(timer==NULL)
98         {
99                 timer = ecore_timer_add(TIMER_INTERVAL, show_downloading_icon_cb, data);
100         }
101         else
102         {
103                 _E("show_downloading_icon!, timer");
104         }
105 }
106
107 static void hide_downloading_icon(void)
108 {
109         if (timer != NULL) {
110                 ecore_timer_del(timer);
111                 timer = NULL;
112                 icon_index = 0;
113         }
114
115         hide_image_icon();
116 }
117
118
119 static void indicator_downloading_change_cb(keynode_t *node, void *data)
120 {
121         int status = 0;
122
123         retm_if(data == NULL, "Invalid parameter!");
124
125         if(icon_get_update_flag()==0)
126         {
127                 updated_while_lcd_off = 1;
128                 return;
129         }
130         updated_while_lcd_off = 0;
131
132         vconf_get_int(VCONFKEY_WIFI_DIRECT_RECEIVING_STATE, &status);
133
134         if (status == 1)
135                 show_downloading_icon(data);
136         else
137                 hide_downloading_icon();
138 }
139
140 static void indicator_downloading_pm_state_change_cb(keynode_t *node, void *data)
141 {
142         int status = 0;
143
144         retm_if(data == NULL, "Invalid parameter!");
145
146         if (vconf_get_int(VCONFKEY_PM_STATE, &status) < 0)
147         {
148                 _E("Error getting VCONFKEY_PM_STATE value");
149
150                 if (timer != NULL)
151                 {
152                         ecore_timer_del(timer);
153                         timer = NULL;
154                 }
155
156                 return;
157         }
158
159         if(status == VCONFKEY_PM_STATE_LCDOFF)
160         {
161                 if (timer != NULL) {
162                         ecore_timer_del(timer);
163                         timer = NULL;
164                 }
165         }
166 }
167
168 static int wake_up_cb(void *data)
169 {
170         if(updated_while_lcd_off == 0 && downloading.obj_exist == EINA_FALSE)
171         {
172                 return OK;
173         }
174
175         indicator_downloading_change_cb(NULL, data);
176         return OK;
177 }
178
179 static int register_downloading_module(void *data)
180 {
181         int ret = 0;
182
183         retvm_if(data == NULL, FAIL, "Invalid parameter!");
184
185         set_app_state(data);
186
187         ret = ret | vconf_notify_key_changed(VCONFKEY_WIFI_DIRECT_RECEIVING_STATE, indicator_downloading_change_cb, data);
188
189         ret = ret | vconf_notify_key_changed(VCONFKEY_PM_STATE,
190                                         indicator_downloading_pm_state_change_cb, data);
191
192         indicator_downloading_change_cb(NULL, data);
193
194         return ret;
195 }
196
197 static int unregister_downloading_module(void)
198 {
199         int ret = 0;
200
201         ret = ret | vconf_ignore_key_changed(VCONFKEY_WIFI_DIRECT_RECEIVING_STATE, indicator_downloading_change_cb);
202
203         ret = ret | vconf_ignore_key_changed(VCONFKEY_PM_STATE,
204                                                 indicator_downloading_pm_state_change_cb);
205
206         return ret;
207 }