2 * Copyright (c) 2010 Samsung Electronics, Inc.
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.
14 * Created on: Jan 8, 2014
15 * Author: Sunyeop Hwang
17 #include <unicode/ustring.h>
18 #include <unicode/ucol.h>
19 #include <package-manager.h>
20 #include <pkgmgr-info.h>
22 #include "setting-double.h"
23 #include "setting_data_vconf.h"
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;
36 static struct _double_menu_item *_get_selected_app()
38 struct _double_menu_item *pitem = NULL;
42 appid = vconf_get_str(VCONFKEY_WMS_POWERKEY_DOUBLE_PRESSING);
44 if (appid && strlen(appid)) {
45 if (!strcmp(appid, "none")) {
47 } else if (!strcmp(appid, "recent")) {
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);
67 static int _sort_app_list_cb(const void *d1, const void *d2)
69 UChar app1[128] = { 0, };
70 UChar app2[128] = { 0, };
72 struct _double_menu_item *r1 = (struct _double_menu_item *) d1;
73 struct _double_menu_item *r2 = (struct _double_menu_item *) d2;
75 u_uastrcpy(app1, r1->name);
76 u_uastrcpy(app2, r2->name);
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);
97 static int _app_list_cb(pkgmgrinfo_appinfo_h handle, void *user_data)
99 appdata *ad = user_data;
101 ERR("appdata is null");
109 pkgmgrinfo_appinfo_h tmp_handle;
111 ret = pkgmgrinfo_appinfo_get_appid(handle, &appid);
113 if(ret < 0 || !appid) {
114 ERR("pkgmgrinfo_appinfo_get_appid error");
118 ret = pkgmgrinfo_appinfo_get_appinfo(appid, &tmp_handle);
119 if (ret != PMINFO_R_OK) {
120 ERR("pkgmgrinfo_appinfo_get_appinfo error");
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);
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);
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));
141 pitem->index = ++list_index;
142 pitem->appid = strdup(appid);
143 pitem->pkgid = strdup(pkgid);
144 pitem->name = strdup(name);
146 app_list = eina_list_sorted_insert(app_list, _sort_app_list_cb, pitem);
151 pkgmgrinfo_appinfo_destroy_appinfo(tmp_handle);
155 static void _clear_app_list()
157 struct _double_menu_item *pitem = NULL;
158 Eina_List *list = NULL;
160 EINA_LIST_FOREACH(app_list, list, pitem) {
164 app_list = eina_list_free(app_list);
168 static void _make_app_list(void* data)
172 ERR("appdata is null");
180 pkgmgrinfo_appinfo_filter_h handle = NULL;
182 if (pkgmgrinfo_appinfo_filter_create(&handle) != PMINFO_R_OK) {
183 ERR("pkgmgrinfo_appinfo_filter_create error");
187 if (pkgmgrinfo_appinfo_filter_add_bool(handle, PMINFO_APPINFO_PROP_APP_NODISPLAY, 0)
189 ERR("pkgmgrinfo_appinfo_filter_add_bool error");
190 pkgmgrinfo_appinfo_filter_destroy(handle);
194 if (pkgmgrinfo_appinfo_filter_foreach_appinfo(handle, _app_list_cb, ad)
196 ERR("pkgmgrinfo_appinfo_filter_foreach_appinfo error");
197 pkgmgrinfo_appinfo_filter_destroy(handle);
201 pkgmgrinfo_appinfo_filter_destroy(handle);
203 //app_list = eina_list_sort(app_list, eina_list_count(app_list), _sort_app_list_cb);
206 static void _gl_double_del(void *data, Evas_Object *obj)
208 Double_Item_Data *id = data;
213 static char *_gl_double_title_get(void *data, Evas_Object *obj, const char *part)
215 char buf[1024] = {0, };
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();
223 snprintf(buf, sizeof(buf)-1, "%s", _(selected_app->name));
224 DBG("elm.text.2 : %s", buf);
231 static char *_gl_double_app_title_get(void *data, Evas_Object *obj, const char *part)
233 Double_Item_Data *id = data;
235 if (!strcmp(part, "elm.text")) {
236 return strdup(_(id->pitem->name));
242 static Evas_Object *_gl_double_app_radio_get(void *data, Evas_Object *obj, const char *part)
244 Evas_Object *radio = NULL;
245 Evas_Object *radio_main = evas_object_data_get(obj, "radio_main");
246 Double_Item_Data *id = data;
248 if( !strcmp(part, "elm.icon") )
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);
263 static void _gl_double_app_sel_cb(void *data, Evas_Object *obj, void *event_info)
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);
272 ERR("appdata or id is null!!");
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);
291 elm_naviframe_item_pop(ad->nf);
293 if(!ad->double_rdg) {
294 evas_object_del(ad->double_rdg);
295 ad->double_rdg = NULL;
299 static void change_double_pressing_cb(keynode_t *key, void * data)
304 ERR("appdata is null!!");
307 if (g_double_app_genlist) {
308 struct _double_menu_item *selected_app = NULL;
309 selected_app = _get_selected_app();
311 elm_radio_value_set(ad->double_rdg, selected_app->index);
313 elm_radio_value_set(ad->double_rdg, -1);
316 Elm_Object_Item *item = NULL;
317 item = elm_genlist_first_item_get(g_double_app_genlist);
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);
325 item = elm_genlist_item_next_get(item);
329 if (g_double_genlist) {
330 elm_genlist_realized_items_update(g_double_genlist);
334 static void update_double_app_list(void *data)
339 ERR("appdata is null!!");
345 if (g_double_genlist) {
346 elm_genlist_realized_items_update(g_double_genlist);
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;
355 elm_genlist_clear(g_double_app_genlist);
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;
363 selected_app = _get_selected_app();
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);
371 if (id_none->pitem == selected_app) {
372 sel_it = id_none->item;
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);
381 if (id_recent->pitem == selected_app) {
382 sel_it = id_recent->item;
385 EINA_LIST_FOREACH(app_list, list, pitem) {
386 Double_Item_Data *id = calloc(sizeof(Double_Item_Data), 1);
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);
392 if (id->pitem == selected_app) {
398 elm_radio_value_set(ad->double_rdg, selected_app->index);
400 elm_radio_value_set(ad->double_rdg, -1);
403 elm_genlist_item_show(sel_it, ELM_GENLIST_ITEM_SCROLLTO_TOP);
405 elm_genlist_item_class_free(itc);
410 static void change_language_cb(keynode_t *key, void * data)
415 ERR("appdata is null!!");
419 UErrorCode status = U_ZERO_ERROR;
424 const char *lang = vconf_get_str(VCONFKEY_LANGSET);
425 coll = ucol_open(lang, &status);
427 update_double_app_list(ad);
430 static int _double_press_check_appinfo(void *data, char *appid)
435 ERR("appdata is null!!");
439 pkgmgrinfo_appinfo_h tmp_handle;
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);
449 r = pkgmgrinfo_appinfo_is_nodisplay(tmp_handle, &nodisplay);
450 if (r != PMINFO_R_OK) {
451 ERR("pkgmgrinfo_appinfo_is_nodisplay error");
456 update_double_app_list(ad);
462 static void change_app_state_cb(keynode_t *key, void * data)
467 ERR("appdata is null!!");
471 char appid[256] = {0, };
472 char type[7] = {0, };
476 value = vconf_get_str(VCONFKEY_AIL_INFO_STATE);
479 strcpy(appid, value + 7);
480 strncpy(type, value, 6);
481 DBG("type :%s, appid :%s", type, appid);
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);
488 DBG("appid :%s", appid);
492 void clear_double_app_cb(void *data , Evas *e, Evas_Object *obj, void *event_info)
501 pkgmgr_client_free(pc);
505 pkgmgr_client_free(pc2);
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);
518 Evas_Object *create_double_app_list(void *data)
523 ERR("appdata is null!!");
527 Evas_Object *layout = NULL;
528 Evas_Object *genlist = NULL;
529 Elm_Object_Item *nf_it = NULL;
530 Elm_Object_Item *sel_it = NULL;
532 struct _double_menu_item *selected_app = NULL;
533 struct _double_menu_item *pitem = NULL;
534 Eina_List *list = NULL;
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;
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);
546 genlist = elm_genlist_add(layout);
547 evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
549 selected_app = _get_selected_app();
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);
557 if (id_none->pitem == selected_app) {
558 sel_it = id_none->item;
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);
567 if (id_recent->pitem == selected_app) {
568 sel_it = id_recent->item;
571 EINA_LIST_FOREACH(app_list, list, pitem) {
572 Double_Item_Data *id = calloc(sizeof(Double_Item_Data), 1);
574 id->item = elm_genlist_item_append(genlist, itc, id, NULL,
575 ELM_GENLIST_ITEM_NONE,
576 _gl_double_app_sel_cb, ad);
578 if (id->pitem == selected_app) {
583 ad->double_rdg = elm_radio_add(genlist);
584 elm_radio_state_value_set(ad->double_rdg, -1);
587 elm_radio_value_set(ad->double_rdg, selected_app->index);
589 elm_radio_value_set(ad->double_rdg, -1);
591 evas_object_data_set(genlist, "radio_main", ad->double_rdg);
593 elm_genlist_item_show(sel_it, ELM_GENLIST_ITEM_SCROLLTO_TOP);
595 g_double_app_genlist = genlist;
597 elm_object_part_content_set(layout, "elm.genlist", genlist);
599 elm_genlist_item_class_free(itc);
604 static int _double_press_appinfo_cb(pkgmgrinfo_appinfo_h handle, void *data)
609 ERR("appdata is null!!");
614 pkgmgrinfo_appinfo_h tmp_handle;
617 r = pkgmgrinfo_appinfo_get_appid(handle, &appid);
618 if(r < 0 || !appid) {
619 ERR("pkgmgrinfo_appinfo_get_appid error");
622 r = pkgmgrinfo_appinfo_get_appinfo(appid, &tmp_handle);
623 if (r != PMINFO_R_OK) {
624 ERR("pkgmgrinfo_appinfo_get_appinfo error");
628 r = pkgmgrinfo_appinfo_is_nodisplay(tmp_handle, &nodisplay);
629 if (r != PMINFO_R_OK) {
630 ERR("pkgmgrinfo_appinfo_is_nodisplay error");
636 update_double_app_list(ad);
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)
648 ERR("appdata is null!!");
652 if (!pkgid || !key || !val) {
653 ERR("pkgid or key or val is null");
658 if (!strncmp(key, "end", 3) && !strncmp(val, "ok", 2)) {
659 DBG("end install/update for some pkgid");
661 pkgmgrinfo_pkginfo_h handle;
663 ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
664 if (ret != PMINFO_R_OK)
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);
671 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
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)
683 ERR("appdata is null!!");
687 if (!pkgid || !key || !val) {
688 ERR("pkgid or key or val is null");
693 if (!strncmp(key, "end", 3) && !strncmp(val, "ok", 2)) {
694 DBG("end uninstall for some pkgid");
695 update_double_app_list(ad);
700 void init_double_pressing(void *data)
705 ERR("appdata is null!!");
710 pitem_none = calloc(sizeof(struct _double_menu_item), 1);
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");
720 pitem_recent = calloc(sizeof(struct _double_menu_item), 1);
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");
729 UErrorCode status = U_ZERO_ERROR;
734 const char *lang = vconf_get_str(VCONFKEY_LANGSET);
735 coll = ucol_open(lang, &status);
737 int event_type = PMINFO_CLIENT_STATUS_INSTALL | PMINFO_CLIENT_STATUS_UPGRADE;
741 pkgmgr_client_free(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);
751 int event_type2 = PMINFO_CLIENT_STATUS_UNINSTALL;
754 pkgmgr_client_free(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);
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);
771 Evas_Object *create_double_list(void *data)
776 ERR("appdata is null!!");
780 Evas_Object *genlist = NULL;
781 Evas_Object *layout = NULL;
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;
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);
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);
797 //elm_genlist_item_append(genlist, itc, NULL, NULL,
798 // ELM_GENLIST_ITEM_NONE, _double_app_list_cb, ad);
800 elm_genlist_item_class_free(itc);
802 g_double_genlist = genlist;
804 elm_object_part_content_set(layout, "elm.genlist", genlist);
809 void clear_double_cb(void *data , Evas *e, Evas_Object *obj, void *event_info)
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);