12
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
*
|
|
5 |
* This program is free software: you can redistribute it and/or modify
|
|
6 |
* it under the terms of the GNU Lesser General Public License as published by
|
|
7 |
* the Free Software Foundation, version 2.1 of the License.
|
|
8 |
*
|
|
9 |
* This program is distributed in the hope that it will be useful,
|
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
* GNU Lesser General Public License for more details.
|
|
13 |
*
|
|
14 |
* You should have received a copy of the GNU Lesser General Public License
|
|
15 |
* along with this program. If not,
|
|
16 |
* see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/".
|
|
17 |
*
|
|
18 |
* Description:
|
|
19 |
*
|
|
20 |
*/
|
|
21 |
|
|
22 |
|
|
23 |
#include <QtCore/QDir>
|
|
24 |
#include <QtCore/QFile>
|
|
25 |
#include <QtGui/QIcon>
|
|
26 |
#include <QtGui>
|
|
27 |
#include <QtCore/QDebug>
|
|
28 |
#include <QtCore/QUrl>
|
|
29 |
#include <QString>
|
|
30 |
#include "actionjsobject.h"
|
|
31 |
#include "HistoryManager_p.h"
|
|
32 |
#include "HistoryManager.h"
|
|
33 |
|
|
34 |
//#include "wrtsettings.h"
|
|
35 |
#include "bedrockprovisioning.h"
|
|
36 |
#include <browsercontentdll.h>
|
|
37 |
#include "webpagecontroller.h"
|
|
38 |
#include "wrtbrowsercontainer.h"
|
|
39 |
|
|
40 |
|
|
41 |
namespace WRT {
|
|
42 |
|
|
43 |
HistoryManagerPrivate::HistoryManagerPrivate(HistoryManager * mgr) :
|
|
44 |
q(mgr),
|
|
45 |
m_connectedToHistory(false),
|
|
46 |
m_maxUrls(10) // TODO: read from settings
|
|
47 |
{
|
|
48 |
QFileInfo dbFile("browserContent.db");
|
|
49 |
|
16
|
50 |
QString databaseName = BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsString("DataBaseName");
|
|
51 |
m_historySession=new BrowserContent("Bedrock",databaseName);
|
12
|
52 |
if (m_historySession) {
|
|
53 |
m_connectedToHistory = true;
|
|
54 |
} else {
|
|
55 |
qDebug() << "HistoryManagerPrivate: Failed to connect to history database";
|
|
56 |
}
|
|
57 |
|
|
58 |
m_actionsParent = new QObject(mgr);
|
|
59 |
m_actionsParent->setObjectName("actions");
|
|
60 |
|
|
61 |
m_actionClearHistory = new QAction("clearHistory", m_actionsParent);
|
|
62 |
|
|
63 |
m_actionClearJSO = new ActionJSObject(m_actionsParent, m_actionClearHistory);
|
|
64 |
|
|
65 |
m_actionClearHistory->setObjectName("clearHistory");
|
|
66 |
|
|
67 |
}
|
|
68 |
|
|
69 |
HistoryManagerPrivate::~HistoryManagerPrivate()
|
|
70 |
{
|
|
71 |
delete m_historySession;
|
|
72 |
delete m_actionClearHistory;
|
|
73 |
delete m_actionClearJSO;
|
|
74 |
}
|
|
75 |
|
|
76 |
/*!
|
|
77 |
* \class HistoryManager
|
|
78 |
*
|
|
79 |
* This class is responsible for managing history, This class could be used
|
|
80 |
* mainly for Creating, adding history, adding recent history items, deleting
|
|
81 |
* and editing history.
|
|
82 |
*
|
|
83 |
*/
|
|
84 |
|
|
85 |
/*!
|
|
86 |
* Basic constructor
|
|
87 |
* @param parent : parent widget (Defaulted to NULL ) if not specified
|
|
88 |
*/
|
|
89 |
HistoryManager::HistoryManager(QWidget *parent) :
|
|
90 |
QObject(parent),
|
|
91 |
d(new HistoryManagerPrivate(this))
|
|
92 |
{
|
|
93 |
|
|
94 |
m_isHistoryDbreadRequired=true;
|
|
95 |
connect(d->m_actionClearHistory, SIGNAL(triggered()), this, SIGNAL(confirmHistoryClear()));
|
|
96 |
|
|
97 |
}
|
|
98 |
/*
|
|
99 |
void HistoryManager::actionClearHistory()
|
|
100 |
{
|
|
101 |
emit confirmClearHistory();
|
|
102 |
}
|
|
103 |
*/
|
|
104 |
|
|
105 |
HistoryManager::~HistoryManager()
|
|
106 |
{
|
|
107 |
disconnect(d->m_actionClearHistory, SIGNAL(triggered()), this, SIGNAL(historyCleared()));
|
|
108 |
delete d;
|
|
109 |
}
|
|
110 |
|
|
111 |
HistoryManager* HistoryManager::getSingleton()
|
|
112 |
{
|
|
113 |
static HistoryManager* singleton = 0;
|
|
114 |
|
|
115 |
if(!singleton){
|
|
116 |
singleton = new HistoryManager;
|
|
117 |
singleton->setObjectName("historyManager");
|
|
118 |
}
|
|
119 |
|
|
120 |
//assert(singleton);
|
|
121 |
return singleton;
|
|
122 |
}
|
|
123 |
}
|
|
124 |
|
|
125 |
QString HistoryManager::getHistoryFoldersJSON(QString folderName)
|
|
126 |
{
|
|
127 |
|
|
128 |
bool flag = true;
|
|
129 |
|
|
130 |
QString historyFolders = "[";
|
|
131 |
if (folderName == "")
|
|
132 |
{
|
|
133 |
m_historyMap.clear();
|
|
134 |
m_folderVector.clear();
|
|
135 |
d->m_historySession->fetchSerializedHistory(m_folderVector, m_historyMap);
|
|
136 |
|
|
137 |
for (int i = m_folderVector.size() - 1; i >= 0; i--)
|
|
138 |
{
|
|
139 |
//check for folder nodes
|
|
140 |
historyFolders.append("\"");
|
|
141 |
historyFolders.append(m_folderVector[i]);
|
|
142 |
historyFolders.append("\"");
|
|
143 |
|
|
144 |
|
|
145 |
if (i != 0)
|
|
146 |
historyFolders.append(",");
|
|
147 |
if (flag)
|
|
148 |
{
|
|
149 |
if (m_folderVector[i].count() > 0)
|
|
150 |
{
|
|
151 |
d->m_actionClearHistory->setEnabled(true);
|
|
152 |
flag=false;
|
|
153 |
}
|
|
154 |
|
|
155 |
}
|
|
156 |
}
|
|
157 |
if (flag)
|
|
158 |
{
|
|
159 |
d->m_actionClearHistory->setEnabled(false);
|
|
160 |
}
|
|
161 |
historyFolders.append("]");
|
|
162 |
m_folderVector.clear();
|
|
163 |
}
|
|
164 |
if (folderName == "")
|
|
165 |
{
|
|
166 |
return historyFolders;
|
|
167 |
|
|
168 |
}
|
|
169 |
else
|
|
170 |
{
|
|
171 |
return m_historyMap[folderName];
|
|
172 |
}
|
|
173 |
}
|
|
174 |
|
|
175 |
/*!
|
|
176 |
* Add the node to the folder in proxy model. If the folder doesnt exist in proxy, create
|
|
177 |
* the folder and add the node to it
|
|
178 |
*/
|
|
179 |
|
|
180 |
/*!
|
|
181 |
* Add to recent urls
|
|
182 |
* @param url: url to be added to recent url list
|
|
183 |
* @param title: title for this item in recent url list
|
|
184 |
* @param icon: icon to be added for this item in recent url list
|
|
185 |
*/
|
|
186 |
Q_DECL_EXPORT void HistoryManager::addHistory(const QString &url, const QString &title)
|
|
187 |
{
|
|
188 |
|
|
189 |
//Check for a valid history entry
|
|
190 |
if (url.isEmpty() || title.isEmpty())
|
|
191 |
return;
|
|
192 |
|
|
193 |
bool enabled = (bool) BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsInt("SaveHistory");
|
|
194 |
if(!enabled)
|
|
195 |
return;
|
|
196 |
|
|
197 |
QDateTime currentDateTime = QDateTime::currentDateTime();
|
|
198 |
|
|
199 |
HistoryLeaf* leaf=new HistoryLeaf();
|
|
200 |
leaf->setTitle(title);
|
|
201 |
leaf->setUrl(url);
|
|
202 |
leaf->setDate(currentDateTime.date());
|
|
203 |
leaf->setLastVisited(currentDateTime.time());
|
|
204 |
|
|
205 |
if (d->m_connectedToHistory){
|
|
206 |
if(ErrNone == d->m_historySession->addHistory(leaf)){
|
|
207 |
d->m_actionClearHistory->setEnabled(true);
|
|
208 |
}
|
|
209 |
}
|
|
210 |
delete leaf;
|
|
211 |
}
|
|
212 |
|
|
213 |
/*!
|
|
214 |
* Add to recent urls
|
|
215 |
* @param url: url to be added to recent url list
|
|
216 |
* @param title: title for this item in recent url list
|
|
217 |
* @param icon: icon to be added for this item in recent url list
|
|
218 |
*/
|
|
219 |
|
|
220 |
void HistoryManager::addHistory(const QUrl &url, const QString &title)
|
|
221 |
{
|
|
222 |
addHistory(url.toString(), title);
|
|
223 |
}
|
|
224 |
|
|
225 |
|
|
226 |
/*!
|
|
227 |
* delete recent urls
|
|
228 |
* clears all the recent url list.
|
|
229 |
*/
|
|
230 |
void HistoryManager::clearHistory()
|
|
231 |
{
|
|
232 |
|
|
233 |
if (d->m_connectedToHistory) {
|
|
234 |
d->m_historySession->clearHistory();
|
|
235 |
}
|
|
236 |
|
|
237 |
d->m_actionClearHistory->setEnabled(false);
|
|
238 |
|
|
239 |
emit historyCleared();
|
|
240 |
}
|
|
241 |
|
|
242 |
QAction * HistoryManager::getActionClearHistory()
|
|
243 |
{
|
|
244 |
return d->m_actionClearHistory;
|
|
245 |
}
|
|
246 |
|
|
247 |
int HistoryManager::getPageRank(const QString &url)
|
|
248 |
{
|
|
249 |
//Check for a valid entry
|
|
250 |
if (url.isNull())
|
|
251 |
return 0;
|
|
252 |
|
|
253 |
int rank = 0;
|
|
254 |
QList<HistoryLeaf*> historyNodes = d->m_historySession->fetchHistory();
|
|
255 |
|
|
256 |
for (int i=0; i < historyNodes.count(); i++) {
|
|
257 |
//Update rank if there is a history for this URL.
|
|
258 |
if (!historyNodes[i]->getUrl().compare(url))
|
|
259 |
rank++;
|
|
260 |
}
|
|
261 |
|
|
262 |
while (!historyNodes.isEmpty())
|
|
263 |
delete historyNodes.takeFirst();
|
|
264 |
|
|
265 |
return rank;
|
|
266 |
}
|
14
|
267 |
|
|
268 |
QMap<QString, QString> HistoryManager::findHistory(QString title)
|
|
269 |
{
|
|
270 |
return d->m_historySession->findSimilarHistoryItems(title);
|
|
271 |
}
|