1
mirror of https://invent.kde.org/network/falkon.git synced 2024-09-21 17:52:10 +02:00

Fixed showing download size at download manager and fixed hiding

adblocked flash objects
This commit is contained in:
nowrep 2011-04-21 13:28:07 +02:00
parent 5bf7d732a8
commit db5791c3d2
5 changed files with 55 additions and 59 deletions

View File

@ -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)

View File

@ -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*);

View File

@ -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<QWebView*>(parent)) {
view = aView;
break;
}
parent = parent->parentWidget();
}
if (!view)
QTimer::singleShot(200, this, SLOT(hideAdBlocked()));
return;
const QString selector = "%1[type=\"application/x-shockwave-flash\"]";
QList<QWebFrame*> 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();
}
}
}
@ -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");

View File

@ -69,6 +69,8 @@ private slots:
void toWhitelist();
void findElement();
void hideAdBlocked();
private:
bool checkElement(QWebElement el);
bool checkUrlOnElement(QWebElement el);

View File

@ -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;
}