1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 18:56:34 +01:00

[Fix] editing new bookmark + moving some classes to own thread

- history model and database writer are now in own thread
- this will keep main thread (GUI) responsive when writing to
  database
- it also greatly increases performance when deleting multiple
  items in history
This commit is contained in:
nowrep 2011-12-17 14:30:54 +01:00
parent 88d15cd3b8
commit 976e5b5696
16 changed files with 134 additions and 83 deletions

View File

@ -62,7 +62,7 @@ MainApplication::MainApplication(const QList<CommandLineOptions::ActionPair> &cm
, m_desktopNotifications(0)
, m_iconProvider(new IconProvider(this))
, m_searchEnginesManager(0)
, m_dbWriter(new DatabaseWriter(this))
, m_dbWriter(new DatabaseWriter())
, m_isClosing(false)
, m_isStateChanged(false)
, m_isExited(false)

View File

@ -578,7 +578,7 @@ void QupZilla::aboutToShowBookmarksMenu()
m_menuBookmarks->addAction(act);
}
Menu* menuBookmarks = new Menu(tr("Bookmarks In ToolBar"), m_menuBookmarks);
Menu* menuBookmarks = new Menu(_bookmarksToolbar, m_menuBookmarks);
menuBookmarks->setIcon(QIcon(style()->standardIcon(QStyle::SP_DirOpenIcon)));
query.exec("SELECT title, url, icon FROM bookmarks WHERE folder='bookmarksToolbar'");
@ -1170,7 +1170,7 @@ void QupZilla::openFile()
{
QString filePath = QFileDialog::getOpenFileName(this, tr("Open file..."), QDir::homePath(), "(*.html *.htm *.jpg *.png)");
if (!filePath.isEmpty()) {
loadAddress(QUrl(filePath));
loadAddress(QUrl::fromLocalFile(filePath));
}
}

View File

