diff options
-rw-r--r-- | src/history/historymanager.cpp | 61 | ||||
-rw-r--r-- | src/history/historymanager.h | 25 | ||||
-rw-r--r-- | src/history/historymodels.cpp | 4 | ||||
-rw-r--r-- | src/history/historymodels.h | 17 |
4 files changed, 72 insertions, 35 deletions
diff --git a/src/history/historymanager.cpp b/src/history/historymanager.cpp index 92f9caee..59cc121e 100644 --- a/src/history/historymanager.cpp +++ b/src/history/historymanager.cpp @@ -59,7 +59,7 @@ #include <QtAlgorithms> -static const unsigned int HISTORY_VERSION = 23; +static const unsigned int HISTORY_VERSION = 24; HistoryManager::HistoryManager(QObject *parent) @@ -68,8 +68,6 @@ HistoryManager::HistoryManager(QObject *parent) , m_historyLimit(0) , m_historyTreeModel(0) { - kDebug() << "Loading HistoryManager..."; - connect(this, SIGNAL(entryAdded(const HistoryItem &)), m_saveTimer, SLOT(changeOccurred())); connect(this, SIGNAL(entryRemoved(const HistoryItem &)), m_saveTimer, SLOT(changeOccurred())); connect(m_saveTimer, SIGNAL(saveNeeded()), this, SLOT(save())); @@ -82,7 +80,6 @@ HistoryManager::HistoryManager(QObject *parent) // QWebHistoryInterface will delete the history manager QWebHistoryInterface::setDefaultInterface(this); - kDebug() << "Loading HistoryManager... DONE"; } @@ -115,11 +112,31 @@ void HistoryManager::addHistoryEntry(const QString &url) cleanUrl.setPassword(QString()); cleanUrl.setHost(cleanUrl.host().toLower()); - HistoryItem item(cleanUrl.toString(), QDateTime::currentDateTime()); + QString checkUrlString = cleanUrl.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)) + { + int index = m_historyFilterModel->historyLocation(checkUrlString); + item = m_history.at(index); + m_history.removeOne(item); + emit entryRemoved(item); + + item.dateTime = QDateTime::currentDateTime(); + item.visitCount++; + } + else + { + item = HistoryItem(checkUrlString, QDateTime::currentDateTime()); + } + m_history.prepend(item); emit entryAdded(item); - + if (m_history.count() == 1) checkForExpired(); } @@ -328,15 +345,31 @@ void HistoryManager::load() buffer.close(); buffer.setBuffer(&data); buffer.open(QIODevice::ReadOnly); - quint32 ver; - stream >> ver; - if (ver != HISTORY_VERSION) - continue; + quint32 version; + stream >> version; + HistoryItem item; - stream >> item.url; - stream >> item.dateTime; - stream >> item.title; + + switch (version) + { + case HISTORY_VERSION: // default case + stream >> item.url; + stream >> item.dateTime; + stream >> item.title; + stream >> item.visitCount; + break; + case 23: // this will be used to upgrade previous structure... + stream >> item.url; + stream >> item.dateTime; + stream >> item.title; + item.visitCount = 1; + break; + + default: + continue; + }; + if (!item.dateTime.isValid()) continue; @@ -415,7 +448,7 @@ void HistoryManager::save() QByteArray data; QDataStream stream(&data, QIODevice::WriteOnly); HistoryItem item = m_history.at(i); - stream << HISTORY_VERSION << item.url << item.dateTime << item.title; + stream << HISTORY_VERSION << item.url << item.dateTime << item.title << item.visitCount; out << data; } tempFile.close(); diff --git a/src/history/historymanager.h b/src/history/historymanager.h index 1e03fb1c..a4099de7 100644 --- a/src/history/historymanager.h +++ b/src/history/historymanager.h @@ -61,14 +61,16 @@ public: const QString &t = QString() ) : title(t) - , url(u), - dateTime(d) + , url(u) + , dateTime(d) + , visitCount(1) {} inline bool operator==(const HistoryItem &other) const { return other.title == title - && other.url == url && other.dateTime == dateTime; + && other.url == url + && other.dateTime == dateTime; } // history is sorted in reverse @@ -80,6 +82,7 @@ public: QString title; QString url; QDateTime dateTime; + int visitCount; }; @@ -100,12 +103,6 @@ class REKONQ_TESTS_EXPORT HistoryManager : public QWebHistoryInterface { Q_OBJECT -signals: - void historyReset(); - void entryAdded(const HistoryItem &item); - void entryRemoved(const HistoryItem &item); - void entryUpdated(int offset); - public: HistoryManager(QObject *parent = 0); ~HistoryManager(); @@ -123,12 +120,18 @@ public: // History manager keeps around these models for use by the completer and other classes HistoryFilterModel *historyFilterModel() const { return m_historyFilterModel; }; HistoryTreeModel *historyTreeModel() const { return m_historyTreeModel; }; + +Q_SIGNALS: + void historyReset(); + void entryAdded(const HistoryItem &item); + void entryRemoved(const HistoryItem &item); + void entryUpdated(int offset); -public slots: +public Q_SLOTS: void clear(); void loadSettings(); -private slots: +private Q_SLOTS: void save(); void checkForExpired(); diff --git a/src/history/historymodels.cpp b/src/history/historymodels.cpp index 793ff7e5..d9d3efef 100644 --- a/src/history/historymodels.cpp +++ b/src/history/historymodels.cpp @@ -192,8 +192,8 @@ bool HistoryModel::removeRows(int row, int count, const QModelIndex &parent) HistoryFilterModel::HistoryFilterModel(QAbstractItemModel *sourceModel, QObject *parent) - : QAbstractProxyModel(parent), - m_loaded(false) + : QAbstractProxyModel(parent) + , m_loaded(false) { setSourceModel(sourceModel); } diff --git a/src/history/historymodels.h b/src/history/historymodels.h index d193cf86..8cac9245 100644 --- a/src/history/historymodels.h +++ b/src/history/historymodels.h @@ -50,11 +50,6 @@ class REKONQ_TESTS_EXPORT HistoryModel : public QAbstractTableModel { Q_OBJECT -public slots: - void historyReset(); - void entryAdded(); - void entryUpdated(int offset); - public: enum Roles { @@ -66,12 +61,18 @@ public: explicit HistoryModel(HistoryManager *history, QObject *parent = 0); +public Q_SLOTS: + void historyReset(); + void entryAdded(); + void entryUpdated(int offset); + +public: QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; int columnCount(const QModelIndex &parent = QModelIndex()) const; int rowCount(const QModelIndex &parent = QModelIndex()) const; bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()); - + private: HistoryManager *m_historyManager; }; @@ -118,7 +119,7 @@ public: bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()); QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; -private slots: +private Q_SLOTS: void sourceReset(); void sourceDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight); void sourceRowsInserted(const QModelIndex &parent, int start, int end); @@ -165,7 +166,7 @@ public: void setSourceModel(QAbstractItemModel *sourceModel); -private slots: +private Q_SLOTS: void sourceReset(); void sourceRowsInserted(const QModelIndex &parent, int start, int end); void sourceRowsRemoved(const QModelIndex &parent, int start, int end); |