History Implementation using Browser Provider. 04/40304/2 submit/tizen_tv/20150604.064555
authorPriyesh Lakar <pri.lakar@samsung.com>
Tue, 2 Jun 2015 06:37:56 +0000 (12:07 +0530)
committerPriyesh Lakar <pri.lakar@samsung.com>
Wed, 3 Jun 2015 05:39:48 +0000 (11:09 +0530)
Change-Id: Id6588ef903ae08804233e5de0e71092886f1313f

services/BookmarkService/CMakeLists.txt
services/HistoryService/HistoryService.h
services/HistoryService/src/HistoryService.cpp

index cf84d3e..e659588 100644 (file)
@@ -24,7 +24,14 @@ if(TIZEN_BUILD)
     target_link_libraries(${PROJECT_NAME} ${pkgs_LDFLAGS})
 endif(TIZEN_BUILD)
 
-pkg_check_modules(browser-provider REQUIRED "capi-web-bookmark")
+SET(bp_pkgs_list
+        capi-web-bookmark
+        capi-web-history
+    )
+
+pkg_check_modules(browser-provider REQUIRED "${bp_pkgs_list}")
+
+#pkg_check_modules(browser-provider REQUIRED "capi-web-bookmark")
 include_directories(${browser-provider_INCLUDE_DIRS})
 
 add_dependencies(${PROJECT_NAME} StorageService)
index 60be194..e92cf5d 100644 (file)
@@ -28,7 +28,7 @@
 #include "HistoryItem.h"
 #include "HistoryStorage.h"
 #include "StorageService.h"
-
+#include <web/web_history.h>
 #define DOMAIN_HISTORY_SERVICE "org.tizen.browser.historyservice"
 
 namespace tizen_browser
@@ -90,7 +90,7 @@ public:
     boost::signals2::signal<void (bool)>historyEmpty;
 private:
     bool m_testDbMod;;
-
+    std::vector<std::shared_ptr<HistoryItem>> history_list;
     std::shared_ptr<tizen_browser::services::StorageService> m_storageManager;
 
     /**
index 95ee009..cd2864e 100644 (file)
@@ -20,8 +20,8 @@
 
 #include "ServiceManager.h"
 #include "HistoryService.h"
+#include "HistoryItem.h"
 #include "AbstractWebEngine.h"
-
 namespace tizen_browser
 {
 namespace services
@@ -58,19 +58,79 @@ void HistoryService::setStorageServiceTestMode(bool testmode) {
        m_testDbMod = testmode;
 }
 
-/**
- * @throws HistoryException on error
- */
-void HistoryService::addHistoryItem(std::shared_ptr<HistoryItem> hi)
+int HistoryService::getHistoryItemsCount(){
+    return 1;
+    //return getStorageManager()->getHistoryItemsCount();
+}
+
+static int __get_duplicated_ids_p(int **ids, int *count, const int limit, const int offset,
+               const bp_history_offset order_column_offset, const int ordering,
+               const bp_history_offset check_column_offset,
+               const char *keyword, const int is_like)
 {
-    getStorageManager()->addHistoryItem(hi);
+    bp_history_rows_cond_fmt conds;
+    memset(&conds, 0x00, sizeof(bp_history_rows_cond_fmt));
+
+    conds.limit = limit;
+    conds.offset = offset;
+    conds.ordering = ordering;
+    conds.order_offset = order_column_offset;
+    conds.period_offset = BP_HISTORY_O_DATE_CREATED;
+    conds.period_type = BP_HISTORY_DATE_ALL;
+
+    return bp_history_adaptor_get_cond_ids_p
+       (ids, count,
+        &conds,
+        check_column_offset,
+        keyword,
+        is_like);
 }
 
