load recent app data 03/42503/3
authorSoohye Shin <soohye.shin@samsung.com>
Mon, 29 Jun 2015 10:42:42 +0000 (19:42 +0900)
committerSoohye Shin <soohye.shin@samsung.com>
Tue, 30 Jun 2015 07:40:49 +0000 (16:40 +0900)
Change-Id: Ic95c6ca437de3f888ccc23b4b98302c2c089f2c1
Signed-off-by: Soohye Shin <soohye.shin@samsung.com>
CMakeLists.txt
packaging/org.tizen.home.spec
src/data/data_recent.c
src/view/view_recent.c

index bfdffcc..f58ef70 100644 (file)
@@ -67,6 +67,7 @@ pkg_check_modules(PKGS REQUIRED
                gio-2.0
                libgum
                app-utils
+               pkgmgr-info
                capi-appfw-application)
 
 FOREACH(flag ${PKGS_CFLAGS})
index 594c5b3..11b37b6 100644 (file)
@@ -16,6 +16,7 @@ BuildRequires: pkgconfig(json-glib-1.0)
 BuildRequires: pkgconfig(gio-2.0)
 BuildRequires: pkgconfig(libgum)
 BuildRequires: pkgconfig(app-utils)
+BuildRequires: pkgconfig(pkgmgr-info)
 BuildRequires: edje-bin
 BuildRequires: gettext-devel
 
index 5bad2b3..460a06a 100644 (file)
 #include <Eina.h>
 #include <stdbool.h>
 #include <app_contents.h>
+#include <glib.h>
+#include <pkgmgr-info.h>
 
 #include "data_recent.h"
 #include "datamgr.h"
+#include "utils.h"
+
+/* FIXME: change default thumbnail */
+#define THUMB_DEFAULT "/usr/share/icons/default/small/apps_img_app_default_4x2.png"
+
+static struct datamgr_item *_new_datamgr_item(char *title, char *icon,
+               char *parameter, enum recent_item_type type)
+{
+       struct datamgr_item *di;
+
+       di = calloc(1, sizeof(*di));
+       if (!di) {
+               _ERR("failed to calloc datamgr item");
+               return NULL;
+       }
+
+       di->title = strdup(title);
+       di->icon = strdup(icon);
+       di->rtype = type;
+       di->parameter = strdup(parameter);
+       di->action = ITEM_SELECT_ACTION_LAUNCH;
+
+       return di;
+}
+
+static void _app_list_foreach(gpointer data, gpointer user_data)
+{
+       struct recent_data *rdata;
+       char *label, *thumb, *thumb_land;
+       pkgmgrinfo_appinfo_h handle;
+       int r;
+       struct datamgr_item *di;
+       struct datamgr *dm;
+
+       if (!data) {
+               _ERR("Invalid argument");
+               return;
+       }
+
+       rdata = data;
+       dm = user_data;
+
+       if (!strcmp(rdata->id, PACKAGE))
+               return;
+
+       r = pkgmgrinfo_appinfo_get_appinfo(rdata->id, &handle);
+       if (r != PMINFO_R_OK) {
+               _ERR("failed to get app info");
+               return;
+       }
+
+       r = pkgmgrinfo_appinfo_get_label(handle, &label);
+       if (r != PMINFO_R_OK) {
+               _ERR("failed to get app label");
+       }
+
+       r = pkgmgrinfo_appinfo_get_effectimage(handle, &thumb, &thumb_land);
+       if (r != PMINFO_R_OK) {
+               _ERR("failed to get app icon");
+       }
+
+       if (!strcmp(thumb_land, ""))
+               thumb_land = THUMB_DEFAULT;
+
+       di = _new_datamgr_item(label, thumb_land, rdata->id, RECENT_ITEM_ICON);
+       if (di)
+               dm->list = eina_list_append(dm->list, di);
+
+       pkgmgrinfo_appinfo_destroy_appinfo(handle);
+}
+
+static bool _load_recent_app(struct datamgr *dm)
+{
+       GList *app_list = NULL;
+       int r;
+
+       r = app_contents_get_recent_list(CONTENTS_APP, -1, &app_list);
+       if (r != APP_CONTENTS_ERROR_NONE) {
+               _ERR("failed to get recent app list");
+               return false;
+       }
+
+       g_list_foreach(app_list, _app_list_foreach, dm);
+
+       app_contents_free_recent_list(app_list);
+
+       return true;
+}
+
+static bool _load_recent(struct datamgr *dm)
+{
+       if (!_load_recent_app(dm))
+               _ERR("failed to load recent app");
+
+       /* It should be implemented later about media contents */
+
+       return true;
+}
+
+static void _unload_recent(struct datamgr *dm)
+{
+       struct datamgr_item *di;
+
+       EINA_LIST_FREE(dm->list, di) {
+               free(di->title);
+               free(di->subtitle);
+               free(di->icon);
+               free(di->parameter);
+
+               free(di);
+       }
+
+       dm->list = NULL;
+}
 
 static Eina_List *_get_items(struct datamgr *dm)
 {
@@ -29,29 +145,50 @@ static Eina_List *_get_items(struct datamgr *dm)
                return NULL;
        }
 
+       _unload_recent(dm);
+       _load_recent(dm);
+
        return dm->list;
 }
 
 static void _fini(struct datamgr *dm)
 {
-       /* It should be implemented later */
+       if (!dm) {
+               _ERR("Invalid argument");
+               return;
+       }
+
+       _unload_recent(dm);
 }
 
 static bool _init(struct datamgr *dm)
 {
-       /* It should be implemented later */
+       return _load_recent(dm);
+}
 
