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