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