apply FSL(Flora Software License)
[profile/ivi/indicator-win.git] / modules / home / home.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_FIXED5
28 #define MODULE_NAME             "home"
29
30 static int register_home_module(void *data);
31 static int unregister_home_module(void);
32
33 Indicator_Icon_Object home = {
34         .type = INDICATOR_IMG_ICON,
35         .name = MODULE_NAME,
36         .priority = ICON_PRIORITY,
37         .always_top = EINA_FALSE,
38         .txt_obj = {0,},
39         .img_obj = {0,},
40         .obj_exist = EINA_FALSE,
41         .fixed = EINA_TRUE,
42         .exist_in_view = EINA_FALSE,
43         .init = register_home_module,
44         .fini = unregister_home_module,
45 };
46
47 static const char *icon_path[] = {
48         "Home/B03_Home.png",
49         "Home/B03_Home_press.png",
50         NULL
51 };
52
53 static void change_home_icon_cb(keynode_t *node, void *data)
54 {
55         int status = 0;
56         int ret = -1;
57
58         retif(data == NULL, , "Invalid parameter!");
59
60         ret = vconf_get_int(VCONF_INDICATOR_HOME_PRESSED, &status);
61
62         if (ret == 0) {
63                 if (status == 1) {
64                         INFO("change_home_icon_cb : Home Button Pressed!");
65                         home.img_obj.data = icon_path[1];
66                         indicator_util_icon_show(&home);
67                 } else {
68                         INFO("change_home_icon_cb : Home Button Pressed!");
69                         home.img_obj.data = icon_path[0];
70                         indicator_util_icon_show(&home);
71                 }
72         }
73 }
74 static int register_home_module(void *data)
75 {
76         int r = 0, ret = -1;
77
78         retif(data == NULL, FAIL, "Invalid parameter!");
79
80         ret = vconf_notify_key_changed(VCONF_INDICATOR_HOME_PRESSED,
81                                        change_home_icon_cb, data);
82         if (ret != 0) {
83                 ERR("Failed to register callback!");
84                 r = ret;
85         }
86
87         home.img_obj.data = icon_path[0];
88         indicator_util_icon_show(&home);
89         return 0;
90 }
91
92 static int unregister_home_module(void)
93 {
94         int ret = -1;
95
96         ret = vconf_ignore_key_changed(VCONF_INDICATOR_HOME_PRESSED,
97                                        change_home_icon_cb);
98         if (ret != 0)
99                 ERR("Failed to unregister callback!");
100
101         indicator_util_icon_hide(&home);
102         return 0;
103 }