summaryrefslogtreecommitdiffabout
path: root/kabc/plugins/opie
authorzautrix <zautrix>2004-07-03 21:47:33 (UTC)
committer zautrix <zautrix>2004-07-03 21:47:33 (UTC)
commit5e59162e6eb6603610d1ca4c96d5d97acae0f60b (patch) (side-by-side diff)
treec891d1e2125cf6f68509332fe06c878709525480 /kabc/plugins/opie
parent54e76d203297aa5da51342492d482187f4d6cd20 (diff)
downloadkdepimpi-5e59162e6eb6603610d1ca4c96d5d97acae0f60b.zip
kdepimpi-5e59162e6eb6603610d1ca4c96d5d97acae0f60b.tar.gz
kdepimpi-5e59162e6eb6603610d1ca4c96d5d97acae0f60b.tar.bz2
Fixed crash when accessing opie resource
Diffstat (limited to 'kabc/plugins/opie') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/plugins/opie/resourceopie.cpp3
1 files changed, 2 insertions, 1 deletions
diff --git a/kabc/plugins/opie/resourceopie.cpp b/kabc/plugins/opie/resourceopie.cpp
index a4f8d8a..3b2a6b7 100644
--- a/kabc/plugins/opie/resourceopie.cpp
+++ b/kabc/plugins/opie/resourceopie.cpp
@@ -126,193 +126,194 @@ Ticket *ResourceOpie::requestSaveTicket()
{
kdDebug(5700) << "ResourceOpie::requestSaveTicket()" << endl;
if ( !addressBook() ) return 0;
if ( !lock( mFileName ) ) {
kdDebug(5700) << "ResourceOpie::requestSaveTicket(): Unable to lock file '"
<< mFileName << "'" << endl;
return 0;
}
return createTicket( this );
}
bool ResourceOpie::doOpen()
{
// qDebug("ResourceOpie::doOpen() %s", mFileName.latin1());
/*US
QFile file( mFileName );
if ( !file.exists() ) {
// try to create the file
bool ok = file.open( IO_WriteOnly );
if ( ok )
file.close();
return ok;
} else {
if ( !file.open( IO_ReadWrite ) )
return false;
if ( file.size() == 0 ) {
file.close();
return true;
}
//US bool ok = mFormat->checkFormat( &file );
bool ok = true;
file.close();
return ok;
}
*/
qDebug("ResourceOpie::doOpen() has to be fixed - %s", mFileName.latin1());
return true;
}
void ResourceOpie::doClose()
{
// qDebug("ResourceOpie::doClose() %s", mFileName.latin1());
}
bool ResourceOpie::load()
{
// qDebug("ResourceOpie::load() %s", mFileName.latin1());
kdDebug(5700) << "ResourceOpie::load(): '" << mFileName << "'" << endl;
qDebug("ResourceOpie::load: Try to load file() %s", mFileName.latin1());
OContactAccessBackend_XML* backend = new OContactAccessBackend_XML( "KDEPim/Pi", mFileName );
OContactAccess* access = new OContactAccess("KDEPim/Pi", 0l, backend, false);
if ( !access ) {
qDebug("Unable to load file() %s", mFileName.latin1());
addressBook()->error( i18n( "Unable to load file '%1'." ).arg( mFileName ) );
return false;
}
access -> setReadAhead( 32 ); // Use ReadAhead-Cache if available
if (mConverter == 0)
mConverter = new OpieConverter();
OContactAccess::List::Iterator it;
OContactAccess::List allList = access->allRecords();
bool res = false;
for ( it = allList.begin(); it != allList.end(); ++it )
{
OContact c = (*it);
KABC::Addressee addressee;
res = mConverter->opieToAddressee( c, addressee );
if ( !addressee.isEmpty() && res )
{
addressee.setResource( this );
addressBook()->insertAddressee( addressee );
}
// qDebug("found %s", c.fullName().latin1());
}
delete access;
- delete backend;
+ // it seems so, that deletion of access deletes backend as well
+ //delete backend;
return true;
}
bool ResourceOpie::save( Ticket *ticket )
{
qDebug("ResourceOpie::save() has to be fixed - %s", mFileName.latin1());
/*US
qDebug("ResourceOpie::save %s", mFileName.latin1());
kdDebug(5700) << "ResourceOpie::save()" << endl;
// create backup file
QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() );
*/
/*US we use a simpler method to create a backupfile
(void) KSaveFile::backupFile( mFileName, QString::null
,extension );
KSaveFile saveFile( mFileName );
bool ok = false;
if ( saveFile.status() == 0 && saveFile.file() )
{
mFormat->saveAll( addressBook(), this, saveFile.file() );
ok = saveFile.close();
}
*/
/*US
//US ToDo: write backupfile
QFile info;
info.setName( mFileName );
bool ok = info.open( IO_WriteOnly );
if ( ok ) {
//US mFormat->saveAll( addressBook(), this, &info );
info.close();
ok = true;
}
else {
}
if ( !ok )
addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) );
delete ticket;
unlock( mFileName );
return ok;
qDebug("ResourceOpie::save has to be changed");
*/
return true;
}
bool ResourceOpie::lock( const QString &fileName )
{
qDebug("ResourceOpie::lock() has to be fixed - %s", mFileName.latin1());
/*US
// qDebug("ResourceOpie::lock() %s", fileName.latin1());
kdDebug(5700) << "ResourceOpie::lock()" << endl;
QString fn = fileName;
//US change the implementation how the lockfilename is getting created
//US fn.replace( QRegExp("/"), "_" );
//US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" );
KURL url(fn);
QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
kdDebug(5700) << "-- lock name: " << lockName << endl;
if (QFile::exists( lockName )) 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 = ::link( QFile::encodeName( mLockUniqueName ),
QFile::encodeName( lockName ) );
if ( result == 0 ) {