-rw-r--r-- | kabc/vcardformatimpl.cpp | 28 |
1 files changed, 10 insertions, 18 deletions
diff --git a/kabc/vcardformatimpl.cpp b/kabc/vcardformatimpl.cpp index b9fe6ff..ec5ed80 100644 --- a/kabc/vcardformatimpl.cpp +++ b/kabc/vcardformatimpl.cpp @@ -1,231 +1,223 @@ /* This file is part of libkabc. Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* Enhanced Version of the file for platform independent KDE tools. Copyright (c) 2004 Ulf Schenk $Id$ */ #include <qfile.h> #include <qregexp.h> +#include <qapplication.h> #include <kdebug.h> #include <kmdcodec.h> #include <kstandarddirs.h> #include <ktempfile.h> #include <VCard.h> #include "addressbook.h" #include "vcardformatimpl.h" using namespace KABC; using namespace VCARD; int VCardFormatImpl::debug = -1; VCardFormatImpl::VCardFormatImpl() { debug = (getenv("KABC_DEBUG") != 0); } bool VCardFormatImpl::load( Addressee &addressee, QFile *file ) { kdDebug(5700) << "VCardFormat::load()" << endl; QByteArray fdata = file->readAll(); QCString data(fdata.data(), fdata.size()+1); VCardEntity e( data ); VCardListIterator it( e.cardList() ); if ( it.current() ) { //US VCard v(*it.current()); //US loadAddressee( addressee, v ); loadAddressee( addressee, it.current() ); return true; } return false; } + +#include <kmessagebox.h> bool VCardFormatImpl::loadAll( AddressBook *addressBook, Resource *resource, QFile *file ) { - kdDebug(5700) << "VCardFormat::loadAll()" << endl; - - QByteArray fdata = file->readAll(); - QCString data(fdata.data(), fdata.size()+1); - + + QCString data(file->readAll().data(), file->size()+1); VCardEntity e( data ); VCardListIterator it( e.cardList() ); for (; it.current(); ++it) { //US VCard v(*it.current()); Addressee addressee; //US loadAddressee( addressee, v ); loadAddressee( addressee, it.current() ); addressee.setResource( resource ); addressBook->insertAddressee( addressee ); if (debug == true) { printf("address %s loaded successfully\n", addressee.formattedName().latin1()); } } - return true; } void VCardFormatImpl::save( const Addressee &addressee, QFile *file ) { VCardEntity vcards; VCardList vcardlist; vcardlist.setAutoDelete( true ); VCard *v = new VCard; saveAddressee( addressee, v, false ); vcardlist.append( v ); vcards.setCardList( vcardlist ); QCString vcardData = vcards.asString(); file->writeBlock( (const char*)vcardData, vcardData.length() ); } void VCardFormatImpl::saveAll( AddressBook *ab, Resource *resource, QFile *file ) { - VCardEntity vcards; - VCardList vcardlist; - vcardlist.setAutoDelete( true ); - AddressBook::Iterator it; + AddressBook::Iterator it; for ( it = ab->begin(); it != ab->end(); ++it ) { if ( (*it).resource() == resource ) { - VCard *v = new VCard; - saveAddressee( (*it), v, true ); + save((*it),file); + qApp->processEvents(); (*it).setChanged( false ); - vcardlist.append( v ); } } - - vcards.setCardList( vcardlist ); - - QCString vcardData = vcards.asString(); - file->writeBlock( (const char*)vcardData, vcardData.length() ); + // for memory usage status test only + // KMessageBox::information ( 0, "Stoppppp", QString("Stop ") ); } bool VCardFormatImpl::loadAddressee( Addressee& addressee, VCard *v ) { QPtrList<ContentLine> contentLines = v->contentLineList(); ContentLine *cl; for( cl = contentLines.first(); cl; cl = contentLines.next() ) { QCString n = cl->name(); if ( n.left( 2 ) == "X-" ) { n = n.mid( 2 ); int posDash = n.find( "-" ); addressee.insertCustom( QString::fromUtf8( n.left( posDash ) ), QString::fromUtf8( n.mid( posDash + 1 ) ), QString::fromUtf8( cl->value()->asString() ) ); continue; } EntityType type = cl->entityType(); switch( type ) { case EntityUID: addressee.setUid( readTextValue( cl ) ); break; case EntityEmail: addressee.insertEmail( readTextValue( cl ) ); break; case EntityName: addressee.setName( readTextValue( cl ) ); break; case EntityFullName: addressee.setFormattedName( readTextValue( cl ) ); break; case EntityURL: addressee.setUrl( KURL( readTextValue( cl ) ) ); break; case EntityNickname: addressee.setNickName( readTextValue( cl ) ); break; case EntityLabel: // not yet supported by kabc break; case EntityMailer: addressee.setMailer( readTextValue( cl ) ); break; case EntityTitle: addressee.setTitle( readTextValue( cl ) ); break; case EntityRole: addressee.setRole( readTextValue( cl ) ); break; case EntityOrganisation: addressee.setOrganization( readTextValue( cl ) ); break; case EntityNote: addressee.setNote( readTextValue( cl ) ); break; case EntityProductID: addressee.setProductId( readTextValue( cl ) ); break; case EntitySortString: addressee.setSortString( readTextValue( cl ) ); break; case EntityN: readNValue( cl, addressee ); break; case EntityAddress: addressee.insertAddress( readAddressValue( cl ) ); break; case EntityTelephone: addressee.insertPhoneNumber( readTelephoneValue( cl ) ); break; case EntityCategories: addressee.setCategories( QStringList::split( ",", readTextValue( cl ) ) ); break; case EntityBirthday: addressee.setBirthday( readDateValue( cl ) ); break; |