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