-rw-r--r-- | kde2file/abdump/main.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/kde2file/abdump/main.cpp b/kde2file/abdump/main.cpp index d452ee9..1ee64f5 100644 --- a/kde2file/abdump/main.cpp +++ b/kde2file/abdump/main.cpp @@ -91,103 +91,105 @@ int main( int argc, char *argv[] ) qDebug("read "); } QString fileName = QDir::homeDirPath ()+"/.kdeaddressbookdump.vcf"; KABC::StdAddressBook* standardAddressBook = KABC::StdAddressBook::self(); standardAddressBook->setAutomaticSave( false ); qDebug("************************************* "); qDebug("***************kdeABdump************* "); qDebug("************************************* "); if ( !read ) { KABC::AddressBook::Iterator it; KABC::VCardConverter converter; QString datastream; for( it = standardAddressBook->begin(); it != standardAddressBook->end(); ++it ) { if ( (*it).isEmpty() || ! (*it).resource() ) continue; if ( (*it).resource()->readOnly() ) continue; KABC::Addressee a = ( *it ); QString vcard = converter.createVCard( a ); vcard += QString("\r\n"); datastream += vcard; } QFile outFile(fileName); if ( outFile.open(IO_WriteOnly) ) { QTextStream t( &outFile ); // use a text stream t.setEncoding( QTextStream::UnicodeUTF8 ); t <<datastream; t << "\r\n\r\n"; outFile.close(); } } else { //Addressee::List aList;//parseVCards( const QString& vcard ); KABC::Addressee::List list; int added = 0, changedC = 0, deleted = 0; QFile file( fileName ); if ( file.open( IO_ReadOnly ) ) { QTextStream t( &file ); // use a text stream t.setEncoding( QTextStream::UnicodeUTF8 ); QString data; data = t.read(); file.close(); KABC::VCardConverter converter; list = converter.parseVCards( data ); qDebug("kdeABdump::file has %d entries", list.count()); KABC::Addressee::List::Iterator it; for ( it = list.begin();it != list.end();++it) { + (*it).setChanged( true ); bool changed = ((*it).custom( "KADDRESSBOOK", "X-ExternalID" ) == "changed"); (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); //qDebug("ext %s ", (*it).custom( "KADDRESSBOOK", "X-ExternalID" ).latin1()); if ( changed ) { //qDebug("changed Addressee found! "); KABC::Addressee std = standardAddressBook->findByUid( (*it).uid() ); if ( ! std.isEmpty() ) (*it).setResource(std.resource()); standardAddressBook->insertAddressee( (*it) ); ++changedC; } else { //maybe added? KABC::Addressee std = standardAddressBook->findByUid( (*it).uid() ); if ( std.isEmpty() ) { standardAddressBook->insertAddressee( (*it) ); ++added; } } } KABC::AddressBook::Iterator itA = standardAddressBook->begin(); KABC::AddressBook::Iterator it2 ; while ( itA != standardAddressBook->end() ) { bool found = false; KABC::Addressee::List::Iterator itL; for ( itL = list.begin();itL != list.end();++itL) { if ( (*itL).uid() == (*itA).uid() ) { found = true; break; } } if ( !found ) { it2 = itA; ++itA; standardAddressBook->removeAddressee( it2 ); ++deleted; } else { ++itA; } } //standardAddressBook->saveAll(); standardAddressBook->setAutomaticSave( true ); qDebug("************************************* "); qDebug("*************kdeABdump*************** "); qDebug("************************************* "); qDebug("Addressbook entries\nchanged %d\ndeleted %d\nadded %d\nfrom file %s", changedC,deleted, added, fileName.latin1()); } else qDebug("error open file "); } - KABC::StdAddressBook::close(); - + delete standardAddressBook; + //KABC::StdAddressBook::close(); + //StdAddressBook::mSelf = 0; qDebug("ente "); return 0; } |