summaryrefslogtreecommitdiff
path: root/src/history.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/history.cpp')
-rw-r--r--src/history.cpp120
1 files changed, 112 insertions, 8 deletions
diff --git a/src/history.cpp b/src/history.cpp
index ea322b65..cb6e80b0 100644
--- a/src/history.cpp
+++ b/src/history.cpp
@@ -44,8 +44,10 @@
#include <QDebug>
+
static const unsigned int HISTORY_VERSION = 23;
+
HistoryManager::HistoryManager(QObject *parent)
: QWebHistoryInterface(parent)
, m_saveTimer(new AutoSaver(this))
@@ -68,21 +70,25 @@ HistoryManager::HistoryManager(QObject *parent)
QWebHistoryInterface::setDefaultInterface(this);
}
+
HistoryManager::~HistoryManager()
{
m_saveTimer->saveIfNeccessary();
}
+
QList<HistoryItem> HistoryManager::history() const
{
return m_history;
}
+
bool HistoryManager::historyContains(const QString &url) const
{
return m_historyFilterModel->historyContains(url);
}
+
void HistoryManager::addHistoryEntry(const QString &url)
{
QUrl cleanUrl(url);
@@ -92,6 +98,7 @@ void HistoryManager::addHistoryEntry(const QString &url)
addHistoryItem(item);
}
+
void HistoryManager::setHistory(const QList<HistoryItem> &history, bool loadedAndSorted)
{
m_history = history;
@@ -111,21 +118,25 @@ void HistoryManager::setHistory(const QList<HistoryItem> &history, bool loadedAn
emit historyReset();
}
+
HistoryModel *HistoryManager::historyModel() const
{
return m_historyModel;
}
+
HistoryFilterModel *HistoryManager::historyFilterModel() const
{
return m_historyFilterModel;
}
+
HistoryTreeModel *HistoryManager::historyTreeModel() const
{
return m_historyTreeModel;
}
+
void HistoryManager::checkForExpired()
{
if (m_historyLimit < 0 || m_history.isEmpty())
@@ -155,6 +166,7 @@ void HistoryManager::checkForExpired()
m_expiredTimer.start(nextTimeout * 1000);
}
+
void HistoryManager::addHistoryItem(const HistoryItem &item)
{
QWebSettings *globalSettings = QWebSettings::globalSettings();
@@ -167,6 +179,8 @@ void HistoryManager::addHistoryItem(const HistoryItem &item)
checkForExpired();
}
+
+
void HistoryManager::updateHistoryItem(const QUrl &url, const QString &title)
{
for (int i = 0; i < m_history.count(); ++i) {
@@ -181,11 +195,13 @@ void HistoryManager::updateHistoryItem(const QUrl &url, const QString &title)
}
}
+
int HistoryManager::historyLimit() const
{
return m_historyLimit;
}
+
void HistoryManager::setHistoryLimit(int limit)
{
if (m_historyLimit == limit)
@@ -195,6 +211,7 @@ void HistoryManager::setHistoryLimit(int limit)
m_saveTimer->changeOccurred();
}
+
void HistoryManager::clear()
{
m_history.clear();
@@ -204,6 +221,7 @@ void HistoryManager::clear()
historyReset();
}
+
void HistoryManager::loadSettings()
{
// load settings
@@ -212,6 +230,8 @@ void HistoryManager::loadSettings()
m_historyLimit = settings.value(QLatin1String("historyLimit"), 30).toInt();
}
+
+
void HistoryManager::load()
{
loadSettings();
@@ -275,6 +295,7 @@ void HistoryManager::load()
}
}
+
void HistoryManager::save()
{
QSettings settings;
@@ -339,6 +360,10 @@ void HistoryManager::save()
m_lastSavedUrl = m_history.value(0).url;
}
+
+
+// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+
HistoryModel::HistoryModel(HistoryManager *history, QObject *parent)
: QAbstractTableModel(parent)
, m_history(history)
@@ -350,23 +375,27 @@ HistoryModel::HistoryModel(HistoryManager *history, QObject *parent)
connect(m_history, SIGNAL(entryUpdated(int)), this, SLOT(entryUpdated(int)));
}
+
void HistoryModel::historyReset()
{
reset();
}
+
void HistoryModel::entryAdded()
{
beginInsertRows(QModelIndex(), 0, 0);
endInsertRows();
}
+
void HistoryModel::entryUpdated(int offset)
{
QModelIndex idx = index(offset, 0);
emit dataChanged(idx, idx);
}
+
QVariant HistoryModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (orientation == Qt::Horizontal
@@ -379,6 +408,7 @@ QVariant HistoryModel::headerData(int section, Qt::Orientation orientation, int
return QAbstractTableModel::headerData(section, orientation, role);
}
+
QVariant HistoryModel::data(const QModelIndex &index, int role) const
{
QList<HistoryItem> lst = m_history->history();
@@ -419,16 +449,19 @@ QVariant HistoryModel::data(const QModelIndex &index, int role) const
return QVariant();
}
+
int HistoryModel::columnCount(const QModelIndex &parent) const
{
return (parent.isValid()) ? 0 : 2;
}
+
int HistoryModel::rowCount(const QModelIndex &parent) const
{
return (parent.isValid()) ? 0 : m_history->history().count();
}
+
bool HistoryModel::removeRows(int row, int count, const QModelIndex &parent)
{
if (parent.isValid())
@@ -445,6 +478,10 @@ bool HistoryModel::removeRows(int row, int count, const QModelIndex &parent)
return true;
}
+
+
+// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+
#define MOVEDROWS 15
/*
@@ -563,23 +600,27 @@ QModelIndex HistoryMenuModel::parent(const QModelIndex &index) const
}
+// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+
HistoryMenu::HistoryMenu(QWidget *parent)
: ModelMenu(parent)
, m_history(0)
{
- connect(this, SIGNAL(activated(const QModelIndex &)),
- this, SLOT(activated(const QModelIndex &)));
+ connect(this, SIGNAL(activated(const QModelIndex &)), this, SLOT(activated(const QModelIndex &)));
setHoverRole(HistoryModel::UrlStringRole);
}
+
void HistoryMenu::activated(const QModelIndex &index)
{
emit openUrl(index.data(HistoryModel::UrlRole).toUrl());
}
+
bool HistoryMenu::prePopulated()
{
- if (!m_history) {
+ if (!m_history)
+ {
m_history = BrowserApplication::historyManager();
m_historyMenuModel = new HistoryMenuModel(m_history->historyTreeModel(), this);
setModel(m_historyMenuModel);
@@ -594,41 +635,47 @@ bool HistoryMenu::prePopulated()
return false;
}
+
void HistoryMenu::postPopulated()
{
if (m_history->history().count() > 0)
addSeparator();
- QAction *showAllAction = new QAction( i18n("Show All History"), this);
+ KAction *showAllAction = new KAction( i18n("Show All History"), this);
connect(showAllAction, SIGNAL(triggered()), this, SLOT(showHistoryDialog()));
addAction(showAllAction);
- QAction *clearAction = new QAction( i18n("Clear History"), this);
+ KAction *clearAction = new KAction( i18n("Clear History"), this);
connect(clearAction, SIGNAL(triggered()), m_history, SLOT(clear()));
addAction(clearAction);
}
+
void HistoryMenu::showHistoryDialog()
{
HistoryDialog *dialog = new HistoryDialog(this);
- connect(dialog, SIGNAL(openUrl(const QUrl&)),
- this, SIGNAL(openUrl(const QUrl&)));
+ connect(dialog, SIGNAL(openUrl(const QUrl&)), this, SIGNAL(openUrl(const QUrl&)));
dialog->show();
}
-void HistoryMenu::setInitialActions(QList<QAction*> actions)
+
+void HistoryMenu::setInitialActions(QList<KAction*> actions)
{
m_initialActions = actions;
for (int i = 0; i < m_initialActions.count(); ++i)
addAction(m_initialActions.at(i));
}
+
+// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+
TreeProxyModel::TreeProxyModel(QObject *parent) : QSortFilterProxyModel(parent)
{
setSortRole(HistoryModel::DateTimeRole);
setFilterCaseSensitivity(Qt::CaseInsensitive);
}
+
bool TreeProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
{
if (!source_parent.isValid())
@@ -636,6 +683,9 @@ bool TreeProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_
return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent);
}
+
+// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+
HistoryDialog::HistoryDialog(QWidget *parent, HistoryManager *setHistory) : QDialog(parent)
{
HistoryManager *history = setHistory;
@@ -666,6 +716,7 @@ HistoryDialog::HistoryDialog(QWidget *parent, HistoryManager *setHistory) : QDia
this, SLOT(customContextMenuRequested(const QPoint &)));
}
+
void HistoryDialog::customContextMenuRequested(const QPoint &pos)
{
QMenu menu;
@@ -680,6 +731,7 @@ void HistoryDialog::customContextMenuRequested(const QPoint &pos)
menu.exec(QCursor::pos());
}
+
void HistoryDialog::open()
{
QModelIndex index = tree->currentIndex();
@@ -688,6 +740,7 @@ void HistoryDialog::open()
emit openUrl(index.data(HistoryModel::UrlRole).toUrl());
}
+
void HistoryDialog::copy()
{
QModelIndex index = tree->currentIndex();
@@ -699,6 +752,9 @@ void HistoryDialog::copy()
clipboard->setText(url);
}
+
+// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+
HistoryFilterModel::HistoryFilterModel(QAbstractItemModel *sourceModel, QObject *parent)
: QAbstractProxyModel(parent),
m_loaded(false)
@@ -706,6 +762,7 @@ HistoryFilterModel::HistoryFilterModel(QAbstractItemModel *sourceModel, QObject
setSourceModel(sourceModel);
}
+
int HistoryFilterModel::historyLocation(const QString &url) const
{
load();
@@ -714,11 +771,13 @@ int HistoryFilterModel::historyLocation(const QString &url) const
return sourceModel()->rowCount() - m_historyHash.value(url);
}
+
QVariant HistoryFilterModel::data(const QModelIndex &index, int role) const
{
return QAbstractProxyModel::data(index, role);
}
+
void HistoryFilterModel::setSourceModel(QAbstractItemModel *newSourceModel)
{
if (sourceModel()) {
@@ -745,22 +804,26 @@ void HistoryFilterModel::setSourceModel(QAbstractItemModel *newSourceModel)
}
}
+
void HistoryFilterModel::sourceDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
{
emit dataChanged(mapFromSource(topLeft), mapFromSource(bottomRight));
}
+
QVariant HistoryFilterModel::headerData(int section, Qt::Orientation orientation, int role) const
{
return sourceModel()->headerData(section, orientation, role);
}
+
void HistoryFilterModel::sourceReset()
{
m_loaded = false;
reset();
}
+
int HistoryFilterModel::rowCount(const QModelIndex &parent) const
{
load();
@@ -769,11 +832,13 @@ int HistoryFilterModel::rowCount(const QModelIndex &parent) const
return m_historyHash.count();
}
+
int HistoryFilterModel::columnCount(const QModelIndex &parent) const
{
return (parent.isValid()) ? 0 : 2;
}
+
QModelIndex HistoryFilterModel::mapToSource(const QModelIndex &proxyIndex) const
{
load();
@@ -781,6 +846,7 @@ QModelIndex HistoryFilterModel::mapToSource(const QModelIndex &proxyIndex) const
return sourceModel()->index(sourceRow, proxyIndex.column());
}
+
QModelIndex HistoryFilterModel::mapFromSource(const QModelIndex &sourceIndex) const
{
load();
@@ -807,6 +873,7 @@ QModelIndex HistoryFilterModel::mapFromSource(const QModelIndex &sourceIndex) co
return createIndex(realRow, sourceIndex.column(), sourceModel()->rowCount() - sourceIndex.row());
}
+
QModelIndex HistoryFilterModel::index(int row, int column, const QModelIndex &parent) const
{
load();
@@ -817,11 +884,13 @@ QModelIndex HistoryFilterModel::index(int row, int column, const QModelIndex &pa
return createIndex(row, column, m_sourceRow[row]);
}
+
QModelIndex HistoryFilterModel::parent(const QModelIndex &) const
{
return QModelIndex();
}
+
void HistoryFilterModel::load() const
{
if (m_loaded)
@@ -840,6 +909,7 @@ void HistoryFilterModel::load() const
m_loaded = true;
}
+
void HistoryFilterModel::sourceRowsInserted(const QModelIndex &parent, int start, int end)
{
Q_ASSERT(start == end && start == 0);
@@ -862,6 +932,7 @@ void HistoryFilterModel::sourceRowsInserted(const QModelIndex &parent, int start
endInsertRows();
}
+
void HistoryFilterModel::sourceRowsRemoved(const QModelIndex &, int start, int end)
{
Q_UNUSED(start);
@@ -869,6 +940,9 @@ void HistoryFilterModel::sourceRowsRemoved(const QModelIndex &, int start, int e
sourceReset();
}
+
+
+// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/*
Removing a continuous block of rows will remove filtered rows too as this is
the users intention.
@@ -894,11 +968,13 @@ bool HistoryFilterModel::removeRows(int row, int count, const QModelIndex &paren
return true;
}
+
HistoryCompletionModel::HistoryCompletionModel(QObject *parent)
: QAbstractProxyModel(parent)
{
}
+
QVariant HistoryCompletionModel::data(const QModelIndex &index, int role) const
{
if (sourceModel()
@@ -919,22 +995,26 @@ QVariant HistoryCompletionModel::data(const QModelIndex &index, int role) const
return QAbstractProxyModel::data(index, role);
}
+
int HistoryCompletionModel::rowCount(const QModelIndex &parent) const
{
return (parent.isValid() || !sourceModel()) ? 0 : sourceModel()->rowCount(parent) * 2;
}
+
int HistoryCompletionModel::columnCount(const QModelIndex &parent) const
{
return (parent.isValid()) ? 0 : 1;
}
+
QModelIndex HistoryCompletionModel::mapFromSource(const QModelIndex &sourceIndex) const
{
int row = sourceIndex.row() * 2;
return index(row, sourceIndex.column());
}
+
QModelIndex HistoryCompletionModel::mapToSource(const QModelIndex &proxyIndex) const
{
if (!sourceModel())
@@ -943,6 +1023,7 @@ QModelIndex HistoryCompletionModel::mapToSource(const QModelIndex &proxyIndex) c
return sourceModel()->index(row, proxyIndex.column());
}
+
QModelIndex HistoryCompletionModel::index(int row, int column, const QModelIndex &parent) const
{
if (row < 0 || row >= rowCount(parent)
@@ -951,11 +1032,13 @@ QModelIndex HistoryCompletionModel::index(int row, int column, const QModelIndex
return createIndex(row, column, 0);
}
+
QModelIndex HistoryCompletionModel::parent(const QModelIndex &) const
{
return QModelIndex();
}
+
void HistoryCompletionModel::setSourceModel(QAbstractItemModel *newSourceModel)
{
if (sourceModel()) {
@@ -979,22 +1062,29 @@ void HistoryCompletionModel::setSourceModel(QAbstractItemModel *newSourceModel)
reset();
}
+
void HistoryCompletionModel::sourceReset()
{
reset();
}
+
+
+// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+
HistoryTreeModel::HistoryTreeModel(QAbstractItemModel *sourceModel, QObject *parent)
: QAbstractProxyModel(parent)
{
setSourceModel(sourceModel);
}
+
QVariant HistoryTreeModel::headerData(int section, Qt::Orientation orientation, int role) const
{
return sourceModel()->headerData(section, orientation, role);
}
+
QVariant HistoryTreeModel::data(const QModelIndex &index, int role) const
{
if ((role == Qt::EditRole || role == Qt::DisplayRole)) {
@@ -1024,11 +1114,13 @@ QVariant HistoryTreeModel::data(const QModelIndex &index, int role) const
return QAbstractProxyModel::data(index, role);
}
+
int HistoryTreeModel::columnCount(const QModelIndex &parent) const
{
return sourceModel()->columnCount(mapToSource(parent));
}
+
int HistoryTreeModel::rowCount(const QModelIndex &parent) const
{
if ( parent.internalId() != 0
@@ -1062,6 +1154,7 @@ int HistoryTreeModel::rowCount(const QModelIndex &parent) const
return (end - start);
}
+
// Translate the top level date row into the offset where that date starts
int HistoryTreeModel::sourceDateRow(int row) const
{
@@ -1079,6 +1172,7 @@ int HistoryTreeModel::sourceDateRow(int row) const
return m_sourceRowCache.at(row);
}
+
QModelIndex HistoryTreeModel::mapToSource(const QModelIndex &proxyIndex) const
{
int offset = proxyIndex.internalId();
@@ -1088,6 +1182,7 @@ QModelIndex HistoryTreeModel::mapToSource(const QModelIndex &proxyIndex) const
return sourceModel()->index(startDateRow + proxyIndex.row(), proxyIndex.column());
}
+
QModelIndex HistoryTreeModel::index(int row, int column, const QModelIndex &parent) const
{
if (row < 0
@@ -1100,6 +1195,7 @@ QModelIndex HistoryTreeModel::index(int row, int column, const QModelIndex &pare
return createIndex(row, column, parent.row() + 1);
}
+
QModelIndex HistoryTreeModel::parent(const QModelIndex &index) const
{
int offset = index.internalId();
@@ -1108,6 +1204,7 @@ QModelIndex HistoryTreeModel::parent(const QModelIndex &index) const
return createIndex(offset - 1, 0, 0);
}
+
bool HistoryTreeModel::hasChildren(const QModelIndex &parent) const
{
QModelIndex grandparent = parent.parent();
@@ -1116,6 +1213,7 @@ bool HistoryTreeModel::hasChildren(const QModelIndex &parent) const
return false;
}
+
Qt::ItemFlags HistoryTreeModel::flags(const QModelIndex &index) const
{
if (!index.isValid())
@@ -1123,6 +1221,7 @@ Qt::ItemFlags HistoryTreeModel::flags(const QModelIndex &index) const
return Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled;
}
+
bool HistoryTreeModel::removeRows(int row, int count, const QModelIndex &parent)
{
if (row < 0 || count <= 0 || row + count > rowCount(parent))
@@ -1144,6 +1243,7 @@ bool HistoryTreeModel::removeRows(int row, int count, const QModelIndex &parent)
return true;
}
+
void HistoryTreeModel::setSourceModel(QAbstractItemModel *newSourceModel)
{
if (sourceModel()) {
@@ -1169,12 +1269,14 @@ void HistoryTreeModel::setSourceModel(QAbstractItemModel *newSourceModel)
reset();
}
+
void HistoryTreeModel::sourceReset()
{
m_sourceRowCache.clear();
reset();
}
+
void HistoryTreeModel::sourceRowsInserted(const QModelIndex &parent, int start, int end)
{
Q_UNUSED(parent); // Avoid warnings when compiling release
@@ -1197,6 +1299,7 @@ void HistoryTreeModel::sourceRowsInserted(const QModelIndex &parent, int start,
}
}
+
QModelIndex HistoryTreeModel::mapFromSource(const QModelIndex &sourceIndex) const
{
if (!sourceIndex.isValid())
@@ -1214,6 +1317,7 @@ QModelIndex HistoryTreeModel::mapFromSource(const QModelIndex &sourceIndex) cons
return createIndex(row, sourceIndex.column(), dateRow + 1);
}
+
void HistoryTreeModel::sourceRowsRemoved(const QModelIndex &parent, int start, int end)
{
Q_UNUSED(parent); // Avoid warnings when compiling release