summaryrefslogtreecommitdiffabout
path: root/kabc/addressbook.h
Unidiff
Diffstat (limited to 'kabc/addressbook.h') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressbook.h337
1 files changed, 337 insertions, 0 deletions
diff --git a/kabc/addressbook.h b/kabc/addressbook.h
new file mode 100644
index 0000000..3383fc0
--- a/dev/null
+++ b/kabc/addressbook.h
@@ -0,0 +1,337 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@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., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/*
22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk
24
25$Id$
26*/
27
28#ifndef KABC_ADDRESSBOOK_H
29#define KABC_ADDRESSBOOK_H
30
31#include <qobject.h>
32
33#include <kresources/manager.h>
34#include <qptrlist.h>
35
36#ifndef KAB_EMBEDDED
37
38#else //KAB_EMBEDDED
39#endif //KAB_EMBEDDED
40
41
42#include "addressee.h"
43#include "field.h"
44
45namespace KABC {
46
47class ErrorHandler;
48class Resource;
49class Ticket;
50
51/**
52 @short Address Book
53
54 This class provides access to a collection of address book entries.
55*/
56class AddressBook : public QObject
57{
58 Q_OBJECT
59
60 friend QDataStream &operator<<( QDataStream &, const AddressBook & );
61 friend QDataStream &operator>>( QDataStream &, AddressBook & );
62 friend class StdAddressBook;
63
64 public:
65 /**
66 @short Address Book Iterator
67
68 This class provides an iterator for address book entries.
69 */
70 class Iterator
71 {
72 public:
73 Iterator();
74 Iterator( const Iterator & );
75 ~Iterator();
76
77 Iterator &operator=( const Iterator & );
78 const Addressee &operator*() const;
79 Addressee &operator*();
80 Addressee* operator->();
81 Iterator &operator++();
82 Iterator &operator++(int);
83 Iterator &operator--();
84 Iterator &operator--(int);
85 bool operator==( const Iterator &it );
86 bool operator!=( const Iterator &it );
87
88 struct IteratorData;
89 IteratorData *d;
90 };
91
92 /**
93 @short Address Book Const Iterator
94
95 This class provides a const iterator for address book entries.
96 */
97 class ConstIterator
98 {
99 public:
100 ConstIterator();
101 ConstIterator( const ConstIterator & );
102 ~ConstIterator();
103
104 ConstIterator &operator=( const ConstIterator & );
105 const Addressee &operator*() const;
106 const Addressee* operator->() const;
107 ConstIterator &operator++();
108 ConstIterator &operator++(int);
109 ConstIterator &operator--();
110 ConstIterator &operator--(int);
111 bool operator==( const ConstIterator &it );
112 bool operator!=( const ConstIterator &it );
113
114 struct ConstIteratorData;
115 ConstIteratorData *d;
116 };
117
118 /**
119 Constructs a address book object.
120
121 @param format File format class.
122 */
123 AddressBook();
124 AddressBook( const QString &config );
125 virtual ~AddressBook();
126
127 /**
128 Requests a ticket for saving the addressbook. Calling this function locks
129 the addressbook for all other processes. If the address book is already
130 locked the function returns 0. You need the returned @ref Ticket object
131 for calling the @ref save() function.
132
133 @see save()
134 */
135 Ticket *requestSaveTicket( Resource *resource=0 );
136
137 /**
138 Load address book from file.
139 */
140 bool load();
141
142 /**
143 Save address book. The address book is saved to the file, the Ticket
144 object has been requested for by @ref requestSaveTicket().
145
146 @param ticket a ticket object returned by @ref requestSaveTicket()
147 */
148 bool save( Ticket *ticket );
149
150 /**
151 Returns a iterator for first entry of address book.
152 */
153 Iterator begin();
154
155 /**
156 Returns a const iterator for first entry of address book.
157 */
158 ConstIterator begin() const;
159
160 /**
161 Returns a iterator for first entry of address book.
162 */
163 Iterator end();
164
165 /**
166 Returns a const iterator for first entry of address book.
167 */
168 ConstIterator end() const;
169
170 /**
171 Removes all entries from address book.
172 */
173 void clear();
174
175 /**
176 Insert an Addressee object into address book. If an object with the same
177 unique id already exists in the address book it it replaced by the new
178 one. If not the new object is appended to the address book.
179 */
180 void insertAddressee( const Addressee & );
181
182 /**
183 Removes entry from the address book.
184 */
185 void removeAddressee( const Addressee & );
186
187 /**
188 This is like @ref removeAddressee() just above, with the difference that
189 the first element is a iterator, returned by @ref begin().
190 */
191 void removeAddressee( const Iterator & );
192
193 /**
194 Find the specified entry in address book. Returns end(), if the entry
195 couldn't be found.
196 */
197 Iterator find( const Addressee & );
198
199 /**
200 Find the entry specified by an unique id. Returns an empty Addressee
201 object, if the address book does not contain an entry with this id.
202 */
203 Addressee findByUid( const QString & );
204
205
206 /**
207 Returns a list of all addressees in the address book. This list can
208 be sorted with @ref KABC::AddresseeList for example.
209 */
210 Addressee::List allAddressees();
211
212 /**
213 Find all entries with the specified name in the address book. Returns
214 an empty list, if no entries could be found.
215 */
216 Addressee::List findByName( const QString & );
217
218 /**
219 Find all entries with the specified email address in the address book.
220 Returns an empty list, if no entries could be found.
221 */
222 Addressee::List findByEmail( const QString & );
223
224 /**
225 Find all entries wich have the specified category in the address book.
226 Returns an empty list, if no entries could be found.
227 */
228 Addressee::List findByCategory( const QString & );
229
230 /**
231 Return a string identifying this addressbook.
232 */
233 virtual QString identifier();
234
235 /**
236 Used for debug output.
237 */
238 void dump() const;
239
240 void emitAddressBookLocked() { emit addressBookLocked( this ); }
241 void emitAddressBookUnlocked() { emit addressBookUnlocked( this ); }
242 void emitAddressBookChanged() { emit addressBookChanged( this ); }
243
244 /**
245 Return list of all Fields known to the address book which are associated
246 with the given field category.
247 */
248 Field::List fields( int category = Field::All );
249
250 /**
251 Add custom field to address book.
252
253 @param label User visible label of the field.
254 @param category Ored list of field categories.
255 @param key Identifier used as key for reading and writing the field.
256 @param app String used as application key for reading and writing
257 the field.
258 */
259 bool addCustomField( const QString &label, int category = Field::All,
260 const QString &key = QString::null,
261 const QString &app = QString::null );
262
263
264 /**
265 Add address book resource.
266 */
267 bool addResource( Resource * );
268
269 /**
270 Remove address book resource.
271 */
272 bool removeResource( Resource * );
273
274 /**
275 Return pointer list of all resources.
276 */
277 QPtrList<Resource> resources();
278
279 /**
280 Set the @p ErrorHandler, that is used by @ref error() to
281 provide gui-independend error messages.
282 */
283 void setErrorHandler( ErrorHandler * );
284
285 /**
286 Shows gui independend error messages.
287 */
288 void error( const QString& );
289
290 /**
291 Query all resources to clean up their lock files
292 */
293 void cleanUp();
294
295 signals:
296 /**
297 Emitted, when the address book has changed on disk.
298 */
299 void addressBookChanged( AddressBook * );
300
301 /**
302 Emitted, when the address book has been locked for writing.
303 */
304 void addressBookLocked( AddressBook * );
305
306 /**
307 Emitted, when the address book has been unlocked.
308 */
309 void addressBookUnlocked( AddressBook * );
310
311 protected:
312 void deleteRemovedAddressees();
313 void setStandardResource( Resource * );
314 Resource *standardResource();
315 KRES::Manager<Resource> *resourceManager();
316
317 private:
318#ifndef KAB_EMBEDDED
319 QPtrList<Resource> mDummy; // Remove in KDE 4
320#endif //KAB_EMBEDDED
321
322#ifdef KAB_EMBEDDED
323//US optimization
324 void init(const QString &config);
325#endif //KAB_EMBEDDED
326
327
328 struct AddressBookData;
329 AddressBookData *d;
330};
331
332QDataStream &operator<<( QDataStream &, const AddressBook & );
333QDataStream &operator>>( QDataStream &, AddressBook & );
334
335}
336
337#endif