apply FSL(Flora Software License)
[apps/home/indicator-win.git] / modules / information / fm_radio.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 #include <stdio.h>
18 #include <stdlib.h>
19 #include <vconf.h>
20 #include <appcore-efl.h>
21 #include "common.h"
22 #include "indicator.h"
23 #include "indicator_icon_util.h"
24 #include "modules.h"
25 #include "indicator_ui.h"
26
27 #define ICON_PRIORITY   INDICATOR_PRIORITY_NON_FIXED_7
28 #define MODULE_NAME             "FM_Radio"
29
30 static int register_fm_radio_module(void *data);
31 static int unregister_fm_radio_module(void);
32
33 Indicator_Icon_Object fm_radio = {
34         .type = INDICATOR_IMG_ICON,
35         .name = MODULE_NAME,
36         .priority = ICON_PRIORITY,
37         .always_top = EINA_FALSE,
38         .exist_in_view = EINA_FALSE,
39         .txt_obj = {0,},
40         .img_obj = {0,},
41         .obj_exist = EINA_FALSE,
42         .fixed = EINA_FALSE,
43         .init = register_fm_radio_module,
44         .fini = unregister_fm_radio_module
45 };
46
47 static char *icon_path[] = {
48         "Background_playing/B03_Backgroundplaying_FMradio.png",
49         NULL
50 };
51
52 static void show_image_icon(void *data)
53 {
54         fm_radio.img_obj.data = icon_path[0];
55         indicator_util_icon_show(&fm_radio);
56 }
57
58 static void hide_image_icon(void)
59 {
60         indicator_util_icon_hide(&fm_radio);
61 }
62
63 static void indicator_fm_radio_change_cb(keynode_t *node, void *data)
64 {
65         int status;
66         int ret;
67
68         retif(data == NULL, , "Invalid parameter!");
69
70         ret = vconf_get_int(VCONFKEY_RADIO_STATE, &status);
71         if (ret == OK) {
72                 INFO("FM_RADIO state: %d", status);
73                 if (status == VCONFKEY_RADIO_PLAY)
74                         show_image_icon(data);
75                 else
76                         hide_image_icon();
77         }
78         return;
79 }
80
81 static int register_fm_radio_module(void *data)
82 {
83         int ret;
84
85         retif(data == NULL, FAIL, "Invalid parameter!");
86
87         ret = vconf_notify_key_changed(VCONFKEY_RADIO_STATE,
88                                        indicator_fm_radio_change_cb, data);
89         if (ret != OK)
90                 ERR("Failed to register callback!");
91         indicator_fm_radio_change_cb(NULL, data);
92
93         return ret;
94 }
95
96 static int unregister_fm_radio_module(void)
97 {
98         int ret;
99
100         ret = vconf_ignore_key_changed(VCONFKEY_RADIO_STATE,
101                                        indicator_fm_radio_change_cb);
102         if (ret != OK)
103                 ERR("Failed to unregister callback!");
104
105         hide_image_icon();
106
107         return OK;
108 }