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
41 Private( StdAddressBook *parent )
46 void init(
bool asynchronous );
49 StdAddressBook *mParent;
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 ) {
89 s_gStdAddressBook =
new StdAddressBook( asynchronous,
false );
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() ) );
160 mParent->connect( *it, SIGNAL(loadingError(
Resource*,QString)),
162 mParent->connect( *it, SIGNAL(savingError(
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()
192 KRES::Manager<Resource>::ActiveIterator it;
193 KRES::Manager<Resource> *manager = mParent->resourceManager();
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() );
void savingFinished(Resource *resource)
Emitted when the asynchronous saving of one resource has finished after calling asyncSave().
void resourceLoadingFinished(Resource *resource)
Handles loading success.
void error(const QString &msg)
Shows GUI independent error messages.
Addressee findByUid(const QString &uid) const
Searches an addressee with the specified unique identifier.
void resourceSavingFinished(Resource *resource)
Handles saving success.
void loadingFinished(Resource *resource)
Emitted when the asynchronous loading of one resource has finished after calling asyncLoad().
void resourceLoadingError(Resource *resource, const QString &errMsg)
Handles loading errors.
void resourceSavingError(Resource *resource, const QString &errMsg)
Handles saving errors.
KRES::Manager< Resource > * resourceManager()
Returns the addressbook's resource manager.
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.
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).