summaryrefslogtreecommitdiff
path: root/src/history
diff options
context:
space:
mode:
authormegabigbug <megabigbug@arrakis.(none)>2010-07-20 22:07:04 +0200
committermegabigbug <megabigbug@arrakis.(none)>2010-07-20 22:07:04 +0200
commit68dfc20b8f8d8ff583c4e06ddb61a9986ccb7df7 (patch)
treef1d47659f5eb68593035219293c6a43e29c3a2f8 /src/history
parentrekonq 0.5.50 (diff)
downloadrekonq-68dfc20b8f8d8ff583c4e06ddb61a9986ccb7df7.tar.xz
history review:
- remove AwesomeUrlCompletion class - add an QHash to the history manager: each url have a visit counter - sort history urls by visit count TODO: - reintroduce bookmark item in url resolver (broken when AwesomeUrlCompletion was removed)
Diffstat (limited to 'src/history')
-rw-r--r--src/history/historymanager.cpp98
-rw-r--r--src/history/historymanager.h39
2 files changed, 96 insertions, 41 deletions
diff --git a/src/history/historymanager.cpp b/src/history/historymanager.cpp
index d531c189..a56045a7 100644
--- a/src/history/historymanager.cpp
+++ b/src/history/historymanager.cpp
@@ -69,11 +69,8 @@ HistoryManager::HistoryManager(QObject *parent)
, m_historyModel(0)
, m_historyFilterModel(0)
, m_historyTreeModel(0)
- , m_completion(new AwesomeUrlCompletion)
{
kDebug() << "Loading HistoryManager...";
- // take care of the completion object
- m_completion->setOrder(KCompletion::Weighted);
m_expiredTimer.setSingleShot(true);
connect(&m_expiredTimer, SIGNAL(timeout()), this, SLOT(checkForExpired()));
@@ -95,7 +92,6 @@ HistoryManager::HistoryManager(QObject *parent)
HistoryManager::~HistoryManager()
{
m_saveTimer->saveIfNeccessary();
- delete m_completion;
delete m_saveTimer;
@@ -113,7 +109,7 @@ QList<HistoryItem> HistoryManager::history() const
bool HistoryManager::historyContains(const QString &url) const
{
- return m_historyFilterModel->historyContains(url);
+ return m_hash.contains(url) && m_hash[url].savedCount>0;
}
@@ -129,12 +125,6 @@ void HistoryManager::addHistoryEntry(const QString &url)
cleanUrl.setHost(cleanUrl.host().toLower());
HistoryItem item(cleanUrl.toString(), QDateTime::currentDateTime());
addHistoryEntry(item);
-
- // Add item to completion object
- QString _url(url);
- _url.remove(QRegExp("^http://|/$"));
- UrlSearchItem urlSearchItem(UrlSearchItem::History, _url, QString(), item.dateTime, 1, QString(), QString());
- m_completion->addItem(urlSearchItem);
}
@@ -142,6 +132,13 @@ void HistoryManager::setHistory(const QList<HistoryItem> &history, bool loadedAn
{
m_history = history;
+ //TODO: is there a way to really memorize the visitCount instead of recount it at startup ?
+ m_hash.clear();
+ foreach(HistoryItem i, m_history)
+ {
+ addHistoryHashEntry(i);
+ }
+
// verify that it is sorted by date
if (!loadedAndSorted)
qSort(m_history.begin(), m_history.end());
@@ -220,12 +217,31 @@ void HistoryManager::addHistoryEntry(const HistoryItem &item)
return;
m_history.prepend(item);
+ addHistoryHashEntry(item);
emit entryAdded(item);
if (m_history.count() == 1)
checkForExpired();
}
+void HistoryManager::addHistoryHashEntry(const HistoryItem &item)
+{
+ if (m_hash.contains(item.url))
+ {
+ m_hash[item.url].visitCount++;
+ m_hash[item.url].dateTime = item.dateTime; //store last visit date
+ if (!item.title.isEmpty())
+ {
+ m_hash[item.url].title = item.title; //store last title if not empty
+ }
+ }
+ else
+ {
+ m_hash[item.url] = HistoryHashItem(item.url, item.dateTime, item.title);
+ }
+ m_hash[item.url].savedCount++;
+}
+
void HistoryManager::updateHistoryEntry(const KUrl &url, const QString &title)
{
@@ -237,6 +253,11 @@ void HistoryManager::updateHistoryEntry(const KUrl &url, const QString &title)
m_saveTimer->changeOccurred();
if (m_lastSavedUrl.isEmpty())
m_lastSavedUrl = m_history.at(i).url;
+
+ if (m_hash.contains(url.url()) && !title.isEmpty())
+ {
+ m_hash[url.url()].title = title;
+ }
emit entryUpdated(i);
break;
}
@@ -248,6 +269,10 @@ void HistoryManager::removeHistoryEntry(const HistoryItem &item)
{
m_lastSavedUrl.clear();
m_history.removeOne(item);
+ if (m_hash.contains(item.url) && m_hash[item.url].savedCount>0)
+ {
+ m_hash[item.url].savedCount--; //this counter is used for expired urls
+ }
emit entryRemoved(item);
}
@@ -265,10 +290,37 @@ void HistoryManager::removeHistoryEntry(const KUrl &url, const QString &title)
break;
}
}
+}
+
+
+HistoryHashItem HistoryManager::get(const QString &url)
+{
+ return m_hash[url];
+}
+
+
+QList<HistoryHashItem> HistoryManager::find(const QString &text)
+{
+ QList<HistoryHashItem> list;
+
+ QString url;
+ foreach(url, m_hash.keys())
+ {
+ if (url.contains(text) || m_hash[url].title.contains(text))
+ {
+ list << m_hash[url];
+ }
+ }
+
+ return list;
+}
+
- // Remove item from completion object
- UrlSearchItem urlSearchItem(UrlSearchItem::History, item.url, item.title, item.dateTime, 0, QString(), QString());
- m_completion->removeItem(urlSearchItem);
+QList<HistoryHashItem> HistoryManager::findMostVisited(const QString &text)
+{
+ QList<HistoryHashItem> list = find(text);
+ qSort(list);
+ return list;
}
@@ -369,12 +421,6 @@ void HistoryManager::load()
list.prepend(item);
lastInsertedItem = item;
-
- // Add item to completion object
- //QString _url = item.url;
- //_url.remove(QRegExp("^http://|/$"));
- UrlSearchItem urlSearchItem(UrlSearchItem::History, item.url, item.title, item.dateTime, 1, QString(), QString());
- m_completion->addItem(urlSearchItem);
}
if (needToSort)
qSort(list.begin(), list.end());
@@ -458,12 +504,6 @@ void HistoryManager::save()
}
-AwesomeUrlCompletion * HistoryManager::completionObject() const
-{
- return m_completion;
-}
-
-
void HistoryManager::addDownload(const QString &srcUrl, const QString &destUrl)
{
QWebSettings *globalSettings = QWebSettings::globalSettings();
@@ -519,9 +559,3 @@ bool HistoryManager::clearDownloadsHistory()
return downloadFile.remove();
}
-
-QString HistoryManager::titleForHistoryUrl(QString url)
-{
- return history().at(m_historyFilterModel->historyLocation(url)).title;
-}
-
diff --git a/src/history/historymanager.h b/src/history/historymanager.h
index 7b82579d..b91eec60 100644
--- a/src/history/historymanager.h
+++ b/src/history/historymanager.h
@@ -84,6 +84,31 @@ public:
// ---------------------------------------------------------------------------------------------------------------
+class HistoryHashItem : public HistoryItem
+{
+public:
+ HistoryHashItem() {}
+ explicit HistoryHashItem(const QString &u
+ ,const QDateTime &d = QDateTime()
+ ,const QString &t = QString()
+ )
+ : HistoryItem(u, d, t)
+ ,visitCount(1)
+ ,savedCount(0)
+ {}
+
+ inline bool operator <(const HistoryHashItem &other) const
+ {
+ return visitCount > other.visitCount;
+ }
+
+ int visitCount;
+ int savedCount;
+};
+
+// ---------------------------------------------------------------------------------------------------------------
+
+
class DownloadItem
{
public:
@@ -139,7 +164,9 @@ public:
void updateHistoryEntry(const KUrl &url, const QString &title);
void removeHistoryEntry(const KUrl &url, const QString &title = QString());
- QString titleForHistoryUrl(QString url);
+ HistoryHashItem get(const QString &url);
+ QList<HistoryHashItem> find(const QString &text);
+ QList<HistoryHashItem> findMostVisited(const QString &text);
int historyLimit() const;
void setHistoryLimit(int limit);
@@ -152,11 +179,6 @@ public:
HistoryFilterModel *historyFilterModel() const;
HistoryTreeModel *historyTreeModel() const;
- /**
- * @returns the AwesomeUrlCompletion object.
- */
- AwesomeUrlCompletion *completionObject() const;
-
void addDownload(const QString &srcUrl, const QString &destUrl);
DownloadList downloads();
bool clearDownloadsHistory();
@@ -172,6 +194,7 @@ private slots:
protected:
void addHistoryEntry(const HistoryItem &item);
void removeHistoryEntry(const HistoryItem &item);
+ void addHistoryHashEntry(const HistoryItem &item);
private:
void load();
@@ -180,14 +203,12 @@ private:
int m_historyLimit;
QTimer m_expiredTimer;
QList<HistoryItem> m_history;
+ QHash<QString, HistoryHashItem> m_hash;
QString m_lastSavedUrl;
HistoryModel *m_historyModel;
HistoryFilterModel *m_historyFilterModel;
HistoryTreeModel *m_historyTreeModel;
-
- // the completion object we sync with
- AwesomeUrlCompletion *m_completion;
};