From bb235c5a639b914574e1e247d2de6e479517585f Mon Sep 17 00:00:00 2001 From: zautrix Date: Wed, 20 Oct 2004 21:49:51 +0000 Subject: qtopia resource fixes --- (limited to 'kabc/plugins/qtopia/resourceqtopia.cpp') diff --git a/kabc/plugins/qtopia/resourceqtopia.cpp b/kabc/plugins/qtopia/resourceqtopia.cpp index b7263bb..4ee3c3c 100644 --- a/kabc/plugins/qtopia/resourceqtopia.cpp +++ b/kabc/plugins/qtopia/resourceqtopia.cpp @@ -78,11 +78,11 @@ ResourceQtopia::ResourceQtopia( const QString &fileName ) void ResourceQtopia::init( const QString &fileName ) { - +#ifdef _USE_DIRWATCH_ connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); - +#endif setFileName( fileName ); } @@ -165,7 +165,7 @@ bool ResourceQtopia::load() while ( !n.isNull() ) { QDomElement e = n.toElement(); if ( !e.isNull() ) { - if ( e.tagName() == QString::fromLatin1( "Contacts" ) ) { // we're looking for them + if ( e.tagName() == QString::fromLatin1( "Contacts" ) ) { QDomNode no = e.firstChild(); while ( !no.isNull() ) { QDomElement el = no.toElement(); @@ -186,41 +186,22 @@ bool ResourceQtopia::load() n = n.nextSibling(); } - -#if 0 -/ old code - qDebug("ResourceQtopia::load: %s", fileName().latin1()); - - AddressBookIterator it(*mAccess); - const PimContact* contact; - bool res; - - for (contact=it.toFirst(); it.current(); ++it) - { - contact = it.current(); - - KABC::Addressee addressee; - - //LRres = mConverter->qtopiaToAddressee( (*contact), addressee ); - - if ( !addressee.isEmpty() && res ) - { - addressee.setResource( this ); - addressBook()->insertAddressee( addressee ); - } - } -#endif return true; } bool ResourceQtopia::save( Ticket *ticket ) { - +#ifdef _USE_DIRWATCH_ mDirWatch.stopScan(); +#endif KABC::AddressBook::Iterator it; - bool res; - //pending open file for stream - QTextStream *stream;// = tempFile->textStream(); + bool res; + QFile file( fileName() ); + if (!file.open( IO_WriteOnly ) ) { + return false; + } + QTextStream ts( &file ); + QTextStream *stream = &ts; stream->setEncoding( QTextStream::UnicodeUTF8 ); *stream << "" << endl; *stream << " " << endl; @@ -236,66 +217,27 @@ bool ResourceQtopia::save( Ticket *ticket ) qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1()); } } - - *stream << "" << endl; *stream << "" << endl; - //pending close file + file.close(); +#ifdef _USE_DIRWATCH_ mDirWatch.startScan(); - +#endif delete ticket; unlock( fileName() ); - - -#if 0 - //old code - qDebug("ResourceQtopia::save: %s", fileName().latin1()); - - mDirWatch.stopScan(); - - KABC::AddressBook::Iterator it; - bool res; - - for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { - PimContact c; - KABC::Addressee addressee = (*it); - - //res = mConverter->addresseeToQtopia( *it, c ); - if (res == true) - { - mAccess->addContact(c); -// if (res == false) -// qDebug("Unable to append Contact %s", c.fullName().latin1()); - } - else - { - qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1()); - } - } - -// mAccess->addressBookUpdated(); - - mDirWatch.startScan(); - - delete ticket; - unlock( fileName() ); -#endif return true; } bool ResourceQtopia::lock( const QString &lockfileName ) { + //disabled + return true; qDebug("ResourceQtopia::lock: %s", fileName().latin1()); - - kdDebug(5700) << "ResourceQtopia::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("ResourceOpie::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName().latin1()); @@ -333,6 +275,8 @@ bool ResourceQtopia::lock( const QString &lockfileName ) void ResourceQtopia::unlock( const QString &fileName ) { + //disabled + return; qDebug("ResourceQtopia::unlock() %s", fileName.latin1()); QString fn = fileName; @@ -346,13 +290,17 @@ void ResourceQtopia::unlock( const QString &fileName ) void ResourceQtopia::setFileName( const QString &newFileName ) { +#ifdef _USE_DIRWATCH_ mDirWatch.stopScan(); +#endif mDirWatch.removeFile( fileName() ); Resource::setFileName( newFileName ); mDirWatch.addFile( fileName() ); +#ifdef _USE_DIRWATCH_ mDirWatch.startScan(); +#endif } -- cgit v0.9.0.2