apply FSL(Flora Software License)
[apps/home/indicator-win.git] / modules / information / mmc.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_ui.h"
24 #include "modules.h"
25 #include "indicator_icon_util.h"
26
27 #define ICON_PRIORITY   INDICATOR_PRIORITY_NON_FIXED_6
28 #define MODULE_NAME             "mmc"
29 #define TIMER_INTERVAL  0.3
30
31 static int register_mmc_module(void *data);
32 static int unregister_mmc_module(void);
33
34 Indicator_Icon_Object mmc = {
35         .name = MODULE_NAME,
36         .priority = ICON_PRIORITY,
37         .always_top = EINA_TRUE,
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_mmc_module,
44         .fini = unregister_mmc_module
45 };
46
47 static const char *icon_path[] = {
48         "Background_playing/B03_Memorycard.png",
49         NULL
50 };
51
52 static void indicator_mmc_change_cb(keynode_t *node, void *data)
53 {
54         int status = 0;
55         int ret;
56
57         retif(data == NULL, , "Invalid parameter!");
58
59         ret = vconf_get_int(VCONFKEY_FILEMANAGER_DB_STATUS, &status);
60         if (ret == FAIL) {
61                 ERR("Failed to get VCONFKEY_MMC_STATE!");
62                 return;
63         }
64
65         switch (status) {
66         case VCONFKEY_FILEMANAGER_DB_UPDATING:
67                 INFO("MMC loading");
68                 mmc.img_obj.data = icon_path[0];
69                 indicator_util_icon_show(&mmc);
70                 indicator_util_icon_animation_set(&mmc, ICON_ANI_BLINK);
71                 break;
72
73         case VCONFKEY_FILEMANAGER_DB_UPDATED:
74         default:
75                 indicator_util_icon_hide(&mmc);
76                 break;
77         }
78 }
79
80 static int register_mmc_module(void *data)
81 {
82         int ret;
83
84         retif(data == NULL, FAIL, "Invalid parameter!");
85
86         ret = vconf_notify_key_changed(VCONFKEY_FILEMANAGER_DB_STATUS,
87                                        indicator_mmc_change_cb, data);
88         if (ret != OK)
89                 ERR("Failed to register mmcback!");
90
91         indicator_mmc_change_cb(NULL, data);
92
93         return ret;
94 }
95
96 static int unregister_mmc_module(void)
97 {
98         int ret;
99
100         ret = vconf_ignore_key_changed(VCONFKEY_FILEMANAGER_DB_STATUS,
101                                        indicator_mmc_change_cb);
102         if (ret != OK)
103                 ERR("Failed to unregister mmcback!");
104
105         indicator_util_icon_hide(&mmc);
106
107         return OK;
108 }