-rw-r--r-- | kabc/converter/opie/opieconverterE.pro | 2 | ||||
-rw-r--r-- | kabc/formats/vcardformatplugin2.cpp | 4 | ||||
-rw-r--r-- | kabc/vcardformatimpl.cpp | 48 | ||||
-rw-r--r-- | kabc/vcardformatplugin.cpp | 4 | ||||
-rw-r--r-- | kabc/vcardparser/vcardtool.cpp | 16 |
5 files changed, 50 insertions, 24 deletions
diff --git a/kabc/converter/opie/opieconverterE.pro b/kabc/converter/opie/opieconverterE.pro index 85ba28f..e026f2a 100644 --- a/kabc/converter/opie/opieconverterE.pro +++ b/kabc/converter/opie/opieconverterE.pro @@ -1,32 +1,32 @@ TEMPLATE = lib -INCLUDEPATH += . ../.. ../../../microkde ../../../microkde/kdecore $(QPEDIR)/include $(OPIEDIR)/include +INCLUDEPATH += . ../.. ../../../microkde ../../../microkde/kdecore $(OPIEDIR)/include $(OPEDIR)/include #CONFIG += staticlib OBJECTS_DIR = obj/$(PLATFORM) MOC_DIR = moc/$(PLATFORM) #for static linkage, put it here #DESTDIR=../../lib/$(PLATFORM) #for dynamic linkage, put it here DESTDIR=$(QPEDIR)/lib LIBS += -lmicrokde LIBS += -lmicrokabc LIBS += -L$(QPEDIR)/lib LIBS += -L$(OPIEDIR)/lib LIBS += -lopie LIBS += -lqpe LIBS += -lqte TARGET = microkabc_opieconverter # Input HEADERS += \ opieconverter.h \ SOURCES += \ opieconverter.cpp \ diff --git a/kabc/formats/vcardformatplugin2.cpp b/kabc/formats/vcardformatplugin2.cpp index f19e218..41b0c9a 100644 --- a/kabc/formats/vcardformatplugin2.cpp +++ b/kabc/formats/vcardformatplugin2.cpp @@ -1,120 +1,124 @@ /* Enhanced Version of the file for platform independent KDE tools. Copyright (c) 2004 Ulf Schenk $Id$ */ #include "vcardformatplugin2.h" #include "address.h" #include "addressee.h" #include "vcardparser/vcardtool.h" #include <qtextstream.h> #include <qfile.h> using namespace KABC; extern "C" { FormatPlugin *format() { return new VCardFormatPlugin2(); } } VCardFormatPlugin2::VCardFormatPlugin2() { } VCardFormatPlugin2::~VCardFormatPlugin2() { } bool VCardFormatPlugin2::load( Addressee &addressee, QFile *file ) { + qDebug("VCardFormatPlugin2::load"); QString data; QTextStream t( file ); t.setEncoding( QTextStream::UnicodeUTF8 ); data = t.read(); VCardTool tool; Addressee::List l = tool.parseVCards( data ); if ( ! l.first().isEmpty() ) { addressee = l.first(); return true; } return false; } bool VCardFormatPlugin2::loadAll( AddressBook *addressBook, Resource *resource, QFile *file ) { + qDebug("VCardFormatPlugin2::loadAll"); QString data; QTextStream t( file ); t.setEncoding( QTextStream::UnicodeUTF8 ); data = t.read(); VCardTool tool; Addressee::List l = tool.parseVCards( data ); Addressee::List::Iterator itr; for ( itr = l.begin(); itr != l.end(); ++itr) { Addressee addressee = *itr; addressee.setResource( resource ); addressBook->insertAddressee( addressee ); } return true; } void VCardFormatPlugin2::save( const Addressee &addressee, QFile *file ) { + qDebug("VCardFormatPlugin2::save"); VCardTool tool; Addressee::List vcardlist; vcardlist.append( addressee ); QTextStream t( file ); t.setEncoding( QTextStream::UnicodeUTF8 ); t << tool.createVCards( vcardlist ); } void VCardFormatPlugin2::saveAll( AddressBook *ab, Resource *resource, QFile *file ) { + qDebug("VCardFormatPlugin2::saveAll"); VCardTool tool; Addressee::List vcardlist; AddressBook::Iterator it; for ( it = ab->begin(); it != ab->end(); ++it ) { if ( (*it).resource() == resource ) { (*it).setChanged( false ); vcardlist.append( *it ); } } QTextStream t( file ); t.setEncoding( QTextStream::UnicodeUTF8 ); t << tool.createVCards( vcardlist ); } bool VCardFormatPlugin2::checkFormat( QFile *file ) const { QString line; file->readLine( line, 1024 ); line = line.stripWhiteSpace(); if ( line == "BEGIN:VCARD" ) return true; else return false; } diff --git a/kabc/vcardformatimpl.cpp b/kabc/vcardformatimpl.cpp index f90f813..3fcaf94 100644 --- a/kabc/vcardformatimpl.cpp +++ b/kabc/vcardformatimpl.cpp @@ -479,189 +479,193 @@ void VCardFormatImpl::addUTCValue( VCard *vcard, const TimeZone &tz ) vcard->add(cl); } void VCardFormatImpl::addClassValue( VCard *vcard, const Secrecy &secrecy ) { ContentLine cl; cl.setName( EntityTypeToParamName( EntityClass ) ); ClassValue *v = new ClassValue; switch ( secrecy.type() ) { case Secrecy::Public: v->setType( (int)ClassValue::Public ); break; case Secrecy::Private: v->setType( (int)ClassValue::Private ); break; case Secrecy::Confidential: v->setType( (int)ClassValue::Confidential ); break; } cl.setValue( v ); vcard->add(cl); } Address VCardFormatImpl::readAddressValue( ContentLine *cl ) { Address a; AdrValue *v = (AdrValue *)cl->value(); a.setPostOfficeBox( QString::fromUtf8( v->poBox() ) ); a.setExtended( QString::fromUtf8( v->extAddress() ) ); a.setStreet( QString::fromUtf8( v->street() ) ); a.setLocality( QString::fromUtf8( v->locality() ) ); a.setRegion( QString::fromUtf8( v->region() ) ); a.setPostalCode( QString::fromUtf8( v->postCode() ) ); a.setCountry( QString::fromUtf8( v->countryName() ) ); a.setType( readAddressParam( cl ) ); return a; } int VCardFormatImpl::readAddressParam( ContentLine *cl ) { int type = 0; ParamList params = cl->paramList(); ParamListIterator it( params ); + QCString tmpStr; for( ; it.current(); ++it ) { - if ( (*it)->name() == "TYPE" ) { - if ( (*it)->value() == "dom" ) type |= Address::Dom; - else if ( (*it)->value() == "intl" ) type |= Address::Intl; - else if ( (*it)->value() == "parcel" ) type |= Address::Parcel; - else if ( (*it)->value() == "postal" ) type |= Address::Postal; - else if ( (*it)->value() == "work" ) type |= Address::Work; - else if ( (*it)->value() == "home" ) type |= Address::Home; - else if ( (*it)->value() == "pref" ) type |= Address::Pref; + if ( (*it)->name().upper() == "TYPE" ) { + tmpStr = (*it)->value().lower(); + if ( tmpStr == "dom" ) type |= Address::Dom; + else if ( tmpStr == "intl" ) type |= Address::Intl; + else if ( tmpStr == "parcel" ) type |= Address::Parcel; + else if ( tmpStr == "postal" ) type |= Address::Postal; + else if ( tmpStr == "work" ) type |= Address::Work; + else if ( tmpStr == "home" ) type |= Address::Home; + else if ( tmpStr == "pref" ) type |= Address::Pref; } } return type; } void VCardFormatImpl::addNValue( VCard *vcard, const Addressee &a ) { ContentLine cl; cl.setName(EntityTypeToParamName( EntityN ) ); NValue *v = new NValue; v->setFamily( a.familyName().utf8() ); v->setGiven( a.givenName().utf8() ); v->setMiddle( a.additionalName().utf8() ); v->setPrefix( a.prefix().utf8() ); v->setSuffix( a.suffix().utf8() ); cl.setValue( v ); vcard->add(cl); } void VCardFormatImpl::readNValue( ContentLine *cl, Addressee &a ) { NValue *v = (NValue *)cl->value(); a.setFamilyName( QString::fromUtf8( v->family() ) ); a.setGivenName( QString::fromUtf8( v->given() ) ); a.setAdditionalName( QString::fromUtf8( v->middle() ) ); a.setPrefix( QString::fromUtf8( v->prefix() ) ); a.setSuffix( QString::fromUtf8( v->suffix() ) ); } void VCardFormatImpl::addTelephoneValue( VCard *v, const PhoneNumber &p ) { if ( p.number().isEmpty() ) return; ContentLine cl; cl.setName(EntityTypeToParamName(EntityTelephone)); cl.setValue(new TelValue( p.number().utf8() )); ParamList params; if( p.type() & PhoneNumber::Home ) params.append( new Param( "TYPE", "home" ) ); if( p.type() & PhoneNumber::Work ) params.append( new Param( "TYPE", "work" ) ); if( p.type() & PhoneNumber::Msg ) params.append( new Param( "TYPE", "msg" ) ); if( p.type() & PhoneNumber::Pref ) params.append( new Param( "TYPE", "pref" ) ); if( p.type() & PhoneNumber::Voice ) params.append( new Param( "TYPE", "voice" ) ); if( p.type() & PhoneNumber::Fax ) params.append( new Param( "TYPE", "fax" ) ); if( p.type() & PhoneNumber::Cell ) params.append( new Param( "TYPE", "cell" ) ); if( p.type() & PhoneNumber::Video ) params.append( new Param( "TYPE", "video" ) ); if( p.type() & PhoneNumber::Bbs ) params.append( new Param( "TYPE", "bbs" ) ); if( p.type() & PhoneNumber::Modem ) params.append( new Param( "TYPE", "modem" ) ); if( p.type() & PhoneNumber::Car ) params.append( new Param( "TYPE", "car" ) ); if( p.type() & PhoneNumber::Isdn ) params.append( new Param( "TYPE", "isdn" ) ); if( p.type() & PhoneNumber::Pcs ) params.append( new Param( "TYPE", "pcs" ) ); if( p.type() & PhoneNumber::Pager ) params.append( new Param( "TYPE", "pager" ) ); cl.setParamList( params ); v->add(cl); } PhoneNumber VCardFormatImpl::readTelephoneValue( ContentLine *cl ) { PhoneNumber p; TelValue *value = (TelValue *)cl->value(); p.setNumber( QString::fromUtf8( value->asString() ) ); int type = 0; ParamList params = cl->paramList(); ParamListIterator it( params ); + QCString tmpStr; for( ; it.current(); ++it ) { if ( (*it)->name() == "TYPE" ) { - if ( (*it)->value() == "home" ) type |= PhoneNumber::Home; - else if ( (*it)->value() == "work" ) type |= PhoneNumber::Work; - else if ( (*it)->value() == "msg" ) type |= PhoneNumber::Msg; - else if ( (*it)->value() == "pref" ) type |= PhoneNumber::Pref; - else if ( (*it)->value() == "voice" ) type |= PhoneNumber::Voice; - else if ( (*it)->value() == "fax" ) type |= PhoneNumber::Fax; - else if ( (*it)->value() == "cell" ) type |= PhoneNumber::Cell; - else if ( (*it)->value() == "video" ) type |= PhoneNumber::Video; - else if ( (*it)->value() == "bbs" ) type |= PhoneNumber::Bbs; - else if ( (*it)->value() == "modem" ) type |= PhoneNumber::Modem; - else if ( (*it)->value() == "car" ) type |= PhoneNumber::Car; - else if ( (*it)->value() == "isdn" ) type |= PhoneNumber::Isdn; - else if ( (*it)->value() == "pcs" ) type |= PhoneNumber::Pcs; - else if ( (*it)->value() == "pager" ) type |= PhoneNumber::Pager; + tmpStr = (*it)->value().lower(); + if ( tmpStr == "home" ) type |= PhoneNumber::Home; + else if ( tmpStr == "work" ) type |= PhoneNumber::Work; + else if ( tmpStr == "msg" ) type |= PhoneNumber::Msg; + else if ( tmpStr == "pref" ) type |= PhoneNumber::Pref; + else if ( tmpStr == "voice" ) type |= PhoneNumber::Voice; + else if ( tmpStr == "fax" ) type |= PhoneNumber::Fax; + else if ( tmpStr == "cell" ) type |= PhoneNumber::Cell; + else if ( tmpStr == "video" ) type |= PhoneNumber::Video; + else if ( tmpStr == "bbs" ) type |= PhoneNumber::Bbs; + else if ( tmpStr == "modem" ) type |= PhoneNumber::Modem; + else if ( tmpStr == "car" ) type |= PhoneNumber::Car; + else if ( tmpStr == "isdn" ) type |= PhoneNumber::Isdn; + else if ( tmpStr == "pcs" ) type |= PhoneNumber::Pcs; + else if ( tmpStr == "pager" ) type |= PhoneNumber::Pager; } } p.setType( type ); return p; } QString VCardFormatImpl::readTextValue( ContentLine *cl ) { VCARD::Value *value = cl->value(); if ( value ) { return QString::fromUtf8( value->asString() ); } else { kdDebug(5700) << "No value: " << cl->asString() << endl; return QString::null; } } QDate VCardFormatImpl::readDateValue( ContentLine *cl ) { DateValue *dateValue = (DateValue *)cl->value(); if ( dateValue ) return dateValue->qdate(); else return QDate(); } QDateTime VCardFormatImpl::readDateTimeValue( ContentLine *cl ) { DateValue *dateValue = (DateValue *)cl->value(); if ( dateValue ) return dateValue->qdt(); else return QDateTime(); } Geo VCardFormatImpl::readGeoValue( ContentLine *cl ) { GeoValue *geoValue = (GeoValue *)cl->value(); if ( geoValue ) { Geo geo( geoValue->latitude(), geoValue->longitude() ); return geo; } else return Geo(); } TimeZone VCardFormatImpl::readUTCValue( ContentLine *cl ) { diff --git a/kabc/vcardformatplugin.cpp b/kabc/vcardformatplugin.cpp index 3cba59a..bc18690 100644 --- a/kabc/vcardformatplugin.cpp +++ b/kabc/vcardformatplugin.cpp @@ -1,66 +1,70 @@ /* 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. */ #include "vcardformatplugin.h" #include "vcardformatimpl.h" using namespace KABC; VCardFormatPlugin::VCardFormatPlugin() { mImpl = new VCardFormatImpl; } VCardFormatPlugin::~VCardFormatPlugin() { delete mImpl; } bool VCardFormatPlugin::load( Addressee &addressee, QFile *file ) { + qDebug("VCardFormatPlugin::load"); return mImpl->load( addressee, file ); } bool VCardFormatPlugin::loadAll( AddressBook *addressBook, Resource *resource, QFile *file ) { + qDebug("VCardFormatPlugin::loadAll"); return mImpl->loadAll( addressBook, resource, file ); } void VCardFormatPlugin::save( const Addressee &addressee, QFile *file ) { + qDebug("VCardFormatPlugin::save"); mImpl->save( addressee, file ); } void VCardFormatPlugin::saveAll( AddressBook *addressBook, Resource *resource, QFile *file ) { + qDebug("VCardFormatPlugin::saveAll"); mImpl->saveAll( addressBook, resource, file ); } bool VCardFormatPlugin::checkFormat( QFile *file ) const { QString line; file->readLine( line, 1024 ); line = line.stripWhiteSpace(); if ( line == "BEGIN:VCARD" ) return true; else return false; } diff --git a/kabc/vcardparser/vcardtool.cpp b/kabc/vcardparser/vcardtool.cpp index 01c5b3e..71f29d7 100644 --- a/kabc/vcardparser/vcardtool.cpp +++ b/kabc/vcardparser/vcardtool.cpp @@ -58,101 +58,112 @@ VCardTool::VCardTool() mPhoneTypeMap.insert( "PCS", PhoneNumber::Pcs ); mPhoneTypeMap.insert( "PAGER", PhoneNumber::Pager ); } VCardTool::~VCardTool() { } QString VCardTool::createVCards( Addressee::List list, VCard::Version version ) { VCard::List vCardList; Addressee::List::Iterator addrIt; for ( addrIt = list.begin(); addrIt != list.end(); ++addrIt ) { VCard card; QStringList::ConstIterator strIt; // ADR + LABEL Address::List addresses = (*addrIt).addresses(); for ( Address::List::Iterator it = addresses.begin(); it != addresses.end(); ++it ) { QStringList address; /*US address.append( (*it).postOfficeBox().replace( ';', "\\;" ) ); address.append( (*it).extended().replace( ';', "\\;" ) ); address.append( (*it).street().replace( ';', "\\;" ) ); address.append( (*it).locality().replace( ';', "\\;" ) ); address.append( (*it).region().replace( ';', "\\;" ) ); address.append( (*it).postalCode().replace( ';', "\\;" ) ); address.append( (*it).country().replace( ';', "\\;" ) ); */ //US using the old implementation instead //qDebug("VCardTool::createVCards has to be verified"); address.append( (*it).postOfficeBox().replace( QRegExp(";"), "\\;" ) ); address.append( (*it).extended().replace( QRegExp(";"), "\\;" ) ); address.append( (*it).street().replace( QRegExp(";"), "\\;" ) ); address.append( (*it).locality().replace( QRegExp(";"), "\\;" ) ); address.append( (*it).region().replace( QRegExp(";"), "\\;" ) ); address.append( (*it).postalCode().replace( QRegExp(";"), "\\;" ) ); address.append( (*it).country().replace( QRegExp(";"), "\\;" ) ); VCardLine adrLine( "ADR", address.join( ";" ) ); VCardLine labelLine( "LABEL", (*it).label() ); bool hasLabel = !(*it).label().isEmpty(); QMap<QString, int>::Iterator typeIt; for ( typeIt = mAddressTypeMap.begin(); typeIt != mAddressTypeMap.end(); ++typeIt ) { if ( typeIt.data() & (*it).type() ) { + if ( version == VCard::v3_0 ) { + adrLine.addParameter( "TYPE", typeIt.key().lower() ); + } + else { adrLine.addParameter( "TYPE", typeIt.key() ); - if ( hasLabel ) + } + if ( hasLabel ) { + if ( version == VCard::v3_0 ) { + labelLine.addParameter( "TYPE", typeIt.key().lower() ); + } + else { labelLine.addParameter( "TYPE", typeIt.key() ); } } + } + } card.addLine( adrLine ); if ( hasLabel ) card.addLine( labelLine ); } // AGENT card.addLine( createAgent( version, (*addrIt).agent() ) ); // BDAY card.addLine( VCardLine( "BDAY", createDateTime( (*addrIt).birthday() ) ) ); // CATEGORIES if ( version == VCard::v3_0 ) { QStringList categories = (*addrIt).categories(); QStringList::Iterator catIt; for ( catIt = categories.begin(); catIt != categories.end(); ++catIt ) { //US using the old implementation instead // qDebug("VCardTool::createVCards has to be verified"); //US (*catIt).replace( ',', "\\," ); (*catIt).replace( QRegExp(","), "\\," ); } card.addLine( VCardLine( "CATEGORIES", categories.join( "," ) ) ); } // CLASS if ( version == VCard::v3_0 ) { card.addLine( createSecrecy( (*addrIt).secrecy() ) ); } // EMAIL QStringList emails = (*addrIt).emails(); bool pref = true; for ( strIt = emails.begin(); strIt != emails.end(); ++strIt ) { VCardLine line( "EMAIL", *strIt ); if ( pref == true ) { line.addParameter( "TYPE", "PREF" ); pref = false; } card.addLine( line ); } // FN card.addLine( VCardLine( "FN", (*addrIt).formattedName() ) ); // GEO Geo geo = (*addrIt).geo(); @@ -188,96 +199,99 @@ QString VCardTool::createVCards( Addressee::List list, VCard::Version version ) name.append( (*addrIt).familyName().replace( QRegExp(";"), "\\;" ) ); name.append( (*addrIt).givenName().replace( QRegExp(";"), "\\;" ) ); name.append( (*addrIt).additionalName().replace( QRegExp(";"), "\\;" ) ); name.append( (*addrIt).prefix().replace( QRegExp(";"), "\\;" ) ); name.append( (*addrIt).suffix().replace( QRegExp(";"), "\\;" ) ); if ( !name.join( "" ).isEmpty() ) card.addLine( VCardLine( "N", name.join( ";" ) ) ); // NICKNAME if ( version == VCard::v3_0 ) card.addLine( VCardLine( "NICKNAME", (*addrIt).nickName() ) ); // NOTE card.addLine( VCardLine( "NOTE", (*addrIt).note() ) ); // ORG card.addLine( VCardLine( "ORG", (*addrIt).organization() ) ); // PHOTO card.addLine( createPicture( "PHOTO", (*addrIt).photo() ) ); // PROID if ( version == VCard::v3_0 ) card.addLine( VCardLine( "PRODID", (*addrIt).productId() ) ); // REV card.addLine( VCardLine( "REV", createDateTime( (*addrIt).revision() ) ) ); // ROLE card.addLine( VCardLine( "ROLE", (*addrIt).role() ) ); // SORT-STRING if ( version == VCard::v3_0 ) card.addLine( VCardLine( "SORT-STRING", (*addrIt).sortString() ) ); // SOUND card.addLine( createSound( (*addrIt).sound() ) ); // TEL PhoneNumber::List phoneNumbers = (*addrIt).phoneNumbers(); PhoneNumber::List::ConstIterator phoneIt; for ( phoneIt = phoneNumbers.begin(); phoneIt != phoneNumbers.end(); ++phoneIt ) { VCardLine line( "TEL", (*phoneIt).number() ); QMap<QString, int>::Iterator typeIt; for ( typeIt = mPhoneTypeMap.begin(); typeIt != mPhoneTypeMap.end(); ++typeIt ) { if ( typeIt.data() & (*phoneIt).type() ) + if ( version == VCard::v3_0 ) + line.addParameter( "TYPE", typeIt.key().lower() ); + else line.addParameter( "TYPE", typeIt.key() ); } card.addLine( line ); } // TITLE card.addLine( VCardLine( "TITLE", (*addrIt).title() ) ); // TZ TimeZone timeZone = (*addrIt).timeZone(); if ( timeZone.isValid() ) { QString str; int neg = 1; if ( timeZone.offset() < 0 ) neg = -1; str.sprintf( "%c%02d:%02d", ( timeZone.offset() >= 0 ? '+' : '-' ), ( timeZone.offset() / 60 ) * neg, ( timeZone.offset() % 60 ) * neg ); card.addLine( VCardLine( "TZ", str ) ); } // UID card.addLine( VCardLine( "UID", (*addrIt).uid() ) ); // URL card.addLine( VCardLine( "URL", (*addrIt).url().url() ) ); // VERSION if ( version == VCard::v2_1 ) card.addLine( VCardLine( "VERSION", "2.1" ) ); if ( version == VCard::v3_0 ) card.addLine( VCardLine( "VERSION", "3.0" ) ); // X- QStringList customs = (*addrIt).customs(); for ( strIt = customs.begin(); strIt != customs.end(); ++strIt ) { QString identifier = "X-" + (*strIt).left( (*strIt).find( ":" ) ); QString value = (*strIt).mid( (*strIt).find( ":" ) + 1 ); if ( value.isEmpty() ) continue; card.addLine( VCardLine( identifier, value ) ); } |