From 9fdacb26f9642b5963f4001c452078a2fc7b8daf Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Wed, 19 Jul 2017 22:18:04 +0200 Subject: [PATCH] Save work. --- src/network-web/adblock/adblockicon.cpp | 2 + .../adblock/adblocksubscription.cpp | 64 +++++++++---------- 2 files changed, 34 insertions(+), 32 deletions(-) diff --git a/src/network-web/adblock/adblockicon.cpp b/src/network-web/adblock/adblockicon.cpp index bc3b61094..75137492a 100755 --- a/src/network-web/adblock/adblockicon.cpp +++ b/src/network-web/adblock/adblockicon.cpp @@ -180,6 +180,7 @@ void AdBlockIcon::animateIcon() { } if (pixmap()->isNull()) { + // TODO: Nastavit ikony. setPixmap(QIcon(QSL(":icons/other/adblock.png")).pixmap(16)); } else { @@ -197,6 +198,7 @@ void AdBlockIcon::stopAnimation() { void AdBlockIcon::setEnabled(bool enabled) { if (enabled) { + // TODO: Nastavit ikony. setPixmap(QIcon(QSL(":icons/other/adblock.png")).pixmap(16)); } else { diff --git a/src/network-web/adblock/adblocksubscription.cpp b/src/network-web/adblock/adblocksubscription.cpp index 2466f67be..5fce6d84e 100755 --- a/src/network-web/adblock/adblocksubscription.cpp +++ b/src/network-web/adblock/adblocksubscription.cpp @@ -140,8 +140,7 @@ void AdBlockSubscription::updateSubscription() { connect(m_reply, &QNetworkReply::finished, this, &AdBlockSubscription::subscriptionDownloaded); } -void AdBlockSubscription::subscriptionDownloaded() -{ +void AdBlockSubscription::subscriptionDownloaded() { if (m_reply != qobject_cast(sender())) { return; } @@ -168,52 +167,53 @@ void AdBlockSubscription::subscriptionDownloaded() emit subscriptionChanged(); } -bool AdBlockSubscription::saveDownloadedData(const QByteArray &data) -{ +bool AdBlockSubscription::saveDownloadedData(const QByteArray &data) { QSaveFile file(m_filePath); if (!file.open(QFile::WriteOnly)) { - qWarning() << "AdBlockSubscription::" << __FUNCTION__ << "Unable to open adblock file for writing:" << m_filePath; + qWarning("Unable to open AdBlock file '%s' for writing.", qPrintable(m_filePath)); return false; } - - // Write subscription header - file.write(QString("Title: %1\nUrl: %2\n").arg(title(), url().toString()).toUtf8()); - file.write(data); - file.commit(); - return true; + else { + // Write subscription header + file.write(QString("Title: %1\nUrl: %2\n").arg(title(), url().toString()).toUtf8()); + file.write(data); + file.commit(); + return true; + } } -const AdBlockRule* AdBlockSubscription::rule(int offset) const -{ - if (!QzTools::containsIndex(m_rules, offset)) { +const AdBlockRule *AdBlockSubscription::rule(int offset) const { + if (offset >= 0 && offset < m_rules.size()) { + return m_rules[offset]; + } + else { return 0; } - - return m_rules[offset]; } -QVector AdBlockSubscription::allRules() const -{ +QVector AdBlockSubscription::allRules() const { return m_rules; } -const AdBlockRule* AdBlockSubscription::enableRule(int offset) -{ - if (!QzTools::containsIndex(m_rules, offset)) { +const AdBlockRule *AdBlockSubscription::enableRule(int offset) { + if (offset >= 0 && offset < m_rules.size()) { + AdBlockRule *rule = m_rules[offset]; + rule->setEnabled(true); + AdBlockManager::instance()->removeDisabledRule(rule->filter()); + + emit subscriptionChanged(); + + if (rule->isCssRule()) { + // TODO: opravdu? + //mApp->reloadUserStyleSheet(); + } + + return rule; + } + else { return 0; } - - AdBlockRule* rule = m_rules[offset]; - rule->setEnabled(true); - AdBlockManager::instance()->removeDisabledRule(rule->filter()); - - emit subscriptionChanged(); - - if (rule->isCssRule()) - mApp->reloadUserStyleSheet(); - - return rule; } const AdBlockRule* AdBlockSubscription::disableRule(int offset)