summaryrefslogtreecommitdiffabout
path: root/kabc/addressbook.cpp
Unidiff
Diffstat (limited to 'kabc/addressbook.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressbook.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index 70eda1b..9332e21 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -1,743 +1,770 @@
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 "addressbook.h" 46#include "addressbook.h"
46#include "resource.h" 47#include "resource.h"
47 48
48//US #include "addressbook.moc" 49//US #include "addressbook.moc"
49 50
50using namespace KABC; 51using namespace KABC;
51 52
52struct AddressBook::AddressBookData 53struct AddressBook::AddressBookData
53{ 54{
54 Addressee::List mAddressees; 55 Addressee::List mAddressees;
55 Addressee::List mRemovedAddressees; 56 Addressee::List mRemovedAddressees;
56 Field::List mAllFields; 57 Field::List mAllFields;
57 KConfig *mConfig; 58 KConfig *mConfig;
58 KRES::Manager<Resource> *mManager; 59 KRES::Manager<Resource> *mManager;
59//US ErrorHandler *mErrorHandler; 60//US ErrorHandler *mErrorHandler;
60}; 61};
61 62
62struct AddressBook::Iterator::IteratorData 63struct AddressBook::Iterator::IteratorData
63{ 64{
64 Addressee::List::Iterator mIt; 65 Addressee::List::Iterator mIt;
65}; 66};
66 67
67struct AddressBook::ConstIterator::ConstIteratorData 68struct AddressBook::ConstIterator::ConstIteratorData
68{ 69{
69 Addressee::List::ConstIterator mIt; 70 Addressee::List::ConstIterator mIt;
70}; 71};
71 72
72AddressBook::Iterator::Iterator() 73AddressBook::Iterator::Iterator()
73{ 74{
74 d = new IteratorData; 75 d = new IteratorData;
75} 76}
76 77
77AddressBook::Iterator::Iterator( const AddressBook::Iterator &i ) 78AddressBook::Iterator::Iterator( const AddressBook::Iterator &i )
78{ 79{
79 d = new IteratorData; 80 d = new IteratorData;
80 d->mIt = i.d->mIt; 81 d->mIt = i.d->mIt;
81} 82}
82 83
83AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i ) 84AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i )
84{ 85{
85 if( this == &i ) return *this; // guard against self assignment 86 if( this == &i ) return *this; // guard against self assignment
86 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
87 d = new IteratorData; 88 d = new IteratorData;
88 d->mIt = i.d->mIt; 89 d->mIt = i.d->mIt;
89 return *this; 90 return *this;
90} 91}
91 92
92AddressBook::Iterator::~Iterator() 93AddressBook::Iterator::~Iterator()
93{ 94{
94 delete d; 95 delete d;
95} 96}
96 97
97const Addressee &AddressBook::Iterator::operator*() const 98const Addressee &AddressBook::Iterator::operator*() const
98{ 99{
99 return *(d->mIt); 100 return *(d->mIt);
100} 101}
101 102
102Addressee &AddressBook::Iterator::operator*() 103Addressee &AddressBook::Iterator::operator*()
103{ 104{
104 return *(d->mIt); 105 return *(d->mIt);
105} 106}
106 107
107Addressee *AddressBook::Iterator::operator->() 108Addressee *AddressBook::Iterator::operator->()
108{ 109{
109 return &(*(d->mIt)); 110 return &(*(d->mIt));
110} 111}
111 112
112AddressBook::Iterator &AddressBook::Iterator::operator++() 113AddressBook::Iterator &AddressBook::Iterator::operator++()
113{ 114{
114 (d->mIt)++; 115 (d->mIt)++;
115 return *this; 116 return *this;
116} 117}
117 118
118AddressBook::Iterator &AddressBook::Iterator::operator++(int) 119AddressBook::Iterator &AddressBook::Iterator::operator++(int)
119{ 120{
120 (d->mIt)++; 121 (d->mIt)++;
121 return *this; 122 return *this;
122} 123}
123 124
124AddressBook::Iterator &AddressBook::Iterator::operator--() 125AddressBook::Iterator &AddressBook::Iterator::operator--()
125{ 126{
126 (d->mIt)--; 127 (d->mIt)--;
127 return *this; 128 return *this;
128} 129}
129 130
130AddressBook::Iterator &AddressBook::Iterator::operator--(int) 131AddressBook::Iterator &AddressBook::Iterator::operator--(int)
131{ 132{
132 (d->mIt)--; 133 (d->mIt)--;
133 return *this; 134 return *this;
134} 135}
135 136
136bool AddressBook::Iterator::operator==( const Iterator &it ) 137bool AddressBook::Iterator::operator==( const Iterator &it )
137{ 138{
138 return ( d->mIt == it.d->mIt ); 139 return ( d->mIt == it.d->mIt );
139} 140}
140 141
141bool AddressBook::Iterator::operator!=( const Iterator &it ) 142bool AddressBook::Iterator::operator!=( const Iterator &it )
142{ 143{
143 return ( d->mIt != it.d->mIt ); 144 return ( d->mIt != it.d->mIt );
144} 145}
145 146
146 147
147AddressBook::ConstIterator::ConstIterator() 148AddressBook::ConstIterator::ConstIterator()
148{ 149{
149 d = new ConstIteratorData; 150 d = new ConstIteratorData;
150} 151}
151 152
152AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i ) 153AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i )
153{ 154{
154 d = new ConstIteratorData; 155 d = new ConstIteratorData;
155 d->mIt = i.d->mIt; 156 d->mIt = i.d->mIt;
156} 157}
157 158
158AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i ) 159AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i )
159{ 160{
160 if( this == &i ) return *this; // guard for self assignment 161 if( this == &i ) return *this; // guard for self assignment
161 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
162 d = new ConstIteratorData; 163 d = new ConstIteratorData;
163 d->mIt = i.d->mIt; 164 d->mIt = i.d->mIt;
164 return *this; 165 return *this;
165} 166}
166 167
167AddressBook::ConstIterator::~ConstIterator() 168AddressBook::ConstIterator::~ConstIterator()
168{ 169{
169 delete d; 170 delete d;
170} 171}
171 172
172const Addressee &AddressBook::ConstIterator::operator*() const 173const Addressee &AddressBook::ConstIterator::operator*() const
173{ 174{
174 return *(d->mIt); 175 return *(d->mIt);
175} 176}
176 177
177const Addressee* AddressBook::ConstIterator::operator->() const 178const Addressee* AddressBook::ConstIterator::operator->() const
178{ 179{
179 return &(*(d->mIt)); 180 return &(*(d->mIt));
180} 181}
181 182
182AddressBook::ConstIterator &AddressBook::ConstIterator::operator++() 183AddressBook::ConstIterator &AddressBook::ConstIterator::operator++()
183{ 184{
184 (d->mIt)++; 185 (d->mIt)++;
185 return *this; 186 return *this;
186} 187}
187 188
188AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int) 189AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int)
189{ 190{
190 (d->mIt)++; 191 (d->mIt)++;
191 return *this; 192 return *this;
192} 193}
193 194
194AddressBook::ConstIterator &AddressBook::ConstIterator::operator--() 195AddressBook::ConstIterator &AddressBook::ConstIterator::operator--()
195{ 196{
196 (d->mIt)--; 197 (d->mIt)--;
197 return *this; 198 return *this;
198} 199}
199 200
200AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int) 201AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int)
201{ 202{
202 (d->mIt)--; 203 (d->mIt)--;
203 return *this; 204 return *this;
204} 205}
205 206
206bool AddressBook::ConstIterator::operator==( const ConstIterator &it ) 207bool AddressBook::ConstIterator::operator==( const ConstIterator &it )
207{ 208{
208 return ( d->mIt == it.d->mIt ); 209 return ( d->mIt == it.d->mIt );
209} 210}
210 211
211bool AddressBook::ConstIterator::operator!=( const ConstIterator &it ) 212bool AddressBook::ConstIterator::operator!=( const ConstIterator &it )
212{ 213{
213 return ( d->mIt != it.d->mIt ); 214 return ( d->mIt != it.d->mIt );
214} 215}
215 216
216 217
217AddressBook::AddressBook() 218AddressBook::AddressBook()
218{ 219{
219 init(0, "contact"); 220 init(0, "contact");
220} 221}
221 222
222AddressBook::AddressBook( const QString &config ) 223AddressBook::AddressBook( const QString &config )
223{ 224{
224 init(config, "contact"); 225 init(config, "contact");
225} 226}
226 227
227AddressBook::AddressBook( const QString &config, const QString &family ) 228AddressBook::AddressBook( const QString &config, const QString &family )
228{ 229{
229 init(config, family); 230 init(config, family);
230 231
231} 232}
232 233
233// the default family is "contact" 234// the default family is "contact"
234void AddressBook::init(const QString &config, const QString &family ) 235void AddressBook::init(const QString &config, const QString &family )
235{ 236{
236 d = new AddressBookData; 237 d = new AddressBookData;
237 QString fami = family; 238 QString fami = family;
238 qDebug("new ab "); 239 qDebug("new ab ");
239 if (config != 0) { 240 if (config != 0) {
240 qDebug("config != 0 "); 241 qDebug("config != 0 ");
241 if ( family == "syncContact" ) { 242 if ( family == "syncContact" ) {
242 qDebug("creating sync config "); 243 qDebug("creating sync config ");
243 fami = "contact"; 244 fami = "contact";
244 KConfig* con = new KConfig( locateLocal("config", "syncContactrc") ); 245 KConfig* con = new KConfig( locateLocal("config", "syncContactrc") );
245 con->setGroup( "General" ); 246 con->setGroup( "General" );
246 con->writeEntry( "ResourceKeys", QString("sync") ); 247 con->writeEntry( "ResourceKeys", QString("sync") );
247 con->writeEntry( "Standard", QString("sync") ); 248 con->writeEntry( "Standard", QString("sync") );
248 con->setGroup( "Resource_sync" ); 249 con->setGroup( "Resource_sync" );
249 con->writeEntry( "FileFormat", QString("vcard") ); 250 con->writeEntry( "FileFormat", QString("vcard") );
250 con->writeEntry( "FileName", config ); 251 con->writeEntry( "FileName", config );
251 con->writeEntry( "ResourceIdentifier", QString("sync") ); 252 con->writeEntry( "ResourceIdentifier", QString("sync") );
252 con->writeEntry( "ResourceName", QString("sync_res") ); 253 con->writeEntry( "ResourceName", QString("sync_res") );
253 con->writeEntry( "ResourceType", QString("file") ); 254 con->writeEntry( "ResourceType", QString("file") );
254 //con->sync(); 255 //con->sync();
255 d->mConfig = con; 256 d->mConfig = con;
256 } 257 }
257 else 258 else
258 d->mConfig = new KConfig( locateLocal("config", config) ); 259 d->mConfig = new KConfig( locateLocal("config", config) );
259// qDebug("AddressBook::init 1 config=%s",config.latin1() ); 260// qDebug("AddressBook::init 1 config=%s",config.latin1() );
260 } 261 }
261 else { 262 else {
262 d->mConfig = 0; 263 d->mConfig = 0;
263// qDebug("AddressBook::init 1 config=0"); 264// qDebug("AddressBook::init 1 config=0");
264 } 265 }
265 266
266//US d->mErrorHandler = 0; 267//US d->mErrorHandler = 0;
267 d->mManager = new KRES::Manager<Resource>( fami, false ); 268 d->mManager = new KRES::Manager<Resource>( fami, false );
268 d->mManager->readConfig( d->mConfig ); 269 d->mManager->readConfig( d->mConfig );
269 if ( family == "syncContact" ) { 270 if ( family == "syncContact" ) {
270 KRES::Manager<Resource> *manager = d->mManager; 271 KRES::Manager<Resource> *manager = d->mManager;
271 KRES::Manager<Resource>::ActiveIterator it; 272 KRES::Manager<Resource>::ActiveIterator it;
272 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { 273 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
273 (*it)->setAddressBook( this ); 274 (*it)->setAddressBook( this );
274 if ( !(*it)->open() ) 275 if ( !(*it)->open() )
275 error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); 276 error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) );
276 } 277 }
277 Resource *res = standardResource(); 278 Resource *res = standardResource();
278 if ( !res ) { 279 if ( !res ) {
279 qDebug("ERROR: no standard resource"); 280 qDebug("ERROR: no standard resource");
280 res = manager->createResource( "file" ); 281 res = manager->createResource( "file" );
281 if ( res ) 282 if ( res )
282 { 283 {
283 addResource( res ); 284 addResource( res );
284 } 285 }
285 else 286 else
286 qDebug(" No resource available!!!"); 287 qDebug(" No resource available!!!");
287 } 288 }
288 setStandardResource( res ); 289 setStandardResource( res );
289 manager->writeConfig(); 290 manager->writeConfig();
290 } 291 }
291 addCustomField( i18n( "Department" ), KABC::Field::Organization, 292 addCustomField( i18n( "Department" ), KABC::Field::Organization,
292 "X-Department", "KADDRESSBOOK" ); 293 "X-Department", "KADDRESSBOOK" );
293 addCustomField( i18n( "Profession" ), KABC::Field::Organization, 294 addCustomField( i18n( "Profession" ), KABC::Field::Organization,
294 "X-Profession", "KADDRESSBOOK" ); 295 "X-Profession", "KADDRESSBOOK" );
295 addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, 296 addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization,
296 "X-AssistantsName", "KADDRESSBOOK" ); 297 "X-AssistantsName", "KADDRESSBOOK" );
297 addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, 298 addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization,
298 "X-ManagersName", "KADDRESSBOOK" ); 299 "X-ManagersName", "KADDRESSBOOK" );
299 addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, 300 addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal,
300 "X-SpousesName", "KADDRESSBOOK" ); 301 "X-SpousesName", "KADDRESSBOOK" );
301 addCustomField( i18n( "Office" ), KABC::Field::Personal, 302 addCustomField( i18n( "Office" ), KABC::Field::Personal,
302 "X-Office", "KADDRESSBOOK" ); 303 "X-Office", "KADDRESSBOOK" );
303 addCustomField( i18n( "IM Address" ), KABC::Field::Personal, 304 addCustomField( i18n( "IM Address" ), KABC::Field::Personal,
304 "X-IMAddress", "KADDRESSBOOK" ); 305 "X-IMAddress", "KADDRESSBOOK" );
305 addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, 306 addCustomField( i18n( "Anniversary" ), KABC::Field::Personal,
306 "X-Anniversary", "KADDRESSBOOK" ); 307 "X-Anniversary", "KADDRESSBOOK" );
307 308
308 //US added this field to become compatible with Opie/qtopia addressbook 309 //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 // values can be "female" or "male" or "". An empty field represents undefined.
310 addCustomField( i18n( "Gender" ), KABC::Field::Personal, 311 addCustomField( i18n( "Gender" ), KABC::Field::Personal,
311 "X-Gender", "KADDRESSBOOK" ); 312 "X-Gender", "KADDRESSBOOK" );
312 addCustomField( i18n( "Children" ), KABC::Field::Personal, 313 addCustomField( i18n( "Children" ), KABC::Field::Personal,
313 "X-Children", "KADDRESSBOOK" ); 314 "X-Children", "KADDRESSBOOK" );
314 addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, 315 addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal,
315 "X-FreeBusyUrl", "KADDRESSBOOK" ); 316 "X-FreeBusyUrl", "KADDRESSBOOK" );
316 addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, 317 addCustomField( i18n( "ExternalID" ), KABC::Field::Personal,
317 "X-ExternalID", "KADDRESSBOOK" ); 318 "X-ExternalID", "KADDRESSBOOK" );
318} 319}
319 320
320AddressBook::~AddressBook() 321AddressBook::~AddressBook()
321{ 322{
322 delete d->mConfig; d->mConfig = 0; 323 delete d->mConfig; d->mConfig = 0;
323 delete d->mManager; d->mManager = 0; 324 delete d->mManager; d->mManager = 0;
324//US delete d->mErrorHandler; d->mErrorHandler = 0; 325//US delete d->mErrorHandler; d->mErrorHandler = 0;
325 delete d; d = 0; 326 delete d; d = 0;
326} 327}
327 328
328bool AddressBook::load() 329bool AddressBook::load()
329{ 330{
330 331
331 332
332 clear(); 333 clear();
333 334
334 KRES::Manager<Resource>::ActiveIterator it; 335 KRES::Manager<Resource>::ActiveIterator it;
335 bool ok = true; 336 bool ok = true;
336 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) 337 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it )
337 if ( !(*it)->load() ) { 338 if ( !(*it)->load() ) {
338 error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); 339 error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) );
339 ok = false; 340 ok = false;
340 } 341 }
341 342
342 // mark all addressees as unchanged 343 // mark all addressees as unchanged
343 Addressee::List::Iterator addrIt; 344 Addressee::List::Iterator addrIt;
344 for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) 345 for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt )
345 (*addrIt).setChanged( false ); 346 (*addrIt).setChanged( false );
346 347
347 return ok; 348 return ok;
348} 349}
349 350
350bool AddressBook::save( Ticket *ticket ) 351bool AddressBook::save( Ticket *ticket )
351{ 352{
352 kdDebug(5700) << "AddressBook::save()"<< endl; 353 kdDebug(5700) << "AddressBook::save()"<< endl;
353 354
354 if ( ticket->resource() ) { 355 if ( ticket->resource() ) {
355 deleteRemovedAddressees(); 356 deleteRemovedAddressees();
356 return ticket->resource()->save( ticket ); 357 return ticket->resource()->save( ticket );
357 } 358 }
358 359
359 return false; 360 return false;
360} 361}
361bool AddressBook::saveAB() 362bool AddressBook::saveAB()
362{ 363{
363 bool ok = true; 364 bool ok = true;
364 365
365 deleteRemovedAddressees(); 366 deleteRemovedAddressees();
366 367
367 KRES::Manager<Resource>::ActiveIterator it; 368 KRES::Manager<Resource>::ActiveIterator it;
368 KRES::Manager<Resource> *manager = d->mManager; 369 KRES::Manager<Resource> *manager = d->mManager;
369 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { 370 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
370 if ( !(*it)->readOnly() && (*it)->isOpen() ) { 371 if ( !(*it)->readOnly() && (*it)->isOpen() ) {
371 Ticket *ticket = requestSaveTicket( *it ); 372 Ticket *ticket = requestSaveTicket( *it );
372// qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); 373// qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() );
373 if ( !ticket ) { 374 if ( !ticket ) {
374 error( i18n( "Unable to save to resource '%1'. It is locked." ) 375 error( i18n( "Unable to save to resource '%1'. It is locked." )
375 .arg( (*it)->resourceName() ) ); 376 .arg( (*it)->resourceName() ) );
376 return false; 377 return false;
377 } 378 }
378 379
379 //if ( !save( ticket ) ) 380 //if ( !save( ticket ) )
380 if ( ticket->resource() ) { 381 if ( ticket->resource() ) {
381 if ( ! ticket->resource()->save( ticket ) ) 382 if ( ! ticket->resource()->save( ticket ) )
382 ok = false; 383 ok = false;
383 } else 384 } else
384 ok = false; 385 ok = false;
385 386
386 } 387 }
387 } 388 }
388 return ok; 389 return ok;
389} 390}
390 391
391AddressBook::Iterator AddressBook::begin() 392AddressBook::Iterator AddressBook::begin()
392{ 393{
393 Iterator it = Iterator(); 394 Iterator it = Iterator();
394 it.d->mIt = d->mAddressees.begin(); 395 it.d->mIt = d->mAddressees.begin();
395 return it; 396 return it;
396} 397}
397 398
398AddressBook::ConstIterator AddressBook::begin() const 399AddressBook::ConstIterator AddressBook::begin() const
399{ 400{
400 ConstIterator it = ConstIterator(); 401 ConstIterator it = ConstIterator();
401 it.d->mIt = d->mAddressees.begin(); 402 it.d->mIt = d->mAddressees.begin();
402 return it; 403 return it;
403} 404}
404 405
405AddressBook::Iterator AddressBook::end() 406AddressBook::Iterator AddressBook::end()
406{ 407{
407 Iterator it = Iterator(); 408 Iterator it = Iterator();
408 it.d->mIt = d->mAddressees.end(); 409 it.d->mIt = d->mAddressees.end();
409 return it; 410 return it;
410} 411}
411 412
412AddressBook::ConstIterator AddressBook::end() const 413AddressBook::ConstIterator AddressBook::end() const
413{ 414{
414 ConstIterator it = ConstIterator(); 415 ConstIterator it = ConstIterator();
415 it.d->mIt = d->mAddressees.end(); 416 it.d->mIt = d->mAddressees.end();
416 return it; 417 return it;
417} 418}
418 419
419void AddressBook::clear() 420void AddressBook::clear()
420{ 421{
421 d->mAddressees.clear(); 422 d->mAddressees.clear();
422} 423}
423 424
424Ticket *AddressBook::requestSaveTicket( Resource *resource ) 425Ticket *AddressBook::requestSaveTicket( Resource *resource )
425{ 426{
426 kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; 427 kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl;
427 428
428 if ( !resource ) 429 if ( !resource )
429 { 430 {
430 qDebug("AddressBook::requestSaveTicket no resource" ); 431 qDebug("AddressBook::requestSaveTicket no resource" );
431 resource = standardResource(); 432 resource = standardResource();
432 } 433 }
433 434
434 KRES::Manager<Resource>::ActiveIterator it; 435 KRES::Manager<Resource>::ActiveIterator it;
435 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { 436 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
436 if ( (*it) == resource ) { 437 if ( (*it) == resource ) {
437 if ( (*it)->readOnly() || !(*it)->isOpen() ) 438 if ( (*it)->readOnly() || !(*it)->isOpen() )
438 return 0; 439 return 0;
439 else 440 else
440 return (*it)->requestSaveTicket(); 441 return (*it)->requestSaveTicket();
441 } 442 }
442 } 443 }
443 444
444 return 0; 445 return 0;
445} 446}
446 447
447void AddressBook::insertAddressee( const Addressee &a ) 448void AddressBook::insertAddressee( const Addressee &a )
448{ 449{
449 Addressee::List::Iterator it; 450 Addressee::List::Iterator it;
450 for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { 451 for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) {
451 if ( a.uid() == (*it).uid() ) { 452 if ( a.uid() == (*it).uid() ) {
452 bool changed = false; 453 bool changed = false;
453 Addressee addr = a; 454 Addressee addr = a;
454 if ( addr != (*it) ) 455 if ( addr != (*it) )
455 changed = true; 456 changed = true;
456 457
457 (*it) = a; 458 (*it) = a;
458 if ( (*it).resource() == 0 ) 459 if ( (*it).resource() == 0 )
459 (*it).setResource( standardResource() ); 460 (*it).setResource( standardResource() );
460 461
461 if ( changed ) { 462 if ( changed ) {
462 (*it).setRevision( QDateTime::currentDateTime() ); 463 (*it).setRevision( QDateTime::currentDateTime() );
463 (*it).setChanged( true ); 464 (*it).setChanged( true );
464 } 465 }
465 466
466 return; 467 return;
467 } 468 }
468 } 469 }
469 d->mAddressees.append( a ); 470 d->mAddressees.append( a );
470 Addressee& addr = d->mAddressees.last(); 471 Addressee& addr = d->mAddressees.last();
471 if ( addr.resource() == 0 ) 472 if ( addr.resource() == 0 )
472 addr.setResource( standardResource() ); 473 addr.setResource( standardResource() );
473 474
474 addr.setChanged( true ); 475 addr.setChanged( true );
475} 476}
476 477
477void AddressBook::removeAddressee( const Addressee &a ) 478void AddressBook::removeAddressee( const Addressee &a )
478{ 479{
479 Iterator it; 480 Iterator it;
480 for ( it = begin(); it != end(); ++it ) { 481 for ( it = begin(); it != end(); ++it ) {
481 if ( a.uid() == (*it).uid() ) { 482 if ( a.uid() == (*it).uid() ) {
482 removeAddressee( it ); 483 removeAddressee( it );
483 return; 484 return;
484 } 485 }
485 } 486 }
486} 487}
487 488
488void AddressBook::removeAddressee( const Iterator &it ) 489void AddressBook::removeAddressee( const Iterator &it )
489{ 490{
490 d->mRemovedAddressees.append( (*it) ); 491 d->mRemovedAddressees.append( (*it) );
491 d->mAddressees.remove( it.d->mIt ); 492 d->mAddressees.remove( it.d->mIt );
492} 493}
493 494
494AddressBook::Iterator AddressBook::find( const Addressee &a ) 495AddressBook::Iterator AddressBook::find( const Addressee &a )
495{ 496{
496 Iterator it; 497 Iterator it;
497 for ( it = begin(); it != end(); ++it ) { 498 for ( it = begin(); it != end(); ++it ) {
498 if ( a.uid() == (*it).uid() ) { 499 if ( a.uid() == (*it).uid() ) {
499 return it; 500 return it;
500 } 501 }
501 } 502 }
502 return end(); 503 return end();
503} 504}
504 505
505Addressee AddressBook::findByUid( const QString &uid ) 506Addressee AddressBook::findByUid( const QString &uid )
506{ 507{
507 Iterator it; 508 Iterator it;
508 for ( it = begin(); it != end(); ++it ) { 509 for ( it = begin(); it != end(); ++it ) {
509 if ( uid == (*it).uid() ) { 510 if ( uid == (*it).uid() ) {
510 return *it; 511 return *it;
511 } 512 }
512 } 513 }
513 return Addressee(); 514 return Addressee();
514} 515}
516Addressee::List AddressBook::getExternLastSyncAddressees()
517{
518 Addressee::List results;
519
520 Iterator it;
521 for ( it = begin(); it != end(); ++it ) {
522 if ( (*it).uid().left( 20 ) == "last-syncAddressee-" ) {
523 if ( (*it).familyName().left(3) == "E: " )
524 results.append( *it );
525 }
526 }
527
528 return results;
529}
530void AddressBook::resetTempSyncStat()
531{
532
533
534 Iterator it;
535 for ( it = begin(); it != end(); ++it ) {
536 (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL );
537 }
538
539}
540
541
515 542
516Addressee::List AddressBook::allAddressees() 543Addressee::List AddressBook::allAddressees()
517{ 544{
518 return d->mAddressees; 545 return d->mAddressees;
519} 546}
520 547
521Addressee::List AddressBook::findByName( const QString &name ) 548Addressee::List AddressBook::findByName( const QString &name )
522{ 549{
523 Addressee::List results; 550 Addressee::List results;
524 551
525 Iterator it; 552 Iterator it;
526 for ( it = begin(); it != end(); ++it ) { 553 for ( it = begin(); it != end(); ++it ) {
527 if ( name == (*it).realName() ) { 554 if ( name == (*it).realName() ) {
528 results.append( *it ); 555 results.append( *it );
529 } 556 }
530 } 557 }
531 558
532 return results; 559 return results;
533} 560}
534 561
535Addressee::List AddressBook::findByEmail( const QString &email ) 562Addressee::List AddressBook::findByEmail( const QString &email )
536{ 563{
537 Addressee::List results; 564 Addressee::List results;
538 QStringList mailList; 565 QStringList mailList;
539 566
540 Iterator it; 567 Iterator it;
541 for ( it = begin(); it != end(); ++it ) { 568 for ( it = begin(); it != end(); ++it ) {
542 mailList = (*it).emails(); 569 mailList = (*it).emails();
543 for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { 570 for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) {
544 if ( email == (*ite) ) { 571 if ( email == (*ite) ) {
545 results.append( *it ); 572 results.append( *it );
546 } 573 }
547 } 574 }
548 } 575 }
549 576
550 return results; 577 return results;
551} 578}
552 579
553Addressee::List AddressBook::findByCategory( const QString &category ) 580Addressee::List AddressBook::findByCategory( const QString &category )
554{ 581{
555 Addressee::List results; 582 Addressee::List results;
556 583
557 Iterator it; 584 Iterator it;
558 for ( it = begin(); it != end(); ++it ) { 585 for ( it = begin(); it != end(); ++it ) {
559 if ( (*it).hasCategory( category) ) { 586 if ( (*it).hasCategory( category) ) {
560 results.append( *it ); 587 results.append( *it );
561 } 588 }
562 } 589 }
563 590
564 return results; 591 return results;
565} 592}
566 593
567void AddressBook::dump() const 594void AddressBook::dump() const
568{ 595{
569 kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; 596 kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl;
570 597
571 ConstIterator it; 598 ConstIterator it;
572 for( it = begin(); it != end(); ++it ) { 599 for( it = begin(); it != end(); ++it ) {
573 (*it).dump(); 600 (*it).dump();
574 } 601 }
575 602
576 kdDebug(5700) << "AddressBook::dump() --- end ---" << endl; 603 kdDebug(5700) << "AddressBook::dump() --- end ---" << endl;
577} 604}
578 605
579QString AddressBook::identifier() 606QString AddressBook::identifier()
580{ 607{
581 QStringList identifier; 608 QStringList identifier;
582 609
583 610
584 KRES::Manager<Resource>::ActiveIterator it; 611 KRES::Manager<Resource>::ActiveIterator it;
585 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { 612 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
586 if ( !(*it)->identifier().isEmpty() ) 613 if ( !(*it)->identifier().isEmpty() )
587 identifier.append( (*it)->identifier() ); 614 identifier.append( (*it)->identifier() );
588 } 615 }
589 616
590 return identifier.join( ":" ); 617 return identifier.join( ":" );
591} 618}
592 619
593Field::List AddressBook::fields( int category ) 620Field::List AddressBook::fields( int category )
594{ 621{
595 if ( d->mAllFields.isEmpty() ) { 622 if ( d->mAllFields.isEmpty() ) {
596 d->mAllFields = Field::allFields(); 623 d->mAllFields = Field::allFields();
597 } 624 }
598 625
599 if ( category == Field::All ) return d->mAllFields; 626 if ( category == Field::All ) return d->mAllFields;
600 627
601 Field::List result; 628 Field::List result;
602 Field::List::ConstIterator it; 629 Field::List::ConstIterator it;
603 for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) { 630 for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) {
604 if ( (*it)->category() & category ) result.append( *it ); 631 if ( (*it)->category() & category ) result.append( *it );
605 } 632 }
606 633
607 return result; 634 return result;
608} 635}
609 636
610bool AddressBook::addCustomField( const QString &label, int category, 637bool AddressBook::addCustomField( const QString &label, int category,
611 const QString &key, const QString &app ) 638 const QString &key, const QString &app )
612{ 639{
613 if ( d->mAllFields.isEmpty() ) { 640 if ( d->mAllFields.isEmpty() ) {
614 d->mAllFields = Field::allFields(); 641 d->mAllFields = Field::allFields();
615 } 642 }
616//US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app; 643//US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app;
617 QString a = app.isNull() ? KGlobal::getAppName() : app; 644 QString a = app.isNull() ? KGlobal::getAppName() : app;
618 645
619 QString k = key.isNull() ? label : key; 646 QString k = key.isNull() ? label : key;
620 647
621 Field *field = Field::createCustomField( label, category, k, a ); 648 Field *field = Field::createCustomField( label, category, k, a );
622 649
623 if ( !field ) return false; 650 if ( !field ) return false;
624 651
625 d->mAllFields.append( field ); 652 d->mAllFields.append( field );
626 653
627 return true; 654 return true;
628} 655}
629 656
630QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab ) 657QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab )
631{ 658{
632 if (!ab.d) return s; 659 if (!ab.d) return s;
633 660
634 return s << ab.d->mAddressees; 661 return s << ab.d->mAddressees;
635} 662}
636 663
637QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab ) 664QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab )
638{ 665{
639 if (!ab.d) return s; 666 if (!ab.d) return s;
640 667
641 s >> ab.d->mAddressees; 668 s >> ab.d->mAddressees;
642 669
643 return s; 670 return s;
644} 671}
645 672
646bool AddressBook::addResource( Resource *resource ) 673bool AddressBook::addResource( Resource *resource )
647{ 674{
648 if ( !resource->open() ) { 675 if ( !resource->open() ) {
649 kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl; 676 kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl;
650 return false; 677 return false;
651 } 678 }
652 679
653 resource->setAddressBook( this ); 680 resource->setAddressBook( this );
654 681
655 d->mManager->add( resource ); 682 d->mManager->add( resource );
656 return true; 683 return true;
657} 684}
658 685
659bool AddressBook::removeResource( Resource *resource ) 686bool AddressBook::removeResource( Resource *resource )
660{ 687{
661 resource->close(); 688 resource->close();
662 689
663 if ( resource == standardResource() ) 690 if ( resource == standardResource() )
664 d->mManager->setStandardResource( 0 ); 691 d->mManager->setStandardResource( 0 );
665 692
666 resource->setAddressBook( 0 ); 693 resource->setAddressBook( 0 );
667 694
668 d->mManager->remove( resource ); 695 d->mManager->remove( resource );
669 return true; 696 return true;
670} 697}
671 698
672QPtrList<Resource> AddressBook::resources() 699QPtrList<Resource> AddressBook::resources()
673{ 700{
674 QPtrList<Resource> list; 701 QPtrList<Resource> list;
675 702
676// qDebug("AddressBook::resources() 1"); 703// qDebug("AddressBook::resources() 1");
677 704
678 KRES::Manager<Resource>::ActiveIterator it; 705 KRES::Manager<Resource>::ActiveIterator it;
679 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) 706 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it )
680 list.append( *it ); 707 list.append( *it );
681 708
682 return list; 709 return list;
683} 710}
684 711
685/*US 712/*US
686void AddressBook::setErrorHandler( ErrorHandler *handler ) 713void AddressBook::setErrorHandler( ErrorHandler *handler )
687{ 714{
688 delete d->mErrorHandler; 715 delete d->mErrorHandler;
689 d->mErrorHandler = handler; 716 d->mErrorHandler = handler;
690} 717}
691*/ 718*/
692 719
693void AddressBook::error( const QString& msg ) 720void AddressBook::error( const QString& msg )
694{ 721{
695/*US 722/*US
696 if ( !d->mErrorHandler ) // create default error handler 723 if ( !d->mErrorHandler ) // create default error handler
697 d->mErrorHandler = new ConsoleErrorHandler; 724 d->mErrorHandler = new ConsoleErrorHandler;
698 725
699 if ( d->mErrorHandler ) 726 if ( d->mErrorHandler )
700 d->mErrorHandler->error( msg ); 727 d->mErrorHandler->error( msg );
701 else 728 else
702 kdError(5700) << "no error handler defined" << endl; 729 kdError(5700) << "no error handler defined" << endl;
703*/ 730*/
704 kdDebug(5700) << "msg" << endl; 731 kdDebug(5700) << "msg" << endl;
705 qDebug(msg); 732 qDebug(msg);
706} 733}
707 734
708void AddressBook::deleteRemovedAddressees() 735void AddressBook::deleteRemovedAddressees()
709{ 736{
710 Addressee::List::Iterator it; 737 Addressee::List::Iterator it;
711 for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) { 738 for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) {
712 Resource *resource = (*it).resource(); 739 Resource *resource = (*it).resource();
713 if ( resource && !resource->readOnly() && resource->isOpen() ) 740 if ( resource && !resource->readOnly() && resource->isOpen() )
714 resource->removeAddressee( *it ); 741 resource->removeAddressee( *it );
715 } 742 }
716 743
717 d->mRemovedAddressees.clear(); 744 d->mRemovedAddressees.clear();
718} 745}
719 746
720void AddressBook::setStandardResource( Resource *resource ) 747void AddressBook::setStandardResource( Resource *resource )
721{ 748{
722// qDebug("AddressBook::setStandardResource 1"); 749// qDebug("AddressBook::setStandardResource 1");
723 d->mManager->setStandardResource( resource ); 750 d->mManager->setStandardResource( resource );
724} 751}
725 752
726Resource *AddressBook::standardResource() 753Resource *AddressBook::standardResource()
727{ 754{
728 return d->mManager->standardResource(); 755 return d->mManager->standardResource();
729} 756}
730 757
731KRES::Manager<Resource> *AddressBook::resourceManager() 758KRES::Manager<Resource> *AddressBook::resourceManager()
732{ 759{
733 return d->mManager; 760 return d->mManager;
734} 761}
735 762
736void AddressBook::cleanUp() 763void AddressBook::cleanUp()
737{ 764{
738 KRES::Manager<Resource>::ActiveIterator it; 765 KRES::Manager<Resource>::ActiveIterator it;
739 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { 766 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
740 if ( !(*it)->readOnly() && (*it)->isOpen() ) 767 if ( !(*it)->readOnly() && (*it)->isOpen() )
741 (*it)->cleanUp(); 768 (*it)->cleanUp();
742 } 769 }
743} 770}