From ee6e29a5092d32165b7bf6b39069bd8a1dcd5b0a Mon Sep 17 00:00:00 2001 From: zautrix Date: Sun, 10 Oct 2004 16:00:04 +0000 Subject: many phone AB sync fixes --- (limited to 'kabc/addressbook.cpp') diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index d037d2f..ad0f702 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp @@ -341,17 +341,16 @@ AddressBook::~AddressBook() bool AddressBook::load() { - clear(); - KRES::Manager::ActiveIterator it; bool ok = true; for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) if ( !(*it)->load() ) { - error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); + qDebug( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); ok = false; + } else { + qDebug( i18n("Resource loaded: '%1'").arg( (*it)->resourceName() ) ); } - // mark all addressees as unchanged Addressee::List::Iterator addrIt; for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) { @@ -404,6 +403,75 @@ void AddressBook::export2File( QString fileName ) t << "\r\n\r\n"; outFile.close(); } +// if QStringList uids is empty, all are exported +bool AddressBook::export2PhoneFormat( QStringList uids ,QString fileName ) +{ + KABC::VCardConverter converter; + QString datastream; + Iterator it; + bool all = uids.isEmpty(); + for ( it = begin(); it != end(); ++it ) { + // for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { + if ( ! all ) { + if ( ! ( uids.contains((*it).uid() ) )) + continue; + } + KABC::Addressee a = ( *it ); + if ( a.isEmpty() ) + continue; + a.simplifyEmails(); + a.simplifyPhoneNumbers(); + a.simplifyPhoneNumberTypes(); + a.simplifyAddresses(); + + QString vcard; + QString vcardnew; + converter.addresseeToVCard( a, vcard ); + int start = 0; + int next; + while ( (next = vcard.find("TYPE=", start) )>= 0 ) { + int semi = vcard.find(";", next); + int dopp = vcard.find(":", next); + int sep; + if ( semi < dopp && semi >= 0 ) + sep = semi ; + else + sep = dopp; + vcardnew +=vcard.mid( start, next - start); + vcardnew +=vcard.mid( next+5,sep -next -5 ).upper(); + start = sep; + } + vcardnew += vcard.mid( start,vcard.length() ); + vcard = ""; + start = 0; + while ( (next = vcardnew.find("ADR", start) )>= 0 ) { + int sep = vcardnew.find(":", next); + vcard +=vcardnew.mid( start, next - start+3); + start = sep; + } + vcard += vcardnew.mid( start,vcardnew.length() ); + vcard.replace ( QRegExp(";;;") , "" ); + vcard.replace ( QRegExp(";;") , "" ); + datastream += vcard; + + } + + QFile outFile(fileName); + if ( outFile.open(IO_WriteOnly) ) { + datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" ); + QTextStream t( &outFile ); // use a text stream + t.setEncoding( QTextStream::UnicodeUTF8 ); + t <::ActiveIterator it; KRES::Manager *manager = d->mManager; + qDebug("SaveAB::saving..." ); for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { + qDebug("SaveAB::checking resource..." ); + if ( (*it)->readOnly() ) + qDebug("readonly." ); + if ( (*it)->isOpen() ) + qDebug("open" ); + if ( !(*it)->readOnly() && (*it)->isOpen() ) { Ticket *ticket = requestSaveTicket( *it ); -// qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); + qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); if ( !ticket ) { - error( i18n( "Unable to save to resource '%1'. It is locked." ) + qDebug( i18n( "Unable to save to resource '%1'. It is locked." ) .arg( (*it)->resourceName() ) ); return false; } @@ -530,6 +649,9 @@ bool AddressBook::saveAB() if ( ticket->resource() ) { if ( ! ticket->resource()->save( ticket ) ) ok = false; + else + qDebug("StdAddressBook::saved '%s'", ticket->resource()->resourceName().latin1() ); + } else ok = false; @@ -593,7 +715,7 @@ Ticket *AddressBook::requestSaveTicket( Resource *resource ) return 0; } - +//void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) { if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { -- cgit v0.9.0.2