tizen 2.3 release
[apps/home/b2-clocksetting.git] / src / setting-double.c
1 /*
2  * Copyright (c) 2010 Samsung Electronics, Inc.
3  * All rights reserved.
4  *
5  * This software is a confidential and proprietary information
6  * of Samsung Electronics, Inc. ("Confidential Information").  You
7  * shall not disclose such Confidential Information and shall use
8  * it only in accordance with the terms of the license agreement
9  * you entered into with Samsung Electronics.
10  */
11 /*
12  * setting-double.c
13  *
14  *  Created on: Jan 8, 2014
15  *      Author: Sunyeop Hwang
16  */
17 #include <unicode/ustring.h>
18 #include <unicode/ucol.h>
19 #include <package-manager.h>
20 #include <pkgmgr-info.h>
21
22 #include "setting-double.h"
23 #include "setting_data_vconf.h"
24 #include "util.h"
25
26 static Evas_Object *g_double_genlist = NULL;
27 static Evas_Object *g_double_app_genlist = NULL;
28 static Eina_List *app_list = NULL;
29 static int list_index = 1;
30 struct _double_menu_item *pitem_none = NULL;
31 struct _double_menu_item *pitem_recent = NULL;
32 //pkgmgr_client *pc = NULL;
33 //pkgmgr_client *pc2 = NULL;
34 static UCollator *coll = NULL;
35
36 static struct _double_menu_item *_get_selected_app()
37 {
38         struct _double_menu_item *pitem = NULL;
39         char *appid = NULL;
40         char *p = NULL;
41
42         appid = vconf_get_str(VCONFKEY_WMS_POWERKEY_DOUBLE_PRESSING);
43
44         if (appid && strlen(appid)) {
45                 if (!strcmp(appid, "none")) {
46                         return pitem_none;
47                 } else if (!strcmp(appid, "recent")) {
48                         return pitem_recent;
49                 } else {
50                         Eina_List *list = NULL;
51                         EINA_LIST_FOREACH(app_list, list, pitem) {
52                                 if (pitem->pkgid && pitem->appid) {
53                                         char buf[1024] = {0, };
54                                         snprintf(buf, sizeof(buf) - 1, "%s/%s", pitem->pkgid, pitem->appid);
55                                         if (!strcmp(appid, buf)) {
56                                                 DBG("pkgid/appid for double power key is %s/%s", pitem->pkgid, pitem->appid);
57                                                 return pitem;
58                                         }
59                                 }
60                         }
61                 }
62         }
63
64         return NULL;
65 }
66
67 static int _sort_app_list_cb(const void *d1, const void *d2)
68 {
69         UChar app1[128] = { 0, };
70         UChar app2[128] = { 0, };
71
72         struct _double_menu_item *r1 = (struct _double_menu_item *) d1;
73         struct _double_menu_item *r2 = (struct _double_menu_item *) d2;
74
75         u_uastrcpy(app1, r1->name);
76         u_uastrcpy(app2, r2->name);
77
78         //DBG("before ucol_open");
79         //UErrorCode status = U_ZERO_ERROR;
80         //UCollator *coll = ucol_open(getenv("LANG"), &status);
81         UCollationResult ret = ucol_strcoll(coll, app1, -1, app2, -1);
82
83         //ucol_close(coll);
84
85         switch (ret) {
86                 case UCOL_EQUAL:
87                         return 0;
88                 case UCOL_GREATER:
89                         return 1;
90                 case UCOL_LESS:
91                         return -1;
92                 default:
93                         return 0;
94         }
95 }
96
97 static int _app_list_cb(pkgmgrinfo_appinfo_h handle, void *user_data)
98 {
99         appdata *ad = user_data;
100         if (!ad) {
101                 ERR("appdata is null");
102                 return -1;
103         }
104
105         char *appid = NULL;
106         char *name = NULL;
107         char *pkgid = NULL;
108         int ret = 0;
109         pkgmgrinfo_appinfo_h tmp_handle;
110
111         ret = pkgmgrinfo_appinfo_get_appid(handle, &appid);
112
113         if(ret < 0 || !appid) {
114                 ERR("pkgmgrinfo_appinfo_get_appid error");
115                 return -1;
116         } else {
117
118                 ret = pkgmgrinfo_appinfo_get_appinfo(appid, &tmp_handle);
119                 if (ret != PMINFO_R_OK) {
120                         ERR("pkgmgrinfo_appinfo_get_appinfo error");
121                         return -1;
122                 }
123                 ret = pkgmgrinfo_appinfo_get_pkgid(tmp_handle, &pkgid);
124                 if (ret != PMINFO_R_OK) {
125                         ERR("pkgmgrinfo_appinfo_get_pkgid error");
126                         pkgmgrinfo_appinfo_destroy_appinfo(tmp_handle);
127                         return -1;
128                 }
129                 ret = pkgmgrinfo_appinfo_get_label(tmp_handle, &name);
130                 if (ret != PMINFO_R_OK) {
131                         ERR("pkgmgrinfo_appinfo_get_label error");
132                         pkgmgrinfo_appinfo_destroy_appinfo(tmp_handle);
133                         return -1;
134                 }
135
136                 if (strcmp(name, "Call")) {
137                         struct _double_menu_item *pitem = NULL;
138                         pitem = (struct _double_menu_item *)calloc(1, sizeof(struct _double_menu_item));
139                         memset(pitem, 0x0, sizeof(struct _double_menu_item));
140
141                         pitem->index = ++list_index;
142                         pitem->appid = strdup(appid);
143                         pitem->pkgid = strdup(pkgid);
144                         pitem->name = strdup(name);
145
146                         app_list = eina_list_sorted_insert(app_list, _sort_app_list_cb, pitem);
147                 
148                 }
149         }
150
151         pkgmgrinfo_appinfo_destroy_appinfo(tmp_handle);
152         return 0;
153 }
154
155 static void _clear_app_list()
156 {
157         struct _double_menu_item *pitem = NULL;
158         Eina_List *list = NULL;
159
160         EINA_LIST_FOREACH(app_list, list, pitem) {
161                 FREE(pitem->appid);
162                 FREE(pitem->name);
163         }
164         app_list = eina_list_free(app_list);
165         list_index = 1;
166 }
167
168 static void _make_app_list(void* data)
169 {
170         appdata *ad = data;
171         if (!ad) {
172                 ERR("appdata is null");
173                 return;
174         }
175
176         if (app_list) {
177                 _clear_app_list();
178         }
179
180         pkgmgrinfo_appinfo_filter_h handle = NULL;
181
182         if (pkgmgrinfo_appinfo_filter_create(&handle) != PMINFO_R_OK) {
183                 ERR("pkgmgrinfo_appinfo_filter_create error");
184                 return;
185         }
186
187         if (pkgmgrinfo_appinfo_filter_add_bool(handle, PMINFO_APPINFO_PROP_APP_NODISPLAY, 0)
188                         != PMINFO_R_OK) {
189                 ERR("pkgmgrinfo_appinfo_filter_add_bool error");
190                 pkgmgrinfo_appinfo_filter_destroy(handle);
191                 return;
192         }
193
194         if (pkgmgrinfo_appinfo_filter_foreach_appinfo(handle, _app_list_cb, ad)
195                         != PMINFO_R_OK) {
196                 ERR("pkgmgrinfo_appinfo_filter_foreach_appinfo error");
197                 pkgmgrinfo_appinfo_filter_destroy(handle);
198                 return;
199         }
200
201         pkgmgrinfo_appinfo_filter_destroy(handle);
202
203         //app_list = eina_list_sort(app_list, eina_list_count(app_list), _sort_app_list_cb);
204 }
205
206 static void _gl_double_del(void *data, Evas_Object *obj)
207 {
208         Double_Item_Data *id = data;
209         if (id)
210                 free(id);
211 }
212
213 static char *_gl_double_title_get(void *data, Evas_Object *obj, const char *part)
214 {
215         char buf[1024] = {0, };
216
217         if (!strcmp(part, "elm.text.1") || !strcmp(part, "elm.text")) {
218                 snprintf(buf, sizeof(buf)-1, "%s", _("IDS_ST_MBODY_DOUBLE_PRESS_ABB"));
219                 DBG("elm.text.1 : %s", buf);
220         } else if (!strcmp(part, "elm.text.2")) {
221                 struct _double_menu_item *selected_app = _get_selected_app();
222                 if (selected_app) {
223                         snprintf(buf, sizeof(buf)-1, "%s", _(selected_app->name));
224                         DBG("elm.text.2 : %s", buf);
225                 }
226         }
227
228         return strdup(buf);
229 }
230
231 static char *_gl_double_app_title_get(void *data, Evas_Object *obj, const char *part)
232 {
233         Double_Item_Data *id = data;
234
235         if (!strcmp(part, "elm.text")) {
236                 return strdup(_(id->pitem->name));
237         }
238
239         return NULL;
240 }
241
242 static Evas_Object *_gl_double_app_radio_get(void *data, Evas_Object *obj, const char *part)
243 {
244         Evas_Object *radio = NULL;
245         Evas_Object *radio_main = evas_object_data_get(obj, "radio_main");
246         Double_Item_Data *id = data;
247
248         if( !strcmp(part, "elm.icon") )
249         {
250                 radio = elm_radio_add(obj);
251                 elm_object_style_set(radio, "list");
252                 elm_radio_state_value_set(radio, id->pitem->index);
253                 evas_object_size_hint_align_set(radio, EVAS_HINT_FILL, EVAS_HINT_FILL);
254                 evas_object_size_hint_weight_set(radio, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
255                 evas_object_propagate_events_set(radio, EINA_FALSE);
256                 evas_object_repeat_events_set(radio, EINA_TRUE);
257                 elm_radio_group_add(radio, radio_main);
258         }
259
260         return radio;
261 }
262
263 static void _gl_double_app_sel_cb(void *data, Evas_Object *obj, void *event_info)
264 {
265         Elm_Object_Item *item = (Elm_Object_Item *)event_info;
266         elm_genlist_item_selected_set(item, EINA_FALSE);
267         Double_Item_Data *id = (Double_Item_Data *)elm_object_item_data_get(item);
268
269         appdata *ad = data;
270
271         if (!ad || !id) {
272                 ERR("appdata or id is null!!");
273                 return;
274         }
275
276         if (id->pitem && id->pitem->index == 0) {
277                 char buf[1024] = {0, };
278                 snprintf(buf, sizeof(buf) - 1, "none");
279                 vconf_set_str(VCONFKEY_WMS_POWERKEY_DOUBLE_PRESSING, buf);
280         } else if (id->pitem && id->pitem->index == 1) {
281                 char buf[1024] = {0, };
282                 snprintf(buf, sizeof(buf) - 1, "recent");
283                 vconf_set_str(VCONFKEY_WMS_POWERKEY_DOUBLE_PRESSING, buf);
284         } else if (id->pitem && id->pitem->appid && strlen(id->pitem->appid)) {
285                 char buf[1024] = {0, };
286                 DBG("%s/%s is selected", id->pitem->pkgid, id->pitem->appid);
287                 snprintf(buf, sizeof(buf) - 1, "%s/%s", id->pitem->pkgid, id->pitem->appid);
288                 vconf_set_str(VCONFKEY_WMS_POWERKEY_DOUBLE_PRESSING, buf);
289         }
290
291         elm_naviframe_item_pop(ad->nf);
292
293         if(!ad->double_rdg) {
294                 evas_object_del(ad->double_rdg);
295                 ad->double_rdg = NULL;
296         }
297 }
298
299 static void change_double_pressing_cb(keynode_t *key, void * data)
300 {
301         appdata *ad = data;
302
303         if (!ad) {
304                 ERR("appdata is null!!");
305                 return;
306         }
307         if (g_double_app_genlist) {
308                 struct _double_menu_item *selected_app = NULL;
309                 selected_app = _get_selected_app();
310                 if (selected_app) {
311                         elm_radio_value_set(ad->double_rdg, selected_app->index);
312                 } else {
313                         elm_radio_value_set(ad->double_rdg, -1);
314                 }
315
316                 Elm_Object_Item *item = NULL;
317                 item = elm_genlist_first_item_get(g_double_app_genlist);
318
319                 while (item) {
320                         Double_Item_Data *id = (Double_Item_Data *)elm_object_item_data_get(item);
321                         if (id->pitem == selected_app) {
322                                 elm_genlist_item_show(item, ELM_GENLIST_ITEM_SCROLLTO_TOP);
323                                 break;
324                         }
325                         item = elm_genlist_item_next_get(item);
326                 }
327         }
328
329         if (g_double_genlist) {
330                 elm_genlist_realized_items_update(g_double_genlist);
331         }
332 }
333
334 static void update_double_app_list(void *data)
335 {
336         appdata *ad = data;
337
338         if (!ad) {
339                 ERR("appdata is null!!");
340                 return;
341         }
342
343         _make_app_list(ad);
344
345         if (g_double_genlist) {
346                 elm_genlist_realized_items_update(g_double_genlist);
347         }
348
349         if (g_double_app_genlist) {
350                 struct _double_menu_item *selected_app = NULL;
351                 struct _double_menu_item *pitem = NULL;
352                 Eina_List *list = NULL;
353                 Elm_Object_Item *sel_it = NULL;
354
355                 elm_genlist_clear(g_double_app_genlist);
356
357                 Elm_Genlist_Item_Class *itc = elm_genlist_item_class_new();
358                 itc->item_style = "1text.1icon.1";
359                 itc->func.text_get = _gl_double_app_title_get;
360                 itc->func.content_get = _gl_double_app_radio_get;
361                 itc->func.del = _gl_double_del;
362
363                 selected_app = _get_selected_app();
364
365                 Double_Item_Data *id_none = calloc(sizeof(Double_Item_Data), 1);
366                 id_none->pitem = pitem_none;
367                 id_none->item = elm_genlist_item_append(g_double_app_genlist, itc, id_none, NULL,
368                                 ELM_GENLIST_ITEM_NONE,
369                                 _gl_double_app_sel_cb, ad);
370
371                 if (id_none->pitem == selected_app) {
372                         sel_it = id_none->item;
373                 }
374
375                 Double_Item_Data *id_recent = calloc(sizeof(Double_Item_Data), 1);
376                 id_recent->pitem = pitem_recent;
377                 id_recent->item = elm_genlist_item_append(g_double_app_genlist, itc, id_recent, NULL,
378                                 ELM_GENLIST_ITEM_NONE,
379                                 _gl_double_app_sel_cb, ad);
380
381                 if (id_recent->pitem == selected_app) {
382                         sel_it = id_recent->item;
383                 }
384
385                 EINA_LIST_FOREACH(app_list, list, pitem) {
386                         Double_Item_Data *id = calloc(sizeof(Double_Item_Data), 1);
387                         id->pitem = pitem;
388                         id->item = elm_genlist_item_append(g_double_app_genlist, itc, id, NULL,
389                                         ELM_GENLIST_ITEM_NONE,
390                                         _gl_double_app_sel_cb, ad);
391
392                         if (id->pitem == selected_app) {
393                                 sel_it = id->item;
394                         }
395                 }
396
397                 if (selected_app) {
398                         elm_radio_value_set(ad->double_rdg, selected_app->index);
399                 } else {
400                         elm_radio_value_set(ad->double_rdg, -1);
401                 }
402
403                 elm_genlist_item_show(sel_it, ELM_GENLIST_ITEM_SCROLLTO_TOP);
404
405                 elm_genlist_item_class_free(itc);
406         }
407
408 }
409
410 static void change_language_cb(keynode_t *key, void * data)
411 {
412         appdata *ad = data;
413
414         if (!ad) {
415                 ERR("appdata is null!!");
416                 return;
417         }
418
419         UErrorCode status = U_ZERO_ERROR;
420         if (coll) {
421                 ucol_close(coll);
422                 coll = NULL;
423         }
424         const char *lang = vconf_get_str(VCONFKEY_LANGSET);
425         coll = ucol_open(lang, &status);
426         
427         update_double_app_list(ad);
428 }
429
430 static int _double_press_check_appinfo(void *data, char *appid)
431 {
432         appdata *ad = data;
433
434         if (!ad) {
435                 ERR("appdata is null!!");
436                 return -1;
437         }
438         int r;
439         pkgmgrinfo_appinfo_h tmp_handle;
440         int nodisplay = 0;
441
442         DBG("appid:%s", appid);
443         r = pkgmgrinfo_appinfo_get_appinfo(appid, &tmp_handle);
444         if (r != PMINFO_R_OK) {
445                 ERR("pkgmgrinfo_appinfo_get_appinfo error : %d", r);
446                 return -1;
447         }
448
449         r = pkgmgrinfo_appinfo_is_nodisplay(tmp_handle, &nodisplay);
450         if (r != PMINFO_R_OK) {
451                 ERR("pkgmgrinfo_appinfo_is_nodisplay error");
452                 return -1;
453         }
454
455         if (!nodisplay) {
456                 update_double_app_list(ad);
457         }
458
459         return 0;
460 }
461
462 static void change_app_state_cb(keynode_t *key, void * data)
463 {
464         appdata *ad = data;
465
466         if (!ad) {
467                 ERR("appdata is null!!");
468                 return;
469         }
470
471         char appid[256] = {0, };
472         char type[7] = {0, };
473         char *value = NULL;
474         char *p = NULL;
475
476         value = vconf_get_str(VCONFKEY_AIL_INFO_STATE);
477         
478         if (value) {
479                 strcpy(appid, value + 7);
480                 strncpy(type, value, 6);
481                 DBG("type :%s, appid :%s", type, appid);
482
483                 if (!strncmp(type, "delete", 6)) {
484                         update_double_app_list(ad);
485                 } else if (!strncmp(type, "create", 6) || !strncmp(type, "update", 6)) {
486                         _double_press_check_appinfo(ad, appid);
487                 }
488                 DBG("appid :%s", appid);
489         }
490 }
491
492 void clear_double_app_cb(void *data , Evas *e, Evas_Object *obj, void *event_info)
493 {
494         if (coll) {
495                 ucol_close(coll);
496                 coll = NULL;
497         }
498
499 #if 0
500         if (pc) {
501                 pkgmgr_client_free(pc);
502                 pc = NULL;
503         }
504         if (pc2) {
505                 pkgmgr_client_free(pc2);
506                 pc2 = NULL;
507         }
508 #endif
509
510         FREE(pitem_none);
511         FREE(pitem_recent);
512         g_double_app_genlist = NULL;
513         unregister_vconf_changing(VCONFKEY_WMS_POWERKEY_DOUBLE_PRESSING, change_double_pressing_cb);
514         unregister_vconf_changing(VCONFKEY_LANGSET, change_language_cb);
515         unregister_vconf_changing(VCONFKEY_AIL_INFO_STATE, change_app_state_cb);
516 }
517
518 Evas_Object *create_double_app_list(void *data)
519 {
520         appdata *ad = data;
521
522         if (!ad) {
523                 ERR("appdata is null!!");
524                 return NULL;
525         }
526
527         Evas_Object *layout = NULL;
528         Evas_Object *genlist = NULL;
529         Elm_Object_Item *nf_it = NULL;
530         Elm_Object_Item *sel_it = NULL;
531
532         struct _double_menu_item *selected_app = NULL;
533         struct _double_menu_item *pitem = NULL;
534         Eina_List *list = NULL;
535
536         Elm_Genlist_Item_Class *itc = elm_genlist_item_class_new();
537         itc->item_style = "1text.1icon.1";
538         itc->func.text_get = _gl_double_app_title_get;
539         itc->func.content_get = _gl_double_app_radio_get;
540         itc->func.del = _gl_double_del;
541
542         layout = elm_layout_add(ad->nf);
543         elm_layout_file_set(layout, EDJE_PATH, "setting/genlist/layout");
544         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
545
546         genlist = elm_genlist_add(layout);
547         evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
548
549         selected_app = _get_selected_app();
550
551         Double_Item_Data *id_none = calloc(sizeof(Double_Item_Data), 1);
552         id_none->pitem = pitem_none;
553         id_none->item = elm_genlist_item_append(genlist, itc, id_none, NULL,
554                         ELM_GENLIST_ITEM_NONE,
555                         _gl_double_app_sel_cb, ad);
556
557         if (id_none->pitem == selected_app) {
558                 sel_it = id_none->item;
559         }
560
561         Double_Item_Data *id_recent = calloc(sizeof(Double_Item_Data), 1);
562         id_recent->pitem = pitem_recent;
563         id_recent->item = elm_genlist_item_append(genlist, itc, id_recent, NULL,
564                         ELM_GENLIST_ITEM_NONE,
565                         _gl_double_app_sel_cb, ad);
566
567         if (id_recent->pitem == selected_app) {
568                 sel_it = id_recent->item;
569         }
570
571         EINA_LIST_FOREACH(app_list, list, pitem) {
572                 Double_Item_Data *id = calloc(sizeof(Double_Item_Data), 1);
573                 id->pitem = pitem;
574                 id->item = elm_genlist_item_append(genlist, itc, id, NULL,
575                                 ELM_GENLIST_ITEM_NONE,
576                                 _gl_double_app_sel_cb, ad);
577
578                 if (id->pitem == selected_app) {
579                         sel_it = id->item;
580                 }
581         }
582
583         ad->double_rdg = elm_radio_add(genlist);
584         elm_radio_state_value_set(ad->double_rdg, -1);
585
586         if (selected_app) {
587                 elm_radio_value_set(ad->double_rdg, selected_app->index);
588         } else {
589                 elm_radio_value_set(ad->double_rdg, -1);
590         }
591         evas_object_data_set(genlist, "radio_main", ad->double_rdg);
592
593         elm_genlist_item_show(sel_it, ELM_GENLIST_ITEM_SCROLLTO_TOP);
594
595         g_double_app_genlist = genlist;
596
597         elm_object_part_content_set(layout, "elm.genlist", genlist);
598
599         elm_genlist_item_class_free(itc);
600
601         return layout;
602 }
603
604 static int _double_press_appinfo_cb(pkgmgrinfo_appinfo_h handle, void *data)
605 {
606         appdata *ad = data;
607
608         if (!ad) {
609                 ERR("appdata is null!!");
610                 return -1;
611         }
612         char *appid = NULL;
613         int r;
614         pkgmgrinfo_appinfo_h tmp_handle;
615         int nodisplay = 0;
616
617         r = pkgmgrinfo_appinfo_get_appid(handle, &appid);
618         if(r < 0 || !appid) {
619                 ERR("pkgmgrinfo_appinfo_get_appid error");
620                 return -1;
621         } else {
622                 r = pkgmgrinfo_appinfo_get_appinfo(appid, &tmp_handle);
623                 if (r != PMINFO_R_OK) {
624                         ERR("pkgmgrinfo_appinfo_get_appinfo error");
625                         return -1;
626                 }
627
628                 r = pkgmgrinfo_appinfo_is_nodisplay(tmp_handle, &nodisplay);
629                 if (r != PMINFO_R_OK) {
630                         ERR("pkgmgrinfo_appinfo_is_nodisplay error");
631                         return -1;
632                 }
633         }
634
635         if (!nodisplay) {
636                 update_double_app_list(ad);
637         }
638
639         return 0;
640 }
641
642 static int _double_press_app_event_cb(int req_id, const char *pkg_type, const char *pkgid, 
643                                 const char key, const char *val, const void *pmsg, void *data)
644 {
645         appdata *ad = data;
646
647         if (!ad) {
648                 ERR("appdata is null!!");
649                 return -1;
650         }
651
652         if (!pkgid || !key || !val) {
653                 ERR("pkgid or key or val is null");
654                 return -1;
655         }
656
657         int ret = 0;
658         if (!strncmp(key, "end", 3) && !strncmp(val, "ok", 2)) {
659                 DBG("end install/update for some pkgid");
660
661                 pkgmgrinfo_pkginfo_h handle;
662
663                 ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
664                 if (ret != PMINFO_R_OK)
665                         return -1;
666                 ret = pkgmgrinfo_appinfo_get_list(handle, PMINFO_UI_APP, _double_press_appinfo_cb , data);
667                 if (ret != PMINFO_R_OK) {
668                         pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
669                         return -1;
670                 }
671                 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
672
673         }
674
675 }
676
677 static int _double_press_app_uninstall_event_cb(int req_id, const char *pkg_type, const char *pkgid, 
678                                 const char key, const char *val, const void *pmsg, void *data)
679 {
680         appdata *ad = data;
681
682         if (!ad) {
683                 ERR("appdata is null!!");
684                 return -1;
685         }
686
687         if (!pkgid || !key || !val) {
688                 ERR("pkgid or key or val is null");
689                 return -1;
690         }
691
692         int ret = 0;
693         if (!strncmp(key, "end", 3) && !strncmp(val, "ok", 2)) {
694                 DBG("end uninstall for some pkgid");
695                 update_double_app_list(ad);
696         }
697
698 }
699
700 void init_double_pressing(void *data)
701 {
702         appdata *ad = data;
703
704         if (!ad) {
705                 ERR("appdata is null!!");
706                 return NULL;
707         }
708
709         FREE(pitem_none);
710         pitem_none = calloc(sizeof(struct _double_menu_item), 1);
711
712         if (pitem_none) {
713                 pitem_none->index = 0;
714                 pitem_none->appid = strdup("none");
715                 pitem_none->pkgid = strdup("none");
716                 pitem_none->name = strdup("IDS_LCKSCN_BODY_NONE");
717         }
718
719         FREE(pitem_recent);
720         pitem_recent = calloc(sizeof(struct _double_menu_item), 1);
721
722         if (pitem_recent) {
723                 pitem_recent->index = 1;
724                 pitem_recent->appid = strdup("recent");
725                 pitem_recent->pkgid = strdup("recent");
726                 pitem_recent->name = strdup("IDS_ST_OPT_RECENT_APPS_ABB");
727         }
728
729         UErrorCode status = U_ZERO_ERROR;
730         if (coll) {
731                 ucol_close(coll);
732                 coll = NULL;
733         }
734         const char *lang = vconf_get_str(VCONFKEY_LANGSET);
735         coll = ucol_open(lang, &status);
736
737         int event_type = PMINFO_CLIENT_STATUS_INSTALL | PMINFO_CLIENT_STATUS_UPGRADE;
738
739 #if 0
740         if (pc) {
741                 pkgmgr_client_free(pc);
742                 pc = NULL;
743         }
744
745         if (!ad->pc) {
746                 ad->pc = pkgmgr_client_new(PC_LISTENING);
747                 pkgmgr_client_set_status_type(ad->pc, event_type);
748                 pkgmgr_client_listen_status(ad->pc, _double_press_app_event_cb, ad);
749         }
750
751         int event_type2 = PMINFO_CLIENT_STATUS_UNINSTALL;
752
753         if (pc2) {
754                 pkgmgr_client_free(pc2);
755                 pc2 = NULL;
756
757         if (!ad->pc2) {
758                 ad->pc2 = pkgmgr_client_new(PMINFO_LISTENING);
759                 pkgmgr_client_set_status_type(ad->pc2, event_type2);
760                 pkgmgr_client_listen_status(ad->pc2, _double_press_app_uninstall_event_cb, ad);
761         }
762 #endif
763
764         _make_app_list(ad);
765
766         register_vconf_changing(VCONFKEY_WMS_POWERKEY_DOUBLE_PRESSING, change_double_pressing_cb, ad);
767         register_vconf_changing(VCONFKEY_LANGSET, change_language_cb, ad);
768         register_vconf_changing(VCONFKEY_AIL_INFO_STATE, change_app_state_cb, ad);
769 }
770
771 Evas_Object *create_double_list(void *data)
772 {
773         appdata *ad = data;
774
775         if (!ad) {
776                 ERR("appdata is null!!");
777                 return NULL;
778         }
779
780         Evas_Object *genlist = NULL;
781         Evas_Object *layout = NULL;
782         int idx = 0;
783
784         Elm_Genlist_Item_Class *itc = elm_genlist_item_class_new();
785         itc->item_style = "2text";
786         itc->func.text_get = _gl_double_title_get;
787
788         layout = elm_layout_add(ad->nf);
789         elm_layout_file_set(layout, EDJE_PATH, "setting/genlist/layout");
790         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
791
792         genlist = elm_genlist_add(layout);
793         elm_genlist_block_count_set(genlist, 14);
794         elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
795         evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
796
797         //elm_genlist_item_append(genlist, itc, NULL, NULL,
798         //              ELM_GENLIST_ITEM_NONE, _double_app_list_cb, ad);
799
800         elm_genlist_item_class_free(itc);
801
802         g_double_genlist = genlist;
803
804         elm_object_part_content_set(layout, "elm.genlist", genlist);
805
806         return layout;
807 }
808
809 void clear_double_cb(void *data , Evas *e, Evas_Object *obj, void *event_info)
810 {
811         FREE(pitem_none);
812         FREE(pitem_recent);
813         g_double_genlist = NULL;
814         g_double_app_genlist = NULL;
815         unregister_vconf_changing(VCONFKEY_WMS_POWERKEY_DOUBLE_PRESSING, change_double_pressing_cb);
816         unregister_vconf_changing(VCONFKEY_LANGSET, change_language_cb);
817         unregister_vconf_changing(VCONFKEY_AIL_INFO_STATE, change_app_state_cb);
818 }
819