-/**
- * If hi->getUrl() exists on a table HISTORY update visit_counter and visit_date, unless insert hi to database.
- *
- * @throws HistoryException on error
- */
+void HistoryService::addHistoryItem(std::shared_ptr<HistoryItem> his){
+
+    BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
+    his->setFavIcon(his->getFavIcon());
+    std::shared_ptr<tizen_browser::tools::BrowserImage> favicon = his->getFavIcon();
+
+    int id = -1;
+    int ret = bp_history_adaptor_create(&id);
+    if (ret<0){
+        BROWSER_LOGE("Error! Could not create new bookmark!");
+    }
+
+    int *ids=NULL;
+    int count=-1;
+    int **id1=&ids;
+    int *count1=&count;
+
+    bp_history_rows_cond_fmt conds;
+    conds.limit = 20;  //no of rows to get negative means no limitation
+
+    conds.offset = -1;   //the first row's index
+    conds.order_offset =BP_HISTORY_O_DATE_CREATED; // property to sort
+
+    conds.ordering = 1; //way of ordering 0 asc 1 desc
+
+    conds.period_offset = BP_HISTORY_O_DATE_CREATED;
+    conds.period_type = BP_HISTORY_DATE_TODAY;
+
+    ret = bp_history_adaptor_get_cond_ids_p(id1 ,count1, &conds, 0, NULL, 0);
+    if (ret<0){
+        BROWSER_LOGE("Error! Could not get ids!");
+    }
+
+    bp_history_adaptor_set_url(id, (his->getUrl()).c_str());
+    bp_history_adaptor_set_title(id, (his->getTitle()).c_str());
+
+
+    std::unique_ptr<tizen_browser::tools::Blob> favicon_blob = tizen_browser::tools::EflTools::getBlobPNG(favicon);
+    unsigned char * fav = std::move((unsigned char*)favicon_blob->getData());
+    bp_history_adaptor_set_icon(id, favicon->width, favicon->height, fav, favicon_blob->getLength());
+
+    BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
+}
+
+
 void HistoryService::insertOrRefresh(std::shared_ptr<HistoryItem> hi) {
        getStorageManager()->insertOrRefresh(hi);
 }
@@ -94,33 +154,48 @@ void HistoryService::clearURLHistory(const std::string & url)
     }
 }
 
-/**
- * @throws HistoryException on error
- */
-std::shared_ptr<HistoryItem> HistoryService::getHistoryItem(const std::string & url)
-{
-    return getStorageManager()->getHistoryItem(url);
-}
 
-/**
- * @throws HistoryException on error
- */
 HistoryItemVector& HistoryService::getHistoryItems(int historyDepthInDays, int maxItems)
 {
-    return getStorageManager()->getHistoryItems(historyDepthInDays, maxItems);
-}
+    history_list.clear();
 
-/**
- * @throws HistoryException on error
- */
-int HistoryService::getHistoryItemsCount()
-{
-    return getStorageManager()->getHistoryItemsCount();
+    int *ids=NULL;
+    int count=-1;
+    int **id1=&ids;
+    int *count1=&count;
+
+    bp_history_rows_cond_fmt conds;
+    conds.limit = 20;  //no of rows to get negative means no limitation
+
+    conds.offset = -1;   //the first row's index
+    conds.order_offset =BP_HISTORY_O_DATE_CREATED; // property to sort
+
+    conds.ordering = 1; //way of ordering 0 asc 1 desc
+
+    conds.period_offset = BP_HISTORY_O_DATE_CREATED;
+
+    conds.period_type = BP_HISTORY_DATE_TODAY;
+
+    int ret = bp_history_adaptor_get_cond_ids_p(id1 ,count1, &conds, 0, NULL, 0);
+    if (ret<0){
+        BROWSER_LOGD("Error! Could not get ids!");
+    }
+
+    bp_history_offset offset = (BP_HISTORY_O_URL | BP_HISTORY_O_TITLE | BP_HISTORY_O_FAVICON);
+
+    for(int i = 0; i< (*count1); i++){
+        bp_history_info_fmt history_info;
+        bp_history_adaptor_get_info(ids[i],offset,&history_info);
+
+        std::shared_ptr<HistoryItem> history = std::make_shared<HistoryItem>(std::string(history_info.url));
+        history_list.push_back(history);
+    }
+    ids = NULL;
+    free(ids);
+
+    return history_list;
 }
 
-/**
- * @throws HistoryException on error
- */
 int HistoryService::getHistoryVisitCounter(const std::string & url)
 {
     return getStorageManager()->getHistoryVisitCounter(url);