File indexing completed on 2024-11-10 04:40:37

0001 /*
0002     SPDX-FileCopyrightText: 2008 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "cachepolicy.h"
0008 #include <QDebug>
0009 
0010 using namespace Akonadi;
0011 
0012 /**
0013  * @internal
0014  */
0015 class Akonadi::CachePolicyPrivate : public QSharedData
0016 {
0017 public:
0018     QStringList localParts;
0019     int timeout = -1;
0020     int interval = -1;
0021     bool inherit = true;
0022     bool syncOnDemand = false;
0023 };
0024 
0025 CachePolicy::CachePolicy()
0026 {
0027     static QSharedDataPointer<CachePolicyPrivate> sharedPrivate(new CachePolicyPrivate);
0028     d = sharedPrivate;
0029 }
0030 
0031 CachePolicy::CachePolicy(const CachePolicy &other)
0032     : d(other.d)
0033 {
0034 }
0035 
0036 CachePolicy::~CachePolicy()
0037 {
0038 }
0039 
0040 CachePolicy &CachePolicy::operator=(const CachePolicy &other)
0041 {
0042     d = other.d;
0043     return *this;
0044 }
0045 
0046 bool Akonadi::CachePolicy::operator==(const CachePolicy &other) const
0047 {
0048     if (!d->inherit && !other.d->inherit) {
0049         return d->localParts == other.d->localParts && d->timeout == other.d->timeout && d->interval == other.d->interval
0050             && d->syncOnDemand == other.d->syncOnDemand;
0051     }
0052     return d->inherit == other.d->inherit;
0053 }
0054 
0055 bool CachePolicy::inheritFromParent() const
0056 {
0057     return d->inherit;
0058 }
0059 
0060 void CachePolicy::setInheritFromParent(bool inherit)
0061 {
0062     d->inherit = inherit;
0063 }
0064 
0065 QStringList CachePolicy::localParts() const
0066 {
0067     return d->localParts;
0068 }
0069 
0070 void CachePolicy::setLocalParts(const QStringList &parts)
0071 {
0072     d->localParts = parts;
0073 }
0074 
0075 int CachePolicy::cacheTimeout() const
0076 {
0077     return d->timeout;
0078 }
0079 
0080 void CachePolicy::setCacheTimeout(int timeout)
0081 {
0082     d->timeout = timeout;
0083 }
0084 
0085 int CachePolicy::intervalCheckTime() const
0086 {
0087     return d->interval;
0088 }
0089 
0090 void CachePolicy::setIntervalCheckTime(int time)
0091 {
0092     d->interval = time;
0093 }
0094 
0095 bool CachePolicy::syncOnDemand() const
0096 {
0097     return d->syncOnDemand;
0098 }
0099 
0100 void CachePolicy::setSyncOnDemand(bool enable)
0101 {
0102     d->syncOnDemand = enable;
0103 }
0104 
0105 QDebug operator<<(QDebug d, const CachePolicy &c)
0106 {
0107     return d << "CachePolicy: \n"
0108              << "   inherit:" << c.inheritFromParent() << '\n'
0109              << "   interval:" << c.intervalCheckTime() << '\n'
0110              << "   timeout:" << c.cacheTimeout() << '\n'
0111              << "   sync on demand:" << c.syncOnDemand() << '\n'
0112              << "   local parts:" << c.localParts();
0113 }