summaryrefslogtreecommitdiffabout
path: root/kabc/addressbook.cpp
Unidiff
Diffstat (limited to 'kabc/addressbook.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressbook.cpp8
1 files changed, 3 insertions, 5 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index adb451f..5fb49eb 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -1,940 +1,938 @@
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 <libkcal/syncdefines.h> 45#include <libkcal/syncdefines.h>
46#include "addressbook.h" 46#include "addressbook.h"
47#include "resource.h" 47#include "resource.h"
48 48
49//US #include "addressbook.moc" 49//US #include "addressbook.moc"
50 50
51using namespace KABC; 51using namespace KABC;
52 52
53struct AddressBook::AddressBookData 53struct AddressBook::AddressBookData
54{ 54{
55 Addressee::List mAddressees; 55 Addressee::List mAddressees;
56 Addressee::List mRemovedAddressees; 56 Addressee::List mRemovedAddressees;
57 Field::List mAllFields; 57 Field::List mAllFields;
58 KConfig *mConfig; 58 KConfig *mConfig;
59 KRES::Manager<Resource> *mManager; 59 KRES::Manager<Resource> *mManager;
60//US ErrorHandler *mErrorHandler; 60//US ErrorHandler *mErrorHandler;
61}; 61};
62 62
63struct AddressBook::Iterator::IteratorData 63struct AddressBook::Iterator::IteratorData
64{ 64{
65 Addressee::List::Iterator mIt; 65 Addressee::List::Iterator mIt;
66}; 66};
67 67
68struct AddressBook::ConstIterator::ConstIteratorData 68struct AddressBook::ConstIterator::ConstIteratorData
69{ 69{
70 Addressee::List::ConstIterator mIt; 70 Addressee::List::ConstIterator mIt;
71}; 71};
72 72
73AddressBook::Iterator::Iterator() 73AddressBook::Iterator::Iterator()
74{ 74{
75 d = new IteratorData; 75 d = new IteratorData;
76} 76}
77 77
78AddressBook::Iterator::Iterator( const AddressBook::Iterator &i ) 78AddressBook::Iterator::Iterator( const AddressBook::Iterator &i )
79{ 79{
80 d = new IteratorData; 80 d = new IteratorData;
81 d->mIt = i.d->mIt; 81 d->mIt = i.d->mIt;
82} 82}
83 83
84AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i ) 84AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i )
85{ 85{
86 if( this == &i ) return *this; // guard against self assignment 86 if( this == &i ) return *this; // guard against self assignment
87 delete d; // delete the old data the Iterator was completely constructed before 87 delete d; // delete the old data the Iterator was completely constructed before
88 d = new IteratorData; 88 d = new IteratorData;
89 d->mIt = i.d->mIt; 89 d->mIt = i.d->mIt;
90 return *this; 90 return *this;
91} 91}
92 92
93AddressBook::Iterator::~Iterator() 93AddressBook::Iterator::~Iterator()
94{ 94{
95 delete d; 95 delete d;
96} 96}
97 97
98const Addressee &AddressBook::Iterator::operator*() const 98const Addressee &AddressBook::Iterator::operator*() const
99{ 99{
100 return *(d->mIt); 100 return *(d->mIt);
101} 101}
102 102
103Addressee &AddressBook::Iterator::operator*() 103Addressee &AddressBook::Iterator::operator*()
104{ 104{
105 return *(d->mIt); 105 return *(d->mIt);
106} 106}
107 107
108Addressee *AddressBook::Iterator::operator->() 108Addressee *AddressBook::Iterator::operator->()
109{ 109{
110 return &(*(d->mIt)); 110 return &(*(d->mIt));
111} 111}
112 112
113AddressBook::Iterator &AddressBook::Iterator::operator++() 113AddressBook::Iterator &AddressBook::Iterator::operator++()
114{ 114{
115 (d->mIt)++; 115 (d->mIt)++;
116 return *this; 116 return *this;
117} 117}
118 118
119AddressBook::Iterator &AddressBook::Iterator::operator++(int) 119AddressBook::Iterator &AddressBook::Iterator::operator++(int)
120{ 120{
121 (d->mIt)++; 121 (d->mIt)++;
122 return *this; 122 return *this;
123} 123}
124 124
125AddressBook::Iterator &AddressBook::Iterator::operator--() 125AddressBook::Iterator &AddressBook::Iterator::operator--()
126{ 126{
127 (d->mIt)--; 127 (d->mIt)--;
128 return *this; 128 return *this;
129} 129}
130 130
131AddressBook::Iterator &AddressBook::Iterator::operator--(int) 131AddressBook::Iterator &AddressBook::Iterator::operator--(int)
132{ 132{
133 (d->mIt)--; 133 (d->mIt)--;
134 return *this; 134 return *this;
135} 135}
136 136
137bool AddressBook::Iterator::operator==( const Iterator &it ) 137bool AddressBook::Iterator::operator==( const Iterator &it )
138{ 138{
139 return ( d->mIt == it.d->mIt ); 139 return ( d->mIt == it.d->mIt );
140} 140}
141 141
142bool AddressBook::Iterator::operator!=( const Iterator &it ) 142bool AddressBook::Iterator::operator!=( const Iterator &it )
143{ 143{
144 return ( d->mIt != it.d->mIt ); 144 return ( d->mIt != it.d->mIt );
145} 145}
146 146
147 147
148AddressBook::ConstIterator::ConstIterator() 148AddressBook::ConstIterator::ConstIterator()
149{ 149{
150 d = new ConstIteratorData; 150 d = new ConstIteratorData;
151} 151}
152 152
153AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i ) 153AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i )
154{ 154{
155 d = new ConstIteratorData; 155 d = new ConstIteratorData;
156 d->mIt = i.d->mIt; 156 d->mIt = i.d->mIt;
157} 157}
158 158
159AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i ) 159AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i )
160{ 160{
161 if( this == &i ) return *this; // guard for self assignment 161 if( this == &i ) return *this; // guard for self assignment
162 delete d; // delete the old data because the Iterator was really constructed before 162 delete d; // delete the old data because the Iterator was really constructed before
163 d = new ConstIteratorData; 163 d = new ConstIteratorData;
164 d->mIt = i.d->mIt; 164 d->mIt = i.d->mIt;
165 return *this; 165 return *this;
166} 166}
167 167
168AddressBook::ConstIterator::~ConstIterator() 168AddressBook::ConstIterator::~ConstIterator()
169{ 169{
170 delete d; 170 delete d;
171} 171}
172 172
173const Addressee &AddressBook::ConstIterator::operator*() const 173const Addressee &AddressBook::ConstIterator::operator*() const
174{ 174{
175 return *(d->mIt); 175 return *(d->mIt);
176} 176}
177 177
178const Addressee* AddressBook::ConstIterator::operator->() const 178const Addressee* AddressBook::ConstIterator::operator->() const
179{ 179{
180 return &(*(d->mIt)); 180 return &(*(d->mIt));
181} 181}
182 182
183AddressBook::ConstIterator &AddressBook::ConstIterator::operator++() 183AddressBook::ConstIterator &AddressBook::ConstIterator::operator++()
184{ 184{
185 (d->mIt)++; 185 (d->mIt)++;
186 return *this; 186 return *this;
187} 187}
188 188
189AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int) 189AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int)
190{ 190{
191 (d->mIt)++; 191 (d->mIt)++;
192 return *this; 192 return *this;
193} 193}
194 194
195AddressBook::ConstIterator &AddressBook::ConstIterator::operator--() 195AddressBook::ConstIterator &AddressBook::ConstIterator::operator--()
196{ 196{
197 (d->mIt)--; 197 (d->mIt)--;
198 return *this; 198 return *this;
199} 199}
200 200
201AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int) 201AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int)
202{ 202{
203 (d->mIt)--; 203 (d->mIt)--;
204 return *this; 204 return *this;
205} 205}
206 206
207bool AddressBook::ConstIterator::operator==( const ConstIterator &it ) 207bool AddressBook::ConstIterator::operator==( const ConstIterator &it )
208{ 208{
209 return ( d->mIt == it.d->mIt ); 209 return ( d->mIt == it.d->mIt );
210} 210}
211 211
212bool AddressBook::ConstIterator::operator!=( const ConstIterator &it ) 212bool AddressBook::ConstIterator::operator!=( const ConstIterator &it )
213{ 213{
214 return ( d->mIt != it.d->mIt ); 214 return ( d->mIt != it.d->mIt );
215} 215}
216 216
217 217
218AddressBook::AddressBook() 218AddressBook::AddressBook()
219{ 219{
220 init(0, "contact"); 220 init(0, "contact");
221} 221}
222 222
223AddressBook::AddressBook( const QString &config ) 223AddressBook::AddressBook( const QString &config )
224{ 224{
225 init(config, "contact"); 225 init(config, "contact");
226} 226}
227 227
228AddressBook::AddressBook( const QString &config, const QString &family ) 228AddressBook::AddressBook( const QString &config, const QString &family )
229{ 229{
230 init(config, family); 230 init(config, family);
231 231
232} 232}
233 233
234// the default family is "contact" 234// the default family is "contact"
235void AddressBook::init(const QString &config, const QString &family ) 235void AddressBook::init(const QString &config, const QString &family )
236{ 236{
237 blockLSEchange = false; 237 blockLSEchange = false;
238 d = new AddressBookData; 238 d = new AddressBookData;
239 QString fami = family; 239 QString fami = family;
240 qDebug("new ab ");
241 if (config != 0) { 240 if (config != 0) {
242 qDebug("config != 0 ");
243 if ( family == "syncContact" ) { 241 if ( family == "syncContact" ) {
244 qDebug("creating sync config "); 242 qDebug("creating sync config ");
245 fami = "contact"; 243 fami = "contact";
246 KConfig* con = new KConfig( locateLocal("config", "syncContactrc") ); 244 KConfig* con = new KConfig( locateLocal("config", "syncContactrc") );
247 con->setGroup( "General" ); 245 con->setGroup( "General" );
248 con->writeEntry( "ResourceKeys", QString("sync") ); 246 con->writeEntry( "ResourceKeys", QString("sync") );
249 con->writeEntry( "Standard", QString("sync") ); 247 con->writeEntry( "Standard", QString("sync") );
250 con->setGroup( "Resource_sync" ); 248 con->setGroup( "Resource_sync" );
251 con->writeEntry( "FileName", config ); 249 con->writeEntry( "FileName", config );
252 con->writeEntry( "FileFormat", QString("vcard") ); 250 con->writeEntry( "FileFormat", QString("vcard") );
253 con->writeEntry( "ResourceIdentifier", QString("sync") ); 251 con->writeEntry( "ResourceIdentifier", QString("sync") );
254 con->writeEntry( "ResourceName", QString("sync_res") ); 252 con->writeEntry( "ResourceName", QString("sync_res") );
255 if ( config.right(4) == ".xml" ) 253 if ( config.right(4) == ".xml" )
256 con->writeEntry( "ResourceType", QString("qtopia") ); 254 con->writeEntry( "ResourceType", QString("qtopia") );
257 else if ( config == "sharp" ) { 255 else if ( config == "sharp" ) {
258 con->writeEntry( "ResourceType", QString("sharp") ); 256 con->writeEntry( "ResourceType", QString("sharp") );
259 } else { 257 } else {
260 con->writeEntry( "ResourceType", QString("file") ); 258 con->writeEntry( "ResourceType", QString("file") );
261 } 259 }
262 //con->sync(); 260 //con->sync();
263 d->mConfig = con; 261 d->mConfig = con;
264 } 262 }
265 else 263 else
266 d->mConfig = new KConfig( locateLocal("config", config) ); 264 d->mConfig = new KConfig( locateLocal("config", config) );
267// qDebug("AddressBook::init 1 config=%s",config.latin1() ); 265// qDebug("AddressBook::init 1 config=%s",config.latin1() );
268 } 266 }
269 else { 267 else {
270 d->mConfig = 0; 268 d->mConfig = 0;
271// qDebug("AddressBook::init 1 config=0"); 269// qDebug("AddressBook::init 1 config=0");
272 } 270 }
273 271
274//US d->mErrorHandler = 0; 272//US d->mErrorHandler = 0;
275 d->mManager = new KRES::Manager<Resource>( fami, false ); 273 d->mManager = new KRES::Manager<Resource>( fami, false );
276 d->mManager->readConfig( d->mConfig ); 274 d->mManager->readConfig( d->mConfig );
277 if ( family == "syncContact" ) { 275 if ( family == "syncContact" ) {
278 KRES::Manager<Resource> *manager = d->mManager; 276 KRES::Manager<Resource> *manager = d->mManager;
279 KRES::Manager<Resource>::ActiveIterator it; 277 KRES::Manager<Resource>::ActiveIterator it;
280 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { 278 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
281 (*it)->setAddressBook( this ); 279 (*it)->setAddressBook( this );
282 if ( !(*it)->open() ) 280 if ( !(*it)->open() )
283 error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); 281 error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) );
284 } 282 }
285 Resource *res = standardResource(); 283 Resource *res = standardResource();
286 if ( !res ) { 284 if ( !res ) {
287 qDebug("ERROR: no standard resource"); 285 qDebug("ERROR: no standard resource");
288 res = manager->createResource( "file" ); 286 res = manager->createResource( "file" );
289 if ( res ) 287 if ( res )
290 { 288 {
291 addResource( res ); 289 addResource( res );
292 } 290 }
293 else 291 else
294 qDebug(" No resource available!!!"); 292 qDebug(" No resource available!!!");
295 } 293 }
296 setStandardResource( res ); 294 setStandardResource( res );
297 manager->writeConfig(); 295 manager->writeConfig();
298 } 296 }
299 addCustomField( i18n( "Department" ), KABC::Field::Organization, 297 addCustomField( i18n( "Department" ), KABC::Field::Organization,
300 "X-Department", "KADDRESSBOOK" ); 298 "X-Department", "KADDRESSBOOK" );
301 addCustomField( i18n( "Profession" ), KABC::Field::Organization, 299 addCustomField( i18n( "Profession" ), KABC::Field::Organization,
302 "X-Profession", "KADDRESSBOOK" ); 300 "X-Profession", "KADDRESSBOOK" );
303 addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, 301 addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization,
304 "X-AssistantsName", "KADDRESSBOOK" ); 302 "X-AssistantsName", "KADDRESSBOOK" );
305 addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, 303 addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization,
306 "X-ManagersName", "KADDRESSBOOK" ); 304 "X-ManagersName", "KADDRESSBOOK" );
307 addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, 305 addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal,
308 "X-SpousesName", "KADDRESSBOOK" ); 306 "X-SpousesName", "KADDRESSBOOK" );
309 addCustomField( i18n( "Office" ), KABC::Field::Personal, 307 addCustomField( i18n( "Office" ), KABC::Field::Personal,
310 "X-Office", "KADDRESSBOOK" ); 308 "X-Office", "KADDRESSBOOK" );
311 addCustomField( i18n( "IM Address" ), KABC::Field::Personal, 309 addCustomField( i18n( "IM Address" ), KABC::Field::Personal,
312 "X-IMAddress", "KADDRESSBOOK" ); 310 "X-IMAddress", "KADDRESSBOOK" );
313 addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, 311 addCustomField( i18n( "Anniversary" ), KABC::Field::Personal,
314 "X-Anniversary", "KADDRESSBOOK" ); 312 "X-Anniversary", "KADDRESSBOOK" );
315 313
316 //US added this field to become compatible with Opie/qtopia addressbook 314 //US added this field to become compatible with Opie/qtopia addressbook
317 // values can be "female" or "male" or "". An empty field represents undefined. 315 // values can be "female" or "male" or "". An empty field represents undefined.
318 addCustomField( i18n( "Gender" ), KABC::Field::Personal, 316 addCustomField( i18n( "Gender" ), KABC::Field::Personal,
319 "X-Gender", "KADDRESSBOOK" ); 317 "X-Gender", "KADDRESSBOOK" );
320 addCustomField( i18n( "Children" ), KABC::Field::Personal, 318 addCustomField( i18n( "Children" ), KABC::Field::Personal,
321 "X-Children", "KADDRESSBOOK" ); 319 "X-Children", "KADDRESSBOOK" );
322 addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, 320 addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal,
323 "X-FreeBusyUrl", "KADDRESSBOOK" ); 321 "X-FreeBusyUrl", "KADDRESSBOOK" );
324 addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, 322 addCustomField( i18n( "ExternalID" ), KABC::Field::Personal,
325 "X-ExternalID", "KADDRESSBOOK" ); 323 "X-ExternalID", "KADDRESSBOOK" );
326} 324}
327 325
328AddressBook::~AddressBook() 326AddressBook::~AddressBook()
329{ 327{
330 delete d->mConfig; d->mConfig = 0; 328 delete d->mConfig; d->mConfig = 0;
331 delete d->mManager; d->mManager = 0; 329 delete d->mManager; d->mManager = 0;
332//US delete d->mErrorHandler; d->mErrorHandler = 0; 330//US delete d->mErrorHandler; d->mErrorHandler = 0;
333 delete d; d = 0; 331 delete d; d = 0;
334} 332}
335 333
336bool AddressBook::load() 334bool AddressBook::load()
337{ 335{
338 336
339 337
340 clear(); 338 clear();
341 339
342 KRES::Manager<Resource>::ActiveIterator it; 340 KRES::Manager<Resource>::ActiveIterator it;
343 bool ok = true; 341 bool ok = true;
344 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) 342 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it )
345 if ( !(*it)->load() ) { 343 if ( !(*it)->load() ) {
346 error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); 344 error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) );
347 ok = false; 345 ok = false;
348 } 346 }
349 347
350 // mark all addressees as unchanged 348 // mark all addressees as unchanged
351 Addressee::List::Iterator addrIt; 349 Addressee::List::Iterator addrIt;
352 for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) { 350 for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) {
353 (*addrIt).setChanged( false ); 351 (*addrIt).setChanged( false );
354 QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" ); 352 QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" );
355 if ( !id.isEmpty() ) { 353 if ( !id.isEmpty() ) {
356 //qDebug("setId aa %s ", id.latin1()); 354 //qDebug("setId aa %s ", id.latin1());
357 (*addrIt).setIDStr(id ); 355 (*addrIt).setIDStr(id );
358 } 356 }
359 } 357 }
360 blockLSEchange = true; 358 blockLSEchange = true;
361 return ok; 359 return ok;
362} 360}
363 361
364bool AddressBook::save( Ticket *ticket ) 362bool AddressBook::save( Ticket *ticket )
365{ 363{
366 kdDebug(5700) << "AddressBook::save()"<< endl; 364 kdDebug(5700) << "AddressBook::save()"<< endl;
367 365
368 if ( ticket->resource() ) { 366 if ( ticket->resource() ) {
369 deleteRemovedAddressees(); 367 deleteRemovedAddressees();
370 return ticket->resource()->save( ticket ); 368 return ticket->resource()->save( ticket );
371 } 369 }
372 370
373 return false; 371 return false;
374} 372}
375bool AddressBook::saveAB() 373bool AddressBook::saveAB()
376{ 374{
377 bool ok = true; 375 bool ok = true;
378 376
379 deleteRemovedAddressees(); 377 deleteRemovedAddressees();
380 Iterator ait; 378 Iterator ait;
381 for ( ait = begin(); ait != end(); ++ait ) { 379 for ( ait = begin(); ait != end(); ++ait ) {
382 if ( !(*ait).IDStr().isEmpty() ) { 380 if ( !(*ait).IDStr().isEmpty() ) {
383 (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); 381 (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() );
384 } 382 }
385 } 383 }
386 KRES::Manager<Resource>::ActiveIterator it; 384 KRES::Manager<Resource>::ActiveIterator it;
387 KRES::Manager<Resource> *manager = d->mManager; 385 KRES::Manager<Resource> *manager = d->mManager;
388 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { 386 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
389 if ( !(*it)->readOnly() && (*it)->isOpen() ) { 387 if ( !(*it)->readOnly() && (*it)->isOpen() ) {
390 Ticket *ticket = requestSaveTicket( *it ); 388 Ticket *ticket = requestSaveTicket( *it );
391// qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); 389// qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() );
392 if ( !ticket ) { 390 if ( !ticket ) {
393 error( i18n( "Unable to save to resource '%1'. It is locked." ) 391 error( i18n( "Unable to save to resource '%1'. It is locked." )
394 .arg( (*it)->resourceName() ) ); 392 .arg( (*it)->resourceName() ) );
395 return false; 393 return false;
396 } 394 }
397 395
398 //if ( !save( ticket ) ) 396 //if ( !save( ticket ) )
399 if ( ticket->resource() ) { 397 if ( ticket->resource() ) {
400 if ( ! ticket->resource()->save( ticket ) ) 398 if ( ! ticket->resource()->save( ticket ) )
401 ok = false; 399 ok = false;
402 } else 400 } else
403 ok = false; 401 ok = false;
404 402
405 } 403 }
406 } 404 }
407 return ok; 405 return ok;
408} 406}
409 407
410AddressBook::Iterator AddressBook::begin() 408AddressBook::Iterator AddressBook::begin()
411{ 409{
412 Iterator it = Iterator(); 410 Iterator it = Iterator();
413 it.d->mIt = d->mAddressees.begin(); 411 it.d->mIt = d->mAddressees.begin();
414 return it; 412 return it;
415} 413}
416 414
417AddressBook::ConstIterator AddressBook::begin() const 415AddressBook::ConstIterator AddressBook::begin() const
418{ 416{
419 ConstIterator it = ConstIterator(); 417 ConstIterator it = ConstIterator();
420 it.d->mIt = d->mAddressees.begin(); 418 it.d->mIt = d->mAddressees.begin();
421 return it; 419 return it;
422} 420}
423 421
424AddressBook::Iterator AddressBook::end() 422AddressBook::Iterator AddressBook::end()
425{ 423{
426 Iterator it = Iterator(); 424 Iterator it = Iterator();
427 it.d->mIt = d->mAddressees.end(); 425 it.d->mIt = d->mAddressees.end();
428 return it; 426 return it;
429} 427}
430 428
431AddressBook::ConstIterator AddressBook::end() const 429AddressBook::ConstIterator AddressBook::end() const
432{ 430{
433 ConstIterator it = ConstIterator(); 431 ConstIterator it = ConstIterator();
434 it.d->mIt = d->mAddressees.end(); 432 it.d->mIt = d->mAddressees.end();
435 return it; 433 return it;
436} 434}
437 435
438void AddressBook::clear() 436void AddressBook::clear()
439{ 437{
440 d->mAddressees.clear(); 438 d->mAddressees.clear();
441} 439}
442 440
443Ticket *AddressBook::requestSaveTicket( Resource *resource ) 441Ticket *AddressBook::requestSaveTicket( Resource *resource )
444{ 442{
445 kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; 443 kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl;
446 444
447 if ( !resource ) 445 if ( !resource )
448 { 446 {
449 qDebug("AddressBook::requestSaveTicket no resource" ); 447 qDebug("AddressBook::requestSaveTicket no resource" );
450 resource = standardResource(); 448 resource = standardResource();
451 } 449 }
452 450
453 KRES::Manager<Resource>::ActiveIterator it; 451 KRES::Manager<Resource>::ActiveIterator it;
454 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { 452 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
455 if ( (*it) == resource ) { 453 if ( (*it) == resource ) {
456 if ( (*it)->readOnly() || !(*it)->isOpen() ) 454 if ( (*it)->readOnly() || !(*it)->isOpen() )
457 return 0; 455 return 0;
458 else 456 else
459 return (*it)->requestSaveTicket(); 457 return (*it)->requestSaveTicket();
460 } 458 }
461 } 459 }
462 460
463 return 0; 461 return 0;
464} 462}
465 463
466void AddressBook::insertAddressee( const Addressee &a, bool setRev ) 464void AddressBook::insertAddressee( const Addressee &a, bool setRev )
467{ 465{
468 if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { 466 if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) {
469 //qDebug("block insert "); 467 //qDebug("block insert ");
470 return; 468 return;
471 } 469 }
472 //qDebug("inserting.... %s ",a.uid().latin1() ); 470 //qDebug("inserting.... %s ",a.uid().latin1() );
473 bool found = false; 471 bool found = false;
474 Addressee::List::Iterator it; 472 Addressee::List::Iterator it;
475 for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { 473 for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) {
476 if ( a.uid() == (*it).uid() ) { 474 if ( a.uid() == (*it).uid() ) {
477 475
478 bool changed = false; 476 bool changed = false;
479 Addressee addr = a; 477 Addressee addr = a;
480 if ( addr != (*it) ) 478 if ( addr != (*it) )
481 changed = true; 479 changed = true;
482 480
483 (*it) = a; 481 (*it) = a;
484 if ( (*it).resource() == 0 ) 482 if ( (*it).resource() == 0 )
485 (*it).setResource( standardResource() ); 483 (*it).setResource( standardResource() );
486 484
487 if ( changed ) { 485 if ( changed ) {
488 if ( setRev ) { 486 if ( setRev ) {
489 487
490 // get rid of micro seconds 488 // get rid of micro seconds
491 QDateTime dt = QDateTime::currentDateTime(); 489 QDateTime dt = QDateTime::currentDateTime();
492 QTime t = dt.time(); 490 QTime t = dt.time();
493 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 491 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) );
494 (*it).setRevision( dt ); 492 (*it).setRevision( dt );
495 } 493 }
496 (*it).setChanged( true ); 494 (*it).setChanged( true );
497 } 495 }
498 496
499 found = true; 497 found = true;
500 } else { 498 } else {
501 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { 499 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) {
502 QString name = (*it).uid().mid( 19 ); 500 QString name = (*it).uid().mid( 19 );
503 Addressee b = a; 501 Addressee b = a;
504 QString id = b.getID( name ); 502 QString id = b.getID( name );
505 if ( ! id.isEmpty() ) { 503 if ( ! id.isEmpty() ) {
506 QString des = (*it).note(); 504 QString des = (*it).note();
507 int startN; 505 int startN;
508 if( (startN = des.find( id ) ) >= 0 ) { 506 if( (startN = des.find( id ) ) >= 0 ) {
509 int endN = des.find( ",", startN+1 ); 507 int endN = des.find( ",", startN+1 );
510 des = des.left( startN ) + des.mid( endN+1 ); 508 des = des.left( startN ) + des.mid( endN+1 );
511 (*it).setNote( des ); 509 (*it).setNote( des );
512 } 510 }
513 } 511 }
514 } 512 }
515 } 513 }
516 } 514 }
517 if ( found ) 515 if ( found )
518 return; 516 return;
519 d->mAddressees.append( a ); 517 d->mAddressees.append( a );
520 Addressee& addr = d->mAddressees.last(); 518 Addressee& addr = d->mAddressees.last();
521 if ( addr.resource() == 0 ) 519 if ( addr.resource() == 0 )
522 addr.setResource( standardResource() ); 520 addr.setResource( standardResource() );
523 521
524 addr.setChanged( true ); 522 addr.setChanged( true );
525} 523}
526 524
527void AddressBook::removeAddressee( const Addressee &a ) 525void AddressBook::removeAddressee( const Addressee &a )
528{ 526{
529 Iterator it; 527 Iterator it;
530 Iterator it2; 528 Iterator it2;
531 bool found = false; 529 bool found = false;
532 for ( it = begin(); it != end(); ++it ) { 530 for ( it = begin(); it != end(); ++it ) {
533 if ( a.uid() == (*it).uid() ) { 531 if ( a.uid() == (*it).uid() ) {
534 found = true; 532 found = true;
535 it2 = it; 533 it2 = it;
536 } else { 534 } else {
537 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { 535 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) {
538 QString name = (*it).uid().mid( 19 ); 536 QString name = (*it).uid().mid( 19 );
539 Addressee b = a; 537 Addressee b = a;
540 QString id = b.getID( name ); 538 QString id = b.getID( name );
541 if ( ! id.isEmpty() ) { 539 if ( ! id.isEmpty() ) {
542 QString des = (*it).note(); 540 QString des = (*it).note();
543 if( des.find( id ) < 0 ) { 541 if( des.find( id ) < 0 ) {
544 des += id + ","; 542 des += id + ",";
545 (*it).setNote( des ); 543 (*it).setNote( des );
546 } 544 }
547 } 545 }
548 } 546 }
549 547
550 } 548 }
551 } 549 }
552 550
553 if ( found ) 551 if ( found )
554 removeAddressee( it2 ); 552 removeAddressee( it2 );
555 553
556} 554}
557 555
558void AddressBook::removeSyncAddressees( bool removeDeleted ) 556void AddressBook::removeSyncAddressees( bool removeDeleted )
559{ 557{
560 Iterator it = begin(); 558 Iterator it = begin();
561 Iterator it2 ; 559 Iterator it2 ;
562 QDateTime dt ( QDate( 2004,1,1) ); 560 QDateTime dt ( QDate( 2004,1,1) );
563 while ( it != end() ) { 561 while ( it != end() ) {
564 (*it).setRevision( dt ); 562 (*it).setRevision( dt );
565 (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); 563 (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" );
566 (*it).setIDStr(""); 564 (*it).setIDStr("");
567 if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { 565 if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) {
568 it2 = it; 566 it2 = it;
569 //qDebug("removing %s ",(*it).uid().latin1() ); 567 //qDebug("removing %s ",(*it).uid().latin1() );
570 ++it; 568 ++it;
571 removeAddressee( it2 ); 569 removeAddressee( it2 );
572 } else { 570 } else {
573 //qDebug("skipping %s ",(*it).uid().latin1() ); 571 //qDebug("skipping %s ",(*it).uid().latin1() );
574 ++it; 572 ++it;
575 } 573 }
576 } 574 }
577 deleteRemovedAddressees(); 575 deleteRemovedAddressees();
578} 576}
579 577
580void AddressBook::removeAddressee( const Iterator &it ) 578void AddressBook::removeAddressee( const Iterator &it )
581{ 579{
582 d->mRemovedAddressees.append( (*it) ); 580 d->mRemovedAddressees.append( (*it) );
583 d->mAddressees.remove( it.d->mIt ); 581 d->mAddressees.remove( it.d->mIt );
584} 582}
585 583
586AddressBook::Iterator AddressBook::find( const Addressee &a ) 584AddressBook::Iterator AddressBook::find( const Addressee &a )
587{ 585{
588 Iterator it; 586 Iterator it;
589 for ( it = begin(); it != end(); ++it ) { 587 for ( it = begin(); it != end(); ++it ) {
590 if ( a.uid() == (*it).uid() ) { 588 if ( a.uid() == (*it).uid() ) {
591 return it; 589 return it;
592 } 590 }
593 } 591 }
594 return end(); 592 return end();
595} 593}
596 594
597Addressee AddressBook::findByUid( const QString &uid ) 595Addressee AddressBook::findByUid( const QString &uid )
598{ 596{
599 Iterator it; 597 Iterator it;
600 for ( it = begin(); it != end(); ++it ) { 598 for ( it = begin(); it != end(); ++it ) {
601 if ( uid == (*it).uid() ) { 599 if ( uid == (*it).uid() ) {
602 return *it; 600 return *it;
603 } 601 }
604 } 602 }
605 return Addressee(); 603 return Addressee();
606} 604}
607void AddressBook::preExternSync( AddressBook* aBook, const QString& csd ) 605void AddressBook::preExternSync( AddressBook* aBook, const QString& csd )
608{ 606{
609 qDebug("AddressBook::preExternSync "); 607 //qDebug("AddressBook::preExternSync ");
610 AddressBook::Iterator it; 608 AddressBook::Iterator it;
611 for ( it = begin(); it != end(); ++it ) { 609 for ( it = begin(); it != end(); ++it ) {
612 (*it).setID( csd, (*it).externalUID() ); 610 (*it).setID( csd, (*it).externalUID() );
613 (*it).computeCsum( csd ); 611 (*it).computeCsum( csd );
614 } 612 }
615 mergeAB( aBook ,csd ); 613 mergeAB( aBook ,csd );
616} 614}
617void AddressBook::postExternSync( AddressBook* aBook , const QString& csd) 615void AddressBook::postExternSync( AddressBook* aBook , const QString& csd)
618{ 616{
619 qDebug("AddressBook::postExternSync "); 617 //qDebug("AddressBook::postExternSync ");
620 AddressBook::Iterator it; 618 AddressBook::Iterator it;
621 for ( it = begin(); it != end(); ++it ) { 619 for ( it = begin(); it != end(); ++it ) {
622 qDebug("check uid %s ", (*it).uid().latin1() ); 620 // qDebug("check uid %s ", (*it).uid().latin1() );
623 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || 621 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ||
624 (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) { 622 (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) {
625 Addressee ad = aBook->findByUid( ( (*it).uid() )); 623 Addressee ad = aBook->findByUid( ( (*it).uid() ));
626 if ( ad.isEmpty() ) { 624 if ( ad.isEmpty() ) {
627 qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1()); 625 qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1());
628 } else { 626 } else {
629 (*it).computeCsum( csd ); 627 (*it).computeCsum( csd );
630 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) 628 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID )
631 ad.setID( csd, (*it).externalUID() ); 629 ad.setID( csd, (*it).externalUID() );
632 ad.setCsum( csd, (*it).getCsum( csd ) ); 630 ad.setCsum( csd, (*it).getCsum( csd ) );
633 aBook->insertAddressee( ad ); 631 aBook->insertAddressee( ad );
634 } 632 }
635 } 633 }
636 } 634 }
637} 635}
638 636
639bool AddressBook::containsExternalUid( const QString& uid ) 637bool AddressBook::containsExternalUid( const QString& uid )
640{ 638{
641 Iterator it; 639 Iterator it;
642 for ( it = begin(); it != end(); ++it ) { 640 for ( it = begin(); it != end(); ++it ) {
643 if ( uid == (*it).externalUID( ) ) 641 if ( uid == (*it).externalUID( ) )
644 return true; 642 return true;
645 } 643 }
646 return false; 644 return false;
647} 645}
648Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) 646Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile )
649{ 647{
650 Iterator it; 648 Iterator it;
651 for ( it = begin(); it != end(); ++it ) { 649 for ( it = begin(); it != end(); ++it ) {
652 if ( uid == (*it).getID( profile ) ) 650 if ( uid == (*it).getID( profile ) )
653 return (*it); 651 return (*it);
654 } 652 }
655 return Addressee(); 653 return Addressee();
656} 654}
657void AddressBook::mergeAB( AddressBook *aBook, const QString& profile ) 655void AddressBook::mergeAB( AddressBook *aBook, const QString& profile )
658{ 656{
659 Iterator it; 657 Iterator it;
660 Addressee ad; 658 Addressee ad;
661 for ( it = begin(); it != end(); ++it ) { 659 for ( it = begin(); it != end(); ++it ) {
662 ad = aBook->findByExternUid( (*it).externalUID(), profile ); 660 ad = aBook->findByExternUid( (*it).externalUID(), profile );
663 if ( !ad.isEmpty() ) { 661 if ( !ad.isEmpty() ) {
664 (*it).mergeContact( ad ); 662 (*it).mergeContact( ad );
665 } 663 }
666 } 664 }
667#if 0 665#if 0
668 // test only 666 // test only
669 for ( it = begin(); it != end(); ++it ) { 667 for ( it = begin(); it != end(); ++it ) {
670 668
671 qDebug("uid %s ", (*it).uid().latin1()); 669 qDebug("uid %s ", (*it).uid().latin1());
672 } 670 }
673#endif 671#endif
674} 672}
675 673
676#if 0 674#if 0
677Addressee::List AddressBook::getExternLastSyncAddressees() 675Addressee::List AddressBook::getExternLastSyncAddressees()
678{ 676{
679 Addressee::List results; 677 Addressee::List results;
680 678
681 Iterator it; 679 Iterator it;
682 for ( it = begin(); it != end(); ++it ) { 680 for ( it = begin(); it != end(); ++it ) {
683 if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { 681 if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) {
684 if ( (*it).familyName().left(4) == "!E: " ) 682 if ( (*it).familyName().left(4) == "!E: " )
685 results.append( *it ); 683 results.append( *it );
686 } 684 }
687 } 685 }
688 686
689 return results; 687 return results;
690} 688}
691#endif 689#endif
692void AddressBook::resetTempSyncStat() 690void AddressBook::resetTempSyncStat()
693{ 691{
694 Iterator it; 692 Iterator it;
695 for ( it = begin(); it != end(); ++it ) { 693 for ( it = begin(); it != end(); ++it ) {
696 (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); 694 (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL );
697 } 695 }
698 696
699} 697}
700 698
701QStringList AddressBook:: uidList() 699QStringList AddressBook:: uidList()
702{ 700{
703 QStringList results; 701 QStringList results;
704 Iterator it; 702 Iterator it;
705 for ( it = begin(); it != end(); ++it ) { 703 for ( it = begin(); it != end(); ++it ) {
706 results.append( (*it).uid() ); 704 results.append( (*it).uid() );
707 } 705 }
708 return results; 706 return results;
709} 707}
710 708
711 709
712Addressee::List AddressBook::allAddressees() 710Addressee::List AddressBook::allAddressees()
713{ 711{
714 return d->mAddressees; 712 return d->mAddressees;
715 713
716} 714}
717 715
718Addressee::List AddressBook::findByName( const QString &name ) 716Addressee::List AddressBook::findByName( const QString &name )
719{ 717{
720 Addressee::List results; 718 Addressee::List results;
721 719
722 Iterator it; 720 Iterator it;
723 for ( it = begin(); it != end(); ++it ) { 721 for ( it = begin(); it != end(); ++it ) {
724 if ( name == (*it).realName() ) { 722 if ( name == (*it).realName() ) {
725 results.append( *it ); 723 results.append( *it );
726 } 724 }
727 } 725 }
728 726
729 return results; 727 return results;
730} 728}
731 729
732Addressee::List AddressBook::findByEmail( const QString &email ) 730Addressee::List AddressBook::findByEmail( const QString &email )
733{ 731{
734 Addressee::List results; 732 Addressee::List results;
735 QStringList mailList; 733 QStringList mailList;
736 734
737 Iterator it; 735 Iterator it;
738 for ( it = begin(); it != end(); ++it ) { 736 for ( it = begin(); it != end(); ++it ) {
739 mailList = (*it).emails(); 737 mailList = (*it).emails();
740 for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { 738 for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) {
741 if ( email == (*ite) ) { 739 if ( email == (*ite) ) {
742 results.append( *it ); 740 results.append( *it );
743 } 741 }
744 } 742 }
745 } 743 }
746 744
747 return results; 745 return results;
748} 746}
749 747
750Addressee::List AddressBook::findByCategory( const QString &category ) 748Addressee::List AddressBook::findByCategory( const QString &category )
751{ 749{
752 Addressee::List results; 750 Addressee::List results;
753 751
754 Iterator it; 752 Iterator it;
755 for ( it = begin(); it != end(); ++it ) { 753 for ( it = begin(); it != end(); ++it ) {
756 if ( (*it).hasCategory( category) ) { 754 if ( (*it).hasCategory( category) ) {
757 results.append( *it ); 755 results.append( *it );
758 } 756 }
759 } 757 }
760 758
761 return results; 759 return results;
762} 760}
763 761
764void AddressBook::dump() const 762void AddressBook::dump() const
765{ 763{
766 kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; 764 kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl;
767 765
768 ConstIterator it; 766 ConstIterator it;
769 for( it = begin(); it != end(); ++it ) { 767 for( it = begin(); it != end(); ++it ) {
770 (*it).dump(); 768 (*it).dump();
771 } 769 }
772 770
773 kdDebug(5700) << "AddressBook::dump() --- end ---" << endl; 771 kdDebug(5700) << "AddressBook::dump() --- end ---" << endl;
774} 772}
775 773
776QString AddressBook::identifier() 774QString AddressBook::identifier()
777{ 775{
778 QStringList identifier; 776 QStringList identifier;
779 777
780 778
781 KRES::Manager<Resource>::ActiveIterator it; 779 KRES::Manager<Resource>::ActiveIterator it;
782 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { 780 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
783 if ( !(*it)->identifier().isEmpty() ) 781 if ( !(*it)->identifier().isEmpty() )
784 identifier.append( (*it)->identifier() ); 782 identifier.append( (*it)->identifier() );
785 } 783 }
786 784
787 return identifier.join( ":" ); 785 return identifier.join( ":" );
788} 786}
789 787
790Field::List AddressBook::fields( int category ) 788Field::List AddressBook::fields( int category )
791{ 789{
792 if ( d->mAllFields.isEmpty() ) { 790 if ( d->mAllFields.isEmpty() ) {
793 d->mAllFields = Field::allFields(); 791 d->mAllFields = Field::allFields();
794 } 792 }
795 793
796 if ( category == Field::All ) return d->mAllFields; 794 if ( category == Field::All ) return d->mAllFields;
797 795
798 Field::List result; 796 Field::List result;
799 Field::List::ConstIterator it; 797 Field::List::ConstIterator it;
800 for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) { 798 for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) {
801 if ( (*it)->category() & category ) result.append( *it ); 799 if ( (*it)->category() & category ) result.append( *it );
802 } 800 }
803 801
804 return result; 802 return result;
805} 803}
806 804
807bool AddressBook::addCustomField( const QString &label, int category, 805bool AddressBook::addCustomField( const QString &label, int category,
808 const QString &key, const QString &app ) 806 const QString &key, const QString &app )
809{ 807{
810 if ( d->mAllFields.isEmpty() ) { 808 if ( d->mAllFields.isEmpty() ) {
811 d->mAllFields = Field::allFields(); 809 d->mAllFields = Field::allFields();
812 } 810 }
813//US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app; 811//US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app;
814 QString a = app.isNull() ? KGlobal::getAppName() : app; 812 QString a = app.isNull() ? KGlobal::getAppName() : app;
815 813
816 QString k = key.isNull() ? label : key; 814 QString k = key.isNull() ? label : key;
817 815
818 Field *field = Field::createCustomField( label, category, k, a ); 816 Field *field = Field::createCustomField( label, category, k, a );
819 817
820 if ( !field ) return false; 818 if ( !field ) return false;
821 819
822 d->mAllFields.append( field ); 820 d->mAllFields.append( field );
823 821
824 return true; 822 return true;
825} 823}
826 824
827QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab ) 825QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab )
828{ 826{
829 if (!ab.d) return s; 827 if (!ab.d) return s;
830 828
831 return s << ab.d->mAddressees; 829 return s << ab.d->mAddressees;
832} 830}
833 831
834QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab ) 832QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab )
835{ 833{
836 if (!ab.d) return s; 834 if (!ab.d) return s;
837 835
838 s >> ab.d->mAddressees; 836 s >> ab.d->mAddressees;
839 837
840 return s; 838 return s;
841} 839}
842 840
843bool AddressBook::addResource( Resource *resource ) 841bool AddressBook::addResource( Resource *resource )
844{ 842{
845 if ( !resource->open() ) { 843 if ( !resource->open() ) {
846 kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl; 844 kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl;
847 return false; 845 return false;
848 } 846 }
849 847
850 resource->setAddressBook( this ); 848 resource->setAddressBook( this );
851 849
852 d->mManager->add( resource ); 850 d->mManager->add( resource );
853 return true; 851 return true;
854} 852}
855 853
856bool AddressBook::removeResource( Resource *resource ) 854bool AddressBook::removeResource( Resource *resource )
857{ 855{
858 resource->close(); 856 resource->close();
859 857
860 if ( resource == standardResource() ) 858 if ( resource == standardResource() )
861 d->mManager->setStandardResource( 0 ); 859 d->mManager->setStandardResource( 0 );
862 860
863 resource->setAddressBook( 0 ); 861 resource->setAddressBook( 0 );
864 862
865 d->mManager->remove( resource ); 863 d->mManager->remove( resource );
866 return true; 864 return true;
867} 865}
868 866
869QPtrList<Resource> AddressBook::resources() 867QPtrList<Resource> AddressBook::resources()
870{ 868{
871 QPtrList<Resource> list; 869 QPtrList<Resource> list;
872 870
873// qDebug("AddressBook::resources() 1"); 871// qDebug("AddressBook::resources() 1");
874 872
875 KRES::Manager<Resource>::ActiveIterator it; 873 KRES::Manager<Resource>::ActiveIterator it;
876 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) 874 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it )
877 list.append( *it ); 875 list.append( *it );
878 876
879 return list; 877 return list;
880} 878}
881 879
882/*US 880/*US
883void AddressBook::setErrorHandler( ErrorHandler *handler ) 881void AddressBook::setErrorHandler( ErrorHandler *handler )
884{ 882{
885 delete d->mErrorHandler; 883 delete d->mErrorHandler;
886 d->mErrorHandler = handler; 884 d->mErrorHandler = handler;
887} 885}
888*/ 886*/
889 887
890void AddressBook::error( const QString& msg ) 888void AddressBook::error( const QString& msg )
891{ 889{
892/*US 890/*US
893 if ( !d->mErrorHandler ) // create default error handler 891 if ( !d->mErrorHandler ) // create default error handler
894 d->mErrorHandler = new ConsoleErrorHandler; 892 d->mErrorHandler = new ConsoleErrorHandler;
895 893
896 if ( d->mErrorHandler ) 894 if ( d->mErrorHandler )
897 d->mErrorHandler->error( msg ); 895 d->mErrorHandler->error( msg );
898 else 896 else
899 kdError(5700) << "no error handler defined" << endl; 897 kdError(5700) << "no error handler defined" << endl;
900*/ 898*/
901 kdDebug(5700) << "msg" << endl; 899 kdDebug(5700) << "msg" << endl;
902 qDebug(msg); 900 qDebug(msg);
903} 901}
904 902
905void AddressBook::deleteRemovedAddressees() 903void AddressBook::deleteRemovedAddressees()
906{ 904{
907 Addressee::List::Iterator it; 905 Addressee::List::Iterator it;
908 for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) { 906 for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) {
909 Resource *resource = (*it).resource(); 907 Resource *resource = (*it).resource();
910 if ( resource && !resource->readOnly() && resource->isOpen() ) 908 if ( resource && !resource->readOnly() && resource->isOpen() )
911 resource->removeAddressee( *it ); 909 resource->removeAddressee( *it );
912 } 910 }
913 911
914 d->mRemovedAddressees.clear(); 912 d->mRemovedAddressees.clear();
915} 913}
916 914
917void AddressBook::setStandardResource( Resource *resource ) 915void AddressBook::setStandardResource( Resource *resource )
918{ 916{
919// qDebug("AddressBook::setStandardResource 1"); 917// qDebug("AddressBook::setStandardResource 1");
920 d->mManager->setStandardResource( resource ); 918 d->mManager->setStandardResource( resource );
921} 919}
922 920
923Resource *AddressBook::standardResource() 921Resource *AddressBook::standardResource()
924{ 922{
925 return d->mManager->standardResource(); 923 return d->mManager->standardResource();
926} 924}
927 925
928KRES::Manager<Resource> *AddressBook::resourceManager() 926KRES::Manager<Resource> *AddressBook::resourceManager()
929{ 927{
930 return d->mManager; 928 return d->mManager;
931} 929}
932 930
933void AddressBook::cleanUp() 931void AddressBook::cleanUp()
934{ 932{
935 KRES::Manager<Resource>::ActiveIterator it; 933 KRES::Manager<Resource>::ActiveIterator it;
936 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { 934 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
937 if ( !(*it)->readOnly() && (*it)->isOpen() ) 935 if ( !(*it)->readOnly() && (*it)->isOpen() )
938 (*it)->cleanUp(); 936 (*it)->cleanUp();
939 } 937 }
940} 938}