Using UrlHistoryList do display history list (on urientry edition).
[profile/tv/apps/web/browser.git] / services / HistoryService / HistoryService.h
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef __HISTORY_SERVICE_H
18 #define __HISTORY_SERVICE_H
19
20 #include <vector>
21 #include <memory>
22 #include <boost/date_time/gregorian/gregorian.hpp>
23 #include <boost/signals2/signal.hpp>
24
25 #include "ServiceFactory.h"
26 #include "service_macros.h"
27 #include "BrowserImage.h"
28 #include "HistoryItem.h"
29 #include "StorageService.h"
30 #include <web/web_history.h>
31 #define DOMAIN_HISTORY_SERVICE "org.tizen.browser.historyservice"
32
33 namespace tizen_browser
34 {
35 namespace services
36 {
37
38 class HistoryMatchFinder;
39 typedef std::shared_ptr<HistoryMatchFinder> HistoryMatchFinderPtr;
40
41 class BROWSER_EXPORT HistoryService: public tizen_browser::core::AbstractService
42 {
43 public:
44     HistoryService();
45     virtual ~HistoryService();
46     virtual std::string getName();
47     int getHistoryId(const std::string & url);
48     void addHistoryItem(std::shared_ptr<HistoryItem> hi,
49                         std::shared_ptr<tizen_browser::tools::BrowserImage> thumbnail=std::shared_ptr<tizen_browser::tools::BrowserImage>());
50     void clearAllHistory();
51     void clearURLHistory(const std::string & url);
52     std::shared_ptr<HistoryItem> getHistoryItem(const std::string & url);
53     std::shared_ptr<HistoryItemVector> getHistoryAll();
54     std::shared_ptr<HistoryItemVector> getHistoryToday();
55     std::shared_ptr<HistoryItemVector> getHistoryYesterday();
56     std::shared_ptr<HistoryItemVector> getHistoryLastWeek();
57     std::shared_ptr<HistoryItemVector> getHistoryLastMonth();
58     std::shared_ptr<HistoryItemVector> getHistoryOlder();
59     std::shared_ptr<HistoryItem> getCurrentTab();
60     std::shared_ptr<HistoryItemVector> getMostVisitedHistoryItems();
61     void cleanMostVisitedHistoryItems();
62     std::shared_ptr<HistoryItemVector> getHistoryItemsByKeyword(const std::string & keyword, int maxItems);
63     std::shared_ptr<HistoryItemVector> getHistoryItemsByURL(const std::string & url, int maxItems);
64
65     /**
66      * @brief Searches for history items matching given pattern.
67      *
68      * Splits pattern into words by removing spaces. History item matches
69      * pattern, when its url contains all words (order not considered).
70      *
71      * @param keywords string containing keywords separated by spaces
72      * @param maxItems searched items number will be shortened to this maxItems.
73      * if -1: no shortening.
74      * @param minKeywordLength minimum length of the longest keyword picked,
75      * from which searching will start. If longest keyword is shorter than
76      * #minKeywordLength, then search will not start.
77      * @return vector of shared pointers to history items matching given
78      * pattern
79      */
80     std::shared_ptr<HistoryItemVector> getHistoryItemsByKeywordsString(
81             const std::string& keywordsString, const int maxItems,
82             const int minKeywordLength);
83
84     int getHistoryItemsCount();
85     void setStorageServiceTestMode(bool testmode = true);
86
87     boost::signals2::signal<void (bool)>historyEmpty;
88     boost::signals2::signal<void (std::shared_ptr<tizen_browser::services::HistoryItem>)> historyAdded;
89     boost::signals2::signal<void (const std::string& uri)> historyDeleted;
90     boost::signals2::signal<void ()> historyAllDeleted;
91
92 private:
93     bool m_testDbMod;;
94     std::vector<std::shared_ptr<HistoryItem>> history_list;
95     std::shared_ptr<tizen_browser::services::StorageService> m_storageManager;
96     HistoryMatchFinderPtr m_historyMatchFinder;
97
98     /**
99      * @throws StorageExceptionInitialization on error
100      */
101     void initDatabaseBookmark(const std::string & db_str);
102
103     std::shared_ptr<HistoryItem> getHistoryItem(int* ids, int idNumber = 0);
104     std::shared_ptr<HistoryItemVector> getHistoryItems(bp_history_date_defs period = BP_HISTORY_DATE_TODAY);
105     std::shared_ptr<tizen_browser::services::StorageService> getStorageManager();
106     bool isDuplicate(const char* url) const;
107 };
108
109 }
110 }
111
112 #endif