#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)
{
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;
}
-
#include "utils.h"
#define MESSAGE_NO_CONTENTS "No Contents"
+#define PADDING_BOX 26
struct _priv {
Evas_Object *win;
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)
{
}
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);
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,
}
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);
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);
_unload_recent(priv);
- inputmgr_remove_callback(priv->base, &base_handler);
datamgr_fini(priv->dm);
evas_object_del(priv->base);
free(priv);