summaryrefslogtreecommitdiffabout
path: root/kabc
Side-by-side diff
Diffstat (limited to 'kabc') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressbook.cpp11
-rw-r--r--kabc/addressbook.h1
-rw-r--r--kabc/addressee.cpp2
-rw-r--r--kabc/plugins/sharpdtm/resourcesharpdtm.cpp215
-rw-r--r--kabc/tmpaddressbook.cpp9
5 files changed, 61 insertions, 177 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index 4c4ae09..8487ff3 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -1160,6 +1160,17 @@ bool AddressBook::addResource( Resource *resource )
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 )
{
diff --git a/kabc/addressbook.h b/kabc/addressbook.h
index 75f8b51..2351add 100644
--- a/kabc/addressbook.h
+++ b/kabc/addressbook.h
@@ -274,6 +274,7 @@ class AddressBook : public QObject
/**
Remove address book resource.
*/
+ void removeResources();
bool removeResource( Resource * );
/**
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp
index 3d4992c..028d3bb 100644
--- a/kabc/addressee.cpp
+++ b/kabc/addressee.cpp
@@ -272,7 +272,7 @@ void Addressee::computeCsum(const QString &dev)
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() );
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
@@ -67,24 +67,20 @@ ResourceSharpDTM::ResourceSharpDTM( const KConfig *config )
: Resource( config ), mConverter (0)
{
// we can not choose the filename. Therefore use the default to display
-
- QString fileName = SlZDataBase::addressbookFileName();
- init( fileName );
+ mAccess = 0;
+ QString fileName = SlZDataBase::addressbookFileName();
+ init( fileName );
}
ResourceSharpDTM::ResourceSharpDTM( const QString &fileName )
: Resource( 0 )
{
- init( fileName );
+ 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 );
}
@@ -104,108 +100,76 @@ void ResourceSharpDTM::writeConfig( KConfig *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());
-
- // the last parameter in the SlZDataBase constructor means "readonly"
- mAccess = new SlZDataBase(fileName(),
- SlZDataBase::addressbookItems(),
- NULL, false);
+ qDebug("%xResourceSharpDTM::doOpen: %s", this,fileName().latin1());
- if ( !mAccess ) {
- qDebug("Unable to load file() %s", fileName().latin1());
- return false;
- }
-
- 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;
+ if ( ! mAccess ) {
+ // the last parameter in the SlZDataBase constructor means "readonly"
+ mAccess = new SlZDataBase(fileName(),
+ SlZDataBase::addressbookItems(),
+ NULL, false);
}
- }
-
- return true;
+ if ( !mAccess ) {
+ qDebug("Unable to load file() %s", fileName().latin1());
+ return false;
+ }
+ 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());
-
- 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;
+ 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 ) {
@@ -223,10 +187,7 @@ bool ResourceSharpDTM::save( Ticket *ticket )
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());
@@ -254,11 +215,9 @@ bool ResourceSharpDTM::save( Ticket *ticket )
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());
-
+ qDebug("Unable to append Contact: %s", addressee.formattedName().latin1());
}
else
{
@@ -289,108 +248,28 @@ bool ResourceSharpDTM::save( Ticket *ticket )
}
}
}
-
- //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();
-
+ Resource::setFileName( newFileName );
}
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 )
diff --git a/kabc/tmpaddressbook.cpp b/kabc/tmpaddressbook.cpp
index 6e24302..cfa57e3 100644
--- a/kabc/tmpaddressbook.cpp
+++ b/kabc/tmpaddressbook.cpp
@@ -44,13 +44,6 @@ TmpAddressBook::TmpAddressBook( const QString &config )
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();
}