Tizen release 1.0
[apps/home/settings.git] / setting-phone / src / setting-phone-ticker-notification.c
1 /*
2  * setting
3  *
4  * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd All Rights Reserved 
5  *
6  * This file is part of org.tizen.setting
7  * Written by Hyejin Kim <hyejin0906.kim@samsung.com>
8  *
9  * PROPRIETARY/CONFIDENTIAL
10  * 
11  * This software is the confidential and proprietary information of 
12  * SAMSUNG ELECTRONICS ("Confidential Information"). You shall not
13  * disclose such Confidential Information and shall use it only in
14  * accordance with the terms of the license agreement you entered
15  * into with SAMSUNG ELECTRONICS.
16  *
17  * SAMSUNG make no representations or warranties about the suitability 
18  * of the software, either express or implied, including but not limited
19  * to the implied warranties of merchantability, fitness for a particular
20  * purpose, or non-infringement. SAMSUNG shall not be liable for any
21  * damages suffered by licensee as a result of using, modifying or
22  * distributing this software or its derivatives.
23  *
24  */
25 #include <setting-phone-ticker-notification.h>
26 #include <ail.h>
27
28 static void get_3rd_applist(void *data, Evas_Object *scroller);
29
30 static char *get_appname(char *keyname);
31
32 static int setting_phone_ticker_notfication_create(void *cb);
33 static int setting_phone_ticker_notfication_destroy(void *cb);
34 static int setting_phone_ticker_notfication_update(void *cb);
35 static int setting_phone_ticker_notfication_cleanup(void *cb);
36
37 setting_view setting_view_phone_ticker_notification = {
38         .create = setting_phone_ticker_notfication_create,
39         .destroy = setting_phone_ticker_notfication_destroy,
40         .update = setting_phone_ticker_notfication_update,
41         .cleanup = setting_phone_ticker_notfication_cleanup,
42 };
43
44 /* ***************************************************
45  *
46  *basic func
47  *
48  ***************************************************/
49
50 static int setting_phone_ticker_notfication_create(void *cb)
51 {
52         /* error check */
53         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
54
55         SettingPhoneUG *ad = (SettingPhoneUG *) cb;
56
57         Evas_Object *navi_bar = NULL;
58         Evas_Object *scroller;
59         /* Evas_Object *outer_box; */
60
61         /* scroller is a genlist */
62         ad->ly_ticker =
63             setting_create_layout_navi_bar_genlist(ad->win_main_layout,
64                                                    ad->win_get,
65                                                    setting_gettext
66                                                    ("IDS_ST_BODY_EVENTS_NOTIFICATIONS"),
67                                                    dgettext("sys_string", "IDS_COM_BODY_BACK"),
68                                                    NULL,
69                                                    setting_phone_noti_click_softkey_back_cb,
70                                                    NULL, ad, &scroller,
71                                                    &navi_bar);
72         int value;
73         int err;
74         Elm_Object_Item *item;
75
76         item =
77             elm_genlist_item_append(scroller, &(ad->itc_seperator), NULL, NULL,
78                                     ELM_GENLIST_ITEM_NONE, NULL, NULL);
79         elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
80         setting_get_bool_slp_key(BOOL_SLP_SETTING_TICKER_NOTI_DISPLAY_CONTENT,
81                                  &value, &err);
82         ad->data_n_dsp =
83             setting_create_Gendial_field_def(scroller, &(ad->itc_1text_1icon),
84                                              setting_phone_noti_mouse_up_Gendial_list_cb,
85                                              ad, SWALLOW_Type_1TOGGLE, NULL,
86                                              NULL, value,
87                                              "IDS_ST_BODY_DISPLAY_CONTENTS",
88                                              NULL,
89                                              setting_phone_noti_mouse_up_chk_btn_cb);
90         if (ad->data_n_dsp) {
91                 ad->data_n_dsp->userdata = ad;
92         } else {
93                 SETTING_TRACE_ERROR("ad->data_n_dsp is NULL");
94         }
95
96         item =
97             elm_genlist_item_append(scroller, &(ad->itc_seperator), NULL, NULL,
98                                     ELM_GENLIST_ITEM_NONE, NULL, NULL);
99         elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
100         setting_get_bool_slp_key(BOOL_SLP_SETTING_TICKER_NOTI_MESSAGES, &value,
101                                  &err);
102         ad->data_n_msg =
103             setting_create_Gendial_field_def(scroller, &(ad->itc_1text_1icon),
104                                              setting_phone_noti_mouse_up_Gendial_list_cb,
105                                              ad, SWALLOW_Type_1TOGGLE, NULL,
106                                              NULL, value,
107                                              "IDS_COM_BODY_MESSAGES", NULL,
108                                              setting_phone_noti_mouse_up_chk_btn_cb);
109         if (ad->data_n_msg) {
110                 ad->data_n_msg->userdata = ad;
111         } else {
112                 SETTING_TRACE_ERROR("ad->data_n_msg is NULL");
113         }
114
115         setting_get_bool_slp_key(BOOL_SLP_SETTING_TICKER_NOTI_VMAIL, &value,
116                                  &err);
117         ad->data_n_vmail =
118             setting_create_Gendial_field_def(scroller, &(ad->itc_1text_1icon),
119                                              setting_phone_noti_mouse_up_Gendial_list_cb,
120                                              ad, SWALLOW_Type_1TOGGLE, NULL,
121                                              NULL, value,
122                                              "IDS_ST_BODY_VOICE_MAIL", NULL,
123                                              setting_phone_noti_mouse_up_chk_btn_cb);
124         if (ad->data_n_vmail) {
125                 ad->data_n_vmail->userdata = ad;
126         } else {
127                 SETTING_TRACE_ERROR("ad->data_n_vmail is NULL");
128         }
129
130         setting_get_bool_slp_key(BOOL_SLP_SETTING_TICKER_NOTI_EMAIL, &value,
131                                  &err);
132         ad->data_n_email =
133             setting_create_Gendial_field_def(scroller, &(ad->itc_1text_1icon),
134                                              setting_phone_noti_mouse_up_Gendial_list_cb,
135                                              ad, SWALLOW_Type_1TOGGLE, NULL,
136                                              NULL, value, "IDS_ST_BODY_EMAIL", NULL,
137                                              setting_phone_noti_mouse_up_chk_btn_cb);
138         if (ad->data_n_email) {
139                 ad->data_n_email->userdata = ad;
140         } else {
141                 SETTING_TRACE_ERROR("ad->data_n_email is NULL");
142         }
143
144         item =
145             elm_genlist_item_append(scroller, &(ad->itc_seperator), NULL, NULL,
146                                     ELM_GENLIST_ITEM_NONE, NULL, NULL);
147         elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
148         setting_get_bool_slp_key(BOOL_SLP_SETTING_TICKER_NOTI_SNS, &value,
149                                  &err);
150         ad->data_n_sns =
151             setting_create_Gendial_field_def(scroller, &(ad->itc_1text_1icon),
152                                              setting_phone_noti_mouse_up_Gendial_list_cb,
153                                              ad, SWALLOW_Type_1TOGGLE, NULL,
154                                              NULL, value, "IDS_ST_BODY_SNS", NULL,
155                                              setting_phone_noti_mouse_up_chk_btn_cb);
156         if (ad->data_n_sns) {
157                 ad->data_n_sns->userdata = ad;
158         } else {
159                 SETTING_TRACE_ERROR("ad->data_n_sns is NULL");
160         }
161
162         item =
163             elm_genlist_item_append(scroller, &(ad->itc_seperator), NULL, NULL,
164                                     ELM_GENLIST_ITEM_NONE, NULL, NULL);
165         elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
166         setting_get_bool_slp_key(BOOL_SLP_SETTING_TICKER_NOTI_FILE_TRAN, &value,
167                                  &err);
168         ad->data_n_file =
169             setting_create_Gendial_field_def(scroller, &(ad->itc_1text_1icon),
170                                              setting_phone_noti_mouse_up_Gendial_list_cb,
171                                              ad, SWALLOW_Type_1TOGGLE, NULL,
172                                              NULL, value,
173                                              "IDS_ST_BODY_FILE_TRANSFER", NULL,
174                                              setting_phone_noti_mouse_up_chk_btn_cb);
175         if (ad->data_n_file) {
176                 ad->data_n_file->userdata = ad;
177         } else {
178                 SETTING_TRACE_ERROR("ad->data_n_file is NULL");
179         }
180
181         get_3rd_applist(ad, scroller);
182
183         setting_view_phone_ticker_notification.is_create = 1;
184         return SETTING_RETURN_SUCCESS;
185 }
186
187 static int setting_phone_ticker_notfication_destroy(void *cb)
188 {
189         SETTING_TRACE_BEGIN;
190         /* error check */
191         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
192
193         SettingPhoneUG *ad = (SettingPhoneUG *) cb;
194
195         if (ad->ly_ticker != NULL) {
196                 evas_object_del(ad->ly_ticker);
197
198                 setting_view_phone_ticker_notification.is_create = 0;
199         }
200
201         return SETTING_RETURN_SUCCESS;
202 }
203
204 static int setting_phone_ticker_notfication_update(void *cb)
205 {
206         /* error check */
207         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
208
209         SettingPhoneUG *ad = (SettingPhoneUG *) cb;
210
211         if (ad->ly_ticker != NULL) {
212                 evas_object_show(ad->ly_ticker);
213         }
214
215         return SETTING_RETURN_SUCCESS;
216 }
217
218 static int setting_phone_ticker_notfication_cleanup(void *cb)
219 {
220         /* error check */
221         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
222
223         SettingPhoneUG *ad = (SettingPhoneUG *) cb;
224
225         if (ad->ly_ticker != NULL) {
226                 evas_object_hide(ad->ly_ticker);
227         }
228
229         return SETTING_RETURN_SUCCESS;
230 }
231
232 /* ***************************************************
233  *
234  *general func
235  *
236  ***************************************************/
237
238 /* ***************************************************
239  *
240  *call back func
241  *
242  ***************************************************/
243
244 static void
245 setting_phone_noti_mouse_up_chk_btn_cb(void *data, Evas_Object *obj,
246                                        void *event_info)
247 {
248         SETTING_TRACE_BEGIN;
249         /* error check */
250         retm_if(data == NULL, "Data parameter is NULL");
251         Setting_GenGroupItem_Data *list_item =
252             (Setting_GenGroupItem_Data *) data;
253         SettingPhoneUG *ad = list_item->userdata;
254         list_item->chk_status = elm_check_state_get(obj);       /*  for genlist update status */
255
256         int err = -1;
257         if (list_item->eo_check == ad->data_n_dsp->eo_check) {
258                 setting_set_bool_slp_key
259                     (BOOL_SLP_SETTING_TICKER_NOTI_DISPLAY_CONTENT,
260                      list_item->chk_status, &err);
261         } else if (list_item->eo_check == ad->data_n_msg->eo_check) {
262                 setting_set_bool_slp_key(BOOL_SLP_SETTING_TICKER_NOTI_MESSAGES,
263                                          list_item->chk_status, &err);
264         } else if (list_item->eo_check == ad->data_n_vmail->eo_check) {
265                 setting_set_bool_slp_key(BOOL_SLP_SETTING_TICKER_NOTI_VMAIL,
266                                          list_item->chk_status, &err);
267         } else if (list_item->eo_check == ad->data_n_email->eo_check) {
268                 setting_set_bool_slp_key(BOOL_SLP_SETTING_TICKER_NOTI_EMAIL,
269                                          list_item->chk_status, &err);
270         } else if (list_item->eo_check == ad->data_n_sns->eo_check) {
271                 setting_set_bool_slp_key(BOOL_SLP_SETTING_TICKER_NOTI_SNS,
272                                          list_item->chk_status, &err);
273         } else if (list_item->eo_check == ad->data_n_file->eo_check) {
274                 setting_set_bool_slp_key(BOOL_SLP_SETTING_TICKER_NOTI_FILE_TRAN,
275                                          list_item->chk_status, &err);
276         }
277         return;
278 }
279
280 static void
281 setting_phone_noti_mouse_up_Gendial_list_cb(void *data, Evas_Object *obj,
282                                             void *event_info)
283 {
284         /* error check */
285         setting_retm_if(data == NULL, "Data parameter is NULL");
286
287         retm_if(event_info == NULL, "Invalid argument: event info is NULL");
288         SettingPhoneUG *ad = (SettingPhoneUG *) data;
289
290         Elm_Object_Item *item = (Elm_Object_Item *) event_info;
291         elm_genlist_item_selected_set(item, 0);
292         Setting_GenGroupItem_Data *list_item =
293             (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
294
295         int old_status = elm_check_state_get(list_item->eo_check);
296         /* new status */
297         list_item->chk_status = !old_status;
298         elm_check_state_set(list_item->eo_check, list_item->chk_status);
299
300         int err = -1;
301         if (list_item->eo_check == ad->data_n_dsp->eo_check) {
302                 setting_set_bool_slp_key
303                     (BOOL_SLP_SETTING_TICKER_NOTI_DISPLAY_CONTENT,
304                      list_item->chk_status, &err);
305         } else if (list_item->eo_check == ad->data_n_msg->eo_check) {
306                 setting_set_bool_slp_key(BOOL_SLP_SETTING_TICKER_NOTI_MESSAGES,
307                                          list_item->chk_status, &err);
308         } else if (list_item->eo_check == ad->data_n_vmail->eo_check) {
309                 setting_set_bool_slp_key(BOOL_SLP_SETTING_TICKER_NOTI_VMAIL,
310                                          list_item->chk_status, &err);
311         } else if (list_item->eo_check == ad->data_n_email->eo_check) {
312                 setting_set_bool_slp_key(BOOL_SLP_SETTING_TICKER_NOTI_EMAIL,
313                                          list_item->chk_status, &err);
314         } else if (list_item->eo_check == ad->data_n_sns->eo_check) {
315                 setting_set_bool_slp_key(BOOL_SLP_SETTING_TICKER_NOTI_SNS,
316                                          list_item->chk_status, &err);
317         } else if (list_item->eo_check == ad->data_n_file->eo_check) {
318                 setting_set_bool_slp_key(BOOL_SLP_SETTING_TICKER_NOTI_FILE_TRAN,
319                                          list_item->chk_status, &err);
320         }
321 }
322
323 static void
324 setting_phone_noti_click_softkey_back_cb(void *data, Evas_Object *obj,
325                                          void *event_info)
326 {
327         /* error check */
328         retm_if(data == NULL, "Data parameter is NULL");
329
330         SettingPhoneUG *ad = (SettingPhoneUG *) data;
331
332         /* Send destroy request */
333         ug_destroy_me(ad->ug);
334 }
335
336 /*****/
337
338 static void
339 setting_phone_noti_3rd_apps_chk_btn_cb(void *data, Evas_Object *obj,
340                                        void *event_info)
341 {
342         SETTING_TRACE_BEGIN;
343         /* error check */
344         retm_if(data == NULL, "Data parameter is NULL");
345         Setting_GenGroupItem_Data *list_item =
346             (Setting_GenGroupItem_Data *) data;
347
348         list_item->chk_status = elm_check_state_get(obj);       /*  for genlist update status */
349
350         if (0 != vconf_set_int(list_item->sub_desc, list_item->chk_status)) {
351                 SETTING_TRACE("Set vconf[%s] failed", list_item->sub_desc);
352                 /*  restore if failed */
353                 list_item->chk_status = !list_item->chk_status;
354                 elm_check_state_set(list_item->eo_check, list_item->chk_status);
355         } else {
356                 SETTING_TRACE("Set vconf[%s] success", list_item->sub_desc);
357
358                 int ret = -1;
359                 ret = vconf_set_int(list_item->sub_desc, list_item->chk_status);
360                 if (ret) {
361                         SETTING_TRACE("Set vconf[%s] failed",
362                                       list_item->sub_desc);
363                 } else {
364                         ret =
365                             heynoti_publish
366                             ("setting_event_noti_3rdapp_changed");
367                         SETTING_TRACE("heynoti publish ret = %d ", ret);
368                         if (ret < 0) {
369                                 SETTING_TRACE_ERROR
370                                     ("heynoti_publish error - [%d] failed",
371                                      ret);
372                         }
373                 }
374
375                 if (ret < 0) {
376                         SETTING_TRACE("heynoti publish ret = %d ", ret);
377                         /*  restore if failed */
378                         list_item->chk_status = !list_item->chk_status;
379                         elm_check_state_set(list_item->eo_check,
380                                             list_item->chk_status);
381                 }
382         }
383 }
384
385 static void
386 setting_phone_noti_3rd_apps_mouse_up_Gendial_list_cb(void *data,
387                                                      Evas_Object *obj,
388                                                      void *event_info)
389 {
390         /* error check */
391         setting_retm_if(data == NULL, "Data parameter is NULL");
392
393         retm_if(event_info == NULL, "Invalid argument: event info is NULL");
394         Elm_Object_Item *item = (Elm_Object_Item *) event_info;
395
396         elm_genlist_item_selected_set(item, 0);
397         Setting_GenGroupItem_Data *list_item =
398             (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
399
400         int old_status = elm_check_state_get(list_item->eo_check);
401         /* new status */
402         list_item->chk_status = !old_status;
403         elm_check_state_set(list_item->eo_check, list_item->chk_status);
404 }
405
406 static void get_3rd_applist(void *data, Evas_Object *scroller)
407 {
408         SettingPhoneUG *ad = (SettingPhoneUG *) data;
409
410         keylist_t *kl = NULL;
411         keynode_t *temp_node = NULL;
412
413         kl = vconf_keylist_new();
414
415         int i = 0;
416         while ((temp_node = vconf_keylist_nextnode(kl))) {
417                 /*  draw a node */
418                 if (VCONF_TYPE_INT == vconf_keynode_get_type(temp_node)) {
419                         SETTING_TRACE("key = %s, value = %d",
420                                       vconf_keynode_get_name(temp_node),
421                                       vconf_keynode_get_int(temp_node));
422                         /*  draw control */
423                         int val = vconf_keynode_get_int(temp_node);
424
425                         /*  get applist */
426                         char *vconf_key = vconf_keynode_get_name(temp_node);    /*  key */
427
428                         /*  get app name with app_pkg_name and AIL */
429                         /*  parsing */
430                         char *app_name = get_appname(vconf_key);
431                         if (!app_name) {
432                                 app_name = strdup("UNTITLED");
433                         }
434
435                         i++;
436                         if (i == 1) {
437                                 Elm_Object_Item *item = NULL;
438                                 item = elm_genlist_item_append(scroller, &(ad->itc_seperator), NULL, NULL,
439                                                     ELM_GENLIST_ITEM_NONE, NULL, NULL);
440                                 setting_retm_if(item == NULL, "elm_genlist_item_append failed");
441                                 elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
442                         }
443
444                         /*  get app name */
445                         Setting_GenGroupItem_Data *obj =
446                             setting_create_Gendial_field_def(scroller,
447                                                              &(ad->
448                                                                itc_1text_1icon),
449                                                              setting_phone_noti_3rd_apps_mouse_up_Gendial_list_cb,
450                                                              ad,
451                                                              SWALLOW_Type_1TOGGLE,
452                                                              NULL, NULL,
453                                                              val, app_name,
454                                                              NULL,
455                                                              setting_phone_noti_3rd_apps_chk_btn_cb);
456                         if (obj) {
457                                 obj->sub_desc = (char *)g_strdup(vconf_key);
458                                 ad->app_list = eina_list_append(ad->app_list, obj);     /*  resources are freed at itc structure. */
459                         } else {
460                                 SETTING_TRACE_ERROR("obj is NULL");
461                         }
462
463                         if (app_name) {
464                                 free(app_name);
465                                 app_name = NULL;
466                         }
467
468                 } else {
469                         SETTING_TRACE("Unknown Type\n");
470                 }
471         }
472         vconf_keylist_free(kl);
473 }
474
475 /*  utility*/
476 static char *strrstr(const char *str, const char *strSearch)
477 {
478         char *ptr, *last = NULL;
479         ptr = (char *)str;
480         while ((ptr = strstr(ptr, strSearch)))
481                 last = ptr++;
482         return last;
483 }
484
485
486 static char* package_get_name(char* package, int* err_ref)
487 {
488     ail_appinfo_h handle;
489     ail_error_e ret;
490
491     char *str = NULL;
492     char *ret_str = NULL;
493
494         int err = -1;
495
496     ret = ail_package_get_appinfo(package, &handle);
497     if (ret != AIL_ERROR_OK) {
498         err =  AIL_ERROR_FAIL;
499     }   
500
501     ret = ail_appinfo_get_str(handle, AIL_PROP_NAME_STR, &str);
502     if (ret != AIL_ERROR_OK) {
503         err =  AIL_ERROR_FAIL;
504     }   
505
506         if (str) {
507                 ret_str = strdup(str);
508         } else {
509                 SETTING_TRACE_ERROR("str is NULL");
510         }
511     SETTING_TRACE("1 Package[%s] : %s", package, ret_str);
512
513     ret = ail_package_destroy_appinfo(handle);
514     if (ret != AIL_ERROR_OK) {
515         err =  AIL_ERROR_FAIL;
516     }   
517
518         *err_ref = err;
519     SETTING_TRACE("2 Package[%s] : %s", package, ret_str);
520         return ret_str;
521 }
522
523
524 /*  input : package name*/
525
526 /*  outout : app name*/
527 static char *get_appname(char *keyname)
528 {
529         int err = -1;
530
531         char* pkg_name = strrstr(keyname, "/");
532         pkg_name++;
533         char *ret2 = package_get_name(pkg_name, &err);
534
535         if (ret2) {
536                 SETTING_TRACE("app name : %s", ret2);
537                 return ret2;
538         } else {
539                 return strdup("UNTITLED");
540         }
541 }
542