KDAV

etagcache.cpp
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
12using namespace KDAV;
13
14namespace KDAV
15{
16class EtagCachePrivate
17{
18public:
20 QSet<QString> mChangedRemoteIds;
21};
22}
23
25 : QObject(parent)
26 , d(new EtagCachePrivate)
27{
28}
29
30EtagCache::~EtagCache() = default;
31
32void EtagCache::setEtag(const QString &remoteId, const QString &etag)
33{
34 setEtagInternal(remoteId, etag);
35
36 d->mChangedRemoteIds.remove(remoteId);
37}
38
39void EtagCache::setEtagInternal(const QString &remoteId, const QString &etag)
40{
41 d->mCache[remoteId] = etag;
42}
43
44bool EtagCache::contains(const QString &remoteId) const
45{
46 return d->mCache.contains(remoteId);
47}
48
49bool EtagCache::etagChanged(const QString &remoteId, const QString &refEtag) const
50{
51 if (!contains(remoteId)) {
52 return true;
53 }
54 return d->mCache.value(remoteId) != refEtag;
55}
56
57void EtagCache::markAsChanged(const QString &remoteId)
58{
59 d->mChangedRemoteIds.insert(remoteId);
60}
61
62bool EtagCache::isOutOfDate(const QString &remoteId) const
63{
64 return d->mChangedRemoteIds.contains(remoteId);
65}
66
67void EtagCache::removeEtag(const QString &remoteId)
68{
69 d->mChangedRemoteIds.remove(remoteId);
70 d->mCache.remove(remoteId);
71}
72
73QMap<QString, QString> EtagCache::etagCacheMap() const
74{
75 return d->mCache;
76}
77
79{
80 return d->mCache.keys();
81}
82
84{
85 return d->mChangedRemoteIds.values();
86}
87
88#include "moc_etagcache.cpp"
QStringList urls() const
Returns the list of all items URLs.
Definition etagcache.cpp:78
bool etagChanged(const QString &remoteId, const QString &refEtag) const
Check if the known ETag for the remote ID is equal to refEtag.
Definition etagcache.cpp:49
void removeEtag(const QString &remoteId)
Removes the entry for item with remote ID remoteId.
Definition etagcache.cpp:67
void setEtagInternal(const QString &remoteId, const QString &etag)
Sets the ETag for the remote ID.
Definition etagcache.cpp:39
bool contains(const QString &remoteId) const
Checks if the given item is in the cache.
Definition etagcache.cpp:44
bool isOutOfDate(const QString &remoteId) const
Returns true if the remote ID is marked as changed (is contained in the return of changedRemoteIds)
Definition etagcache.cpp:62
EtagCache(QObject *parent=nullptr)
Creates a new ETag cache and populates it with the ETags of items found in collection.
Definition etagcache.cpp:24
void markAsChanged(const QString &remoteId)
Mark an item as changed in the backend.
Definition etagcache.cpp:57
void setEtag(const QString &remoteId, const QString &etag)
Sets the ETag for the remote ID.
Definition etagcache.cpp:32
QStringList changedRemoteIds() const
Returns the list of remote ids of items that have been changed in the backend.
Definition etagcache.cpp:83
The KDAV namespace.
T qobject_cast(QObject *object)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:16:34 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.