Fix reset most visited sites functionality. 26/49026/8 accepted/tizen/tv/20151006.042220 submit/tizen_tv/20151006.003037
authorDariusz Frankiewicz <d.frankiewic@samsung.com>
Mon, 5 Oct 2015 09:00:32 +0000 (11:00 +0200)
committerDariusz Frankiewicz <d.frankiewic@samsung.com>
Mon, 5 Oct 2015 13:03:56 +0000 (15:03 +0200)
[Issue]    https://bugs.tizen.org/jira/browse/TT-175
[Problem]  Reset most visited sites isn't working.
[Cause]    Not implemented.
[Solution] Implemented setting site visit counter to 0 and
           displaying only sites with counter grater then 0.
[Verify]   Visit some sites, go to settings, press Reset Most Visted
           Sites button, check if on new tab most visited sites are empty.

Change-Id: I05d44043744a1b7859b23df282dfb53745fb894d
Signed-off-by: Dariusz Frankiewicz <d.frankiewic@samsung.com>
services/HistoryService/HistoryService.cpp
services/HistoryService/HistoryService.h
services/SimpleUI/SimpleUI.cpp

index c60d669..f641b85 100644 (file)
@@ -159,19 +159,20 @@ std::shared_ptr<HistoryItemVector> HistoryService::getMostVisitedHistoryItems()
     int *ids=nullptr;
     int count=-1;
     bp_history_rows_cond_fmt conds;
-    conds.limit = 20;  //no of rows to get negative means no limitation
+    conds.limit = 5;  //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.order_offset = BP_HISTORY_O_FREQUENCY; // 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;
+    //TODO: consider to change below line to BP_HISTORY_DATE_LAST_MONTH
+    conds.period_type = BP_HISTORY_DATE_ALL; // set from which period most visited sites are generated
 
     int ret = bp_history_adaptor_get_cond_ids_p(&ids ,&count, &conds, 0, nullptr, 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 | BP_HISTORY_O_DATE_CREATED | BP_HISTORY_O_THUMBNAIL);
+    bp_history_offset offset = (BP_HISTORY_O_URL | BP_HISTORY_O_TITLE | BP_HISTORY_O_FREQUENCY | BP_HISTORY_O_FAVICON | BP_HISTORY_O_DATE_CREATED | BP_HISTORY_O_THUMBNAIL);
 
     int freq_arr[1000];
     for(int i = 0; i< count; i++){
@@ -213,7 +214,7 @@ std::shared_ptr<HistoryItemVector> HistoryService::getMostVisitedHistoryItems()
         history->setUrl(std::string(history_info.url ? history_info.url : ""));
         history->setTitle(std::string(history_info.title ? history_info.title : ""));
 
-        //thumbail
+        //thumbnail
         if (history_info.thumbnail_length != -1) {
             std::shared_ptr<tizen_browser::tools::BrowserImage> hi = std::make_shared<tizen_browser::tools::BrowserImage>();
             hi->imageType = tools::BrowserImage::ImageTypePNG;
@@ -226,13 +227,40 @@ std::shared_ptr<HistoryItemVector> HistoryService::getMostVisitedHistoryItems()
         } else {
             BROWSER_LOGD("history thumbnail lenght is -1");
         }
-
-        ret_history_list->push_back(history);
+        if(history_info.frequency > 0)
+            ret_history_list->push_back(history);
     }
+
     free(ids);
     return ret_history_list;
 }
 
+void HistoryService::cleanMostVisitedHistoryItems()
+{
+    BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
+
+    int *ids=nullptr;
+    int count=-1;
+    bp_history_rows_cond_fmt conds;
+    conds.limit = -1;  // no of rows to get negative means no limitation
+    conds.offset = -1;   // the first row's index
+    conds.order_offset = BP_HISTORY_O_ALL; // 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_ALL; // set from which period most visited sites are generated
+
+    int ret = bp_history_adaptor_get_cond_ids_p(&ids ,&count, &conds, 0, nullptr, 0);
+    if (ret<0){
+        BROWSER_LOGD("Error! Could not get ids!");
+        return;
+    }
+
+    for(int i = 0; i < count; i++){
+            bp_history_adaptor_set_frequency(ids[i], 0);
+    }
+    BROWSER_LOGD("Deleted Most Visited Sites!");
+}
+
 std::shared_ptr<HistoryItemVector> HistoryService::getHistoryItemsByURL(const std::string& url, int maxItems)
 {
     std::string search("%" + tools::extractDomain(url) + "%");     // add SQL 'any character' signs
index 7764bd3..fc5b7eb 100644 (file)
@@ -55,6 +55,7 @@ public:
     std::shared_ptr<HistoryItemVector> getHistoryOlder();
     std::shared_ptr<HistoryItem> getCurrentTab();
     std::shared_ptr<HistoryItemVector> getMostVisitedHistoryItems();
+    void cleanMostVisitedHistoryItems();
     std::shared_ptr<HistoryItemVector> getHistoryItemsByURL(const std::string & url, int maxItems);
     int getHistoryItemsCount();
     void setStorageServiceTestMode(bool testmode = true);
index b797ac6..56a99f2 100644 (file)
@@ -946,6 +946,10 @@ void SimpleUI::onDeleteMostVisitedButton(PopupButtons button, std::shared_ptr< P
     if (button == OK) {
         BROWSER_LOGD("[%s]: OK", __func__);
         BROWSER_LOGD("[%s]: Deleting most visited", __func__);
+
+        //TODO: display notification popup
+
+        m_historyService->cleanMostVisitedHistoryItems();
     }
 }