From c9b28f31e6db4c370674a83bd0417c936ebbbdea Mon Sep 17 00:00:00 2001 From: nowrep Date: Wed, 4 Apr 2012 14:45:45 +0200 Subject: [PATCH] Fixed bug when page with null icon could get "error page" siteicon - also fixed deleting history entries --- .gitignore | 7 +-- src/lib/history/historymanager.cpp | 2 +- src/lib/history/historymodel.cpp | 75 ++++++++++++------------------ src/lib/history/historymodel.h | 4 -- src/lib/webview/tabbedwebview.cpp | 2 - src/lib/webview/webpage.cpp | 16 ++++--- src/lib/webview/webpage.h | 4 +- src/lib/webview/webtab.cpp | 3 +- src/lib/webview/webview.cpp | 13 +++++- src/lib/webview/webview.h | 1 + 10 files changed, 59 insertions(+), 68 deletions(-) diff --git a/.gitignore b/.gitignore index dd07be66f..ba92d8a21 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ build DEBIAN -tools_ *.deb *.pro.user *.autosave @@ -12,12 +11,8 @@ tools_ headers*.tar.gz license_template Makefile* -TestPlugin-build -search_* -src-* bin/qupzilla -*.so -libqupzilla.* +lib*.so* bin/core qupzilla.sh git_revision diff --git a/src/lib/history/historymanager.cpp b/src/lib/history/historymanager.cpp index fbb32088e..c2ed78d75 100644 --- a/src/lib/history/historymanager.cpp +++ b/src/lib/history/historymanager.cpp @@ -306,9 +306,9 @@ void HistoryManager::slotRefreshTable() item->setText(1, url.toEncoded()); item->setToolTip(0, title); item->setToolTip(1, url.toEncoded()); - item->setData(0, Qt::UserRole + 10, id); item->setIcon(0, _iconForUrl(url)); + ui->historyTree->addTopLevelItem(item); ++counter; diff --git a/src/lib/history/historymodel.cpp b/src/lib/history/historymodel.cpp index b182d2cf7..60fab553e 100644 --- a/src/lib/history/historymodel.cpp +++ b/src/lib/history/historymodel.cpp @@ -30,9 +30,6 @@ HistoryModel::HistoryModel(QupZilla* mainClass) , p_QupZilla(mainClass) { loadSettings(); - - connect(this, SIGNAL(signalAddHistoryEntry(QUrl, QString)), this, SLOT(slotAddHistoryEntry(QUrl, QString))); - connect(this, SIGNAL(signalDeleteHistoryEntry(QList)), this, SLOT(slotDeleteHistoryEntry(QList))); } void HistoryModel::loadSettings() @@ -46,7 +43,7 @@ void HistoryModel::loadSettings() // AddHistoryEntry void HistoryModel::addHistoryEntry(WebView* view) { - if (!m_isSaving) { + if (!m_isSaving || view->loadingError()) { return; } @@ -57,17 +54,11 @@ void HistoryModel::addHistoryEntry(WebView* view) } 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()) { + if (url.scheme() == "qupzilla" || url.scheme() == "about" || url.isEmpty()) { return; } if (title == "") { @@ -125,7 +116,35 @@ void HistoryModel::deleteHistoryEntry(int index) void HistoryModel::deleteHistoryEntry(const QList &list) { - emit signalDeleteHistoryEntry(list); + QSqlDatabase db = QSqlDatabase::database(); + db.transaction(); + + foreach(int index, list) { + QSqlQuery query; + query.prepare("SELECT id, count, date, url, title FROM history WHERE id=?"); + query.addBindValue(index); + query.exec(); + + query.next(); + HistoryEntry entry; + entry.id = query.value(0).toInt(); + entry.count = query.value(1).toInt(); + entry.date = QDateTime::fromMSecsSinceEpoch(query.value(2).toLongLong()); + entry.url = query.value(3).toUrl(); + entry.title = query.value(4).toString(); + + query.prepare("DELETE FROM history WHERE id=?"); + query.addBindValue(index); + query.exec(); + + query.prepare("DELETE FROM icons WHERE url=?"); + query.addBindValue(entry.url.toEncoded(QUrl::RemoveFragment)); + query.exec(); + + emit historyEntryDeleted(entry); + } + + db.commit(); } void HistoryModel::deleteHistoryEntry(const QString &url, const QString &title) @@ -141,38 +160,6 @@ void HistoryModel::deleteHistoryEntry(const QString &url, const QString &title) } } -void HistoryModel::slotDeleteHistoryEntry(const QList &list) -{ - QSqlDatabase db = QSqlDatabase::database(); - db.transaction(); - - foreach(int index, list) { - QSqlQuery query; - query.prepare("SELECT id, count, date, url, title FROM history WHERE id=?"); - query.bindValue(0, index); - query.exec(); - - HistoryEntry entry; - entry.id = query.value(0).toInt(); - entry.count = query.value(1).toInt(); - entry.date = QDateTime::fromMSecsSinceEpoch(query.value(2).toLongLong()); - entry.url = query.value(3).toUrl(); - entry.title = query.value(4).toString(); - - query.prepare("DELETE FROM history WHERE id=?"); - query.bindValue(0, index); - query.exec(); - - query.prepare("DELETE FROM icons WHERE url=?"); - query.bindValue(0, entry.url.toEncoded(QUrl::RemoveFragment)); - query.exec(); - - emit historyEntryDeleted(entry); - } - - db.commit(); -} - bool HistoryModel::urlIsStored(const QString &url) { QSqlQuery query; diff --git a/src/lib/history/historymodel.h b/src/lib/history/historymodel.h index aa9e5d39b..51a105140 100644 --- a/src/lib/history/historymodel.h +++ b/src/lib/history/historymodel.h @@ -64,10 +64,6 @@ public: void loadSettings(); -private slots: - void slotAddHistoryEntry(const QUrl &url, QString title); - void slotDeleteHistoryEntry(const QList &list); - signals: void historyEntryAdded(HistoryEntry entry); void historyEntryDeleted(HistoryEntry entry); diff --git a/src/lib/webview/tabbedwebview.cpp b/src/lib/webview/tabbedwebview.cpp index e932cdf02..e74a15de5 100644 --- a/src/lib/webview/tabbedwebview.cpp +++ b/src/lib/webview/tabbedwebview.cpp @@ -82,8 +82,6 @@ void TabbedWebView::slotIconChanged() return; } - mApp->iconProvider()->saveIcon(this); - showIcon(); } diff --git a/src/lib/webview/webpage.cpp b/src/lib/webview/webpage.cpp index c5eda2a81..3152214b4 100644 --- a/src/lib/webview/webpage.cpp +++ b/src/lib/webview/webpage.cpp @@ -67,7 +67,6 @@ WebPage::WebPage(QupZilla* mainClass) , m_runningLoop(0) , m_blockAlerts(false) , m_secureStatus(false) - , m_isClosing(false) { m_networkProxy = new NetworkManagerProxy(this); m_networkProxy->setPrimaryNetworkAccessManager(mApp->networkManager()); @@ -135,6 +134,11 @@ void WebPage::scheduleAdjustPage() } } +bool WebPage::loadingError() const +{ + return !mainFrame()->findFirstElement("span[id=\"qupzilla-error-page\"]").isNull(); +} + bool WebPage::isRunningLoop() { return m_runningLoop; @@ -553,7 +557,7 @@ bool WebPage::extension(Extension extension, const ExtensionOption* option, Exte errString.replace("%RULE%", tr("Blocked by rule %1").arg(rule)); exReturn->baseUrl = exOption->url; - exReturn->content = errString.toUtf8(); + exReturn->content = QString(errString + "").toUtf8(); if (PopupWebPage* popupPage = qobject_cast(exOption->frame->page())) { WebView* view = qobject_cast(popupPage->view()); @@ -599,7 +603,7 @@ bool WebPage::extension(Extension extension, const ExtensionOption* option, Exte errString.replace("%LI-3%", tr("If your computer or network is protected by a firewall or proxy, make sure that QupZilla is permitted to access the Web.")); errString.replace("%TRY-AGAIN%", tr("Try Again")); - exReturn->content = errString.toUtf8(); + exReturn->content = QString(errString + "").toUtf8(); return true; } @@ -631,7 +635,7 @@ bool WebPage::javaScriptPrompt(QWebFrame* originatingFrame, const QString &msg, m_runningLoop = &eLoop; connect(ui->buttonBox, SIGNAL(clicked(QAbstractButton*)), &eLoop, SLOT(quit())); - if (eLoop.exec() == 1 || m_isClosing) { + if (eLoop.exec() == 1) { return result; } m_runningLoop = 0; @@ -673,7 +677,7 @@ bool WebPage::javaScriptConfirm(QWebFrame* originatingFrame, const QString &msg) m_runningLoop = &eLoop; connect(ui->buttonBox, SIGNAL(clicked(QAbstractButton*)), &eLoop, SLOT(quit())); - if (eLoop.exec() == 1 || m_isClosing) { + if (eLoop.exec() == 1) { return false; } m_runningLoop = 0; @@ -728,7 +732,7 @@ void WebPage::javaScriptAlert(QWebFrame* originatingFrame, const QString &msg) m_runningLoop = &eLoop; connect(ui->buttonBox, SIGNAL(clicked(QAbstractButton*)), &eLoop, SLOT(quit())); - if (eLoop.exec() == 1 || m_isClosing) { + if (eLoop.exec() == 1) { return; } m_runningLoop = 0; diff --git a/src/lib/webview/webpage.h b/src/lib/webview/webpage.h index 274a8124c..820481f67 100644 --- a/src/lib/webview/webpage.h +++ b/src/lib/webview/webpage.h @@ -66,6 +66,8 @@ public: void scheduleAdjustPage(); bool isRunningLoop(); + bool loadingError() const; + static void setUserAgent(const QString &agent); QString userAgentForUrl(const QUrl &url) const; @@ -126,8 +128,6 @@ private: bool m_blockAlerts; bool m_secureStatus; bool m_adjustingScheduled; - - bool m_isClosing; }; #endif // WEBPAGE_H diff --git a/src/lib/webview/webtab.cpp b/src/lib/webview/webtab.cpp index 419bd3623..51f2f8658 100644 --- a/src/lib/webview/webtab.cpp +++ b/src/lib/webview/webtab.cpp @@ -224,8 +224,9 @@ void WebTab::restoreTab(const WebTab::SavedTab &tab) m_savedTab = tab; int index = tabIndex(); - m_view->tabWidget()->setTabIcon(tabIndex(), tab.icon); + m_view->tabWidget()->setTabIcon(index, tab.icon); m_view->tabWidget()->setTabText(index, tab.title); + m_view->tabWidget()->setTabToolTip(index, tab.title); m_locationBar.data()->showUrl(tab.url); } else { diff --git a/src/lib/webview/webview.cpp b/src/lib/webview/webview.cpp index bdf55c53d..e53c4fb24 100644 --- a/src/lib/webview/webview.cpp +++ b/src/lib/webview/webview.cpp @@ -155,6 +155,11 @@ void WebView::load(const QNetworkRequest &request, QNetworkAccessManager::Operat } +bool WebView::loadingError() const +{ + return page()->loadingError(); +} + bool WebView::isLoading() const { return m_isLoading; @@ -343,8 +348,12 @@ void WebView::emitChangedUrl() void WebView::slotIconChanged() { - m_siteIcon = icon(); - m_siteIconUrl = url(); + if (!loadingError()) { + m_siteIcon = icon(); + m_siteIconUrl = url(); + + mApp->iconProvider()->saveIcon(this); + } } void WebView::openUrlInNewWindow() diff --git a/src/lib/webview/webview.h b/src/lib/webview/webview.h index 3904a90a9..544c0cbcb 100644 --- a/src/lib/webview/webview.h +++ b/src/lib/webview/webview.h @@ -41,6 +41,7 @@ public: void load(const QNetworkRequest &request, QNetworkAccessManager::Operation operation = QNetworkAccessManager::GetOperation, const QByteArray &body = QByteArray()); + bool loadingError() const; bool isLoading() const; int loadProgress() const;