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()) {
// 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 {

View File

@ -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<QNetworkReply*>(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<AdBlockRule*> AdBlockSubscription::allRules() const
{
QVector<AdBlockRule*> 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)