#include <glib.h>
#include <pkgmgr-info.h>
#include <tv_service_proxy_channel_info.h>
+#include <media_content.h>
+#include <app_media.h>
#include "data_recent.h"
#include "datamgr.h"
#include "utils.h"
#include "defs.h"
-/* FIXME: change default thumbnail */
-#define THUMB_DEFAULT "/usr/share/icons/default/small/apps_img_app_default_4x2.png"
-
#define BUF_TITLE_MAX 128
static struct datamgr_item *_new_datamgr_item(char *title, char *thumb,
- char *parameter, char *icon, int type)
+ char *subtitle, char *parameter, char *key, char *value,
+ char *icon, int type)
{
struct datamgr_item *di;
di->type = type;
di->parameter = strdup(parameter);
di->action = ITEM_SELECT_ACTION_LAUNCH;
+ if (subtitle)
+ di->subtitle = strdup(subtitle);
+ if (key)
+ di->key = strdup(key);
+ if (value)
+ di->value = strdup(value);
return di;
}
static void _app_list_foreach(gpointer data, gpointer user_data)
{
struct recent_data *rdata;
- char *label, *thumb, *thumb_land;
+ char *label, *thumb;
pkgmgrinfo_appinfo_h handle;
int r;
struct datamgr_item *di;
return;
}
+ label = NULL;
+ thumb = NULL;
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);
+ r = pkgmgrinfo_appinfo_get_icon(handle, &thumb);
if (r != PMINFO_R_OK)
_ERR("failed to get app icon");
- if (!thumb_land || !strcmp(thumb_land, ""))
- thumb_land = THUMB_DEFAULT;
+ if (!thumb || !strcmp(thumb, ""))
+ thumb = IMAGE_RECENT_THUMB_APP;
- di = _new_datamgr_item(label, thumb_land, rdata->id, IMAGE_RECENT_APP,
- 0);
+ di = _new_datamgr_item(label, thumb, NULL, rdata->id, NULL, NULL,
+ IMAGE_RECENT_ICON_APP, 0);
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 void _channel_list_foreach(gpointer data, gpointer user_data)
{
struct recent_data *rdata;
channel.program_name ?
channel.program_name : "");
- di = _new_datamgr_item(buf, THUMB_DEFAULT, rdata->id,
- IMAGE_RECENT_CHANNEL, 1);
+ di = _new_datamgr_item(buf, IMAGE_RECENT_THUMB_CHANNEL, NULL,
+ PACKAGE_LIVETV, KEY_CHANNEL, rdata->id,
+ IMAGE_RECENT_ICON_CHANNEL, 1);
if (di)
dm->list = eina_list_append(dm->list, di);
}
-static bool _load_recent_channel(struct datamgr *dm)
+static void _gallery_list_foreach(gpointer data, gpointer user_data)
{
- GList *channel_list = NULL;
+ struct recent_data *rdata;
+ struct datamgr_item *di;
+ struct datamgr *dm;
+ app_media *am;
+ app_media_info *aminfo;
+ media_info_h media;
int r;
- r = app_contents_get_recent_list(CONTENTS_CHANNEL, 1, &channel_list);
- if (r != APP_CONTENTS_ERROR_NONE) {
- _ERR("failed to get recent channel list");
- return false;
+ if (!data || !user_data) {
+ _ERR("Invalid arguement");
+ return;
}
- g_list_foreach(channel_list, _channel_list_foreach, dm);
+ rdata = data;
+ dm = user_data;
- app_contents_free_recent_list(channel_list);
+ r = media_info_get_media_from_db(rdata->id, &media);
+ if (r != MEDIA_CONTENT_ERROR_NONE) {
+ _ERR("failed to get media");
+ return;
+ }
- return true;
+ am = app_media_create(media);
+ if (!am) {
+ _ERR("failed to create media");
+ media_info_destroy(media);
+ return;
+ }
+
+ aminfo = app_media_get_info(am);
+ if (!aminfo) {
+ _ERR("failed to get media info");
+ app_media_destroy(am);
+ media_info_destroy(media);
+ return;
+ }
+
+ di = _new_datamgr_item(aminfo->title, aminfo->thumbnail_path, NULL,
+ PACKAGE_MEDIAHUB, KEY_MEDIA, rdata->id,
+ IMAGE_RECENT_ICON_GALLERY, 1);
+
+ if (di)
+ dm->list = eina_list_append(dm->list, di);
+
+ app_media_destroy(am);
+ media_info_destroy(media);
}
-static bool _load_recent(struct datamgr *dm)
+static void _get_duration(int duration, char **str)
{
- if (!_load_recent_app(dm))
- _ERR("failed to load recent app");
+ char buf[BUF_TITLE_MAX];
+ int h, m, s, sec;
+
+ sec = duration / 1000;
+ h = sec / 3600;
+ m = (sec % 3600) / 60;
+ s = sec % 60;
+
+ if (h)
+ snprintf(buf, sizeof(buf), "%d:%02d:%02d", h, m, s);
+ else
+ snprintf(buf, sizeof(buf), "%d:%02d", m, s);
+
+ *str = buf;
+}
+
+static void _movie_list_foreach(gpointer data, gpointer user_data)
+{
+ struct recent_data *rdata;
+ struct datamgr_item *di;
+ struct datamgr *dm;
+ app_media *am;
+ app_media_info *aminfo;
+ media_info_h media;
+ int r;
+ char *dur = NULL;
+
+ if (!data || !user_data) {
+ _ERR("Invalid arguement");
+ return;
+ }
- if (!_load_recent_channel(dm))
- _ERR("failed to load recent channel");
+ rdata = data;
+ dm = user_data;
- /* It should be implemented later about media contents */
+ r = media_info_get_media_from_db(rdata->id, &media);
+ if (r != MEDIA_CONTENT_ERROR_NONE) {
+ _ERR("failed to get media");
+ return;
+ }
+
+ am = app_media_create(media);
+ if (!am) {
+ _ERR("failed to create media");
+ media_info_destroy(media);
+ return;
+ }
+
+ aminfo = app_media_get_info(am);
+ if (!aminfo) {
+ _ERR("failed to get media info");
+ app_media_destroy(am);
+ media_info_destroy(media);
+ return;
+ }
+
+ if (aminfo->video && aminfo->video->duration)
+ _get_duration(aminfo->video->duration, &dur);
+
+ di = _new_datamgr_item(aminfo->title, aminfo->thumbnail_path,
+ dur ? dur : NULL, PACKAGE_MEDIAHUB, KEY_MEDIA,
+ rdata->id, IMAGE_RECENT_ICON_MOVIE, 1);
+
+ if (di)
+ dm->list = eina_list_append(dm->list, di);
+
+ app_media_destroy(am);
+ media_info_destroy(media);
+}
+
+static void _music_list_foreach(gpointer data, gpointer user_data)
+{
+ struct recent_data *rdata;
+ struct datamgr_item *di;
+ struct datamgr *dm;
+ app_media *am;
+ app_media_info *aminfo;
+ media_info_h media;
+ int r;
+
+ if (!data || !user_data) {
+ _ERR("Invalid arguement");
+ return;
+ }
+
+ rdata = data;
+ dm = user_data;
+
+ r = media_info_get_media_from_db(rdata->id, &media);
+ if (r != MEDIA_CONTENT_ERROR_NONE) {
+ _ERR("failed to get media");
+ return;
+ }
+
+ am = app_media_create(media);
+ if (!am) {
+ _ERR("failed to create media");
+ media_info_destroy(media);
+ return;
+ }
+
+ aminfo = app_media_get_info(am);
+ if (!aminfo) {
+ _ERR("failed to get media info");
+ app_media_destroy(am);
+ media_info_destroy(media);
+ return;
+ }
+
+ di = _new_datamgr_item(aminfo->title, aminfo->thumbnail_path,
+ aminfo->audio->artist, PACKAGE_MEDIAHUB, KEY_MEDIA,
+ rdata->id, IMAGE_RECENT_ICON_MUSIC, 1);
+
+ if (di)
+ dm->list = eina_list_append(dm->list, di);
+
+ app_media_destroy(am);
+ media_info_destroy(media);
+}
+
+static bool _load_recent(struct datamgr *dm, enum app_contents_type type,
+ int count, GFunc func)
+{
+ GList *rlist = NULL;
+ int r;
+
+ r = app_contents_get_recent_list(type, count, &rlist);
+ if (r != APP_CONTENTS_ERROR_NONE) {
+ _ERR("failed to get recent list");
+ return false;
+ }
+
+ g_list_foreach(rlist, func, dm);
+
+ app_contents_free_recent_list(rlist);
return true;
}
EINA_LIST_FREE(dm->list, di) {
free(di->title);
+ free(di->subtitle);
free(di->icon);
free(di->focus_icon);
free(di->parameter);
+ free(di->key);
+ free(di->value);
free(di);
}
}
_unload_recent(dm);
- _load_recent(dm);
+
+ if (!_load_recent(dm, CONTENTS_APP, -1, _app_list_foreach))
+ _ERR("failed to load recent app contents");
+
+ if (!_load_recent(dm, CONTENTS_CHANNEL, 1, _channel_list_foreach))
+ _ERR("failed to load recent channel contents");
+
+ if (!_load_recent(dm, CONTENTS_GALLERY, 1, _gallery_list_foreach))
+ _ERR("failed to load recent gallery contents");
+
+ if (!_load_recent(dm, CONTENTS_MOVIE, 1, _movie_list_foreach))
+ _ERR("failed to load recent movie contents");
+
+ if (!_load_recent(dm, CONTENTS_MUSIC, 1, _music_list_foreach))
+ _ERR("failed to load recent music contents");
+
+ /* TODO: Sort for contents list */
return dm->list;
}
_unload_recent(dm);
+ media_content_disconnect();
tv_service_channel_info_destroy();
}
return false;
}
- return _load_recent(dm);
+ r = media_content_connect();
+ if (r != MEDIA_CONTENT_ERROR_NONE) {
+ tv_service_channel_info_destroy();
+ _ERR("failed to connect media content");
+ return false;
+ }
+
+ return true;
}
static void _select(struct datamgr_item *di)
switch (di->action) {
case ITEM_SELECT_ACTION_LAUNCH:
- utils_launch_app(di->parameter);
+ utils_launch_app(di->parameter, di->key, di->value);
break;
default:
_ERR("Invalid state");
static void _clear(struct datamgr *dm)
{
- int r;
-
- r = app_contents_recent_clear(CONTENTS_APP);
- if (r != APP_CONTENTS_ERROR_NONE) {
- _ERR("failed to clear app recent");
- return;
- }
-
- /* It should be implemeted later about media contents */
+ /* It should be implemented later */
}
static struct data_class dclass = {