tizen_2.0_build
[profile/ivi/indicator-win.git] / modules / setting / silent.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_1
28 #define MODULE_NAME             "silent"
29
30 static int register_silent_module(void *data);
31 static int unregister_silent_module(void);
32 static int hib_enter_silent_module(void);
33 static int hib_leave_silent_module(void *data);
34
35 Indicator_Icon_Object silent = {
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_silent_module,
46         .fini = unregister_silent_module,
47         .hib_enter = hib_enter_silent_module,
48         .hib_leave = hib_leave_silent_module
49 };
50
51 enum {
52         PROFILE_SOUND_VIBRATION,
53         PROFILE_MUTE,
54         PROFILE_VIBRATION,
55         PROFILE_NUM,
56 };
57
58 static const char *icon_path[PROFILE_NUM] = {
59         [PROFILE_SOUND_VIBRATION] = "Profile/B03_Profile_Sound_Vibration.png",
60         [PROFILE_MUTE] = "Profile/B03_Profile_Mute.png",
61         [PROFILE_VIBRATION] = "Profile/B03_Profile_Vibration.png",
62 };
63
64 static void indicator_silent_change_cb(keynode_t *node, void *data)
65 {
66         int sound_status = 0;
67         int vib_status = 0;
68         int ret;
69         const char *selected_image = NULL;
70
71         retif(data == NULL, , "Invalid parameter!");
72
73         ret = vconf_get_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, &sound_status);
74         ret =
75             vconf_get_bool(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, &vib_status);
76
77         if (ret == OK) {
78                 INFO("CURRENT Sound Status: %d vib_status: %d", sound_status,
79                      vib_status);
80
81                 if (sound_status == TRUE) {
82                         if (vib_status == TRUE)
83                                 /* Sound and Vibration Mode */
84                                 selected_image =
85                                         icon_path[PROFILE_SOUND_VIBRATION];
86                 } else {
87                         if (vib_status != TRUE)
88                                 /* Mute Mode */
89                                 selected_image = icon_path[PROFILE_MUTE];
90                         else
91                                 /* Vibration Only Mode */
92                                 selected_image = icon_path[PROFILE_VIBRATION];
93                 }
94
95                 if (selected_image != NULL) {
96                         silent.img_obj.data = selected_image;
97                         indicator_util_icon_show(&silent);
98                         return;
99                 }
100
101                 /* If path is not set to 'selected_image', Hide All Image */
102                 indicator_util_icon_hide(&silent);
103                 return;
104         }
105
106         ERR("Failed to get current profile!");
107         return;
108 }
109
110 static int register_silent_module(void *data)
111 {
112         int ret;
113
114         retif(data == NULL, FAIL, "Invalid parameter!");
115
116         ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL,
117                                        indicator_silent_change_cb, data);
118         if (ret != OK)
119                 ERR("Fail: register VCONFKEY_SETAPPL_SOUND_STATUS_BOOL");
120
121         ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL,
122                                        indicator_silent_change_cb, data);
123         if (ret != OK)
124                 ERR("Fail: register VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL");
125
126         indicator_silent_change_cb(NULL, data);
127
128         return ret;
129 }
130
131 static int unregister_silent_module(void)
132 {
133         int ret;
134
135         ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL,
136                                        indicator_silent_change_cb);
137         if (ret != OK)
138                 ERR("Fail: ignore VCONFKEY_SETAPPL_SOUND_STATUS_BOOL");
139
140         ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL,
141                                        indicator_silent_change_cb);
142         if (ret != OK)
143                 ERR("Fail: ignore VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL");
144
145         indicator_util_icon_hide(&silent);
146
147         return OK;
148 }
149
150 static int hib_enter_silent_module(void)
151 {
152         int ret;
153
154         ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL,
155                                        indicator_silent_change_cb);
156         if (ret != OK)
157                 ERR("H_Fail: ignore VCONFKEY_SETAPPL_SOUND_STATUS_BOOL");
158
159         ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL,
160                                        indicator_silent_change_cb);
161         if (ret != OK)
162                 ERR("H_Fail: ignore VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL");
163
164         return OK;
165 }
166
167 static int hib_leave_silent_module(void *data)
168 {
169         int ret;
170
171         retif(data == NULL, FAIL, "Invalid parameter!");
172
173         ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL,
174                                        indicator_silent_change_cb, data);
175         if (ret != OK)
176                 ERR("H_Fail: register VCONFKEY_SETAPPL_SOUND_STATUS_BOOL");
177
178         ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL,
179                                        indicator_silent_change_cb, data);
180         if (ret != OK)
181                 ERR("H_Fail: register VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL");
182
183         indicator_silent_change_cb(NULL, data);
184
185         return OK;
186 }