author | zautrix <zautrix> | 2004-09-07 20:33:23 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-09-07 20:33:23 (UTC) |
commit | 64a8ef1629f523df3006de5cb2b9882a50d96a05 (patch) (unidiff) | |
tree | b931dc5397b4eec926603080b20eddda131999ff /kabc | |
parent | 9d5c8750ae671e73ec8ebc0a71f30fd30680f2c0 (diff) | |
download | kdepimpi-64a8ef1629f523df3006de5cb2b9882a50d96a05.zip kdepimpi-64a8ef1629f523df3006de5cb2b9882a50d96a05.tar.gz kdepimpi-64a8ef1629f523df3006de5cb2b9882a50d96a05.tar.bz2 |
Fixed Kopi-Kapi external app communication
-rw-r--r-- | kabc/addressbook.cpp | 2 | ||||
-rw-r--r-- | kabc/stdaddressbook.cpp | 14 |
2 files changed, 13 insertions, 3 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index c61b387..47d298a 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp | |||
@@ -334,193 +334,193 @@ Ticket *AddressBook::requestSaveTicket( Resource *resource ) | |||
334 | resource = standardResource(); | 334 | resource = standardResource(); |
335 | } | 335 | } |
336 | 336 | ||
337 | KRES::Manager<Resource>::ActiveIterator it; | 337 | KRES::Manager<Resource>::ActiveIterator it; |
338 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 338 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
339 | if ( (*it) == resource ) { | 339 | if ( (*it) == resource ) { |
340 | if ( (*it)->readOnly() || !(*it)->isOpen() ) | 340 | if ( (*it)->readOnly() || !(*it)->isOpen() ) |
341 | return 0; | 341 | return 0; |
342 | else | 342 | else |
343 | return (*it)->requestSaveTicket(); | 343 | return (*it)->requestSaveTicket(); |
344 | } | 344 | } |
345 | } | 345 | } |
346 | 346 | ||
347 | return 0; | 347 | return 0; |
348 | } | 348 | } |
349 | 349 | ||
350 | void AddressBook::insertAddressee( const Addressee &a ) | 350 | void AddressBook::insertAddressee( const Addressee &a ) |
351 | { | 351 | { |
352 | Addressee::List::Iterator it; | 352 | Addressee::List::Iterator it; |
353 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { | 353 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { |
354 | if ( a.uid() == (*it).uid() ) { | 354 | if ( a.uid() == (*it).uid() ) { |
355 | bool changed = false; | 355 | bool changed = false; |
356 | Addressee addr = a; | 356 | Addressee addr = a; |
357 | if ( addr != (*it) ) | 357 | if ( addr != (*it) ) |
358 | changed = true; | 358 | changed = true; |
359 | 359 | ||
360 | (*it) = a; | 360 | (*it) = a; |
361 | if ( (*it).resource() == 0 ) | 361 | if ( (*it).resource() == 0 ) |
362 | (*it).setResource( standardResource() ); | 362 | (*it).setResource( standardResource() ); |
363 | 363 | ||
364 | if ( changed ) { | 364 | if ( changed ) { |
365 | (*it).setRevision( QDateTime::currentDateTime() ); | 365 | (*it).setRevision( QDateTime::currentDateTime() ); |
366 | (*it).setChanged( true ); | 366 | (*it).setChanged( true ); |
367 | } | 367 | } |
368 | 368 | ||
369 | return; | 369 | return; |
370 | } | 370 | } |
371 | } | 371 | } |
372 | d->mAddressees.append( a ); | 372 | d->mAddressees.append( a ); |
373 | Addressee& addr = d->mAddressees.last(); | 373 | Addressee& addr = d->mAddressees.last(); |
374 | if ( addr.resource() == 0 ) | 374 | if ( addr.resource() == 0 ) |
375 | addr.setResource( standardResource() ); | 375 | addr.setResource( standardResource() ); |
376 | 376 | ||
377 | addr.setChanged( true ); | 377 | addr.setChanged( true ); |
378 | } | 378 | } |
379 | 379 | ||
380 | void AddressBook::removeAddressee( const Addressee &a ) | 380 | void AddressBook::removeAddressee( const Addressee &a ) |
381 | { | 381 | { |
382 | Iterator it; | 382 | Iterator it; |
383 | for ( it = begin(); it != end(); ++it ) { | 383 | for ( it = begin(); it != end(); ++it ) { |
384 | if ( a.uid() == (*it).uid() ) { | 384 | if ( a.uid() == (*it).uid() ) { |
385 | removeAddressee( it ); | 385 | removeAddressee( it ); |
386 | return; | 386 | return; |
387 | } | 387 | } |
388 | } | 388 | } |
389 | } | 389 | } |
390 | 390 | ||
391 | void AddressBook::removeAddressee( const Iterator &it ) | 391 | void AddressBook::removeAddressee( const Iterator &it ) |
392 | { | 392 | { |
393 | d->mRemovedAddressees.append( (*it) ); | 393 | d->mRemovedAddressees.append( (*it) ); |
394 | d->mAddressees.remove( it.d->mIt ); | 394 | d->mAddressees.remove( it.d->mIt ); |
395 | } | 395 | } |
396 | 396 | ||
397 | AddressBook::Iterator AddressBook::find( const Addressee &a ) | 397 | AddressBook::Iterator AddressBook::find( const Addressee &a ) |
398 | { | 398 | { |
399 | Iterator it; | 399 | Iterator it; |
400 | for ( it = begin(); it != end(); ++it ) { | 400 | for ( it = begin(); it != end(); ++it ) { |
401 | if ( a.uid() == (*it).uid() ) { | 401 | if ( a.uid() == (*it).uid() ) { |
402 | return it; | 402 | return it; |
403 | } | 403 | } |
404 | } | 404 | } |
405 | return end(); | 405 | return end(); |
406 | } | 406 | } |
407 | 407 | ||
408 | Addressee AddressBook::findByUid( const QString &uid ) | 408 | Addressee AddressBook::findByUid( const QString &uid ) |
409 | { | 409 | { |
410 | Iterator it; | 410 | Iterator it; |
411 | for ( it = begin(); it != end(); ++it ) { | 411 | for ( it = begin(); it != end(); ++it ) { |
412 | if ( uid == (*it).uid() ) { | 412 | if ( uid == (*it).uid() ) { |
413 | return *it; | 413 | return *it; |
414 | } | 414 | } |
415 | } | 415 | } |
416 | return Addressee(); | 416 | return Addressee(); |
417 | } | 417 | } |
418 | 418 | ||
419 | Addressee::List AddressBook::allAddressees() | 419 | Addressee::List AddressBook::allAddressees() |
420 | { | 420 | { |
421 | return d->mAddressees; | 421 | return d->mAddressees; |
422 | } | 422 | } |
423 | 423 | ||
424 | Addressee::List AddressBook::findByName( const QString &name ) | 424 | Addressee::List AddressBook::findByName( const QString &name ) |
425 | { | 425 | { |
426 | Addressee::List results; | 426 | Addressee::List results; |
427 | 427 | ||
428 | Iterator it; | 428 | Iterator it; |
429 | for ( it = begin(); it != end(); ++it ) { | 429 | for ( it = begin(); it != end(); ++it ) { |
430 | if ( name == (*it).name() ) { | 430 | if ( name == (*it).realName() ) { |
431 | results.append( *it ); | 431 | results.append( *it ); |
432 | } | 432 | } |
433 | } | 433 | } |
434 | 434 | ||
435 | return results; | 435 | return results; |
436 | } | 436 | } |
437 | 437 | ||
438 | Addressee::List AddressBook::findByEmail( const QString &email ) | 438 | Addressee::List AddressBook::findByEmail( const QString &email ) |
439 | { | 439 | { |
440 | Addressee::List results; | 440 | Addressee::List results; |
441 | QStringList mailList; | 441 | QStringList mailList; |
442 | 442 | ||
443 | Iterator it; | 443 | Iterator it; |
444 | for ( it = begin(); it != end(); ++it ) { | 444 | for ( it = begin(); it != end(); ++it ) { |
445 | mailList = (*it).emails(); | 445 | mailList = (*it).emails(); |
446 | for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { | 446 | for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { |
447 | if ( email == (*ite) ) { | 447 | if ( email == (*ite) ) { |
448 | results.append( *it ); | 448 | results.append( *it ); |
449 | } | 449 | } |
450 | } | 450 | } |
451 | } | 451 | } |
452 | 452 | ||
453 | return results; | 453 | return results; |
454 | } | 454 | } |
455 | 455 | ||
456 | Addressee::List AddressBook::findByCategory( const QString &category ) | 456 | Addressee::List AddressBook::findByCategory( const QString &category ) |
457 | { | 457 | { |
458 | Addressee::List results; | 458 | Addressee::List results; |
459 | 459 | ||
460 | Iterator it; | 460 | Iterator it; |
461 | for ( it = begin(); it != end(); ++it ) { | 461 | for ( it = begin(); it != end(); ++it ) { |
462 | if ( (*it).hasCategory( category) ) { | 462 | if ( (*it).hasCategory( category) ) { |
463 | results.append( *it ); | 463 | results.append( *it ); |
464 | } | 464 | } |
465 | } | 465 | } |
466 | 466 | ||
467 | return results; | 467 | return results; |
468 | } | 468 | } |
469 | 469 | ||
470 | void AddressBook::dump() const | 470 | void AddressBook::dump() const |
471 | { | 471 | { |
472 | kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; | 472 | kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; |
473 | 473 | ||
474 | ConstIterator it; | 474 | ConstIterator it; |
475 | for( it = begin(); it != end(); ++it ) { | 475 | for( it = begin(); it != end(); ++it ) { |
476 | (*it).dump(); | 476 | (*it).dump(); |
477 | } | 477 | } |
478 | 478 | ||
479 | kdDebug(5700) << "AddressBook::dump() --- end ---" << endl; | 479 | kdDebug(5700) << "AddressBook::dump() --- end ---" << endl; |
480 | } | 480 | } |
481 | 481 | ||
482 | QString AddressBook::identifier() | 482 | QString AddressBook::identifier() |
483 | { | 483 | { |
484 | QStringList identifier; | 484 | QStringList identifier; |
485 | 485 | ||
486 | 486 | ||
487 | KRES::Manager<Resource>::ActiveIterator it; | 487 | KRES::Manager<Resource>::ActiveIterator it; |
488 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 488 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
489 | if ( !(*it)->identifier().isEmpty() ) | 489 | if ( !(*it)->identifier().isEmpty() ) |
490 | identifier.append( (*it)->identifier() ); | 490 | identifier.append( (*it)->identifier() ); |
491 | } | 491 | } |
492 | 492 | ||
493 | return identifier.join( ":" ); | 493 | return identifier.join( ":" ); |
494 | } | 494 | } |
495 | 495 | ||
496 | Field::List AddressBook::fields( int category ) | 496 | Field::List AddressBook::fields( int category ) |
497 | { | 497 | { |
498 | if ( d->mAllFields.isEmpty() ) { | 498 | if ( d->mAllFields.isEmpty() ) { |
499 | d->mAllFields = Field::allFields(); | 499 | d->mAllFields = Field::allFields(); |
500 | } | 500 | } |
501 | 501 | ||
502 | if ( category == Field::All ) return d->mAllFields; | 502 | if ( category == Field::All ) return d->mAllFields; |
503 | 503 | ||
504 | Field::List result; | 504 | Field::List result; |
505 | Field::List::ConstIterator it; | 505 | Field::List::ConstIterator it; |
506 | for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) { | 506 | for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) { |
507 | if ( (*it)->category() & category ) result.append( *it ); | 507 | if ( (*it)->category() & category ) result.append( *it ); |
508 | } | 508 | } |
509 | 509 | ||
510 | return result; | 510 | return result; |
511 | } | 511 | } |
512 | 512 | ||
513 | bool AddressBook::addCustomField( const QString &label, int category, | 513 | bool AddressBook::addCustomField( const QString &label, int category, |
514 | const QString &key, const QString &app ) | 514 | const QString &key, const QString &app ) |
515 | { | 515 | { |
516 | if ( d->mAllFields.isEmpty() ) { | 516 | if ( d->mAllFields.isEmpty() ) { |
517 | d->mAllFields = Field::allFields(); | 517 | d->mAllFields = Field::allFields(); |
518 | } | 518 | } |
519 | //US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app; | 519 | //US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app; |
520 | QString a = app.isNull() ? KGlobal::getAppName() : app; | 520 | QString a = app.isNull() ? KGlobal::getAppName() : app; |
521 | 521 | ||
522 | QString k = key.isNull() ? label : key; | 522 | QString k = key.isNull() ? label : key; |
523 | 523 | ||
524 | Field *field = Field::createCustomField( label, category, k, a ); | 524 | Field *field = Field::createCustomField( label, category, k, a ); |
525 | 525 | ||
526 | if ( !field ) return false; | 526 | if ( !field ) return false; |
diff --git a/kabc/stdaddressbook.cpp b/kabc/stdaddressbook.cpp index 760820e..9f38f08 100644 --- a/kabc/stdaddressbook.cpp +++ b/kabc/stdaddressbook.cpp | |||
@@ -1,198 +1,208 @@ | |||
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 | /* |
22 | Enhanced Version of the file for platform independent KDE tools. | 22 | Enhanced Version of the file for platform independent KDE tools. |
23 | Copyright (c) 2004 Ulf Schenk | 23 | Copyright (c) 2004 Ulf Schenk |
24 | 24 | ||
25 | $Id$ | 25 | $Id$ |
26 | */ | 26 | */ |
27 | 27 | ||
28 | #include <qdir.h> | 28 | #include <qdir.h> |
29 | #include "resource.h" | 29 | #include "resource.h" |
30 | #include <kresources/manager.h> | 30 | #include <kresources/manager.h> |
31 | #include <kdebug.h> | 31 | #include <kdebug.h> |
32 | #include <klocale.h> | 32 | #include <klocale.h> |
33 | #include <kstaticdeleter.h> | 33 | #include <kstaticdeleter.h> |
34 | #include <kstandarddirs.h> | 34 | #include <kstandarddirs.h> |
35 | 35 | ||
36 | #include "stdaddressbook.h" | 36 | #include "stdaddressbook.h" |
37 | 37 | ||
38 | using namespace KABC; | 38 | using namespace KABC; |
39 | 39 | ||
40 | StdAddressBook *StdAddressBook::mSelf = 0; | 40 | StdAddressBook *StdAddressBook::mSelf = 0; |
41 | bool StdAddressBook::mAutomaticSave = true; | 41 | bool StdAddressBook::mAutomaticSave = true; |
42 | 42 | ||
43 | static KStaticDeleter<StdAddressBook> addressBookDeleter; | 43 | static KStaticDeleter<StdAddressBook> addressBookDeleter; |
44 | 44 | ||
45 | QString StdAddressBook::fileName() | 45 | QString StdAddressBook::fileName() |
46 | { | 46 | { |
47 | return locateLocal( "data", "kabc/std.vcf" ); | 47 | return locateLocal( "data", "kabc/std.vcf" ); |
48 | } | 48 | } |
49 | 49 | ||
50 | QString StdAddressBook::directoryName() | 50 | QString StdAddressBook::directoryName() |
51 | { | 51 | { |
52 | return locateLocal( "data", "kabc/stdvcf" ); | 52 | return locateLocal( "data", "kabc/stdvcf" ); |
53 | } | 53 | } |
54 | 54 | ||
55 | void StdAddressBook::handleCrash() | 55 | void StdAddressBook::handleCrash() |
56 | { | 56 | { |
57 | StdAddressBook::self()->cleanUp(); | 57 | StdAddressBook::self()->cleanUp(); |
58 | } | 58 | } |
59 | 59 | ||
60 | StdAddressBook *StdAddressBook::self() | 60 | StdAddressBook *StdAddressBook::self() |
61 | { | 61 | { |
62 | 62 | ||
63 | if ( !mSelf ) | 63 | if ( !mSelf ) |
64 | { | 64 | { |
65 | QString appdir = StdAddressBook::setTempAppDir(); | 65 | QString appdir = StdAddressBook::setTempAppDir(); |
66 | 66 | qDebug("****************************************************** "); | |
67 | kdDebug(5700) << "StdAddressBook::self()" << endl; | 67 | qDebug("****************************************************** "); |
68 | qDebug("****************************************************** "); | ||
69 | qDebug("****************************************************** "); | ||
70 | qDebug("****************************************************** "); | ||
68 | // US im am not sure why I have to use the other format here?? | 71 | // US im am not sure why I have to use the other format here?? |
69 | #ifdef KAB_EMBEDDED | 72 | #ifdef KAB_EMBEDDED |
70 | mSelf = addressBookDeleter.setObject( new StdAddressBook ); | 73 | mSelf = addressBookDeleter.setObject( new StdAddressBook ); |
71 | #else //KAB_EMBEDDED | 74 | #else //KAB_EMBEDDED |
72 | addressBookDeleter.setObject( mSelf, new StdAddressBook ); | 75 | addressBookDeleter.setObject( mSelf, new StdAddressBook ); |
73 | #endif //KAB_EMBEDDED | 76 | #endif //KAB_EMBEDDED |
74 | KStandardDirs::setAppDir( appdir ); | 77 | KStandardDirs::setAppDir( appdir ); |
75 | } | 78 | } |
76 | 79 | ||
77 | return mSelf; | 80 | return mSelf; |
78 | } | 81 | } |
79 | 82 | ||
80 | QString StdAddressBook::setTempAppDir() | 83 | QString StdAddressBook::setTempAppDir() |
81 | { | 84 | { |
82 | QString appDIR = KStandardDirs::appDir(); | 85 | QString appDIR = KStandardDirs::appDir(); |
83 | #ifdef DESKTOP_VERSION | 86 | #ifdef DESKTOP_VERSION |
84 | QString appdir = QDir::homeDirPath(); | 87 | QString appdir = QDir::homeDirPath(); |
85 | if ( appdir.right(1) == "\\" || appdir.right(1) == "/" ) | 88 | if ( appdir.right(1) == "\\" || appdir.right(1) == "/" ) |
86 | appdir += "kaddressbook/"; | 89 | appdir += "kaddressbook/"; |
87 | else | 90 | else |
88 | appdir += "/kaddressbook/"; | 91 | appdir += "/kaddressbook/"; |
89 | KStandardDirs::setAppDir( QDir::convertSeparators( appdir )); | 92 | KStandardDirs::setAppDir( QDir::convertSeparators( appdir )); |
90 | #else | 93 | #else |
91 | QString appdir = QDir::homeDirPath() + "/kdepim/apps/kaddressbook"; | 94 | QString appdir = QDir::homeDirPath() + "/kdepim/apps/kaddressbook"; |
92 | 95 | ||
93 | KStandardDirs::setAppDir( appdir ); | 96 | KStandardDirs::setAppDir( appdir ); |
94 | #endif | 97 | #endif |
95 | 98 | ||
96 | return appDIR; | 99 | return appDIR; |
97 | } | 100 | } |
98 | StdAddressBook *StdAddressBook::self( bool onlyFastResources ) | 101 | StdAddressBook *StdAddressBook::self( bool onlyFastResources ) |
99 | { | 102 | { |
100 | 103 | ||
101 | if ( !mSelf ) | 104 | if ( !mSelf ) |
102 | { | 105 | { |
106 | qDebug("++++++++++++++++++++++++++++++++++++++++++++++++ "); | ||
107 | qDebug("++++++++++++++++++++++++++++++++++++++++++++++++ "); | ||
108 | qDebug("++++++++++++++++++++++++++++++++++++++++++++++++ "); | ||
109 | qDebug("++++++++++++++++++++++++++++++++++++++++++++++++ "); | ||
110 | qDebug("++++++++++++++++++++++++++++++++++++++++++++++++ "); | ||
111 | qDebug("++++++++++++++++++++++++++++++++++++++++++++++++ "); | ||
112 | qDebug("++++++++++++++++++++++++++++++++++++++++++++++++ "); | ||
103 | QString appdir =StdAddressBook::setTempAppDir(); | 113 | QString appdir =StdAddressBook::setTempAppDir(); |
104 | #ifdef KAB_EMBEDDED | 114 | #ifdef KAB_EMBEDDED |
105 | mSelf = addressBookDeleter.setObject( new StdAddressBook( onlyFastResources ) ); | 115 | mSelf = addressBookDeleter.setObject( new StdAddressBook( onlyFastResources ) ); |
106 | #else //KAB_EMBEDDED | 116 | #else //KAB_EMBEDDED |
107 | addressBookDeleter.setObject( mSelf, new StdAddressBook( onlyFastResources ) ); | 117 | addressBookDeleter.setObject( mSelf, new StdAddressBook( onlyFastResources ) ); |
108 | #endif //KAB_EMBEDDED | 118 | #endif //KAB_EMBEDDED |
109 | KStandardDirs::setAppDir( appdir ); | 119 | KStandardDirs::setAppDir( appdir ); |
110 | } | 120 | } |
111 | return mSelf; | 121 | return mSelf; |
112 | } | 122 | } |
113 | 123 | ||
114 | StdAddressBook::StdAddressBook() | 124 | StdAddressBook::StdAddressBook() |
115 | : AddressBook( "kabcrc" ) | 125 | : AddressBook( "kabcrc" ) |
116 | { | 126 | { |
117 | 127 | ||
118 | init( false ); | 128 | init( false ); |
119 | } | 129 | } |
120 | 130 | ||
121 | StdAddressBook::StdAddressBook( bool onlyFastResources ) | 131 | StdAddressBook::StdAddressBook( bool onlyFastResources ) |
122 | : AddressBook( "kabcrc" ) | 132 | : AddressBook( "kabcrc" ) |
123 | { | 133 | { |
124 | 134 | ||
125 | init( onlyFastResources ); | 135 | init( onlyFastResources ); |
126 | } | 136 | } |
127 | 137 | ||
128 | StdAddressBook::~StdAddressBook() | 138 | StdAddressBook::~StdAddressBook() |
129 | { | 139 | { |
130 | if ( mAutomaticSave ) | 140 | if ( mAutomaticSave ) |
131 | save(); | 141 | save(); |
132 | } | 142 | } |
133 | 143 | ||
134 | void StdAddressBook::init( bool ) | 144 | void StdAddressBook::init( bool ) |
135 | { | 145 | { |
136 | KRES::Manager<Resource> *manager = resourceManager(); | 146 | KRES::Manager<Resource> *manager = resourceManager(); |
137 | KRES::Manager<Resource>::ActiveIterator it; | 147 | KRES::Manager<Resource>::ActiveIterator it; |
138 | 148 | ||
139 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | 149 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { |
140 | (*it)->setAddressBook( this ); | 150 | (*it)->setAddressBook( this ); |
141 | if ( !(*it)->open() ) | 151 | if ( !(*it)->open() ) |
142 | error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); | 152 | error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); |
143 | } | 153 | } |
144 | 154 | ||
145 | Resource *res = standardResource(); | 155 | Resource *res = standardResource(); |
146 | if ( !res ) { | 156 | if ( !res ) { |
147 | res = manager->createResource( "file" ); | 157 | res = manager->createResource( "file" ); |
148 | if ( res ) | 158 | if ( res ) |
149 | { | 159 | { |
150 | addResource( res ); | 160 | addResource( res ); |
151 | } | 161 | } |
152 | else | 162 | else |
153 | qDebug(" No resource available!!!"); | 163 | qDebug(" No resource available!!!"); |
154 | } | 164 | } |
155 | 165 | ||
156 | setStandardResource( res ); | 166 | setStandardResource( res ); |
157 | manager->writeConfig(); | 167 | manager->writeConfig(); |
158 | 168 | ||
159 | load(); | 169 | load(); |
160 | } | 170 | } |
161 | 171 | ||
162 | bool StdAddressBook::save() | 172 | bool StdAddressBook::save() |
163 | { | 173 | { |
164 | kdDebug(5700) << "StdAddressBook::save()" << endl; | 174 | kdDebug(5700) << "StdAddressBook::save()" << endl; |
165 | 175 | ||
166 | bool ok = true; | 176 | bool ok = true; |
167 | AddressBook *ab = self(); | 177 | AddressBook *ab = self(); |
168 | 178 | ||
169 | ab->deleteRemovedAddressees(); | 179 | ab->deleteRemovedAddressees(); |
170 | 180 | ||
171 | KRES::Manager<Resource>::ActiveIterator it; | 181 | KRES::Manager<Resource>::ActiveIterator it; |
172 | KRES::Manager<Resource> *manager = ab->resourceManager(); | 182 | KRES::Manager<Resource> *manager = ab->resourceManager(); |
173 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | 183 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { |
174 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { | 184 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { |
175 | Ticket *ticket = ab->requestSaveTicket( *it ); | 185 | Ticket *ticket = ab->requestSaveTicket( *it ); |
176 | // qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); | 186 | // qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); |
177 | if ( !ticket ) { | 187 | if ( !ticket ) { |
178 | ab->error( i18n( "Unable to save to resource '%1'. It is locked." ) | 188 | ab->error( i18n( "Unable to save to resource '%1'. It is locked." ) |
179 | .arg( (*it)->resourceName() ) ); | 189 | .arg( (*it)->resourceName() ) ); |
180 | return false; | 190 | return false; |
181 | } | 191 | } |
182 | 192 | ||
183 | if ( !ab->save( ticket ) ) | 193 | if ( !ab->save( ticket ) ) |
184 | ok = false; | 194 | ok = false; |
185 | } | 195 | } |
186 | } | 196 | } |
187 | 197 | ||
188 | return ok; | 198 | return ok; |
189 | } | 199 | } |
190 | 200 | ||
191 | void StdAddressBook::close() | 201 | void StdAddressBook::close() |
192 | { | 202 | { |
193 | //US destructObject is not defined on my system???. Is setObject(0) the same ??? | 203 | //US destructObject is not defined on my system???. Is setObject(0) the same ??? |
194 | //US addressBookDeleter.destructObject(); | 204 | //US addressBookDeleter.destructObject(); |
195 | addressBookDeleter.setObject(0); | 205 | addressBookDeleter.setObject(0); |
196 | 206 | ||
197 | } | 207 | } |
198 | 208 | ||