change to use app-utils for getting the list for web history 37/49037/4
authorSoohye Shin <soohye.shin@samsung.com>
Mon, 5 Oct 2015 12:35:28 +0000 (21:35 +0900)
committerSoohye Shin <soohye.shin@samsung.com>
Tue, 6 Oct 2015 12:23:04 +0000 (21:23 +0900)
Change-Id: I2f508c2afe4133464bf531504cece7d5cee5cd50
Signed-off-by: Soohye Shin <soohye.shin@samsung.com>
src/data/data_recent.c

index 7bbb4b7..5b0de58 100644 (file)
@@ -406,6 +406,79 @@ static void _music_list_foreach(gpointer data, gpointer user_data)
        media_info_destroy(media);
 }
 
+static void _web_list_foreach(gpointer data, gpointer user_data)
+{
+       struct recent_data *rdata;
+       struct datamgr *dm;
+       int r, w, h, size, time, id;
+       char *title, *url;
+       unsigned char *value;
+       struct thumbnail_data *thumbnail;
+       struct datamgr_item *di;
+
+       if (!data || !user_data) {
+               _ERR("Invalid argument");
+               return;
+       }
+
+       rdata = data;
+       dm = user_data;
+
+       r = bp_history_adaptor_initialize();
+       if (r < 0) {
+               _ERR("Initialize history adaptor failed.");
+               return;
+       }
+
+       id = atoi(rdata->id);
+
+       r = bp_history_adaptor_get_title(id, &title);
+       if (r < 0) {
+               _ERR("failed to get title of history");
+               goto err;
+       }
+
+       r = bp_history_adaptor_get_url(id, &url);
+       if (r < 0) {
+               _ERR("failed to get url of history");
+               goto err;
+       }
+
+       r = bp_history_adaptor_get_date_visited(id, &time);
+       if (r < 0) {
+               _ERR("failed to get icon of history");
+               goto err;
+       }
+
+       r = bp_history_adaptor_get_snapshot(id, &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);
+
+err:
+       bp_history_adaptor_deinitialize();
+}
+
 static bool _load_recent(struct datamgr *dm, enum app_contents_type type,
                int count, GFunc func)
 {
@@ -509,91 +582,6 @@ static bool _load_recent_notification(struct datamgr *dm)
        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)
 {
        if (!dm) {
@@ -621,8 +609,8 @@ 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");
+       if (!_load_recent(dm, CONTENTS_WEB, 1, _web_list_foreach))
+               _ERR("failed to load recent web contents");
 
        dm->list = eina_list_sort(dm->list, 0, _sort_list);
 
@@ -690,7 +678,10 @@ static int _select(struct datamgr_item *di)
 
 static void _clear(struct datamgr *dm)
 {
-       if (!app_contents_recent_clear_all())
+       int r;
+
+       r = app_contents_recent_clear_all();
+       if (r != APP_CONTENTS_ERROR_NONE)
                _ERR("failed to clear all recents");
 }