File indexing completed on 2024-04-28 03:53:56

0001 /*
0002     SPDX-FileCopyrightText: 2010 Grégory Oestreicher <greg@kamago.net>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "etagcache.h"
0008 
0009 #include <QMap>
0010 #include <QSet>
0011 
0012 using namespace KDAV;
0013 
0014 namespace KDAV
0015 {
0016 class EtagCachePrivate
0017 {
0018 public:
0019     QMap<QString, QString> mCache;
0020     QSet<QString> mChangedRemoteIds;
0021 };
0022 }
0023 
0024 EtagCache::EtagCache(QObject *parent)
0025     : QObject(parent)
0026     , d(new EtagCachePrivate)
0027 {
0028 }
0029 
0030 EtagCache::~EtagCache() = default;
0031 
0032 void EtagCache::setEtag(const QString &remoteId, const QString &etag)
0033 {
0034     setEtagInternal(remoteId, etag);
0035 
0036     d->mChangedRemoteIds.remove(remoteId);
0037 }
0038 
0039 void EtagCache::setEtagInternal(const QString &remoteId, const QString &etag)
0040 {
0041     d->mCache[remoteId] = etag;
0042 }
0043 
0044 bool EtagCache::contains(const QString &remoteId) const
0045 {
0046     return d->mCache.contains(remoteId);
0047 }
0048 
0049 bool EtagCache::etagChanged(const QString &remoteId, const QString &refEtag) const
0050 {
0051     if (!contains(remoteId)) {
0052         return true;
0053     }
0054     return d->mCache.value(remoteId) != refEtag;
0055 }
0056 
0057 void EtagCache::markAsChanged(const QString &remoteId)
0058 {
0059     d->mChangedRemoteIds.insert(remoteId);
0060 }
0061 
0062 bool EtagCache::isOutOfDate(const QString &remoteId) const
0063 {
0064     return d->mChangedRemoteIds.contains(remoteId);
0065 }
0066 
0067 void EtagCache::removeEtag(const QString &remoteId)
0068 {
0069     d->mChangedRemoteIds.remove(remoteId);
0070     d->mCache.remove(remoteId);
0071 }
0072 
0073 QMap<QString, QString> EtagCache::etagCacheMap() const
0074 {
0075     return d->mCache;
0076 }
0077 
0078 QStringList EtagCache::urls() const
0079 {
0080     return d->mCache.keys();
0081 }
0082 
0083 QStringList EtagCache::changedRemoteIds() const
0084 {
0085     return d->mChangedRemoteIds.values();
0086 }
0087 
0088 #include "moc_etagcache.cpp"