add recent web history 82/48982/6
authorSoohye Shin <soohye.shin@samsung.com>
Fri, 2 Oct 2015 12:02:03 +0000 (21:02 +0900)
committerSoohye Shin <soohye.shin@samsung.com>
Mon, 5 Oct 2015 08:39:20 +0000 (17:39 +0900)
Change-Id: If68e0159b9aa7b5459a0bd11b66dc43694227708
Signed-off-by: Soohye Shin <soohye.shin@samsung.com>
CMakeLists.txt
include/datamgr.h
include/defs.h
org.tizen.home.xml.in
packaging/org.tizen.home.spec
src/data/data_recent.c
src/view/view_recent.c

index 1aecd4e..3cc2b1e 100644 (file)
@@ -75,6 +75,7 @@ pkg_check_modules(PKGS REQUIRED
                tv-service
                ecore-wayland
                ui-gadget-1
+               capi-web-history
                capi-appfw-application)
 
 FOREACH(flag ${PKGS_CFLAGS})
index 657fdd9..81b5fc2 100644 (file)
@@ -43,12 +43,24 @@ struct datamgr {
        struct data_class *dclass;
 };
 
+enum thumbnail_type {
+       THUMBNAIL_FILE,
+       THUMBNAIL_DATA
+};
+
+struct thumbnail_data {
+       enum thumbnail_type type;
+       char *file;
+       char *format;
+       void *data;
+       int size;
+};
+
 struct datamgr_item {
        char *title;
        char *subtitle;
        char *icon;
        char *focus_icon;
-       char *thumbnail;
        char *parameter;
        char *key;
        char *value;
@@ -56,6 +68,7 @@ struct datamgr_item {
        enum datamgr_item_select_action action;
        int type;
        time_t time;
+       struct thumbnail_data *thumbnail;
 };
 
 struct data_class {
index 740e1ca..4611d42 100644 (file)
 #define FONT_LIGHT "BreezeSans:style=Light"
 #define FONT_REGULAR "BreezeSans:style=Regular"
 
+#define FORMAT_PNG "png"
+
 #endif /* __AIR_HOME_DEFS_H__ */
index 266b6f0..8da1544 100644 (file)
@@ -9,5 +9,6 @@
        <privileges>
                <privilege>http://tizen.org/privilege/internal/usermanagement</privilege>
                <privilege>http://tizen.org/privilege/appmanager.launch</privilege>
+               <privilege>http://tizen.org/privilege/web-history.admin</privilege>
        </privileges>
 </manifest>
index 6f96790..ebbbefd 100644 (file)
@@ -21,6 +21,7 @@ BuildRequires: pkgconfig(tv-service)
 BuildRequires: pkgconfig(notification)
 BuildRequires: pkgconfig(ecore-wayland)
 BuildRequires: pkgconfig(ui-gadget-1)
+BuildRequires: pkgconfig(capi-web-history)
 BuildRequires: edje-bin
 BuildRequires: gettext-devel
 
index 24ab8c1..7bbb4b7 100644 (file)
@@ -26,6 +26,7 @@
 #include <app_media.h>
 #include <app_define.h>
 #include <app_contents.h>
+#include <web/web_history.h>
 #include <time.h>
 #include <ctype.h>
 
@@ -37,9 +38,9 @@
 #define BUF_TITLE_MAX 128
 #define MAX_BUF 64
 
-static struct datamgr_item *_new_datamgr_item(char *title, char *thumb,
-               char *subtitle, char *parameter, char *key, char *value,
-               char *icon, int type, time_t time)
+static struct datamgr_item *_new_datamgr_item(char *title, char *subtitle,
+               char *parameter, char *key, char *value, char *icon, int type,
+               time_t time)
 {
        struct datamgr_item *di;
 
@@ -50,13 +51,12 @@ static struct datamgr_item *_new_datamgr_item(char *title, char *thumb,
        }
 
        di->title = strdup(title);
-       di->focus_icon = strdup(icon);
+       di->icon = strdup(icon);
        di->type = type;
        di->parameter = strdup(parameter);
        di->action = ITEM_SELECT_ACTION_LAUNCH;
        di->time = time;
-       if (thumb)
-               di->icon = strdup(thumb);
+
        if (subtitle)
                di->subtitle = strdup(subtitle);
        if (key && value) {
@@ -74,6 +74,7 @@ static void _app_list_foreach(gpointer data, gpointer user_data)
        pkgmgrinfo_appinfo_h handle;
        int r;
        struct datamgr_item *di;
+       struct thumbnail_data *thumbnail;
        struct datamgr *dm;
        bool nodisplay;
 
@@ -113,10 +114,17 @@ static void _app_list_foreach(gpointer data, gpointer user_data)
        if (!thumb || !strcmp(thumb, ""))
                thumb = IMAGE_RECENT_THUMB_APP;
 
-       di = _new_datamgr_item(label, thumb, NULL, rdata->id, NULL, NULL,
+       di = _new_datamgr_item(label, NULL, rdata->id, NULL, NULL,
                        IMAGE_RECENT_ICON_APP, 0, rdata->time);
-       if (di)
+       if (di) {
+               thumbnail = calloc(1, sizeof(*thumbnail));
+               if (thumbnail) {
+                       thumbnail->file = strdup(thumb);
+                       thumbnail->type = THUMBNAIL_FILE;
+                       di->thumbnail = thumbnail;
+               }
                dm->list = eina_list_append(dm->list, di);
+       }
 
        pkgmgrinfo_appinfo_destroy_appinfo(handle);
 }
@@ -148,6 +156,7 @@ static void _channel_list_foreach(gpointer data, gpointer user_data)
 {
        struct recent_data *rdata;
        struct datamgr_item *di;
+       struct thumbnail_data *thumbnail;
        struct datamgr *dm;
        TvServiceChannel channel;
        int r;
@@ -180,11 +189,18 @@ static void _channel_list_foreach(gpointer data, gpointer user_data)
 
        _get_program(atoi(rdata->id), &program);
 
-       di = _new_datamgr_item(buf, thumb ? thumb : IMAGE_RECENT_THUMB_CHANNEL,
-                       program, APP_ID_LIVETV, PARAM_SERVICE_ID,
+       di = _new_datamgr_item(buf, program, APP_ID_LIVETV, PARAM_SERVICE_ID,
                        rdata->id, IMAGE_RECENT_ICON_CHANNEL, 1, rdata->time);
-       if (di)
+       if (di) {
+               thumbnail = calloc(1, sizeof(*thumbnail));
+               if (thumbnail) {
+                       thumbnail->file = strdup(thumb ? thumb :
+                                       IMAGE_RECENT_THUMB_CHANNEL);
+                       thumbnail->type = THUMBNAIL_FILE;
+                       di->thumbnail = thumbnail;
+               }
                dm->list = eina_list_append(dm->list, di);
+       }
 }
 
 static void _set_up_string(char *str)
@@ -199,6 +215,7 @@ static void _gallery_list_foreach(gpointer data, gpointer user_data)
 {
        struct recent_data *rdata;
        struct datamgr_item *di;
+       struct thumbnail_data *thumbnail;
        struct datamgr *dm;
        app_media *am;
        app_media_info *aminfo;
@@ -240,11 +257,17 @@ static void _gallery_list_foreach(gpointer data, gpointer user_data)
        _set_up_string(day);
        snprintf(buf, sizeof(buf), "%s, %s", day, date);
 
-       di = _new_datamgr_item(buf, aminfo->thumbnail_path, NULL,
-                       APP_ID_MEDIAHUB, PARAM_MEDIA_ID, rdata->id,
-                       IMAGE_RECENT_ICON_GALLERY, 1, rdata->time);
-       if (di)
+       di = _new_datamgr_item(buf, NULL, APP_ID_MEDIAHUB, PARAM_MEDIA_ID,
+                       rdata->id, IMAGE_RECENT_ICON_GALLERY, 1, rdata->time);
+       if (di) {
+               thumbnail = calloc(1, sizeof(*thumbnail));
+               if (thumbnail) {
+                       thumbnail->file = strdup(aminfo->thumbnail_path);
+                       thumbnail->type = THUMBNAIL_FILE;
+                       di->thumbnail = thumbnail;
+               }
                dm->list = eina_list_append(dm->list, di);
+       }
 
        app_media_destroy(am);
        media_info_destroy(media);
@@ -269,6 +292,7 @@ static void _movie_list_foreach(gpointer data, gpointer user_data)
 {
        struct recent_data *rdata;
        struct datamgr_item *di;
+       struct thumbnail_data *thumbnail;
        struct datamgr *dm;
        app_media *am;
        app_media_info *aminfo;
@@ -308,11 +332,18 @@ static void _movie_list_foreach(gpointer data, gpointer user_data)
        if (aminfo->video && aminfo->video->duration)
                _get_duration(aminfo->video->duration, dur, sizeof(dur));
 
-       di = _new_datamgr_item(aminfo->title, aminfo->thumbnail_path,
-                       dur, APP_ID_MEDIAHUB, PARAM_MEDIA_ID,
-                       rdata->id, IMAGE_RECENT_ICON_MOVIE, 1, rdata->time);
-       if (di)
+       di = _new_datamgr_item(aminfo->title, dur, APP_ID_MEDIAHUB,
+                       PARAM_MEDIA_ID, rdata->id, IMAGE_RECENT_ICON_MOVIE, 1,
+                       rdata->time);
+       if (di) {
+               thumbnail = calloc(1, sizeof(*thumbnail));
+               if (thumbnail) {
+                       thumbnail->file = strdup(aminfo->thumbnail_path);
+                       thumbnail->type = THUMBNAIL_FILE;
+                       di->thumbnail = thumbnail;
+               }
                dm->list = eina_list_append(dm->list, di);
+       }
 
        app_media_destroy(am);
        media_info_destroy(media);
@@ -322,6 +353,7 @@ static void _music_list_foreach(gpointer data, gpointer user_data)
 {
        struct recent_data *rdata;
        struct datamgr_item *di;
+       struct thumbnail_data *thumbnail;
        struct datamgr *dm;
        app_media *am;
        app_media_info *aminfo;
@@ -357,11 +389,18 @@ static void _music_list_foreach(gpointer data, gpointer user_data)
                return;
        }
 
-       di = _new_datamgr_item(aminfo->title, aminfo->thumbnail_path,
-                       aminfo->audio->artist, APP_ID_MEDIAHUB, PARAM_MEDIA_ID,
-                       rdata->id, IMAGE_RECENT_ICON_MUSIC, 1, rdata->time);
-       if (di)
+       di = _new_datamgr_item(aminfo->title, aminfo->audio->artist,
+                       APP_ID_MEDIAHUB, PARAM_MEDIA_ID, rdata->id,
+                       IMAGE_RECENT_ICON_MUSIC, 1, rdata->time);
+       if (di) {
+               thumbnail = calloc(1, sizeof(*thumbnail));
+               if (thumbnail) {
+                       thumbnail->file = strdup(aminfo->thumbnail_path);
+                       thumbnail->type = THUMBNAIL_FILE;
+                       di->thumbnail = thumbnail;
+               }
                dm->list = eina_list_append(dm->list, di);
+       }
 
        app_media_destroy(am);
        media_info_destroy(media);
@@ -386,6 +425,18 @@ static bool _load_recent(struct datamgr *dm, enum app_contents_type type,
        return true;
 }
 
+static void _unload_thumbnail(struct thumbnail_data *thumbnail)
+{
+       if (!thumbnail)
+               return;
+
+       free(thumbnail->file);
+       free(thumbnail->data);
+       free(thumbnail->format);
+
+       free(thumbnail);
+}
+
 static void _unload_recent(struct datamgr *dm)
 {
        struct datamgr_item *di;
@@ -399,6 +450,8 @@ static void _unload_recent(struct datamgr *dm)
                free(di->key);
                free(di->value);
 
+               _unload_thumbnail(di->thumbnail);
+
                free(di);
        }
 
@@ -424,6 +477,7 @@ static int _sort_list(const void *data1, const void *data2)
 static bool _load_recent_notification(struct datamgr *dm)
 {
        struct datamgr_item *di;
+       struct thumbnail_data *thumbnail;
        int time, count;
        char buf[MAX_BUF];
 
@@ -440,13 +494,104 @@ static bool _load_recent_notification(struct datamgr *dm)
                return false;
        }
 
-       di = _new_datamgr_item(MESSAGE_NOTIFICATION, IMAGE_RECENT_THUMB_NOTI,
-                       buf, APP_ID_INFOSQUARE, NULL, NULL,
-                       IMAGE_RECENT_ICON_APP, 0, time);
-       if (di)
+       di = _new_datamgr_item(MESSAGE_NOTIFICATION, buf, APP_ID_INFOSQUARE,
+                       NULL, NULL, IMAGE_RECENT_ICON_APP, 0, time);
+       if (di) {
+               thumbnail = calloc(1, sizeof(*thumbnail));
+               if (thumbnail) {
+                       thumbnail->file = strdup(IMAGE_RECENT_THUMB_NOTI);
+                       thumbnail->type = THUMBNAIL_FILE;
+                       di->thumbnail = thumbnail;
+               }
                dm->list = eina_list_append(dm->list, di);
+       }
+
+       return true;
+}
+
+static bool _load_recent_web(struct datamgr *dm)
+{
+       int r, time, count, *ids, w, h, size;
+       char *title, *url;
+       struct datamgr_item *di;
+       struct thumbnail_data *thumbnail;
+       unsigned char *value;
+       bp_history_rows_cond_fmt conds;
+
+       conds.limit = 1;
+       conds.offset = 0;
+       conds.ordering = 1;
+       conds.order_offset = BP_HISTORY_O_FREQUENCY;
+       conds.period_offset = BP_HISTORY_O_DATE_CREATED;
+       conds.period_type = BP_HISTORY_DATE_ALL;
+
+       r = bp_history_adaptor_initialize();
+       if (r < 0) {
+               _ERR("failed to initialize history adaptor");
+               return false;
+       }
+
+       ids = NULL;
+       count = 0;
+       r = bp_history_adaptor_get_cond_ids_p(&ids, &count, &conds,
+                       BP_HISTORY_O_TITLE | BP_HISTORY_O_URL, NULL, 1);
+       if (r < 0 || count == 0) {
+               _ERR("failed to get cond ids of history");
+               goto err;
+       }
+
+       title = NULL;
+       r = bp_history_adaptor_get_title(ids[0], &title);
+       if (r < 0) {
+               _ERR("failed to get title of history");
+               goto err;
+       }
+
+       r = bp_history_adaptor_get_url(ids[0], &url);
+       if (r < 0) {
+               _ERR("failed to get url of history");
+               goto err;
+       }
+
+       r = bp_history_adaptor_get_date_visited(ids[0], &time);
+       if (r < 0) {
+               _ERR("failed to get icon of history");
+               goto err;
+       }
+
+       r = bp_history_adaptor_get_snapshot(ids[0], &w, &h, &value, &size);
+       if (r < 0) {
+               _ERR("failed to get snapshot of history");
+               goto err;
+       }
+
+       di = _new_datamgr_item(title, url, APP_ID_BROWSER, NULL, NULL,
+                       IMAGE_RECENT_ICON_WEB, 1, time);
+       if (!di)
+               goto err;
+
+       thumbnail = calloc(1, sizeof(*thumbnail));
+       if (thumbnail) {
+               thumbnail->type = THUMBNAIL_DATA;
+               thumbnail->data = calloc(1, size);
+               if (thumbnail->data) {
+                       memcpy(thumbnail->data, value, size);
+                       thumbnail->format = strdup(FORMAT_PNG);
+                       thumbnail->size = size;
+                       di->thumbnail = thumbnail;
+               } else
+                       free(thumbnail);
+       }
+       dm->list = eina_list_append(dm->list, di);
+
+       free(ids);
+       bp_history_adaptor_deinitialize();
 
        return true;
+err:
+       free(ids);
+       bp_history_adaptor_deinitialize();
+       return false;
 }
 
 static Eina_List *_get_items(struct datamgr *dm)
@@ -476,6 +621,9 @@ static Eina_List *_get_items(struct datamgr *dm)
        if (!_load_recent_notification(dm))
                _ERR("failed to load recent notification contents");
 
+       if (!_load_recent_web(dm))
+               _ERR("failed to load recent web content");
+
        dm->list = eina_list_sort(dm->list, 0, _sort_list);
 
        return dm->list;
index 9899855..1f682c7 100644 (file)
@@ -73,7 +73,7 @@ static void _focused(int id, void *data, Evas_Object *obj,
 
                bi = data;
                bi->priv->cur = bi;
-               /* fallthrought */
+               /* fallthrough */
        case INPUT_HANDLER_TYPE_DELETE:
                elm_object_signal_emit(obj, SIG_FOCUS, SRC_PROG);
                break;
@@ -295,8 +295,8 @@ static void _set_item_bg(struct color_data bg, Evas_Object *eo,
        elm_object_part_content_set(eo, part, rect);
 }
 
-static Evas_Object *_set_thumb(Evas_Object *eo, const char *file,
-               const char *part)
+static Evas_Object *_add_thumb(Evas_Object *eo,
+               struct thumbnail_data *thumbnail)
 {
        Evas_Object *image;
        int w, h;
@@ -307,20 +307,38 @@ static Evas_Object *_set_thumb(Evas_Object *eo, const char *file,
                return NULL;
        }
 
-       if (!elm_image_file_set(image, file, NULL)) {
-               if (!elm_image_file_set(image, IMAGE_RECENT_THUMB_APP, NULL)) {
-                       _ERR("failed to set image file");
+       switch (thumbnail->type) {
+       case THUMBNAIL_FILE:
+               if (!elm_image_file_set(image, thumbnail->file, NULL)) {
+                       if (!elm_image_file_set(image, IMAGE_RECENT_THUMB_APP,
+                                       NULL)) {
+                               _ERR("failed to set image file");
+                               evas_object_del(image);
+                               return NULL;
+                       }
+               }
+               break;
+       case THUMBNAIL_DATA:
+               if (!elm_image_memfile_set(image, thumbnail->data,
+                               thumbnail->size, thumbnail->format, NULL)) {
+                       _ERR("failed to set memfile");
                        evas_object_del(image);
                        return NULL;
                }
+               break;
+       default:
+               _ERR("Invalid type");
+               evas_object_del(image);
+               return NULL;
        }
+
        elm_image_object_size_get(image, &w, &h);
        if (w <= IMAGE_MAX_SIZE && h <= IMAGE_MAX_SIZE)
                elm_image_resizable_set(image, EINA_FALSE, EINA_FALSE);
        else
                elm_image_fill_outside_set(image, EINA_TRUE);
 
-       elm_object_part_content_set(eo, part, image);
+       elm_object_part_content_set(eo, PART_RECENT_THUMBNAIL, image);
 
        return image;
 }
@@ -358,10 +376,14 @@ static struct _bar_item *_pack_item(struct _priv *priv, Evas_Object *box,
        }
        evas_object_show(eo);
 
-       ic = utils_add_icon(eo, di->focus_icon, PART_RECENT_ICON);
+       ic = utils_add_icon(eo, di->icon, PART_RECENT_ICON);
        if (!ic)
                _ERR("failed to add icon");
 
+       thumb = _add_thumb(eo, di->thumbnail);
+       if (!thumb)
+               _ERR("failed to add thumbnail");
+
        lbl = utils_add_label(eo, di->title, STYLE_LABEL_RECENT_TITLE,
                        PART_RECENT_TITLE);
        if (!lbl) {
@@ -371,16 +393,6 @@ static struct _bar_item *_pack_item(struct _priv *priv, Evas_Object *box,
                return NULL;
        }
 
-       if (di->icon) {
-               thumb = _set_thumb(eo, di->icon, PART_RECENT_THUMBNAIL);
-               if (!thumb) {
-                       _ERR("failed to add thumb");
-                       evas_object_del(eo);
-                       free(bi);
-                       return NULL;
-               }
-       }
-
        if (di->subtitle) {
                sub_lbl = utils_add_label(eo, di->subtitle,
                                STYLE_LABEL_RECENT_SUBTITLE,