-rw-r--r-- | kabc/addressbook.cpp | 11 | ||||
-rw-r--r-- | kabc/addressbook.h | 1 | ||||
-rw-r--r-- | kabc/addressee.cpp | 2 | ||||
-rw-r--r-- | kabc/plugins/sharpdtm/resourcesharpdtm.cpp | 137 | ||||
-rw-r--r-- | kabc/tmpaddressbook.cpp | 9 |
5 files changed, 22 insertions, 138 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index 4c4ae09..8487ff3 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp @@ -1131,64 +1131,75 @@ bool AddressBook::addCustomField( const QString &label, int category, return true; } QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab ) { if (!ab.d) return s; return s << ab.d->mAddressees; } QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab ) { if (!ab.d) return s; s >> ab.d->mAddressees; return s; } bool AddressBook::addResource( Resource *resource ) { if ( !resource->open() ) { kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl; return false; } resource->setAddressBook( this ); d->mManager->add( resource ); return true; } +void AddressBook::removeResources() +{ + //remove all possible resources. This should cleanup the configfile. + QPtrList<KABC::Resource> mResources = resources(); + + QPtrListIterator<KABC::Resource> it(mResources); + for ( ; it.current(); ++it ) { + KABC::Resource *res = it.current(); + removeResource(res); + } +} bool AddressBook::removeResource( Resource *resource ) { resource->close(); if ( resource == standardResource() ) d->mManager->setStandardResource( 0 ); resource->setAddressBook( 0 ); d->mManager->remove( resource ); return true; } QPtrList<Resource> AddressBook::resources() { QPtrList<Resource> list; // qDebug("AddressBook::resources() 1"); KRES::Manager<Resource>::ActiveIterator it; for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) list.append( *it ); return list; } /*US void AddressBook::setErrorHandler( ErrorHandler *handler ) { delete d->mErrorHandler; d->mErrorHandler = handler; diff --git a/kabc/addressbook.h b/kabc/addressbook.h index 75f8b51..2351add 100644 --- a/kabc/addressbook.h +++ b/kabc/addressbook.h @@ -245,64 +245,65 @@ class AddressBook : public QObject void emitAddressBookLocked() { emit addressBookLocked( this ); } void emitAddressBookUnlocked() { emit addressBookUnlocked( this ); } void emitAddressBookChanged() { emit addressBookChanged( this ); } /** Return list of all Fields known to the address book which are associated with the given field category. */ Field::List fields( int category = Field::All ); /** Add custom field to address book. @param label User visible label of the field. @param category Ored list of field categories. @param key Identifier used as key for reading and writing the field. @param app String used as application key for reading and writing the field. */ bool addCustomField( const QString &label, int category = Field::All, const QString &key = QString::null, const QString &app = QString::null ); /** Add address book resource. */ bool addResource( Resource * ); /** Remove address book resource. */ + void removeResources(); bool removeResource( Resource * ); /** Return pointer list of all resources. */ QPtrList<Resource> resources(); /** Set the @p ErrorHandler, that is used by @ref error() to provide gui-independend error messages. */ void setErrorHandler( ErrorHandler * ); /** Shows gui independend error messages. */ void error( const QString& ); /** Query all resources to clean up their lock files */ void cleanUp(); // sync stuff //Addressee::List getExternLastSyncAddressees(); void resetTempSyncStat(); QStringList uidList(); void removeSyncAddressees( bool removeDeleted = false ); void mergeAB( AddressBook *aBook, const QString& profile, bool isSubset ); Addressee findByExternUid( const QString& uid , const QString& profile ); bool containsExternalUid( const QString& uid ); diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp index 3d4992c..028d3bb 100644 --- a/kabc/addressee.cpp +++ b/kabc/addressee.cpp @@ -243,65 +243,65 @@ void Addressee::computeCsum(const QString &dev) t.append( ( *phoneIter ).number()+QString::number( ( *phoneIter ).type() ) ); t.sort(); uint iii; for ( iii = 0; iii < t.count(); ++iii) l.append( t[iii] ); t = mData->emails; t.sort(); for ( iii = 0; iii < t.count(); ++iii) l.append( t[iii] ); t = mData->categories; t.sort(); for ( iii = 0; iii < t.count(); ++iii) l.append( t[iii] ); t = mData->custom; t.sort(); for ( iii = 0; iii < t.count(); ++iii) if ( t[iii].left( 25 ) != "KADDRESSBOOK-X-ExternalID" ) { int find = t[iii].find (':')+1; //qDebug("lennnn %d %d ", find, t[iii].length()); if ( find < t[iii].length()) l.append( t[iii] ); } KABC::Address::List::Iterator addressIter; for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end(); ++addressIter ) { t = (*addressIter).asList(); t.sort(); for ( iii = 0; iii < t.count(); ++iii) l.append( t[iii] ); } uint cs = getCsum4List(l); -#if 1 +#if 0 for ( iii = 0; iii < l.count(); ++iii) qDebug("%d***%s***",iii,l[iii].latin1()); qDebug("CSUM computed %d %s %s", cs,QString::number (cs ).latin1(), uid().latin1() ); #endif setCsum( dev, QString::number (cs )); } void Addressee::mergeContact( const Addressee& ad , bool isSubSet) // = false) { detach(); if ( mData->name.isEmpty() ) mData->name = ad.mData->name; if ( mData->formattedName.isEmpty() ) mData->formattedName = ad.mData->formattedName; if ( mData->familyName.isEmpty() ) mData->familyName = ad.mData->familyName; if ( mData->givenName.isEmpty() ) mData->givenName = ad.mData->givenName ; if ( mData->additionalName ) mData->additionalName = ad.mData->additionalName; if ( mData->prefix.isEmpty() ) mData->prefix = ad.mData->prefix; if ( mData->suffix.isEmpty() ) mData->suffix = ad.mData->suffix; if ( mData->nickName.isEmpty() ) mData->nickName = ad.mData->nickName; if ( !mData->birthday.isValid() ) if ( ad.mData->birthday.isValid()) mData->birthday = ad.mData->birthday; if ( mData->mailer.isEmpty() ) mData->mailer = ad.mData->mailer; if ( !mData->timeZone.isValid() ) mData->timeZone = ad.mData->timeZone; if ( !mData->geo.isValid() ) mData->geo = ad.mData->geo; if ( mData->title .isEmpty() ) mData->title = ad.mData->title ; if ( mData->role.isEmpty() ) mData->role = ad.mData->role ; if ( mData->organization.isEmpty() ) mData->organization = ad.mData->organization ; if ( mData->note.isEmpty() ) mData->note = ad.mData->note ; if ( mData->productId.isEmpty() ) mData->productId = ad.mData->productId; if ( mData->sortString.isEmpty() ) mData->sortString = ad.mData->sortString; if ( !mData->secrecy.isValid() ) mData->secrecy = ad.mData->secrecy; diff --git a/kabc/plugins/sharpdtm/resourcesharpdtm.cpp b/kabc/plugins/sharpdtm/resourcesharpdtm.cpp index ba17c50..48b7d91 100644 --- a/kabc/plugins/sharpdtm/resourcesharpdtm.cpp +++ b/kabc/plugins/sharpdtm/resourcesharpdtm.cpp @@ -38,369 +38,248 @@ $Id$ #include <kapplication.h> #include <kconfig.h> #include <kdebug.h> #include <klocale.h> //US #include <ksavefile.h> #include <kstandarddirs.h> #include <kmessagebox.h> #include <sl/slzdb.h> #include <libkdepim/ksyncprofile.h> #include "resourcesharpdtmconfig.h" #include "resourcesharpdtm.h" #include "stdaddressbook.h" #include "sharpdtmconverter.h" //#define ALLOW_LOCKING using namespace KABC; extern "C" { void *init_microkabc_sharpdtm() { return new KRES::PluginFactory<ResourceSharpDTM,ResourceSharpDTMConfig>(); } } ResourceSharpDTM::ResourceSharpDTM( const KConfig *config ) : Resource( config ), mConverter (0) { // we can not choose the filename. Therefore use the default to display - + mAccess = 0; QString fileName = SlZDataBase::addressbookFileName(); init( fileName ); } ResourceSharpDTM::ResourceSharpDTM( const QString &fileName ) : Resource( 0 ) { + mAccess = 0; init( fileName ); } void ResourceSharpDTM::init( const QString &fileName ) { - - connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); - connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); - connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); - setFileName( fileName ); } ResourceSharpDTM::~ResourceSharpDTM() { if (mConverter != 0) delete mConverter; if(mAccess != 0) delete mAccess; } void ResourceSharpDTM::writeConfig( KConfig *config ) { Resource::writeConfig( config ); } Ticket *ResourceSharpDTM::requestSaveTicket() { - qDebug("ResourceSharpDTM::requestSaveTicket: %s", fileName().latin1()); if ( !addressBook() ) return 0; - -#ifdef ALLOW_LOCKING - if ( !lock( fileName() ) ) { - qDebug("ResourceSharpDTM::requestSaveTicket(): Unable to lock file "); - return 0; - } -#endif return createTicket( this ); } bool ResourceSharpDTM::doOpen() { - qDebug("ResourceSharpDTM::doOpen: %s", fileName().latin1()); + qDebug("%xResourceSharpDTM::doOpen: %s", this,fileName().latin1()); + if ( ! mAccess ) { // the last parameter in the SlZDataBase constructor means "readonly" mAccess = new SlZDataBase(fileName(), SlZDataBase::addressbookItems(), NULL, false); - + } if ( !mAccess ) { qDebug("Unable to load file() %s", fileName().latin1()); return false; } - - if (mConverter == 0) - { + if (mConverter == 0) { mConverter = new SharpDTMConverter(); bool res = mConverter->init(); if ( !res ) { QString msg("Unable to initialize sharp converter. Most likely a problem with the category file"); - qDebug(msg); delete mAccess; mAccess = 0; return false; } } - return true; } void ResourceSharpDTM::doClose() { - qDebug("ResourceSharpDTM::doClose: %s", fileName().latin1()); - - if(mAccess) - { - delete mAccess; - mAccess = 0; - } - // it seems so, that deletion of access deletes backend as well - //delete backend; - return; } bool ResourceSharpDTM::load() { - qDebug("ResourceSharpDTM::load: %s", fileName().latin1()); - + qDebug("%xResourceSharpDTM::load: %s",this, fileName().latin1()); bool res = false; - CardId id; - for (bool res=mAccess->first(); res == true; res=mAccess->next()) { id = mAccess->cardId(); - KABC::Addressee addressee; - res = mConverter->sharpToAddressee( id, mAccess, addressee ); - if ( !addressee.isEmpty() && res ) { addressee.setResource( this ); addressBook()->insertAddressee( addressee ); } } - return true; } bool ResourceSharpDTM::save( Ticket *ticket ) { qDebug("ResourceSharpDTM::save: %s", fileName().latin1()); - - mDirWatch.stopScan(); - KABC::AddressBook::Iterator it; bool res; KABC::Addressee::List changedAddressees; typedef QMap<int,QString> AddresseeMap; AddresseeMap map; CardId id ; - for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { QString uid = (*it).originalExternalUID(); bool res; if ( uid.isEmpty() ) id = 0; else id = uid.toUInt(); KABC::Addressee addressee = (*it); if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL ) { res = mAccess->startEditCard(id); if (res == true) { res = mConverter->addresseeToSharp( (*it), mAccess, id ); if (res == true) { - res = mAccess->finishEditCard(&id); - //(*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); - //(*it).setExternalUID( QString::number( id ) ); - //(*it).setOriginalExternalUID( QString::number( id ) ); + res = mAccess->finishEditCard(&id);; map.insert(id,(*it).uid()); if (res == false) qDebug("Unable to append Contact: %s", addressee.formattedName().latin1()); } else { qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1()); mAccess->cancelEditCard(); } } } else if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { res = mAccess->deleteCard(&id); if ( !res ) qDebug("delete error "); } else if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { //changed res = mAccess->startEditCard(id); if (res == true) { res = mConverter->addresseeToSharp( (*it), mAccess, id ); if (res == true) { res = mAccess->finishEditCard(&id); - //(*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_CSUM ); map.insert(id,(*it).uid()); if (res == false) qDebug("Unable to append Contact: %s", addressee.formattedName().latin1()); - } else { qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1()); mAccess->cancelEditCard(); } } } } } AddresseeMap::Iterator itam; for ( res=mAccess->first(); res == true; res=mAccess->next()) { id = mAccess->cardId(); int idint = id; itam = map.find( idint ); if ( itam != map.end() ) { KABC::Addressee addressee; res = mConverter->sharpToAddressee( id, mAccess, addressee ); if ( !addressee.isEmpty() && res ) { addressee.setResource( this ); addressee.setUid( itam.data() ); addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); addressBook()->insertAddressee( addressee , false ); } } } - - //US mAccess->save(); - - mDirWatch.startScan(); delete ticket; - unlock( fileName() ); return true; } bool ResourceSharpDTM::lock( const QString &lockfileName ) { -#ifdef ALLOW_LOCKING - qDebug("ResourceSharpDTM::lock: %s", fileName().latin1()); - - kdDebug(5700) << "ResourceSharpDTM::lock()" << endl; - - QString fn = lockfileName; - - KURL url(fn); - QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); - - kdDebug(5700) << "-- lock name: " << lockName << endl; - - if (QFile::exists( lockName )) - { - qDebug("ResourceSharpDTM::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName()); - return false; - } - - - QString lockUniqueName; - lockUniqueName = fn + KApplication::randomString( 8 ); - - url = lockUniqueName; -//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); - mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); - kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; - - // Create unique file - QFile file( mLockUniqueName ); - file.open( IO_WriteOnly ); - file.close(); - - // Create lock file - int result = 0; -#ifndef _WIN32_ - result = ::link( QFile::encodeName( mLockUniqueName ), - QFile::encodeName( lockName ) ); -#endif - if ( result == 0 ) { - addressBook()->emitAddressBookLocked(); - return true; - } - - // TODO: check stat - - return false; -#else - return true; -#endif } void ResourceSharpDTM::unlock( const QString &fileName ) { -#ifdef ALLOW_LOCKING - qDebug("ResourceSharpDTM::unlock() %s", fileName.latin1()); - - QString fn = fileName; - KURL url(fn); - QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); - QFile::remove( lockName ); - QFile::remove( mLockUniqueName ); - addressBook()->emitAddressBookUnlocked(); -#endif } void ResourceSharpDTM::setFileName( const QString &newFileName ) { - mDirWatch.stopScan(); - mDirWatch.removeFile( fileName() ); - Resource::setFileName( newFileName ); - - mDirWatch.addFile( fileName() ); - mDirWatch.startScan(); - } void ResourceSharpDTM::fileChanged() { - // There is a small theoretical chance that KDirWatch calls us before - // we are fully constructed - if (!addressBook()) - return; - QString text( i18n( "Sharp DTM resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( fileName() ) ); - if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { - load(); - addressBook()->emitAddressBookChanged(); - } } void ResourceSharpDTM::removeAddressee( const Addressee &addr ) { } void ResourceSharpDTM::cleanUp() { unlock( fileName() ); } diff --git a/kabc/tmpaddressbook.cpp b/kabc/tmpaddressbook.cpp index 6e24302..cfa57e3 100644 --- a/kabc/tmpaddressbook.cpp +++ b/kabc/tmpaddressbook.cpp @@ -15,42 +15,35 @@ 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 <qptrlist.h> #include "tmpaddressbook.h" using namespace KABC; #include "resource.h" TmpAddressBook::TmpAddressBook() : AddressBook(0, "tmpcontact") { } TmpAddressBook::TmpAddressBook( const QString &config ) : AddressBook( config, "tmpcontact" ) { } TmpAddressBook::~TmpAddressBook() { - //remove all possible resources. This should cleanup the configfile. - QPtrList<KABC::Resource> mResources = resources(); - - QPtrListIterator<KABC::Resource> it(mResources); - for ( ; it.current(); ++it ) { - KABC::Resource *res = it.current(); - removeResource(res); - } + removeResources(); } |