76b7e9b3ac4bd09eead4b0853adfafa601d0b0f0
[profile/ivi/indicator-win.git] / modules / information / alarm.c
1 /*
2  * Copyright 2012  Samsung Electronics Co., Ltd
3  *
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
7  *
8  *  http://www.tizenopensource.org/license
9  *
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.
15  */
16
17
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <vconf.h>
21 #include "common.h"
22 #include "indicator.h"
23 #include "indicator_ui.h"
24 #include "modules.h"
25 #include "indicator_icon_util.h"
26
27 #define ICON_PRIORITY   INDICATOR_PRIORITY_NON_FIXED_2
28 #define MODULE_NAME             "alarm"
29
30 static int register_alarm_module(void *data);
31 static int unregister_alarm_module(void);
32 static int hib_enter_alarm_module(void);
33 static int hib_leave_alarm_module(void *data);
34
35 Indicator_Icon_Object useralarm = {
36         .type = INDICATOR_IMG_ICON,
37         .name = MODULE_NAME,
38         .priority = ICON_PRIORITY,
39         .always_top = EINA_FALSE,
40         .exist_in_view = EINA_FALSE,
41         .txt_obj = {0,},
42         .img_obj = {0,},
43         .obj_exist = EINA_FALSE,
44         .fixed = EINA_FALSE,
45         .init = register_alarm_module,
46         .fini = unregister_alarm_module,
47         .hib_enter = hib_enter_alarm_module,
48         .hib_leave = hib_leave_alarm_module
49 };
50
51 static char *icon_path[] = {
52         "Alarm/B03_Alarm.png",
53         NULL
54 };
55
56 static void show_image_icon(void *data)
57 {
58         useralarm.img_obj.data = icon_path[0];
59         indicator_util_icon_show(&useralarm);
60 }
61
62 static void hide_image_icon(void)
63 {
64         indicator_util_icon_hide(&useralarm);
65 }
66
67 static void indicator_alarm_change_cb(keynode_t *node, void *data)
68 {
69         int status = 0;
70         int ret;
71
72         retif(data == NULL, , "Invalid parameter!");
73
74         ret = vconf_get_int(VCONFKEY_ALARM_STATE, &status);
75         if (ret == OK) {
76                 if (status > 0) {
77                         INFO("ALARM COUNT: %d", status);
78                         show_image_icon(data);
79                         return;
80                 }
81                 INFO("ALARM COUNT: %d", status);
82                 hide_image_icon();
83                 return;
84         }
85         ERR("Failed to get alarm count!");
86         return;
87 }
88
89 static int register_alarm_module(void *data)
90 {
91         int ret;
92
93         retif(data == NULL, FAIL, "Invalid parameter!");
94
95         ret = vconf_notify_key_changed(VCONFKEY_ALARM_STATE,
96                                        indicator_alarm_change_cb, data);
97         if (ret != OK)
98                 ERR("Failed to register callback!");
99
100         indicator_alarm_change_cb(NULL, data);
101
102         return ret;
103 }
104
105 static int unregister_alarm_module(void)
106 {
107         int ret;
108
109         ret = vconf_ignore_key_changed(VCONFKEY_ALARM_STATE,
110                                        indicator_alarm_change_cb);
111         if (ret != OK)
112                 ERR("Failed to unregister callback!");
113
114         hide_image_icon();
115
116         return OK;
117 }
118
119 static int hib_enter_alarm_module(void)
120 {
121         int ret;
122
123         ret = vconf_ignore_key_changed(VCONFKEY_ALARM_STATE,
124                                        indicator_alarm_change_cb);
125         if (ret != OK)
126                 ERR("Failed to unregister callback!");
127
128         return OK;
129 }
130
131 static int hib_leave_alarm_module(void *data)
132 {
133         int ret;
134
135         retif(data == NULL, FAIL, "Invalid parameter!");
136
137         ret = vconf_notify_key_changed(VCONFKEY_ALARM_STATE,
138                                        indicator_alarm_change_cb, data);
139         retif(ret != OK, FAIL, "Failed to register callback!");
140
141         indicator_alarm_change_cb(NULL, data);
142         return OK;
143 }