Save work.

This commit is contained in:
Martin Rotter 2017-07-19 22:18:04 +02:00
parent 07d77d1d24
commit 9fdacb26f9
2 changed files with 34 additions and 32 deletions

View file

@ -180,6 +180,7 @@ void AdBlockIcon::animateIcon() {
} }
if (pixmap()->isNull()) { if (pixmap()->isNull()) {
// TODO: Nastavit ikony.
setPixmap(QIcon(QSL(":icons/other/adblock.png")).pixmap(16)); setPixmap(QIcon(QSL(":icons/other/adblock.png")).pixmap(16));
} }
else { else {
@ -197,6 +198,7 @@ void AdBlockIcon::stopAnimation() {
void AdBlockIcon::setEnabled(bool enabled) { void AdBlockIcon::setEnabled(bool enabled) {
if (enabled) { if (enabled) {
// TODO: Nastavit ikony.
setPixmap(QIcon(QSL(":icons/other/adblock.png")).pixmap(16)); setPixmap(QIcon(QSL(":icons/other/adblock.png")).pixmap(16));
} }
else { else {

View file

@ -140,8 +140,7 @@ void AdBlockSubscription::updateSubscription() {
connect(m_reply, &QNetworkReply::finished, this, &AdBlockSubscription::subscriptionDownloaded); connect(m_reply, &QNetworkReply::finished, this, &AdBlockSubscription::subscriptionDownloaded);
} }
void AdBlockSubscription::subscriptionDownloaded() void AdBlockSubscription::subscriptionDownloaded() {
{
if (m_reply != qobject_cast<QNetworkReply*>(sender())) { if (m_reply != qobject_cast<QNetworkReply*>(sender())) {
return; return;
} }
@ -168,53 +167,54 @@ void AdBlockSubscription::subscriptionDownloaded()
emit subscriptionChanged(); emit subscriptionChanged();
} }
bool AdBlockSubscription::saveDownloadedData(const QByteArray &data) bool AdBlockSubscription::saveDownloadedData(const QByteArray &data) {
{
QSaveFile file(m_filePath); QSaveFile file(m_filePath);
if (!file.open(QFile::WriteOnly)) { 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; return false;
} }
else {
// Write subscription header // Write subscription header
file.write(QString("Title: %1\nUrl: %2\n").arg(title(), url().toString()).toUtf8()); file.write(QString("Title: %1\nUrl: %2\n").arg(title(), url().toString()).toUtf8());
file.write(data); file.write(data);
file.commit(); file.commit();
return true; return true;
} }
const AdBlockRule* AdBlockSubscription::rule(int offset) const
{
if (!QzTools::containsIndex(m_rules, offset)) {
return 0;
} }
const AdBlockRule *AdBlockSubscription::rule(int offset) const {
if (offset >= 0 && offset < m_rules.size()) {
return m_rules[offset]; return m_rules[offset];
} }
else {
return 0;
}
}
QVector<AdBlockRule*> AdBlockSubscription::allRules() const QVector<AdBlockRule*> AdBlockSubscription::allRules() const {
{
return m_rules; return m_rules;
} }
const AdBlockRule* AdBlockSubscription::enableRule(int offset) const AdBlockRule *AdBlockSubscription::enableRule(int offset) {
{ if (offset >= 0 && offset < m_rules.size()) {
if (!QzTools::containsIndex(m_rules, offset)) {
return 0;
}
AdBlockRule *rule = m_rules[offset]; AdBlockRule *rule = m_rules[offset];
rule->setEnabled(true); rule->setEnabled(true);
AdBlockManager::instance()->removeDisabledRule(rule->filter()); AdBlockManager::instance()->removeDisabledRule(rule->filter());
emit subscriptionChanged(); emit subscriptionChanged();
if (rule->isCssRule()) if (rule->isCssRule()) {
mApp->reloadUserStyleSheet(); // TODO: opravdu?
//mApp->reloadUserStyleSheet();
}
return rule; return rule;
} }
else {
return 0;
}
}
const AdBlockRule* AdBlockSubscription::disableRule(int offset) const AdBlockRule* AdBlockSubscription::disableRule(int offset)
{ {