From a377183ad57fc8d9edf2f75a7c32b90ee3ee9ed3 Mon Sep 17 00:00:00 2001 From: Priyesh Lakar Date: Tue, 2 Jun 2015 12:07:56 +0530 Subject: [PATCH] History Implementation using Browser Provider. Change-Id: Id6588ef903ae08804233e5de0e71092886f1313f --- services/BookmarkService/CMakeLists.txt | 9 +- services/HistoryService/HistoryService.h | 4 +- services/HistoryService/src/HistoryService.cpp | 139 +++++++++++++++++++------ 3 files changed, 117 insertions(+), 35 deletions(-) diff --git a/services/BookmarkService/CMakeLists.txt b/services/BookmarkService/CMakeLists.txt index cf84d3e..e659588 100644 --- a/services/BookmarkService/CMakeLists.txt +++ b/services/BookmarkService/CMakeLists.txt @@ -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) diff --git a/services/HistoryService/HistoryService.h b/services/HistoryService/HistoryService.h index 60be194..e92cf5d 100644 --- a/services/HistoryService/HistoryService.h +++ b/services/HistoryService/HistoryService.h @@ -28,7 +28,7 @@ #include "HistoryItem.h" #include "HistoryStorage.h" #include "StorageService.h" - +#include #define DOMAIN_HISTORY_SERVICE "org.tizen.browser.historyservice" namespace tizen_browser @@ -90,7 +90,7 @@ public: boost::signals2::signalhistoryEmpty; private: bool m_testDbMod;; - + std::vector> history_list; std::shared_ptr m_storageManager; /** diff --git a/services/HistoryService/src/HistoryService.cpp b/services/HistoryService/src/HistoryService.cpp index 95ee009..cd2864e 100644 --- a/services/HistoryService/src/HistoryService.cpp +++ b/services/HistoryService/src/HistoryService.cpp @@ -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 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 his){ + + BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__); + his->setFavIcon(his->getFavIcon()); + std::shared_ptr 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 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 hi) { getStorageManager()->insertOrRefresh(hi); } @@ -94,33 +154,48 @@ void HistoryService::clearURLHistory(const std::string & url) } } -/** - * @throws HistoryException on error - */ -std::shared_ptr 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 history = std::make_shared(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); -- 2.7.4