-       return true;
+static void _select(struct datamgr_item *di)
+{
+       if (!di || !di->parameter)
+               return;
+
+       switch (di->action) {
+       case ITEM_SELECT_ACTION_LAUNCH:
+               utils_launch_app(di->parameter);
+               break;
+       default:
+               _ERR("Invalid state");
+               return;
+       }
 }
 
 static struct data_class dclass = {
        .init = _init,
        .fini = _fini,
-       .get_items = _get_items
+       .get_items = _get_items,
+       .select = _select
 };
 
 struct data_class *datamgr_recent_get_dclass(void)
 {
        return &dclass;
 }
-
index be4c5a2..cbc981f 100644 (file)
@@ -27,6 +27,7 @@
 #include "utils.h"
 
 #define MESSAGE_NO_CONTENTS "No Contents"
+#define PADDING_BOX 26
 
 struct _priv {
        Evas_Object *win;
@@ -62,31 +63,6 @@ static bool _add_delete_btn(struct _priv *priv, Evas_Object *base)
        return true;
 }
 
-static void _key_down(int id, void *data, Evas *e, Evas_Object *obj,
-               Evas_Event_Key_Down *ev)
-{
-       struct _priv *priv;
-
-       if (!data) {
-               _ERR("Invalid argument");
-               return;
-       }
-
-       priv = data;
-
-       if (!strcmp(ev->keyname, KEY_BACK) ||
-                       !strcmp(ev->keyname, KEY_BACK_REMOTE)) {
-               elm_object_signal_emit(priv->base, SIG_HIDE_RECENT, SRC_PROG);
-       } else if (!strcmp(ev->keyname, KEY_ENTER) ||
-                       !strcmp(ev->keyname, KEY_ENTER_REMOTE)) {
-               /* It should be implemented later */
-       }
-}
-
-static input_handler base_handler = {
-       .key_down = _key_down
-};
-
 static void _hide_done(void *data, Evas_Object *obj, const char *emission,
                const char *source)
 {
@@ -141,7 +117,6 @@ static Evas_Object *_create(Evas_Object *win, void *data)
        }
 
        viewmgr_set_view_data(VIEW_RECENT, priv);
-       inputmgr_add_callback(base, 0, &base_handler, priv);
        elm_object_signal_callback_add(base, SIG_HIDE_RECENT_DONE, SRC_EDJE,
                        _hide_done, NULL);
 
@@ -160,9 +135,31 @@ static void _unfocused(int id, void *data, Evas_Object *obj,
        elm_object_signal_emit(obj, SIG_UNFOCUS, SRC_PROG);
 }
 
+static void _eo_key_down(int id, void *data, Evas *e, Evas_Object *obj,
+               Evas_Event_Key_Down *ev)
+{
+       struct _bar_item *bi;
+       struct _priv *priv;
+
+       if (!data)
+               return;
+
+       bi = data;
+       priv = bi->priv;
+
+       if (!strcmp(ev->keyname, KEY_DOWN) || !strcmp(ev->keyname, KEY_BACK)
+                       || !strcmp(ev->keyname, KEY_BACK_REMOTE)) {
+               elm_object_signal_emit(priv->base, SIG_HIDE_RECENT, SRC_PROG);
+       } else if (!strcmp(ev->keyname, KEY_ENTER) ||
+                       !strcmp(ev->keyname, KEY_ENTER_REMOTE)) {
+               datamgr_select_item(priv->dm, bi->di);
+       }
+}
+
 static input_handler eo_handler = {
        .focused = _focused,
-       .unfocused = _unfocused
+       .unfocused = _unfocused,
+       .key_down = _eo_key_down
 };
 
 static struct _bar_item *_pack_item(struct _priv *priv, Evas_Object *box,
@@ -197,13 +194,14 @@ static struct _bar_item *_pack_item(struct _priv *priv, Evas_Object *box,
        }
        evas_object_show(eo);
 
-       ic = utils_add_icon(eo, di->icon, PART_BAR_ITEM_ICON);
+       ic = utils_add_icon(eo, di->icon, PART_RECENT_THUMBNAIL);
        if (!ic) {
                _ERR("failed to add icon");
                evas_object_del(eo);
                free(bi);
                return NULL;
        }
+       elm_image_fill_outside_set(ic, EINA_TRUE);
 
        lbl = utils_add_label(eo, di->title, STYLE_LABEL_RECENT_TITLE,
                        PART_RECENT_TITLE);
@@ -260,6 +258,7 @@ static void _load_recent(struct _priv *priv)
        elm_object_content_set(scr, box);
        elm_object_part_content_set(priv->base, PART_RECENT_CONTENTS, scr);
        elm_object_part_text_set(priv->base, PART_RECENT_NO_CONTENTS, "");
+       elm_box_padding_set(box, PADDING_BOX * elm_config_scale_get(), 0);
 
        EINA_LIST_FOREACH(list, l, di) {
                bi = _pack_item(priv, box, di);
@@ -343,7 +342,6 @@ static void _destroy(void *data)
 
        _unload_recent(priv);
 
-       inputmgr_remove_callback(priv->base, &base_handler);
        datamgr_fini(priv->dm);
        evas_object_del(priv->base);
        free(priv);