From a656e6c5fd5662a3d990115e2b5851570149d594 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Sun, 10 Jul 2011 17:21:47 +0200 Subject: WARNING: HISTORY_VERSION upgrade!! This commit changes rekonq history data struct to manage also the first time you visited a site. This way we can "expose" this new info in the SSL widget. (We can obviously do a lot more with it...) --- src/history/historymanager.cpp | 26 ++++++++++++++++++-------- src/history/historymanager.h | 13 ++++++++----- src/history/historymodels.cpp | 25 ++++++++++++++++++------- src/history/historymodels.h | 3 ++- 4 files changed, 46 insertions(+), 21 deletions(-) (limited to 'src/history') diff --git a/src/history/historymanager.cpp b/src/history/historymanager.cpp index 742e957c..0b5e9e48 100644 --- a/src/history/historymanager.cpp +++ b/src/history/historymanager.cpp @@ -59,7 +59,7 @@ #include -static const unsigned int HISTORY_VERSION = 24; +static const unsigned int HISTORY_VERSION = 25; HistoryManager::HistoryManager(QObject *parent) @@ -123,7 +123,7 @@ void HistoryManager::addHistoryEntry(const QString &url) m_history.removeOne(item); emit entryRemoved(item); - item.dateTime = QDateTime::currentDateTime(); + item.lastDateTimeVisit = QDateTime::currentDateTime(); item.visitCount++; } else @@ -172,7 +172,7 @@ void HistoryManager::checkForExpired() while(!m_history.isEmpty()) { - QDateTime checkForExpired = m_history.last().dateTime; + QDateTime checkForExpired = m_history.last().lastDateTimeVisit; checkForExpired.setDate(checkForExpired.date().addDays(m_historyLimit)); if(now.daysTo(checkForExpired) > 7) { @@ -352,23 +352,33 @@ void HistoryManager::load() { case HISTORY_VERSION: // default case stream >> item.url; - stream >> item.dateTime; + stream >> item.firstDateTimeVisit; + stream >> item.lastDateTimeVisit; stream >> item.title; stream >> item.visitCount; break; - case 23: // this will be used to upgrade previous structure... + case 24: // this was history structure for rekonq < 0.8 stream >> item.url; - stream >> item.dateTime; + stream >> item.lastDateTimeVisit; + stream >> item.title; + stream >> item.visitCount; + item.firstDateTimeVisit = item.lastDateTimeVisit; + break; + + case 23: // this will be used to upgrade previous structure... + stream >> item.url; + stream >> item.lastDateTimeVisit; stream >> item.title; item.visitCount = 1; + item.firstDateTimeVisit = item.lastDateTimeVisit; break; default: continue; }; - if(!item.dateTime.isValid()) + if (!item.lastDateTimeVisit.isValid()) continue; if(item == lastInsertedItem) @@ -446,7 +456,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 << item.visitCount; + stream << HISTORY_VERSION << item.url << item.firstDateTimeVisit << item.lastDateTimeVisit << item.title << item.visitCount; out << data; } tempFile.close(); diff --git a/src/history/historymanager.h b/src/history/historymanager.h index e22b7042..101bc09d 100644 --- a/src/history/historymanager.h +++ b/src/history/historymanager.h @@ -65,7 +65,8 @@ public: ) : title(t) , url(u) - , dateTime(d) + , firstDateTimeVisit(d) + , lastDateTimeVisit(d) , visitCount(1) {} @@ -73,23 +74,25 @@ public: { return other.title == title && other.url == url - && other.dateTime == dateTime; + && other.firstDateTimeVisit == firstDateTimeVisit + && other.lastDateTimeVisit == lastDateTimeVisit; } inline qreal relevance() const { - return log(visitCount) - log(dateTime.daysTo(QDateTime::currentDateTime()) + 1); + return log(visitCount) - log(lastDateTimeVisit.daysTo(QDateTime::currentDateTime()) + 1); } // history is sorted in reverse inline bool operator <(const HistoryItem &other) const { - return dateTime > other.dateTime; + return lastDateTimeVisit > other.lastDateTimeVisit; } QString title; QString url; - QDateTime dateTime; + QDateTime firstDateTimeVisit; + QDateTime lastDateTimeVisit; int visitCount; }; diff --git a/src/history/historymodels.cpp b/src/history/historymodels.cpp index e78c3ac1..0315513b 100644 --- a/src/history/historymodels.cpp +++ b/src/history/historymodels.cpp @@ -115,9 +115,11 @@ QVariant HistoryModel::data(const QModelIndex &index, int role) const switch(role) { case DateTimeRole: - return item.dateTime; + return item.lastDateTimeVisit; case DateRole: - return item.dateTime.date(); + return item.lastDateTimeVisit.date(); + case FirstDateTimeVisitRole: + return item.firstDateTimeVisit; case UrlRole: return QUrl(item.url); case Qt::UserRole: @@ -152,7 +154,7 @@ QVariant HistoryModel::data(const QModelIndex &index, int role) const QString tooltip = ""; if(!item.title.isEmpty()) tooltip = item.title + '\n'; - tooltip += item.dateTime.toString(Qt::SystemLocaleShortDate) + '\n' + item.url; + tooltip += item.lastDateTimeVisit.toString(Qt::SystemLocaleShortDate) + '\n' + item.url; return tooltip; } return QVariant(); @@ -188,7 +190,7 @@ bool HistoryModel::removeRows(int row, int count, const QModelIndex &parent) } -// ------------------------------------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------ HistoryFilterModel::HistoryFilterModel(QAbstractItemModel *sourceModel, QObject *parent) @@ -436,7 +438,7 @@ QVariant HistoryTreeModel::headerData(int section, Qt::Orientation orientation, QVariant HistoryTreeModel::data(const QModelIndex &index, int role) const { - if((role == Qt::EditRole || role == Qt::DisplayRole)) + if (role == Qt::EditRole || role == Qt::DisplayRole) { int start = index.internalId(); if(start == 0) @@ -456,15 +458,24 @@ QVariant HistoryTreeModel::data(const QModelIndex &index, int role) const } } } - if(role == Qt::DecorationRole && index.column() == 0 && !index.parent().isValid()) + + if (role == Qt::DecorationRole && index.column() == 0 && !index.parent().isValid()) return KIcon("view-history"); - if(role == HistoryModel::DateRole && index.column() == 0 && index.internalId() == 0) + + if (role == HistoryModel::DateRole && index.column() == 0 && index.internalId() == 0) { int offset = sourceDateRow(index.row()); QModelIndex idx = sourceModel()->index(offset, 0); return idx.data(HistoryModel::DateRole); } + if (role == HistoryModel::FirstDateTimeVisitRole && index.column() == 0 && index.internalId() == 0) + { + int offset = sourceDateRow(index.row()); + QModelIndex idx = sourceModel()->index(offset, 0); + return idx.data(HistoryModel::FirstDateTimeVisitRole); + } + return QAbstractProxyModel::data(index, role); } diff --git a/src/history/historymodels.h b/src/history/historymodels.h index 8cb1a5dd..7388cef5 100644 --- a/src/history/historymodels.h +++ b/src/history/historymodels.h @@ -56,7 +56,8 @@ public: DateRole = Qt::UserRole + 1, DateTimeRole = Qt::UserRole + 2, UrlRole = Qt::UserRole + 3, - UrlStringRole = Qt::UserRole + 4 + UrlStringRole = Qt::UserRole + 4, + FirstDateTimeVisitRole = Qt::UserRole + 5 }; explicit HistoryModel(HistoryManager *history, QObject *parent = 0); -- cgit v1.2.1