diff --git a/src/app/mainapplication.cpp b/src/app/mainapplication.cpp index e1f7d2cf3..23e688ade 100644 --- a/src/app/mainapplication.cpp +++ b/src/app/mainapplication.cpp @@ -62,7 +62,7 @@ MainApplication::MainApplication(const QList &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) diff --git a/src/app/qupzilla.cpp b/src/app/qupzilla.cpp index ed93ca99d..9e325eb5a 100644 --- a/src/app/qupzilla.cpp +++ b/src/app/qupzilla.cpp @@ -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)); } } diff --git a/src/bookmarks/bookmarksmanager.cpp b/src/bookmarks/bookmarksmanager.cpp index 4584d93cb..134b60e9a 100644 --- a/src/bookmarks/bookmarksmanager.cpp +++ b/src/bookmarks/bookmarksmanager.cpp @@ -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 list = ui->bookmarksTree->findItems(tr("Bookmarks In ToolBar"), Qt::MatchExactly); + QList 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()) { diff --git a/src/bookmarks/bookmarksmodel.cpp b/src/bookmarks/bookmarksmodel.cpp index c3ced3e06..637ef0114 100644 --- a/src/bookmarks/bookmarksmodel.cpp +++ b/src/bookmarks/bookmarksmodel.cpp @@ -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; } diff --git a/src/bookmarks/bookmarksmodel.h b/src/bookmarks/bookmarksmodel.h index 4441f2cef..c3a3b62a5 100644 --- a/src/bookmarks/bookmarksmodel.h +++ b/src/bookmarks/bookmarksmodel.h @@ -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 #include #include @@ -29,7 +33,7 @@ class BookmarksModel : public QObject { Q_OBJECT public: - explicit BookmarksModel(QObject* parent); + explicit BookmarksModel(QObject* parent = 0); struct Bookmark { int id; diff --git a/src/bookmarks/bookmarkswidget.cpp b/src/bookmarks/bookmarkswidget.cpp index 636dce299..dab9b145b 100644 --- a/src/bookmarks/bookmarkswidget.cpp +++ b/src/bookmarks/bookmarkswidget.cpp @@ -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()) { diff --git a/src/history/historymanager.cpp b/src/history/historymanager.cpp index bad25cf31..065fcdce9 100644 --- a/src/history/historymanager.cpp +++ b/src/history/historymanager.cpp @@ -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 list = ui->historyTree->allItems(); foreach(QTreeWidgetItem * item, list) { if (!item) { diff --git a/src/history/historymanager.h b/src/history/historymanager.h index 7090bda37..ede4e3452 100644 --- a/src/history/historymanager.h +++ b/src/history/historymanager.h @@ -62,6 +62,8 @@ private: Ui::HistoryManager* ui; QWeakPointer p_QupZilla; HistoryModel* m_historyModel; + + QList m_ignoredIds; }; #endif // HISTORYMANAGER_H diff --git a/src/history/historymodel.cpp b/src/history/historymodel.cpp index 9a525aab7..14079b5e7 100644 --- a/src/history/historymodel.cpp +++ b/src/history/historymodel.cpp @@ -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"); + + 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) diff --git a/src/history/historymodel.h b/src/history/historymodel.h index b6f59f204..815cdafa4 100644 --- a/src/history/historymodel.h +++ b/src/history/historymodel.h @@ -24,6 +24,7 @@ #include #include #include +#include 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 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; diff --git a/src/other/databasewriter.cpp b/src/other/databasewriter.cpp index d48830738..79b9bdc54 100644 --- a/src/other/databasewriter.cpp +++ b/src/other/databasewriter.cpp @@ -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() diff --git a/src/other/databasewriter.h b/src/other/databasewriter.h index 7d4048365..c0b2c3e34 100644 --- a/src/other/databasewriter.h +++ b/src/other/databasewriter.h @@ -19,25 +19,25 @@ #define DATABASEWRITER_H #include +#include #include #include -#include +#include 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 m_queries; }; diff --git a/src/sidebar/bookmarkssidebar.cpp b/src/sidebar/bookmarkssidebar.cpp index c74867501..23e1099a8 100644 --- a/src/sidebar/bookmarkssidebar.cpp +++ b/src/sidebar/bookmarkssidebar.cpp @@ -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; diff --git a/src/src.pro b/src/src.pro index c475c4919..a5dfabdcd 100644 --- a/src/src.pro +++ b/src/src.pro @@ -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 \ diff --git a/src/tools/toolbutton.h b/src/tools/toolbutton.h index 95526f721..bb2b94d5f 100644 --- a/src/tools/toolbutton.h +++ b/src/tools/toolbutton.h @@ -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; diff --git a/src/webview/webview.cpp b/src/webview/webview.cpp index 2288bf799..fe83245d1 100644 --- a/src/webview/webview.cpp +++ b/src/webview/webview.cpp @@ -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 ///