mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-11 01:22:10 +01:00
Fixed showing download size at download manager and fixed hiding
adblocked flash objects
This commit is contained in:
parent
5bf7d732a8
commit
db5791c3d2
|
@ -180,22 +180,37 @@ QString DownloadItem::remaingTimeToString(QTime time)
|
||||||
|
|
||||||
QString DownloadItem::currentSpeedToString(double speed)
|
QString DownloadItem::currentSpeedToString(double speed)
|
||||||
{
|
{
|
||||||
speed/=1024; // Conversion to kB/s
|
if (speed < 0)
|
||||||
if (speed>1000) {
|
return tr("Unknown speed");
|
||||||
speed/=1024;
|
|
||||||
return QString::number(speed, 'g', 3)+" MB/s";
|
speed /= 1024; // kB
|
||||||
}else
|
if (speed < 1000)
|
||||||
return QString::number(speed, 'g', 3)+" kB/s";
|
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 < 0)
|
||||||
if (size>1000) {
|
return tr("Unknown size");
|
||||||
size/=1024;
|
|
||||||
return QString::number(size)+" MB";
|
double _size = (double)size;
|
||||||
}else
|
_size /= 1024; //kB
|
||||||
return QString::number(size)+" 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)
|
void DownloadItem::updateDownloadInfo(double currSpeed, qint64 received, qint64 total)
|
||||||
|
|
|
@ -52,7 +52,7 @@ public:
|
||||||
|
|
||||||
static QString remaingTimeToString(QTime time);
|
static QString remaingTimeToString(QTime time);
|
||||||
static QString currentSpeedToString(double speed);
|
static QString currentSpeedToString(double speed);
|
||||||
static QString fileSizeToString(int size);
|
static QString fileSizeToString(qint64 size);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void deleteItem(DownloadItem*);
|
void deleteItem(DownloadItem*);
|
||||||
|
|
|
@ -57,39 +57,8 @@ ClickToFlash::ClickToFlash(const QUrl &pluginUrl, const QStringList &argumentNam
|
||||||
QString urlString = pluginUrl.toEncoded();
|
QString urlString = pluginUrl.toEncoded();
|
||||||
AdBlockSubscription* subscription = manager->subscription();
|
AdBlockSubscription* subscription = manager->subscription();
|
||||||
if (!subscription->allow(urlString) && subscription->block(urlString)) {
|
if (!subscription->allow(urlString) && subscription->block(urlString)) {
|
||||||
QWidget* parent = parentWidget();
|
QTimer::singleShot(200, this, SLOT(hideAdBlocked()));
|
||||||
QWebView* view = 0;
|
|
||||||
while (parent) {
|
|
||||||
if (QWebView* aView = qobject_cast<QWebView*>(parent)) {
|
|
||||||
view = aView;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
parent = parent->parentWidget();
|
|
||||||
}
|
|
||||||
if (!view)
|
|
||||||
return;
|
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();
|
load();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ClickToFlash::hideAdBlocked()
|
||||||
|
{
|
||||||
|
findElement();
|
||||||
|
if (!m_element.isNull()) {
|
||||||
|
m_element.setAttribute("style", "display:none;");
|
||||||
|
deleteLater();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ClickToFlash::findElement()
|
void ClickToFlash::findElement()
|
||||||
{
|
{
|
||||||
QWidget* parent = parentWidget();
|
QWidget* parent = parentWidget();
|
||||||
|
@ -179,7 +157,7 @@ void ClickToFlash::load()
|
||||||
{
|
{
|
||||||
findElement();
|
findElement();
|
||||||
if (m_element.isNull()) {
|
if (m_element.isNull()) {
|
||||||
|
qWarning("Click2Flash: Cannot find Flash object.");
|
||||||
} else {
|
} else {
|
||||||
QWebElement substitute = m_element.clone();
|
QWebElement substitute = m_element.clone();
|
||||||
substitute.setAttribute(QLatin1String("type"), "application/futuresplash");
|
substitute.setAttribute(QLatin1String("type"), "application/futuresplash");
|
||||||
|
|
|
@ -69,6 +69,8 @@ private slots:
|
||||||
void toWhitelist();
|
void toWhitelist();
|
||||||
void findElement();
|
void findElement();
|
||||||
|
|
||||||
|
void hideAdBlocked();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool checkElement(QWebElement el);
|
bool checkElement(QWebElement el);
|
||||||
bool checkUrlOnElement(QWebElement el);
|
bool checkUrlOnElement(QWebElement el);
|
||||||
|
|
|
@ -68,17 +68,6 @@ void WebPage::setSSLCertificate(QSslCertificate cert)
|
||||||
|
|
||||||
QSslCertificate WebPage::sslCertificate()
|
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())))
|
if (m_SslCert.subjectInfo(QSslCertificate::CommonName).remove("*").contains(QRegExp(mainFrame()->url().host())))
|
||||||
return m_SslCert;
|
return m_SslCert;
|
||||||
else
|
else
|
||||||
|
@ -201,6 +190,18 @@ bool WebPage::extension(Extension extension, const ExtensionOption* option, Exte
|
||||||
|
|
||||||
exReturn->baseUrl = exOption->url.toString();
|
exReturn->baseUrl = exOption->url.toString();
|
||||||
exReturn->content = errString.toUtf8();
|
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;
|
return true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user