Пример #1
0
const AdBlockRule* AdBlockSubscription::disableRule(int offset) {
  if (!IS_IN_ARRAY(offset, m_rules)) {
    return 0;
  }

  AdBlockRule* rule = m_rules[offset];

  rule->setEnabled(false);
  AdBlockManager::instance()->addDisabledRule(rule->filter());
  emit subscriptionChanged();

  return rule;
}
Пример #2
0
const AdBlockRule* AdBlockSubscription::enableRule(int offset) {
  if (IS_IN_ARRAY(offset, m_rules)) {
    AdBlockRule* rule = m_rules[offset];

    rule->setEnabled(true);
    AdBlockManager::instance()->removeDisabledRule(rule->filter());
    emit subscriptionChanged();

    return rule;
  }
  else {
    return 0;
  }
}
void AdBlockSubscription::loadSubscription(const QStringList &disabledRules)
{
    QFile file(m_filePath);

    if (!file.exists()) {
        QTimer::singleShot(0, this, SLOT(updateSubscription()));
        return;
    }

    if (!file.open(QFile::ReadOnly)) {
        qWarning() << "AdBlockSubscription::" << __FUNCTION__ << "Unable to open adblock file for reading" << m_filePath;
        QTimer::singleShot(0, this, SLOT(updateSubscription()));
        return;
    }

    QTextStream textStream(&file);
    textStream.setCodec("UTF-8");
    // Header is on 3rd line
    textStream.readLine(1024);
    textStream.readLine(1024);
    QString header = textStream.readLine(1024);

    if (!header.startsWith(QLatin1String("[Adblock")) || m_title.isEmpty()) {
        qWarning() << "AdBlockSubscription::" << __FUNCTION__ << "invalid format of adblock file" << m_filePath;
        QTimer::singleShot(0, this, SLOT(updateSubscription()));
        return;
    }

    m_rules.clear();

    while (!textStream.atEnd()) {
        AdBlockRule* rule = new AdBlockRule(textStream.readLine(), this);

        if (disabledRules.contains(rule->filter())) {
            rule->setEnabled(false);
        }

        m_rules.append(rule);
    }

    populateCache();

    // Initial update
    if (m_rules.isEmpty() && !m_updated) {
        QTimer::singleShot(0, this, SLOT(updateSubscription()));
    }
}
const AdBlockRule* AdBlockSubscription::disableRule(int offset)
{
    if (!QzTools::vectorContainsIndex(m_rules, offset)) {
        return 0;
    }

    AdBlockRule* rule = m_rules[offset];
    rule->setEnabled(false);
    AdBlockManager::instance()->addDisabledRule(rule->filter());

    if (rule->isCssRule()) {
        populateCache();
        mApp->reloadUserStyleSheet();
    }

    return rule;
}
Пример #5
0
const AdBlockRule* AdBlockSubscription::enableRule(int offset)
{
    if (!QzTools::containsIndex(m_rules, offset)) {
        return 0;
    }

    AdBlockRule* rule = m_rules[offset];
    rule->setEnabled(true);
    AdBlockManager::instance()->removeDisabledRule(rule->filter());

    emit subscriptionChanged();

    if (rule->isCssRule())
        mApp->reloadUserStyleSheet();

    return rule;
}