Tizen 2.4 SDK Rev5
[apps/home/b2-clocksetting.git] / src / setting-double.c
1 /*
2  *  Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
4  *  Licensed under the Flora License, Version 1.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://floralicense.org/license/
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                         if (pitem) {
146                                 memset(pitem, 0x0, sizeof(struct _double_menu_item));
147
148                                 pitem->index = ++list_index;
149                                 pitem->appid = strdup(appid);
150                                 pitem->pkgid = strdup(pkgid);
151                                 pitem->name = strdup(name);
152
153                                 app_list = eina_list_sorted_insert(app_list, _sort_app_list_cb, pitem);
154                         }
155                 }
156         }
157
158         pkgmgrinfo_appinfo_destroy_appinfo(tmp_handle);
159         return 0;
160 }
161
162 static void _clear_app_list()
163 {
164         struct _double_menu_item *pitem = NULL;
165         Eina_List *list = NULL;
166
167         EINA_LIST_FOREACH(app_list, list, pitem) {
168                 FREE(pitem->appid);
169                 FREE(pitem->name);
170         }
171         app_list = eina_list_free(app_list);
172         list_index = 1;
173 }
174
175 static void _make_app_list(void *data)
176 {
177         appdata *ad = data;
178         if (!ad) {
179                 ERR("appdata is null");
180                 return;
181         }
182
183         if (app_list) {
184                 _clear_app_list();
185         }
186
187         pkgmgrinfo_appinfo_filter_h handle = NULL;
188
189         if (pkgmgrinfo_appinfo_filter_create(&handle) != PMINFO_R_OK) {
190                 ERR("pkgmgrinfo_appinfo_filter_create error");
191                 return;
192         }
193
194         if (pkgmgrinfo_appinfo_filter_add_bool(handle, PMINFO_APPINFO_PROP_APP_NODISPLAY, 0)
195                 != PMINFO_R_OK) {
196                 ERR("pkgmgrinfo_appinfo_filter_add_bool error");
197                 pkgmgrinfo_appinfo_filter_destroy(handle);
198                 return;
199         }
200
201         if (pkgmgrinfo_appinfo_filter_foreach_appinfo(handle, _app_list_cb, ad)
202                 != PMINFO_R_OK) {
203                 ERR("pkgmgrinfo_appinfo_filter_foreach_appinfo error");
204                 pkgmgrinfo_appinfo_filter_destroy(handle);
205                 return;
206         }
207
208         pkgmgrinfo_appinfo_filter_destroy(handle);
209
210         /*app_list = eina_list_sort(app_list, eina_list_count(app_list), _sort_app_list_cb); */
211 }
212
213 static void _gl_double_del(void *data, Evas_Object *obj)
214 {
215         Double_Item_Data *id = data;
216         if (id)
217                 free(id);
218 }
219
220 static char *_gl_double_title_get(void *data, Evas_Object *obj, const char *part)
221 {
222         char buf[1024] = {0, };
223
224         if (!strcmp(part, "elm.text.1") || !strcmp(part, "elm.text")) {
225                 snprintf(buf, sizeof(buf) - 1, "%s", _("IDS_ST_MBODY_DOUBLE_PRESS_ABB"));
226                 DBG("elm.text.1 : %s", buf);
227         } else if (!strcmp(part, "elm.text.2")) {
228                 struct _double_menu_item *selected_app = _get_selected_app();
229                 if (selected_app) {
230                         snprintf(buf, sizeof(buf) - 1, "%s", _(selected_app->name));
231                         DBG("elm.text.2 : %s", buf);
232                 }
233         }
234
235         return strdup(buf);
236 }
237
238 static char *_gl_double_app_title_get(void *data, Evas_Object *obj, const char *part)
239 {
240         Double_Item_Data *id = data;
241
242         if (!strcmp(part, "elm.text")) {
243                 return strdup(_(id->pitem->name));
244         }
245
246         return NULL;
247 }
248
249 static Evas_Object *_gl_double_app_radio_get(void *data, Evas_Object *obj, const char *part)
250 {
251         Evas_Object *radio = NULL;
252         Evas_Object *radio_main = evas_object_data_get(obj, "radio_main");
253         Double_Item_Data *id = data;
254
255         if (!strcmp(part, "elm.icon")) {
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                 if (id_none) {
373                         id_none->pitem = pitem_none;
374                         id_none->item = elm_genlist_item_append(g_double_app_genlist, itc, id_none, NULL,
375                                                                                                         ELM_GENLIST_ITEM_NONE,
376                                                                                                         _gl_double_app_sel_cb, ad);
377
378                         if (id_none->pitem == selected_app) {
379                                 sel_it = id_none->item;
380                         }
381                 }
382
383                 Double_Item_Data *id_recent = calloc(sizeof(Double_Item_Data), 1);
384                 if (id_recent) {
385                         id_recent->pitem = pitem_recent;
386                         id_recent->item = elm_genlist_item_append(g_double_app_genlist, itc, id_recent, NULL,
387                                                                                                           ELM_GENLIST_ITEM_NONE,
388                                                                                                           _gl_double_app_sel_cb, ad);
389
390                         if (id_recent->pitem == selected_app) {
391                                 sel_it = id_recent->item;
392                         }
393                 }
394
395                 EINA_LIST_FOREACH(app_list, list, pitem) {
396                         Double_Item_Data *id = calloc(sizeof(Double_Item_Data), 1);
397                         if (id) {
398                                 id->pitem = pitem;
399                                 id->item = elm_genlist_item_append(g_double_app_genlist, itc, id, NULL,
400                                                                                                    ELM_GENLIST_ITEM_NONE,
401                                                                                                    _gl_double_app_sel_cb, ad);
402
403                                 if (id->pitem == selected_app) {
404                                         sel_it = id->item;
405                                 }
406                         }
407                 }
408
409                 if (selected_app) {
410                         elm_radio_value_set(ad->double_rdg, selected_app->index);
411                 } else {
412                         elm_radio_value_set(ad->double_rdg, -1);
413                 }
414
415                 elm_genlist_item_show(sel_it, ELM_GENLIST_ITEM_SCROLLTO_TOP);
416
417                 elm_genlist_item_class_free(itc);
418         }
419
420 }
421
422 static void change_language_cb(keynode_t *key, void *data)
423 {
424         appdata *ad = data;
425
426         if (!ad) {
427                 ERR("appdata is null!!");
428                 return;
429         }
430
431         UErrorCode status = U_ZERO_ERROR;
432         if (coll) {
433                 ucol_close(coll);
434                 coll = NULL;
435         }
436         const char *lang = vconf_get_str(VCONFKEY_LANGSET);
437         coll = ucol_open(lang, &status);
438
439         update_double_app_list(ad);
440 }
441
442 static int _double_press_check_appinfo(void *data, char *appid)
443 {
444         appdata *ad = data;
445
446         if (!ad) {
447                 ERR("appdata is null!!");
448                 return -1;
449         }
450         int r;
451         pkgmgrinfo_appinfo_h tmp_handle;
452         int nodisplay = 0;
453
454         DBG("appid:%s", appid);
455         r = pkgmgrinfo_appinfo_get_appinfo(appid, &tmp_handle);
456         if (r != PMINFO_R_OK) {
457                 ERR("pkgmgrinfo_appinfo_get_appinfo error : %d", r);
458                 return -1;
459         }
460
461         r = pkgmgrinfo_appinfo_is_nodisplay(tmp_handle, &nodisplay);
462         if (r != PMINFO_R_OK) {
463                 ERR("pkgmgrinfo_appinfo_is_nodisplay error");
464                 return -1;
465         }
466
467         if (!nodisplay) {
468                 update_double_app_list(ad);
469         }
470
471         return 0;
472 }
473
474 static void change_app_state_cb(keynode_t *key, void *data)
475 {
476         appdata *ad = data;
477
478         if (!ad) {
479                 ERR("appdata is null!!");
480                 return;
481         }
482
483         char appid[256] = {0, };
484         char type[7] = {0, };
485         char *value = NULL;
486         char *p = NULL;
487
488         value = vconf_get_str(VCONFKEY_AIL_INFO_STATE);
489
490         if (value && (strlen(value + 7) < 256)) {
491                 strcpy(appid, value + 7);
492                 strncpy(type, value, 6);
493                 DBG("type :%s, appid :%s", type, appid);
494
495                 if (!strncmp(type, "delete", 6)) {
496                         update_double_app_list(ad);
497                 } else if (!strncmp(type, "create", 6) || !strncmp(type, "update", 6)) {
498                         _double_press_check_appinfo(ad, appid);
499                 }
500                 DBG("appid :%s", appid);
501         }
502 }
503
504 void clear_double_app_cb(void *data , Evas *e, Evas_Object *obj, void *event_info)
505 {
506         if (coll) {
507                 ucol_close(coll);
508                 coll = NULL;
509         }
510
511 #if 0
512         if (pc) {
513                 pkgmgr_client_free(pc);
514                 pc = NULL;
515         }
516         if (pc2) {
517                 pkgmgr_client_free(pc2);
518                 pc2 = NULL;
519         }
520 #endif
521
522         FREE(pitem_none);
523         FREE(pitem_recent);
524         g_double_app_genlist = NULL;
525         unregister_vconf_changing(VCONFKEY_WMS_POWERKEY_DOUBLE_PRESSING, change_double_pressing_cb);
526         unregister_vconf_changing(VCONFKEY_LANGSET, change_language_cb);
527         unregister_vconf_changing(VCONFKEY_AIL_INFO_STATE, change_app_state_cb);
528 }
529
530 #ifdef O_TYPE
531 static char *
532 _gl_menu_title_text_get(void *data, Evas_Object *obj, const char *part)
533 {
534         char buf[1024];
535
536         snprintf(buf, 1023, "%s", _("IDS_ST_MBODY_DOUBLE_PRESS_ABB"));
537         return strdup(buf);
538 }
539 #endif
540 Evas_Object *create_double_app_list(void *data)
541 {
542         appdata *ad = data;
543
544         if (!ad) {
545                 ERR("appdata is null!!");
546                 return NULL;
547         }
548
549         Evas_Object *layout = NULL;
550         Evas_Object *genlist = NULL;
551         Elm_Object_Item *nf_it = NULL;
552         Elm_Object_Item *sel_it = NULL;
553
554         struct _double_menu_item *selected_app = NULL;
555         struct _double_menu_item *pitem = NULL;
556         Eina_List *list = NULL;
557
558         Elm_Genlist_Item_Class *itc = elm_genlist_item_class_new();
559         itc->item_style = "1text.1icon.1";
560         itc->func.text_get = _gl_double_app_title_get;
561         itc->func.content_get = _gl_double_app_radio_get;
562         itc->func.del = _gl_double_del;
563
564         layout = elm_layout_add(ad->nf);
565         elm_layout_file_set(layout, EDJE_PATH, "setting/genlist/layout");
566         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
567
568         genlist = elm_genlist_add(layout);
569         evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
570
571         selected_app = _get_selected_app();
572
573 #ifdef _CIRCLE
574         Elm_Genlist_Item_Class *title_item = elm_genlist_item_class_new();
575         title_item ->func.text_get = _gl_menu_title_text_get;
576         title_item->item_style = "title";
577         title_item->func.del = _gl_double_del;
578
579         elm_genlist_item_append(genlist, title_item, NULL, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
580
581         elm_genlist_item_class_free(title_item);
582 #endif
583         Double_Item_Data *id_none = calloc(sizeof(Double_Item_Data), 1);
584         if (id_none) {
585                 id_none->pitem = pitem_none;
586                 id_none->item = elm_genlist_item_append(genlist, itc, id_none, NULL,
587                                                                                                 ELM_GENLIST_ITEM_NONE,
588                                                                                                 _gl_double_app_sel_cb, ad);
589
590                 if (id_none->pitem == selected_app) {
591                         sel_it = id_none->item;
592                 }
593         }
594
595         Double_Item_Data *id_recent = calloc(sizeof(Double_Item_Data), 1);
596         if (id_recent) {
597                 id_recent->pitem = pitem_recent;
598                 id_recent->item = elm_genlist_item_append(genlist, itc, id_recent, NULL,
599                                                                                                   ELM_GENLIST_ITEM_NONE,
600                                                                                                   _gl_double_app_sel_cb, ad);
601
602                 if (id_recent->pitem == selected_app) {
603                         sel_it = id_recent->item;
604                 }
605         }
606
607         EINA_LIST_FOREACH(app_list, list, pitem) {
608                 Double_Item_Data *id = calloc(sizeof(Double_Item_Data), 1);
609                 if (id) {
610                         id->pitem = pitem;
611                         id->item = elm_genlist_item_append(genlist, itc, id, NULL,
612                                                                                            ELM_GENLIST_ITEM_NONE,
613                                                                                            _gl_double_app_sel_cb, ad);
614
615                         if (id->pitem == selected_app) {
616                                 sel_it = id->item;
617                         }
618                 }
619         }
620
621         ad->double_rdg = elm_radio_add(genlist);
622         elm_radio_state_value_set(ad->double_rdg, -1);
623
624         if (selected_app) {
625                 elm_radio_value_set(ad->double_rdg, selected_app->index);
626         } else {
627                 elm_radio_value_set(ad->double_rdg, -1);
628         }
629         evas_object_data_set(genlist, "radio_main", ad->double_rdg);
630
631         elm_genlist_item_show(sel_it, ELM_GENLIST_ITEM_SCROLLTO_TOP);
632
633         g_double_app_genlist = genlist;
634
635         elm_object_part_content_set(layout, "elm.genlist", genlist);
636
637 #ifdef _CIRCLE
638         Elm_Genlist_Item_Class *padding = elm_genlist_item_class_new();
639         padding->item_style = "padding";
640         padding->func.del = _gl_double_del;
641
642         elm_genlist_item_append(genlist, padding, NULL, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
643         elm_genlist_item_class_free(padding);
644 #endif
645         elm_genlist_item_class_free(itc);
646
647         return layout;
648 }
649
650 static int _double_press_appinfo_cb(pkgmgrinfo_appinfo_h handle, void *data)
651 {
652         appdata *ad = data;
653
654         if (!ad) {
655                 ERR("appdata is null!!");
656                 return -1;
657         }
658         char *appid = NULL;
659         int r;
660         pkgmgrinfo_appinfo_h tmp_handle;
661         int nodisplay = 0;
662
663         r = pkgmgrinfo_appinfo_get_appid(handle, &appid);
664         if (r < 0 || !appid) {
665                 ERR("pkgmgrinfo_appinfo_get_appid error");
666                 return -1;
667         } else {
668                 r = pkgmgrinfo_appinfo_get_appinfo(appid, &tmp_handle);
669                 if (r != PMINFO_R_OK) {
670                         ERR("pkgmgrinfo_appinfo_get_appinfo error");
671                         return -1;
672                 }
673
674                 r = pkgmgrinfo_appinfo_is_nodisplay(tmp_handle, &nodisplay);
675                 if (r != PMINFO_R_OK) {
676                         ERR("pkgmgrinfo_appinfo_is_nodisplay error");
677                         return -1;
678                 }
679         }
680
681         if (!nodisplay) {
682                 update_double_app_list(ad);
683         }
684
685         return 0;
686 }
687
688 static int _double_press_app_event_cb(int req_id, const char *pkg_type, const char *pkgid,
689                                                                           const char key, const char *val, const void *pmsg, void *data)
690 {
691         appdata *ad = data;
692
693         if (!ad) {
694                 ERR("appdata is null!!");
695                 return -1;
696         }
697
698         if (!pkgid || !key || !val) {
699                 ERR("pkgid or key or val is null");
700                 return -1;
701         }
702
703         int ret = 0;
704         if (!strncmp(key, "end", 3) && !strncmp(val, "ok", 2)) {
705                 DBG("end install/update for some pkgid");
706
707                 pkgmgrinfo_pkginfo_h handle;
708
709                 ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
710                 if (ret != PMINFO_R_OK)
711                         return -1;
712                 ret = pkgmgrinfo_appinfo_get_list(handle, PMINFO_UI_APP, _double_press_appinfo_cb , data);
713                 if (ret != PMINFO_R_OK) {
714                         pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
715                         return -1;
716                 }
717                 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
718
719         }
720         return 0;
721 }
722
723 static int _double_press_app_uninstall_event_cb(int req_id, const char *pkg_type, const char *pkgid,
724                                                                                                 const char key, const char *val, const void *pmsg, void *data)
725 {
726         appdata *ad = data;
727
728         if (!ad) {
729                 ERR("appdata is null!!");
730                 return -1;
731         }
732
733         if (!pkgid || !key || !val) {
734                 ERR("pkgid or key or val is null");
735                 return -1;
736         }
737
738         int ret = 0;
739         if (!strncmp(key, "end", 3) && !strncmp(val, "ok", 2)) {
740                 DBG("end uninstall for some pkgid");
741                 update_double_app_list(ad);
742         }
743         return 0;
744 }
745
746 void init_double_pressing(void *data)
747 {
748         appdata *ad = data;
749
750         if (!ad) {
751                 ERR("appdata is null!!");
752                 return NULL;
753         }
754
755         FREE(pitem_none);
756         pitem_none = calloc(sizeof(struct _double_menu_item), 1);
757
758         if (pitem_none) {
759                 pitem_none->index = 0;
760                 pitem_none->appid = strdup("none");
761                 pitem_none->pkgid = strdup("none");
762                 pitem_none->name = strdup("IDS_LCKSCN_BODY_NONE");
763         }
764
765         FREE(pitem_recent);
766         pitem_recent = calloc(sizeof(struct _double_menu_item), 1);
767
768         if (pitem_recent) {
769                 pitem_recent->index = 1;
770                 pitem_recent->appid = strdup("recent");
771                 pitem_recent->pkgid = strdup("recent");
772                 pitem_recent->name = strdup("IDS_ST_OPT_RECENT_APPS_ABB");
773         }
774
775         UErrorCode status = U_ZERO_ERROR;
776         if (coll) {
777                 ucol_close(coll);
778                 coll = NULL;
779         }
780         const char *lang = vconf_get_str(VCONFKEY_LANGSET);
781         coll = ucol_open(lang, &status);
782
783         int event_type = PMINFO_CLIENT_STATUS_INSTALL | PMINFO_CLIENT_STATUS_UPGRADE;
784
785 #if 0
786         if (pc) {
787                 pkgmgr_client_free(pc);
788                 pc = NULL;
789         }
790
791         if (!ad->pc) {
792                 ad->pc = pkgmgr_client_new(PC_LISTENING);
793                 pkgmgr_client_set_status_type(ad->pc, event_type);
794                 pkgmgr_client_listen_status(ad->pc, _double_press_app_event_cb, ad);
795         }
796
797         int event_type2 = PMINFO_CLIENT_STATUS_UNINSTALL;
798
799         if (pc2) {
800                 pkgmgr_client_free(pc2);
801                 pc2 = NULL;
802
803                 if (!ad->pc2) {
804                         ad->pc2 = pkgmgr_client_new(PMINFO_LISTENING);
805                         pkgmgr_client_set_status_type(ad->pc2, event_type2);
806                         pkgmgr_client_listen_status(ad->pc2, _double_press_app_uninstall_event_cb, ad);
807                 }
808         }
809 #endif
810
811         _make_app_list(ad);
812
813         register_vconf_changing(VCONFKEY_WMS_POWERKEY_DOUBLE_PRESSING, change_double_pressing_cb, ad);
814         register_vconf_changing(VCONFKEY_LANGSET, change_language_cb, ad);
815         register_vconf_changing(VCONFKEY_AIL_INFO_STATE, change_app_state_cb, ad);
816 }
817
818 Evas_Object *create_double_list(void * data)
819 {
820         appdata *ad = data;
821
822         if (!ad) {
823                 ERR("appdata is null!!");
824                 return NULL;
825         }
826
827         Evas_Object *genlist = NULL;
828         Evas_Object *layout = NULL;
829         int idx = 0;
830
831         Elm_Genlist_Item_Class *itc = elm_genlist_item_class_new();
832         itc->item_style = "2text";
833         itc->func.text_get = _gl_double_title_get;
834
835         layout = elm_layout_add(ad->nf);
836         elm_layout_file_set(layout, EDJE_PATH, "setting/genlist/layout");
837         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
838
839         genlist = elm_genlist_add(layout);
840         elm_genlist_block_count_set(genlist, 14);
841         elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
842         evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
843
844         /*elm_genlist_item_append(genlist, itc, NULL, NULL, */
845         /*              ELM_GENLIST_ITEM_NONE, _double_app_list_cb, ad); */
846
847         elm_genlist_item_class_free(itc);
848
849         g_double_genlist = genlist;
850
851         elm_object_part_content_set(layout, "elm.genlist", genlist);
852
853         return layout;
854 }
855
856 void clear_double_cb(void * data , Evas * e, Evas_Object * obj, void * event_info)
857 {
858         FREE(pitem_none);
859         FREE(pitem_recent);
860         g_double_genlist = NULL;
861         g_double_app_genlist = NULL;
862         unregister_vconf_changing(VCONFKEY_WMS_POWERKEY_DOUBLE_PRESSING, change_double_pressing_cb);
863         unregister_vconf_changing(VCONFKEY_LANGSET, change_language_cb);
864         unregister_vconf_changing(VCONFKEY_AIL_INFO_STATE, change_app_state_cb);
865 }
866