author | zautrix <zautrix> | 2004-10-20 21:49:51 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-10-20 21:49:51 (UTC) |
commit | bb235c5a639b914574e1e247d2de6e479517585f (patch) (side-by-side diff) | |
tree | 0f074ec87d93b6f5fb81b6893f0174cabc52c1df /kabc/plugins/qtopia/resourceqtopia.cpp | |
parent | 8e00329a4a5f0b66d26d20f067ab6aefca17f17a (diff) | |
download | kdepimpi-bb235c5a639b914574e1e247d2de6e479517585f.zip kdepimpi-bb235c5a639b914574e1e247d2de6e479517585f.tar.gz kdepimpi-bb235c5a639b914574e1e247d2de6e479517585f.tar.bz2 |
qtopia resource fixes
Diffstat (limited to 'kabc/plugins/qtopia/resourceqtopia.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kabc/plugins/qtopia/resourceqtopia.cpp | 98 |
1 files changed, 23 insertions, 75 deletions
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 << "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>" << endl; *stream << " <Groups>" << endl; @@ -236,66 +217,27 @@ bool ResourceQtopia::save( Ticket *ticket ) qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1()); } } - - *stream << "</Contacts>" << endl; *stream << "</AddressBook>" << 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 } |