summaryrefslogtreecommitdiffabout
path: root/kabc
authorzautrix <zautrix>2004-09-18 08:25:05 (UTC)
committer zautrix <zautrix>2004-09-18 08:25:05 (UTC)
commit983b010853dfadfec3638e2afd90e522985f67fb (patch) (unidiff)
treeb691b7664b9f6f23d0d92a0e05bf3e8cbcf2df67 /kabc
parentdf03bd8c7ff6a738dd386001679542ae4b493a07 (diff)
downloadkdepimpi-983b010853dfadfec3638e2afd90e522985f67fb.zip
kdepimpi-983b010853dfadfec3638e2afd90e522985f67fb.tar.gz
kdepimpi-983b010853dfadfec3638e2afd90e522985f67fb.tar.bz2
more AB syncing
Diffstat (limited to 'kabc') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressbook.cpp101
-rw-r--r--kabc/addressbook.h1
2 files changed, 100 insertions, 2 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index 47d298a..70eda1b 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -109,312 +109,409 @@ Addressee *AddressBook::Iterator::operator->()
109 return &(*(d->mIt)); 109 return &(*(d->mIt));
110} 110}
111 111
112AddressBook::Iterator &AddressBook::Iterator::operator++() 112AddressBook::Iterator &AddressBook::Iterator::operator++()
113{ 113{
114 (d->mIt)++; 114 (d->mIt)++;
115 return *this; 115 return *this;
116} 116}
117 117
118AddressBook::Iterator &AddressBook::Iterator::operator++(int) 118AddressBook::Iterator &AddressBook::Iterator::operator++(int)
119{ 119{
120 (d->mIt)++; 120 (d->mIt)++;
121 return *this; 121 return *this;
122} 122}
123 123
124AddressBook::Iterator &AddressBook::Iterator::operator--() 124AddressBook::Iterator &AddressBook::Iterator::operator--()
125{ 125{
126 (d->mIt)--; 126 (d->mIt)--;
127 return *this; 127 return *this;
128} 128}
129 129
130AddressBook::Iterator &AddressBook::Iterator::operator--(int) 130AddressBook::Iterator &AddressBook::Iterator::operator--(int)
131{ 131{
132 (d->mIt)--; 132 (d->mIt)--;
133 return *this; 133 return *this;
134} 134}
135 135
136bool AddressBook::Iterator::operator==( const Iterator &it ) 136bool AddressBook::Iterator::operator==( const Iterator &it )
137{ 137{
138 return ( d->mIt == it.d->mIt ); 138 return ( d->mIt == it.d->mIt );
139} 139}
140 140
141bool AddressBook::Iterator::operator!=( const Iterator &it ) 141bool AddressBook::Iterator::operator!=( const Iterator &it )
142{ 142{
143 return ( d->mIt != it.d->mIt ); 143 return ( d->mIt != it.d->mIt );
144} 144}
145 145
146 146
147AddressBook::ConstIterator::ConstIterator() 147AddressBook::ConstIterator::ConstIterator()
148{ 148{
149 d = new ConstIteratorData; 149 d = new ConstIteratorData;
150} 150}
151 151
152AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i ) 152AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i )
153{ 153{
154 d = new ConstIteratorData; 154 d = new ConstIteratorData;
155 d->mIt = i.d->mIt; 155 d->mIt = i.d->mIt;
156} 156}
157 157
158AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i ) 158AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i )
159{ 159{
160 if( this == &i ) return *this; // guard for self assignment 160 if( this == &i ) return *this; // guard for self assignment
161 delete d; // delete the old data because the Iterator was really constructed before 161 delete d; // delete the old data because the Iterator was really constructed before
162 d = new ConstIteratorData; 162 d = new ConstIteratorData;
163 d->mIt = i.d->mIt; 163 d->mIt = i.d->mIt;
164 return *this; 164 return *this;
165} 165}
166 166
167AddressBook::ConstIterator::~ConstIterator() 167AddressBook::ConstIterator::~ConstIterator()
168{ 168{
169 delete d; 169 delete d;
170} 170}
171 171
172const Addressee &AddressBook::ConstIterator::operator*() const 172const Addressee &AddressBook::ConstIterator::operator*() const
173{ 173{
174 return *(d->mIt); 174 return *(d->mIt);
175} 175}
176 176
177const Addressee* AddressBook::ConstIterator::operator->() const 177const Addressee* AddressBook::ConstIterator::operator->() const
178{ 178{
179 return &(*(d->mIt)); 179 return &(*(d->mIt));
180} 180}
181 181
182AddressBook::ConstIterator &AddressBook::ConstIterator::operator++() 182AddressBook::ConstIterator &AddressBook::ConstIterator::operator++()
183{ 183{
184 (d->mIt)++; 184 (d->mIt)++;
185 return *this; 185 return *this;
186} 186}
187 187
188AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int) 188AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int)
189{ 189{
190 (d->mIt)++; 190 (d->mIt)++;
191 return *this; 191 return *this;
192} 192}
193 193
194AddressBook::ConstIterator &AddressBook::ConstIterator::operator--() 194AddressBook::ConstIterator &AddressBook::ConstIterator::operator--()
195{ 195{
196 (d->mIt)--; 196 (d->mIt)--;
197 return *this; 197 return *this;
198} 198}
199 199
200AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int) 200AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int)
201{ 201{
202 (d->mIt)--; 202 (d->mIt)--;
203 return *this; 203 return *this;
204} 204}
205 205
206bool AddressBook::ConstIterator::operator==( const ConstIterator &it ) 206bool AddressBook::ConstIterator::operator==( const ConstIterator &it )
207{ 207{
208 return ( d->mIt == it.d->mIt ); 208 return ( d->mIt == it.d->mIt );
209} 209}
210 210
211bool AddressBook::ConstIterator::operator!=( const ConstIterator &it ) 211bool AddressBook::ConstIterator::operator!=( const ConstIterator &it )
212{ 212{
213 return ( d->mIt != it.d->mIt ); 213 return ( d->mIt != it.d->mIt );
214} 214}
215 215
216 216
217AddressBook::AddressBook() 217AddressBook::AddressBook()
218{ 218{
219 init(0, "contact"); 219 init(0, "contact");
220} 220}
221 221
222AddressBook::AddressBook( const QString &config ) 222AddressBook::AddressBook( const QString &config )
223{ 223{
224 init(config, "contact"); 224 init(config, "contact");
225} 225}
226 226
227AddressBook::AddressBook( const QString &config, const QString &family ) 227AddressBook::AddressBook( const QString &config, const QString &family )
228{ 228{
229 init(config, family); 229 init(config, family);
230 230
231} 231}
232 232
233// the default family is "contact" 233// the default family is "contact"
234void AddressBook::init(const QString &config, const QString &family ) 234void AddressBook::init(const QString &config, const QString &family )
235{ 235{
236 d = new AddressBookData; 236 d = new AddressBookData;
237 QString fami = family;
238 qDebug("new ab ");
237 if (config != 0) { 239 if (config != 0) {
240 qDebug("config != 0 ");
241 if ( family == "syncContact" ) {
242 qDebug("creating sync config ");
243 fami = "contact";
244 KConfig* con = new KConfig( locateLocal("config", "syncContactrc") );
245 con->setGroup( "General" );
246 con->writeEntry( "ResourceKeys", QString("sync") );
247 con->writeEntry( "Standard", QString("sync") );
248 con->setGroup( "Resource_sync" );
249 con->writeEntry( "FileFormat", QString("vcard") );
250 con->writeEntry( "FileName", config );
251 con->writeEntry( "ResourceIdentifier", QString("sync") );
252 con->writeEntry( "ResourceName", QString("sync_res") );
253 con->writeEntry( "ResourceType", QString("file") );
254 //con->sync();
255 d->mConfig = con;
256 }
257 else
238 d->mConfig = new KConfig( locateLocal("config", config) ); 258 d->mConfig = new KConfig( locateLocal("config", config) );
239// qDebug("AddressBook::init 1 config=%s",config.latin1() ); 259// qDebug("AddressBook::init 1 config=%s",config.latin1() );
240 } 260 }
241 else { 261 else {
242 d->mConfig = 0; 262 d->mConfig = 0;
243// qDebug("AddressBook::init 1 config=0"); 263// qDebug("AddressBook::init 1 config=0");
244 } 264 }
245 265
246//US d->mErrorHandler = 0; 266//US d->mErrorHandler = 0;
247 d->mManager = new KRES::Manager<Resource>( family, false ); 267 d->mManager = new KRES::Manager<Resource>( fami, false );
248 d->mManager->readConfig( d->mConfig ); 268 d->mManager->readConfig( d->mConfig );
269 if ( family == "syncContact" ) {
270 KRES::Manager<Resource> *manager = d->mManager;
271 KRES::Manager<Resource>::ActiveIterator it;
272 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
273 (*it)->setAddressBook( this );
274 if ( !(*it)->open() )
275 error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) );
276 }
277 Resource *res = standardResource();
278 if ( !res ) {
279 qDebug("ERROR: no standard resource");
280 res = manager->createResource( "file" );
281 if ( res )
282 {
283 addResource( res );
284 }
285 else
286 qDebug(" No resource available!!!");
287 }
288 setStandardResource( res );
289 manager->writeConfig();
290 }
291 addCustomField( i18n( "Department" ), KABC::Field::Organization,
292 "X-Department", "KADDRESSBOOK" );
293 addCustomField( i18n( "Profession" ), KABC::Field::Organization,
294 "X-Profession", "KADDRESSBOOK" );
295 addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization,
296 "X-AssistantsName", "KADDRESSBOOK" );
297 addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization,
298 "X-ManagersName", "KADDRESSBOOK" );
299 addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal,
300 "X-SpousesName", "KADDRESSBOOK" );
301 addCustomField( i18n( "Office" ), KABC::Field::Personal,
302 "X-Office", "KADDRESSBOOK" );
303 addCustomField( i18n( "IM Address" ), KABC::Field::Personal,
304 "X-IMAddress", "KADDRESSBOOK" );
305 addCustomField( i18n( "Anniversary" ), KABC::Field::Personal,
306 "X-Anniversary", "KADDRESSBOOK" );
307
308 //US added this field to become compatible with Opie/qtopia addressbook
309 // values can be "female" or "male" or "". An empty field represents undefined.
310 addCustomField( i18n( "Gender" ), KABC::Field::Personal,
311 "X-Gender", "KADDRESSBOOK" );
312 addCustomField( i18n( "Children" ), KABC::Field::Personal,
313 "X-Children", "KADDRESSBOOK" );
314 addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal,
315 "X-FreeBusyUrl", "KADDRESSBOOK" );
316 addCustomField( i18n( "ExternalID" ), KABC::Field::Personal,
317 "X-ExternalID", "KADDRESSBOOK" );
249} 318}
250 319
251AddressBook::~AddressBook() 320AddressBook::~AddressBook()
252{ 321{
253 delete d->mConfig; d->mConfig = 0; 322 delete d->mConfig; d->mConfig = 0;
254 delete d->mManager; d->mManager = 0; 323 delete d->mManager; d->mManager = 0;
255//US delete d->mErrorHandler; d->mErrorHandler = 0; 324//US delete d->mErrorHandler; d->mErrorHandler = 0;
256 delete d; d = 0; 325 delete d; d = 0;
257} 326}
258 327
259bool AddressBook::load() 328bool AddressBook::load()
260{ 329{
261 330
262 331
263 clear(); 332 clear();
264 333
265 KRES::Manager<Resource>::ActiveIterator it; 334 KRES::Manager<Resource>::ActiveIterator it;
266 bool ok = true; 335 bool ok = true;
267 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) 336 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it )
268 if ( !(*it)->load() ) { 337 if ( !(*it)->load() ) {
269 error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); 338 error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) );
270 ok = false; 339 ok = false;
271 } 340 }
272 341
273 // mark all addressees as unchanged 342 // mark all addressees as unchanged
274 Addressee::List::Iterator addrIt; 343 Addressee::List::Iterator addrIt;
275 for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) 344 for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt )
276 (*addrIt).setChanged( false ); 345 (*addrIt).setChanged( false );
277 346
278 return ok; 347 return ok;
279} 348}
280 349
281bool AddressBook::save( Ticket *ticket ) 350bool AddressBook::save( Ticket *ticket )
282{ 351{
283 kdDebug(5700) << "AddressBook::save()"<< endl; 352 kdDebug(5700) << "AddressBook::save()"<< endl;
284 353
285 if ( ticket->resource() ) { 354 if ( ticket->resource() ) {
286 deleteRemovedAddressees(); 355 deleteRemovedAddressees();
287
288 return ticket->resource()->save( ticket ); 356 return ticket->resource()->save( ticket );
289 } 357 }
290 358
291 return false; 359 return false;
292} 360}
361bool AddressBook::saveAB()
362{
363 bool ok = true;
364
365 deleteRemovedAddressees();
366
367 KRES::Manager<Resource>::ActiveIterator it;
368 KRES::Manager<Resource> *manager = d->mManager;
369 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
370 if ( !(*it)->readOnly() && (*it)->isOpen() ) {
371 Ticket *ticket = requestSaveTicket( *it );
372// qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() );
373 if ( !ticket ) {
374 error( i18n( "Unable to save to resource '%1'. It is locked." )
375 .arg( (*it)->resourceName() ) );
376 return false;
377 }
378
379 //if ( !save( ticket ) )
380 if ( ticket->resource() ) {
381 if ( ! ticket->resource()->save( ticket ) )
382 ok = false;
383 } else
384 ok = false;
385
386 }
387 }
388 return ok;
389}
293 390
294AddressBook::Iterator AddressBook::begin() 391AddressBook::Iterator AddressBook::begin()
295{ 392{
296 Iterator it = Iterator(); 393 Iterator it = Iterator();
297 it.d->mIt = d->mAddressees.begin(); 394 it.d->mIt = d->mAddressees.begin();
298 return it; 395 return it;
299} 396}
300 397
301AddressBook::ConstIterator AddressBook::begin() const 398AddressBook::ConstIterator AddressBook::begin() const
302{ 399{
303 ConstIterator it = ConstIterator(); 400 ConstIterator it = ConstIterator();
304 it.d->mIt = d->mAddressees.begin(); 401 it.d->mIt = d->mAddressees.begin();
305 return it; 402 return it;
306} 403}
307 404
308AddressBook::Iterator AddressBook::end() 405AddressBook::Iterator AddressBook::end()
309{ 406{
310 Iterator it = Iterator(); 407 Iterator it = Iterator();
311 it.d->mIt = d->mAddressees.end(); 408 it.d->mIt = d->mAddressees.end();
312 return it; 409 return it;
313} 410}
314 411
315AddressBook::ConstIterator AddressBook::end() const 412AddressBook::ConstIterator AddressBook::end() const
316{ 413{
317 ConstIterator it = ConstIterator(); 414 ConstIterator it = ConstIterator();
318 it.d->mIt = d->mAddressees.end(); 415 it.d->mIt = d->mAddressees.end();
319 return it; 416 return it;
320} 417}
321 418
322void AddressBook::clear() 419void AddressBook::clear()
323{ 420{
324 d->mAddressees.clear(); 421 d->mAddressees.clear();
325} 422}
326 423
327Ticket *AddressBook::requestSaveTicket( Resource *resource ) 424Ticket *AddressBook::requestSaveTicket( Resource *resource )
328{ 425{
329 kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; 426 kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl;
330 427
331 if ( !resource ) 428 if ( !resource )
332 { 429 {
333 qDebug("AddressBook::requestSaveTicket no resource" ); 430 qDebug("AddressBook::requestSaveTicket no resource" );
334 resource = standardResource(); 431 resource = standardResource();
335 } 432 }
336 433
337 KRES::Manager<Resource>::ActiveIterator it; 434 KRES::Manager<Resource>::ActiveIterator it;
338 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { 435 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
339 if ( (*it) == resource ) { 436 if ( (*it) == resource ) {
340 if ( (*it)->readOnly() || !(*it)->isOpen() ) 437 if ( (*it)->readOnly() || !(*it)->isOpen() )
341 return 0; 438 return 0;
342 else 439 else
343 return (*it)->requestSaveTicket(); 440 return (*it)->requestSaveTicket();
344 } 441 }
345 } 442 }
346 443
347 return 0; 444 return 0;
348} 445}
349 446
350void AddressBook::insertAddressee( const Addressee &a ) 447void AddressBook::insertAddressee( const Addressee &a )
351{ 448{
352 Addressee::List::Iterator it; 449 Addressee::List::Iterator it;
353 for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { 450 for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) {
354 if ( a.uid() == (*it).uid() ) { 451 if ( a.uid() == (*it).uid() ) {
355 bool changed = false; 452 bool changed = false;
356 Addressee addr = a; 453 Addressee addr = a;
357 if ( addr != (*it) ) 454 if ( addr != (*it) )
358 changed = true; 455 changed = true;
359 456
360 (*it) = a; 457 (*it) = a;
361 if ( (*it).resource() == 0 ) 458 if ( (*it).resource() == 0 )
362 (*it).setResource( standardResource() ); 459 (*it).setResource( standardResource() );
363 460
364 if ( changed ) { 461 if ( changed ) {
365 (*it).setRevision( QDateTime::currentDateTime() ); 462 (*it).setRevision( QDateTime::currentDateTime() );
366 (*it).setChanged( true ); 463 (*it).setChanged( true );
367 } 464 }
368 465
369 return; 466 return;
370 } 467 }
371 } 468 }
372 d->mAddressees.append( a ); 469 d->mAddressees.append( a );
373 Addressee& addr = d->mAddressees.last(); 470 Addressee& addr = d->mAddressees.last();
374 if ( addr.resource() == 0 ) 471 if ( addr.resource() == 0 )
375 addr.setResource( standardResource() ); 472 addr.setResource( standardResource() );
376 473
377 addr.setChanged( true ); 474 addr.setChanged( true );
378} 475}
379 476
380void AddressBook::removeAddressee( const Addressee &a ) 477void AddressBook::removeAddressee( const Addressee &a )
381{ 478{
382 Iterator it; 479 Iterator it;
383 for ( it = begin(); it != end(); ++it ) { 480 for ( it = begin(); it != end(); ++it ) {
384 if ( a.uid() == (*it).uid() ) { 481 if ( a.uid() == (*it).uid() ) {
385 removeAddressee( it ); 482 removeAddressee( it );
386 return; 483 return;
387 } 484 }
388 } 485 }
389} 486}
390 487
391void AddressBook::removeAddressee( const Iterator &it ) 488void AddressBook::removeAddressee( const Iterator &it )
392{ 489{
393 d->mRemovedAddressees.append( (*it) ); 490 d->mRemovedAddressees.append( (*it) );
394 d->mAddressees.remove( it.d->mIt ); 491 d->mAddressees.remove( it.d->mIt );
395} 492}
396 493
397AddressBook::Iterator AddressBook::find( const Addressee &a ) 494AddressBook::Iterator AddressBook::find( const Addressee &a )
398{ 495{
399 Iterator it; 496 Iterator it;
400 for ( it = begin(); it != end(); ++it ) { 497 for ( it = begin(); it != end(); ++it ) {
401 if ( a.uid() == (*it).uid() ) { 498 if ( a.uid() == (*it).uid() ) {
402 return it; 499 return it;
403 } 500 }
404 } 501 }
405 return end(); 502 return end();
406} 503}
407 504
408Addressee AddressBook::findByUid( const QString &uid ) 505Addressee AddressBook::findByUid( const QString &uid )
409{ 506{
410 Iterator it; 507 Iterator it;
411 for ( it = begin(); it != end(); ++it ) { 508 for ( it = begin(); it != end(); ++it ) {
412 if ( uid == (*it).uid() ) { 509 if ( uid == (*it).uid() ) {
413 return *it; 510 return *it;
414 } 511 }
415 } 512 }
416 return Addressee(); 513 return Addressee();
417} 514}
418 515
419Addressee::List AddressBook::allAddressees() 516Addressee::List AddressBook::allAddressees()
420{ 517{
diff --git a/kabc/addressbook.h b/kabc/addressbook.h
index f89d7da..e43de31 100644
--- a/kabc/addressbook.h
+++ b/kabc/addressbook.h
@@ -16,256 +16,257 @@
16 along with this library; see the file COPYING.LIB. If not, write to 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, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21/* 21/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (c) 2004 Ulf Schenk
24 24
25$Id$ 25$Id$
26*/ 26*/
27 27
28#ifndef KABC_ADDRESSBOOK_H 28#ifndef KABC_ADDRESSBOOK_H
29#define KABC_ADDRESSBOOK_H 29#define KABC_ADDRESSBOOK_H
30 30
31#include <qobject.h> 31#include <qobject.h>
32 32
33#include <kresources/manager.h> 33#include <kresources/manager.h>
34#include <qptrlist.h> 34#include <qptrlist.h>
35 35
36#include "addressee.h" 36#include "addressee.h"
37#include "field.h" 37#include "field.h"
38 38
39namespace KABC { 39namespace KABC {
40 40
41class ErrorHandler; 41class ErrorHandler;
42class Resource; 42class Resource;
43class Ticket; 43class Ticket;
44 44
45/** 45/**
46 @short Address Book 46 @short Address Book
47 47
48 This class provides access to a collection of address book entries. 48 This class provides access to a collection of address book entries.
49*/ 49*/
50class AddressBook : public QObject 50class AddressBook : public QObject
51{ 51{
52 Q_OBJECT 52 Q_OBJECT
53 53
54 friend QDataStream &operator<<( QDataStream &, const AddressBook & ); 54 friend QDataStream &operator<<( QDataStream &, const AddressBook & );
55 friend QDataStream &operator>>( QDataStream &, AddressBook & ); 55 friend QDataStream &operator>>( QDataStream &, AddressBook & );
56 friend class StdAddressBook; 56 friend class StdAddressBook;
57 57
58 public: 58 public:
59 /** 59 /**
60 @short Address Book Iterator 60 @short Address Book Iterator
61 61
62 This class provides an iterator for address book entries. 62 This class provides an iterator for address book entries.
63 */ 63 */
64 class Iterator 64 class Iterator
65 { 65 {
66 public: 66 public:
67 Iterator(); 67 Iterator();
68 Iterator( const Iterator & ); 68 Iterator( const Iterator & );
69 ~Iterator(); 69 ~Iterator();
70 70
71 Iterator &operator=( const Iterator & ); 71 Iterator &operator=( const Iterator & );
72 const Addressee &operator*() const; 72 const Addressee &operator*() const;
73 Addressee &operator*(); 73 Addressee &operator*();
74 Addressee* operator->(); 74 Addressee* operator->();
75 Iterator &operator++(); 75 Iterator &operator++();
76 Iterator &operator++(int); 76 Iterator &operator++(int);
77 Iterator &operator--(); 77 Iterator &operator--();
78 Iterator &operator--(int); 78 Iterator &operator--(int);
79 bool operator==( const Iterator &it ); 79 bool operator==( const Iterator &it );
80 bool operator!=( const Iterator &it ); 80 bool operator!=( const Iterator &it );
81 81
82 struct IteratorData; 82 struct IteratorData;
83 IteratorData *d; 83 IteratorData *d;
84 }; 84 };
85 85
86 /** 86 /**
87 @short Address Book Const Iterator 87 @short Address Book Const Iterator
88 88
89 This class provides a const iterator for address book entries. 89 This class provides a const iterator for address book entries.
90 */ 90 */
91 class ConstIterator 91 class ConstIterator
92 { 92 {
93 public: 93 public:
94 ConstIterator(); 94 ConstIterator();
95 ConstIterator( const ConstIterator & ); 95 ConstIterator( const ConstIterator & );
96 ~ConstIterator(); 96 ~ConstIterator();
97 97
98 ConstIterator &operator=( const ConstIterator & ); 98 ConstIterator &operator=( const ConstIterator & );
99 const Addressee &operator*() const; 99 const Addressee &operator*() const;
100 const Addressee* operator->() const; 100 const Addressee* operator->() const;
101 ConstIterator &operator++(); 101 ConstIterator &operator++();
102 ConstIterator &operator++(int); 102 ConstIterator &operator++(int);
103 ConstIterator &operator--(); 103 ConstIterator &operator--();
104 ConstIterator &operator--(int); 104 ConstIterator &operator--(int);
105 bool operator==( const ConstIterator &it ); 105 bool operator==( const ConstIterator &it );
106 bool operator!=( const ConstIterator &it ); 106 bool operator!=( const ConstIterator &it );
107 107
108 struct ConstIteratorData; 108 struct ConstIteratorData;
109 ConstIteratorData *d; 109 ConstIteratorData *d;
110 }; 110 };
111 111
112 /** 112 /**
113 Constructs a address book object. 113 Constructs a address book object.
114 114
115 @param format File format class. 115 @param format File format class.
116 */ 116 */
117 AddressBook(); 117 AddressBook();
118 AddressBook( const QString &config ); 118 AddressBook( const QString &config );
119 AddressBook( const QString &config, const QString &family ); 119 AddressBook( const QString &config, const QString &family );
120 virtual ~AddressBook(); 120 virtual ~AddressBook();
121 121
122 /** 122 /**
123 Requests a ticket for saving the addressbook. Calling this function locks 123 Requests a ticket for saving the addressbook. Calling this function locks
124 the addressbook for all other processes. If the address book is already 124 the addressbook for all other processes. If the address book is already
125 locked the function returns 0. You need the returned @ref Ticket object 125 locked the function returns 0. You need the returned @ref Ticket object
126 for calling the @ref save() function. 126 for calling the @ref save() function.
127 127
128 @see save() 128 @see save()
129 */ 129 */
130 Ticket *requestSaveTicket( Resource *resource=0 ); 130 Ticket *requestSaveTicket( Resource *resource=0 );
131 131
132 /** 132 /**
133 Load address book from file. 133 Load address book from file.
134 */ 134 */
135 bool load(); 135 bool load();
136 136
137 /** 137 /**
138 Save address book. The address book is saved to the file, the Ticket 138 Save address book. The address book is saved to the file, the Ticket
139 object has been requested for by @ref requestSaveTicket(). 139 object has been requested for by @ref requestSaveTicket().
140 140
141 @param ticket a ticket object returned by @ref requestSaveTicket() 141 @param ticket a ticket object returned by @ref requestSaveTicket()
142 */ 142 */
143 bool save( Ticket *ticket ); 143 bool save( Ticket *ticket );
144 bool saveAB( );
144 145
145 /** 146 /**
146 Returns a iterator for first entry of address book. 147 Returns a iterator for first entry of address book.
147 */ 148 */
148 Iterator begin(); 149 Iterator begin();
149 150
150 /** 151 /**
151 Returns a const iterator for first entry of address book. 152 Returns a const iterator for first entry of address book.
152 */ 153 */
153 ConstIterator begin() const; 154 ConstIterator begin() const;
154 155
155 /** 156 /**
156 Returns a iterator for first entry of address book. 157 Returns a iterator for first entry of address book.
157 */ 158 */
158 Iterator end(); 159 Iterator end();
159 160
160 /** 161 /**
161 Returns a const iterator for first entry of address book. 162 Returns a const iterator for first entry of address book.
162 */ 163 */
163 ConstIterator end() const; 164 ConstIterator end() const;
164 165
165 /** 166 /**
166 Removes all entries from address book. 167 Removes all entries from address book.
167 */ 168 */
168 void clear(); 169 void clear();
169 170
170 /** 171 /**
171 Insert an Addressee object into address book. If an object with the same 172 Insert an Addressee object into address book. If an object with the same
172 unique id already exists in the address book it it replaced by the new 173 unique id already exists in the address book it it replaced by the new
173 one. If not the new object is appended to the address book. 174 one. If not the new object is appended to the address book.
174 */ 175 */
175 void insertAddressee( const Addressee & ); 176 void insertAddressee( const Addressee & );
176 177
177 /** 178 /**
178 Removes entry from the address book. 179 Removes entry from the address book.
179 */ 180 */
180 void removeAddressee( const Addressee & ); 181 void removeAddressee( const Addressee & );
181 182
182 /** 183 /**
183 This is like @ref removeAddressee() just above, with the difference that 184 This is like @ref removeAddressee() just above, with the difference that
184 the first element is a iterator, returned by @ref begin(). 185 the first element is a iterator, returned by @ref begin().
185 */ 186 */
186 void removeAddressee( const Iterator & ); 187 void removeAddressee( const Iterator & );
187 188
188 /** 189 /**
189 Find the specified entry in address book. Returns end(), if the entry 190 Find the specified entry in address book. Returns end(), if the entry
190 couldn't be found. 191 couldn't be found.
191 */ 192 */
192 Iterator find( const Addressee & ); 193 Iterator find( const Addressee & );
193 194
194 /** 195 /**
195 Find the entry specified by an unique id. Returns an empty Addressee 196 Find the entry specified by an unique id. Returns an empty Addressee
196 object, if the address book does not contain an entry with this id. 197 object, if the address book does not contain an entry with this id.
197 */ 198 */
198 Addressee findByUid( const QString & ); 199 Addressee findByUid( const QString & );
199 200
200 201
201 /** 202 /**
202 Returns a list of all addressees in the address book. This list can 203 Returns a list of all addressees in the address book. This list can
203 be sorted with @ref KABC::AddresseeList for example. 204 be sorted with @ref KABC::AddresseeList for example.
204 */ 205 */
205 Addressee::List allAddressees(); 206 Addressee::List allAddressees();
206 207
207 /** 208 /**
208 Find all entries with the specified name in the address book. Returns 209 Find all entries with the specified name in the address book. Returns
209 an empty list, if no entries could be found. 210 an empty list, if no entries could be found.
210 */ 211 */
211 Addressee::List findByName( const QString & ); 212 Addressee::List findByName( const QString & );
212 213
213 /** 214 /**
214 Find all entries with the specified email address in the address book. 215 Find all entries with the specified email address in the address book.
215 Returns an empty list, if no entries could be found. 216 Returns an empty list, if no entries could be found.
216 */ 217 */
217 Addressee::List findByEmail( const QString & ); 218 Addressee::List findByEmail( const QString & );
218 219
219 /** 220 /**
220 Find all entries wich have the specified category in the address book. 221 Find all entries wich have the specified category in the address book.
221 Returns an empty list, if no entries could be found. 222 Returns an empty list, if no entries could be found.
222 */ 223 */
223 Addressee::List findByCategory( const QString & ); 224 Addressee::List findByCategory( const QString & );
224 225
225 /** 226 /**
226 Return a string identifying this addressbook. 227 Return a string identifying this addressbook.
227 */ 228 */
228 virtual QString identifier(); 229 virtual QString identifier();
229 230
230 /** 231 /**
231 Used for debug output. 232 Used for debug output.
232 */ 233 */
233 void dump() const; 234 void dump() const;
234 235
235 void emitAddressBookLocked() { emit addressBookLocked( this ); } 236 void emitAddressBookLocked() { emit addressBookLocked( this ); }
236 void emitAddressBookUnlocked() { emit addressBookUnlocked( this ); } 237 void emitAddressBookUnlocked() { emit addressBookUnlocked( this ); }
237 void emitAddressBookChanged() { emit addressBookChanged( this ); } 238 void emitAddressBookChanged() { emit addressBookChanged( this ); }
238 239
239 /** 240 /**
240 Return list of all Fields known to the address book which are associated 241 Return list of all Fields known to the address book which are associated
241 with the given field category. 242 with the given field category.
242 */ 243 */
243 Field::List fields( int category = Field::All ); 244 Field::List fields( int category = Field::All );
244 245
245 /** 246 /**
246 Add custom field to address book. 247 Add custom field to address book.
247 248
248 @param label User visible label of the field. 249 @param label User visible label of the field.
249 @param category Ored list of field categories. 250 @param category Ored list of field categories.
250 @param key Identifier used as key for reading and writing the field. 251 @param key Identifier used as key for reading and writing the field.
251 @param app String used as application key for reading and writing 252 @param app String used as application key for reading and writing
252 the field. 253 the field.
253 */ 254 */
254 bool addCustomField( const QString &label, int category = Field::All, 255 bool addCustomField( const QString &label, int category = Field::All,
255 const QString &key = QString::null, 256 const QString &key = QString::null,
256 const QString &app = QString::null ); 257 const QString &app = QString::null );
257 258
258 259
259 /** 260 /**
260 Add address book resource. 261 Add address book resource.
261 */ 262 */
262 bool addResource( Resource * ); 263 bool addResource( Resource * );
263 264
264 /** 265 /**
265 Remove address book resource. 266 Remove address book resource.
266 */ 267 */
267 bool removeResource( Resource * ); 268 bool removeResource( Resource * );
268 269
269 /** 270 /**
270 Return pointer list of all resources. 271 Return pointer list of all resources.
271 */ 272 */