| 1 | /* |
|---|---|
| 2 | SPDX-FileCopyrightText: 2010 Grégory Oestreicher <greg@kamago.net> |
| 3 | |
| 4 | SPDX-License-Identifier: LGPL-2.0-or-later |
| 5 | */ |
| 6 | |
| 7 | #include "etagcache.h" |
| 8 | |
| 9 | #include <QMap> |
| 10 | #include <QSet> |
| 11 | |
| 12 | using namespace KDAV; |
| 13 | |
| 14 | namespace KDAV |
| 15 | { |
| 16 | class EtagCachePrivate |
| 17 | { |
| 18 | public: |
| 19 | QMap<QString, QString> mCache; |
| 20 | QSet<QString> mChangedRemoteIds; |
| 21 | }; |
| 22 | } |
| 23 | |
| 24 | EtagCache::EtagCache(QObject *parent) |
| 25 | : QObject(parent) |
| 26 | , d(new EtagCachePrivate) |
| 27 | { |
| 28 | } |
| 29 | |
| 30 | EtagCache::~EtagCache() = default; |
| 31 | |
| 32 | void EtagCache::setEtag(const QString &remoteId, const QString &etag) |
| 33 | { |
| 34 | setEtagInternal(remoteId, etag); |
| 35 | |
| 36 | d->mChangedRemoteIds.remove(value: remoteId); |
| 37 | } |
| 38 | |
| 39 | void EtagCache::setEtagInternal(const QString &remoteId, const QString &etag) |
| 40 | { |
| 41 | d->mCache[remoteId] = etag; |
| 42 | } |
| 43 | |
| 44 | bool EtagCache::contains(const QString &remoteId) const |
| 45 | { |
| 46 | return d->mCache.contains(key: remoteId); |
| 47 | } |
| 48 | |
| 49 | bool EtagCache::etagChanged(const QString &remoteId, const QString &refEtag) const |
| 50 | { |
| 51 | if (!contains(remoteId)) { |
| 52 | return true; |
| 53 | } |
| 54 | return d->mCache.value(key: remoteId) != refEtag; |
| 55 | } |
| 56 | |
| 57 | void EtagCache::markAsChanged(const QString &remoteId) |
| 58 | { |
| 59 | d->mChangedRemoteIds.insert(value: remoteId); |
| 60 | } |
| 61 | |
| 62 | bool EtagCache::isOutOfDate(const QString &remoteId) const |
| 63 | { |
| 64 | return d->mChangedRemoteIds.contains(value: remoteId); |
| 65 | } |
| 66 | |
| 67 | void EtagCache::removeEtag(const QString &remoteId) |
| 68 | { |
| 69 | d->mChangedRemoteIds.remove(value: remoteId); |
| 70 | d->mCache.remove(key: remoteId); |
| 71 | } |
| 72 | |
| 73 | QMap<QString, QString> EtagCache::etagCacheMap() const |
| 74 | { |
| 75 | return d->mCache; |
| 76 | } |
| 77 | |
| 78 | QStringList EtagCache::urls() const |
| 79 | { |
| 80 | return d->mCache.keys(); |
| 81 | } |
| 82 | |
| 83 | QStringList EtagCache::changedRemoteIds() const |
| 84 | { |
| 85 | return d->mChangedRemoteIds.values(); |
| 86 | } |
| 87 | |
| 88 | #include "moc_etagcache.cpp" |
| 89 |
