diff --git a/src/downloads/downloaditem.cpp b/src/downloads/downloaditem.cpp index ec79f5f18..7a4dd3737 100644 --- a/src/downloads/downloaditem.cpp +++ b/src/downloads/downloaditem.cpp @@ -180,22 +180,37 @@ QString DownloadItem::remaingTimeToString(QTime time) QString DownloadItem::currentSpeedToString(double speed) { - speed/=1024; // Conversion to kB/s - if (speed>1000) { - speed/=1024; - return QString::number(speed, 'g', 3)+" MB/s"; - }else - return QString::number(speed, 'g', 3)+" kB/s"; + if (speed < 0) + return tr("Unknown speed"); + + speed /= 1024; // kB + if (speed < 1000) + return QString::number(speed, 'f', 0)+" kB/s"; + + speed /= 1024; //MB + if (speed < 1000) + return QString::number(speed, 'f', 2)+" MB/s"; + + speed /= 1024; //GB + return QString::number(speed, 'f', 2)+" GB/s"; } -QString DownloadItem::fileSizeToString(int size) +QString DownloadItem::fileSizeToString(qint64 size) { - size/=1024; - if (size>1000) { - size/=1024; - return QString::number(size)+" MB"; - }else - return QString::number(size)+" kB"; + if (size < 0) + return tr("Unknown size"); + + double _size = (double)size; + _size /= 1024; //kB + if (_size < 1000) + return QString::number(_size, 'f', 0)+" kB"; + + _size /= 1024; //MB + if (_size < 1000) + return QString::number(_size, 'f', 1)+" MB"; + + _size /= 1024; //GB + return QString::number(_size, 'f', 2)+" GB"; } void DownloadItem::updateDownloadInfo(double currSpeed, qint64 received, qint64 total) diff --git a/src/downloads/downloaditem.h b/src/downloads/downloaditem.h index 0492f24b2..5d186988f 100644 --- a/src/downloads/downloaditem.h +++ b/src/downloads/downloaditem.h @@ -52,7 +52,7 @@ public: static QString remaingTimeToString(QTime time); static QString currentSpeedToString(double speed); - static QString fileSizeToString(int size); + static QString fileSizeToString(qint64 size); signals: void deleteItem(DownloadItem*); diff --git a/src/plugins/clicktoflash.cpp b/src/plugins/clicktoflash.cpp index dbe6c4756..6bfaaeabe 100644 --- a/src/plugins/clicktoflash.cpp +++ b/src/plugins/clicktoflash.cpp @@ -57,39 +57,8 @@ ClickToFlash::ClickToFlash(const QUrl &pluginUrl, const QStringList &argumentNam QString urlString = pluginUrl.toEncoded(); AdBlockSubscription* subscription = manager->subscription(); if (!subscription->allow(urlString) && subscription->block(urlString)) { - QWidget* parent = parentWidget(); - QWebView* view = 0; - while (parent) { - if (QWebView* aView = qobject_cast(parent)) { - view = aView; - break; - } - parent = parent->parentWidget(); - } - if (!view) - return; - - const QString selector = "%1[type=\"application/x-shockwave-flash\"]"; - - QList frames; - frames.append(view->page()->mainFrame()); - while (!frames.isEmpty()) { - QWebFrame* frame = frames.takeFirst(); - QWebElement docElement = frame->documentElement(); - - QWebElementCollection elements; - elements.append(docElement.findAll(selector.arg("object"))); - elements.append(docElement.findAll(selector.arg("embed"))); - - foreach(QWebElement element, elements) { - if (checkElement(element)) { - element.setAttribute("style", "visible:none;"); - deleteLater(); - return; - } - } - frames += frame->childFrames(); - } + QTimer::singleShot(200, this, SLOT(hideAdBlocked())); + return; } } @@ -138,6 +107,15 @@ void ClickToFlash::toWhitelist() load(); } +void ClickToFlash::hideAdBlocked() +{ + findElement(); + if (!m_element.isNull()) { + m_element.setAttribute("style", "display:none;"); + deleteLater(); + } +} + void ClickToFlash::findElement() { QWidget* parent = parentWidget(); @@ -179,7 +157,7 @@ void ClickToFlash::load() { findElement(); if (m_element.isNull()) { - + qWarning("Click2Flash: Cannot find Flash object."); } else { QWebElement substitute = m_element.clone(); substitute.setAttribute(QLatin1String("type"), "application/futuresplash"); diff --git a/src/plugins/clicktoflash.h b/src/plugins/clicktoflash.h index ae146c3e8..70a6a4b3c 100644 --- a/src/plugins/clicktoflash.h +++ b/src/plugins/clicktoflash.h @@ -69,6 +69,8 @@ private slots: void toWhitelist(); void findElement(); + void hideAdBlocked(); + private: bool checkElement(QWebElement el); bool checkUrlOnElement(QWebElement el); diff --git a/src/webview/webpage.cpp b/src/webview/webpage.cpp index fa5ed90e3..f688867f6 100644 --- a/src/webview/webpage.cpp +++ b/src/webview/webpage.cpp @@ -68,17 +68,6 @@ void WebPage::setSSLCertificate(QSslCertificate cert) QSslCertificate WebPage::sslCertificate() { -// QSslCertificate cert; -// foreach (QSslCertificate c, m_SslCerts) { -// if (c.subjectInfo(QSslCertificate::CommonName).remove("*").contains(QRegExp(mainFrame()->url().host()))) -// return c; -// } -// return cert; -// if (mainFrame()->url().scheme() == "https" && !mainFrame()->title().contains(tr("Failed loading page"))) -// return m_SslCert; -// else -// return QSslCertificate(); - if (m_SslCert.subjectInfo(QSslCertificate::CommonName).remove("*").contains(QRegExp(mainFrame()->url().host()))) return m_SslCert; else @@ -201,6 +190,18 @@ bool WebPage::extension(Extension extension, const ExtensionOption* option, Exte exReturn->baseUrl = exOption->url.toString(); exReturn->content = errString.toUtf8(); + if (exOption->frame != exOption->frame->page()->mainFrame()) { + QWebElement docElement = exOption->frame->page()->mainFrame()->documentElement(); + + QWebElementCollection elements; + elements.append(docElement.findAll("iframe")); + foreach (QWebElement element, elements) { + QString src = element.attribute("src"); + if (exOption->url.toString().contains(src)) + element.setAttribute("style", "display:none;"); + } + } + return true; break; }