From 591b4c3cb201c3d405f4a0a168c65bfe83325c0c Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Wed, 15 Feb 2012 16:54:55 +0100 Subject: New History Manager, NO MORE QWebHistoryInterface based. We are just saving datas on our own, I don't like QtWebKit APIs to do it. We now call addHistoryEntry(url, title) on loadFinished. Data structure will remain the same as usual, but I think API is better and data are now saved when we really have them ready. REVIEW:104257 --- src/history/historymanager.cpp | 55 ++++++++++-------------------------------- 1 file changed, 13 insertions(+), 42 deletions(-) (limited to 'src/history/historymanager.cpp') diff --git a/src/history/historymanager.cpp b/src/history/historymanager.cpp index 602e4606..c78bb009 100644 --- a/src/history/historymanager.cpp +++ b/src/history/historymanager.cpp @@ -63,7 +63,7 @@ static const unsigned int HISTORY_VERSION = 25; HistoryManager::HistoryManager(QObject *parent) - : QWebHistoryInterface(parent) + : QObject(parent) , m_saveTimer(new AutoSaver(this)) , m_historyLimit(0) , m_historyTreeModel(0) @@ -77,9 +77,6 @@ HistoryManager::HistoryManager(QObject *parent) HistoryModel *historyModel = new HistoryModel(this, this); m_historyFilterModel = new HistoryFilterModel(historyModel, this); m_historyTreeModel = new HistoryTreeModel(m_historyFilterModel, this); - - // QWebHistoryInterface will delete the history manager - QWebHistoryInterface::setDefaultInterface(this); } @@ -95,30 +92,33 @@ bool HistoryManager::historyContains(const QString &url) const } -void HistoryManager::addHistoryEntry(const QString &url) +void HistoryManager::addHistoryEntry(const KUrl &url, const QString &title) { QWebSettings *globalSettings = QWebSettings::globalSettings(); if (globalSettings->testAttribute(QWebSettings::PrivateBrowsingEnabled)) return; - QUrl cleanUrl(url); + if (url.isEmpty()) + return; + + QUrl urlToClean(url); // don't store about: urls (home page related) - if (cleanUrl.scheme() == QString("about")) + if (urlToClean.scheme() == QString("about")) return; - cleanUrl.setPassword(QString()); - cleanUrl.setHost(cleanUrl.host().toLower()); - QString checkUrlString = cleanUrl.toString(); + urlToClean.setPassword(QString()); + urlToClean.setHost(urlToClean.host().toLower()); + QString urlString = urlToClean.toString(); HistoryItem item; // NOTE // check if the url has just been visited. // if so, remove previous entry from history, update and prepend it - if (historyContains(checkUrlString)) + if (historyContains(urlString)) { - int index = m_historyFilterModel->historyLocation(checkUrlString); + int index = m_historyFilterModel->historyLocation(urlString); item = m_history.at(index); m_history.removeOne(item); emit entryRemoved(item); @@ -128,7 +128,7 @@ void HistoryManager::addHistoryEntry(const QString &url) } else { - item = HistoryItem(checkUrlString, QDateTime::currentDateTime()); + item = HistoryItem(urlString, QDateTime::currentDateTime(), title); } m_history.prepend(item); @@ -196,35 +196,6 @@ void HistoryManager::checkForExpired() } -void HistoryManager::updateHistoryEntry(const KUrl &url, const QString &title) -{ - QString urlString = url.url(); - urlString.remove(QL1S("www.")); - if (urlString.startsWith(QL1S("http")) && urlString.endsWith(QL1C('/'))) - urlString.remove(urlString.length() - 1, 1); - - for (int i = 0; i < m_history.count(); ++i) - { - QString itemUrl = m_history.at(i).url; - itemUrl.remove(QL1S("www.")); - if (itemUrl.startsWith(QL1S("http")) && itemUrl.endsWith(QL1C('/'))) - itemUrl.remove(itemUrl.length() - 1, 1); - - if (urlString == itemUrl) - { - m_history[i].title = title; - m_history[i].url = url.url(); - m_saveTimer->changeOccurred(); - if (m_lastSavedUrl.isEmpty()) - m_lastSavedUrl = m_history.at(i).url; - - emit entryUpdated(i); - break; - } - } -} - - void HistoryManager::removeHistoryEntry(const KUrl &url, const QString &title) { HistoryItem item; -- cgit v1.2.1