-rw-r--r-- | kabc/plugins/sharpdtm/resourcesharpdtm.cpp | 137 |
1 files changed, 8 insertions, 129 deletions
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 @@ -68,5 +68,5 @@ ResourceSharpDTM::ResourceSharpDTM( const KConfig *config ) { // we can not choose the filename. Therefore use the default to display - + mAccess = 0; QString fileName = SlZDataBase::addressbookFileName(); init( fileName ); @@ -76,4 +76,5 @@ ResourceSharpDTM::ResourceSharpDTM( const QString &fileName ) : Resource( 0 ) { + mAccess = 0; init( fileName ); } @@ -81,9 +82,4 @@ ResourceSharpDTM::ResourceSharpDTM( const QString &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 ); } @@ -106,15 +102,7 @@ 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 ); } @@ -123,18 +111,17 @@ Ticket *ResourceSharpDTM::requestSaveTicket() 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(); @@ -142,5 +129,4 @@ bool ResourceSharpDTM::doOpen() { QString msg("Unable to initialize sharp converter. Most likely a problem with the category file"); - qDebug(msg); delete mAccess; @@ -149,5 +135,4 @@ bool ResourceSharpDTM::doOpen() } } - return true; } @@ -155,14 +140,4 @@ bool ResourceSharpDTM::doOpen() 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; } @@ -170,18 +145,12 @@ void ResourceSharpDTM::doClose() 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 ) { @@ -190,5 +159,4 @@ bool ResourceSharpDTM::load() } } - return true; } @@ -197,7 +165,4 @@ bool ResourceSharpDTM::save( Ticket *ticket ) { qDebug("ResourceSharpDTM::save: %s", fileName().latin1()); - - mDirWatch.stopScan(); - KABC::AddressBook::Iterator it; bool res; @@ -206,5 +171,4 @@ bool ResourceSharpDTM::save( Ticket *ticket ) AddresseeMap map; CardId id ; - for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { @@ -224,8 +188,5 @@ bool ResourceSharpDTM::save( Ticket *ticket ) 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) @@ -255,9 +216,7 @@ bool ResourceSharpDTM::save( Ticket *ticket ) { 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 @@ -290,10 +249,5 @@ bool ResourceSharpDTM::save( Ticket *ticket ) } } - - //US mAccess->save(); - - mDirWatch.startScan(); delete ticket; - unlock( fileName() ); return true; @@ -302,94 +256,19 @@ bool ResourceSharpDTM::save( Ticket *ticket ) 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(); - } } |