summaryrefslogtreecommitdiffabout
path: root/kabc/addressbook.cpp
Unidiff
Diffstat (limited to 'kabc/addressbook.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressbook.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index 97bd3ef..0838157 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -1,641 +1,641 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 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 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/*US 28/*US
29 29
30#include <qfile.h> 30#include <qfile.h>
31#include <qregexp.h> 31#include <qregexp.h>
32#include <qtimer.h> 32#include <qtimer.h>
33 33
34#include <kapplication.h> 34#include <kapplication.h>
35#include <kinstance.h> 35#include <kinstance.h>
36#include <kstandarddirs.h> 36#include <kstandarddirs.h>
37 37
38#include "errorhandler.h" 38#include "errorhandler.h"
39*/ 39*/
40#include <qptrlist.h> 40#include <qptrlist.h>
41 41
42#include <kglobal.h> 42#include <kglobal.h>
43#include <klocale.h> 43#include <klocale.h>
44#include <kdebug.h> 44#include <kdebug.h>
45#include "addressbook.h" 45#include "addressbook.h"
46#include "resource.h" 46#include "resource.h"
47 47
48//US #include "addressbook.moc" 48//US #include "addressbook.moc"
49 49
50using namespace KABC; 50using namespace KABC;
51 51
52struct AddressBook::AddressBookData 52struct AddressBook::AddressBookData
53{ 53{
54 Addressee::List mAddressees; 54 Addressee::List mAddressees;
55 Addressee::List mRemovedAddressees; 55 Addressee::List mRemovedAddressees;
56 Field::List mAllFields; 56 Field::List mAllFields;
57 KConfig *mConfig; 57 KConfig *mConfig;
58 KRES::Manager<Resource> *mManager; 58 KRES::Manager<Resource> *mManager;
59//US ErrorHandler *mErrorHandler; 59//US ErrorHandler *mErrorHandler;
60}; 60};
61 61
62struct AddressBook::Iterator::IteratorData 62struct AddressBook::Iterator::IteratorData
63{ 63{
64 Addressee::List::Iterator mIt; 64 Addressee::List::Iterator mIt;
65}; 65};
66 66
67struct AddressBook::ConstIterator::ConstIteratorData 67struct AddressBook::ConstIterator::ConstIteratorData
68{ 68{
69 Addressee::List::ConstIterator mIt; 69 Addressee::List::ConstIterator mIt;
70}; 70};
71 71
72AddressBook::Iterator::Iterator() 72AddressBook::Iterator::Iterator()
73{ 73{
74 d = new IteratorData; 74 d = new IteratorData;
75} 75}
76 76
77AddressBook::Iterator::Iterator( const AddressBook::Iterator &i ) 77AddressBook::Iterator::Iterator( const AddressBook::Iterator &i )
78{ 78{
79 d = new IteratorData; 79 d = new IteratorData;
80 d->mIt = i.d->mIt; 80 d->mIt = i.d->mIt;
81} 81}
82 82
83AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i ) 83AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i )
84{ 84{
85 if( this == &i ) return *this; // guard against self assignment 85 if( this == &i ) return *this; // guard against self assignment
86 delete d; // delete the old data the Iterator was completely constructed before 86 delete d; // delete the old data the Iterator was completely constructed before
87 d = new IteratorData; 87 d = new IteratorData;
88 d->mIt = i.d->mIt; 88 d->mIt = i.d->mIt;
89 return *this; 89 return *this;
90} 90}
91 91
92AddressBook::Iterator::~Iterator() 92AddressBook::Iterator::~Iterator()
93{ 93{
94 delete d; 94 delete d;
95} 95}
96 96
97const Addressee &AddressBook::Iterator::operator*() const 97const Addressee &AddressBook::Iterator::operator*() const
98{ 98{
99 return *(d->mIt); 99 return *(d->mIt);
100} 100}
101 101
102Addressee &AddressBook::Iterator::operator*() 102Addressee &AddressBook::Iterator::operator*()
103{ 103{
104 return *(d->mIt); 104 return *(d->mIt);
105} 105}
106 106
107Addressee *AddressBook::Iterator::operator->() 107Addressee *AddressBook::Iterator::operator->()
108{ 108{
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); 219 init(0);
220} 220}
221 221
222AddressBook::AddressBook( const QString &config ) 222AddressBook::AddressBook( const QString &config )
223{ 223{
224 init(config); 224 init(config);
225} 225}
226 226
227void AddressBook::init(const QString &config) 227void AddressBook::init(const QString &config)
228{ 228{
229 d = new AddressBookData; 229 d = new AddressBookData;
230 if (config != 0) { 230 if (config != 0) {
231 d->mConfig = new KConfig( config ); 231 d->mConfig = new KConfig( config );
232// qDebug("AddressBook::init 1 config=%s",config.latin1() ); 232// qDebug("AddressBook::init 1 config=%s",config.latin1() );
233 } 233 }
234 else { 234 else {
235 d->mConfig = 0; 235 d->mConfig = 0;
236// qDebug("AddressBook::init 1 config=0"); 236// qDebug("AddressBook::init 1 config=0");
237 } 237 }
238 238
239//US d->mErrorHandler = 0; 239//US d->mErrorHandler = 0;
240 d->mManager = new KRES::Manager<Resource>( "contact" ); 240 d->mManager = new KRES::Manager<Resource>( "contact" );
241 d->mManager->readConfig( d->mConfig ); 241 d->mManager->readConfig( d->mConfig );
242} 242}
243 243
244AddressBook::~AddressBook() 244AddressBook::~AddressBook()
245{ 245{
246 delete d->mConfig; d->mConfig = 0; 246 delete d->mConfig; d->mConfig = 0;
247 delete d->mManager; d->mManager = 0; 247 delete d->mManager; d->mManager = 0;
248//US delete d->mErrorHandler; d->mErrorHandler = 0; 248//US delete d->mErrorHandler; d->mErrorHandler = 0;
249 delete d; d = 0; 249 delete d; d = 0;
250} 250}
251 251
252bool AddressBook::load() 252bool AddressBook::load()
253{ 253{
254 kdDebug(5700) << "AddressBook::load()" << endl; 254
255 255
256 clear(); 256 clear();
257 257
258 KRES::Manager<Resource>::ActiveIterator it; 258 KRES::Manager<Resource>::ActiveIterator it;
259 bool ok = true; 259 bool ok = true;
260 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) 260 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it )
261 if ( !(*it)->load() ) { 261 if ( !(*it)->load() ) {
262 error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); 262 error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) );
263 ok = false; 263 ok = false;
264 } 264 }
265 265
266 // mark all addressees as unchanged 266 // mark all addressees as unchanged
267 Addressee::List::Iterator addrIt; 267 Addressee::List::Iterator addrIt;
268 for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) 268 for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt )
269 (*addrIt).setChanged( false ); 269 (*addrIt).setChanged( false );
270 270
271 return ok; 271 return ok;
272} 272}
273 273
274bool AddressBook::save( Ticket *ticket ) 274bool AddressBook::save( Ticket *ticket )
275{ 275{
276 kdDebug(5700) << "AddressBook::save()"<< endl; 276 kdDebug(5700) << "AddressBook::save()"<< endl;
277 277
278 if ( ticket->resource() ) { 278 if ( ticket->resource() ) {
279 deleteRemovedAddressees(); 279 deleteRemovedAddressees();
280 280
281 return ticket->resource()->save( ticket ); 281 return ticket->resource()->save( ticket );
282 } 282 }
283 283
284 return false; 284 return false;
285} 285}
286 286
287AddressBook::Iterator AddressBook::begin() 287AddressBook::Iterator AddressBook::begin()
288{ 288{
289 Iterator it = Iterator(); 289 Iterator it = Iterator();
290 it.d->mIt = d->mAddressees.begin(); 290 it.d->mIt = d->mAddressees.begin();
291 return it; 291 return it;
292} 292}
293 293
294AddressBook::ConstIterator AddressBook::begin() const 294AddressBook::ConstIterator AddressBook::begin() const
295{ 295{
296 ConstIterator it = ConstIterator(); 296 ConstIterator it = ConstIterator();
297 it.d->mIt = d->mAddressees.begin(); 297 it.d->mIt = d->mAddressees.begin();
298 return it; 298 return it;
299} 299}
300 300
301AddressBook::Iterator AddressBook::end() 301AddressBook::Iterator AddressBook::end()
302{ 302{
303 Iterator it = Iterator(); 303 Iterator it = Iterator();
304 it.d->mIt = d->mAddressees.end(); 304 it.d->mIt = d->mAddressees.end();
305 return it; 305 return it;
306} 306}
307 307
308AddressBook::ConstIterator AddressBook::end() const 308AddressBook::ConstIterator AddressBook::end() const
309{ 309{
310 ConstIterator it = ConstIterator(); 310 ConstIterator it = ConstIterator();
311 it.d->mIt = d->mAddressees.end(); 311 it.d->mIt = d->mAddressees.end();
312 return it; 312 return it;
313} 313}
314 314
315void AddressBook::clear() 315void AddressBook::clear()
316{ 316{
317 d->mAddressees.clear(); 317 d->mAddressees.clear();
318} 318}
319 319
320Ticket *AddressBook::requestSaveTicket( Resource *resource ) 320Ticket *AddressBook::requestSaveTicket( Resource *resource )
321{ 321{
322 kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; 322 kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl;
323 323
324 if ( !resource ) 324 if ( !resource )
325 { 325 {
326 qDebug("AddressBook::requestSaveTicket no resource" ); 326 qDebug("AddressBook::requestSaveTicket no resource" );
327 resource = standardResource(); 327 resource = standardResource();
328 } 328 }
329 329
330 KRES::Manager<Resource>::ActiveIterator it; 330 KRES::Manager<Resource>::ActiveIterator it;
331 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { 331 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
332 if ( (*it) == resource ) { 332 if ( (*it) == resource ) {
333 if ( (*it)->readOnly() || !(*it)->isOpen() ) 333 if ( (*it)->readOnly() || !(*it)->isOpen() )
334 return 0; 334 return 0;
335 else 335 else
336 return (*it)->requestSaveTicket(); 336 return (*it)->requestSaveTicket();
337 } 337 }
338 } 338 }
339 339
340 return 0; 340 return 0;
341} 341}
342 342
343void AddressBook::insertAddressee( const Addressee &a ) 343void AddressBook::insertAddressee( const Addressee &a )
344{ 344{
345 Addressee::List::Iterator it; 345 Addressee::List::Iterator it;
346 for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { 346 for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) {
347 if ( a.uid() == (*it).uid() ) { 347 if ( a.uid() == (*it).uid() ) {
348 bool changed = false; 348 bool changed = false;
349 Addressee addr = a; 349 Addressee addr = a;
350 if ( addr != (*it) ) 350 if ( addr != (*it) )
351 changed = true; 351 changed = true;
352 352
353 (*it) = a; 353 (*it) = a;
354 if ( (*it).resource() == 0 ) 354 if ( (*it).resource() == 0 )
355 (*it).setResource( standardResource() ); 355 (*it).setResource( standardResource() );
356 356
357 if ( changed ) { 357 if ( changed ) {
358 (*it).setRevision( QDateTime::currentDateTime() ); 358 (*it).setRevision( QDateTime::currentDateTime() );
359 (*it).setChanged( true ); 359 (*it).setChanged( true );
360 } 360 }
361 361
362 return; 362 return;
363 } 363 }
364 } 364 }
365 d->mAddressees.append( a ); 365 d->mAddressees.append( a );
366 Addressee& addr = d->mAddressees.last(); 366 Addressee& addr = d->mAddressees.last();
367 if ( addr.resource() == 0 ) 367 if ( addr.resource() == 0 )
368 addr.setResource( standardResource() ); 368 addr.setResource( standardResource() );
369 369
370 addr.setChanged( true ); 370 addr.setChanged( true );
371} 371}
372 372
373void AddressBook::removeAddressee( const Addressee &a ) 373void AddressBook::removeAddressee( const Addressee &a )
374{ 374{
375 Iterator it; 375 Iterator it;
376 for ( it = begin(); it != end(); ++it ) { 376 for ( it = begin(); it != end(); ++it ) {
377 if ( a.uid() == (*it).uid() ) { 377 if ( a.uid() == (*it).uid() ) {
378 removeAddressee( it ); 378 removeAddressee( it );
379 return; 379 return;
380 } 380 }
381 } 381 }
382} 382}
383 383
384void AddressBook::removeAddressee( const Iterator &it ) 384void AddressBook::removeAddressee( const Iterator &it )
385{ 385{
386 d->mRemovedAddressees.append( (*it) ); 386 d->mRemovedAddressees.append( (*it) );
387 d->mAddressees.remove( it.d->mIt ); 387 d->mAddressees.remove( it.d->mIt );
388} 388}
389 389
390AddressBook::Iterator AddressBook::find( const Addressee &a ) 390AddressBook::Iterator AddressBook::find( const Addressee &a )
391{ 391{
392 Iterator it; 392 Iterator it;
393 for ( it = begin(); it != end(); ++it ) { 393 for ( it = begin(); it != end(); ++it ) {
394 if ( a.uid() == (*it).uid() ) { 394 if ( a.uid() == (*it).uid() ) {
395 return it; 395 return it;
396 } 396 }
397 } 397 }
398 return end(); 398 return end();
399} 399}
400 400
401Addressee AddressBook::findByUid( const QString &uid ) 401Addressee AddressBook::findByUid( const QString &uid )
402{ 402{
403 Iterator it; 403 Iterator it;
404 for ( it = begin(); it != end(); ++it ) { 404 for ( it = begin(); it != end(); ++it ) {
405 if ( uid == (*it).uid() ) { 405 if ( uid == (*it).uid() ) {
406 return *it; 406 return *it;
407 } 407 }
408 } 408 }
409 return Addressee(); 409 return Addressee();
410} 410}
411 411
412Addressee::List AddressBook::allAddressees() 412Addressee::List AddressBook::allAddressees()
413{ 413{
414 return d->mAddressees; 414 return d->mAddressees;
415} 415}
416 416
417Addressee::List AddressBook::findByName( const QString &name ) 417Addressee::List AddressBook::findByName( const QString &name )
418{ 418{
419 Addressee::List results; 419 Addressee::List results;
420 420
421 Iterator it; 421 Iterator it;
422 for ( it = begin(); it != end(); ++it ) { 422 for ( it = begin(); it != end(); ++it ) {
423 if ( name == (*it).name() ) { 423 if ( name == (*it).name() ) {
424 results.append( *it ); 424 results.append( *it );
425 } 425 }
426 } 426 }
427 427
428 return results; 428 return results;
429} 429}
430 430
431Addressee::List AddressBook::findByEmail( const QString &email ) 431Addressee::List AddressBook::findByEmail( const QString &email )
432{ 432{
433 Addressee::List results; 433 Addressee::List results;
434 QStringList mailList; 434 QStringList mailList;
435 435
436 Iterator it; 436 Iterator it;
437 for ( it = begin(); it != end(); ++it ) { 437 for ( it = begin(); it != end(); ++it ) {
438 mailList = (*it).emails(); 438 mailList = (*it).emails();
439 for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { 439 for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) {
440 if ( email == (*ite) ) { 440 if ( email == (*ite) ) {
441 results.append( *it ); 441 results.append( *it );
442 } 442 }
443 } 443 }
444 } 444 }
445 445
446 return results; 446 return results;
447} 447}
448 448
449Addressee::List AddressBook::findByCategory( const QString &category ) 449Addressee::List AddressBook::findByCategory( const QString &category )
450{ 450{
451 Addressee::List results; 451 Addressee::List results;
452 452
453 Iterator it; 453 Iterator it;
454 for ( it = begin(); it != end(); ++it ) { 454 for ( it = begin(); it != end(); ++it ) {
455 if ( (*it).hasCategory( category) ) { 455 if ( (*it).hasCategory( category) ) {
456 results.append( *it ); 456 results.append( *it );
457 } 457 }
458 } 458 }
459 459
460 return results; 460 return results;
461} 461}
462 462
463void AddressBook::dump() const 463void AddressBook::dump() const
464{ 464{
465 kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; 465 kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl;
466 466
467 ConstIterator it; 467 ConstIterator it;
468 for( it = begin(); it != end(); ++it ) { 468 for( it = begin(); it != end(); ++it ) {
469 (*it).dump(); 469 (*it).dump();
470 } 470 }
471 471
472 kdDebug(5700) << "AddressBook::dump() --- end ---" << endl; 472 kdDebug(5700) << "AddressBook::dump() --- end ---" << endl;
473} 473}
474 474
475QString AddressBook::identifier() 475QString AddressBook::identifier()
476{ 476{
477 QStringList identifier; 477 QStringList identifier;
478 478
479 479
480 KRES::Manager<Resource>::ActiveIterator it; 480 KRES::Manager<Resource>::ActiveIterator it;
481 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { 481 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
482 if ( !(*it)->identifier().isEmpty() ) 482 if ( !(*it)->identifier().isEmpty() )
483 identifier.append( (*it)->identifier() ); 483 identifier.append( (*it)->identifier() );
484 } 484 }
485 485
486 return identifier.join( ":" ); 486 return identifier.join( ":" );
487} 487}
488 488
489Field::List AddressBook::fields( int category ) 489Field::List AddressBook::fields( int category )
490{ 490{
491 if ( d->mAllFields.isEmpty() ) { 491 if ( d->mAllFields.isEmpty() ) {
492 d->mAllFields = Field::allFields(); 492 d->mAllFields = Field::allFields();
493 } 493 }
494 494
495 if ( category == Field::All ) return d->mAllFields; 495 if ( category == Field::All ) return d->mAllFields;
496 496
497 Field::List result; 497 Field::List result;
498 Field::List::ConstIterator it; 498 Field::List::ConstIterator it;
499 for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) { 499 for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) {
500 if ( (*it)->category() & category ) result.append( *it ); 500 if ( (*it)->category() & category ) result.append( *it );
501 } 501 }
502 502
503 return result; 503 return result;
504} 504}
505 505
506bool AddressBook::addCustomField( const QString &label, int category, 506bool AddressBook::addCustomField( const QString &label, int category,
507 const QString &key, const QString &app ) 507 const QString &key, const QString &app )
508{ 508{
509 if ( d->mAllFields.isEmpty() ) { 509 if ( d->mAllFields.isEmpty() ) {
510 d->mAllFields = Field::allFields(); 510 d->mAllFields = Field::allFields();
511 } 511 }
512//US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app; 512//US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app;
513 QString a = app.isNull() ? KGlobal::getAppName() : app; 513 QString a = app.isNull() ? KGlobal::getAppName() : app;
514 514
515 QString k = key.isNull() ? label : key; 515 QString k = key.isNull() ? label : key;
516 516
517 Field *field = Field::createCustomField( label, category, k, a ); 517 Field *field = Field::createCustomField( label, category, k, a );
518 518
519 if ( !field ) return false; 519 if ( !field ) return false;
520 520
521 d->mAllFields.append( field ); 521 d->mAllFields.append( field );
522 522
523 return true; 523 return true;
524} 524}
525 525
526QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab ) 526QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab )
527{ 527{
528 if (!ab.d) return s; 528 if (!ab.d) return s;
529 529
530 return s << ab.d->mAddressees; 530 return s << ab.d->mAddressees;
531} 531}
532 532
533QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab ) 533QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab )
534{ 534{
535 if (!ab.d) return s; 535 if (!ab.d) return s;
536 536
537 s >> ab.d->mAddressees; 537 s >> ab.d->mAddressees;
538 538
539 return s; 539 return s;
540} 540}
541 541
542bool AddressBook::addResource( Resource *resource ) 542bool AddressBook::addResource( Resource *resource )
543{ 543{
544 qDebug("AddressBook::addResource 1"); 544 qDebug("AddressBook::addResource 1");
545 545
546 if ( !resource->open() ) { 546 if ( !resource->open() ) {
547 kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl; 547 kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl;
548 return false; 548 return false;
549 } 549 }
550 550
551 resource->setAddressBook( this ); 551 resource->setAddressBook( this );
552 552
553 d->mManager->add( resource ); 553 d->mManager->add( resource );
554 return true; 554 return true;
555} 555}
556 556
557bool AddressBook::removeResource( Resource *resource ) 557bool AddressBook::removeResource( Resource *resource )
558{ 558{
559 resource->close(); 559 resource->close();
560 560
561 if ( resource == standardResource() ) 561 if ( resource == standardResource() )
562 d->mManager->setStandardResource( 0 ); 562 d->mManager->setStandardResource( 0 );
563 563
564 resource->setAddressBook( 0 ); 564 resource->setAddressBook( 0 );
565 565
566 d->mManager->remove( resource ); 566 d->mManager->remove( resource );
567 return true; 567 return true;
568} 568}
569 569
570QPtrList<Resource> AddressBook::resources() 570QPtrList<Resource> AddressBook::resources()
571{ 571{
572 QPtrList<Resource> list; 572 QPtrList<Resource> list;
573 573
574// qDebug("AddressBook::resources() 1"); 574// qDebug("AddressBook::resources() 1");
575 575
576 KRES::Manager<Resource>::ActiveIterator it; 576 KRES::Manager<Resource>::ActiveIterator it;
577 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) 577 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it )
578 list.append( *it ); 578 list.append( *it );
579 579
580 return list; 580 return list;
581} 581}
582 582
583/*US 583/*US
584void AddressBook::setErrorHandler( ErrorHandler *handler ) 584void AddressBook::setErrorHandler( ErrorHandler *handler )
585{ 585{
586 delete d->mErrorHandler; 586 delete d->mErrorHandler;
587 d->mErrorHandler = handler; 587 d->mErrorHandler = handler;
588} 588}
589*/ 589*/
590 590
591void AddressBook::error( const QString& msg ) 591void AddressBook::error( const QString& msg )
592{ 592{
593/*US 593/*US
594 if ( !d->mErrorHandler ) // create default error handler 594 if ( !d->mErrorHandler ) // create default error handler
595 d->mErrorHandler = new ConsoleErrorHandler; 595 d->mErrorHandler = new ConsoleErrorHandler;
596 596
597 if ( d->mErrorHandler ) 597 if ( d->mErrorHandler )
598 d->mErrorHandler->error( msg ); 598 d->mErrorHandler->error( msg );
599 else 599 else
600 kdError(5700) << "no error handler defined" << endl; 600 kdError(5700) << "no error handler defined" << endl;
601*/ 601*/
602 kdDebug(5700) << "msg" << endl; 602 kdDebug(5700) << "msg" << endl;
603 qDebug(msg); 603 qDebug(msg);
604} 604}
605 605
606void AddressBook::deleteRemovedAddressees() 606void AddressBook::deleteRemovedAddressees()
607{ 607{
608 Addressee::List::Iterator it; 608 Addressee::List::Iterator it;
609 for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) { 609 for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) {
610 Resource *resource = (*it).resource(); 610 Resource *resource = (*it).resource();
611 if ( resource && !resource->readOnly() && resource->isOpen() ) 611 if ( resource && !resource->readOnly() && resource->isOpen() )
612 resource->removeAddressee( *it ); 612 resource->removeAddressee( *it );
613 } 613 }
614 614
615 d->mRemovedAddressees.clear(); 615 d->mRemovedAddressees.clear();
616} 616}
617 617
618void AddressBook::setStandardResource( Resource *resource ) 618void AddressBook::setStandardResource( Resource *resource )
619{ 619{
620// qDebug("AddressBook::setStandardResource 1"); 620// qDebug("AddressBook::setStandardResource 1");
621 d->mManager->setStandardResource( resource ); 621 d->mManager->setStandardResource( resource );
622} 622}
623 623
624Resource *AddressBook::standardResource() 624Resource *AddressBook::standardResource()
625{ 625{
626 return d->mManager->standardResource(); 626 return d->mManager->standardResource();
627} 627}
628 628
629KRES::Manager<Resource> *AddressBook::resourceManager() 629KRES::Manager<Resource> *AddressBook::resourceManager()
630{ 630{
631 return d->mManager; 631 return d->mManager;
632} 632}
633 633
634void AddressBook::cleanUp() 634void AddressBook::cleanUp()
635{ 635{
636 KRES::Manager<Resource>::ActiveIterator it; 636 KRES::Manager<Resource>::ActiveIterator it;
637 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { 637 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
638 if ( !(*it)->readOnly() && (*it)->isOpen() ) 638 if ( !(*it)->readOnly() && (*it)->isOpen() )
639 (*it)->cleanUp(); 639 (*it)->cleanUp();
640 } 640 }
641} 641}