6b4a369cff6102e447a159b4402454c3bddb9b86
[apps/home/b2-clocksetting.git] / src / setting-notification.c
1 /*
2  * setting-notification.c
3  *
4  *  Created on: Feb 14, 2014
5  *      Author: min-hoyun
6  */
7
8 #include "setting-notification.h"
9
10
11 static struct _noti_menu_item noti_menu_its[] = {
12         { "IDS_ST_BUTTON_NOTIFICATIONS",         1, _noti_gl_enabling_noti_cb },
13         { NULL, 0, NULL }
14 };
15
16 static struct _noti_data g_noti_data;
17 static bool is_called_myself;
18
19
20 void _initialize_noti()
21 {
22         is_called_myself = false;
23
24         g_noti_data.g_noti_genlist = NULL;
25         g_noti_data.is_enable_noti = 0;
26         g_noti_data.temp_ad = NULL;
27
28         register_vconf_changing(VCONF_WMS_NOTIFICATION_KEY, noti_enabling_vconf_changed_cb, NULL);
29 }
30
31 void _noti_gl_enabling_noti_cb(void *data, Evas_Object *obj, void *event_info)
32 {
33         DBG("Setting - _noti_gl_enabling_noti_cb() is called!");
34
35         Elm_Object_Item* it = (Elm_Object_Item *)event_info;
36         appdata *ad = data;
37
38         if( ad == NULL )
39         {
40                 DBG("%s", "_noti_gl_enabling_noti_cb - ad or check is null");
41                 return;
42         }
43
44         is_called_myself = true;
45
46         g_noti_data.is_enable_noti = (g_noti_data.is_enable_noti) ? 0 : 1;
47
48         vconf_set_int(VCONF_WMS_NOTIFICATION_KEY, g_noti_data.is_enable_noti);
49
50         elm_genlist_item_selected_set(it, EINA_FALSE);
51
52         if(g_noti_data.g_noti_genlist)
53         {
54                 elm_genlist_realized_items_update(g_noti_data.g_noti_genlist);
55         }
56 }
57
58 Eina_Bool _clear_noti_cb(void *data, Elm_Object_Item *it)
59 {
60         DBG("Setting - _clear_noti_cb() is called!");
61
62         is_called_myself = false;
63
64         g_noti_data.g_noti_genlist = NULL;
65         g_noti_data.is_enable_noti = 0;
66         g_noti_data.temp_ad = NULL;
67
68         unregister_vconf_changing(VCONF_WMS_NOTIFICATION_KEY, noti_enabling_vconf_changed_cb);
69
70         return EINA_TRUE;
71 }
72
73 char * _gl_noti_title_get(void *data, Evas_Object *obj, const char *part)
74 {
75         char buf[1024] = {0,};
76         Noti_Item_Data *id = data;
77         int index = id->index;
78
79         if( !strcmp(part, "elm.text.1") )
80         {
81                 snprintf(buf, sizeof(buf)-1, "%s", _(noti_menu_its[index % 1].name));
82         }
83         else if( !strcmp(part, "elm.text.2") )
84         {
85                 vconf_get_int(VCONF_WMS_NOTIFICATION_KEY, &g_noti_data.is_enable_noti);
86                 snprintf(buf, sizeof(buf)-1, "%s", (g_noti_data.is_enable_noti) ? _("IDS_EMAIL_BODY_ENABLED_M_STATUS")
87                                                                                                                                                 : _("IDS_ST_MBODY_DISABLED_ABB"));
88         }
89         return strdup(buf);
90 }
91
92 Evas_Object * _gl_noti_check_get(void *data, Evas_Object *obj, const char *part)
93 {
94         Evas_Object *check = NULL;
95         Noti_Item_Data *id = data;
96         int index = id->index;
97
98         if( !strcmp(part, "elm.icon") )
99         {
100                 check = elm_check_add(obj);
101                 elm_object_style_set(check, "list");
102                 vconf_get_int(VCONF_WMS_NOTIFICATION_KEY, &g_noti_data.is_enable_noti);
103                 elm_check_state_set(check, (g_noti_data.is_enable_noti) ? EINA_TRUE : EINA_FALSE);
104                 evas_object_size_hint_weight_set(check, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
105                 evas_object_propagate_events_set(check, EINA_FALSE);
106                 evas_object_repeat_events_set(check, EINA_TRUE);
107         }
108
109         return check;
110 }
111
112 static void _noti_gl_del(void *data, Evas_Object *obj)
113 {
114         Noti_Item_Data *id = data;
115         if (id)
116                 free(id);
117 }
118
119 Evas_Object* _create_noti_list(void* data)
120 {
121         DBG("Setting - _create_noti_list() is called!");
122
123         appdata *ad = data;
124         if( ad == NULL )
125         {
126                 DBG("%s", "_create_noti_list - appdata is null");
127                 return NULL;
128         }
129         Evas_Object *genlist  = NULL;
130         struct _noti_menu_item *menu_its = NULL;
131         int idx = 0;
132
133         Elm_Genlist_Item_Class *itc = elm_genlist_item_class_new();
134         itc->item_style = "2text.1icon.1";
135         itc->func.text_get = _gl_noti_title_get;
136         itc->func.content_get = _gl_noti_check_get;
137         itc->func.del = _noti_gl_del;
138
139         Evas_Object * layout = elm_layout_add(ad->nf);
140         elm_layout_file_set(layout, EDJE_PATH, "setting/genlist/layout");
141         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
142
143         genlist = elm_genlist_add(layout);
144         elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
145
146         menu_its = noti_menu_its;
147
148 #if 0
149         device_info_h* device_info = NULL;
150         bundle *b = NULL;
151         char *val = NULL;
152         capability_manager_create_device_info(&device_info);
153         capability_manager_get_device_features(device_info, &b);
154         val = bundle_get_val(b, "smartrelay");
155         capability_manager_destroy_device_info(device_info);
156 #endif
157
158         for (idx = 0; idx < NOTIFICATION_ITEM_COUNT; idx++)
159         {
160                 Noti_Item_Data *id = calloc(sizeof(Noti_Item_Data), 1);
161                 id->index = idx;
162                 id->item = elm_genlist_item_append(
163                                 genlist,                                // genlist object
164                                 itc,                            // item class
165                                 id,                             // data
166                                 NULL,
167                                 ELM_GENLIST_ITEM_NONE,
168                                 menu_its[ idx ].func,   // call back
169                                 ad);
170         }
171         elm_genlist_item_class_free(itc);
172
173         g_noti_data.g_noti_genlist = genlist;
174
175         elm_object_part_content_set(layout, "elm.genlist", genlist);
176
177         return layout;
178 }
179
180 void noti_enabling_vconf_changed_cb(keynode_t *key, void * data)
181 {
182         DBG("Setting - noti_enabling_vconf_changed_cb() is called!");
183
184         if(is_called_myself)
185         {
186                 DBG("Setting - is_called_myself!! Return!!");
187                 is_called_myself = false;
188                 return;
189         }
190
191         g_noti_data.is_enable_noti = vconf_keynode_get_int(key);
192
193         DBG("Setting - Noti value: %d", g_noti_data.is_enable_noti);
194
195         if(g_noti_data.g_noti_genlist)
196         {
197                 elm_genlist_realized_items_update(g_noti_data.g_noti_genlist);
198         }
199 }