23 #include <kapplication.h>
27 #include <kresources/manager.h>
28 #include <ksimpleconfig.h>
29 #include <kstandarddirs.h>
30 #include <kstaticdeleter.h>
34 #include "stdaddressbook.h"
39 bool StdAddressBook::mAutomaticSave =
true;
68 addressBookDeleter.setObject( mSelf,
new StdAddressBook( asynchronous ) );
73 StdAddressBook::StdAddressBook()
76 kdDebug(5700) <<
"StdAddressBook::StdAddressBook()" <<
endl;
81 StdAddressBook::StdAddressBook(
bool asynchronous )
84 kdDebug(5700) <<
"StdAddressBook::StdAddressBook( bool )" <<
endl;
95 void StdAddressBook::init(
bool asynchronous )
97 KRES::Manager<Resource> *manager = resourceManager();
99 KRES::Manager<Resource>::ActiveIterator it;
100 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
101 (*it)->setAddressBook(
this );
102 if ( !(*it)->open() ) {
103 error( TQString(
"Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) );
107 this, TQT_SLOT( resourceLoadingFinished( Resource* ) ) );
109 this, TQT_SLOT( resourceSavingFinished( Resource* ) ) );
111 connect( *it, TQT_SIGNAL( loadingError( Resource*,
const TQString& ) ),
112 this, TQT_SLOT( resourceLoadingError( Resource*,
const TQString& ) ) );
113 connect( *it, TQT_SIGNAL( savingError( Resource*,
const TQString& ) ),
114 this, TQT_SLOT( resourceSavingError( Resource*,
const TQString& ) ) );
117 Resource *res = standardResource();
119 res = manager->createResource(
"file" );
123 kdDebug(5700) <<
"No resource available!!!" <<
endl;
126 setStandardResource( res );
127 manager->writeConfig();
135 bool StdAddressBook::saveAll()
137 kdDebug(5700) <<
"StdAddressBook::saveAll()" <<
endl;
140 deleteRemovedAddressees();
142 KRES::Manager<Resource>::ActiveIterator it;
143 KRES::Manager<Resource> *manager = resourceManager();
144 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
145 if ( !(*it)->readOnly() && (*it)->isOpen() ) {
148 error( i18n(
"Unable to save to resource '%1'. It is locked." )
149 .arg( (*it)->resourceName() ) );
168 return mSelf->saveAll();
175 addressBookDeleter.destructObject();
180 mAutomaticSave = enable;
185 return mAutomaticSave;