-rw-r--r-- | kabc/addressbook.cpp | 72 |
1 files changed, 46 insertions, 26 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index 1050f55..ff05f7e 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp | |||
@@ -214,412 +214,432 @@ bool AddressBook::ConstIterator::operator==( const ConstIterator &it ) | |||
214 | { | 214 | { |
215 | return ( d->mIt == it.d->mIt ); | 215 | return ( d->mIt == it.d->mIt ); |
216 | } | 216 | } |
217 | 217 | ||
218 | bool AddressBook::ConstIterator::operator!=( const ConstIterator &it ) | 218 | bool AddressBook::ConstIterator::operator!=( const ConstIterator &it ) |
219 | { | 219 | { |
220 | return ( d->mIt != it.d->mIt ); | 220 | return ( d->mIt != it.d->mIt ); |
221 | } | 221 | } |
222 | 222 | ||
223 | 223 | ||
224 | AddressBook::AddressBook() | 224 | AddressBook::AddressBook() |
225 | { | 225 | { |
226 | init(0, "contact"); | 226 | init(0, "contact"); |
227 | } | 227 | } |
228 | 228 | ||
229 | AddressBook::AddressBook( const QString &config ) | 229 | AddressBook::AddressBook( const QString &config ) |
230 | { | 230 | { |
231 | init(config, "contact"); | 231 | init(config, "contact"); |
232 | } | 232 | } |
233 | 233 | ||
234 | AddressBook::AddressBook( const QString &config, const QString &family ) | 234 | AddressBook::AddressBook( const QString &config, const QString &family ) |
235 | { | 235 | { |
236 | init(config, family); | 236 | init(config, family); |
237 | 237 | ||
238 | } | 238 | } |
239 | 239 | ||
240 | // the default family is "contact" | 240 | // the default family is "contact" |
241 | void AddressBook::init(const QString &config, const QString &family ) | 241 | void AddressBook::init(const QString &config, const QString &family ) |
242 | { | 242 | { |
243 | blockLSEchange = false; | 243 | blockLSEchange = false; |
244 | d = new AddressBookData; | 244 | d = new AddressBookData; |
245 | QString fami = family; | 245 | QString fami = family; |
246 | if (config != 0) { | 246 | if (config != 0) { |
247 | if ( family == "syncContact" ) { | 247 | if ( family == "syncContact" ) { |
248 | qDebug("creating sync config "); | 248 | qDebug("creating sync config "); |
249 | fami = "contact"; | 249 | fami = "contact"; |
250 | KConfig* con = new KConfig( locateLocal("config", "syncContactrc") ); | 250 | KConfig* con = new KConfig( locateLocal("config", "syncContactrc") ); |
251 | con->setGroup( "General" ); | 251 | con->setGroup( "General" ); |
252 | con->writeEntry( "ResourceKeys", QString("sync") ); | 252 | con->writeEntry( "ResourceKeys", QString("sync") ); |
253 | con->writeEntry( "Standard", QString("sync") ); | 253 | con->writeEntry( "Standard", QString("sync") ); |
254 | con->setGroup( "Resource_sync" ); | 254 | con->setGroup( "Resource_sync" ); |
255 | con->writeEntry( "FileName", config ); | 255 | con->writeEntry( "FileName", config ); |
256 | con->writeEntry( "FileFormat", QString("vcard") ); | 256 | con->writeEntry( "FileFormat", QString("vcard") ); |
257 | con->writeEntry( "ResourceIdentifier", QString("sync") ); | 257 | con->writeEntry( "ResourceIdentifier", QString("sync") ); |
258 | con->writeEntry( "ResourceName", QString("sync_res") ); | 258 | con->writeEntry( "ResourceName", QString("sync_res") ); |
259 | if ( config.right(4) == ".xml" ) | 259 | if ( config.right(4) == ".xml" ) |
260 | con->writeEntry( "ResourceType", QString("qtopia") ); | 260 | con->writeEntry( "ResourceType", QString("qtopia") ); |
261 | else if ( config == "sharp" ) { | 261 | else if ( config == "sharp" ) { |
262 | con->writeEntry( "ResourceType", QString("sharp") ); | 262 | con->writeEntry( "ResourceType", QString("sharp") ); |
263 | } else { | 263 | } else { |
264 | con->writeEntry( "ResourceType", QString("file") ); | 264 | con->writeEntry( "ResourceType", QString("file") ); |
265 | } | 265 | } |
266 | //con->sync(); | 266 | //con->sync(); |
267 | d->mConfig = con; | 267 | d->mConfig = con; |
268 | } | 268 | } |
269 | else | 269 | else |
270 | d->mConfig = new KConfig( locateLocal("config", config) ); | 270 | d->mConfig = new KConfig( locateLocal("config", config) ); |
271 | // qDebug("AddressBook::init 1 config=%s",config.latin1() ); | 271 | // qDebug("AddressBook::init 1 config=%s",config.latin1() ); |
272 | } | 272 | } |
273 | else { | 273 | else { |
274 | d->mConfig = 0; | 274 | d->mConfig = 0; |
275 | // qDebug("AddressBook::init 1 config=0"); | 275 | // qDebug("AddressBook::init 1 config=0"); |
276 | } | 276 | } |
277 | 277 | ||
278 | //US d->mErrorHandler = 0; | 278 | //US d->mErrorHandler = 0; |
279 | d->mManager = new KRES::Manager<Resource>( fami, false ); | 279 | d->mManager = new KRES::Manager<Resource>( fami, false ); |
280 | d->mManager->readConfig( d->mConfig ); | 280 | d->mManager->readConfig( d->mConfig ); |
281 | if ( family == "syncContact" ) { | 281 | if ( family == "syncContact" ) { |
282 | KRES::Manager<Resource> *manager = d->mManager; | 282 | KRES::Manager<Resource> *manager = d->mManager; |
283 | KRES::Manager<Resource>::ActiveIterator it; | 283 | KRES::Manager<Resource>::ActiveIterator it; |
284 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | 284 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { |
285 | (*it)->setAddressBook( this ); | 285 | (*it)->setAddressBook( this ); |
286 | if ( !(*it)->open() ) | 286 | if ( !(*it)->open() ) |
287 | error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); | 287 | error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); |
288 | } | 288 | } |
289 | Resource *res = standardResource(); | 289 | Resource *res = standardResource(); |
290 | if ( !res ) { | 290 | if ( !res ) { |
291 | qDebug("ERROR: no standard resource"); | 291 | qDebug("ERROR: no standard resource"); |
292 | res = manager->createResource( "file" ); | 292 | res = manager->createResource( "file" ); |
293 | if ( res ) | 293 | if ( res ) |
294 | { | 294 | { |
295 | addResource( res ); | 295 | addResource( res ); |
296 | } | 296 | } |
297 | else | 297 | else |
298 | qDebug(" No resource available!!!"); | 298 | qDebug(" No resource available!!!"); |
299 | } | 299 | } |
300 | setStandardResource( res ); | 300 | setStandardResource( res ); |
301 | manager->writeConfig(); | 301 | manager->writeConfig(); |
302 | } | 302 | } |
303 | addCustomField( i18n( "Department" ), KABC::Field::Organization, | 303 | addCustomField( i18n( "Department" ), KABC::Field::Organization, |
304 | "X-Department", "KADDRESSBOOK" ); | 304 | "X-Department", "KADDRESSBOOK" ); |
305 | addCustomField( i18n( "Profession" ), KABC::Field::Organization, | 305 | addCustomField( i18n( "Profession" ), KABC::Field::Organization, |
306 | "X-Profession", "KADDRESSBOOK" ); | 306 | "X-Profession", "KADDRESSBOOK" ); |
307 | addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, | 307 | addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, |
308 | "X-AssistantsName", "KADDRESSBOOK" ); | 308 | "X-AssistantsName", "KADDRESSBOOK" ); |
309 | addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, | 309 | addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, |
310 | "X-ManagersName", "KADDRESSBOOK" ); | 310 | "X-ManagersName", "KADDRESSBOOK" ); |
311 | addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, | 311 | addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, |
312 | "X-SpousesName", "KADDRESSBOOK" ); | 312 | "X-SpousesName", "KADDRESSBOOK" ); |
313 | addCustomField( i18n( "Office" ), KABC::Field::Personal, | 313 | addCustomField( i18n( "Office" ), KABC::Field::Personal, |
314 | "X-Office", "KADDRESSBOOK" ); | 314 | "X-Office", "KADDRESSBOOK" ); |
315 | addCustomField( i18n( "IM Address" ), KABC::Field::Personal, | 315 | addCustomField( i18n( "IM Address" ), KABC::Field::Personal, |
316 | "X-IMAddress", "KADDRESSBOOK" ); | 316 | "X-IMAddress", "KADDRESSBOOK" ); |
317 | addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, | 317 | addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, |
318 | "X-Anniversary", "KADDRESSBOOK" ); | 318 | "X-Anniversary", "KADDRESSBOOK" ); |
319 | 319 | ||
320 | //US added this field to become compatible with Opie/qtopia addressbook | 320 | //US added this field to become compatible with Opie/qtopia addressbook |
321 | // values can be "female" or "male" or "". An empty field represents undefined. | 321 | // values can be "female" or "male" or "". An empty field represents undefined. |
322 | addCustomField( i18n( "Gender" ), KABC::Field::Personal, | 322 | addCustomField( i18n( "Gender" ), KABC::Field::Personal, |
323 | "X-Gender", "KADDRESSBOOK" ); | 323 | "X-Gender", "KADDRESSBOOK" ); |
324 | addCustomField( i18n( "Children" ), KABC::Field::Personal, | 324 | addCustomField( i18n( "Children" ), KABC::Field::Personal, |
325 | "X-Children", "KADDRESSBOOK" ); | 325 | "X-Children", "KADDRESSBOOK" ); |
326 | addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, | 326 | addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, |
327 | "X-FreeBusyUrl", "KADDRESSBOOK" ); | 327 | "X-FreeBusyUrl", "KADDRESSBOOK" ); |
328 | addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, | 328 | addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, |
329 | "X-ExternalID", "KADDRESSBOOK" ); | 329 | "X-ExternalID", "KADDRESSBOOK" ); |
330 | } | 330 | } |
331 | 331 | ||
332 | AddressBook::~AddressBook() | 332 | AddressBook::~AddressBook() |
333 | { | 333 | { |
334 | delete d->mConfig; d->mConfig = 0; | 334 | delete d->mConfig; d->mConfig = 0; |
335 | delete d->mManager; d->mManager = 0; | 335 | delete d->mManager; d->mManager = 0; |
336 | //US delete d->mErrorHandler; d->mErrorHandler = 0; | 336 | //US delete d->mErrorHandler; d->mErrorHandler = 0; |
337 | delete d; d = 0; | 337 | delete d; d = 0; |
338 | } | 338 | } |
339 | 339 | ||
340 | bool AddressBook::load() | 340 | bool AddressBook::load() |
341 | { | 341 | { |
342 | 342 | ||
343 | 343 | ||
344 | clear(); | 344 | clear(); |
345 | 345 | ||
346 | KRES::Manager<Resource>::ActiveIterator it; | 346 | KRES::Manager<Resource>::ActiveIterator it; |
347 | bool ok = true; | 347 | bool ok = true; |
348 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) | 348 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) |
349 | if ( !(*it)->load() ) { | 349 | if ( !(*it)->load() ) { |
350 | error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); | 350 | error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); |
351 | ok = false; | 351 | ok = false; |
352 | } | 352 | } |
353 | 353 | ||
354 | // mark all addressees as unchanged | 354 | // mark all addressees as unchanged |
355 | Addressee::List::Iterator addrIt; | 355 | Addressee::List::Iterator addrIt; |
356 | for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) { | 356 | for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) { |
357 | (*addrIt).setChanged( false ); | 357 | (*addrIt).setChanged( false ); |
358 | QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" ); | 358 | QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" ); |
359 | if ( !id.isEmpty() ) { | 359 | if ( !id.isEmpty() ) { |
360 | //qDebug("setId aa %s ", id.latin1()); | 360 | //qDebug("setId aa %s ", id.latin1()); |
361 | (*addrIt).setIDStr(id ); | 361 | (*addrIt).setIDStr(id ); |
362 | } | 362 | } |
363 | } | 363 | } |
364 | blockLSEchange = true; | 364 | blockLSEchange = true; |
365 | return ok; | 365 | return ok; |
366 | } | 366 | } |
367 | 367 | ||
368 | bool AddressBook::save( Ticket *ticket ) | 368 | bool AddressBook::save( Ticket *ticket ) |
369 | { | 369 | { |
370 | kdDebug(5700) << "AddressBook::save()"<< endl; | 370 | kdDebug(5700) << "AddressBook::save()"<< endl; |
371 | 371 | ||
372 | if ( ticket->resource() ) { | 372 | if ( ticket->resource() ) { |
373 | deleteRemovedAddressees(); | 373 | deleteRemovedAddressees(); |
374 | return ticket->resource()->save( ticket ); | 374 | return ticket->resource()->save( ticket ); |
375 | } | 375 | } |
376 | 376 | ||
377 | return false; | 377 | return false; |
378 | } | 378 | } |
379 | void AddressBook::export2File( QString fileName ) | 379 | void AddressBook::export2File( QString fileName ) |
380 | { | 380 | { |
381 | 381 | ||
382 | QFile outFile( fileName ); | 382 | QFile outFile( fileName ); |
383 | if ( !outFile.open( IO_WriteOnly ) ) { | 383 | if ( !outFile.open( IO_WriteOnly ) ) { |
384 | QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" ); | 384 | QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" ); |
385 | KMessageBox::error( 0, text.arg( fileName ) ); | 385 | KMessageBox::error( 0, text.arg( fileName ) ); |
386 | return ; | 386 | return ; |
387 | } | 387 | } |
388 | QTextStream t( &outFile ); | 388 | QTextStream t( &outFile ); |
389 | t.setEncoding( QTextStream::UnicodeUTF8 ); | 389 | t.setEncoding( QTextStream::UnicodeUTF8 ); |
390 | Iterator it; | 390 | Iterator it; |
391 | KABC::VCardConverter::Version version; | 391 | KABC::VCardConverter::Version version; |
392 | version = KABC::VCardConverter::v3_0; | 392 | version = KABC::VCardConverter::v3_0; |
393 | for ( it = begin(); it != end(); ++it ) { | 393 | for ( it = begin(); it != end(); ++it ) { |
394 | if ( !(*it).IDStr().isEmpty() ) { | 394 | if ( !(*it).IDStr().isEmpty() ) { |
395 | (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() ); | 395 | (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() ); |
396 | } | 396 | } |
397 | KABC::VCardConverter converter; | 397 | KABC::VCardConverter converter; |
398 | QString vcard; | 398 | QString vcard; |
399 | //Resource *resource() const; | 399 | //Resource *resource() const; |
400 | converter.addresseeToVCard( *it, vcard, version ); | 400 | converter.addresseeToVCard( *it, vcard, version ); |
401 | t << vcard << "\r\n"; | 401 | t << vcard << "\r\n"; |
402 | } | 402 | } |
403 | t << "\r\n\r\n"; | 403 | t << "\r\n\r\n"; |
404 | outFile.close(); | 404 | outFile.close(); |
405 | } | 405 | } |
406 | void AddressBook::importFromFile( QString fileName, bool replaceLabel ) | 406 | void AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld ) |
407 | { | 407 | { |
408 | 408 | ||
409 | KABC::Addressee::List list; | 409 | if ( removeOld ) |
410 | QFile file( fileName ); | 410 | setUntagged(); |
411 | 411 | KABC::Addressee::List list; | |
412 | file.open( IO_ReadOnly ); | 412 | QFile file( fileName ); |
413 | QByteArray rawData = file.readAll(); | 413 | file.open( IO_ReadOnly ); |
414 | file.close(); | 414 | QByteArray rawData = file.readAll(); |
415 | QString data; | 415 | file.close(); |
416 | if ( replaceLabel ) { | 416 | QString data; |
417 | data = QString::fromLatin1( rawData.data(), rawData.size() + 1 ); | 417 | if ( replaceLabel ) { |
418 | data.replace ( QRegExp("LABEL") , "ADR" ); | 418 | data = QString::fromLatin1( rawData.data(), rawData.size() + 1 ); |
419 | data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" ); | 419 | data.replace ( QRegExp("LABEL") , "ADR" ); |
420 | } else | 420 | data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" ); |
421 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); | 421 | } else |
422 | KABC::VCardTool tool; | 422 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); |
423 | list = tool.parseVCards( data ); | 423 | KABC::VCardTool tool; |
424 | KABC::Addressee::List::Iterator it; | 424 | list = tool.parseVCards( data ); |
425 | for ( it = list.begin(); it != list.end(); ++it ) { | 425 | KABC::Addressee::List::Iterator it; |
426 | (*it).setResource( 0 ); | 426 | for ( it = list.begin(); it != list.end(); ++it ) { |
427 | if ( replaceLabel ) | 427 | (*it).setResource( 0 ); |
428 | (*it).removeVoice(); | 428 | if ( replaceLabel ) |
429 | insertAddressee( (*it), false, true ); | 429 | (*it).removeVoice(); |
430 | if ( removeOld ) | ||
431 | (*it).setTagged( true ); | ||
432 | insertAddressee( (*it), false, true ); | ||
433 | } | ||
434 | if ( removeOld ) | ||
435 | removeUntagged(); | ||
436 | } | ||
437 | void AddressBook::setUntagged() | ||
438 | { | ||
439 | Iterator ait; | ||
440 | for ( ait = begin(); ait != end(); ++ait ) { | ||
441 | (*ait).setTagged( false ); | ||
442 | } | ||
443 | } | ||
444 | void AddressBook::removeUntagged() | ||
445 | { | ||
446 | Iterator ait; | ||
447 | for ( ait = begin(); ait != end(); ++ait ) { | ||
448 | if (!(*ait).tagged()) | ||
449 | removeAddressee( ait ); | ||
430 | } | 450 | } |
431 | 451 | ||
452 | deleteRemovedAddressees(); | ||
432 | } | 453 | } |
433 | |||
434 | bool AddressBook::saveAB() | 454 | bool AddressBook::saveAB() |
435 | { | 455 | { |
436 | bool ok = true; | 456 | bool ok = true; |
437 | 457 | ||
438 | deleteRemovedAddressees(); | 458 | deleteRemovedAddressees(); |
439 | Iterator ait; | 459 | Iterator ait; |
440 | for ( ait = begin(); ait != end(); ++ait ) { | 460 | for ( ait = begin(); ait != end(); ++ait ) { |
441 | if ( !(*ait).IDStr().isEmpty() ) { | 461 | if ( !(*ait).IDStr().isEmpty() ) { |
442 | (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); | 462 | (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); |
443 | } | 463 | } |
444 | } | 464 | } |
445 | KRES::Manager<Resource>::ActiveIterator it; | 465 | KRES::Manager<Resource>::ActiveIterator it; |
446 | KRES::Manager<Resource> *manager = d->mManager; | 466 | KRES::Manager<Resource> *manager = d->mManager; |
447 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | 467 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { |
448 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { | 468 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { |
449 | Ticket *ticket = requestSaveTicket( *it ); | 469 | Ticket *ticket = requestSaveTicket( *it ); |
450 | // qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); | 470 | // qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); |
451 | if ( !ticket ) { | 471 | if ( !ticket ) { |
452 | error( i18n( "Unable to save to resource '%1'. It is locked." ) | 472 | error( i18n( "Unable to save to resource '%1'. It is locked." ) |
453 | .arg( (*it)->resourceName() ) ); | 473 | .arg( (*it)->resourceName() ) ); |
454 | return false; | 474 | return false; |
455 | } | 475 | } |
456 | 476 | ||
457 | //if ( !save( ticket ) ) | 477 | //if ( !save( ticket ) ) |
458 | if ( ticket->resource() ) { | 478 | if ( ticket->resource() ) { |
459 | if ( ! ticket->resource()->save( ticket ) ) | 479 | if ( ! ticket->resource()->save( ticket ) ) |
460 | ok = false; | 480 | ok = false; |
461 | } else | 481 | } else |
462 | ok = false; | 482 | ok = false; |
463 | 483 | ||
464 | } | 484 | } |
465 | } | 485 | } |
466 | return ok; | 486 | return ok; |
467 | } | 487 | } |
468 | 488 | ||
469 | AddressBook::Iterator AddressBook::begin() | 489 | AddressBook::Iterator AddressBook::begin() |
470 | { | 490 | { |
471 | Iterator it = Iterator(); | 491 | Iterator it = Iterator(); |
472 | it.d->mIt = d->mAddressees.begin(); | 492 | it.d->mIt = d->mAddressees.begin(); |
473 | return it; | 493 | return it; |
474 | } | 494 | } |
475 | 495 | ||
476 | AddressBook::ConstIterator AddressBook::begin() const | 496 | AddressBook::ConstIterator AddressBook::begin() const |
477 | { | 497 | { |
478 | ConstIterator it = ConstIterator(); | 498 | ConstIterator it = ConstIterator(); |
479 | it.d->mIt = d->mAddressees.begin(); | 499 | it.d->mIt = d->mAddressees.begin(); |
480 | return it; | 500 | return it; |
481 | } | 501 | } |
482 | 502 | ||
483 | AddressBook::Iterator AddressBook::end() | 503 | AddressBook::Iterator AddressBook::end() |
484 | { | 504 | { |
485 | Iterator it = Iterator(); | 505 | Iterator it = Iterator(); |
486 | it.d->mIt = d->mAddressees.end(); | 506 | it.d->mIt = d->mAddressees.end(); |
487 | return it; | 507 | return it; |
488 | } | 508 | } |
489 | 509 | ||
490 | AddressBook::ConstIterator AddressBook::end() const | 510 | AddressBook::ConstIterator AddressBook::end() const |
491 | { | 511 | { |
492 | ConstIterator it = ConstIterator(); | 512 | ConstIterator it = ConstIterator(); |
493 | it.d->mIt = d->mAddressees.end(); | 513 | it.d->mIt = d->mAddressees.end(); |
494 | return it; | 514 | return it; |
495 | } | 515 | } |
496 | 516 | ||
497 | void AddressBook::clear() | 517 | void AddressBook::clear() |
498 | { | 518 | { |
499 | d->mAddressees.clear(); | 519 | d->mAddressees.clear(); |
500 | } | 520 | } |
501 | 521 | ||
502 | Ticket *AddressBook::requestSaveTicket( Resource *resource ) | 522 | Ticket *AddressBook::requestSaveTicket( Resource *resource ) |
503 | { | 523 | { |
504 | kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; | 524 | kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; |
505 | 525 | ||
506 | if ( !resource ) | 526 | if ( !resource ) |
507 | { | 527 | { |
508 | qDebug("AddressBook::requestSaveTicket no resource" ); | 528 | qDebug("AddressBook::requestSaveTicket no resource" ); |
509 | resource = standardResource(); | 529 | resource = standardResource(); |
510 | } | 530 | } |
511 | 531 | ||
512 | KRES::Manager<Resource>::ActiveIterator it; | 532 | KRES::Manager<Resource>::ActiveIterator it; |
513 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 533 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
514 | if ( (*it) == resource ) { | 534 | if ( (*it) == resource ) { |
515 | if ( (*it)->readOnly() || !(*it)->isOpen() ) | 535 | if ( (*it)->readOnly() || !(*it)->isOpen() ) |
516 | return 0; | 536 | return 0; |
517 | else | 537 | else |
518 | return (*it)->requestSaveTicket(); | 538 | return (*it)->requestSaveTicket(); |
519 | } | 539 | } |
520 | } | 540 | } |
521 | 541 | ||
522 | return 0; | 542 | return 0; |
523 | } | 543 | } |
524 | 544 | ||
525 | void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) | 545 | void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) |
526 | { | 546 | { |
527 | if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { | 547 | if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { |
528 | //qDebug("block insert "); | 548 | //qDebug("block insert "); |
529 | return; | 549 | return; |
530 | } | 550 | } |
531 | //qDebug("inserting.... %s ",a.uid().latin1() ); | 551 | //qDebug("inserting.... %s ",a.uid().latin1() ); |
532 | bool found = false; | 552 | bool found = false; |
533 | Addressee::List::Iterator it; | 553 | Addressee::List::Iterator it; |
534 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { | 554 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { |
535 | if ( a.uid() == (*it).uid() ) { | 555 | if ( a.uid() == (*it).uid() ) { |
536 | 556 | ||
537 | bool changed = false; | 557 | bool changed = false; |
538 | Addressee addr = a; | 558 | Addressee addr = a; |
539 | if ( addr != (*it) ) | 559 | if ( addr != (*it) ) |
540 | changed = true; | 560 | changed = true; |
541 | 561 | ||
542 | if ( takeResource ) { | 562 | if ( takeResource ) { |
543 | Resource * res = (*it).resource(); | 563 | Resource * res = (*it).resource(); |
544 | (*it) = a; | 564 | (*it) = a; |
545 | (*it).setResource( res ); | 565 | (*it).setResource( res ); |
546 | } else { | 566 | } else { |
547 | (*it) = a; | 567 | (*it) = a; |
548 | if ( (*it).resource() == 0 ) | 568 | if ( (*it).resource() == 0 ) |
549 | (*it).setResource( standardResource() ); | 569 | (*it).setResource( standardResource() ); |
550 | } | 570 | } |
551 | if ( changed ) { | 571 | if ( changed ) { |
552 | if ( setRev ) { | 572 | if ( setRev ) { |
553 | 573 | ||
554 | // get rid of micro seconds | 574 | // get rid of micro seconds |
555 | QDateTime dt = QDateTime::currentDateTime(); | 575 | QDateTime dt = QDateTime::currentDateTime(); |
556 | QTime t = dt.time(); | 576 | QTime t = dt.time(); |
557 | dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); | 577 | dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); |
558 | (*it).setRevision( dt ); | 578 | (*it).setRevision( dt ); |
559 | } | 579 | } |
560 | (*it).setChanged( true ); | 580 | (*it).setChanged( true ); |
561 | } | 581 | } |
562 | 582 | ||
563 | found = true; | 583 | found = true; |
564 | } else { | 584 | } else { |
565 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { | 585 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { |
566 | QString name = (*it).uid().mid( 19 ); | 586 | QString name = (*it).uid().mid( 19 ); |
567 | Addressee b = a; | 587 | Addressee b = a; |
568 | QString id = b.getID( name ); | 588 | QString id = b.getID( name ); |
569 | if ( ! id.isEmpty() ) { | 589 | if ( ! id.isEmpty() ) { |
570 | QString des = (*it).note(); | 590 | QString des = (*it).note(); |
571 | int startN; | 591 | int startN; |
572 | if( (startN = des.find( id ) ) >= 0 ) { | 592 | if( (startN = des.find( id ) ) >= 0 ) { |
573 | int endN = des.find( ",", startN+1 ); | 593 | int endN = des.find( ",", startN+1 ); |
574 | des = des.left( startN ) + des.mid( endN+1 ); | 594 | des = des.left( startN ) + des.mid( endN+1 ); |
575 | (*it).setNote( des ); | 595 | (*it).setNote( des ); |
576 | } | 596 | } |
577 | } | 597 | } |
578 | } | 598 | } |
579 | } | 599 | } |
580 | } | 600 | } |
581 | if ( found ) | 601 | if ( found ) |
582 | return; | 602 | return; |
583 | d->mAddressees.append( a ); | 603 | d->mAddressees.append( a ); |
584 | Addressee& addr = d->mAddressees.last(); | 604 | Addressee& addr = d->mAddressees.last(); |
585 | if ( addr.resource() == 0 ) | 605 | if ( addr.resource() == 0 ) |
586 | addr.setResource( standardResource() ); | 606 | addr.setResource( standardResource() ); |
587 | 607 | ||
588 | addr.setChanged( true ); | 608 | addr.setChanged( true ); |
589 | } | 609 | } |
590 | 610 | ||
591 | void AddressBook::removeAddressee( const Addressee &a ) | 611 | void AddressBook::removeAddressee( const Addressee &a ) |
592 | { | 612 | { |
593 | Iterator it; | 613 | Iterator it; |
594 | Iterator it2; | 614 | Iterator it2; |
595 | bool found = false; | 615 | bool found = false; |
596 | for ( it = begin(); it != end(); ++it ) { | 616 | for ( it = begin(); it != end(); ++it ) { |
597 | if ( a.uid() == (*it).uid() ) { | 617 | if ( a.uid() == (*it).uid() ) { |
598 | found = true; | 618 | found = true; |
599 | it2 = it; | 619 | it2 = it; |
600 | } else { | 620 | } else { |
601 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { | 621 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { |
602 | QString name = (*it).uid().mid( 19 ); | 622 | QString name = (*it).uid().mid( 19 ); |
603 | Addressee b = a; | 623 | Addressee b = a; |
604 | QString id = b.getID( name ); | 624 | QString id = b.getID( name ); |
605 | if ( ! id.isEmpty() ) { | 625 | if ( ! id.isEmpty() ) { |
606 | QString des = (*it).note(); | 626 | QString des = (*it).note(); |
607 | if( des.find( id ) < 0 ) { | 627 | if( des.find( id ) < 0 ) { |
608 | des += id + ","; | 628 | des += id + ","; |
609 | (*it).setNote( des ); | 629 | (*it).setNote( des ); |
610 | } | 630 | } |
611 | } | 631 | } |
612 | } | 632 | } |
613 | 633 | ||
614 | } | 634 | } |
615 | } | 635 | } |
616 | 636 | ||
617 | if ( found ) | 637 | if ( found ) |
618 | removeAddressee( it2 ); | 638 | removeAddressee( it2 ); |
619 | 639 | ||
620 | } | 640 | } |
621 | 641 | ||
622 | void AddressBook::removeSyncAddressees( bool removeDeleted ) | 642 | void AddressBook::removeSyncAddressees( bool removeDeleted ) |
623 | { | 643 | { |
624 | Iterator it = begin(); | 644 | Iterator it = begin(); |
625 | Iterator it2 ; | 645 | Iterator it2 ; |