author | zautrix <zautrix> | 2005-08-23 14:22:11 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-08-23 14:22:11 (UTC) |
commit | e6d678229580cd712ff82ea989e7b151be546dbd (patch) (side-by-side diff) | |
tree | 1cf32674db62993bcdc636d90b3994e9343a8b5f | |
parent | 02fa432f183ad2b18380de0e41399efe3b867dba (diff) | |
download | kdepimpi-e6d678229580cd712ff82ea989e7b151be546dbd.zip kdepimpi-e6d678229580cd712ff82ea989e7b151be546dbd.tar.gz kdepimpi-e6d678229580cd712ff82ea989e7b151be546dbd.tar.bz2 |
stdab fix
-rw-r--r-- | kabc/stdaddressbook.cpp | 27 | ||||
-rw-r--r-- | kabc/stdaddressbook.h | 2 | ||||
-rw-r--r-- | kaddressbook/kabcore.cpp | 2 |
3 files changed, 27 insertions, 4 deletions
diff --git a/kabc/stdaddressbook.cpp b/kabc/stdaddressbook.cpp index a14ae20..43d9fde 100644 --- a/kabc/stdaddressbook.cpp +++ b/kabc/stdaddressbook.cpp @@ -1,188 +1,209 @@ /* This file is part of libkabc. Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* Enhanced Version of the file for platform independent KDE tools. Copyright (c) 2004 Ulf Schenk $Id$ */ #include <qdir.h> #include "resource.h" #include <kresources/manager.h> #include <kdebug.h> #include <klocale.h> #include <kstaticdeleter.h> #include <kstandarddirs.h> #include "stdaddressbook.h" using namespace KABC; StdAddressBook *StdAddressBook::mSelf = 0; bool StdAddressBook::mAutomaticSave = false; static KStaticDeleter<StdAddressBook> addressBookDeleter; QString StdAddressBook::fileName() { return locateLocal( "data", "kabc/std.vcf" ); } QString StdAddressBook::directoryName() { return locateLocal( "data", "kabc/stdvcf" ); } void StdAddressBook::handleCrash() { StdAddressBook::self()->cleanUp(); } +StdAddressBook *StdAddressBook::selfNoLoad() +{ + + if ( !mSelf ) + { + QString appdir = StdAddressBook::setTempAppDir(); +// US im am not sure why I have to use the other format here?? +#ifdef KAB_EMBEDDED + mSelf = addressBookDeleter.setObject( new StdAddressBook ( QString() ) ); +#else //KAB_EMBEDDED + addressBookDeleter.setObject( mSelf, new StdAddressBook( QString() ) ); +#endif //KAB_EMBEDDED + KStandardDirs::setAppDir( appdir ); + } + + return mSelf; +} StdAddressBook *StdAddressBook::self() { if ( !mSelf ) { QString appdir = StdAddressBook::setTempAppDir(); // US im am not sure why I have to use the other format here?? #ifdef KAB_EMBEDDED mSelf = addressBookDeleter.setObject( new StdAddressBook ); #else //KAB_EMBEDDED addressBookDeleter.setObject( mSelf, new StdAddressBook ); #endif //KAB_EMBEDDED KStandardDirs::setAppDir( appdir ); } return mSelf; } QString StdAddressBook::setTempAppDir() { QString appDIR = KStandardDirs::appDir(); #ifdef DESKTOP_VERSION QString appdir = QDir::homeDirPath(); if ( appdir.right(1) == "\\" || appdir.right(1) == "/" ) appdir += "kaddressbook/"; else appdir += "/kaddressbook/"; KStandardDirs::setAppDir( QDir::convertSeparators( appdir )); #else QString appdir = QDir::homeDirPath() + "/kdepim/apps/kaddressbook"; KStandardDirs::setAppDir( appdir ); #endif return appDIR; } StdAddressBook *StdAddressBook::self( bool onlyFastResources ) { if ( !mSelf ) { QString appdir =StdAddressBook::setTempAppDir(); #ifdef KAB_EMBEDDED mSelf = addressBookDeleter.setObject( new StdAddressBook( onlyFastResources ) ); #else //KAB_EMBEDDED addressBookDeleter.setObject( mSelf, new StdAddressBook( onlyFastResources ) ); #endif //KAB_EMBEDDED KStandardDirs::setAppDir( appdir ); } return mSelf; } +StdAddressBook::StdAddressBook( QString ) + : AddressBook( "kabcrc" ) +{ + +} StdAddressBook::StdAddressBook() : AddressBook( "kabcrc" ) { - //init( false ); + init( false ); } StdAddressBook::StdAddressBook( bool onlyFastResources ) : AddressBook( "kabcrc" ) { - if ( onlyFastResources ) - init( onlyFastResources ); + init( onlyFastResources ); } StdAddressBook::~StdAddressBook() { if ( mAutomaticSave ) save(); } void StdAddressBook::init( bool ) { KRES::Manager<Resource> *manager = resourceManager(); KRES::Manager<Resource>::ActiveIterator it; for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { (*it)->setAddressBook( this ); if ( !(*it)->open() ) error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); } Resource *res = standardResource(); if ( !res ) { res = manager->createResource( "file" ); if ( res ) { addResource( res ); } else qDebug(" No resource available!!!"); } setStandardResource( res ); manager->writeConfig(); load(); } bool StdAddressBook::save() { kdDebug(5700) << "StdAddressBook::save()" << endl; bool ok = true; AddressBook *ab = self(); ab->deleteRemovedAddressees(); Iterator ait; for ( ait = ab->begin(); ait != ab->end(); ++ait ) { if ( !(*ait).IDStr().isEmpty() ) { (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); } } KRES::Manager<Resource>::ActiveIterator it; KRES::Manager<Resource> *manager = ab->resourceManager(); for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { if ( !(*it)->readOnly() && (*it)->isOpen() ) { Ticket *ticket = ab->requestSaveTicket( *it ); // qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); if ( !ticket ) { ab->error( i18n( "Unable to save to resource '%1'. It is locked." ) .arg( (*it)->resourceName() ) ); return false; } if ( !ab->save( ticket ) ) ok = false; diff --git a/kabc/stdaddressbook.h b/kabc/stdaddressbook.h index cf130b3..3cd6363 100644 --- a/kabc/stdaddressbook.h +++ b/kabc/stdaddressbook.h @@ -9,143 +9,145 @@ This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* Enhanced Version of the file for platform independent KDE tools. Copyright (c) 2004 Ulf Schenk $Id$ */ #ifndef KABC_STDADDRESSBOOK_H #define KABC_STDADDRESSBOOK_H #include "addressbook.h" namespace KABC { /** Standard KDE address book This class provides access to the standard KDE address book shared by all applications. It's implemented as a singleton. Use @ref self() to get the address book object. On the first self() call the address book also gets loaded. Example: <pre> KABC::AddressBook *ab = KABC::StdAddressBook::self(); KABC::AddressBook::Iterator it; for ( it = ab->begin(); it != ab->end(); ++it ) { kdDebug() << "UID=" << (*it).uid() << endl; // do some other stuff } KABC::StdAddressBook::save(); </pre> */ class StdAddressBook : public AddressBook { public: /** Destructor. */ ~StdAddressBook(); /** Return the standard addressbook object. It also loads slow resources. It is the same as self(false); . */ static StdAddressBook *self(); + static StdAddressBook *selfNoLoad(); /** This is the same as above, but with specified behaviour of resource loading. @param onlyFastResource Only resources marked as 'fast' should be loaded */ // FIXME for KDE4 return StdAddressBook and merge with the metod above -zecke static StdAddressBook *self( bool onlyFastResources ); /** Save the standard address book to disk. */ static bool save(); /** Call this method in your crash handler to allow the library clean up possible locks. */ static void handleCrash(); /** Returns the default file name for vcard-based addressbook */ static QString fileName(); /** Returns the default directory name for vcard-based addressbook */ static QString directoryName(); /** Set the automatic save property of the address book. If @p enable is TRUE (default) the address book is saved at destruction time otherwise you have to call @ref save() to explicitely save it. */ static void setAutomaticSave( bool enable ); /** Closes the address book. Depending on @ref automaticSave() it will save the address book first. */ static void close(); /** Returns whether the address book is saved at destruction time. See also @ref setAutomaticSave(). */ static bool automaticSave(); /** Returns the contact, that is associated with the owner of the address book. This contact should be used by other programs to access user specific data. */ Addressee whoAmI(); /** Sets the users contact. See @ref whoAmI() for more information. @param uid The uid of the users contact. */ void setWhoAmI( const Addressee &addr ); void init( bool onlyFastResources ); protected: StdAddressBook(); + StdAddressBook( QString ); StdAddressBook( bool onlyFastResources ); private: static QString setTempAppDir(); static StdAddressBook *mSelf; static bool mAutomaticSave; }; } #endif diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index c670b1f..77321aa 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp @@ -242,129 +242,129 @@ class KAex2phonePrefs : public QDialog public: KAex2phonePrefs( QWidget *parent=0, const char *name=0 ) : QDialog( parent, name, true ) { setCaption( i18n("Export to phone options") ); QVBoxLayout* lay = new QVBoxLayout( this ); lay->setSpacing( 3 ); lay->setMargin( 3 ); QLabel *lab; lay->addWidget(lab = new QLabel( i18n("Please read Help-Sync Howto\nto know what settings to use."), this ) ); lab->setAlignment (AlignHCenter ); QHBox* temphb; temphb = new QHBox( this ); new QLabel( i18n("I/O device: "), temphb ); mPhoneDevice = new QLineEdit( temphb); lay->addWidget( temphb ); temphb = new QHBox( this ); new QLabel( i18n("Connection: "), temphb ); mPhoneConnection = new QLineEdit( temphb); lay->addWidget( temphb ); temphb = new QHBox( this ); new QLabel( i18n("Model(opt.): "), temphb ); mPhoneModel = new QLineEdit( temphb); lay->addWidget( temphb ); // mWriteToSim = new QCheckBox( i18n("Write Contacts to SIM card\n(if not, write to phone memory)"), this ); // lay->addWidget( mWriteToSim ); lay->addWidget(lab = new QLabel( i18n("NOTE: This will remove all old\ncontact data on phone!"), this ) ); lab->setAlignment (AlignHCenter); QPushButton * ok = new QPushButton( i18n("Export to mobile phone!"), this ); lay->addWidget( ok ); QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); lay->addWidget( cancel ); connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); resize( 220, 240 ); } public: QLineEdit* mPhoneConnection, *mPhoneDevice, *mPhoneModel; QCheckBox* mWriteToSim; }; bool pasteWithNewUid = true; #ifdef KAB_EMBEDDED KABCore::KABCore( KAddressBookMain *client, bool readWrite, QWidget *parent, const char *name ) : QWidget( parent, name ), KSyncInterface(), mGUIClient( client ), mViewManager( 0 ), mExtensionManager( 0 ),mConfigureDialog( 0 ),/*US mLdapSearchDialog( 0 ),*/ mReadWrite( readWrite ), mModified( false ), mMainWindow(client) #else //KAB_EMBEDDED KABCore::KABCore( KXMLGUIClient *client, bool readWrite, QWidget *parent, const char *name ) : QWidget( parent, name ), KSyncInterface(), mGUIClient( client ), mViewManager( 0 ), mExtensionManager( 0 ), mConfigureDialog( 0 ), mLdapSearchDialog( 0 ), mReadWrite( readWrite ), mModified( false ) #endif //KAB_EMBEDDED { // syncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)this, KSyncManager::KAPI, KABPrefs::instance(), syncMenu); // syncManager->setBlockSave(false); mIncSearchWidget = 0; mMiniSplitter = 0; mExtensionBarSplitter = 0; mIsPart = !parent->inherits( "KAddressBookMain" ); - mAddressBook = KABC::StdAddressBook::self(); + mAddressBook = KABC::StdAddressBook::selfNoLoad(); KABC::StdAddressBook::setAutomaticSave( false ); #ifndef KAB_EMBEDDED mAddressBook->setErrorHandler( new KABC::GUIErrorHandler ); #endif //KAB_EMBEDDED connect( mAddressBook, SIGNAL( addressBookChanged( AddressBook * ) ), SLOT( addressBookChanged() ) ); #if 0 // LR moved to addressbook init method mAddressBook->addCustomField( i18n( "Department" ), KABC::Field::Organization, "X-Department", "KADDRESSBOOK" ); mAddressBook->addCustomField( i18n( "Profession" ), KABC::Field::Organization, "X-Profession", "KADDRESSBOOK" ); mAddressBook->addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, "X-AssistantsName", "KADDRESSBOOK" ); mAddressBook->addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, "X-ManagersName", "KADDRESSBOOK" ); mAddressBook->addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, "X-SpousesName", "KADDRESSBOOK" ); mAddressBook->addCustomField( i18n( "Office" ), KABC::Field::Personal, "X-Office", "KADDRESSBOOK" ); mAddressBook->addCustomField( i18n( "IM Address" ), KABC::Field::Personal, "X-IMAddress", "KADDRESSBOOK" ); mAddressBook->addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, "X-Anniversary", "KADDRESSBOOK" ); //US added this field to become compatible with Opie/qtopia addressbook // values can be "female" or "male" or "". An empty field represents undefined. mAddressBook->addCustomField( i18n( "Gender" ), KABC::Field::Personal, "X-Gender", "KADDRESSBOOK" ); mAddressBook->addCustomField( i18n( "Children" ), KABC::Field::Personal, "X-Children", "KADDRESSBOOK" ); mAddressBook->addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, "X-FreeBusyUrl", "KADDRESSBOOK" ); #endif initGUI(); mIncSearchWidget->setFocus(); connect( mViewManager, SIGNAL( selected( const QString& ) ), SLOT( setContactSelected( const QString& ) ) ); connect( mViewManager, SIGNAL( executed( const QString& ) ), SLOT( executeContact( const QString& ) ) ); connect( mViewManager, SIGNAL( deleteRequest( ) ), SLOT( deleteContacts( ) ) ); connect( mViewManager, SIGNAL( modified() ), SLOT( setModified() ) ); connect( mExtensionManager, SIGNAL( modified( const KABC::Addressee::List& ) ), this, SLOT( extensionModified( const KABC::Addressee::List& ) ) ); connect( mExtensionManager, SIGNAL( changedActiveExtension( int ) ), this, SLOT( extensionChanged( int ) ) ); connect( mXXPortManager, SIGNAL( modified() ), SLOT( setModified() ) ); connect( mJumpButtonBar, SIGNAL( jumpToLetter( const QString& ) ), SLOT( incrementalSearchJump( const QString& ) ) ); connect( mIncSearchWidget, SIGNAL( fieldChanged() ), mJumpButtonBar, SLOT( recreateButtons() ) ); connect( mDetails, SIGNAL( sendEmail( const QString& ) ), |