Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
icefox authored and gzsombor committed Sep 12, 2009
1 parent c89487c commit b8c451f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 25 deletions.
45 changes: 20 additions & 25 deletions src/adblock/networkaccesspolicy.cpp
Expand Up @@ -118,39 +118,34 @@ bool NetworkAccessPolicy::importAdBlockRules(QIODevice &importFrom, QList<AdBlo
return NetworkAccessPolicy::importAdBlockRules(txt, rules);
}

bool NetworkAccessPolicy::importAdBlockRules(QTextStream &txt, QList<AdBlockRule*> &rules)
bool NetworkAccessPolicy::importAdBlockRules(QTextStream &textStream, QList<AdBlockRule*> &rules)
{
QString header = txt.readLine(1024);
if (!header.startsWith(QLatin1String("[Adblock"))) {
QString header = textStream.readLine(1024);
if (!header.startsWith(QLatin1String("[Adblock")))
return false;
}
QString line;

rules.clear();
do {
line = txt.readLine();
AdBlockRule *rule = new AdBlockRule(line);
if (rule) {
#if defined(NETWORKACCESS_DEBUG)
qDebug() << rule->toString();
#endif
rules.append(rule);
}
} while (!txt.atEnd());
while (!textStream.atEnd()) {
QString filter = textStream.readLine();
AdBlockRule *rule = new AdBlockRule(filter);
rules.append(rule);
}

return true;
}

void NetworkAccessPolicy::exportSettings(QList<AdBlockRule*> &rules, QFile &fileToExport)
void NetworkAccessPolicy::exportSettings(QList<AdBlockRule*> &rules, QFile &file)
{
Q_UNUSED(rules)
if (!fileToExport.open(QIODevice::WriteOnly)) {
#if defined(NETWORKACCESS_DEBUG)
qDebug() << QLatin1String("Unable to open : ") << fileToExport.fileName();
#endif
if (!file.open(QIODevice::WriteOnly)) {
qWarning() << QLatin1String("Unable to open file for writing: ") << file.fileName();
return;
}
QTextStream txt(&fileToExport);
txt << "[Adblock Plus 0.7.1]";

QTextStream textStream(&file);
textStream << "[Adblock Plus 0.7.1]";
foreach (const AdBlockRule *rule, rules)
textStream << rule->toString() << endl;
}


Expand All @@ -162,7 +157,7 @@ const QList<AdBlockRule*> *NetworkAccessPolicy::accessRules() const
void NetworkAccessPolicy::setAccessRules(QList<AdBlockRule*> &newRules)
{
#if defined(NETWORKACCESS_DEBUG)
qDebug() << "NetworkAccessPolicy::" << __FUNCTION__ << newRules.size();
qDebug() << "NetworkAccessPolicy::" << __FUNCTION__ << newRules.size();
#endif
m_rules->clear();
m_rules->append(newRules);
Expand All @@ -174,10 +169,10 @@ void NetworkAccessPolicy::setAccessRules(QList<AdBlockRule*> &newRules)
void NetworkAccessPolicy::setAccessRules(AdBlockSubscription *subscription, QList<AdBlockRule*> &newRules)
{
#if defined(NETWORKACCESS_DEBUG)
qDebug() << "setAccessRules for : " << subscription->name() << " len : " << newRules.size();
qDebug() << "setAccessRules for : " << subscription->name() << " len : " << newRules.size();
#endif

for (int i= m_rules->size() - 1; i >= 0; --i) {
for (int i = m_rules->size() - 1; i >= 0; --i) {
AdBlockRule *rule = m_rules->at(i);
if (rule->subscription() == subscription)
m_rules->removeAt(i);
Expand Down
1 change: 1 addition & 0 deletions src/adblock/networkaccesspolicy.h
Expand Up @@ -79,3 +79,4 @@ public slots:
};

#endif // NETWORKACCESSPOLICY_H

0 comments on commit b8c451f

Please sign in to comment.