1/*
2 Copyright (c) 2008 Volker Krause <vkrause@kde.org>
3
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
8
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
18*/
19
20#include "cachepolicy.h"
21#include "collection.h"
22
23using namespace Akonadi;
24
25/**
26 * @internal
27 */
28class CachePolicy::Private : public QSharedData
29{
30public:
31 Private()
32 : QSharedData()
33 , inherit(true)
34 , timeout(-1)
35 , interval(-1)
36 , syncOnDemand(false)
37 {}
38
39 Private(const Private &other)
40 : QSharedData(other)
41 {
42 inherit = other.inherit;
43 localParts = other.localParts;
44 timeout = other.timeout;
45 interval = other.interval;
46 syncOnDemand = other.syncOnDemand;
47 }
48
49 bool inherit;
50 QStringList localParts;
51 int timeout;
52 int interval;
53 bool syncOnDemand;
54};
55
56CachePolicy::CachePolicy()
57 : d(new Private)
58{
59}
60
61CachePolicy::CachePolicy(const CachePolicy &other)
62 : d(other.d)
63{
64}
65
66CachePolicy::~ CachePolicy()
67{
68}
69
70CachePolicy &CachePolicy::operator =(const CachePolicy &other)
71{
72 d = other.d;
73 return *this;
74}
75
76bool Akonadi::CachePolicy::operator ==(const CachePolicy &other) const
77{
78 if (!d->inherit && !other.d->inherit) {
79 return d->localParts == other.d->localParts
80 && d->timeout == other.d->timeout
81 && d->interval == other.d->interval
82 && d->syncOnDemand == other.d->syncOnDemand;
83 }
84 return d->inherit == other.d->inherit;
85}
86
87bool CachePolicy::inheritFromParent() const
88{
89 return d->inherit;
90}
91
92void CachePolicy::setInheritFromParent(bool inherit)
93{
94 d->inherit = inherit;
95}
96
97QStringList CachePolicy::localParts() const
98{
99 return d->localParts;
100}
101
102void CachePolicy::setLocalParts(const QStringList &parts)
103{
104 d->localParts = parts;
105}
106
107int CachePolicy::cacheTimeout() const
108{
109 return d->timeout;
110}
111
112void CachePolicy::setCacheTimeout(int timeout)
113{
114 d->timeout = timeout;
115}
116
117int CachePolicy::intervalCheckTime() const
118{
119 return d->interval;
120}
121
122void CachePolicy::setIntervalCheckTime(int time)
123{
124 d->interval = time;
125}
126
127bool CachePolicy::syncOnDemand() const
128{
129 return d->syncOnDemand;
130}
131
132void CachePolicy::setSyncOnDemand(bool enable)
133{
134 d->syncOnDemand = enable;
135}
136
137QDebug operator<<(QDebug d, const CachePolicy &c)
138{
139 return d << "CachePolicy: " << endl
140 << " inherit:" << c.inheritFromParent() << endl
141 << " interval:" << c.intervalCheckTime() << endl
142 << " timeout:" << c.cacheTimeout() << endl
143 << " sync on demand:" << c.syncOnDemand() << endl
144 << " local parts:" << c.localParts();
145}
146