diff options
Diffstat (limited to 'staging/adblock/filterlist.cpp')
-rw-r--r-- | staging/adblock/filterlist.cpp | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/staging/adblock/filterlist.cpp b/staging/adblock/filterlist.cpp index be2bd4e..9fb53ad 100644 --- a/staging/adblock/filterlist.cpp +++ b/staging/adblock/filterlist.cpp @@ -14,19 +14,18 @@ /** * Documentation: * - * https://help.eyeo.com/en/adblockplus/how-to-write-filters + * https://adblockplus.org/filter-cheatsheet + * https://help.eyeo.com/adblockplus/how-to-write-filters * * https://github.com/gorhill/uBlock/wiki/Introduction-to-basic-filtering-syntax * https://github.com/gorhill/uBlock/wiki/Static-filter-syntax * */ -using namespace AdblockPlus; +const QLatin1String comment_lastModified("! Last modified: "); +const QLatin1String comment_expires("! Expires: "); -FilterList::FilterList(QObject *parent) - : QObject(parent) -{ -} +using namespace AdblockPlus; FilterList::~FilterList() { @@ -77,7 +76,18 @@ FilterList::ParseResult FilterList::parse(QTextStream &stream) void FilterList::parseComment(QString &line) { - m_comments.append(line); + if(line.startsWith(comment_lastModified)) { + lastModified = QDateTime::fromString(line.mid(comment_lastModified.size()), "dd MMM yyyy HH:mm 'UTC'"); + expires = lastModified; + + } else if(line.startsWith(comment_expires)) { + const QRegularExpression time_re("(?:(\\d+) days)|(?:(\\d+) hours)"); + const auto match = time_re.match(line); + if(match.hasMatch()) { + expires = expires.addDays(match.captured(1).toInt()); + expires = expires.addSecs(match.captured(2).toInt() * 60 * 60); + } + } } bool FilterList::parseRule(const QString &line) @@ -135,3 +145,13 @@ bool FilterList::parseRule(const QString &line) return true; } + +void FilterList::filter(QWebEngineUrlRequestInfo &info) const +{ +} + +bool FilterList::isUpToDate() const +{ + const auto current = QDateTime::currentDateTime(); + return expires > current; +} |