From 0279018f17be620c935289b0fd658b00153a4afa Mon Sep 17 00:00:00 2001 From: nowrep Date: Sun, 31 Jul 2011 00:50:40 +0200 Subject: [PATCH] Fixed bug with duplicated history entries Added AdBlock cleanup after loading page which removes blocked objects from page --- src/adblock/adblockdialog.cpp | 2 + src/adblock/adblockrule.cpp | 6 +-- src/app/qupzilla.cpp | 40 ++++++++----------- src/app/qupzilla.h | 4 +- src/webview/webpage.cpp | 74 +++++++++++++++++++++-------------- src/webview/webpage.h | 1 + src/webview/webview.cpp | 1 + 7 files changed, 68 insertions(+), 60 deletions(-) diff --git a/src/adblock/adblockdialog.cpp b/src/adblock/adblockdialog.cpp index 956bd7a56..58b774dba 100644 --- a/src/adblock/adblockdialog.cpp +++ b/src/adblock/adblockdialog.cpp @@ -57,6 +57,8 @@ AdBlockDialog::AdBlockDialog(QWidget *parent) adblockCheckBox->setChecked(m_manager->isEnabled()); treeWidget->setContextMenuPolicy(Qt::CustomContextMenu); + treeWidget->setDefaultItemShowMode(TreeWidget::ItemsExpanded); + connect(adblockCheckBox, SIGNAL(toggled(bool)), m_manager, SLOT(setEnabled(bool))); connect(addButton, SIGNAL(clicked()), this, SLOT(addCustomRule())); connect(reloadButton, SIGNAL(clicked()), this, SLOT(updateSubscription())); diff --git a/src/adblock/adblockrule.cpp b/src/adblock/adblockrule.cpp index 1682e1c91..dca185e33 100644 --- a/src/adblock/adblockrule.cpp +++ b/src/adblock/adblockrule.cpp @@ -209,9 +209,7 @@ static QString convertPatternToRegExp(const QString &wildcardPattern) { void AdBlockRule::setPattern(const QString &pattern, bool isRegExp) { - if (isRegExp) - qDebug() << pattern; - m_regExp = QRegExp(isRegExp ? pattern : convertPatternToRegExp(pattern), - Qt::CaseInsensitive, QRegExp::RegExp); + Q_UNUSED(isRegExp) + m_regExp = QRegExp(convertPatternToRegExp(pattern), Qt::CaseInsensitive, QRegExp::RegExp); } diff --git a/src/app/qupzilla.cpp b/src/app/qupzilla.cpp index 538f2345b..33012f698 100644 --- a/src/app/qupzilla.cpp +++ b/src/app/qupzilla.cpp @@ -520,28 +520,14 @@ void QupZilla::receiveMessage(MainApplication::MessageType mes, bool state) } } -void QupZilla::refreshHistory(int index) +void QupZilla::refreshHistory() { if (mApp->isClosing()) return; - QWebHistory* history; - if (index == -1) - history = weView()->page()->history(); - else - history = weView()->page()->history(); - - if (history->canGoBack()) { - m_buttonBack->setEnabled(true); - } else { - m_buttonBack->setEnabled(false); - } - - if (history->canGoForward()) { - m_buttonNext->setEnabled(true); - } else { - m_buttonNext->setEnabled(false); - } + QWebHistory* history = weView()->page()->history(); + m_buttonBack->setEnabled(history->canGoBack()); + m_buttonNext->setEnabled(history->canGoForward()); } void QupZilla::goAtHistoryIndex() @@ -559,13 +545,13 @@ void QupZilla::aboutToShowHistoryBackMenu() m_menuBack->clear(); QWebHistory* history = weView()->history(); int curindex = history->currentItemIndex(); - for (int i = curindex-1;i>=0;i--) { + for (int i = curindex-1; i >= 0; i--) { QWebHistoryItem item = history->itemAt(i); if (item.isValid()) { QString title = item.title(); - if (title.length()>40) { + if (title.length() > 40) { title.truncate(40); - title+=".."; + title += ".."; } QAction* action = m_menuBack->addAction(_iconForUrl(item.url()),title, this, SLOT(goAtHistoryIndex())); action->setData(i); @@ -580,13 +566,13 @@ void QupZilla::aboutToShowHistoryNextMenu() m_menuForward->clear(); QWebHistory* history = weView()->history(); int curindex = history->currentItemIndex(); - for (int i = curindex+1;icount();i++) { + for (int i = curindex+1; i < history->count(); i++) { QWebHistoryItem item = history->itemAt(i); if (item.isValid()) { QString title = item.title(); - if (title.length()>40) { + if (title.length() > 40) { title.truncate(40); - title+=".."; + title += ".."; } QAction* action = m_menuForward->addAction(_iconForUrl(item.url()),title, this, SLOT(goAtHistoryIndex())); action->setData(i); @@ -877,6 +863,12 @@ void QupZilla::loadActionUrl() } } +void QupZilla::loadAddress(const QUrl &url) +{ + weView()->load(url); + locationBar()->setText(url.toEncoded()); +} + void QupZilla::urlEnter() { if (locationBar()->text().isEmpty()) diff --git a/src/app/qupzilla.h b/src/app/qupzilla.h index ed3e7060f..efb8a47bb 100644 --- a/src/app/qupzilla.h +++ b/src/app/qupzilla.h @@ -123,10 +123,10 @@ signals: public slots: void showBookmarksToolbar(); - void refreshHistory(int index=-1); + void refreshHistory(); void loadActionUrl(); void bookmarkPage(); - void loadAddress(QUrl url) { weView()->load(url); locationBar()->setText(url.toEncoded()); } + void loadAddress(const QUrl &url); void showSource(const QString& selectedHtml = ""); void showPageInfo(); void receiveMessage(MainApplication::MessageType mes, bool state); diff --git a/src/webview/webpage.cpp b/src/webview/webpage.cpp index f834d6b79..5f261f483 100644 --- a/src/webview/webpage.cpp +++ b/src/webview/webpage.cpp @@ -38,6 +38,7 @@ WebPage::WebPage(WebView* parent, QupZilla* mainClass) { setForwardUnsupportedContent(true); setPluginFactory(new WebPluginFactory(this)); + history()->setMaximumItemCount(20); connect(this, SIGNAL(unsupportedContent(QNetworkReply*)), SLOT(handleUnsupportedContent(QNetworkReply*))); connect(this, SIGNAL(loadStarted()), this, SLOT(loadingStarted())); connect(this, SIGNAL(loadProgress(int)), this, SLOT(progress(int))); @@ -199,29 +200,7 @@ bool WebPage::extension(Extension extension, const ExtensionOption* option, Exte break; case QNetworkReply::ContentAccessDenied: if (exOption->errorString.startsWith("AdBlockRule")) { - QString rule = exOption->errorString; - rule.remove("AdBlockRule:"); - - QFile file(":/html/adblockPage.html"); - file.open(QFile::ReadOnly); - QString errString = file.readAll(); - errString.replace("%TITLE%", tr("AdBlocked Content")); - - //QPixmap pixmap = QIcon::fromTheme("dialog-warning").pixmap(45,45); - QPixmap pixmap(":/html/adblock_big.png"); - QByteArray bytes; - QBuffer buffer(&bytes); - buffer.open(QIODevice::WriteOnly); - if (pixmap.save(&buffer, "PNG")) { - errString.replace("%IMAGE%", buffer.buffer().toBase64()); - errString.replace("%FAVICON%", buffer.buffer().toBase64()); - } - - errString.replace("%RULE%", tr("Blocked by rule %1").arg(rule)); - - exReturn->baseUrl = exOption->url.toString(); - exReturn->content = errString.toUtf8(); - if (exOption->frame != exOption->frame->page()->mainFrame()) { + if (exOption->frame != exOption->frame->page()->mainFrame()) { //Content in