1 | /* |
2 | This file is part of kabc. |
3 | Copyright (c) 2004 Tobias Koenig <tokoe@kde.org> |
4 | |
5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. |
9 | |
10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. |
14 | |
15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
18 | Boston, MA 02110-1301, USA. |
19 | */ |
20 | |
21 | #ifndef KABC_RESOURCECACHED_H |
22 | #define KABC_RESOURCECACHED_H |
23 | |
24 | #include <kabc/kabc_export.h> |
25 | #include <kabc/resource.h> |
26 | |
27 | #include <kresources/idmapper.h> |
28 | |
29 | namespace KABC { |
30 | |
31 | class KABC_DEPRECATED_EXPORT ResourceCached : public Resource |
32 | { |
33 | Q_OBJECT |
34 | |
35 | public: |
36 | ResourceCached(); |
37 | ResourceCached( const KConfigGroup &group ); |
38 | ~ResourceCached(); |
39 | |
40 | /** |
41 | Writes the resource specific config to file. |
42 | |
43 | @param group The config section to write into |
44 | */ |
45 | virtual void writeConfig( KConfigGroup &group ); |
46 | |
47 | /** |
48 | Insert an addressee into the resource. |
49 | |
50 | @param addr The addressee to add |
51 | */ |
52 | virtual void insertAddressee( const Addressee &addr ); |
53 | |
54 | /** |
55 | Removes an addressee from resource. |
56 | |
57 | @param addr The addressee to remove |
58 | */ |
59 | virtual void removeAddressee( const Addressee &addr ); |
60 | |
61 | /** |
62 | Loads the change cache from a file. |
63 | |
64 | @return @c false if the file cannot be opened for reading, |
65 | otherwise @c true |
66 | |
67 | @see cacheFile() |
68 | */ |
69 | bool loadFromCache(); |
70 | |
71 | /** |
72 | Saves the change cache to a file. |
73 | |
74 | @see cacheFile() |
75 | */ |
76 | void saveToCache(); |
77 | |
78 | /** |
79 | Removes all entries from the cache that are not available in @p list |
80 | |
81 | @param list The list of addressees to keep in the cache if cached |
82 | */ |
83 | void cleanUpCache( const KABC::Addressee::List &list ); |
84 | |
85 | /** |
86 | Returns a reference to the id mapper. |
87 | */ |
88 | KRES::IdMapper &idMapper(); |
89 | |
90 | /** |
91 | Returns whether there are any changes cached. |
92 | */ |
93 | bool hasChanges() const; |
94 | |
95 | /** |
96 | Clears all cached changes. |
97 | */ |
98 | void clearChanges(); |
99 | |
100 | /** |
101 | Clears the change caches for a given addressee |
102 | |
103 | Removes the identifier addressee from all three "type" caches. |
104 | |
105 | @param addr The addressee to remove from the caches |
106 | */ |
107 | void clearChange( const KABC::Addressee &addr ); |
108 | |
109 | /** |
110 | Clears the change caches for a given @p uid |
111 | |
112 | Removes the identifier addressee from all three "type" caches. |
113 | |
114 | @param uid The unique identifier of an addressee to remove from the |
115 | caches. See KABC::Addressee::uid() |
116 | */ |
117 | void clearChange( const QString &uid ); |
118 | |
119 | /** |
120 | Returns a list of the @c "added" addressees |
121 | */ |
122 | KABC::Addressee::List addedAddressees() const; |
123 | |
124 | /** |
125 | Returns a list of the @c "changed" addressees |
126 | */ |
127 | KABC::Addressee::List changedAddressees() const; |
128 | |
129 | /** |
130 | Returns a list of the @c "deleted" addressees |
131 | */ |
132 | KABC::Addressee::List deletedAddressees() const; |
133 | |
134 | protected: |
135 | /** |
136 | Returns the file path of the cache file. |
137 | |
138 | Cache file contents will be in vCard format, see |
139 | KABC::VCardConverter::parseVCards() and |
140 | KABC::VCardConverter::createVCards() |
141 | |
142 | @see loadFromCache() |
143 | @see saveFromCache() |
144 | */ |
145 | virtual QString cacheFile() const; |
146 | |
147 | /** |
148 | Determines the file path for saving caches of a given @p type. |
149 | |
150 | Will be used by loadChangesCache and saveChangesCache(). |
151 | |
152 | @param type The type of change, i.e. @c "added", @c "delete" |
153 | or @c "changed" |
154 | */ |
155 | virtual QString changesCacheFile( const QString &type ) const; |
156 | |
157 | /** |
158 | Loads change caches (added, deleted, changed addressees) from |
159 | respective cache files. |
160 | |
161 | Subclasses can override the filename for each type by re-implementing |
162 | changesCacheFile(). |
163 | |
164 | File contents are expected to be in vCard format. |
165 | See KABC::VCardConverter::parseVCards() |
166 | */ |
167 | void loadChangesCache(); |
168 | |
169 | /** |
170 | Saves cached changes (added, deleted, changed addressees) to |
171 | respective cache files. |
172 | |
173 | Subclasses can override the filename for each type by re-implementing |
174 | changesCacheFile(). |
175 | |
176 | File contents will be in vCard format. |
177 | See KABC::VCardConverter::createVCards() |
178 | */ |
179 | void saveChangesCache(); |
180 | |
181 | /** |
182 | Sets the identifier of the instances IdMapper. |
183 | |
184 | @see idMapper() |
185 | @see IdMapper::setIdentifier() |
186 | */ |
187 | void setIdMapperIdentifier(); |
188 | |
189 | private: |
190 | class Private; |
191 | Private *const d; |
192 | }; |
193 | |
194 | } |
195 | |
196 | #endif |
197 | |