2 * Copyright 2012 Samsung Electronics Co., Ltd
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
8 * http://floralicense.org/license/
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.
18 #include "mgr-app-common-debug.h"
19 #include "mgr-app-common-error.h"
20 #include "mgr-app-common-util.h"
21 #include "mgr-app-view-main.h"
22 #include "mgr-app-view-common.h"
23 #include "mgr-app-string.h"
24 #include "mgr-app-widget.h"
25 #include "mgr-app-uigadget.h"
28 #include <package-manager.h>
29 #include <pkgmgr-info.h>
31 #include <app_manager.h>
33 #define WRT_PREFIX "wgt"
34 #define TPK_PREFIX "tpk"
35 #define RPM_PREFIX "rpm"
37 #define STR_ICON "icon"
39 #define EDC_FILE EDJDIR"/ug-setting-manage-applications-efl/ug-setting-manage-applications-efl.edj"
40 #define EDC_GROUPS "mgr-app-list"
42 #define ELM_TEXT "elm.text"
43 #define ITC_ITEM_STYLE "dialogue/1text.1icon.2"
44 #define ITC_SEP_ITEM_STYLE "dialogue/separator"
45 #define GENLIST_BLOCK_CNT 10
47 #define MAX_BUF_SIZE 32
48 #define MAX_APP_CNT 1024
52 #define STR_INSTALL "install"
53 #define STR_UNINSTALL "uninstall"
54 #define STR_START "start"
57 #define STR_CANCEL "cancel"
58 #define STR_ERROR "error"
59 #define STR_FAIL "fail"
60 #define STR_POPUP_OK "OK"
62 static Evas_Object *_genlist = NULL;
63 static Evas_Object *_index = NULL;
64 static int _index_cnt = 0;
65 static Eina_Bool _initialize = false;
66 static GList *_installed_list = NULL;
67 static int _installed_cnt = 0;
68 static int _target_idx = 0;
69 static Elm_Object_Item *_tabbar_item[VIEW_TYPE_MAX] = {NULL,};
70 static Elm_Object_Item *_navi_it = NULL;
72 static Elm_Genlist_Item_Class *itc = NULL;
73 static Elm_Genlist_Item_Class *itc_sep = NULL;
75 static char *_convert_char_to_string(char ch);
76 static void _register_index_item(Evas_Object *index, char *letter, Elm_Object_Item *item, Eina_Bool init);
77 static void _index_del_item_cb(void *data, Evas_Object *obj, void *event_info);
78 static void _insert_to_app_list(mgr_app_app_info_t *app_info_new, void *user_data);
80 static void _free_resources(struct ug_data * ugd)
84 mgr_app_app_info_t *app_info = NULL;
87 for (i = 0; i < _installed_cnt; i++ ) {
88 app_info = (mgr_app_app_info_t *)g_list_nth_data(_installed_list, 0);
89 if (NULL == app_info) {
92 MGR_APP_MEM_FREE(app_info->pkg_label);
93 MGR_APP_MEM_FREE(app_info->pkg_name);
94 MGR_APP_MEM_FREE(app_info->pkg_type);
95 MGR_APP_MEM_FREE(app_info->icon_path);
96 MGR_APP_MEM_FREE(app_info->main_appid);
97 _installed_list = g_list_remove(_installed_list, app_info);
100 elm_genlist_item_class_free(itc);
101 elm_genlist_item_class_free(itc_sep);
104 static void _app_list_back_cb(void *data, Evas_Object *obj, void *event_info)
107 ret_if(data == NULL);
108 struct ug_data *ugd = (struct ug_data*)data;
110 mgr_app_doubletap_sensor_disable();
112 _free_resources(ugd);
114 mgrapp_set_view_type(VIEW_TYPE_NONE);
116 elm_naviframe_item_pop(ugd->navi_bar);
118 /* bg must delete before starting on_destroy */
119 if (ugd && ugd->bg) {
120 evas_object_del(ugd->bg);
124 if (ugd && ugd->ug) {
125 ug_destroy_me(ugd->ug);
132 /* callback for 'deletion' */
133 static void _gl_del(void *data, Evas_Object *obj)
137 ret_if(data == NULL);
138 mgr_app_app_info_t *app_info = (mgr_app_app_info_t *)data;
142 MGR_APP_MEM_FREE(app_info->pkg_name);
143 MGR_APP_MEM_FREE(app_info->pkg_label);
144 MGR_APP_MEM_FREE(app_info->pkg_type);
145 MGR_APP_MEM_FREE(app_info->icon_path);
146 MGR_APP_MEM_FREE(app_info->main_appid);
147 //MGR_APP_MEM_FREE(app_info);
153 /* callback for 'selection' */
154 static void _gl_sel(void *data, Evas_Object *obj, void *event_info)
158 ret_if(data == NULL);
159 ret_if(event_info == NULL);
161 struct ug_data *ugd = (struct ug_data*)data;
162 Elm_Object_Item *item = (Elm_Object_Item *)event_info;
164 mgr_app_app_info_t *app_info = (mgr_app_app_info_t *)elm_object_item_data_get(item);
165 ret_if(app_info == NULL);
167 elm_genlist_item_selected_set(item, 0);
169 /* create app info view */
170 ugd->data = (void*)app_info;
171 mgrapp_view_info_create(app_info->pkg_name, (void*)ugd);
176 static char *_gl_label_get(void *data, Evas_Object *obj, const char *part)
180 retv_if(data == NULL, NULL);
181 mgr_app_app_info_t *app_info = (mgr_app_app_info_t *)data;
184 char *package_label = app_info->pkg_label;
185 char *icon_path = app_info->icon_path;
187 MGR_APP_DEBUG("package_label:[%s], icon_path:[%s]\n", package_label, icon_path);
188 MGR_APP_DEBUG("part:%s\n", part);
190 /* label for 'elm.text' part */
191 if (package_label && 0 == strcmp(part, ELM_TEXT)) {
192 MGR_APP_MEM_STRDUP(label, package_label);
194 MGR_APP_MEM_STRDUP(label, MGRAPP_STR_ERROR);
201 static Evas_Object *_gl_icon_get(void *data, Evas_Object *obj, const char *part)
205 retv_if(data == NULL, NULL);
206 mgr_app_app_info_t *app_info = (mgr_app_app_info_t *)data;
208 retv_if(app_info->icon_path == NULL, NULL);
209 char *icon_path = NULL;
210 icon_path = app_info->icon_path;
212 Evas_Object *icon = NULL;
214 MGR_APP_DEBUG("icon_path:[%s]\n", icon_path);
215 MGR_APP_DEBUG("part:%s\n", part);
217 /* icon for 'elm.icon' part */
218 icon = elm_icon_add(obj);
219 retv_if(icon == NULL, NULL);
220 evas_object_size_hint_weight_set(icon, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
221 evas_object_size_hint_align_set(icon, EVAS_HINT_FILL, EVAS_HINT_FILL);
222 evas_object_size_hint_aspect_set(icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
224 elm_image_file_set(icon, icon_path, STR_ICON);
225 evas_object_show(icon);
231 static void _index_delayed_changed(void *data, Evas_Object *obj, void *event_info)
234 // called on a change but delayed in case multiple changes happen in a
236 elm_genlist_item_bring_in(elm_object_item_data_get(event_info), ELM_GENLIST_ITEM_SCROLLTO_TOP);
240 static void _index_changed(void *data, Evas_Object *obj, void *event_info)
243 // this is calld on every change, no matter how often
247 static void _index_selected(void *data, Evas_Object *obj, void *event_info)
250 // called on final select
251 elm_genlist_item_bring_in(elm_object_item_data_get(event_info), ELM_GENLIST_ITEM_SCROLLTO_TOP);
255 static gint _app_list_qsort_cb(gconstpointer a, gconstpointer b)
259 retv_if(NULL == a, 0);
260 retv_if(NULL == b, 0);
262 mgr_app_app_info_t *app_info1 = (mgr_app_app_info_t *)a;
263 mgr_app_app_info_t *app_info2 = (mgr_app_app_info_t *)b;
264 char *pkg_label1 = NULL;
265 char *pkg_label2 = NULL;
269 pkg_label1 = app_info1->pkg_label;
270 pkg_label2 = app_info2->pkg_label;
271 retv_if(NULL == pkg_label1, 0);
272 retv_if(NULL == pkg_label2, 0);
274 MGR_APP_DEBUG("pkg_label1: %s", pkg_label1);
275 MGR_APP_DEBUG("pkg_label2: %s", pkg_label2);
277 len = (strlen(pkg_label1) >= strlen(pkg_label2)) ? strlen(pkg_label1) : strlen(pkg_label2);
278 r = strncasecmp(pkg_label1, pkg_label2, len);
287 static void _get_appinfo_from_pkgmgr(const pkgmgrinfo_pkginfo_h handler, mgr_app_app_info_t *app_info)
291 ret_if(NULL == handler || NULL == app_info);
294 char *pkg_name = NULL;
295 char *icon_path = NULL;
296 char *main_appid = NULL;
297 char *pkg_label = NULL;
298 pkgmgrinfo_appinfo_h appinfo_h = NULL;
300 r = pkgmgrinfo_pkginfo_get_pkgid(handler, &pkg_name);
302 MGR_APP_DEBUG_ERR("pkgmgrinfo_pkginfo_get_pkgid is failed %d", r);
305 MGR_APP_MEM_STRDUP(app_info->pkg_name, pkg_name);
306 MGR_APP_DEBUG("pkg_name: %s", pkg_name);
308 /* get label/icon from mainapp */
309 r = pkgmgrinfo_pkginfo_get_mainappid(handler, &main_appid);
311 MGR_APP_DEBUG_ERR("pkgmgrinfo_pkginfo_get_mainappid is failed %d", r);
314 MGR_APP_DEBUG("main_appid: %s", main_appid);
315 MGR_APP_MEM_STRDUP(app_info->main_appid, main_appid);
317 r = pkgmgrinfo_appinfo_get_appinfo(main_appid, &appinfo_h);
319 MGR_APP_DEBUG_ERR("pkgmgrinfo_appinfo_get_appinfo is failed %d", r);
323 r = pkgmgrinfo_appinfo_is_nodisplay(appinfo_h, &app_info->nodisplay);
325 MGR_APP_DEBUG_ERR("pkgmgrinfo_appinfo_is_nodisplay failed. %d", r);
329 r = pkgmgrinfo_appinfo_get_icon(appinfo_h, &icon_path);
331 MGR_APP_DEBUG_ERR("pkgmgrinfo_appinfo_get_icon is failed %d", r);
334 MGR_APP_MEM_STRDUP(app_info->icon_path, icon_path);
335 if (app_info->nodisplay) {
336 mgr_app_set_default_icon(&app_info->icon_path, DEFAULT_ICON_SERVICE);
338 mgr_app_set_default_icon(&app_info->icon_path, DEFAULT_ICON_APP);
340 MGR_APP_DEBUG("icon_path: %s", icon_path);
342 r = pkgmgrinfo_appinfo_get_label(appinfo_h, &pkg_label);
344 MGR_APP_DEBUG_ERR("pkgmgrinfo_appinfo_get_label is failed %d", r);
347 MGR_APP_MEM_STRDUP(app_info->pkg_label, pkg_label);
348 MGR_APP_DEBUG("pkg_label: %s", pkg_label);
352 pkgmgrinfo_appinfo_destroy_appinfo(appinfo_h);
358 static void _insert_to_app_list(mgr_app_app_info_t *app_info_new, void *user_data)
362 ret_if(NULL == app_info_new || NULL == user_data);
364 struct ug_data *ugd = (struct ug_data *)user_data;
365 Elm_Object_Item *new_item = NULL;
366 Elm_Object_Item *prev_item = NULL;
367 Elm_Object_Item *next_item = NULL;
368 Elm_Object_Item *index_item = NULL;
369 mgr_app_app_info_t *prev_info = NULL;
370 mgr_app_app_info_t *next_info = NULL;
371 char *letter_new = NULL;
373 char *letter2 = NULL;
375 /* insert to genlist */
376 if (_target_idx > 1) {
377 prev_item = elm_genlist_nth_item_get(_genlist, _target_idx);
378 if (NULL == prev_item) {
379 MGR_APP_DEBUG_ERR("prev_item is null");
382 new_item = elm_genlist_item_insert_after(_genlist, itc, (void*)app_info_new, NULL, prev_item, ELM_GENLIST_ITEM_NONE, _gl_sel, (void*)ugd);
383 if (NULL == new_item) {
384 MGR_APP_DEBUG_ERR("new_item is null");
388 new_item = elm_genlist_item_append(_genlist, itc, (void*)app_info_new, NULL, ELM_GENLIST_ITEM_NONE, _gl_sel, (void*)ugd);
389 if (NULL == new_item) {
390 MGR_APP_DEBUG_ERR("new_item is null");
395 if (NULL == app_info_new->pkg_label) {
396 MGR_APP_DEBUG_ERR("pkg_name_new is null");
400 letter_new = _convert_char_to_string(app_info_new->pkg_label[0]);
401 if (NULL == letter_new) {
402 MGR_APP_DEBUG_ERR("letter_new is null");
407 /* A' B' are new one */
409 if (_installed_cnt <= 1) {
410 _register_index_item(_index, letter_new, new_item, EINA_FALSE);
412 } else if (_target_idx == 1) {
413 next_item = elm_genlist_item_next_get(new_item);
414 if (NULL == next_item) {
415 MGR_APP_DEBUG_ERR("next_item is null");
418 next_info = (mgr_app_app_info_t *)elm_object_item_data_get(next_item);
419 if (NULL == next_info) {
420 MGR_APP_DEBUG_ERR("next_info is null");
424 if (NULL == next_info->pkg_label) {
425 MGR_APP_DEBUG_ERR("pkg_label is null");
429 letter = _convert_char_to_string(next_info->pkg_label[0]);
430 if (NULL == letter) {
431 MGR_APP_DEBUG_ERR("letter is null");
435 /* remove next letter and insert new letter */
436 /* remove and insert operation is executed in index item delete callback */
438 if (letter_new[0] == letter[0]) {
439 index_item = elm_index_item_find(_index, next_item);
441 elm_object_item_del(index_item);
443 /* insert new letter */
446 _register_index_item(_index, letter_new, new_item, EINA_FALSE);
449 } else if (_target_idx > 1 && _target_idx < _installed_cnt) {
450 prev_item = elm_genlist_item_prev_get(new_item);
451 if (NULL == prev_item) {
452 MGR_APP_DEBUG_ERR("prev_item is null");
455 next_item = elm_genlist_item_next_get(new_item);
456 if (NULL == next_item) {
457 MGR_APP_DEBUG_ERR("next_item is null");
461 prev_info = (mgr_app_app_info_t *)elm_object_item_data_get(prev_item);
462 if (NULL == prev_info) {
463 MGR_APP_DEBUG_ERR("prev_info is null");
466 next_info = (mgr_app_app_info_t *)elm_object_item_data_get(next_item);
467 if (NULL == next_info) {
468 MGR_APP_DEBUG_ERR("next_info is null");
472 if (NULL == prev_info->pkg_label) {
473 MGR_APP_DEBUG_ERR("prev_info->pkg_label is null");
476 if (NULL == next_info->pkg_label) {
477 MGR_APP_DEBUG_ERR("next_info->pkg_label is null");
481 letter = _convert_char_to_string(prev_info->pkg_label[0]);
482 if (NULL == letter) {
483 MGR_APP_DEBUG_ERR("letter is null");
486 letter2 = _convert_char_to_string(next_info->pkg_label[0]);
487 if (NULL == letter2) {
488 MGR_APP_DEBUG_ERR("letter2 is null");
494 if (letter[0] == letter2[0]) {
498 } else if (letter[0] == letter_new[0]) {
504 if (letter[0] < letter_new[0] && letter_new[0] < letter2[0]) {
505 _register_index_item(_index, letter_new, new_item, EINA_FALSE);
508 } else if (letter_new[0] == letter2[0]) {
509 index_item = elm_index_item_find(_index, next_item);
511 elm_object_item_del(index_item);
516 } else if (_target_idx == _installed_cnt) {
517 prev_item = elm_genlist_item_prev_get(new_item);
518 if (NULL == prev_item) {
519 MGR_APP_DEBUG_ERR("prev_item is null");
522 prev_info = (mgr_app_app_info_t *)elm_object_item_data_get(prev_item);
523 if (NULL == prev_info) {
524 MGR_APP_DEBUG_ERR("prev_info is null");
527 if (NULL == prev_info->pkg_label) {
528 MGR_APP_DEBUG_ERR("pkg_label is null");
532 letter = _convert_char_to_string(prev_info->pkg_label[0]);
533 if (NULL == letter) {
534 MGR_APP_DEBUG_ERR("letter is null");
538 /* insert new letter */
540 if (letter_new[0] > letter[0]) {
541 _register_index_item(_index, letter_new, new_item, EINA_FALSE);
546 elm_genlist_realized_items_update(_genlist);
549 MGR_APP_MEM_FREE(letter);
550 MGR_APP_MEM_FREE(letter2);
551 MGR_APP_MEM_FREE(letter_new);
556 static void _notify_by_uninstall(void *data)
560 ret_if(data == NULL);
561 struct ug_data *ugd = (struct ug_data*)data;
563 Evas_Object *noti = elm_notify_add(ugd->navi_bar);
564 elm_notify_align_set(noti, ELM_NOTIFY_ALIGN_FILL, 1.0);
566 Evas_Object *layout = elm_layout_add(noti);
567 elm_layout_theme_set(layout, "standard", "selectioninfo", "center_text");
569 elm_object_content_set(noti, layout);
570 elm_notify_timeout_set(noti, 2);
571 edje_object_part_text_set(_EDJ(layout), ELM_TEXT, MGRAPP_STR_UNINSTALLED);
572 evas_object_show(noti);
577 static void mgrapp_view_list_update_by_install(const char *pkg_type, const char *pkg_name, void *data)
581 ret_if(pkg_name == NULL || data == NULL);
583 struct ug_data *ugd = (struct ug_data*)data;
584 pkgmgr_pkginfo_h pkg_handle = NULL;
585 mgr_app_app_info_t *app_info = NULL;
588 _initialize = EINA_FALSE;
590 r = pkgmgr_pkginfo_get_pkginfo(pkg_name, &pkg_handle);
592 MGR_APP_DEBUG_ERR("pkgmgr_pkginfo_get_pkginfo is failed. %d", r);
596 app_info = (mgr_app_app_info_t*)malloc(sizeof(mgr_app_app_info_t));
597 if (NULL == app_info) {
600 memset(app_info, 0, sizeof(mgr_app_app_info_t));
602 _get_appinfo_from_pkgmgr(pkg_handle, app_info);
604 _target_idx = 1; // 0: genlist separator item
605 _installed_list = g_list_insert_sorted(_installed_list, (gpointer)app_info, _app_list_qsort_cb);
608 _insert_to_app_list(app_info, (void*)ugd);
612 pkgmgr_pkginfo_destroy_pkginfo(pkg_handle);
618 void mgrapp_view_list_update_by_uninstall(const char *pkg_type, const char *pkg_name, void *data)
622 ret_if(pkg_name == NULL);
624 mgr_app_app_info_t *app_info = NULL;
625 Elm_Object_Item *item = NULL;
626 Elm_Object_Item *idx_item = NULL;
629 /* header separator */
630 item = elm_genlist_first_item_get(_genlist);
631 ret_if(item == NULL);
632 item = elm_genlist_item_next_get(item);
633 ret_if(item == NULL);
636 for (i = 0; i < _installed_cnt; i++) {
638 app_info = (mgr_app_app_info_t *)elm_object_item_data_get(item);
639 ret_if(app_info == NULL);
641 if (app_info->pkg_name && 0 == strcmp(app_info->pkg_name, pkg_name)) {
642 MGR_APP_DEBUG_ERR("in");
643 idx_item = elm_index_item_find(_index, item);
645 _index_del_item_cb(item, _index, idx_item);
646 elm_object_item_del(idx_item);
649 _installed_list = g_list_remove(_installed_list, app_info);
650 elm_object_item_del(item);
653 MGR_APP_DEBUG("deleted");
656 item = elm_genlist_item_next_get(item);
657 ret_if(item == NULL);
660 elm_genlist_realized_items_update(_genlist);
665 static void _response_cb(void *data, Evas_Object *obj, void *event_info)
670 evas_object_del(data);
677 int mgrapp_view_listen_cb(int req_id, const char *pkg_type, const char *pkg_name, const char *key, const char *val, const void *pmsg, void *data)
681 MGR_APP_DEBUG("key:%s val:%s", key, val);
682 MGR_APP_DEBUG("pkg_type:%s pkg_name:%s", pkg_type, pkg_name);
683 retv_if(data == NULL, -1);
684 struct ug_data *ugd = (struct ug_data*)data;
686 if (!strncmp(key, STR_START, strlen(key)) && !strncmp(val, STR_UNINSTALL, strlen(val))) {
687 ugd->uninstall = EINA_TRUE;
688 } else if (!strncmp(key, STR_START, strlen(key)) && !strncmp(val, STR_INSTALL, strlen(val))) {
689 ugd->uninstall = EINA_FALSE;
690 } else if (!strncmp(key, STR_ERROR, strlen(key))) {
691 } else if (!strncmp(key, STR_END, strlen(key)) && !strncmp(val, STR_FAIL, strlen(val))) {
692 mgrapp_destroy_popup_progressbar();
693 mgrapp_create_popup_text_1button(ugd->win_main, MGRAPP_STR_FAILED, STR_POPUP_OK, _response_cb);
694 } else if (!strncmp(key, STR_END, strlen(key)) && !strncmp(val, STR_OK, strlen(val))) {
695 if (ugd->uninstall) {
696 mgrapp_destroy_popup_progressbar();
697 mgrapp_create_popup_text_1button(ugd->win_main, MGRAPP_STR_SUCCESS, STR_POPUP_OK, _response_cb);
698 mgrapp_view_list_update_by_uninstall(pkg_type, pkg_name, (void*)ugd);
700 mgrapp_view_list_update_by_install(pkg_type, pkg_name, (void*)ugd);
703 /* check the info view was opened */
704 if (VIEW_TYPE_APP_INFO == mgrapp_get_view_type()) {
705 if (ugd->uninstall) {
706 mgrapp_view_info_destroy(ugd);
707 _notify_by_uninstall((void*)ugd);
708 ugd->uninstall = EINA_FALSE;
711 } else if (!strncmp(key, STR_END, strlen(key)) && !strncmp(val, STR_CANCEL, strlen(val))) {
719 static char *_convert_char_to_string(char ch)
723 char *str_buf = NULL;
724 str_buf = (char*)malloc(sizeof(char)*MAX_BUF_SIZE);
725 retv_if(str_buf == NULL, NULL);
726 memset(str_buf, 0, sizeof(char)*MAX_BUF_SIZE);
728 if (ch >= 'A' && ch <= 'Z') {
729 snprintf(str_buf, MAX_BUF_SIZE, "%c", ch);
730 } else if (ch >= 'a' && ch <= 'z') {
731 snprintf(str_buf, MAX_BUF_SIZE, "%c", ch - 'a' + 'A');
732 } else if (ch >= '0' && ch <= '9') {
733 snprintf(str_buf, MAX_BUF_SIZE, "%c", ch);
735 snprintf(str_buf, MAX_BUF_SIZE, "%s", "etc");
742 static int _compare_index_item_letter_cb(const void *a, const void *b)
746 retv_if(a == NULL, -1);
747 retv_if(b == NULL, -1);
749 const Elm_Object_Item *it1 = (const Elm_Object_Item*)a;
750 const Elm_Object_Item *it2 = (const Elm_Object_Item*)b;
752 const char *letter1 = elm_index_item_letter_get(it1);
753 const char *letter2 = elm_index_item_letter_get(it2);
755 MGR_APP_DEBUG("letter1: %s, letter2: %s", letter1, letter2);
758 len = (strlen(letter1) >= strlen(letter2)) ? strlen(letter1) : strlen(letter2);
761 return strncasecmp(letter1, letter2, len);
765 * _compare_data_index_item_letter_cb be used when _compare_index_item_letter_cb return 0.
767 static int _compare_data_index_item_letter_cb(const void *a, const void *b)
771 retv_if(a == NULL, -1);
772 retv_if(b == NULL, -1);
774 const Elm_Object_Item *it1 = (const Elm_Object_Item*)a;
775 const Elm_Object_Item *it2 = (const Elm_Object_Item*)b;
777 mgr_app_app_info_t *app_info1 = (mgr_app_app_info_t *)elm_object_item_data_get(it1);
778 mgr_app_app_info_t *app_info2 = (mgr_app_app_info_t *)elm_object_item_data_get(it2);
779 retv_if(app_info1 == NULL, -1);
780 retv_if(app_info2 == NULL, -1);
782 MGR_APP_DEBUG("letter1: %s, letter2: %s", app_info1->pkg_label, app_info2->pkg_label);
788 static void _register_index_item(Evas_Object *index, char *letter, Elm_Object_Item *item, Eina_Bool init)
792 MGR_APP_DEBUG("letter: %s", letter);
794 Elm_Object_Item *new_index_item = NULL;
795 Elm_Object_Item *temp_index_item = NULL;
796 Elm_Object_Item *temp_item = NULL;
797 char *temp_letter = NULL;
801 temp_item = elm_genlist_first_item_get(_genlist);
802 ret_if(temp_item == NULL);
804 for (i = 0; i < _installed_cnt; i++) {
805 temp_index_item = elm_index_item_find(index, temp_item);
807 /* indexed genlist item */
808 if (temp_index_item) {
809 temp_letter = elm_index_item_letter_get(temp_index_item);
810 ret_if(temp_letter == NULL);
812 if (letter[0] < temp_letter[0]) {
813 elm_index_item_insert_before(index, temp_item, letter, NULL, item);
817 temp_item = elm_genlist_item_next_get(temp_item);
820 elm_index_item_append(index, letter, NULL, item);
823 new_index_item = elm_index_item_find(index, item);
824 ret_if(new_index_item == NULL);
825 //elm_object_item_del_cb_set(new_index_item, _index_del_item_cb);
826 elm_object_item_data_set(new_index_item, (void*)item);
833 static void _index_del_item_cb(void *data, Evas_Object *obj, void *event_info)
837 ret_if(data == NULL);
838 Elm_Object_Item *item = (Elm_Object_Item*)data;
839 Elm_Object_Item *next_item = NULL;
840 Elm_Object_Item *prev_item = NULL;
841 Elm_Object_Item *index_item = NULL;
842 mgr_app_app_info_t *next_app_info = NULL;
843 char *next_letter = NULL;
846 /* change the index item */
847 next_item = elm_genlist_item_next_get(item);
850 next_app_info = (mgr_app_app_info_t *)elm_object_item_data_get(next_item);
851 ret_if(next_app_info == NULL);
853 index_item = (Elm_Object_Item*)event_info;
854 ret_if(index_item == NULL);
856 next_letter = _convert_char_to_string(next_app_info->pkg_label[0]);
857 ret_if(next_letter == NULL);
859 letter = elm_index_item_letter_get(index_item);
861 MGR_APP_DEBUG_ERR("letter is null.");
865 prev_item = elm_genlist_item_prev_get(item);
868 /* case: B-B', del:B */
869 if (letter[0] == next_letter[0]) {
870 _register_index_item(_index, next_letter, next_item, EINA_FALSE);
873 mgr_app_app_info_t *prev_app_info = (mgr_app_app_info_t *)elm_object_item_data_get(prev_item);
874 if (!prev_app_info) {
875 MGR_APP_DEBUG_ERR("prev_app_info is null.");
879 char *prev_letter = _convert_char_to_string(prev_app_info->pkg_label[0]);
881 MGR_APP_DEBUG_ERR("prev_letter is null.");
885 /* case: A-B'-B-B'', del:B */
886 if (letter[0] == prev_letter[0]) {
887 _register_index_item(_index, prev_letter, prev_item, EINA_FALSE);
889 /* case: A-B-B'-B'', del:B */
890 } else if (letter[0] == next_letter[0]) {
891 _register_index_item(_index, next_letter, next_item, EINA_FALSE);
894 MGR_APP_MEM_FREE(prev_letter);
896 MGR_APP_MEM_FREE(next_letter);
899 MGR_APP_DEBUG("next_item is null");
905 MGR_APP_MEM_FREE(next_letter);
910 static void _gl_realized(void *data, Evas_Object *obj, void *event_info)
915 ret_if(event_info == NULL);
917 if (event_info == elm_genlist_item_next_get(elm_genlist_first_item_get(obj))) { // first is a separator
918 elm_object_item_signal_emit(event_info, "elm,state,top", "");
919 } else if (event_info == elm_genlist_item_prev_get(elm_genlist_last_item_get(obj))) { // last is a separator
920 elm_object_item_signal_emit(event_info, "elm,state,bottom", "");
922 elm_object_item_signal_emit(event_info, "elm,state,center", "");
928 static int _pkgmgr_iter_fn(pkgmgr_pkginfo_h handle, void *data)
932 retv_if(NULL == handle, 0);
934 mgr_app_app_info_t *app_info = NULL;
936 app_info = (mgr_app_app_info_t*)malloc(sizeof(mgr_app_app_info_t));
937 retv_if(app_info == NULL, -1);
938 memset(app_info, 0, sizeof(mgr_app_app_info_t));
940 _get_appinfo_from_pkgmgr(handle, app_info);
942 _installed_list = g_list_append(_installed_list, (gpointer)app_info);
944 MGR_APP_DEBUG("installed cnt %d", _installed_cnt);
950 static void _create_genlist_app_list(seg_type_t seg, void *data)
954 ret_if(data == NULL);
955 struct ug_data *ugd = (struct ug_data*)data;
956 Evas_Object *genlist = NULL;
957 Evas_Object *index = NULL;
958 Elm_Object_Item *item_sep = NULL;
959 Evas_Object *layout = NULL;
961 Elm_Object_Item *item = NULL;
963 char prev_letter[MAX_BUF_SIZE] = {0, };
965 mgr_app_app_info_t *app_info = NULL;
967 int r = PKGMGR_R_ERROR;
969 bool is_running = false;
971 /* set the genlist item style */
972 itc = elm_genlist_item_class_new();
974 itc_sep = elm_genlist_item_class_new();
975 ret_if(itc_sep == NULL);
977 itc->item_style = ITC_ITEM_STYLE;
978 itc->func.text_get = _gl_label_get;
979 itc->func.content_get = _gl_icon_get;
980 itc->func.state_get = NULL;
981 itc->func.del = _gl_del;
983 itc_sep->item_style = ITC_SEP_ITEM_STYLE;
984 itc_sep->func.text_get = NULL;
985 itc_sep->func.content_get= NULL;
986 itc_sep->func.state_get = NULL;
987 itc_sep->func.del = NULL;
989 layout = mgr_app_create_layout_file(ugd->navi_bar, EDC_FILE, EDC_GROUPS);
990 ret_if(NULL == layout);
993 index = elm_index_add(layout);
994 ret_if(index == NULL);
995 elm_object_part_content_set(layout, "elm.swallow.content.index", index);
996 evas_object_show(index);
1000 genlist = elm_genlist_add(layout);
1001 ret_if(genlist == NULL);
1002 elm_object_part_content_set(layout, "elm.swallow.content.genlist", genlist);
1003 evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1004 evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
1005 elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
1006 elm_genlist_block_count_set(genlist, GENLIST_BLOCK_CNT);
1007 elm_scroller_policy_set(genlist, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO);
1008 evas_object_show(genlist);
1009 evas_object_smart_callback_add(genlist, "realized", _gl_realized, NULL);
1017 item_sep = elm_genlist_item_append(genlist, itc_sep, NULL, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
1019 elm_genlist_item_select_mode_set(item_sep, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
1021 for (i = 0; i < _installed_cnt; i++) {
1023 app_info = (mgr_app_app_info_t *)g_list_nth_data(_installed_list, i);
1024 if (NULL == app_info) {
1025 MGR_APP_DEBUG_ERR("app_info is a null");
1028 MGR_APP_DEBUG("genlist %d app_info->pkg_label: %s", i, app_info->pkg_label);
1030 if (LIST_SEG_TYPE_RUNNING == seg
1031 && APP_MANAGER_ERROR_NONE == app_manager_is_running(app_info->main_appid, &is_running)
1032 && false == is_running) {
1036 item = elm_genlist_item_append(genlist, itc, (void*)app_info, NULL, ELM_GENLIST_ITEM_NONE, _gl_sel, (void*)ugd);
1038 /* fast scroll insertion */
1039 letter = _convert_char_to_string(app_info->pkg_label[0]);
1040 if (item && strncmp(letter, prev_letter, MAX_BUF_SIZE) != 0) {
1041 _register_index_item(index, letter, item, EINA_TRUE);
1042 strncpy(prev_letter, letter, MAX_BUF_SIZE);
1045 MGR_APP_MEM_FREE(letter);
1050 item_sep = elm_genlist_item_append(genlist, itc_sep, NULL, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
1052 elm_genlist_item_select_mode_set(item_sep, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
1054 evas_object_smart_callback_add(index, "delay,changed", _index_delayed_changed, index);
1055 evas_object_smart_callback_add(index, "changed", _index_changed, NULL);
1056 evas_object_smart_callback_add(index, "selected", _index_selected, NULL);
1058 elm_object_item_part_content_set(_navi_it, "elm.swallow.content", layout);
1060 /* register pkg-mgr listener */
1061 ret_if(ugd->pc_listen == NULL);
1062 r = pkgmgr_client_listen_status(ugd->pc_listen, mgrapp_view_listen_cb, (void*)ugd);
1064 MGR_APP_DEBUG_ERR("status listen failed!\n");
1071 static void _doubletap_sensor_cb(void *data)
1075 ret_if(NULL == data);
1077 Evas_Object *genlist = (Evas_Object*)data;
1078 Elm_Object_Item *item = NULL;
1080 item = elm_genlist_first_item_get(genlist);
1081 ret_if(NULL == item);
1083 elm_genlist_item_show(item, ELM_GENLIST_ITEM_SCROLLTO_TOP);
1088 static void _create_genlist_app_cb(void *data, Evas_Object *obj, void *event_info)
1092 ret_if(NULL == data);
1094 _create_genlist_app_list(LIST_SEG_TYPE_APPLICATION, data);
1099 static void _create_genlist_all_cb(void *data, Evas_Object *obj, void *event_info)
1103 ret_if(NULL == data);
1105 _create_genlist_app_list(LIST_SEG_TYPE_ALL, data);
1110 static void _create_genlist_running_cb(void *data, Evas_Object *obj, void *event_info)
1114 ret_if(NULL == data);
1116 _create_genlist_app_list(LIST_SEG_TYPE_RUNNING, data);
1121 void mgrapp_view_list_create(void *data)
1125 ret_if(data == NULL);
1127 struct ug_data *ugd = (struct ug_data *)data;
1128 Evas_Object *layout = NULL;
1129 Evas_Object *back_btn = NULL;
1130 Evas_Object *tabbar = NULL;
1131 Elm_Object_Item *tool_it = NULL;
1132 Elm_Object_Item *navi_it = NULL;
1135 mgrapp_set_view_type(VIEW_TYPE_APP_LIST);
1137 Evas_Object *nocontents = NULL;
1138 nocontents = elm_layout_add(ugd->navi_bar);
1139 ret_if(NULL == nocontents);
1140 elm_layout_theme_set(nocontents, "layout", "nocontents", "full");
1143 back_btn = elm_button_add(ugd->navi_bar);
1144 ret_if(NULL == back_btn);
1145 elm_object_style_set(back_btn, "naviframe/end_btn/default");
1146 evas_object_smart_callback_add(back_btn, "clicked", _app_list_back_cb, (void*)ugd);
1148 _navi_it = navi_it = elm_naviframe_item_push(ugd->navi_bar, MGRAPP_STR_MANAGE_APPLICATIONS, back_btn, NULL, nocontents, "tabbar");
1150 r = pkgmgr_pkginfo_get_list(_pkgmgr_iter_fn, data);
1151 if (PKGMGR_R_OK != r) {
1152 MGR_APP_DEBUG_ERR("pkgmgr_get_pkg_list failed. %d", r);
1155 /* sorting by pkg_label */
1156 _installed_list = g_list_sort(_installed_list, _app_list_qsort_cb);
1158 /* create toolbar */
1159 tabbar = elm_toolbar_add(ugd->navi_bar);
1160 ret_if(NULL == tabbar);
1161 elm_toolbar_shrink_mode_set(tabbar, ELM_TOOLBAR_SHRINK_EXPAND);
1162 elm_object_style_set(tabbar, "tabbar");
1163 elm_object_item_part_content_set(navi_it, "tabbar", tabbar);
1165 _tabbar_item[LIST_SEG_TYPE_APPLICATION] = elm_toolbar_item_append(tabbar, NULL, MGRAPP_STR_APPLICATION, _create_genlist_app_cb, (void*)ugd);
1166 _tabbar_item[LIST_SEG_TYPE_RUNNING] = elm_toolbar_item_append(tabbar, NULL, MGRAPP_STR_RUNNING, _create_genlist_running_cb, (void*)ugd);
1167 _tabbar_item[LIST_SEG_TYPE_ALL] = elm_toolbar_item_append(tabbar, NULL, MGRAPP_STR_ALL, _create_genlist_all_cb, (void*)ugd);
1168 elm_toolbar_item_selected_set(_tabbar_item[LIST_SEG_TYPE_APPLICATION], EINA_TRUE);
1170 mgr_app_doubletap_sensor_set_cb(_doubletap_sensor_cb, _genlist);
1171 mgr_app_doubletap_sensor_enable();
1176 void mgrapp_view_list_update(void *data)
1181 mgr_app_doubletap_sensor_set_cb(_doubletap_sensor_cb, _genlist);
1182 mgr_app_doubletap_sensor_enable();