@ -121,7 +121,7 @@ void BookmarksManager::renameFolder()
QString folder = item->text(0);
if (folder == tr("Bookmarks In Menu") || folder == tr("Bookmarks In ToolBar")) {
if (folder == _bookmarksMenu || folder == _bookmarksToolbar) {
return;
}
@ -214,12 +214,12 @@ void BookmarksManager::contextMenuRequested(const QPoint &position)
if (link.isEmpty()) {
QString folderName = ui->bookmarksTree->itemAt(position)->text(0);
QMenu menu;
if (folderName == tr("Bookmarks In ToolBar")) {
if (folderName == _bookmarksToolbar) {
menu.addAction(tr("Add Subfolder"), this, SLOT(addSubfolder()));
menu.addSeparator();
}
if (folderName != tr("Bookmarks In ToolBar") && folderName != tr("Bookmarks In Menu")) {
if (folderName != _bookmarksToolbar && folderName != _bookmarksMenu) {
menu.addAction(tr("Rename folder"), this, SLOT(renameFolder()));
menu.addAction(tr("Remove folder"), this, SLOT(deleteItem()));
}
@ -242,9 +242,9 @@ void BookmarksManager::contextMenuRequested(const QPoint &position)
QMenu moveMenu;
moveMenu.setTitle(tr("Move bookmark to &folder"));
moveMenu.addAction(QIcon(":icons/other/unsortedbookmarks.png"), tr("Unsorted Bookmarks"), this, SLOT(moveBookmark()))->setData("unsorted");
moveMenu.addAction(style()->standardIcon(QStyle::SP_DirOpenIcon), tr("Bookmarks In Menu"), this, SLOT(moveBookmark()))->setData("bookmarksMenu");
moveMenu.addAction(style()->standardIcon(QStyle::SP_DirOpenIcon), tr("Bookmarks In ToolBar"), this, SLOT(moveBookmark()))->setData("bookmarksToolbar");
moveMenu.addAction(QIcon(":icons/other/unsortedbookmarks.png"), _bookmarksUnsorted, this, SLOT(moveBookmark()))->setData("unsorted");
moveMenu.addAction(style()->standardIcon(QStyle::SP_DirOpenIcon), _bookmarksMenu, this, SLOT(moveBookmark()))->setData("bookmarksMenu");
moveMenu.addAction(style()->standardIcon(QStyle::SP_DirOpenIcon), _bookmarksToolbar, this, SLOT(moveBookmark()))->setData("bookmarksToolbar");
QSqlQuery query;
query.exec("SELECT name FROM folders");
while (query.next()) {
@ -270,12 +270,12 @@ void BookmarksManager::refreshTable()
QSqlQuery query;
QTreeWidgetItem* newItem = new QTreeWidgetItem(ui->bookmarksTree);
newItem->setText(0, tr("Bookmarks In Menu"));
newItem->setText(0, _bookmarksMenu);
newItem->setIcon(0, style()->standardIcon(QStyle::SP_DirIcon));
ui->bookmarksTree->addTopLevelItem(newItem);
QTreeWidgetItem* bookmarksToolbar = new QTreeWidgetItem(ui->bookmarksTree);
bookmarksToolbar->setText(0, tr("Bookmarks In ToolBar"));
bookmarksToolbar->setText(0, _bookmarksToolbar);
bookmarksToolbar->setIcon(0, style()->standardIcon(QStyle::SP_DirIcon));
ui->bookmarksTree->addTopLevelItem(bookmarksToolbar);
@ -296,10 +296,10 @@ void BookmarksManager::refreshTable()
QIcon icon = IconProvider::iconFromBase64(query.value(4).toByteArray());
QTreeWidgetItem* item = new QTreeWidgetItem();
if (folder == "bookmarksMenu") {
folder = tr("Bookmarks In Menu");
folder = _bookmarksMenu;
}
if (folder == "bookmarksToolbar") {
folder = tr("Bookmarks In ToolBar");
folder = _bookmarksToolbar;
}
if (folder != "unsorted") {
@ -472,7 +472,7 @@ void BookmarksManager::addSubfolder(const QString &name)
{
m_isRefreshing = true;
QList<QTreeWidgetItem*> list = ui->bookmarksTree->findItems(tr("Bookmarks In ToolBar"), Qt::MatchExactly);
QList<QTreeWidgetItem*> list = ui->bookmarksTree->findItems(_bookmarksToolbar, Qt::MatchExactly);
if (list.count() != 0) {
QTreeWidgetItem* item = new QTreeWidgetItem(list.at(0));
item->setText(0, name);
@ -551,9 +551,9 @@ void BookmarksManager::insertBookmark(const QUrl &url, const QString &title, con
}
layout->addWidget(box);
combo->addItem(QIcon(":icons/other/unsortedbookmarks.png"), tr("Unsorted Bookmarks"));
combo->addItem(style()->standardIcon(QStyle::SP_DirOpenIcon), tr("Bookmarks In Menu"));
combo->addItem(style()->standardIcon(QStyle::SP_DirOpenIcon), tr("Bookmarks In ToolBar"));
combo->addItem(QIcon(":icons/other/unsortedbookmarks.png"), _bookmarksUnsorted);
combo->addItem(style()->standardIcon(QStyle::SP_DirOpenIcon), _bookmarksMenu);
combo->addItem(style()->standardIcon(QStyle::SP_DirOpenIcon), _bookmarksToolbar);
QSqlQuery query;
query.exec("SELECT name FROM folders");
while (query.next()) {
@ -596,9 +596,9 @@ void BookmarksManager::insertAllTabs()
layout->addWidget(combo);
layout->addWidget(box);
combo->addItem(QIcon(":icons/other/unsortedbookmarks.png"), tr("Unsorted Bookmarks"));
combo->addItem(style()->standardIcon(QStyle::SP_DirOpenIcon), tr("Bookmarks In Menu"));
combo->addItem(style()->standardIcon(QStyle::SP_DirOpenIcon), tr("Bookmarks In ToolBar"));
combo->addItem(QIcon(":icons/other/unsortedbookmarks.png"), _bookmarksUnsorted);
combo->addItem(style()->standardIcon(QStyle::SP_DirOpenIcon), _bookmarksMenu);
combo->addItem(style()->standardIcon(QStyle::SP_DirOpenIcon), _bookmarksToolbar);
QSqlQuery query;
query.exec("SELECT name FROM folders");
while (query.next()) {

View File

@ -132,7 +132,7 @@ bool BookmarksModel::saveBookmark(const QUrl &url, const QString &title, const Q
query.bindValue(1, title);
query.bindValue(2, folder);
query.bindValue(3, IconProvider::iconToBase64(icon));
mApp->dbWriter()->executeQuery(query);
query.exec();
Bookmark bookmark;
bookmark.id = query.lastInsertId().toInt();
@ -275,7 +275,7 @@ bool BookmarksModel::createFolder(const QString &name)
bool BookmarksModel::removeFolder(const QString &name)
{
if (name == tr("Bookmarks In Menu") || name == tr("Bookmarks In ToolBar")) {
if (name == _bookmarksMenu || name == _bookmarksToolbar) {
return false;
}

View File

@ -18,6 +18,10 @@
#ifndef BOOKMARKSMODEL_H
#define BOOKMARKSMODEL_H
#define _bookmarksToolbar BookmarksModel::toTranslatedFolder("bookmarksToolbar")
#define _bookmarksMenu BookmarksModel::toTranslatedFolder("bookmarksMenu")
#define _bookmarksUnsorted BookmarksModel::toTranslatedFolder("unsorted")
#include <QObject>
#include <QUrl>
#include <QSettings>
@ -29,7 +33,7 @@ class BookmarksModel : public QObject
{
Q_OBJECT
public:
explicit BookmarksModel(QObject* parent);
explicit BookmarksModel(QObject* parent = 0);
struct Bookmark {
int id;

View File

@ -42,9 +42,9 @@ void BookmarksWidget::loadBookmark()
ui->name->setText(bookmark.title);
// Bookmark folders
ui->folder->addItem(QIcon(":icons/other/unsortedbookmarks.png"), tr("Unsorted Bookmarks"), "unsorted");
ui->folder->addItem(style()->standardIcon(QStyle::SP_DirOpenIcon), tr("Bookmarks In Menu"), "bookmarksMenu");
ui->folder->addItem(style()->standardIcon(QStyle::SP_DirOpenIcon), tr("Bookmarks In ToolBar"), "bookmarksToolbar");
ui->folder->addItem(QIcon(":icons/other/unsortedbookmarks.png"), _bookmarksUnsorted, "unsorted");
ui->folder->addItem(style()->standardIcon(QStyle::SP_DirOpenIcon), _bookmarksMenu, "bookmarksMenu");
ui->folder->addItem(style()->standardIcon(QStyle::SP_DirOpenIcon), _bookmarksToolbar, "bookmarksToolbar");
QSqlQuery query;
query.exec("SELECT name FROM folders");
while (query.next()) {

View File

@ -108,7 +108,6 @@ void HistoryManager::contextMenuRequested(const QPoint &position)
void HistoryManager::deleteItem()
{
QApplication::setOverrideCursor(Qt::WaitCursor);
foreach(QTreeWidgetItem * item, ui->historyTree->selectedItems()) {
if (!item) {
return;
@ -119,15 +118,20 @@ void HistoryManager::deleteItem()
QTreeWidgetItem* children = item->child(i);
int id = children->whatsThis(1).toInt();
m_historyModel->deleteHistoryEntry(id);
ui->historyTree->deleteItem(children);
m_ignoredIds.append(id);
}
ui->historyTree->deleteItem(item);
}
else {
int id = item->whatsThis(1).toInt();
m_historyModel->deleteHistoryEntry(id);
ui->historyTree->deleteItem(item);
m_ignoredIds.append(id);
}
}
QApplication::restoreOverrideCursor();
}
void HistoryManager::historyEntryAdded(const HistoryModel::HistoryEntry &entry)
@ -176,6 +180,11 @@ void HistoryManager::historyEntryAdded(const HistoryModel::HistoryEntry &entry)
void HistoryManager::historyEntryDeleted(const HistoryModel::HistoryEntry &entry)
{
if (m_ignoredIds.contains(entry.id)) {
m_ignoredIds.removeOne(entry.id);
return;
}
QList<QTreeWidgetItem*> list = ui->historyTree->allItems();
foreach(QTreeWidgetItem * item, list) {
if (!item) {

View File

@ -62,6 +62,8 @@ private:
Ui::HistoryManager* ui;
QWeakPointer<QupZilla> p_QupZilla;
HistoryModel* m_historyModel;
QList<int> m_ignoredIds;
};
#endif // HISTORYMANAGER_H

View File

@ -21,12 +21,21 @@
#include "iconprovider.h"
#include "databasewriter.h"
HistoryModel::HistoryModel(QupZilla* mainClass, QObject* parent)
: QObject(parent)
HistoryModel::HistoryModel(QupZilla* mainClass)
: QObject()
, m_isSaving(true)
, p_QupZilla(mainClass)
{
loadSettings();
qRegisterMetaType<HistoryModel::HistoryEntry>("HistoryModel::HistoryEntry");
QThread* t = new QThread(this);
t->start();
moveToThread(t);
connect(this, SIGNAL(signalAddHistoryEntry(QUrl,QString)), this, SLOT(slotAddHistoryEntry(QUrl,QString)));
connect(this, SIGNAL(signalDeleteHistoryEntry(int)), this, SLOT(slotDeleteHistoryEntry(int)));
}
void HistoryModel::loadSettings()
@ -37,14 +46,32 @@ void HistoryModel::loadSettings()
settings.endGroup();
}
int HistoryModel::addHistoryEntry(const QUrl &url, QString &title)
// AddHistoryEntry
void HistoryModel::addHistoryEntry(WebView* view)
{
if (!m_isSaving) {
return -2;
return;
}
QUrl url = view->url();
QString title = view->title();
addHistoryEntry(url, title);
}
void HistoryModel::addHistoryEntry(const QUrl &url, QString title)
{
emit signalAddHistoryEntry(url, title);
}
void HistoryModel::slotAddHistoryEntry(const QUrl &url, QString title)
{
if (!m_isSaving) {
return;
}
if (url.scheme() == "file:" || url.scheme() == "qupzilla" || url.scheme() == "about" ||
title.contains(tr("Failed loading page")) || url.isEmpty()) {
return -1;
return;
}
if (title == "") {
title = tr("No Named Page");
@ -59,7 +86,7 @@ int HistoryModel::addHistoryEntry(const QUrl &url, QString &title)
query.bindValue(0, QDateTime::currentMSecsSinceEpoch());
query.bindValue(1, url);
query.bindValue(2, title);
mApp->dbWriter()->executeQuery(query);
query.exec();
int id = query.lastInsertId().toInt();
HistoryEntry entry;
@ -76,7 +103,7 @@ int HistoryModel::addHistoryEntry(const QUrl &url, QString &title)
query.bindValue(0, QDateTime::currentMSecsSinceEpoch());
query.bindValue(1, title);
query.bindValue(2, url);
mApp->dbWriter()->executeQuery(query);
query.exec();
HistoryEntry before;
before.id = id;
@ -88,30 +115,37 @@ int HistoryModel::addHistoryEntry(const QUrl &url, QString &title)
after.title = title;
emit historyEntryEdited(before, after);
}
return query.lastInsertId().toInt();
}
int HistoryModel::addHistoryEntry(WebView* view)
// DeleteHistoryEntry
void HistoryModel::deleteHistoryEntry(int index)
{
if (!m_isSaving) {
return -2;
}
QUrl url = view->url();
QString title = view->title();
return addHistoryEntry(url, title);
emit signalDeleteHistoryEntry(index);
}
bool HistoryModel::deleteHistoryEntry(int index)
void HistoryModel::deleteHistoryEntry(const QString &url, const QString &title)
{
QSqlQuery query;
query.prepare("SELECT id FROM history WHERE url=? AND title=?");
query.bindValue(0, url);
query.bindValue(1, title);
query.exec();
if (query.next()) {
int id = query.value(0).toInt();
deleteHistoryEntry(id);
}
}
void HistoryModel::slotDeleteHistoryEntry(int index)
{
QSqlQuery query;
query.prepare("SELECT id, count, date, url, title FROM history WHERE id=?");
query.bindValue(0, index);
query.exec();
if (!query.next()) {
return false;
return;
}
HistoryEntry entry;
entry.id = query.value(0).toInt();
entry.count = query.value(1).toInt();
@ -121,27 +155,12 @@ bool HistoryModel::deleteHistoryEntry(int index)
query.prepare("DELETE FROM history WHERE id=?");
query.bindValue(0, index);
mApp->dbWriter()->executeQuery(query);
query.exec();
query.prepare("DELETE FROM icons WHERE url=?");
query.bindValue(0, entry.url.toEncoded(QUrl::RemoveFragment));
mApp->dbWriter()->executeQuery(query);
query.exec();
emit historyEntryDeleted(entry);
return true;
}
bool HistoryModel::deleteHistoryEntry(const QString &url, const QString &title)
{
QSqlQuery query;
query.prepare("SELECT id FROM history WHERE url=? AND title=?");
query.bindValue(0, url);
query.bindValue(1, title);
query.exec();
if (query.next()) {
int id = query.value(0).toInt();
return deleteHistoryEntry(id);
}
return false;
}
bool HistoryModel::urlIsStored(const QString &url)

View File

@ -24,6 +24,7 @@
#include <QFile>
#include <QIcon>
#include <QUrl>
#include <QThread>
class QupZilla;
class WebView;
@ -32,7 +33,7 @@ class HistoryModel : public QObject
{
Q_OBJECT
public:
HistoryModel(QupZilla* mainClass, QObject* parent = 0);
HistoryModel(QupZilla* mainClass);
struct HistoryEntry {
int id;
@ -44,10 +45,12 @@ public:
static QString titleCaseLocalizedMonth(int month);
int addHistoryEntry(WebView* view);
int addHistoryEntry(const QUrl &url, QString &title);
bool deleteHistoryEntry(int index);
bool deleteHistoryEntry(const QString &url, const QString &title);
void addHistoryEntry(WebView* view);
void addHistoryEntry(const QUrl &url, QString title);
void deleteHistoryEntry(int index);
void deleteHistoryEntry(const QString &url, const QString &title);
bool urlIsStored(const QString &url);
QList<HistoryModel::HistoryEntry> mostVisited(int count);
@ -59,6 +62,10 @@ public:
void loadSettings();
private slots:
void slotAddHistoryEntry(const QUrl &url, QString title);
void slotDeleteHistoryEntry(int index);
signals:
void historyEntryAdded(HistoryModel::HistoryEntry entry);
void historyEntryDeleted(HistoryModel::HistoryEntry entry);
@ -66,6 +73,9 @@ signals:
//WARNING: Incomplete HistoryEntry structs are passed to historyEntryEdited!
void historyClear();
void signalAddHistoryEntry(QUrl url, QString title);
void signalDeleteHistoryEntry(int index);
private:
bool m_isSaving;
QupZilla* p_QupZilla;

View File

@ -17,16 +17,19 @@
* ============================================================ */
#include "databasewriter.h"
DatabaseWriter::DatabaseWriter(QObject* parent)
: QObject(parent)
DatabaseWriter::DatabaseWriter()
: QObject()
{
QThread* t = new QThread(this);
t->start();
moveToThread(t);
}
void DatabaseWriter::executeQuery(const QSqlQuery &query)
{
m_queries.append(query);
QtConcurrent::run(this, &DatabaseWriter::execute);
QTimer::singleShot(0, this, SLOT(execute()));
}
void DatabaseWriter::execute()

View File

@ -19,25 +19,25 @@
#define DATABASEWRITER_H
#include <QObject>
#include <QThread>
#include <QSqlQuery>
#include <QList>
#include <QtConcurrentRun>
#include <QTimer>
class DatabaseWriter : public QObject
{
Q_OBJECT
public:
explicit DatabaseWriter(QObject* parent = 0);
explicit DatabaseWriter();
void executeQuery(const QSqlQuery &query);
signals:
public slots:
private:
private slots:
void execute();
private:
QList<QSqlQuery> m_queries;
};

View File

@ -221,7 +221,7 @@ void BookmarksSideBar::refreshTable()
QSqlQuery query;
QTreeWidgetItem* newItem = new QTreeWidgetItem(ui->bookmarksTree);
newItem->setText(0, tr("Bookmarks In Menu"));
newItem->setText(0, _bookmarksMenu);
newItem->setIcon(0, style()->standardIcon(QStyle::SP_DirIcon));
ui->bookmarksTree->addTopLevelItem(newItem);
@ -242,7 +242,7 @@ void BookmarksSideBar::refreshTable()
QIcon icon = IconProvider::iconFromBase64(query.value(4).toByteArray());
QTreeWidgetItem* item;
if (folder == "bookmarksMenu") {
folder = tr("Bookmarks In Menu");
folder = _bookmarksMenu;
}
if (folder == "bookmarksToolbar") {
continue;

View File

@ -178,7 +178,8 @@ SOURCES += main.cpp\
plugins/speeddial.cpp \
other/databasewriter.cpp \
bookmarksimport/htmlimporter.cpp \
tools/enhancedmenu.cpp
tools/enhancedmenu.cpp \
navigation/siteicon.cpp
HEADERS += \
3rdparty/qtwin.h \
@ -297,7 +298,8 @@ HEADERS += \
plugins/speeddial.h \
other/databasewriter.h \
bookmarksimport/htmlimporter.h \
tools/enhancedmenu.h
tools/enhancedmenu.h \
navigation/siteicon.h
FORMS += \
preferences/autofillmanager.ui \

View File

@ -57,9 +57,11 @@ signals:
public slots:
private:
protected:
void mousePressEvent(QMouseEvent* e);
void mouseReleaseEvent(QMouseEvent* e);
private:
void paintEvent(QPaintEvent* e);
bool m_usingMultiIcon;

View File

@ -917,7 +917,7 @@ bool WebView::isUrlValid(const QUrl &url)
}
///
// This function was taken and modified from QTestBrowser to fix bug #33 with flighradar24.com
// This function was taken and modified from QTestBrowser to fix bug #33 with flightradar24.com
// You can find original source and copyright here:
// http://gitorious.org/+qtwebkit-developers/webkit/qtwebkit/blobs/qtwebkit-2.2/Tools/QtTestBrowser/launcherwindow.cpp
///