21 #include "stdaddressbook.h"
24 #include "kresources/manager.h"
27 #include <klocalizedstring.h>
29 #include <kstandarddirs.h>
30 #include <kconfiggroup.h>
32 #include <QCoreApplication>
38 class StdAddressBook::Private
46 void init(
bool asynchronous );
50 static bool mAutomaticSave;
54 bool StdAddressBook::Private::mAutomaticSave =
true;
56 static void deleteGlobalStdAddressBook()
58 if ( s_gStdAddressBook ) {
59 delete s_gStdAddressBook;
60 s_gStdAddressBook = 0;
66 return KStandardDirs::locateLocal(
"data",
QLatin1String(
"kabc/std.vcf" ) );
71 return KStandardDirs::locateLocal(
"data",
QLatin1String(
"kabc/stdvcf" ) );
86 kDebug() <<
"asynchronous=" << asynchronous;
88 if ( !s_gStdAddressBook ) {
91 kDebug() <<
"calling init after instance creation";
92 s_gStdAddressBook->d->init( asynchronous );
103 qAddPostRoutine( deleteGlobalStdAddressBook );
106 return s_gStdAddressBook;
109 StdAddressBook::StdAddressBook()
117 StdAddressBook::StdAddressBook(
bool asynchronous )
122 d->init( asynchronous );
125 StdAddressBook::StdAddressBook(
bool asynchronous,
bool doInit )
131 d->init( asynchronous );
137 if ( Private::mAutomaticSave ) {
144 void StdAddressBook::Private::init(
bool asynchronous )
150 ( *it )->setAddressBook( mParent );
151 if ( !( *it )->open() ) {
152 mParent->error( i18n(
"Unable to open resource '%1'.", ( *it )->resourceName() ) );
155 mParent->connect( *it, SIGNAL(loadingFinished(
Resource*)),
156 mParent, SLOT(resourceLoadingFinished(
Resource*)) );
157 mParent->connect( *it, SIGNAL(savingFinished(
Resource*)),
158 mParent, SLOT(resourceSavingFinished(
Resource*)) );
166 Resource *res = mParent->standardResource();
171 mParent->addResource( res );
173 kDebug() <<
"No resource available!!!";
177 mParent->setStandardResource( res );
180 if ( asynchronous ) {
181 mParent->asyncLoad();
187 bool StdAddressBook::Private::saveAll()
195 if ( !( *it )->readOnly() && ( *it )->isOpen() ) {
196 Ticket *ticket = mParent->requestSaveTicket( *it );
198 mParent->error( i18n(
"Unable to save to resource '%1'. It is locked.",
199 ( *it )->resourceName() ) );
203 if ( !mParent->AddressBook::save( ticket ) ) {
205 mParent->releaseSaveTicket( ticket );
217 if ( s_gStdAddressBook ) {
218 return s_gStdAddressBook->d->saveAll();
226 delete s_gStdAddressBook;
227 s_gStdAddressBook = 0;
232 Private::mAutomaticSave = enable;
237 return Private::mAutomaticSave;
243 KConfigGroup config(&_config,
"General" );
245 return findByUid( config.readEntry(
"WhoAmI" ) );
251 KConfigGroup config(&_config,
"General" );
253 config.writeEntry(
"WhoAmI", addr.
uid() );
Standard KDE address book.
static bool automaticSave()
Returns whether the address book is saved at destruction time.
static void setAutomaticSave(bool state)
Sets the automatic save property of the address book.
static QString fileName()
Returns the default file name for vcard-based addressbook.
Addressee whoAmI() const
Returns the contact, that is associated with the owner of the address book.
static KABC_DEPRECATED bool save()
Saves the standard address book to disk.
Addressee findByUid(const QString &uid) const
Searches an addressee with the specified unique identifier.
Helper class for handling coordinated save of address books.
T * createResource(const QString &type)
ActiveIterator activeEnd()
~StdAddressBook()
Destructor.
static QString directoryName()
Returns the default directory name for vcard-based addressbook.
void setWhoAmI(const Addressee &addr)
Sets the users contact.
void writeConfig(KConfig *cfg=0)
virtual void setResourceName(const QString &name)
QString uid() const
Return unique identifier.
static StdAddressBook * self()
Returns the standard addressbook object.
static void close()
Closes the address book.
ActiveIterator activeBegin()