-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 | 22 |
5 files changed, 53 insertions, 27 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,18 +1,18 @@ 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 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 @@ -21,88 +21,92 @@ 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 ); } diff --git a/kabc/vcardformatimpl.cpp b/kabc/vcardformatimpl.cpp index f90f813..3fcaf94 100644 --- a/kabc/vcardformatimpl.cpp +++ b/kabc/vcardformatimpl.cpp @@ -511,41 +511,43 @@ Address VCardFormatImpl::readAddressValue( ContentLine *cl ) 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() ); @@ -588,48 +590,50 @@ void VCardFormatImpl::addTelephoneValue( VCard *v, const PhoneNumber &p ) 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; } diff --git a/kabc/vcardformatplugin.cpp b/kabc/vcardformatplugin.cpp index 3cba59a..bc18690 100644 --- a/kabc/vcardformatplugin.cpp +++ b/kabc/vcardformatplugin.cpp @@ -22,45 +22,49 @@ #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 @@ -90,35 +90,46 @@ QString VCardTool::createVCards( Addressee::List list, VCard::Version version ) //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() ) { - adrLine.addParameter( "TYPE", typeIt.key() ); - if ( hasLabel ) - labelLine.addParameter( "TYPE", typeIt.key() ); + if ( version == VCard::v3_0 ) { + adrLine.addParameter( "TYPE", typeIt.key().lower() ); + } + else { + adrLine.addParameter( "TYPE", typeIt.key() ); + } + 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 ) { @@ -220,33 +231,36 @@ QString VCardTool::createVCards( Addressee::List list, VCard::Version version ) // 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() ) - line.addParameter( "TYPE", typeIt.key() ); + 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; |