More unused headers removed.
[apps/core/preloaded/indicator-win.git] / src / modules / processing / call.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 <bluetooth.h>
25
26 #include "common.h"
27 #include "indicator.h"
28 #include "main.h"
29 #include "modules.h"
30 #include "icon.h"
31 #include "util.h"
32 #include "log.h"
33
34 #define ICON_PRIORITY   INDICATOR_PRIORITY_MINICTRL3
35 #define MODULE_NAME             "call"
36 #define MINICONTROL_VOICE_NAME  "[voicecall-quickpanel]"
37 #define MINICONTROL_VIDEO_NAME  "[videocall-quickpanel]"
38
39 static int register_call_module(void *data);
40 static int unregister_call_module(void);
41 static void show_call_icon( void *data);
42
43 enum {
44         CALL_UI_STATUS_NONE = 0,
45         CALL_UI_STATUS_INCOM,
46         CALL_UI_STATUS_OUTGOING,
47         CALL_UI_STATUS_ACTIVE,
48         CALL_UI_STATUS_HOLD,
49         CALL_UI_STATUS_END,
50 };
51
52 icon_s call = {
53         .type = INDICATOR_IMG_ICON,
54         .name = MODULE_NAME,
55         .priority = ICON_PRIORITY,
56         .always_top = EINA_TRUE,
57         .exist_in_view = EINA_FALSE,
58         .img_obj = {0,},
59         .obj_exist = EINA_FALSE,
60         .area = INDICATOR_ICON_AREA_MINICTRL,
61         .init = register_call_module,
62         .fini = unregister_call_module,
63         .minictrl_control = NULL //mctrl_monitor_cb
64 };
65
66 static int bt_state = 0;
67
68 static const char *icon_path[] = {
69         "Call/B03_Call_Duringcall.png",
70         "Call/B03_Call_bluetooth.png",
71         NULL
72 };
73
74 static void set_app_state(void* data)
75 {
76         call.ad = data;
77 }
78
79 static void show_image_icon(void *data)
80 {
81         if (bt_state == 1) {
82                 call.img_obj.data = icon_path[1];
83         } else {
84                 call.img_obj.data = icon_path[0];
85         }
86         icon_show(&call);
87 }
88
89 static void hide_image_icon(void)
90 {
91         icon_hide(&call);
92 }
93
94 static void icon_animation_set(enum indicator_icon_ani type)
95 {
96         icon_ani_set(&call, type);
97 }
98
99 static void __bt_ag_sco_state_changed_cb(int result, bool connected, const char *remote_address, bt_audio_profile_type_e type, void *user_data)
100 {
101         int status = 0;
102
103         if (connected) bt_state=1;
104         else bt_state=0;
105
106         vconf_get_int(VCONFKEY_CALL_STATE, &status);
107
108         if (status != VCONFKEY_CALL_OFF) show_call_icon(user_data);
109 }
110
111 static void register_bt_state( void *data)
112 {
113         int error = -1;
114
115         error = bt_initialize();
116         if (error != BT_ERROR_NONE) _E("bt_initialize return [%d]", error);
117
118         error = bt_audio_initialize();
119         if (error != BT_ERROR_NONE) _E("bt_audio_initialize return [%d]", error);
120
121         error = bt_audio_set_connection_state_changed_cb(__bt_ag_sco_state_changed_cb, data);   // callback µî·Ï
122         if (error != BT_ERROR_NONE) _E("bt_ag_set_sco_state_changed_cb return [%d]", error);
123
124 }
125
126 static void unregister_bt_state( void )
127 {
128         int error = -1;
129
130         error = bt_audio_unset_connection_state_changed_cb();
131         if (error != BT_ERROR_NONE) _E("bt_ag_unset_sco_state_changed_cb return [%d]", error);
132
133         error = bt_audio_deinitialize();
134         if (error != BT_ERROR_NONE) _E("bt_audio_deinitialize return [%d]", error);
135
136         error = bt_deinitialize();
137         if (error != BT_ERROR_NONE) _E("bt_audio_deinitialize return [%d]", error);
138 }
139
140 static void show_call_icon( void *data)
141 {
142         int status = 0;
143         int ret = 0;
144
145         ret_if(!data);
146
147         ret = vconf_get_int(VCONFKEY_CALL_STATE, &status);
148         if (ret != OK) {
149                 _E("Failed to get VCONFKEY_CALL_STATE!");
150                 return;
151         }
152
153         switch (status) {
154         case VCONFKEY_CALL_VOICE_CONNECTING:
155         case VCONFKEY_CALL_VIDEO_CONNECTING:
156                 show_image_icon(data);
157                 icon_animation_set(ICON_ANI_BLINK);
158                 break;
159         case VCONFKEY_CALL_VOICE_ACTIVE:
160         case VCONFKEY_CALL_VIDEO_ACTIVE:
161                 show_image_icon(data);
162                 icon_animation_set(ICON_ANI_NONE);
163                 break;
164         case VCONFKEY_CALL_OFF:
165                 hide_image_icon();
166                 break;
167         default:
168                 _E("Invalid value %d", status);
169                 break;
170         }
171 }
172
173 static void indicator_call_change_cb(keynode_t *node, void *data)
174 {
175         int status = 0;
176         int ret = 0;
177
178         ret_if(!data);
179
180         ret = vconf_get_int(VCONFKEY_CALL_STATE, &status);
181         if (ret != OK) {
182                 _E("Failed to get VCONFKEY_CALL_STATE!");
183                 return;
184         }
185
186         switch (status) {
187         case VCONFKEY_CALL_VOICE_CONNECTING:
188         case VCONFKEY_CALL_VIDEO_CONNECTING:
189                 show_image_icon(data);
190                 icon_animation_set(ICON_ANI_BLINK);
191                 break;
192         case VCONFKEY_CALL_VOICE_ACTIVE:
193         case VCONFKEY_CALL_VIDEO_ACTIVE:
194                 show_image_icon(data);
195                 icon_animation_set(ICON_ANI_NONE);
196                 break;
197         case VCONFKEY_CALL_OFF:
198                 hide_image_icon();
199                 break;
200         default:
201                 _E("Invalid value %d", status);
202                 break;
203         }
204 }
205
206 static int register_call_module(void *data)
207 {
208         int ret = 0;
209
210         retv_if(!data, 0);
211
212         set_app_state(data);
213
214         ret = vconf_notify_key_changed(VCONFKEY_CALL_STATE, indicator_call_change_cb, data);
215         register_bt_state(data);
216         if (ret != OK) _E("Failed to register VCONFKEY_CALL_STATE callback!");
217
218         return ret;
219 }
220
221 static int unregister_call_module(void)
222 {
223         int ret = 0;
224
225         ret = vconf_ignore_key_changed(VCONFKEY_CALL_STATE, indicator_call_change_cb);
226         unregister_bt_state();
227         if (ret != OK) _E("Failed to register VCONFKEY_CALL_STATE callback!");
228
229         return ret;
230 }
231 /* End of file */