ccda58dc42565b1bf4d706057ec49074561b55ff
[apps/home/settings.git] / setting-phone / src / setting-phone-ticker-notification-details.c
1 /*
2  * setting
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
5  *
6  * Contact: MyoungJune Park <mj2004.park@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21 #include <setting-phone-ticker-notification-details.h>
22 #include <ail.h>
23
24 #define NOTIFICATION_STR "IDS_ST_BODY_NOTIFICATION"
25 #define DISPLAY_CONTENT_STR "IDS_ST_BODY_DISPLAY_CONTENTS"
26 #define BADGE_STR "IDS_COM_BODY_BADGE_ABB"
27
28 #define STR_NOTIFICATION_DETAILS_HELP1 "You can turn off notification of this application. <br> <br>" \
29                                        "If you don't want to see contents in notification popup, turn off the display contents. <br> <br>"\
30                                        "If you don't want to display badge on app icon with a new event number, turn off the Badge."
31
32 static int setting_phone_ticker_notification_details_create(void *cb);
33 static int setting_phone_ticker_notification_details_destroy(void *cb);
34 static int setting_phone_ticker_notification_details_update(void *cb);
35 static int setting_phone_ticker_notification_details_cleanup(void *cb);
36
37 static void setting_phone_noti_details_chk_btn_cb(void *data, Evas_Object *obj, void *event_info);
38 static void setting_phone_noti_details_mouse_up_Gendial_list_cb(void *data, Evas_Object *obj, void *event_info);
39
40 static int __status_get_notification_str(char* title);
41 static int __status_get_display_contents_str(char* title);
42 static int __status_get_badge_str(char* title);
43 static void __status_set_display_contents_str(void* data);
44
45 setting_view setting_view_phone_ticker_notification_details = {
46         .create = setting_phone_ticker_notification_details_create,
47         .destroy = setting_phone_ticker_notification_details_destroy,
48         .update = setting_phone_ticker_notification_details_update,
49         .cleanup = setting_phone_ticker_notification_details_cleanup,
50 };
51
52 /* ***************************************************
53  *
54  *basic func
55  *
56  ***************************************************/
57 char* g_sel_string = NULL;
58 SettingPhoneUG *g_phone_ad = NULL;
59
60 static int setting_phone_ticker_notification_details_create(void *cb)
61 {
62         /* error check */
63         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
64         SettingPhoneUG *ad = (SettingPhoneUG *) cb;
65         g_phone_ad = ad;
66
67         Evas_Object *scroller;
68
69         /* scroller is a genlist */
70         setting_push_layout_navi_bar_genlist(ad->win_main_layout, ad->win_get,
71                                                    _(ad->sel_string),
72                                                    dgettext("sys_string", "IDS_COM_BODY_BACK"),
73                                                    NULL,
74                                                    setting_phone_noti_details_click_softkey_back_cb,
75                                                    NULL, ad, &scroller,
76                                                    ad->navi_bar);
77
78         Elm_Object_Item *item;
79
80         g_sel_string = ad->sel_string;
81
82         // [UI] Separator
83         item =
84             elm_genlist_item_append(scroller, &(ad->itc_seperator), NULL, NULL,
85                                     ELM_GENLIST_ITEM_NONE, NULL, NULL);
86         elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
87
88         int noti_val = __status_get_notification_str(ad->sel_string);
89
90         // [UI] Notification
91         ad->data_details_notification =
92             setting_create_Gendial_field_def(scroller, &(ad->itc_1text_1icon),
93                                              setting_phone_noti_details_mouse_up_Gendial_list_cb,
94                                              ad, SWALLOW_Type_1TOGGLE, NULL,
95                                              NULL, noti_val,
96                                              NOTIFICATION_STR, NULL,
97                                              setting_phone_noti_details_chk_btn_cb);
98         if (ad->data_details_notification) {
99                 ad->data_details_notification->userdata = ad;
100         } else {
101                 SETTING_TRACE_ERROR("ad->data_launch_effect is NULL");
102         }
103
104         int display_val = __status_get_display_contents_str(ad->sel_string);
105
106         // [UI] Display contents
107         ad->data_details_display_content =
108             setting_create_Gendial_field_def(scroller, &(ad->itc_1text_1icon),
109                                              setting_phone_noti_details_mouse_up_Gendial_list_cb,
110                                              ad, SWALLOW_Type_1TOGGLE, NULL,
111                                              NULL, display_val,
112                                              DISPLAY_CONTENT_STR, NULL,
113                                              setting_phone_noti_details_chk_btn_cb);
114         if (ad->data_details_display_content) {
115                 ad->data_details_display_content->userdata = ad;
116         } else {
117                 SETTING_TRACE_ERROR("ad->data_launch_effect is NULL");
118         }
119
120         // [UI] Badge
121         int badge_val = __status_get_badge_str(ad->sel_string);
122         ad->data_details_badge =
123             setting_create_Gendial_field_def(scroller, &(ad->itc_1text_1icon),
124                                              setting_phone_noti_details_mouse_up_Gendial_list_cb,
125                                              ad, SWALLOW_Type_1TOGGLE, NULL,
126                                              NULL, badge_val,
127                                              BADGE_STR, NULL,
128                                              setting_phone_noti_details_chk_btn_cb);
129         if (ad->data_details_badge) {
130                 ad->data_details_badge->userdata = ad;
131         } else {
132                 SETTING_TRACE_ERROR("ad->data_launch_effect is NULL");
133         }
134         // [UI] help text 1
135         setting_create_Gendial_field_def(scroller, &(ad->itc_bg_1icon), NULL,
136                         ad, SWALLOW_Type_LAYOUT_SPECIALIZTION_X,
137                         NULL, NULL, 0, STR_NOTIFICATION_DETAILS_HELP1, NULL,
138                         NULL);
139
140         setting_view_phone_ticker_notification_details.is_create = 1;
141         return SETTING_RETURN_SUCCESS;
142 }
143
144 static int setting_phone_ticker_notification_details_destroy(void *cb)
145 {
146         SETTING_TRACE_BEGIN;
147         /* error check */
148         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
149
150         SettingPhoneUG *ad = (SettingPhoneUG *) cb;
151
152         elm_naviframe_item_pop(ad->navi_bar);
153         setting_view_phone_ticker_notification_details.is_create = 0;
154
155         return SETTING_RETURN_SUCCESS;
156 }
157
158 static int setting_phone_ticker_notification_details_update(void *cb)
159 {
160         SETTING_TRACE_BEGIN;
161         return SETTING_RETURN_SUCCESS;
162 }
163
164 static int setting_phone_ticker_notification_details_cleanup(void *cb)
165 {
166         SETTING_TRACE_BEGIN;
167         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
168         setting_phone_ticker_notification_details_destroy(cb);
169         return SETTING_RETURN_SUCCESS;
170 }
171
172 /* ***************************************************
173  *
174  *general func
175  *
176  ***************************************************/
177
178 /* ***************************************************
179  *
180  *call back func
181  *
182  ***************************************************/
183
184 static void
185 setting_phone_noti_details_click_softkey_back_cb(void *data, Evas_Object *obj,
186                                          void *event_info)
187 {
188         SETTING_TRACE_BEGIN;
189         /* error check */
190         retm_if(data == NULL, "Data parameter is NULL");
191         SettingPhoneUG *ad = (SettingPhoneUG *) data;
192
193         setting_view_change(&setting_view_phone_ticker_notification_details, &setting_view_phone_ticker_notification, ad);
194 }
195
196
197 // -1  : failed
198 //  0  : off
199 //  1  : on
200 static int __status_get_notification_str(char* title)
201 {
202         SETTING_TRACE_BEGIN;
203         int err;
204         int val = -1;
205
206         if ( 0== safeStrCmp (title, "IDS_COM_BODY_MESSAGES")) {
207                 setting_get_bool_slp_key(BOOL_SLP_SETTING_TICKER_NOTI_MESSAGES, &val, &err);
208
209         } else if ( 0== safeStrCmp (title, "IDS_ST_BODY_EMAIL")) {
210                 setting_get_bool_slp_key(BOOL_SLP_SETTING_TICKER_NOTI_EMAIL, &val, &err);
211         }
212         /* add new menu */
213         else if ( 0== safeStrCmp (title, "IDS_COM_BODY_INSTANT_MESSENGER")) {
214                 setting_get_bool_slp_key(BOOL_SLP_SETTING_TICKER_NOTI_IM, &val, &err);
215         } else if ( 0== safeStrCmp (title, KeyStr_Twitter)) {
216                 setting_get_bool_slp_key(BOOL_SLP_SETTING_TICKER_NOTI_TWITTER, &val, &err);
217         } else if ( 0== safeStrCmp (title, KeyStr_Facebook)) {
218                 setting_get_bool_slp_key(BOOL_SLP_SETTING_TICKER_NOTI_FACEBOOK, &val, &err);
219         }
220
221         SETTING_TRACE_DEBUG("title : %s, value : %d, err : %d", title, val, err);
222
223         return val;
224 }
225
226 // -1  : failed
227 //  0  : off
228 //  1  : on
229 static int __status_get_display_contents_str(char* title)
230 {
231         SETTING_TRACE_BEGIN;
232         int err;
233         int val = -1;
234
235         if ( 0== safeStrCmp (title, "IDS_COM_BODY_MESSAGES")) {
236                 setting_get_bool_slp_key(BOOL_SLP_SETTING_NOTI_DISPLAY_CONTENT_MESSASGES, &val, &err);
237         } else if ( 0== safeStrCmp (title, "IDS_ST_BODY_EMAIL")) {
238                 setting_get_bool_slp_key(BOOL_SLP_SETTING_NOTI_DISPLAY_CONTENT_EMAIL, &val, &err);
239         }
240         /* add new menu */
241         else if ( 0== safeStrCmp (title, "IDS_COM_BODY_INSTANT_MESSENGER")) {
242                 setting_get_bool_slp_key(BOOL_SLP_SETTING_NOTI_DISPLAY_CONTENT_IM, &val, &err);
243         } else if ( 0== safeStrCmp (title, KeyStr_Twitter)) {
244                 setting_get_bool_slp_key(BOOL_SLP_SETTING_NOTI_DISPLAY_CONTENT_TWITTER, &val, &err);
245         } else if ( 0== safeStrCmp (title, KeyStr_Facebook)) {
246                 setting_get_bool_slp_key(BOOL_SLP_SETTING_NOTI_DISPLAY_CONTENT_FACEBOOK, &val, &err);
247         }
248
249         SETTING_TRACE_DEBUG("title : %s, value : %d, err : %d", title, val, err);
250
251         return val;
252 }
253 static int __status_get_badge_str(char* title)
254 {
255         SETTING_TRACE_BEGIN;
256         int val = -1;
257         const char *vconf_key = NULL;
258         if ( 0== safeStrCmp (title, "IDS_COM_BODY_MESSAGES")) {
259                 vconf_key = VCONFKEY_TICKER_NOTI_BADGE_MESSAGES;
260         } else if ( 0== safeStrCmp (title, "IDS_ST_BODY_EMAIL")) {
261                 vconf_key = VCONFKEY_TICKER_NOTI_BADGE_EMAIL;
262         }
263         /* add new menu */
264         else if ( 0== safeStrCmp (title, "IDS_COM_BODY_INSTANT_MESSENGER")) {
265                 vconf_key = VCONFKEY_TICKER_NOTI_BADGE_IM;
266         } else if ( 0== safeStrCmp (title, KeyStr_Twitter)) {
267                 vconf_key = VCONFKEY_TICKER_NOTI_BADGE_TWITTER;
268         } else if ( 0== safeStrCmp (title, KeyStr_Facebook)) {
269                 vconf_key = VCONFKEY_TICKER_NOTI_BADGE_FACEBOOK;
270         }
271         SETTING_TRACE("vconf_key:%s", vconf_key);
272         vconf_get_bool(vconf_key, &val);
273         SETTING_TRACE_DEBUG("title : %s, value : %d", title, val);
274         return val;
275 }
276
277 static void __status_set_notification_str(void* data)
278 {
279         SETTING_TRACE_BEGIN;
280         int err;
281         Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *)data;
282
283         // message update in previos page
284         Setting_GenGroupItem_Data* item_to_update = NULL;
285
286         char* status;
287
288         if (list_item->chk_status == 1) {
289                 status = setting_gettext("IDS_COM_BODY_ON_M_STATUS");
290         } else {
291                 status = setting_gettext("IDS_COM_BODY_OFF_M_STATUS");
292         }
293
294         if ( 0== safeStrCmp (g_sel_string, "IDS_COM_BODY_MESSAGES")) {
295                 setting_set_bool_slp_key(BOOL_SLP_SETTING_TICKER_NOTI_MESSAGES, list_item->chk_status, &err);
296                 item_to_update = g_phone_ad->data_n_msg;
297         } else if ( 0== safeStrCmp (g_sel_string, "IDS_ST_BODY_EMAIL")) {
298                 setting_set_bool_slp_key(BOOL_SLP_SETTING_TICKER_NOTI_EMAIL, list_item->chk_status, &err);
299                 item_to_update = g_phone_ad->data_n_email;
300         }
301         /* add new menu */
302         else if ( 0== safeStrCmp (g_sel_string, "IDS_COM_BODY_INSTANT_MESSENGER")) {
303                 setting_set_bool_slp_key(BOOL_SLP_SETTING_TICKER_NOTI_IM, list_item->chk_status, &err);
304                 item_to_update = g_phone_ad->data_n_im;
305         } else if ( 0== safeStrCmp (g_sel_string, KeyStr_Twitter)) {
306                 setting_set_bool_slp_key(BOOL_SLP_SETTING_TICKER_NOTI_TWITTER, list_item->chk_status, &err);
307                 item_to_update = g_phone_ad->data_n_twt;
308         } else if ( 0== safeStrCmp (g_sel_string, KeyStr_Facebook)) {
309                 setting_set_bool_slp_key(BOOL_SLP_SETTING_TICKER_NOTI_FACEBOOK, list_item->chk_status, &err);
310                 item_to_update = g_phone_ad->data_n_fb;
311         }
312
313         // update UI
314         if (item_to_update) {
315                 item_to_update->sub_desc = strdup(status);
316                 elm_object_item_data_set(item_to_update->item,item_to_update);
317                 elm_genlist_item_update(item_to_update->item);
318         }
319 }
320
321 static void __status_set_display_contents_str(void* data)
322 {
323         SETTING_TRACE_BEGIN;
324         int err;
325         Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *)data;
326
327         // message update in previos page
328
329         char* status;
330
331         if (list_item->chk_status == 1) {
332                 status = setting_gettext("IDS_COM_BODY_ON_M_STATUS");
333         } else {
334                 status = setting_gettext("IDS_COM_BODY_OFF_M_STATUS");
335         }
336
337         if ( 0== safeStrCmp (g_sel_string, "IDS_COM_BODY_MESSAGES")) {
338                 setting_set_bool_slp_key(BOOL_SLP_SETTING_NOTI_DISPLAY_CONTENT_MESSASGES, list_item->chk_status, &err);
339         } else if ( 0== safeStrCmp (g_sel_string, "IDS_ST_BODY_EMAIL")) {
340                 setting_set_bool_slp_key(BOOL_SLP_SETTING_NOTI_DISPLAY_CONTENT_EMAIL, list_item->chk_status, &err);
341         }
342         /* add new menu */
343         else if ( 0== safeStrCmp (g_sel_string, "IDS_COM_BODY_INSTANT_MESSENGER")) {
344                 setting_set_bool_slp_key(BOOL_SLP_SETTING_NOTI_DISPLAY_CONTENT_IM, list_item->chk_status, &err);
345         } else if ( 0== safeStrCmp (g_sel_string, KeyStr_Twitter)) {
346                 setting_set_bool_slp_key(BOOL_SLP_SETTING_NOTI_DISPLAY_CONTENT_TWITTER, list_item->chk_status, &err);
347         } else if ( 0== safeStrCmp (g_sel_string, KeyStr_Facebook)) {
348                 setting_set_bool_slp_key(BOOL_SLP_SETTING_NOTI_DISPLAY_CONTENT_FACEBOOK, list_item->chk_status, &err);
349         }
350 }
351
352 static void __status_set_badge_str(void* data)
353 {
354         SETTING_TRACE_BEGIN;
355         setting_retm_if(data == NULL, "Data parameter is NULL");
356         Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *)data;
357
358         char *status = NULL;
359
360         if (list_item->chk_status == 1) {
361                 status = setting_gettext("IDS_COM_BODY_ON_M_STATUS");
362         } else {
363                 status = setting_gettext("IDS_COM_BODY_OFF_M_STATUS");
364         }
365
366         SETTING_TRACE("g_sel_string:%s", g_sel_string);
367         const char *vconf_key = NULL;
368         if ( 0== safeStrCmp (g_sel_string, "IDS_COM_BODY_MESSAGES")) {
369                 vconf_key = VCONFKEY_TICKER_NOTI_BADGE_MESSAGES;
370         } else if ( 0== safeStrCmp (g_sel_string, "IDS_ST_BODY_EMAIL")) {
371                 vconf_key = VCONFKEY_TICKER_NOTI_BADGE_EMAIL;
372         }
373         /* add new menu */
374         else if ( 0== safeStrCmp (g_sel_string, "IDS_COM_BODY_INSTANT_MESSENGER")) {
375                 vconf_key = VCONFKEY_TICKER_NOTI_BADGE_IM;
376         } else if ( 0== safeStrCmp (g_sel_string, KeyStr_Twitter)) {
377                 vconf_key = VCONFKEY_TICKER_NOTI_BADGE_TWITTER;
378         } else if ( 0== safeStrCmp (g_sel_string, KeyStr_Facebook)) {
379                 vconf_key = VCONFKEY_TICKER_NOTI_BADGE_FACEBOOK;
380         }
381         SETTING_TRACE("vconf_key:%s", vconf_key);
382         int ret = vconf_set_bool(vconf_key, list_item->chk_status);
383         setting_retm_if(ret != 0, "fail to set vconf");
384 }
385
386 /**
387  * genlist click
388  */
389 static void setting_phone_noti_details_mouse_up_Gendial_list_cb(void *data, Evas_Object *obj, void *event_info)
390 {
391         SETTING_TRACE_BEGIN;
392         /* error check */
393         setting_retm_if(data == NULL, "Data parameter is NULL");
394
395         retm_if(event_info == NULL, "Invalid argument: event info is NULL");
396         Elm_Object_Item *item = (Elm_Object_Item *) event_info;
397         elm_genlist_item_selected_set(item, 0);
398         Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
399
400
401         int old_status = elm_check_state_get(list_item->eo_check);
402         list_item->chk_status = !old_status;
403         elm_check_state_set(list_item->eo_check, list_item->chk_status);        /* new status */
404
405         if ( 0== safeStrCmp (list_item->keyStr, NOTIFICATION_STR)) {
406                 __status_set_notification_str(list_item);
407         } else if ( 0== safeStrCmp (list_item->keyStr, DISPLAY_CONTENT_STR)) {
408                 // vconf setting by g_sel_string
409                 __status_set_display_contents_str(list_item);
410         }  else if ( 0== safeStrCmp (list_item->keyStr, BADGE_STR)) {
411                 __status_set_badge_str(list_item);
412         }
413 }
414
415
416 /**
417  * check box
418  */
419 static void setting_phone_noti_details_chk_btn_cb(void *data, Evas_Object *obj, void *event_info)
420  {
421         SETTING_TRACE_BEGIN;
422         /* error check */
423         retm_if(data == NULL, "Data parameter is NULL");
424         Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *) data;
425         list_item->chk_status = elm_check_state_get(obj);       /*  for genlist update status */
426
427         if ( 0== safeStrCmp (list_item->keyStr, NOTIFICATION_STR)) {
428                 __status_set_notification_str(list_item);
429         } else if ( 0== safeStrCmp (list_item->keyStr, DISPLAY_CONTENT_STR)) {
430                 __status_set_display_contents_str(list_item);
431         } else if ( 0== safeStrCmp (list_item->keyStr, BADGE_STR)) {
432                 __status_set_badge_str(list_item);
433         }
434  }
435