From 63b34dc6ccd32c9bc7c3d8c0137ff12530238bde Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Thu, 30 Oct 2008 01:50:51 +0100 Subject: reKonq initial commit. Yeah! --- src/history.cpp | 1277 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1277 insertions(+) create mode 100644 src/history.cpp (limited to 'src/history.cpp') diff --git a/src/history.cpp b/src/history.cpp new file mode 100644 index 00000000..fef1920c --- /dev/null +++ b/src/history.cpp @@ -0,0 +1,1277 @@ +/**************************************************************************** +** +** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the demonstration applications of the Qt Toolkit. +** +** Commercial Usage +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information +** to ensure GNU General Public Licensing requirements will be met: +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. In addition, as a special +** exception, Nokia gives you certain additional rights. These rights +** are described in the Nokia Qt GPL Exception version 1.3, included in +** the file GPL_EXCEPTION.txt in this package. +** +** Qt for Windows(R) Licensees +** As a special exception, Nokia, as the sole copyright holder for Qt +** Designer, grants users of the Qt/Eclipse Integration plug-in the +** right for the Qt/Eclipse Integration to link to functionality +** provided by Qt Designer and its related libraries. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** +****************************************************************************/ + +#include "history.h" + +#include "autosaver.h" +#include "browserapplication.h" + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include + +#include +#include + +#include + +static const unsigned int HISTORY_VERSION = 23; + +HistoryManager::HistoryManager(QObject *parent) + : QWebHistoryInterface(parent) + , m_saveTimer(new AutoSaver(this)) + , m_historyLimit(30) + , m_historyModel(0) + , m_historyFilterModel(0) + , m_historyTreeModel(0) +{ + m_expiredTimer.setSingleShot(true); + connect(&m_expiredTimer, SIGNAL(timeout()), + this, SLOT(checkForExpired())); + connect(this, SIGNAL(entryAdded(const HistoryItem &)), + m_saveTimer, SLOT(changeOccurred())); + connect(this, SIGNAL(entryRemoved(const HistoryItem &)), + m_saveTimer, SLOT(changeOccurred())); + load(); + + m_historyModel = new HistoryModel(this, this); + m_historyFilterModel = new HistoryFilterModel(m_historyModel, this); + m_historyTreeModel = new HistoryTreeModel(m_historyFilterModel, this); + + // QWebHistoryInterface will delete the history manager + QWebHistoryInterface::setDefaultInterface(this); +} + +HistoryManager::~HistoryManager() +{ + m_saveTimer->saveIfNeccessary(); +} + +QList 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); + cleanUrl.setPassword(QString()); + cleanUrl.setHost(cleanUrl.host().toLower()); + HistoryItem item(cleanUrl.toString(), QDateTime::currentDateTime()); + addHistoryItem(item); +} + +void HistoryManager::setHistory(const QList &history, bool loadedAndSorted) +{ + m_history = history; + + // verify that it is sorted by date + if (!loadedAndSorted) + qSort(m_history.begin(), m_history.end()); + + checkForExpired(); + + if (loadedAndSorted) { + m_lastSavedUrl = m_history.value(0).url; + } else { + m_lastSavedUrl = QString(); + m_saveTimer->changeOccurred(); + } + 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()) + return; + + QDateTime now = QDateTime::currentDateTime(); + int nextTimeout = 0; + + while (!m_history.isEmpty()) { + QDateTime checkForExpired = m_history.last().dateTime; + checkForExpired.setDate(checkForExpired.date().addDays(m_historyLimit)); + if (now.daysTo(checkForExpired) > 7) { + // check at most in a week to prevent int overflows on the timer + nextTimeout = 7 * 86400; + } else { + nextTimeout = now.secsTo(checkForExpired); + } + if (nextTimeout > 0) + break; + HistoryItem item = m_history.takeLast(); + // remove from saved file also + m_lastSavedUrl = QString(); + emit entryRemoved(item); + } + + if (nextTimeout > 0) + m_expiredTimer.start(nextTimeout * 1000); +} + +void HistoryManager::addHistoryItem(const HistoryItem &item) +{ + QWebSettings *globalSettings = QWebSettings::globalSettings(); + if (globalSettings->testAttribute(QWebSettings::PrivateBrowsingEnabled)) + return; + + m_history.prepend(item); + emit entryAdded(item); + if (m_history.count() == 1) + checkForExpired(); +} + +void HistoryManager::updateHistoryItem(const QUrl &url, const QString &title) +{ + for (int i = 0; i < m_history.count(); ++i) { + if (url == m_history.at(i).url) { + m_history[i].title = title; + m_saveTimer->changeOccurred(); + if (m_lastSavedUrl.isEmpty()) + m_lastSavedUrl = m_history.at(i).url; + emit entryUpdated(i); + break; + } + } +} + +int HistoryManager::historyLimit() const +{ + return m_historyLimit; +} + +void HistoryManager::setHistoryLimit(int limit) +{ + if (m_historyLimit == limit) + return; + m_historyLimit = limit; + checkForExpired(); + m_saveTimer->changeOccurred(); +} + +void HistoryManager::clear() +{ + m_history.clear(); + m_lastSavedUrl = QString(); + m_saveTimer->changeOccurred(); + m_saveTimer->saveIfNeccessary(); + historyReset(); +} + +void HistoryManager::loadSettings() +{ + // load settings + QSettings settings; + settings.beginGroup(QLatin1String("history")); + m_historyLimit = settings.value(QLatin1String("historyLimit"), 30).toInt(); +} + +void HistoryManager::load() +{ + loadSettings(); + + QFile historyFile(QDesktopServices::storageLocation(QDesktopServices::DataLocation) + + QLatin1String("/history")); + if (!historyFile.exists()) + return; + if (!historyFile.open(QFile::ReadOnly)) { + qWarning() << "Unable to open history file" << historyFile.fileName(); + return; + } + + QList list; + QDataStream in(&historyFile); + // Double check that the history file is sorted as it is read in + bool needToSort = false; + HistoryItem lastInsertedItem; + QByteArray data; + QDataStream stream; + QBuffer buffer; + stream.setDevice(&buffer); + while (!historyFile.atEnd()) { + in >> data; + buffer.close(); + buffer.setBuffer(&data); + buffer.open(QIODevice::ReadOnly); + quint32 ver; + stream >> ver; + if (ver != HISTORY_VERSION) + continue; + HistoryItem item; + stream >> item.url; + stream >> item.dateTime; + stream >> item.title; + + if (!item.dateTime.isValid()) + continue; + + if (item == lastInsertedItem) { + if (lastInsertedItem.title.isEmpty() && !list.isEmpty()) + list[0].title = item.title; + continue; + } + + if (!needToSort && !list.isEmpty() && lastInsertedItem < item) + needToSort = true; + + list.prepend(item); + lastInsertedItem = item; + } + if (needToSort) + qSort(list.begin(), list.end()); + + setHistory(list, true); + + // If we had to sort re-write the whole history sorted + if (needToSort) { + m_lastSavedUrl = QString(); + m_saveTimer->changeOccurred(); + } +} + +void HistoryManager::save() +{ + QSettings settings; + settings.beginGroup(QLatin1String("history")); + settings.setValue(QLatin1String("historyLimit"), m_historyLimit); + + bool saveAll = m_lastSavedUrl.isEmpty(); + int first = m_history.count() - 1; + if (!saveAll) { + // find the first one to save + for (int i = 0; i < m_history.count(); ++i) { + if (m_history.at(i).url == m_lastSavedUrl) { + first = i - 1; + break; + } + } + } + if (first == m_history.count() - 1) + saveAll = true; + + QString directory = QDesktopServices::storageLocation(QDesktopServices::DataLocation); + if (directory.isEmpty()) + directory = QDir::homePath() + QLatin1String("/.") + QCoreApplication::applicationName(); + if (!QFile::exists(directory)) { + QDir dir; + dir.mkpath(directory); + } + + QFile historyFile(directory + QLatin1String("/history")); + // When saving everything use a temporary file to prevent possible data loss. + QTemporaryFile tempFile; + tempFile.setAutoRemove(false); + bool open = false; + if (saveAll) { + open = tempFile.open(); + } else { + open = historyFile.open(QFile::Append); + } + + if (!open) { + qWarning() << "Unable to open history file for saving" + << (saveAll ? tempFile.fileName() : historyFile.fileName()); + return; + } + + QDataStream out(saveAll ? &tempFile : &historyFile); + for (int i = first; i >= 0; --i) { + QByteArray data; + QDataStream stream(&data, QIODevice::WriteOnly); + HistoryItem item = m_history.at(i); + stream << HISTORY_VERSION << item.url << item.dateTime << item.title; + out << data; + } + tempFile.close(); + + if (saveAll) { + if (historyFile.exists() && !historyFile.remove()) + qWarning() << "History: error removing old history." << historyFile.errorString(); + if (!tempFile.rename(historyFile.fileName())) + qWarning() << "History: error moving new history over old." << tempFile.errorString() << historyFile.fileName(); + } + m_lastSavedUrl = m_history.value(0).url; +} + +HistoryModel::HistoryModel(HistoryManager *history, QObject *parent) + : QAbstractTableModel(parent) + , m_history(history) +{ + Q_ASSERT(m_history); + connect(m_history, SIGNAL(historyReset()), + this, SLOT(historyReset())); + connect(m_history, SIGNAL(entryRemoved(const HistoryItem &)), + this, SLOT(historyReset())); + + connect(m_history, SIGNAL(entryAdded(const HistoryItem &)), + this, SLOT(entryAdded())); + 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 + && role == Qt::DisplayRole) { + switch (section) { + case 0: return tr("Title"); + case 1: return tr("Address"); + } + } + return QAbstractTableModel::headerData(section, orientation, role); +} + +QVariant HistoryModel::data(const QModelIndex &index, int role) const +{ + QList lst = m_history->history(); + if (index.row() < 0 || index.row() >= lst.size()) + return QVariant(); + + const HistoryItem &item = lst.at(index.row()); + switch (role) { + case DateTimeRole: + return item.dateTime; + case DateRole: + return item.dateTime.date(); + case UrlRole: + return QUrl(item.url); + case UrlStringRole: + return item.url; + case Qt::DisplayRole: + case Qt::EditRole: { + switch (index.column()) { + case 0: + // when there is no title try to generate one from the url + if (item.title.isEmpty()) { + QString page = QFileInfo(QUrl(item.url).path()).fileName(); + if (!page.isEmpty()) + return page; + return item.url; + } + return item.title; + case 1: + return item.url; + } + } + case Qt::DecorationRole: + if (index.column() == 0) { + return BrowserApplication::instance()->icon(item.url); + } + } + 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()) + return false; + int lastRow = row + count - 1; + beginRemoveRows(parent, row, lastRow); + QList lst = m_history->history(); + for (int i = lastRow; i >= row; --i) + lst.removeAt(i); + disconnect(m_history, SIGNAL(historyReset()), this, SLOT(historyReset())); + m_history->setHistory(lst); + connect(m_history, SIGNAL(historyReset()), this, SLOT(historyReset())); + endRemoveRows(); + return true; +} + +#define MOVEDROWS 15 + +/* + Maps the first bunch of items of the source model to the root +*/ +HistoryMenuModel::HistoryMenuModel(HistoryTreeModel *sourceModel, QObject *parent) + : QAbstractProxyModel(parent) + , m_treeModel(sourceModel) +{ + setSourceModel(sourceModel); +} + +int HistoryMenuModel::bumpedRows() const +{ + QModelIndex first = m_treeModel->index(0, 0); + if (!first.isValid()) + return 0; + return qMin(m_treeModel->rowCount(first), MOVEDROWS); +} + +int HistoryMenuModel::columnCount(const QModelIndex &parent) const +{ + return m_treeModel->columnCount(mapToSource(parent)); +} + +int HistoryMenuModel::rowCount(const QModelIndex &parent) const +{ + if (parent.column() > 0) + return 0; + + if (!parent.isValid()) { + int folders = sourceModel()->rowCount(); + int bumpedItems = bumpedRows(); + if (bumpedItems <= MOVEDROWS + && bumpedItems == sourceModel()->rowCount(sourceModel()->index(0, 0))) + --folders; + return bumpedItems + folders; + } + + if (parent.internalId() == -1) { + if (parent.row() < bumpedRows()) + return 0; + } + + QModelIndex idx = mapToSource(parent); + int defaultCount = sourceModel()->rowCount(idx); + if (idx == sourceModel()->index(0, 0)) + return defaultCount - bumpedRows(); + return defaultCount; +} + +QModelIndex HistoryMenuModel::mapFromSource(const QModelIndex &sourceIndex) const +{ + // currently not used or autotested + Q_ASSERT(false); + int sr = m_treeModel->mapToSource(sourceIndex).row(); + return createIndex(sourceIndex.row(), sourceIndex.column(), sr); +} + +QModelIndex HistoryMenuModel::mapToSource(const QModelIndex &proxyIndex) const +{ + if (!proxyIndex.isValid()) + return QModelIndex(); + + if (proxyIndex.internalId() == -1) { + int bumpedItems = bumpedRows(); + if (proxyIndex.row() < bumpedItems) + return m_treeModel->index(proxyIndex.row(), proxyIndex.column(), m_treeModel->index(0, 0)); + if (bumpedItems <= MOVEDROWS && bumpedItems == sourceModel()->rowCount(m_treeModel->index(0, 0))) + --bumpedItems; + return m_treeModel->index(proxyIndex.row() - bumpedItems, proxyIndex.column()); + } + + QModelIndex historyIndex = m_treeModel->sourceModel()->index(proxyIndex.internalId(), proxyIndex.column()); + QModelIndex treeIndex = m_treeModel->mapFromSource(historyIndex); + return treeIndex; +} + +QModelIndex HistoryMenuModel::index(int row, int column, const QModelIndex &parent) const +{ + if (row < 0 + || column < 0 || column >= columnCount(parent) + || parent.column() > 0) + return QModelIndex(); + if (!parent.isValid()) + return createIndex(row, column, -1); + + QModelIndex treeIndexParent = mapToSource(parent); + + int bumpedItems = 0; + if (treeIndexParent == m_treeModel->index(0, 0)) + bumpedItems = bumpedRows(); + QModelIndex treeIndex = m_treeModel->index(row + bumpedItems, column, treeIndexParent); + QModelIndex historyIndex = m_treeModel->mapToSource(treeIndex); + int historyRow = historyIndex.row(); + if (historyRow == -1) + historyRow = treeIndex.row(); + return createIndex(row, column, historyRow); +} + +QModelIndex HistoryMenuModel::parent(const QModelIndex &index) const +{ + int offset = index.internalId(); + if (offset == -1 || !index.isValid()) + return QModelIndex(); + + QModelIndex historyIndex = m_treeModel->sourceModel()->index(index.internalId(), 0); + QModelIndex treeIndex = m_treeModel->mapFromSource(historyIndex); + QModelIndex treeIndexParent = treeIndex.parent(); + + int sr = m_treeModel->mapToSource(treeIndexParent).row(); + int bumpedItems = bumpedRows(); + if (bumpedItems <= MOVEDROWS && bumpedItems == sourceModel()->rowCount(sourceModel()->index(0, 0))) + --bumpedItems; + return createIndex(bumpedItems + treeIndexParent.row(), treeIndexParent.column(), sr); +} + + +HistoryMenu::HistoryMenu(QWidget *parent) + : ModelMenu(parent) + , m_history(0) +{ + 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) { + m_history = BrowserApplication::historyManager(); + m_historyMenuModel = new HistoryMenuModel(m_history->historyTreeModel(), this); + setModel(m_historyMenuModel); + } + // initial actions + for (int i = 0; i < m_initialActions.count(); ++i) + addAction(m_initialActions.at(i)); + if (!m_initialActions.isEmpty()) + addSeparator(); + setFirstSeparator(m_historyMenuModel->bumpedRows()); + + return false; +} + +void HistoryMenu::postPopulated() +{ + if (m_history->history().count() > 0) + addSeparator(); + + QAction *showAllAction = new QAction(tr("Show All History"), this); + connect(showAllAction, SIGNAL(triggered()), this, SLOT(showHistoryDialog())); + addAction(showAllAction); + + QAction *clearAction = new QAction(tr("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&))); + dialog->show(); +} + +void HistoryMenu::setInitialActions(QList 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()) + return true; + return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent); +} + +HistoryDialog::HistoryDialog(QWidget *parent, HistoryManager *setHistory) : QDialog(parent) +{ + HistoryManager *history = setHistory; + if (!history) + history = BrowserApplication::historyManager(); + setupUi(this); + tree->setUniformRowHeights(true); + tree->setSelectionBehavior(QAbstractItemView::SelectRows); + tree->setTextElideMode(Qt::ElideMiddle); + QAbstractItemModel *model = history->historyTreeModel(); + TreeProxyModel *proxyModel = new TreeProxyModel(this); + connect(search, SIGNAL(textChanged(QString)), + proxyModel, SLOT(setFilterFixedString(QString))); + connect(removeButton, SIGNAL(clicked()), tree, SLOT(removeOne())); + connect(removeAllButton, SIGNAL(clicked()), history, SLOT(clear())); + proxyModel->setSourceModel(model); + tree->setModel(proxyModel); + tree->setExpanded(proxyModel->index(0, 0), true); + tree->setAlternatingRowColors(true); + QFontMetrics fm(font()); + int header = fm.width(QLatin1Char('m')) * 40; + tree->header()->resizeSection(0, header); + tree->header()->setStretchLastSection(true); + connect(tree, SIGNAL(activated(const QModelIndex&)), + this, SLOT(open())); + tree->setContextMenuPolicy(Qt::CustomContextMenu); + connect(tree, SIGNAL(customContextMenuRequested(const QPoint &)), + this, SLOT(customContextMenuRequested(const QPoint &))); +} + +void HistoryDialog::customContextMenuRequested(const QPoint &pos) +{ + QMenu menu; + QModelIndex index = tree->indexAt(pos); + index = index.sibling(index.row(), 0); + if (index.isValid() && !tree->model()->hasChildren(index)) { + menu.addAction(tr("Open"), this, SLOT(open())); + menu.addSeparator(); + menu.addAction(tr("Copy"), this, SLOT(copy())); + } + menu.addAction(tr("Delete"), tree, SLOT(removeOne())); + menu.exec(QCursor::pos()); +} + +void HistoryDialog::open() +{ + QModelIndex index = tree->currentIndex(); + if (!index.parent().isValid()) + return; + emit openUrl(index.data(HistoryModel::UrlRole).toUrl()); +} + +void HistoryDialog::copy() +{ + QModelIndex index = tree->currentIndex(); + if (!index.parent().isValid()) + return; + QString url = index.data(HistoryModel::UrlStringRole).toString(); + + QClipboard *clipboard = QApplication::clipboard(); + clipboard->setText(url); +} + +HistoryFilterModel::HistoryFilterModel(QAbstractItemModel *sourceModel, QObject *parent) + : QAbstractProxyModel(parent), + m_loaded(false) +{ + setSourceModel(sourceModel); +} + +int HistoryFilterModel::historyLocation(const QString &url) const +{ + load(); + if (!m_historyHash.contains(url)) + return 0; + 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()) { + disconnect(sourceModel(), SIGNAL(modelReset()), this, SLOT(sourceReset())); + disconnect(sourceModel(), SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), + this, SLOT(dataChanged(const QModelIndex &, const QModelIndex &))); + disconnect(sourceModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)), + this, SLOT(sourceRowsInserted(const QModelIndex &, int, int))); + disconnect(sourceModel(), SIGNAL(rowsRemoved(const QModelIndex &, int, int)), + this, SLOT(sourceRowsRemoved(const QModelIndex &, int, int))); + } + + QAbstractProxyModel::setSourceModel(newSourceModel); + + if (sourceModel()) { + m_loaded = false; + connect(sourceModel(), SIGNAL(modelReset()), this, SLOT(sourceReset())); + connect(sourceModel(), SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), + this, SLOT(sourceDataChanged(const QModelIndex &, const QModelIndex &))); + connect(sourceModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)), + this, SLOT(sourceRowsInserted(const QModelIndex &, int, int))); + connect(sourceModel(), SIGNAL(rowsRemoved(const QModelIndex &, int, int)), + this, SLOT(sourceRowsRemoved(const QModelIndex &, int, int))); + } +} + +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(); + if (parent.isValid()) + return 0; + return m_historyHash.count(); +} + +int HistoryFilterModel::columnCount(const QModelIndex &parent) const +{ + return (parent.isValid()) ? 0 : 2; +} + +QModelIndex HistoryFilterModel::mapToSource(const QModelIndex &proxyIndex) const +{ + load(); + int sourceRow = sourceModel()->rowCount() - proxyIndex.internalId(); + return sourceModel()->index(sourceRow, proxyIndex.column()); +} + +QModelIndex HistoryFilterModel::mapFromSource(const QModelIndex &sourceIndex) const +{ + load(); + QString url = sourceIndex.data(HistoryModel::UrlStringRole).toString(); + if (!m_historyHash.contains(url)) + return QModelIndex(); + + // This can be done in a binary search, but we can't use qBinary find + // because it can't take: qBinaryFind(m_sourceRow.end(), m_sourceRow.begin(), v); + // so if this is a performance bottlneck then convert to binary search, until then + // the cleaner/easier to read code wins the day. + int realRow = -1; + int sourceModelRow = sourceModel()->rowCount() - sourceIndex.row(); + + for (int i = 0; i < m_sourceRow.count(); ++i) { + if (m_sourceRow.at(i) == sourceModelRow) { + realRow = i; + break; + } + } + if (realRow == -1) + return QModelIndex(); + + return createIndex(realRow, sourceIndex.column(), sourceModel()->rowCount() - sourceIndex.row()); +} + +QModelIndex HistoryFilterModel::index(int row, int column, const QModelIndex &parent) const +{ + load(); + if (row < 0 || row >= rowCount(parent) + || column < 0 || column >= columnCount(parent)) + return QModelIndex(); + + return createIndex(row, column, m_sourceRow[row]); +} + +QModelIndex HistoryFilterModel::parent(const QModelIndex &) const +{ + return QModelIndex(); +} + +void HistoryFilterModel::load() const +{ + if (m_loaded) + return; + m_sourceRow.clear(); + m_historyHash.clear(); + m_historyHash.reserve(sourceModel()->rowCount()); + for (int i = 0; i < sourceModel()->rowCount(); ++i) { + QModelIndex idx = sourceModel()->index(i, 0); + QString url = idx.data(HistoryModel::UrlStringRole).toString(); + if (!m_historyHash.contains(url)) { + m_sourceRow.append(sourceModel()->rowCount() - i); + m_historyHash[url] = sourceModel()->rowCount() - i; + } + } + m_loaded = true; +} + +void HistoryFilterModel::sourceRowsInserted(const QModelIndex &parent, int start, int end) +{ + Q_ASSERT(start == end && start == 0); + Q_UNUSED(end); + if (!m_loaded) + return; + QModelIndex idx = sourceModel()->index(start, 0, parent); + QString url = idx.data(HistoryModel::UrlStringRole).toString(); + if (m_historyHash.contains(url)) { + int sourceRow = sourceModel()->rowCount() - m_historyHash[url]; + int realRow = mapFromSource(sourceModel()->index(sourceRow, 0)).row(); + beginRemoveRows(QModelIndex(), realRow, realRow); + m_sourceRow.removeAt(realRow); + m_historyHash.remove(url); + endRemoveRows(); + } + beginInsertRows(QModelIndex(), 0, 0); + m_historyHash.insert(url, sourceModel()->rowCount() - start); + m_sourceRow.insert(0, sourceModel()->rowCount()); + endInsertRows(); +} + +void HistoryFilterModel::sourceRowsRemoved(const QModelIndex &, int start, int end) +{ + Q_UNUSED(start); + Q_UNUSED(end); + sourceReset(); +} + +/* + Removing a continuous block of rows will remove filtered rows too as this is + the users intention. +*/ +bool HistoryFilterModel::removeRows(int row, int count, const QModelIndex &parent) +{ + if (row < 0 || count <= 0 || row + count > rowCount(parent) || parent.isValid()) + return false; + int lastRow = row + count - 1; + disconnect(sourceModel(), SIGNAL(rowsRemoved(const QModelIndex &, int, int)), + this, SLOT(sourceRowsRemoved(const QModelIndex &, int, int))); + beginRemoveRows(parent, row, lastRow); + int oldCount = rowCount(); + int start = sourceModel()->rowCount() - m_sourceRow.value(row); + int end = sourceModel()->rowCount() - m_sourceRow.value(lastRow); + sourceModel()->removeRows(start, end - start + 1); + endRemoveRows(); + connect(sourceModel(), SIGNAL(rowsRemoved(const QModelIndex &, int, int)), + this, SLOT(sourceRowsRemoved(const QModelIndex &, int, int))); + m_loaded = false; + if (oldCount - count != rowCount()) + reset(); + return true; +} + +HistoryCompletionModel::HistoryCompletionModel(QObject *parent) + : QAbstractProxyModel(parent) +{ +} + +QVariant HistoryCompletionModel::data(const QModelIndex &index, int role) const +{ + if (sourceModel() + && (role == Qt::EditRole || role == Qt::DisplayRole) + && index.isValid()) { + QModelIndex idx = mapToSource(index); + idx = idx.sibling(idx.row(), 1); + QString urlString = idx.data(HistoryModel::UrlStringRole).toString(); + if (index.row() % 2) { + QUrl url = urlString; + QString s = url.toString(QUrl::RemoveScheme + | QUrl::RemoveUserInfo + | QUrl::StripTrailingSlash); + return s.mid(2); // strip // from the front + } + return urlString; + } + 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()) + return QModelIndex(); + int row = proxyIndex.row() / 2; + return sourceModel()->index(row, proxyIndex.column()); +} + +QModelIndex HistoryCompletionModel::index(int row, int column, const QModelIndex &parent) const +{ + if (row < 0 || row >= rowCount(parent) + || column < 0 || column >= columnCount(parent)) + return QModelIndex(); + return createIndex(row, column, 0); +} + +QModelIndex HistoryCompletionModel::parent(const QModelIndex &) const +{ + return QModelIndex(); +} + +void HistoryCompletionModel::setSourceModel(QAbstractItemModel *newSourceModel) +{ + if (sourceModel()) { + disconnect(sourceModel(), SIGNAL(modelReset()), this, SLOT(sourceReset())); + disconnect(sourceModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)), + this, SLOT(sourceReset())); + disconnect(sourceModel(), SIGNAL(rowsRemoved(const QModelIndex &, int, int)), + this, SLOT(sourceReset())); + } + + QAbstractProxyModel::setSourceModel(newSourceModel); + + if (newSourceModel) { + connect(newSourceModel, SIGNAL(modelReset()), this, SLOT(sourceReset())); + connect(sourceModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)), + this, SLOT(sourceReset())); + connect(sourceModel(), SIGNAL(rowsRemoved(const QModelIndex &, int, int)), + this, SLOT(sourceReset())); + } + + 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)) { + int start = index.internalId(); + if (start == 0) { + int offset = sourceDateRow(index.row()); + if (index.column() == 0) { + QModelIndex idx = sourceModel()->index(offset, 0); + QDate date = idx.data(HistoryModel::DateRole).toDate(); + if (date == QDate::currentDate()) + return tr("Earlier Today"); + return date.toString(QLatin1String("dddd, MMMM d, yyyy")); + } + if (index.column() == 1) { + return tr("%1 items").arg(rowCount(index.sibling(index.row(), 0))); + } + } + } + if (role == Qt::DecorationRole && index.column() == 0 && !index.parent().isValid()) + return QIcon(QLatin1String(":history.png")); + 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); + } + + 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 + || parent.column() > 0 + || !sourceModel()) + return 0; + + // row count OF dates + if (!parent.isValid()) { + if (!m_sourceRowCache.isEmpty()) + return m_sourceRowCache.count(); + QDate currentDate; + int rows = 0; + int totalRows = sourceModel()->rowCount(); + + for (int i = 0; i < totalRows; ++i) { + QDate rowDate = sourceModel()->index(i, 0).data(HistoryModel::DateRole).toDate(); + if (rowDate != currentDate) { + m_sourceRowCache.append(i); + currentDate = rowDate; + ++rows; + } + } + Q_ASSERT(m_sourceRowCache.count() == rows); + return rows; + } + + // row count FOR a date + int start = sourceDateRow(parent.row()); + int end = sourceDateRow(parent.row() + 1); + return (end - start); +} + +// Translate the top level date row into the offset where that date starts +int HistoryTreeModel::sourceDateRow(int row) const +{ + if (row <= 0) + return 0; + + if (m_sourceRowCache.isEmpty()) + rowCount(QModelIndex()); + + if (row >= m_sourceRowCache.count()) { + if (!sourceModel()) + return 0; + return sourceModel()->rowCount(); + } + return m_sourceRowCache.at(row); +} + +QModelIndex HistoryTreeModel::mapToSource(const QModelIndex &proxyIndex) const +{ + int offset = proxyIndex.internalId(); + if (offset == 0) + return QModelIndex(); + int startDateRow = sourceDateRow(offset - 1); + return sourceModel()->index(startDateRow + proxyIndex.row(), proxyIndex.column()); +} + +QModelIndex HistoryTreeModel::index(int row, int column, const QModelIndex &parent) const +{ + if (row < 0 + || column < 0 || column >= columnCount(parent) + || parent.column() > 0) + return QModelIndex(); + + if (!parent.isValid()) + return createIndex(row, column, 0); + return createIndex(row, column, parent.row() + 1); +} + +QModelIndex HistoryTreeModel::parent(const QModelIndex &index) const +{ + int offset = index.internalId(); + if (offset == 0 || !index.isValid()) + return QModelIndex(); + return createIndex(offset - 1, 0, 0); +} + +bool HistoryTreeModel::hasChildren(const QModelIndex &parent) const +{ + QModelIndex grandparent = parent.parent(); + if (!grandparent.isValid()) + return true; + return false; +} + +Qt::ItemFlags HistoryTreeModel::flags(const QModelIndex &index) const +{ + if (!index.isValid()) + return Qt::NoItemFlags; + 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)) + return false; + + if (parent.isValid()) { + // removing pages + int offset = sourceDateRow(parent.row()); + return sourceModel()->removeRows(offset + row, count); + } else { + // removing whole dates + for (int i = row + count - 1; i >= row; --i) { + QModelIndex dateParent = index(i, 0); + int offset = sourceDateRow(dateParent.row()); + if (!sourceModel()->removeRows(offset, rowCount(dateParent))) + return false; + } + } + return true; +} + +void HistoryTreeModel::setSourceModel(QAbstractItemModel *newSourceModel) +{ + if (sourceModel()) { + disconnect(sourceModel(), SIGNAL(modelReset()), this, SLOT(sourceReset())); + disconnect(sourceModel(), SIGNAL(layoutChanged()), this, SLOT(sourceReset())); + disconnect(sourceModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)), + this, SLOT(sourceRowsInserted(const QModelIndex &, int, int))); + disconnect(sourceModel(), SIGNAL(rowsRemoved(const QModelIndex &, int, int)), + this, SLOT(sourceRowsRemoved(const QModelIndex &, int, int))); + } + + QAbstractProxyModel::setSourceModel(newSourceModel); + + if (newSourceModel) { + connect(sourceModel(), SIGNAL(modelReset()), this, SLOT(sourceReset())); + connect(sourceModel(), SIGNAL(layoutChanged()), this, SLOT(sourceReset())); + connect(sourceModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)), + this, SLOT(sourceRowsInserted(const QModelIndex &, int, int))); + connect(sourceModel(), SIGNAL(rowsRemoved(const QModelIndex &, int, int)), + this, SLOT(sourceRowsRemoved(const QModelIndex &, int, int))); + } + + 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 + Q_ASSERT(!parent.isValid()); + if (start != 0 || start != end) { + m_sourceRowCache.clear(); + reset(); + return; + } + + m_sourceRowCache.clear(); + QModelIndex treeIndex = mapFromSource(sourceModel()->index(start, 0)); + QModelIndex treeParent = treeIndex.parent(); + if (rowCount(treeParent) == 1) { + beginInsertRows(QModelIndex(), 0, 0); + endInsertRows(); + } else { + beginInsertRows(treeParent, treeIndex.row(), treeIndex.row()); + endInsertRows(); + } +} + +QModelIndex HistoryTreeModel::mapFromSource(const QModelIndex &sourceIndex) const +{ + if (!sourceIndex.isValid()) + return QModelIndex(); + + if (m_sourceRowCache.isEmpty()) + rowCount(QModelIndex()); + + QList::iterator it; + it = qLowerBound(m_sourceRowCache.begin(), m_sourceRowCache.end(), sourceIndex.row()); + if (*it != sourceIndex.row()) + --it; + int dateRow = qMax(0, it - m_sourceRowCache.begin()); + int row = sourceIndex.row() - m_sourceRowCache.at(dateRow); + 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 + Q_ASSERT(!parent.isValid()); + if (m_sourceRowCache.isEmpty()) + return; + for (int i = end; i >= start;) { + QList::iterator it; + it = qLowerBound(m_sourceRowCache.begin(), m_sourceRowCache.end(), i); + // playing it safe + if (it == m_sourceRowCache.end()) { + m_sourceRowCache.clear(); + reset(); + return; + } + + if (*it != i) + --it; + int row = qMax(0, it - m_sourceRowCache.begin()); + int offset = m_sourceRowCache[row]; + QModelIndex dateParent = index(row, 0); + // If we can remove all the rows in the date do that and skip over them + int rc = rowCount(dateParent); + if (i - rc + 1 == offset && start <= i - rc + 1) { + beginRemoveRows(QModelIndex(), row, row); + m_sourceRowCache.removeAt(row); + i -= rc + 1; + } else { + beginRemoveRows(dateParent, i - offset, i - offset); + ++row; + --i; + } + for (int j = row; j < m_sourceRowCache.count(); ++j) + --m_sourceRowCache[j]; + endRemoveRows(); + } +} -- cgit v1.2.1 From 2147abb0c02358b512925191d3e545574ec80e08 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Sat, 1 Nov 2008 13:04:26 +0100 Subject: Localizing strings.. --- src/history.cpp | 127 +++++++++++++++++++++++--------------------------------- 1 file changed, 51 insertions(+), 76 deletions(-) (limited to 'src/history.cpp') diff --git a/src/history.cpp b/src/history.cpp index fef1920c..985a03ac 100644 --- a/src/history.cpp +++ b/src/history.cpp @@ -1,64 +1,47 @@ -/**************************************************************************** -** -** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the demonstration applications of the Qt Toolkit. -** -** Commercial Usage -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Commercial License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Nokia. -** -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information -** to ensure GNU General Public Licensing requirements will be met: -** http://www.fsf.org/licensing/licenses/info/GPLv2.html and -** http://www.gnu.org/copyleft/gpl.html. In addition, as a special -** exception, Nokia gives you certain additional rights. These rights -** are described in the Nokia Qt GPL Exception version 1.3, included in -** the file GPL_EXCEPTION.txt in this package. -** -** Qt for Windows(R) Licensees -** As a special exception, Nokia, as the sole copyright holder for Qt -** Designer, grants users of the Qt/Eclipse Integration plug-in the -** right for the Qt/Eclipse Integration to link to functionality -** provided by Qt Designer and its related libraries. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** -****************************************************************************/ +/* ============================================================ + * + * This file is a part of the reKonq project + * + * Copyright (C) 2008 by Andrea Diamantini + * + * + * This program is free software; you can redistribute it + * and/or modify it under the terms of the GNU General + * Public License as published by the Free Software Foundation; + * either version 2, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + * GNU General Public License for more details. + * + * ============================================================ */ + #include "history.h" #include "autosaver.h" #include "browserapplication.h" -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include -#include +#include -#include -#include -#include -#include +#include +#include +#include +#include -#include -#include +#include +#include -#include +#include static const unsigned int HISTORY_VERSION = 23; @@ -71,12 +54,9 @@ HistoryManager::HistoryManager(QObject *parent) , m_historyTreeModel(0) { m_expiredTimer.setSingleShot(true); - connect(&m_expiredTimer, SIGNAL(timeout()), - this, SLOT(checkForExpired())); - connect(this, SIGNAL(entryAdded(const HistoryItem &)), - m_saveTimer, SLOT(changeOccurred())); - connect(this, SIGNAL(entryRemoved(const HistoryItem &)), - m_saveTimer, SLOT(changeOccurred())); + connect(&m_expiredTimer, SIGNAL(timeout()), this, SLOT(checkForExpired())); + connect(this, SIGNAL(entryAdded(const HistoryItem &)), m_saveTimer, SLOT(changeOccurred())); + connect(this, SIGNAL(entryRemoved(const HistoryItem &)), m_saveTimer, SLOT(changeOccurred())); load(); m_historyModel = new HistoryModel(this, this); @@ -363,15 +343,10 @@ HistoryModel::HistoryModel(HistoryManager *history, QObject *parent) , m_history(history) { Q_ASSERT(m_history); - connect(m_history, SIGNAL(historyReset()), - this, SLOT(historyReset())); - connect(m_history, SIGNAL(entryRemoved(const HistoryItem &)), - this, SLOT(historyReset())); - - connect(m_history, SIGNAL(entryAdded(const HistoryItem &)), - this, SLOT(entryAdded())); - connect(m_history, SIGNAL(entryUpdated(int)), - this, SLOT(entryUpdated(int))); + connect(m_history, SIGNAL(historyReset()), this, SLOT(historyReset())); + connect(m_history, SIGNAL(entryRemoved(const HistoryItem &)), this, SLOT(historyReset())); + connect(m_history, SIGNAL(entryAdded(const HistoryItem &)), this, SLOT(entryAdded())); + connect(m_history, SIGNAL(entryUpdated(int)), this, SLOT(entryUpdated(int))); } void HistoryModel::historyReset() @@ -396,8 +371,8 @@ QVariant HistoryModel::headerData(int section, Qt::Orientation orientation, int if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { switch (section) { - case 0: return tr("Title"); - case 1: return tr("Address"); + case 0: return i18n("Title"); + case 1: return i18n("Address"); } } return QAbstractTableModel::headerData(section, orientation, role); @@ -623,11 +598,11 @@ void HistoryMenu::postPopulated() if (m_history->history().count() > 0) addSeparator(); - QAction *showAllAction = new QAction(tr("Show All History"), this); + QAction *showAllAction = new QAction( i18n("Show All History"), this); connect(showAllAction, SIGNAL(triggered()), this, SLOT(showHistoryDialog())); addAction(showAllAction); - QAction *clearAction = new QAction(tr("Clear History"), this); + QAction *clearAction = new QAction( i18n("Clear History"), this); connect(clearAction, SIGNAL(triggered()), m_history, SLOT(clear())); addAction(clearAction); } @@ -696,11 +671,11 @@ void HistoryDialog::customContextMenuRequested(const QPoint &pos) QModelIndex index = tree->indexAt(pos); index = index.sibling(index.row(), 0); if (index.isValid() && !tree->model()->hasChildren(index)) { - menu.addAction(tr("Open"), this, SLOT(open())); + menu.addAction( i18n("Open"), this, SLOT(open())); menu.addSeparator(); - menu.addAction(tr("Copy"), this, SLOT(copy())); + menu.addAction( i18n("Copy"), this, SLOT(copy())); } - menu.addAction(tr("Delete"), tree, SLOT(removeOne())); + menu.addAction( i18n("Delete"), tree, SLOT(removeOne())); menu.exec(QCursor::pos()); } @@ -1029,16 +1004,16 @@ QVariant HistoryTreeModel::data(const QModelIndex &index, int role) const QModelIndex idx = sourceModel()->index(offset, 0); QDate date = idx.data(HistoryModel::DateRole).toDate(); if (date == QDate::currentDate()) - return tr("Earlier Today"); + return i18n("Earlier Today"); return date.toString(QLatin1String("dddd, MMMM d, yyyy")); } if (index.column() == 1) { - return tr("%1 items").arg(rowCount(index.sibling(index.row(), 0))); + return QString(rowCount(index.sibling(index.row(), 0))) + i18n(" items") ; } } } if (role == Qt::DecorationRole && index.column() == 0 && !index.parent().isValid()) - return QIcon(QLatin1String(":history.png")); + return KIcon("view-history"); if (role == HistoryModel::DateRole && index.column() == 0 && index.internalId() == 0) { int offset = sourceDateRow(index.row()); QModelIndex idx = sourceModel()->index(offset, 0); -- cgit v1.2.1 From 4a0acb308cfecde67af334f48a521c221c4aee1a Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Fri, 7 Nov 2008 00:17:56 +0100 Subject: Setting right license --- src/history.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/history.cpp') diff --git a/src/history.cpp b/src/history.cpp index 985a03ac..ea322b65 100644 --- a/src/history.cpp +++ b/src/history.cpp @@ -2,6 +2,7 @@  *  * This file is a part of the reKonq project  * + * Copyright (C) 2007-2008 Trolltech ASA. All rights reserved * Copyright (C) 2008 by Andrea Diamantini  * * -- cgit v1.2.1 From d62176f7f2a6a204b5017bc661fff2d3a9f76e6e Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Sun, 30 Nov 2008 17:30:57 +0100 Subject: - Ported historyMenu to KAction - some adjs on urlbar - added TODO file to remember things --- src/history.cpp | 120 ++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 112 insertions(+), 8 deletions(-) (limited to 'src/history.cpp') 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 + 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 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 &history, bool loadedAndSorted) { m_history = history; @@ -111,21 +118,25 @@ void HistoryManager::setHistory(const QList &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 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 actions) + +void HistoryMenu::setInitialActions(QList 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 -- cgit v1.2.1 From b9f8ccd9099fa48406203ad5c5389266b3318d88 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Fri, 5 Dec 2008 00:27:23 +0100 Subject: QUrl --> KUrl! --- src/history.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/history.cpp') diff --git a/src/history.cpp b/src/history.cpp index cb6e80b0..43714166 100644 --- a/src/history.cpp +++ b/src/history.cpp @@ -181,10 +181,12 @@ void HistoryManager::addHistoryItem(const HistoryItem &item) -void HistoryManager::updateHistoryItem(const QUrl &url, const QString &title) +void HistoryManager::updateHistoryItem(const KUrl &url, const QString &title) { - for (int i = 0; i < m_history.count(); ++i) { - if (url == m_history.at(i).url) { + for (int i = 0; i < m_history.count(); ++i) + { + if (url == m_history.at(i).url) + { m_history[i].title = title; m_saveTimer->changeOccurred(); if (m_lastSavedUrl.isEmpty()) @@ -654,7 +656,7 @@ void HistoryMenu::postPopulated() void HistoryMenu::showHistoryDialog() { HistoryDialog *dialog = new HistoryDialog(this); - connect(dialog, SIGNAL(openUrl(const QUrl&)), this, SIGNAL(openUrl(const QUrl&))); + connect(dialog, SIGNAL(openUrl(const KUrl&)), this, SIGNAL(openUrl(const KUrl&))); dialog->show(); } -- cgit v1.2.1 From 9b508f95a69ba453bcd21780ace7ababaeeb797e Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Fri, 5 Dec 2008 01:47:03 +0100 Subject: Completely removed QSettings! --- src/history.cpp | 89 +++++++++++++++++++++++++++++++-------------------------- 1 file changed, 48 insertions(+), 41 deletions(-) (limited to 'src/history.cpp') diff --git a/src/history.cpp b/src/history.cpp index 43714166..930e73ae 100644 --- a/src/history.cpp +++ b/src/history.cpp @@ -18,32 +18,23 @@  *  * ============================================================ */ - +// Local Includes #include "history.h" #include "autosaver.h" #include "browserapplication.h" -#include -#include -#include -#include -#include -#include -#include +// Qt Includes +#include +#include +#include #include - -#include -#include -#include -#include - -#include -#include - #include +// KDE Includes +#include + static const unsigned int HISTORY_VERSION = 23; @@ -227,9 +218,9 @@ void HistoryManager::clear() void HistoryManager::loadSettings() { // load settings - QSettings settings; - settings.beginGroup(QLatin1String("history")); - m_historyLimit = settings.value(QLatin1String("historyLimit"), 30).toInt(); + KConfig config("rekonqrc"); + KConfigGroup group = config.group("history"); + m_historyLimit = group.readEntry( QString("historyLimit"), 30 ); } @@ -242,7 +233,8 @@ void HistoryManager::load() + QLatin1String("/history")); if (!historyFile.exists()) return; - if (!historyFile.open(QFile::ReadOnly)) { + if (!historyFile.open(QFile::ReadOnly)) + { qWarning() << "Unable to open history file" << historyFile.fileName(); return; } @@ -256,7 +248,8 @@ void HistoryManager::load() QDataStream stream; QBuffer buffer; stream.setDevice(&buffer); - while (!historyFile.atEnd()) { + while ( !historyFile.atEnd() ) + { in >> data; buffer.close(); buffer.setBuffer(&data); @@ -273,25 +266,27 @@ void HistoryManager::load() if (!item.dateTime.isValid()) continue; - if (item == lastInsertedItem) { + if ( item == lastInsertedItem ) + { if (lastInsertedItem.title.isEmpty() && !list.isEmpty()) list[0].title = item.title; continue; } - if (!needToSort && !list.isEmpty() && lastInsertedItem < item) + if ( !needToSort && !list.isEmpty() && lastInsertedItem < item ) needToSort = true; list.prepend(item); lastInsertedItem = item; } if (needToSort) - qSort(list.begin(), list.end()); + qSort( list.begin(), list.end() ); setHistory(list, true); // If we had to sort re-write the whole history sorted - if (needToSort) { + if (needToSort) + { m_lastSavedUrl = QString(); m_saveTimer->changeOccurred(); } @@ -300,16 +295,19 @@ void HistoryManager::load() void HistoryManager::save() { - QSettings settings; - settings.beginGroup(QLatin1String("history")); - settings.setValue(QLatin1String("historyLimit"), m_historyLimit); + KConfig config("rekonqrc"); + KConfigGroup group = config.group("history"); + group.writeEntry( QString("historyLimit"), m_historyLimit ); bool saveAll = m_lastSavedUrl.isEmpty(); int first = m_history.count() - 1; - if (!saveAll) { + if (!saveAll) + { // find the first one to save - for (int i = 0; i < m_history.count(); ++i) { - if (m_history.at(i).url == m_lastSavedUrl) { + for (int i = 0; i < m_history.count(); ++i) + { + if (m_history.at(i).url == m_lastSavedUrl) + { first = i - 1; break; } @@ -331,20 +329,25 @@ void HistoryManager::save() QTemporaryFile tempFile; tempFile.setAutoRemove(false); bool open = false; - if (saveAll) { + if (saveAll) + { open = tempFile.open(); - } else { + } + else + { open = historyFile.open(QFile::Append); } - if (!open) { + if (!open) + { qWarning() << "Unable to open history file for saving" << (saveAll ? tempFile.fileName() : historyFile.fileName()); return; } QDataStream out(saveAll ? &tempFile : &historyFile); - for (int i = first; i >= 0; --i) { + for (int i = first; i >= 0; --i) + { QByteArray data; QDataStream stream(&data, QIODevice::WriteOnly); HistoryItem item = m_history.at(i); @@ -353,7 +356,8 @@ void HistoryManager::save() } tempFile.close(); - if (saveAll) { + if (saveAll) + { if (historyFile.exists() && !historyFile.remove()) qWarning() << "History: error removing old history." << historyFile.errorString(); if (!tempFile.rename(historyFile.fileName())) @@ -363,9 +367,9 @@ void HistoryManager::save() } - // ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ + HistoryModel::HistoryModel(HistoryManager *history, QObject *parent) : QAbstractTableModel(parent) , m_history(history) @@ -401,8 +405,10 @@ void HistoryModel::entryUpdated(int offset) QVariant HistoryModel::headerData(int section, Qt::Orientation orientation, int role) const { if (orientation == Qt::Horizontal - && role == Qt::DisplayRole) { - switch (section) { + && role == Qt::DisplayRole) + { + switch (section) + { case 0: return i18n("Title"); case 1: return i18n("Address"); } @@ -418,7 +424,8 @@ QVariant HistoryModel::data(const QModelIndex &index, int role) const return QVariant(); const HistoryItem &item = lst.at(index.row()); - switch (role) { + switch (role) + { case DateTimeRole: return item.dateTime; case DateRole: -- cgit v1.2.1 From 19e901a0ca9630b2003dd24ccfa6da54eb70bb09 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Sun, 14 Dec 2008 18:27:17 +0100 Subject: adjusted rekonq name commented out (hopefully, for now) resizeEvents and focusInEvents in urlbar & searchbar --- src/history.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/history.cpp') diff --git a/src/history.cpp b/src/history.cpp index 930e73ae..5466963b 100644 --- a/src/history.cpp +++ b/src/history.cpp @@ -1,6 +1,6 @@ /* ============================================================  * - * This file is a part of the reKonq project + * This file is a part of the rekonq project  * * Copyright (C) 2007-2008 Trolltech ASA. All rights reserved * Copyright (C) 2008 by Andrea Diamantini -- cgit v1.2.1 From 3fcb4e226ebe126f6c3a289d34f1b6a83c1444c1 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Wed, 17 Dec 2008 02:03:21 +0100 Subject: qDebug && qWarning --> kDebug && kWarning --- src/history.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/history.cpp') diff --git a/src/history.cpp b/src/history.cpp index 5466963b..36a710b1 100644 --- a/src/history.cpp +++ b/src/history.cpp @@ -24,16 +24,16 @@ #include "autosaver.h" #include "browserapplication.h" +// KDE Includes +#include +#include + // Qt Includes #include #include #include #include -#include - -// KDE Includes -#include static const unsigned int HISTORY_VERSION = 23; @@ -235,7 +235,7 @@ void HistoryManager::load() return; if (!historyFile.open(QFile::ReadOnly)) { - qWarning() << "Unable to open history file" << historyFile.fileName(); + kWarning() << "Unable to open history file" << historyFile.fileName(); return; } @@ -340,7 +340,7 @@ void HistoryManager::save() if (!open) { - qWarning() << "Unable to open history file for saving" + kWarning() << "Unable to open history file for saving" << (saveAll ? tempFile.fileName() : historyFile.fileName()); return; } @@ -359,9 +359,9 @@ void HistoryManager::save() if (saveAll) { if (historyFile.exists() && !historyFile.remove()) - qWarning() << "History: error removing old history." << historyFile.errorString(); + kWarning() << "History: error removing old history." << historyFile.errorString(); if (!tempFile.rename(historyFile.fileName())) - qWarning() << "History: error moving new history over old." << tempFile.errorString() << historyFile.fileName(); + kWarning() << "History: error moving new history over old." << tempFile.errorString() << historyFile.fileName(); } m_lastSavedUrl = m_history.value(0).url; } -- cgit v1.2.1 From 9e7f74269e25062a33af0a2603bf258cd4b228e2 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Mon, 29 Dec 2008 01:52:07 +0100 Subject: Ported from KMainWindow to KXmlGuiWindow. Yeah! .. --- src/history.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/history.cpp') diff --git a/src/history.cpp b/src/history.cpp index 36a710b1..12a9d57f 100644 --- a/src/history.cpp +++ b/src/history.cpp @@ -668,7 +668,7 @@ void HistoryMenu::showHistoryDialog() } -void HistoryMenu::setInitialActions(QList actions) +void HistoryMenu::setInitialActions(QList actions) { m_initialActions = actions; for (int i = 0; i < m_initialActions.count(); ++i) -- cgit v1.2.1 From 694cbe620e7272deba4e051933df13f8250dd34b Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Fri, 16 Jan 2009 11:46:45 +0100 Subject: Some moc adds and webview fixing.. --- src/history.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/history.cpp') diff --git a/src/history.cpp b/src/history.cpp index 12a9d57f..dedabfdd 100644 --- a/src/history.cpp +++ b/src/history.cpp @@ -18,9 +18,11 @@  *  * ============================================================ */ -// Local Includes +// Self Includes #include "history.h" +#include "history.moc" +// Local Includes #include "autosaver.h" #include "browserapplication.h" -- cgit v1.2.1 From 76d30285358bedd8b2fc6caf48d2a871f7546685 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Mon, 19 Jan 2009 02:26:13 +0100 Subject: Ported tons of code to KConfigXT. To merge kcfg branch we need just to port cookie settings.. --- src/history.cpp | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'src/history.cpp') diff --git a/src/history.cpp b/src/history.cpp index dedabfdd..652ee962 100644 --- a/src/history.cpp +++ b/src/history.cpp @@ -22,12 +22,14 @@ #include "history.h" #include "history.moc" +// Auto Includes +#include "rekonq.h" + // Local Includes #include "autosaver.h" #include "browserapplication.h" // KDE Includes -#include #include // Qt Includes @@ -219,10 +221,19 @@ void HistoryManager::clear() void HistoryManager::loadSettings() { - // load settings - KConfig config("rekonqrc"); - KConfigGroup group = config.group("history"); - m_historyLimit = group.readEntry( QString("historyLimit"), 30 ); + int historyExpire = ReKonfig::expireHistory(); + int days; + switch (historyExpire) + { + case 0: days = 1; break; + case 1: days = 7; break; + case 2: days = 14; break; + case 3: days = 30; break; + case 4: days = 365; break; + case 5: days = -1; break; + default: days = -1; + } + m_historyLimit = days; } @@ -297,9 +308,9 @@ void HistoryManager::load() void HistoryManager::save() { - KConfig config("rekonqrc"); - KConfigGroup group = config.group("history"); - group.writeEntry( QString("historyLimit"), m_historyLimit ); +// KConfig config("rekonqrc"); +// KConfigGroup group = config.group("history"); +// group.writeEntry( QString("historyLimit"), m_historyLimit ); bool saveAll = m_lastSavedUrl.isEmpty(); int first = m_history.count() - 1; @@ -369,7 +380,7 @@ void HistoryManager::save() } -// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ +// -------------------------------------------------------------------------------------------------------------------------- HistoryModel::HistoryModel(HistoryManager *history, QObject *parent) -- cgit v1.2.1 From f7792e37654fb9d0509171d946d53e7697ad53e8 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Sun, 15 Feb 2009 15:35:47 +0100 Subject: BrowserApplication --> Application --- src/history.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/history.cpp') diff --git a/src/history.cpp b/src/history.cpp index 652ee962..9813d438 100644 --- a/src/history.cpp +++ b/src/history.cpp @@ -27,7 +27,7 @@ // Local Includes #include "autosaver.h" -#include "browserapplication.h" +#include "application.h" // KDE Includes #include @@ -465,7 +465,7 @@ QVariant HistoryModel::data(const QModelIndex &index, int role) const } case Qt::DecorationRole: if (index.column() == 0) { - return BrowserApplication::instance()->icon(item.url); + return Application::instance()->icon(item.url); } } return QVariant(); @@ -643,7 +643,7 @@ bool HistoryMenu::prePopulated() { if (!m_history) { - m_history = BrowserApplication::historyManager(); + m_history = Application::historyManager(); m_historyMenuModel = new HistoryMenuModel(m_history->historyTreeModel(), this); setModel(m_historyMenuModel); } @@ -712,7 +712,7 @@ HistoryDialog::HistoryDialog(QWidget *parent, HistoryManager *setHistory) : QDia { HistoryManager *history = setHistory; if (!history) - history = BrowserApplication::historyManager(); + history = Application::historyManager(); setupUi(this); tree->setUniformRowHeights(true); tree->setSelectionBehavior(QAbstractItemView::SelectRows); -- cgit v1.2.1 From 6eb9b36039f9c3a814207950ad35322ea1a8d3f0 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Fri, 20 Mar 2009 00:50:21 +0100 Subject: QDesktopServices removed! Now rekonq lives just in kde directories!! --- src/history.cpp | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) (limited to 'src/history.cpp') diff --git a/src/history.cpp b/src/history.cpp index 9813d438..424c9aad 100644 --- a/src/history.cpp +++ b/src/history.cpp @@ -237,13 +237,12 @@ void HistoryManager::loadSettings() } - void HistoryManager::load() { loadSettings(); - QFile historyFile(QDesktopServices::storageLocation(QDesktopServices::DataLocation) - + QLatin1String("/history")); + QString historyFilePath = KStandardDirs::locateLocal("appdata" , "history"); + QFile historyFile( historyFilePath ); if (!historyFile.exists()) return; if (!historyFile.open(QFile::ReadOnly)) @@ -329,15 +328,9 @@ void HistoryManager::save() if (first == m_history.count() - 1) saveAll = true; - QString directory = QDesktopServices::storageLocation(QDesktopServices::DataLocation); - if (directory.isEmpty()) - directory = QDir::homePath() + QLatin1String("/.") + QCoreApplication::applicationName(); - if (!QFile::exists(directory)) { - QDir dir; - dir.mkpath(directory); - } + QString historyFilePath = KStandardDirs::locateLocal("appdata" , "history"); + QFile historyFile( historyFilePath ); - QFile historyFile(directory + QLatin1String("/history")); // When saving everything use a temporary file to prevent possible data loss. QTemporaryFile tempFile; tempFile.setAutoRemove(false); -- cgit v1.2.1 From 9decbb06f53832362e80d18f86422c79f6fd3698 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Fri, 20 Mar 2009 00:53:02 +0100 Subject: Forgot header.. ;) --- src/history.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/history.cpp') diff --git a/src/history.cpp b/src/history.cpp index 424c9aad..2ce0422b 100644 --- a/src/history.cpp +++ b/src/history.cpp @@ -31,6 +31,7 @@ // KDE Includes #include +#include // Qt Includes #include -- cgit v1.2.1 From 39409ac6a2880ad815d6096231d0fcdcfd2547f6 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Sun, 22 Mar 2009 10:21:09 +0100 Subject: Fixed Copyright intro --- src/history.cpp | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) (limited to 'src/history.cpp') diff --git a/src/history.cpp b/src/history.cpp index 2ce0422b..87910308 100644 --- a/src/history.cpp +++ b/src/history.cpp @@ -1,22 +1,23 @@ /* ============================================================ - * - * This file is a part of the rekonq project - * - * Copyright (C) 2007-2008 Trolltech ASA. All rights reserved - * Copyright (C) 2008 by Andrea Diamantini - * - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General - * Public License as published by the Free Software Foundation; - * either version 2, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the - * GNU General Public License for more details. - * - * ============================================================ */ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2007-2008 Trolltech ASA. All rights reserved +* Copyright (C) 2008 by Andrea Diamantini +* +* +* This program is free software; you can redistribute it +* and/or modify it under the terms of the GNU General +* Public License as published by the Free Software Foundation; +* either version 2, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* ============================================================ */ + // Self Includes #include "history.h" -- cgit v1.2.1 From 48b25611c94d380b40948a3de0bfab5678668e1d Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Wed, 25 Mar 2009 00:47:24 +0100 Subject: Huge update. Fixed quite all of the settings troubles.. From now on, we (mainly) go on WebView bugfixing.. --- src/history.cpp | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src/history.cpp') diff --git a/src/history.cpp b/src/history.cpp index 87910308..5023bfd3 100644 --- a/src/history.cpp +++ b/src/history.cpp @@ -309,10 +309,6 @@ void HistoryManager::load() void HistoryManager::save() { -// KConfig config("rekonqrc"); -// KConfigGroup group = config.group("history"); -// group.writeEntry( QString("historyLimit"), m_historyLimit ); - bool saveAll = m_lastSavedUrl.isEmpty(); int first = m_history.count() - 1; if (!saveAll) -- cgit v1.2.1 From 473540ed565ce6c2f5767e29b956aad0dadf458d Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Sat, 28 Mar 2009 15:46:46 +0100 Subject: Added QNetworkDiskCache. Thanks to Ben Meyer's Qt Blog post --- src/history.cpp | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) (limited to 'src/history.cpp') diff --git a/src/history.cpp b/src/history.cpp index 5023bfd3..5c545b10 100644 --- a/src/history.cpp +++ b/src/history.cpp @@ -177,7 +177,6 @@ void HistoryManager::addHistoryItem(const HistoryItem &item) } - void HistoryManager::updateHistoryItem(const KUrl &url, const QString &title) { for (int i = 0; i < m_history.count(); ++i) @@ -493,9 +492,11 @@ bool HistoryModel::removeRows(int row, int count, const QModelIndex &parent) -// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ +// ----------------------------------------------------------------------------------------------- + + +#define MOVEDROWS 10 -#define MOVEDROWS 15 /* Maps the first bunch of items of the source model to the root @@ -507,6 +508,7 @@ HistoryMenuModel::HistoryMenuModel(HistoryTreeModel *sourceModel, QObject *paren setSourceModel(sourceModel); } + int HistoryMenuModel::bumpedRows() const { QModelIndex first = m_treeModel->index(0, 0); @@ -515,11 +517,13 @@ int HistoryMenuModel::bumpedRows() const return qMin(m_treeModel->rowCount(first), MOVEDROWS); } + int HistoryMenuModel::columnCount(const QModelIndex &parent) const { return m_treeModel->columnCount(mapToSource(parent)); } + int HistoryMenuModel::rowCount(const QModelIndex &parent) const { if (parent.column() > 0) @@ -546,6 +550,7 @@ int HistoryMenuModel::rowCount(const QModelIndex &parent) const return defaultCount; } + QModelIndex HistoryMenuModel::mapFromSource(const QModelIndex &sourceIndex) const { // currently not used or autotested @@ -554,6 +559,7 @@ QModelIndex HistoryMenuModel::mapFromSource(const QModelIndex &sourceIndex) cons return createIndex(sourceIndex.row(), sourceIndex.column(), sr); } + QModelIndex HistoryMenuModel::mapToSource(const QModelIndex &proxyIndex) const { if (!proxyIndex.isValid()) @@ -573,6 +579,7 @@ QModelIndex HistoryMenuModel::mapToSource(const QModelIndex &proxyIndex) const return treeIndex; } + QModelIndex HistoryMenuModel::index(int row, int column, const QModelIndex &parent) const { if (row < 0 @@ -595,6 +602,7 @@ QModelIndex HistoryMenuModel::index(int row, int column, const QModelIndex &pare return createIndex(row, column, historyRow); } + QModelIndex HistoryMenuModel::parent(const QModelIndex &index) const { int offset = index.internalId(); @@ -613,7 +621,8 @@ QModelIndex HistoryMenuModel::parent(const QModelIndex &index) const } -// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ +// ------------------------------------------------------------------------------------------------------------- + HistoryMenu::HistoryMenu(QWidget *parent) : ModelMenu(parent) @@ -680,7 +689,8 @@ void HistoryMenu::setInitialActions(QList actions) } -// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ +// -------------------------------------------------------------------------------------------------------------- + TreeProxyModel::TreeProxyModel(QObject *parent) : QSortFilterProxyModel(parent) { @@ -697,7 +707,8 @@ bool TreeProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_ } -// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ +// ----------------------------------------------------------------------------------------------------- + HistoryDialog::HistoryDialog(QWidget *parent, HistoryManager *setHistory) : QDialog(parent) { @@ -766,7 +777,7 @@ void HistoryDialog::copy() } -// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ +// --------------------------------------------------------------------------------------------------------------- HistoryFilterModel::HistoryFilterModel(QAbstractItemModel *sourceModel, QObject *parent) : QAbstractProxyModel(parent), @@ -954,8 +965,6 @@ void HistoryFilterModel::sourceRowsRemoved(const QModelIndex &, int start, int e } - -// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ /* Removing a continuous block of rows will remove filtered rows too as this is the users intention. @@ -982,6 +991,9 @@ bool HistoryFilterModel::removeRows(int row, int count, const QModelIndex &paren } +// ------------------------------------------------------------------------------------------------------ + + HistoryCompletionModel::HistoryCompletionModel(QObject *parent) : QAbstractProxyModel(parent) { @@ -1082,8 +1094,8 @@ void HistoryCompletionModel::sourceReset() } +// ------------------------------------------------------------------------------------------------------ -// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ HistoryTreeModel::HistoryTreeModel(QAbstractItemModel *sourceModel, QObject *parent) : QAbstractProxyModel(parent) -- cgit v1.2.1 From a934072cf9695e46e793898102590322f43c0733 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Sat, 28 Mar 2009 15:53:26 +0100 Subject: astyle. First round.. --- src/history.cpp | 310 ++++++++++++++++++++++++++++++++------------------------ 1 file changed, 180 insertions(+), 130 deletions(-) (limited to 'src/history.cpp') diff --git a/src/history.cpp b/src/history.cpp index 5c545b10..96efd3e5 100644 --- a/src/history.cpp +++ b/src/history.cpp @@ -46,12 +46,12 @@ static const unsigned int HISTORY_VERSION = 23; HistoryManager::HistoryManager(QObject *parent) - : QWebHistoryInterface(parent) - , m_saveTimer(new AutoSaver(this)) - , m_historyLimit(30) - , m_historyModel(0) - , m_historyFilterModel(0) - , m_historyTreeModel(0) + : QWebHistoryInterface(parent) + , m_saveTimer(new AutoSaver(this)) + , m_historyLimit(30) + , m_historyModel(0) + , m_historyFilterModel(0) + , m_historyTreeModel(0) { m_expiredTimer.setSingleShot(true); connect(&m_expiredTimer, SIGNAL(timeout()), this, SLOT(checkForExpired())); @@ -106,9 +106,12 @@ void HistoryManager::setHistory(const QList &history, bool loadedAn checkForExpired(); - if (loadedAndSorted) { + if (loadedAndSorted) + { m_lastSavedUrl = m_history.value(0).url; - } else { + } + else + { m_lastSavedUrl = QString(); m_saveTimer->changeOccurred(); } @@ -142,13 +145,17 @@ void HistoryManager::checkForExpired() QDateTime now = QDateTime::currentDateTime(); int nextTimeout = 0; - while (!m_history.isEmpty()) { + while (!m_history.isEmpty()) + { QDateTime checkForExpired = m_history.last().dateTime; checkForExpired.setDate(checkForExpired.date().addDays(m_historyLimit)); - if (now.daysTo(checkForExpired) > 7) { + if (now.daysTo(checkForExpired) > 7) + { // check at most in a week to prevent int overflows on the timer nextTimeout = 7 * 86400; - } else { + } + else + { nextTimeout = now.secsTo(checkForExpired); } if (nextTimeout > 0) @@ -179,9 +186,9 @@ void HistoryManager::addHistoryItem(const HistoryItem &item) void HistoryManager::updateHistoryItem(const KUrl &url, const QString &title) { - for (int i = 0; i < m_history.count(); ++i) + for (int i = 0; i < m_history.count(); ++i) { - if (url == m_history.at(i).url) + if (url == m_history.at(i).url) { m_history[i].title = title; m_saveTimer->changeOccurred(); @@ -223,16 +230,16 @@ void HistoryManager::clear() void HistoryManager::loadSettings() { int historyExpire = ReKonfig::expireHistory(); - int days; - switch (historyExpire) + int days; + switch (historyExpire) { - case 0: days = 1; break; - case 1: days = 7; break; - case 2: days = 14; break; - case 3: days = 30; break; - case 4: days = 365; break; - case 5: days = -1; break; - default: days = -1; + case 0: days = 1; break; + case 1: days = 7; break; + case 2: days = 14; break; + case 3: days = 30; break; + case 4: days = 365; break; + case 5: days = -1; break; + default: days = -1; } m_historyLimit = days; } @@ -243,10 +250,10 @@ void HistoryManager::load() loadSettings(); QString historyFilePath = KStandardDirs::locateLocal("appdata" , "history"); - QFile historyFile( historyFilePath ); + QFile historyFile(historyFilePath); if (!historyFile.exists()) return; - if (!historyFile.open(QFile::ReadOnly)) + if (!historyFile.open(QFile::ReadOnly)) { kWarning() << "Unable to open history file" << historyFile.fileName(); return; @@ -261,7 +268,7 @@ void HistoryManager::load() QDataStream stream; QBuffer buffer; stream.setDevice(&buffer); - while ( !historyFile.atEnd() ) + while (!historyFile.atEnd()) { in >> data; buffer.close(); @@ -279,26 +286,26 @@ void HistoryManager::load() if (!item.dateTime.isValid()) continue; - if ( item == lastInsertedItem ) + if (item == lastInsertedItem) { if (lastInsertedItem.title.isEmpty() && !list.isEmpty()) list[0].title = item.title; continue; } - if ( !needToSort && !list.isEmpty() && lastInsertedItem < item ) + if (!needToSort && !list.isEmpty() && lastInsertedItem < item) needToSort = true; list.prepend(item); lastInsertedItem = item; } if (needToSort) - qSort( list.begin(), list.end() ); + qSort(list.begin(), list.end()); setHistory(list, true); // If we had to sort re-write the whole history sorted - if (needToSort) + if (needToSort) { m_lastSavedUrl = QString(); m_saveTimer->changeOccurred(); @@ -310,12 +317,12 @@ void HistoryManager::save() { bool saveAll = m_lastSavedUrl.isEmpty(); int first = m_history.count() - 1; - if (!saveAll) + if (!saveAll) { // find the first one to save - for (int i = 0; i < m_history.count(); ++i) + for (int i = 0; i < m_history.count(); ++i) { - if (m_history.at(i).url == m_lastSavedUrl) + if (m_history.at(i).url == m_lastSavedUrl) { first = i - 1; break; @@ -326,30 +333,30 @@ void HistoryManager::save() saveAll = true; QString historyFilePath = KStandardDirs::locateLocal("appdata" , "history"); - QFile historyFile( historyFilePath ); + QFile historyFile(historyFilePath); // When saving everything use a temporary file to prevent possible data loss. QTemporaryFile tempFile; tempFile.setAutoRemove(false); bool open = false; - if (saveAll) + if (saveAll) { open = tempFile.open(); } - else + else { open = historyFile.open(QFile::Append); } - if (!open) + if (!open) { kWarning() << "Unable to open history file for saving" - << (saveAll ? tempFile.fileName() : historyFile.fileName()); + << (saveAll ? tempFile.fileName() : historyFile.fileName()); return; } QDataStream out(saveAll ? &tempFile : &historyFile); - for (int i = first; i >= 0; --i) + for (int i = first; i >= 0; --i) { QByteArray data; QDataStream stream(&data, QIODevice::WriteOnly); @@ -359,7 +366,7 @@ void HistoryManager::save() } tempFile.close(); - if (saveAll) + if (saveAll) { if (historyFile.exists() && !historyFile.remove()) kWarning() << "History: error removing old history." << historyFile.errorString(); @@ -374,8 +381,8 @@ void HistoryManager::save() HistoryModel::HistoryModel(HistoryManager *history, QObject *parent) - : QAbstractTableModel(parent) - , m_history(history) + : QAbstractTableModel(parent) + , m_history(history) { Q_ASSERT(m_history); connect(m_history, SIGNAL(historyReset()), this, SLOT(historyReset())); @@ -408,12 +415,12 @@ void HistoryModel::entryUpdated(int offset) QVariant HistoryModel::headerData(int section, Qt::Orientation orientation, int role) const { if (orientation == Qt::Horizontal - && role == Qt::DisplayRole) + && role == Qt::DisplayRole) { - switch (section) + switch (section) { - case 0: return i18n("Title"); - case 1: return i18n("Address"); + case 0: return i18n("Title"); + case 1: return i18n("Address"); } } return QAbstractTableModel::headerData(section, orientation, role); @@ -427,7 +434,7 @@ QVariant HistoryModel::data(const QModelIndex &index, int role) const return QVariant(); const HistoryItem &item = lst.at(index.row()); - switch (role) + switch (role) { case DateTimeRole: return item.dateTime; @@ -438,23 +445,27 @@ QVariant HistoryModel::data(const QModelIndex &index, int role) const case UrlStringRole: return item.url; case Qt::DisplayRole: - case Qt::EditRole: { - switch (index.column()) { - case 0: - // when there is no title try to generate one from the url - if (item.title.isEmpty()) { - QString page = QFileInfo(QUrl(item.url).path()).fileName(); - if (!page.isEmpty()) - return page; - return item.url; - } - return item.title; - case 1: + case Qt::EditRole: + { + switch (index.column()) + { + case 0: + // when there is no title try to generate one from the url + if (item.title.isEmpty()) + { + QString page = QFileInfo(QUrl(item.url).path()).fileName(); + if (!page.isEmpty()) + return page; return item.url; + } + return item.title; + case 1: + return item.url; } - } + } case Qt::DecorationRole: - if (index.column() == 0) { + if (index.column() == 0) + { return Application::instance()->icon(item.url); } } @@ -502,8 +513,8 @@ bool HistoryModel::removeRows(int row, int count, const QModelIndex &parent) Maps the first bunch of items of the source model to the root */ HistoryMenuModel::HistoryMenuModel(HistoryTreeModel *sourceModel, QObject *parent) - : QAbstractProxyModel(parent) - , m_treeModel(sourceModel) + : QAbstractProxyModel(parent) + , m_treeModel(sourceModel) { setSourceModel(sourceModel); } @@ -529,16 +540,18 @@ int HistoryMenuModel::rowCount(const QModelIndex &parent) const if (parent.column() > 0) return 0; - if (!parent.isValid()) { + if (!parent.isValid()) + { int folders = sourceModel()->rowCount(); int bumpedItems = bumpedRows(); if (bumpedItems <= MOVEDROWS - && bumpedItems == sourceModel()->rowCount(sourceModel()->index(0, 0))) + && bumpedItems == sourceModel()->rowCount(sourceModel()->index(0, 0))) --folders; return bumpedItems + folders; } - if (parent.internalId() == -1) { + if (parent.internalId() == -1) + { if (parent.row() < bumpedRows()) return 0; } @@ -565,7 +578,8 @@ QModelIndex HistoryMenuModel::mapToSource(const QModelIndex &proxyIndex) const if (!proxyIndex.isValid()) return QModelIndex(); - if (proxyIndex.internalId() == -1) { + if (proxyIndex.internalId() == -1) + { int bumpedItems = bumpedRows(); if (proxyIndex.row() < bumpedItems) return m_treeModel->index(proxyIndex.row(), proxyIndex.column(), m_treeModel->index(0, 0)); @@ -583,8 +597,8 @@ QModelIndex HistoryMenuModel::mapToSource(const QModelIndex &proxyIndex) const QModelIndex HistoryMenuModel::index(int row, int column, const QModelIndex &parent) const { if (row < 0 - || column < 0 || column >= columnCount(parent) - || parent.column() > 0) + || column < 0 || column >= columnCount(parent) + || parent.column() > 0) return QModelIndex(); if (!parent.isValid()) return createIndex(row, column, -1); @@ -625,8 +639,8 @@ QModelIndex HistoryMenuModel::parent(const QModelIndex &index) const HistoryMenu::HistoryMenu(QWidget *parent) - : ModelMenu(parent) - , m_history(0) + : ModelMenu(parent) + , m_history(0) { connect(this, SIGNAL(activated(const QModelIndex &)), this, SLOT(activated(const QModelIndex &))); setHoverRole(HistoryModel::UrlStringRole); @@ -641,7 +655,7 @@ void HistoryMenu::activated(const QModelIndex &index) bool HistoryMenu::prePopulated() { - if (!m_history) + if (!m_history) { m_history = Application::historyManager(); m_historyMenuModel = new HistoryMenuModel(m_history->historyTreeModel(), this); @@ -663,11 +677,11 @@ void HistoryMenu::postPopulated() if (m_history->history().count() > 0) addSeparator(); - KAction *showAllAction = new KAction( i18n("Show All History"), this); + KAction *showAllAction = new KAction(i18n("Show All History"), this); connect(showAllAction, SIGNAL(triggered()), this, SLOT(showHistoryDialog())); addAction(showAllAction); - KAction *clearAction = new KAction( i18n("Clear History"), this); + KAction *clearAction = new KAction(i18n("Clear History"), this); connect(clearAction, SIGNAL(triggered()), m_history, SLOT(clear())); addAction(clearAction); } @@ -746,12 +760,13 @@ void HistoryDialog::customContextMenuRequested(const QPoint &pos) QMenu menu; QModelIndex index = tree->indexAt(pos); index = index.sibling(index.row(), 0); - if (index.isValid() && !tree->model()->hasChildren(index)) { - menu.addAction( i18n("Open"), this, SLOT(open())); + if (index.isValid() && !tree->model()->hasChildren(index)) + { + menu.addAction(i18n("Open"), this, SLOT(open())); menu.addSeparator(); - menu.addAction( i18n("Copy"), this, SLOT(copy())); + menu.addAction(i18n("Copy"), this, SLOT(copy())); } - menu.addAction( i18n("Delete"), tree, SLOT(removeOne())); + menu.addAction(i18n("Delete"), tree, SLOT(removeOne())); menu.exec(QCursor::pos()); } @@ -780,8 +795,8 @@ void HistoryDialog::copy() // --------------------------------------------------------------------------------------------------------------- HistoryFilterModel::HistoryFilterModel(QAbstractItemModel *sourceModel, QObject *parent) - : QAbstractProxyModel(parent), - m_loaded(false) + : QAbstractProxyModel(parent), + m_loaded(false) { setSourceModel(sourceModel); } @@ -804,23 +819,25 @@ QVariant HistoryFilterModel::data(const QModelIndex &index, int role) const void HistoryFilterModel::setSourceModel(QAbstractItemModel *newSourceModel) { - if (sourceModel()) { + if (sourceModel()) + { disconnect(sourceModel(), SIGNAL(modelReset()), this, SLOT(sourceReset())); disconnect(sourceModel(), SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), this, SLOT(dataChanged(const QModelIndex &, const QModelIndex &))); disconnect(sourceModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)), - this, SLOT(sourceRowsInserted(const QModelIndex &, int, int))); + this, SLOT(sourceRowsInserted(const QModelIndex &, int, int))); disconnect(sourceModel(), SIGNAL(rowsRemoved(const QModelIndex &, int, int)), - this, SLOT(sourceRowsRemoved(const QModelIndex &, int, int))); + this, SLOT(sourceRowsRemoved(const QModelIndex &, int, int))); } QAbstractProxyModel::setSourceModel(newSourceModel); - if (sourceModel()) { + if (sourceModel()) + { m_loaded = false; connect(sourceModel(), SIGNAL(modelReset()), this, SLOT(sourceReset())); connect(sourceModel(), SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), - this, SLOT(sourceDataChanged(const QModelIndex &, const QModelIndex &))); + this, SLOT(sourceDataChanged(const QModelIndex &, const QModelIndex &))); connect(sourceModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)), this, SLOT(sourceRowsInserted(const QModelIndex &, int, int))); connect(sourceModel(), SIGNAL(rowsRemoved(const QModelIndex &, int, int)), @@ -885,8 +902,10 @@ QModelIndex HistoryFilterModel::mapFromSource(const QModelIndex &sourceIndex) co int realRow = -1; int sourceModelRow = sourceModel()->rowCount() - sourceIndex.row(); - for (int i = 0; i < m_sourceRow.count(); ++i) { - if (m_sourceRow.at(i) == sourceModelRow) { + for (int i = 0; i < m_sourceRow.count(); ++i) + { + if (m_sourceRow.at(i) == sourceModelRow) + { realRow = i; break; } @@ -902,7 +921,7 @@ QModelIndex HistoryFilterModel::index(int row, int column, const QModelIndex &pa { load(); if (row < 0 || row >= rowCount(parent) - || column < 0 || column >= columnCount(parent)) + || column < 0 || column >= columnCount(parent)) return QModelIndex(); return createIndex(row, column, m_sourceRow[row]); @@ -922,10 +941,12 @@ void HistoryFilterModel::load() const m_sourceRow.clear(); m_historyHash.clear(); m_historyHash.reserve(sourceModel()->rowCount()); - for (int i = 0; i < sourceModel()->rowCount(); ++i) { + for (int i = 0; i < sourceModel()->rowCount(); ++i) + { QModelIndex idx = sourceModel()->index(i, 0); QString url = idx.data(HistoryModel::UrlStringRole).toString(); - if (!m_historyHash.contains(url)) { + if (!m_historyHash.contains(url)) + { m_sourceRow.append(sourceModel()->rowCount() - i); m_historyHash[url] = sourceModel()->rowCount() - i; } @@ -942,7 +963,8 @@ void HistoryFilterModel::sourceRowsInserted(const QModelIndex &parent, int start return; QModelIndex idx = sourceModel()->index(start, 0, parent); QString url = idx.data(HistoryModel::UrlStringRole).toString(); - if (m_historyHash.contains(url)) { + if (m_historyHash.contains(url)) + { int sourceRow = sourceModel()->rowCount() - m_historyHash[url]; int realRow = mapFromSource(sourceModel()->index(sourceRow, 0)).row(); beginRemoveRows(QModelIndex(), realRow, realRow); @@ -975,7 +997,7 @@ bool HistoryFilterModel::removeRows(int row, int count, const QModelIndex &paren return false; int lastRow = row + count - 1; disconnect(sourceModel(), SIGNAL(rowsRemoved(const QModelIndex &, int, int)), - this, SLOT(sourceRowsRemoved(const QModelIndex &, int, int))); + this, SLOT(sourceRowsRemoved(const QModelIndex &, int, int))); beginRemoveRows(parent, row, lastRow); int oldCount = rowCount(); int start = sourceModel()->rowCount() - m_sourceRow.value(row); @@ -983,7 +1005,7 @@ bool HistoryFilterModel::removeRows(int row, int count, const QModelIndex &paren sourceModel()->removeRows(start, end - start + 1); endRemoveRows(); connect(sourceModel(), SIGNAL(rowsRemoved(const QModelIndex &, int, int)), - this, SLOT(sourceRowsRemoved(const QModelIndex &, int, int))); + this, SLOT(sourceRowsRemoved(const QModelIndex &, int, int))); m_loaded = false; if (oldCount - count != rowCount()) reset(); @@ -995,7 +1017,7 @@ bool HistoryFilterModel::removeRows(int row, int count, const QModelIndex &paren HistoryCompletionModel::HistoryCompletionModel(QObject *parent) - : QAbstractProxyModel(parent) + : QAbstractProxyModel(parent) { } @@ -1003,12 +1025,14 @@ HistoryCompletionModel::HistoryCompletionModel(QObject *parent) QVariant HistoryCompletionModel::data(const QModelIndex &index, int role) const { if (sourceModel() - && (role == Qt::EditRole || role == Qt::DisplayRole) - && index.isValid()) { + && (role == Qt::EditRole || role == Qt::DisplayRole) + && index.isValid()) + { QModelIndex idx = mapToSource(index); idx = idx.sibling(idx.row(), 1); QString urlString = idx.data(HistoryModel::UrlStringRole).toString(); - if (index.row() % 2) { + if (index.row() % 2) + { QUrl url = urlString; QString s = url.toString(QUrl::RemoveScheme | QUrl::RemoveUserInfo @@ -1052,7 +1076,7 @@ QModelIndex HistoryCompletionModel::mapToSource(const QModelIndex &proxyIndex) c QModelIndex HistoryCompletionModel::index(int row, int column, const QModelIndex &parent) const { if (row < 0 || row >= rowCount(parent) - || column < 0 || column >= columnCount(parent)) + || column < 0 || column >= columnCount(parent)) return QModelIndex(); return createIndex(row, column, 0); } @@ -1066,17 +1090,19 @@ QModelIndex HistoryCompletionModel::parent(const QModelIndex &) const void HistoryCompletionModel::setSourceModel(QAbstractItemModel *newSourceModel) { - if (sourceModel()) { + if (sourceModel()) + { disconnect(sourceModel(), SIGNAL(modelReset()), this, SLOT(sourceReset())); disconnect(sourceModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)), - this, SLOT(sourceReset())); + this, SLOT(sourceReset())); disconnect(sourceModel(), SIGNAL(rowsRemoved(const QModelIndex &, int, int)), - this, SLOT(sourceReset())); + this, SLOT(sourceReset())); } QAbstractProxyModel::setSourceModel(newSourceModel); - if (newSourceModel) { + if (newSourceModel) + { connect(newSourceModel, SIGNAL(modelReset()), this, SLOT(sourceReset())); connect(sourceModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)), this, SLOT(sourceReset())); @@ -1098,7 +1124,7 @@ void HistoryCompletionModel::sourceReset() HistoryTreeModel::HistoryTreeModel(QAbstractItemModel *sourceModel, QObject *parent) - : QAbstractProxyModel(parent) + : QAbstractProxyModel(parent) { setSourceModel(sourceModel); } @@ -1112,25 +1138,30 @@ 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) { + if (start == 0) + { int offset = sourceDateRow(index.row()); - if (index.column() == 0) { + if (index.column() == 0) + { QModelIndex idx = sourceModel()->index(offset, 0); QDate date = idx.data(HistoryModel::DateRole).toDate(); if (date == QDate::currentDate()) return i18n("Earlier Today"); return date.toString(QLatin1String("dddd, MMMM d, yyyy")); } - if (index.column() == 1) { + if (index.column() == 1) + { return QString(rowCount(index.sibling(index.row(), 0))) + i18n(" items") ; } } } 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); @@ -1148,22 +1179,25 @@ int HistoryTreeModel::columnCount(const QModelIndex &parent) const int HistoryTreeModel::rowCount(const QModelIndex &parent) const { - if ( parent.internalId() != 0 - || parent.column() > 0 - || !sourceModel()) + if (parent.internalId() != 0 + || parent.column() > 0 + || !sourceModel()) return 0; // row count OF dates - if (!parent.isValid()) { + if (!parent.isValid()) + { if (!m_sourceRowCache.isEmpty()) return m_sourceRowCache.count(); QDate currentDate; int rows = 0; int totalRows = sourceModel()->rowCount(); - for (int i = 0; i < totalRows; ++i) { + for (int i = 0; i < totalRows; ++i) + { QDate rowDate = sourceModel()->index(i, 0).data(HistoryModel::DateRole).toDate(); - if (rowDate != currentDate) { + if (rowDate != currentDate) + { m_sourceRowCache.append(i); currentDate = rowDate; ++rows; @@ -1189,7 +1223,8 @@ int HistoryTreeModel::sourceDateRow(int row) const if (m_sourceRowCache.isEmpty()) rowCount(QModelIndex()); - if (row >= m_sourceRowCache.count()) { + if (row >= m_sourceRowCache.count()) + { if (!sourceModel()) return 0; return sourceModel()->rowCount(); @@ -1211,8 +1246,8 @@ QModelIndex HistoryTreeModel::mapToSource(const QModelIndex &proxyIndex) const QModelIndex HistoryTreeModel::index(int row, int column, const QModelIndex &parent) const { if (row < 0 - || column < 0 || column >= columnCount(parent) - || parent.column() > 0) + || column < 0 || column >= columnCount(parent) + || parent.column() > 0) return QModelIndex(); if (!parent.isValid()) @@ -1252,13 +1287,17 @@ bool HistoryTreeModel::removeRows(int row, int count, const QModelIndex &parent) if (row < 0 || count <= 0 || row + count > rowCount(parent)) return false; - if (parent.isValid()) { + if (parent.isValid()) + { // removing pages int offset = sourceDateRow(parent.row()); return sourceModel()->removeRows(offset + row, count); - } else { + } + else + { // removing whole dates - for (int i = row + count - 1; i >= row; --i) { + for (int i = row + count - 1; i >= row; --i) + { QModelIndex dateParent = index(i, 0); int offset = sourceDateRow(dateParent.row()); if (!sourceModel()->removeRows(offset, rowCount(dateParent))) @@ -1271,18 +1310,20 @@ bool HistoryTreeModel::removeRows(int row, int count, const QModelIndex &parent) void HistoryTreeModel::setSourceModel(QAbstractItemModel *newSourceModel) { - if (sourceModel()) { + if (sourceModel()) + { disconnect(sourceModel(), SIGNAL(modelReset()), this, SLOT(sourceReset())); disconnect(sourceModel(), SIGNAL(layoutChanged()), this, SLOT(sourceReset())); disconnect(sourceModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)), - this, SLOT(sourceRowsInserted(const QModelIndex &, int, int))); + this, SLOT(sourceRowsInserted(const QModelIndex &, int, int))); disconnect(sourceModel(), SIGNAL(rowsRemoved(const QModelIndex &, int, int)), - this, SLOT(sourceRowsRemoved(const QModelIndex &, int, int))); + this, SLOT(sourceRowsRemoved(const QModelIndex &, int, int))); } QAbstractProxyModel::setSourceModel(newSourceModel); - if (newSourceModel) { + if (newSourceModel) + { connect(sourceModel(), SIGNAL(modelReset()), this, SLOT(sourceReset())); connect(sourceModel(), SIGNAL(layoutChanged()), this, SLOT(sourceReset())); connect(sourceModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)), @@ -1306,7 +1347,8 @@ void HistoryTreeModel::sourceRowsInserted(const QModelIndex &parent, int start, { Q_UNUSED(parent); // Avoid warnings when compiling release Q_ASSERT(!parent.isValid()); - if (start != 0 || start != end) { + if (start != 0 || start != end) + { m_sourceRowCache.clear(); reset(); return; @@ -1315,10 +1357,13 @@ void HistoryTreeModel::sourceRowsInserted(const QModelIndex &parent, int start, m_sourceRowCache.clear(); QModelIndex treeIndex = mapFromSource(sourceModel()->index(start, 0)); QModelIndex treeParent = treeIndex.parent(); - if (rowCount(treeParent) == 1) { + if (rowCount(treeParent) == 1) + { beginInsertRows(QModelIndex(), 0, 0); endInsertRows(); - } else { + } + else + { beginInsertRows(treeParent, treeIndex.row(), treeIndex.row()); endInsertRows(); } @@ -1349,11 +1394,13 @@ void HistoryTreeModel::sourceRowsRemoved(const QModelIndex &parent, int start, i Q_ASSERT(!parent.isValid()); if (m_sourceRowCache.isEmpty()) return; - for (int i = end; i >= start;) { + for (int i = end; i >= start;) + { QList::iterator it; it = qLowerBound(m_sourceRowCache.begin(), m_sourceRowCache.end(), i); // playing it safe - if (it == m_sourceRowCache.end()) { + if (it == m_sourceRowCache.end()) + { m_sourceRowCache.clear(); reset(); return; @@ -1366,11 +1413,14 @@ void HistoryTreeModel::sourceRowsRemoved(const QModelIndex &parent, int start, i QModelIndex dateParent = index(row, 0); // If we can remove all the rows in the date do that and skip over them int rc = rowCount(dateParent); - if (i - rc + 1 == offset && start <= i - rc + 1) { + if (i - rc + 1 == offset && start <= i - rc + 1) + { beginRemoveRows(QModelIndex(), row, row); m_sourceRowCache.removeAt(row); i -= rc + 1; - } else { + } + else + { beginRemoveRows(dateParent, i - offset, i - offset); ++row; --i; -- cgit v1.2.1 From 48c84f9437f7197edcca59ae8d7807bc3c22f83e Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Tue, 21 Apr 2009 23:46:09 +0200 Subject: Updated History classes with Ben Meyer patches via kojots350 (thank you all..) --- src/history.cpp | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) (limited to 'src/history.cpp') diff --git a/src/history.cpp b/src/history.cpp index 96efd3e5..16acfa46 100644 --- a/src/history.cpp +++ b/src/history.cpp @@ -3,6 +3,7 @@ * This file is a part of the rekonq project * * Copyright (C) 2007-2008 Trolltech ASA. All rights reserved +* Copyright (C) 2008 Benjamin C. Meyer * Copyright (C) 2008 by Andrea Diamantini * * @@ -92,7 +93,7 @@ void HistoryManager::addHistoryEntry(const QString &url) cleanUrl.setPassword(QString()); cleanUrl.setHost(cleanUrl.host().toLower()); HistoryItem item(cleanUrl.toString(), QDateTime::currentDateTime()); - addHistoryItem(item); + addHistoryEntry(item); } @@ -171,7 +172,7 @@ void HistoryManager::checkForExpired() } -void HistoryManager::addHistoryItem(const HistoryItem &item) +void HistoryManager::addHistoryEntry(const HistoryItem &item) { QWebSettings *globalSettings = QWebSettings::globalSettings(); if (globalSettings->testAttribute(QWebSettings::PrivateBrowsingEnabled)) @@ -184,7 +185,7 @@ void HistoryManager::addHistoryItem(const HistoryItem &item) } -void HistoryManager::updateHistoryItem(const KUrl &url, const QString &title) +void HistoryManager::updateHistoryEntry(const KUrl &url, const QString &title) { for (int i = 0; i < m_history.count(); ++i) { @@ -201,6 +202,28 @@ void HistoryManager::updateHistoryItem(const KUrl &url, const QString &title) } +void HistoryManager::removeHistoryEntry(const HistoryItem &item) +{ + m_lastSavedUrl.clear(); + m_history.removeOne(item); + emit entryRemoved(item); +} + + +void HistoryManager::removeHistoryEntry(const KUrl &url, const QString &title) +{ + for (int i = 0; i < m_history.count(); ++i) + { + if (url == m_history.at(i).url + && (title.isEmpty() || title == m_history.at(i).title)) + { + removeHistoryEntry(m_history.at(i)); + break; + } + } +} + + int HistoryManager::historyLimit() const { return m_historyLimit; @@ -1154,7 +1177,7 @@ QVariant HistoryTreeModel::data(const QModelIndex &index, int role) const } if (index.column() == 1) { - return QString(rowCount(index.sibling(index.row(), 0))) + i18n(" items") ; + return QString::number(rowCount(index.sibling(index.row(), 0))) + i18n(" items") ; } } } @@ -1382,7 +1405,11 @@ QModelIndex HistoryTreeModel::mapFromSource(const QModelIndex &sourceIndex) cons it = qLowerBound(m_sourceRowCache.begin(), m_sourceRowCache.end(), sourceIndex.row()); if (*it != sourceIndex.row()) --it; + int dateRow = qMax(0, it - m_sourceRowCache.begin()); + // FIXME fix crach on history submenu open. BUG:'ASSERT failure in QList::at: "index out of range"' + // it crashes when dateRow == 1 + // kDebug() << m_sourceRowCache << dateRow; int row = sourceIndex.row() - m_sourceRowCache.at(dateRow); return createIndex(row, sourceIndex.column(), dateRow + 1); } -- cgit v1.2.1 From 7557af13f9f904cb9a6240d2101fb14e1ffdca99 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Wed, 22 Apr 2009 01:33:28 +0200 Subject: Fixing Copyrights --- src/history.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/history.cpp') diff --git a/src/history.cpp b/src/history.cpp index 16acfa46..eb718a1b 100644 --- a/src/history.cpp +++ b/src/history.cpp @@ -4,7 +4,8 @@ * * Copyright (C) 2007-2008 Trolltech ASA. All rights reserved * Copyright (C) 2008 Benjamin C. Meyer -* Copyright (C) 2008 by Andrea Diamantini +* Copyright (C) 2008-2009 by Andrea Diamantini +* Copyright (C) 2009 rekonq team. Please, see AUTHORS file for details * * * This program is free software; you can redistribute it -- cgit v1.2.1 From e657ef44ef1eef1f998101ab3dcce1a251d729fc Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Sun, 26 Apr 2009 01:45:38 +0200 Subject: Fixed copyright strings, per file, as decided --- src/history.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/history.cpp') diff --git a/src/history.cpp b/src/history.cpp index eb718a1b..a59a4ce3 100644 --- a/src/history.cpp +++ b/src/history.cpp @@ -5,7 +5,6 @@ * Copyright (C) 2007-2008 Trolltech ASA. All rights reserved * Copyright (C) 2008 Benjamin C. Meyer * Copyright (C) 2008-2009 by Andrea Diamantini -* Copyright (C) 2009 rekonq team. Please, see AUTHORS file for details * * * This program is free software; you can redistribute it -- cgit v1.2.1 From 82862fbd150afae0101757d1d6081e0e6ddf7baa Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Wed, 29 Apr 2009 11:24:11 +0200 Subject: astyle --- src/history.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/history.cpp') diff --git a/src/history.cpp b/src/history.cpp index a59a4ce3..ee21a8f2 100644 --- a/src/history.cpp +++ b/src/history.cpp @@ -212,10 +212,10 @@ void HistoryManager::removeHistoryEntry(const HistoryItem &item) void HistoryManager::removeHistoryEntry(const KUrl &url, const QString &title) { - for (int i = 0; i < m_history.count(); ++i) + for (int i = 0; i < m_history.count(); ++i) { if (url == m_history.at(i).url - && (title.isEmpty() || title == m_history.at(i).title)) + && (title.isEmpty() || title == m_history.at(i).title)) { removeHistoryEntry(m_history.at(i)); break; -- cgit v1.2.1 From 2c9ea8dd8a766c1518d2d09e711bde3d7e52270e Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Fri, 1 May 2009 01:44:22 +0200 Subject: i18n plural bugs. Courtesy patch of Kristol Baf --- src/history.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/history.cpp') diff --git a/src/history.cpp b/src/history.cpp index ee21a8f2..afcb477a 100644 --- a/src/history.cpp +++ b/src/history.cpp @@ -1177,7 +1177,7 @@ QVariant HistoryTreeModel::data(const QModelIndex &index, int role) const } if (index.column() == 1) { - return QString::number(rowCount(index.sibling(index.row(), 0))) + i18n(" items") ; + return i18np("1 item", "%1 items", rowCount(index.sibling(index.row(), 0))); } } } -- cgit v1.2.1 From 06b2dc0ce6ec6dd4cb090c22e2f9f8521138146b Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Wed, 6 May 2009 03:09:23 +0200 Subject: EBN Krazy fixes. 1st round.. --- src/history.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/history.cpp') diff --git a/src/history.cpp b/src/history.cpp index afcb477a..544b1f90 100644 --- a/src/history.cpp +++ b/src/history.cpp @@ -36,9 +36,17 @@ #include // Qt Includes -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include #include -- cgit v1.2.1