21#include "stdaddressbook.h"
24#include "kresources/manager.h"
27#include <klocalizedstring.h>
29#include <kstandarddirs.h>
30#include <kconfiggroup.h>
32 #include <QCoreApplication>
38class StdAddressBook::Private
46 void init(
bool asynchronous );
50 static bool mAutomaticSave;
54bool StdAddressBook::Private::mAutomaticSave =
true;
56static 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;
109StdAddressBook::StdAddressBook()
110 :
AddressBook( QString() ), d( new Private( this ) )
117StdAddressBook::StdAddressBook(
bool asynchronous )
118 :
AddressBook( QString() ), d( new Private( this ) )
122 d->init( asynchronous );
125StdAddressBook::StdAddressBook(
bool asynchronous,
bool doInit )
126 :
AddressBook( QString() ), d( new Private( this ) )
131 d->init( asynchronous );
137 if ( Private::mAutomaticSave ) {
144void 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*)) );
160 mParent->connect( *it, SIGNAL(loadingError(
Resource*,QString)),
161 mParent, SLOT(resourceLoadingError(
Resource*,QString)) );
162 mParent->connect( *it, SIGNAL(savingError(
Resource*,QString)),
163 mParent, SLOT(resourceSavingError(
Resource*,QString)) );
166 Resource *res = mParent->standardResource();
171 mParent->addResource( res );
173 kDebug() <<
"No resource available!!!";
177 mParent->setStandardResource( res );
180 if ( asynchronous ) {
181 mParent->asyncLoad();
187bool 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;
242 KConfig _config( QLatin1String(
"kabcrc" ) );
243 KConfigGroup config(&_config,
"General" );
245 return findByUid( config.readEntry(
"WhoAmI" ) );
250 KConfig _config( QLatin1String(
"kabcrc" ) );
251 KConfigGroup config(&_config,
"General" );
253 config.writeEntry(
"WhoAmI", addr.
uid() );
Addressee findByUid(const QString &uid) const
Searches an addressee with the specified unique identifier.
QString uid() const
Return unique identifier.
Standard KDE address book.
~StdAddressBook()
Destructor.
static bool automaticSave()
Returns whether the address book is saved at destruction time.
Addressee whoAmI() const
Returns the contact, that is associated with the owner of the address book.
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.
void setWhoAmI(const Addressee &addr)
Sets the users contact.
static KABC_DEPRECATED bool save()
Saves the standard address book to disk.
static void close()
Closes the address book.
static QString directoryName()
Returns the default directory name for vcard-based addressbook.
static StdAddressBook * self()
Returns the standard addressbook object.
Helper class for handling coordinated save of address books.
void writeConfig(KConfig *cfg=0)
ActiveIterator activeBegin()
ActiveIterator activeEnd()
T * createResource(const QString &type)
virtual void setResourceName(const QString &name)
Class that holds a Calendar Url (FBURL/CALADRURI/CALURI)