2 * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 * Created on: Jan 8, 2014
21 * Author: Sunyeop Hwang
23 #include <unicode/ustring.h>
24 #include <unicode/ucol.h>
25 #include <package-manager.h>
26 #include <pkgmgr-info.h>
28 #include "setting-double.h"
29 #include "setting_data_vconf.h"
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;
42 static struct _double_menu_item *_get_selected_app()
44 struct _double_menu_item *pitem = NULL;
48 appid = vconf_get_str(VCONFKEY_WMS_POWERKEY_DOUBLE_PRESSING);
50 if (appid && strlen(appid)) {
51 if (!strcmp(appid, "none")) {
53 } else if (!strcmp(appid, "recent")) {
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);
73 static int _sort_app_list_cb(const void *d1, const void *d2)
75 UChar app1[128] = { 0, };
76 UChar app2[128] = { 0, };
78 struct _double_menu_item *r1 = (struct _double_menu_item *) d1;
79 struct _double_menu_item *r2 = (struct _double_menu_item *) d2;
81 u_uastrcpy(app1, r1->name);
82 u_uastrcpy(app2, r2->name);
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);
103 static int _app_list_cb(pkgmgrinfo_appinfo_h handle, void *user_data)
105 appdata *ad = user_data;
107 ERR("appdata is null");
115 pkgmgrinfo_appinfo_h tmp_handle;
117 ret = pkgmgrinfo_appinfo_get_appid(handle, &appid);
119 if(ret < 0 || !appid) {
120 ERR("pkgmgrinfo_appinfo_get_appid error");
124 ret = pkgmgrinfo_appinfo_get_appinfo(appid, &tmp_handle);
125 if (ret != PMINFO_R_OK) {
126 ERR("pkgmgrinfo_appinfo_get_appinfo error");
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);
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);
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));
147 pitem->index = ++list_index;
148 pitem->appid = strdup(appid);
149 pitem->pkgid = strdup(pkgid);
150 pitem->name = strdup(name);
152 app_list = eina_list_sorted_insert(app_list, _sort_app_list_cb, pitem);
157 pkgmgrinfo_appinfo_destroy_appinfo(tmp_handle);
161 static void _clear_app_list()
163 struct _double_menu_item *pitem = NULL;
164 Eina_List *list = NULL;
166 EINA_LIST_FOREACH(app_list, list, pitem) {
170 app_list = eina_list_free(app_list);
174 static void _make_app_list(void* data)
178 ERR("appdata is null");
186 pkgmgrinfo_appinfo_filter_h handle = NULL;
188 if (pkgmgrinfo_appinfo_filter_create(&handle) != PMINFO_R_OK) {
189 ERR("pkgmgrinfo_appinfo_filter_create error");
193 if (pkgmgrinfo_appinfo_filter_add_bool(handle, PMINFO_APPINFO_PROP_APP_NODISPLAY, 0)
195 ERR("pkgmgrinfo_appinfo_filter_add_bool error");
196 pkgmgrinfo_appinfo_filter_destroy(handle);
200 if (pkgmgrinfo_appinfo_filter_foreach_appinfo(handle, _app_list_cb, ad)
202 ERR("pkgmgrinfo_appinfo_filter_foreach_appinfo error");
203 pkgmgrinfo_appinfo_filter_destroy(handle);
207 pkgmgrinfo_appinfo_filter_destroy(handle);
209 //app_list = eina_list_sort(app_list, eina_list_count(app_list), _sort_app_list_cb);
212 static void _gl_double_del(void *data, Evas_Object *obj)
214 Double_Item_Data *id = data;
219 static char *_gl_double_title_get(void *data, Evas_Object *obj, const char *part)
221 char buf[1024] = {0, };
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();
229 snprintf(buf, sizeof(buf)-1, "%s", _(selected_app->name));
230 DBG("elm.text.2 : %s", buf);
237 static char *_gl_double_app_title_get(void *data, Evas_Object *obj, const char *part)
239 Double_Item_Data *id = data;
241 if (!strcmp(part, "elm.text")) {
242 return strdup(_(id->pitem->name));
248 static Evas_Object *_gl_double_app_radio_get(void *data, Evas_Object *obj, const char *part)
250 Evas_Object *radio = NULL;
251 Evas_Object *radio_main = evas_object_data_get(obj, "radio_main");
252 Double_Item_Data *id = data;
254 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);
269 static void _gl_double_app_sel_cb(void *data, Evas_Object *obj, void *event_info)
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);
278 ERR("appdata or id is null!!");
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);
297 elm_naviframe_item_pop(ad->nf);
299 if(!ad->double_rdg) {
300 evas_object_del(ad->double_rdg);
301 ad->double_rdg = NULL;
305 static void change_double_pressing_cb(keynode_t *key, void * data)
310 ERR("appdata is null!!");
313 if (g_double_app_genlist) {
314 struct _double_menu_item *selected_app = NULL;
315 selected_app = _get_selected_app();
317 elm_radio_value_set(ad->double_rdg, selected_app->index);
319 elm_radio_value_set(ad->double_rdg, -1);
322 Elm_Object_Item *item = NULL;
323 item = elm_genlist_first_item_get(g_double_app_genlist);
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);
331 item = elm_genlist_item_next_get(item);
335 if (g_double_genlist) {
336 elm_genlist_realized_items_update(g_double_genlist);
340 static void update_double_app_list(void *data)
345 ERR("appdata is null!!");
351 if (g_double_genlist) {
352 elm_genlist_realized_items_update(g_double_genlist);
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;
361 elm_genlist_clear(g_double_app_genlist);
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;
369 selected_app = _get_selected_app();
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);
377 if (id_none->pitem == selected_app) {
378 sel_it = id_none->item;
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);
387 if (id_recent->pitem == selected_app) {
388 sel_it = id_recent->item;
391 EINA_LIST_FOREACH(app_list, list, pitem) {
392 Double_Item_Data *id = calloc(sizeof(Double_Item_Data), 1);
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);
398 if (id->pitem == selected_app) {
404 elm_radio_value_set(ad->double_rdg, selected_app->index);
406 elm_radio_value_set(ad->double_rdg, -1);
409 elm_genlist_item_show(sel_it, ELM_GENLIST_ITEM_SCROLLTO_TOP);
411 elm_genlist_item_class_free(itc);
416 static void change_language_cb(keynode_t *key, void * data)
421 ERR("appdata is null!!");
425 UErrorCode status = U_ZERO_ERROR;
430 const char *lang = vconf_get_str(VCONFKEY_LANGSET);
431 coll = ucol_open(lang, &status);
433 update_double_app_list(ad);
436 static int _double_press_check_appinfo(void *data, char *appid)
441 ERR("appdata is null!!");
445 pkgmgrinfo_appinfo_h tmp_handle;
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);
455 r = pkgmgrinfo_appinfo_is_nodisplay(tmp_handle, &nodisplay);
456 if (r != PMINFO_R_OK) {
457 ERR("pkgmgrinfo_appinfo_is_nodisplay error");
462 update_double_app_list(ad);
468 static void change_app_state_cb(keynode_t *key, void * data)
473 ERR("appdata is null!!");
477 char appid[256] = {0, };
478 char type[7] = {0, };
482 value = vconf_get_str(VCONFKEY_AIL_INFO_STATE);
485 strcpy(appid, value + 7);
486 strncpy(type, value, 6);
487 DBG("type :%s, appid :%s", type, appid);
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);
494 DBG("appid :%s", appid);
498 void clear_double_app_cb(void *data , Evas *e, Evas_Object *obj, void *event_info)
507 pkgmgr_client_free(pc);
511 pkgmgr_client_free(pc2);
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);
524 Evas_Object *create_double_app_list(void *data)
529 ERR("appdata is null!!");
533 Evas_Object *layout = NULL;
534 Evas_Object *genlist = NULL;
535 Elm_Object_Item *nf_it = NULL;
536 Elm_Object_Item *sel_it = NULL;
538 struct _double_menu_item *selected_app = NULL;
539 struct _double_menu_item *pitem = NULL;
540 Eina_List *list = NULL;
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;
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);
552 genlist = elm_genlist_add(layout);
553 evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
555 selected_app = _get_selected_app();
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);
563 if (id_none->pitem == selected_app) {
564 sel_it = id_none->item;
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);
573 if (id_recent->pitem == selected_app) {
574 sel_it = id_recent->item;
577 EINA_LIST_FOREACH(app_list, list, pitem) {
578 Double_Item_Data *id = calloc(sizeof(Double_Item_Data), 1);
580 id->item = elm_genlist_item_append(genlist, itc, id, NULL,
581 ELM_GENLIST_ITEM_NONE,
582 _gl_double_app_sel_cb, ad);
584 if (id->pitem == selected_app) {
589 ad->double_rdg = elm_radio_add(genlist);
590 elm_radio_state_value_set(ad->double_rdg, -1);
593 elm_radio_value_set(ad->double_rdg, selected_app->index);
595 elm_radio_value_set(ad->double_rdg, -1);
597 evas_object_data_set(genlist, "radio_main", ad->double_rdg);
599 elm_genlist_item_show(sel_it, ELM_GENLIST_ITEM_SCROLLTO_TOP);
601 g_double_app_genlist = genlist;
603 elm_object_part_content_set(layout, "elm.genlist", genlist);
605 elm_genlist_item_class_free(itc);
610 static int _double_press_appinfo_cb(pkgmgrinfo_appinfo_h handle, void *data)
615 ERR("appdata is null!!");
620 pkgmgrinfo_appinfo_h tmp_handle;
623 r = pkgmgrinfo_appinfo_get_appid(handle, &appid);
624 if(r < 0 || !appid) {
625 ERR("pkgmgrinfo_appinfo_get_appid error");
628 r = pkgmgrinfo_appinfo_get_appinfo(appid, &tmp_handle);
629 if (r != PMINFO_R_OK) {
630 ERR("pkgmgrinfo_appinfo_get_appinfo error");
634 r = pkgmgrinfo_appinfo_is_nodisplay(tmp_handle, &nodisplay);
635 if (r != PMINFO_R_OK) {
636 ERR("pkgmgrinfo_appinfo_is_nodisplay error");
642 update_double_app_list(ad);
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)
654 ERR("appdata is null!!");
658 if (!pkgid || !key || !val) {
659 ERR("pkgid or key or val is null");
664 if (!strncmp(key, "end", 3) && !strncmp(val, "ok", 2)) {
665 DBG("end install/update for some pkgid");
667 pkgmgrinfo_pkginfo_h handle;
669 ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
670 if (ret != PMINFO_R_OK)
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);
677 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
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)
689 ERR("appdata is null!!");
693 if (!pkgid || !key || !val) {
694 ERR("pkgid or key or val is null");
699 if (!strncmp(key, "end", 3) && !strncmp(val, "ok", 2)) {
700 DBG("end uninstall for some pkgid");
701 update_double_app_list(ad);
706 void init_double_pressing(void *data)
711 ERR("appdata is null!!");
716 pitem_none = calloc(sizeof(struct _double_menu_item), 1);
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");
726 pitem_recent = calloc(sizeof(struct _double_menu_item), 1);
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");
735 UErrorCode status = U_ZERO_ERROR;
740 const char *lang = vconf_get_str(VCONFKEY_LANGSET);
741 coll = ucol_open(lang, &status);
743 int event_type = PMINFO_CLIENT_STATUS_INSTALL | PMINFO_CLIENT_STATUS_UPGRADE;
747 pkgmgr_client_free(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);
757 int event_type2 = PMINFO_CLIENT_STATUS_UNINSTALL;
760 pkgmgr_client_free(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);
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);
777 Evas_Object *create_double_list(void *data)
782 ERR("appdata is null!!");
786 Evas_Object *genlist = NULL;
787 Evas_Object *layout = NULL;
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;
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);
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);
803 //elm_genlist_item_append(genlist, itc, NULL, NULL,
804 // ELM_GENLIST_ITEM_NONE, _double_app_list_cb, ad);
806 elm_genlist_item_class_free(itc);
808 g_double_genlist = genlist;
810 elm_object_part_content_set(layout, "elm.genlist", genlist);
815 void clear_double_cb(void *data , Evas *e, Evas_Object *obj, void *event_info)
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);