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