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