summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressee.cpp4
-rw-r--r--kabc/addressee.h5
-rw-r--r--kabc/field.cpp8
-rw-r--r--kabc/phonenumber.cpp4
-rw-r--r--kabc/phonenumber.h3
-rw-r--r--kabc/vcard21parser.cpp5
-rw-r--r--kabc/vcard21parser.h1
-rw-r--r--kabc/vcardformatimpl.cpp2
-rw-r--r--kabc/vcardparser/vcardtool.cpp1
9 files changed, 29 insertions, 4 deletions
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp
index d484073..6b282e2 100644
--- a/kabc/addressee.cpp
+++ b/kabc/addressee.cpp
@@ -1,1622 +1,1626 @@
/*** Warning! This file has been generated by the script makeaddressee ***/
/*
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 <kconfig.h>
#include <ksharedptr.h>
#include <kdebug.h>
#include <kapplication.h>
#include <klocale.h>
//US
#include <kstandarddirs.h>
//US #include "resource.h"
#include "addressee.h"
using namespace KABC;
static bool matchBinaryPattern( int value, int pattern );
struct Addressee::AddresseeData : public KShared
{
QString uid;
QString name;
QString formattedName;
QString familyName;
QString givenName;
QString additionalName;
QString prefix;
QString suffix;
QString nickName;
QDateTime birthday;
QString mailer;
TimeZone timeZone;
Geo geo;
QString title;
QString role;
QString organization;
QString note;
QString productId;
QDateTime revision;
QString sortString;
KURL url;
Secrecy secrecy;
Picture logo;
Picture photo;
Sound sound;
Agent agent;
PhoneNumber::List phoneNumbers;
Address::List addresses;
Key::List keys;
QStringList emails;
QStringList categories;
QStringList custom;
Resource *resource;
bool empty :1;
bool changed :1;
};
Addressee::Addressee()
{
mData = new AddresseeData;
mData->empty = true;
mData->changed = false;
mData->resource = 0;
}
Addressee::~Addressee()
{
}
Addressee::Addressee( const Addressee &a )
{
mData = a.mData;
}
Addressee &Addressee::operator=( const Addressee &a )
{
mData = a.mData;
return (*this);
}
Addressee Addressee::copy()
{
Addressee a;
*(a.mData) = *mData;
return a;
}
void Addressee::detach()
{
if ( mData.count() == 1 ) return;
*this = copy();
}
bool Addressee::operator==( const Addressee &a ) const
{
if ( uid() != a.uid() ) return false;
if ( mData->name != a.mData->name ) return false;
if ( mData->formattedName != a.mData->formattedName ) return false;
if ( mData->familyName != a.mData->familyName ) return false;
if ( mData->givenName != a.mData->givenName ) return false;
if ( mData->additionalName != a.mData->additionalName ) return false;
if ( mData->prefix != a.mData->prefix ) return false;
if ( mData->suffix != a.mData->suffix ) return false;
if ( mData->nickName != a.mData->nickName ) return false;
if ( mData->birthday != a.mData->birthday ) return false;
if ( mData->mailer != a.mData->mailer ) return false;
if ( mData->timeZone != a.mData->timeZone ) return false;
if ( mData->geo != a.mData->geo ) return false;
if ( mData->title != a.mData->title ) return false;
if ( mData->role != a.mData->role ) return false;
if ( mData->organization != a.mData->organization ) return false;
if ( mData->note != a.mData->note ) return false;
if ( mData->productId != a.mData->productId ) return false;
if ( mData->revision != a.mData->revision ) return false;
if ( mData->sortString != a.mData->sortString ) return false;
if ( mData->secrecy != a.mData->secrecy ) return false;
if ( mData->logo != a.mData->logo ) return false;
if ( mData->photo != a.mData->photo ) return false;
if ( mData->sound != a.mData->sound ) return false;
if ( mData->agent != a.mData->agent ) return false;
if ( ( mData->url.isValid() || a.mData->url.isValid() ) &&
( mData->url != a.mData->url ) ) return false;
if ( mData->phoneNumbers != a.mData->phoneNumbers ) return false;
if ( mData->addresses != a.mData->addresses ) return false;
if ( mData->keys != a.mData->keys ) return false;
if ( mData->emails != a.mData->emails ) return false;
if ( mData->categories != a.mData->categories ) return false;
if ( mData->custom != a.mData->custom ) return false;
return true;
}
bool Addressee::operator!=( const Addressee &a ) const
{
return !( a == *this );
}
bool Addressee::isEmpty() const
{
return mData->empty;
}
void Addressee::setUid( const QString &id )
{
if ( id == mData->uid ) return;
detach();
mData->empty = false;
mData->uid = id;
}
QString Addressee::uid() const
{
if ( mData->uid.isEmpty() )
mData->uid = KApplication::randomString( 10 );
return mData->uid;
}
QString Addressee::uidLabel()
{
return i18n("Unique Identifier");
}
void Addressee::setName( const QString &name )
{
if ( name == mData->name ) return;
detach();
mData->empty = false;
mData->name = name;
}
QString Addressee::name() const
{
return mData->name;
}
QString Addressee::nameLabel()
{
return i18n("Name");
}
void Addressee::setFormattedName( const QString &formattedName )
{
if ( formattedName == mData->formattedName ) return;
detach();
mData->empty = false;
mData->formattedName = formattedName;
}
QString Addressee::formattedName() const
{
return mData->formattedName;
}
QString Addressee::formattedNameLabel()
{
return i18n("Formatted Name");
}
void Addressee::setFamilyName( const QString &familyName )
{
if ( familyName == mData->familyName ) return;
detach();
mData->empty = false;
mData->familyName = familyName;
}
QString Addressee::familyName() const
{
return mData->familyName;
}
QString Addressee::familyNameLabel()
{
return i18n("Family Name");
}
void Addressee::setGivenName( const QString &givenName )
{
if ( givenName == mData->givenName ) return;
detach();
mData->empty = false;
mData->givenName = givenName;
}
QString Addressee::givenName() const
{
return mData->givenName;
}
QString Addressee::givenNameLabel()
{
return i18n("Given Name");
}
void Addressee::setAdditionalName( const QString &additionalName )
{
if ( additionalName == mData->additionalName ) return;
detach();
mData->empty = false;
mData->additionalName = additionalName;
}
QString Addressee::additionalName() const
{
return mData->additionalName;
}
QString Addressee::additionalNameLabel()
{
return i18n("Additional Names");
}
void Addressee::setPrefix( const QString &prefix )
{
if ( prefix == mData->prefix ) return;
detach();
mData->empty = false;
mData->prefix = prefix;
}
QString Addressee::prefix() const
{
return mData->prefix;
}
QString Addressee::prefixLabel()
{
return i18n("Honorific Prefixes");
}
void Addressee::setSuffix( const QString &suffix )
{
if ( suffix == mData->suffix ) return;
detach();
mData->empty = false;
mData->suffix = suffix;
}
QString Addressee::suffix() const
{
return mData->suffix;
}
QString Addressee::suffixLabel()
{
return i18n("Honorific Suffixes");
}
void Addressee::setNickName( const QString &nickName )
{
if ( nickName == mData->nickName ) return;
detach();
mData->empty = false;
mData->nickName = nickName;
}
QString Addressee::nickName() const
{
return mData->nickName;
}
QString Addressee::nickNameLabel()
{
return i18n("Nick Name");
}
void Addressee::setBirthday( const QDateTime &birthday )
{
if ( birthday == mData->birthday ) return;
detach();
mData->empty = false;
mData->birthday = birthday;
}
QDateTime Addressee::birthday() const
{
return mData->birthday;
}
QString Addressee::birthdayLabel()
{
return i18n("Birthday");
}
QString Addressee::homeAddressStreetLabel()
{
return i18n("Home Address Street");
}
QString Addressee::homeAddressLocalityLabel()
{
return i18n("Home Address Locality");
}
QString Addressee::homeAddressRegionLabel()
{
return i18n("Home Address Region");
}
QString Addressee::homeAddressPostalCodeLabel()
{
return i18n("Home Address Postal Code");
}
QString Addressee::homeAddressCountryLabel()
{
return i18n("Home Address Country");
}
QString Addressee::homeAddressLabelLabel()
{
return i18n("Home Address Label");
}
QString Addressee::businessAddressStreetLabel()
{
return i18n("Business Address Street");
}
QString Addressee::businessAddressLocalityLabel()
{
return i18n("Business Address Locality");
}
QString Addressee::businessAddressRegionLabel()
{
return i18n("Business Address Region");
}
QString Addressee::businessAddressPostalCodeLabel()
{
return i18n("Business Address Postal Code");
}
QString Addressee::businessAddressCountryLabel()
{
return i18n("Business Address Country");
}
QString Addressee::businessAddressLabelLabel()
{
return i18n("Business Address Label");
}
QString Addressee::homePhoneLabel()
{
return i18n("Home Phone");
}
QString Addressee::businessPhoneLabel()
{
return i18n("Business Phone");
}
QString Addressee::mobilePhoneLabel()
{
return i18n("Mobile Phone");
}
QString Addressee::homeFaxLabel()
{
return i18n("Home Fax");
}
QString Addressee::businessFaxLabel()
{
return i18n("Business Fax");
}
QString Addressee::carPhoneLabel()
{
return i18n("Car Phone");
}
QString Addressee::isdnLabel()
{
return i18n("ISDN");
}
QString Addressee::pagerLabel()
{
return i18n("Pager");
}
+QString Addressee::sipLabel()
+{
+ return i18n("SIP");
+}
QString Addressee::emailLabel()
{
return i18n("Email Address");
}
void Addressee::setMailer( const QString &mailer )
{
if ( mailer == mData->mailer ) return;
detach();
mData->empty = false;
mData->mailer = mailer;
}
QString Addressee::mailer() const
{
return mData->mailer;
}
QString Addressee::mailerLabel()
{
return i18n("Mail Client");
}
void Addressee::setTimeZone( const TimeZone &timeZone )
{
if ( timeZone == mData->timeZone ) return;
detach();
mData->empty = false;
mData->timeZone = timeZone;
}
TimeZone Addressee::timeZone() const
{
return mData->timeZone;
}
QString Addressee::timeZoneLabel()
{
return i18n("Time Zone");
}
void Addressee::setGeo( const Geo &geo )
{
if ( geo == mData->geo ) return;
detach();
mData->empty = false;
mData->geo = geo;
}
Geo Addressee::geo() const
{
return mData->geo;
}
QString Addressee::geoLabel()
{
return i18n("Geographic Position");
}
void Addressee::setTitle( const QString &title )
{
if ( title == mData->title ) return;
detach();
mData->empty = false;
mData->title = title;
}
QString Addressee::title() const
{
return mData->title;
}
QString Addressee::titleLabel()
{
return i18n("Title");
}
void Addressee::setRole( const QString &role )
{
if ( role == mData->role ) return;
detach();
mData->empty = false;
mData->role = role;
}
QString Addressee::role() const
{
return mData->role;
}
QString Addressee::roleLabel()
{
return i18n("Role");
}
void Addressee::setOrganization( const QString &organization )
{
if ( organization == mData->organization ) return;
detach();
mData->empty = false;
mData->organization = organization;
}
QString Addressee::organization() const
{
return mData->organization;
}
QString Addressee::organizationLabel()
{
return i18n("Organization");
}
void Addressee::setNote( const QString &note )
{
if ( note == mData->note ) return;
detach();
mData->empty = false;
mData->note = note;
}
QString Addressee::note() const
{
return mData->note;
}
QString Addressee::noteLabel()
{
return i18n("Note");
}
void Addressee::setProductId( const QString &productId )
{
if ( productId == mData->productId ) return;
detach();
mData->empty = false;
mData->productId = productId;
}
QString Addressee::productId() const
{
return mData->productId;
}
QString Addressee::productIdLabel()
{
return i18n("Product Identifier");
}
void Addressee::setRevision( const QDateTime &revision )
{
if ( revision == mData->revision ) return;
detach();
mData->empty = false;
mData->revision = revision;
}
QDateTime Addressee::revision() const
{
return mData->revision;
}
QString Addressee::revisionLabel()
{
return i18n("Revision Date");
}
void Addressee::setSortString( const QString &sortString )
{
if ( sortString == mData->sortString ) return;
detach();
mData->empty = false;
mData->sortString = sortString;
}
QString Addressee::sortString() const
{
return mData->sortString;
}
QString Addressee::sortStringLabel()
{
return i18n("Sort String");
}
void Addressee::setUrl( const KURL &url )
{
if ( url == mData->url ) return;
detach();
mData->empty = false;
mData->url = url;
}
KURL Addressee::url() const
{
return mData->url;
}
QString Addressee::urlLabel()
{
return i18n("URL");
}
void Addressee::setSecrecy( const Secrecy &secrecy )
{
if ( secrecy == mData->secrecy ) return;
detach();
mData->empty = false;
mData->secrecy = secrecy;
}
Secrecy Addressee::secrecy() const
{
return mData->secrecy;
}
QString Addressee::secrecyLabel()
{
return i18n("Security Class");
}
void Addressee::setLogo( const Picture &logo )
{
if ( logo == mData->logo ) return;
detach();
mData->empty = false;
mData->logo = logo;
}
Picture Addressee::logo() const
{
return mData->logo;
}
QString Addressee::logoLabel()
{
return i18n("Logo");
}
void Addressee::setPhoto( const Picture &photo )
{
if ( photo == mData->photo ) return;
detach();
mData->empty = false;
mData->photo = photo;
}
Picture Addressee::photo() const
{
return mData->photo;
}
QString Addressee::photoLabel()
{
return i18n("Photo");
}
void Addressee::setSound( const Sound &sound )
{
if ( sound == mData->sound ) return;
detach();
mData->empty = false;
mData->sound = sound;
}
Sound Addressee::sound() const
{
return mData->sound;
}
QString Addressee::soundLabel()
{
return i18n("Sound");
}
void Addressee::setAgent( const Agent &agent )
{
if ( agent == mData->agent ) return;
detach();
mData->empty = false;
mData->agent = agent;
}
Agent Addressee::agent() const
{
return mData->agent;
}
QString Addressee::agentLabel()
{
return i18n("Agent");
}
void Addressee::setNameFromString( const QString &str )
{
setFormattedName( str );
setName( str );
QStringList titles;
titles += i18n( "Dr." );
titles += i18n( "Miss" );
titles += i18n( "Mr." );
titles += i18n( "Mrs." );
titles += i18n( "Ms." );
titles += i18n( "Prof." );
QStringList suffixes;
suffixes += i18n( "I" );
suffixes += i18n( "II" );
suffixes += i18n( "III" );
suffixes += i18n( "Jr." );
suffixes += i18n( "Sr." );
QStringList prefixes;
prefixes += "van";
prefixes += "von";
prefixes += "de";
//US KConfig config( "kabcrc" );
KConfig config( locateLocal( "config", "kabcrc") );
config.setGroup( "General" );
titles += config.readListEntry( "Prefixes" );
titles.remove( "" );
prefixes += config.readListEntry( "Inclusions" );
prefixes.remove( "" );
suffixes += config.readListEntry( "Suffixes" );
suffixes.remove( "" );
// clear all name parts
setPrefix( "" );
setGivenName( "" );
setAdditionalName( "" );
setFamilyName( "" );
setSuffix( "" );
if ( str.isEmpty() )
return;
int i = str.find(',');
if( i < 0 ) {
QStringList parts = QStringList::split( " ", str );
int leftOffset = 0;
int rightOffset = parts.count() - 1;
QString suffix;
while ( rightOffset >= 0 ) {
if ( suffixes.contains( parts[ rightOffset ] ) ) {
suffix.prepend(parts[ rightOffset ] + (suffix.isEmpty() ? "" : " "));
rightOffset--;
} else
break;
}
setSuffix( suffix );
if ( rightOffset < 0 )
return;
if ( rightOffset - 1 >= 0 && prefixes.contains( parts[ rightOffset - 1 ].lower() ) ) {
setFamilyName( parts[ rightOffset - 1 ] + " " + parts[ rightOffset ] );
rightOffset--;
} else
setFamilyName( parts[ rightOffset ] );
QString prefix;
while ( leftOffset < rightOffset ) {
if ( titles.contains( parts[ leftOffset ] ) ) {
prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] );
leftOffset++;
} else
break;
}
setPrefix( prefix );
if ( leftOffset < rightOffset ) {
setGivenName( parts[ leftOffset ] );
leftOffset++;
}
QString additionalName;
while ( leftOffset < rightOffset ) {
additionalName.append( ( additionalName.isEmpty() ? "" : " ") + parts[ leftOffset ] );
leftOffset++;
}
setAdditionalName( additionalName );
} else {
QString part1 = str.left( i );
QString part2 = str.mid( i + 1 );
QStringList parts = QStringList::split( " ", part1 );
int leftOffset = 0;
int rightOffset = parts.count() - 1;
QString suffix;
while ( rightOffset >= 0 ) {
if ( suffixes.contains( parts[ rightOffset ] ) ) {
suffix.prepend(parts[ rightOffset ] + (suffix.isEmpty() ? "" : " "));
rightOffset--;
} else
break;
}
setSuffix( suffix );
if ( rightOffset - 1 >= 0 && prefixes.contains( parts[ rightOffset - 1 ].lower() ) ) {
setFamilyName( parts[ rightOffset - 1 ] + " " + parts[ rightOffset ] );
rightOffset--;
} else
setFamilyName( parts[ rightOffset ] );
QString prefix;
while ( leftOffset < rightOffset ) {
if ( titles.contains( parts[ leftOffset ] ) ) {
prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] );
leftOffset++;
} else
break;
}
parts = QStringList::split( " ", part2 );
leftOffset = 0;
rightOffset = parts.count();
while ( leftOffset < rightOffset ) {
if ( titles.contains( parts[ leftOffset ] ) ) {
prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] );
leftOffset++;
} else
break;
}
setPrefix( prefix );
if ( leftOffset < rightOffset ) {
setGivenName( parts[ leftOffset ] );
leftOffset++;
}
QString additionalName;
while ( leftOffset < rightOffset ) {
additionalName.append( ( additionalName.isEmpty() ? "" : " ") + parts[ leftOffset ] );
leftOffset++;
}
setAdditionalName( additionalName );
}
}
QString Addressee::realName() const
{
if ( !formattedName().isEmpty() )
return formattedName();
QString n = assembledName();
if ( n.isEmpty() )
n = name();
return n;
}
QString Addressee::assembledName() const
{
QString name = prefix() + " " + givenName() + " " + additionalName() + " " +
familyName() + " " + suffix();
return name.simplifyWhiteSpace();
}
QString Addressee::fullEmail( const QString &email ) const
{
QString e;
if ( email.isNull() ) {
e = preferredEmail();
} else {
e = email;
}
if ( e.isEmpty() ) return QString::null;
QString text;
if ( realName().isEmpty() )
text = e;
else
text = assembledName() + " <" + e + ">";
return text;
}
void Addressee::insertEmail( const QString &email, bool preferred )
{
detach();
QStringList::Iterator it = mData->emails.find( email );
if ( it != mData->emails.end() ) {
if ( !preferred || it == mData->emails.begin() ) return;
mData->emails.remove( it );
mData->emails.prepend( email );
} else {
if ( preferred ) {
mData->emails.prepend( email );
} else {
mData->emails.append( email );
}
}
}
void Addressee::removeEmail( const QString &email )
{
detach();
QStringList::Iterator it = mData->emails.find( email );
if ( it == mData->emails.end() ) return;
mData->emails.remove( it );
}
QString Addressee::preferredEmail() const
{
if ( mData->emails.count() == 0 ) return QString::null;
else return mData->emails.first();
}
QStringList Addressee::emails() const
{
return mData->emails;
}
void Addressee::setEmails( const QStringList& emails ) {
detach();
mData->emails = emails;
}
void Addressee::insertPhoneNumber( const PhoneNumber &phoneNumber )
{
detach();
mData->empty = false;
PhoneNumber::List::Iterator it;
for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
if ( (*it).id() == phoneNumber.id() ) {
*it = phoneNumber;
return;
}
}
mData->phoneNumbers.append( phoneNumber );
}
void Addressee::removePhoneNumber( const PhoneNumber &phoneNumber )
{
detach();
PhoneNumber::List::Iterator it;
for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
if ( (*it).id() == phoneNumber.id() ) {
mData->phoneNumbers.remove( it );
return;
}
}
}
PhoneNumber Addressee::phoneNumber( int type ) const
{
PhoneNumber phoneNumber( "", type );
PhoneNumber::List::ConstIterator it;
for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
if ( matchBinaryPattern( (*it).type(), type ) ) {
if ( (*it).type() & PhoneNumber::Pref )
return (*it);
else if ( phoneNumber.number().isEmpty() )
phoneNumber = (*it);
}
}
return phoneNumber;
}
PhoneNumber::List Addressee::phoneNumbers() const
{
return mData->phoneNumbers;
}
PhoneNumber::List Addressee::phoneNumbers( int type ) const
{
PhoneNumber::List list;
PhoneNumber::List::ConstIterator it;
for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
if ( matchBinaryPattern( (*it).type(), type ) ) {
list.append( *it );
}
}
return list;
}
PhoneNumber Addressee::findPhoneNumber( const QString &id ) const
{
PhoneNumber::List::ConstIterator it;
for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
if ( (*it).id() == id ) {
return *it;
}
}
return PhoneNumber();
}
void Addressee::insertKey( const Key &key )
{
detach();
mData->empty = false;
Key::List::Iterator it;
for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
if ( (*it).id() == key.id() ) {
*it = key;
return;
}
}
mData->keys.append( key );
}
void Addressee::removeKey( const Key &key )
{
detach();
Key::List::Iterator it;
for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
if ( (*it).id() == key.id() ) {
mData->keys.remove( key );
return;
}
}
}
Key Addressee::key( int type, QString customTypeString ) const
{
Key::List::ConstIterator it;
for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
if ( (*it).type() == type ) {
if ( type == Key::Custom ) {
if ( customTypeString.isEmpty() ) {
return *it;
} else {
if ( (*it).customTypeString() == customTypeString )
return (*it);
}
} else {
return *it;
}
}
}
return Key( QString(), type );
}
void Addressee::setKeys( const Key::List& list ) {
detach();
mData->keys = list;
}
Key::List Addressee::keys() const
{
return mData->keys;
}
Key::List Addressee::keys( int type, QString customTypeString ) const
{
Key::List list;
Key::List::ConstIterator it;
for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
if ( (*it).type() == type ) {
if ( type == Key::Custom ) {
if ( customTypeString.isEmpty() ) {
list.append(*it);
} else {
if ( (*it).customTypeString() == customTypeString )
list.append(*it);
}
} else {
list.append(*it);
}
}
}
return list;
}
Key Addressee::findKey( const QString &id ) const
{
Key::List::ConstIterator it;
for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
if ( (*it).id() == id ) {
return *it;
}
}
return Key();
}
QString Addressee::asString() const
{
return "Smith, agent Smith...";
}
void Addressee::dump() const
{
return;
kdDebug(5700) << "Addressee {" << endl;
kdDebug(5700) << " Uid: '" << uid() << "'" << endl;
kdDebug(5700) << " Name: '" << name() << "'" << endl;
kdDebug(5700) << " FormattedName: '" << formattedName() << "'" << endl;
kdDebug(5700) << " FamilyName: '" << familyName() << "'" << endl;
kdDebug(5700) << " GivenName: '" << givenName() << "'" << endl;
kdDebug(5700) << " AdditionalName: '" << additionalName() << "'" << endl;
kdDebug(5700) << " Prefix: '" << prefix() << "'" << endl;
kdDebug(5700) << " Suffix: '" << suffix() << "'" << endl;
kdDebug(5700) << " NickName: '" << nickName() << "'" << endl;
kdDebug(5700) << " Birthday: '" << birthday().toString() << "'" << endl;
kdDebug(5700) << " Mailer: '" << mailer() << "'" << endl;
kdDebug(5700) << " TimeZone: '" << timeZone().asString() << "'" << endl;
kdDebug(5700) << " Geo: '" << geo().asString() << "'" << endl;
kdDebug(5700) << " Title: '" << title() << "'" << endl;
kdDebug(5700) << " Role: '" << role() << "'" << endl;
kdDebug(5700) << " Organization: '" << organization() << "'" << endl;
kdDebug(5700) << " Note: '" << note() << "'" << endl;
kdDebug(5700) << " ProductId: '" << productId() << "'" << endl;
kdDebug(5700) << " Revision: '" << revision().toString() << "'" << endl;
kdDebug(5700) << " SortString: '" << sortString() << "'" << endl;
kdDebug(5700) << " Url: '" << url().url() << "'" << endl;
kdDebug(5700) << " Secrecy: '" << secrecy().asString() << "'" << endl;
kdDebug(5700) << " Logo: '" << logo().asString() << "'" << endl;
kdDebug(5700) << " Photo: '" << photo().asString() << "'" << endl;
kdDebug(5700) << " Sound: '" << sound().asString() << "'" << endl;
kdDebug(5700) << " Agent: '" << agent().asString() << "'" << endl;
kdDebug(5700) << " Emails {" << endl;
QStringList e = emails();
QStringList::ConstIterator it;
for( it = e.begin(); it != e.end(); ++it ) {
kdDebug(5700) << " " << (*it) << endl;
}
kdDebug(5700) << " }" << endl;
kdDebug(5700) << " PhoneNumbers {" << endl;
PhoneNumber::List p = phoneNumbers();
PhoneNumber::List::ConstIterator it2;
for( it2 = p.begin(); it2 != p.end(); ++it2 ) {
kdDebug(5700) << " Type: " << int((*it2).type()) << " Number: " << (*it2).number() << endl;
}
kdDebug(5700) << " }" << endl;
Address::List a = addresses();
Address::List::ConstIterator it3;
for( it3 = a.begin(); it3 != a.end(); ++it3 ) {
(*it3).dump();
}
kdDebug(5700) << " Keys {" << endl;
Key::List k = keys();
Key::List::ConstIterator it4;
for( it4 = k.begin(); it4 != k.end(); ++it4 ) {
kdDebug(5700) << " Type: " << int((*it4).type()) <<
" Key: " << (*it4).textData() <<
" CustomString: " << (*it4).customTypeString() << endl;
}
kdDebug(5700) << " }" << endl;
kdDebug(5700) << "}" << endl;
}
void Addressee::insertAddress( const Address &address )
{
detach();
mData->empty = false;
Address::List::Iterator it;
for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
if ( (*it).id() == address.id() ) {
*it = address;
return;
}
}
mData->addresses.append( address );
}
void Addressee::removeAddress( const Address &address )
{
detach();
Address::List::Iterator it;
for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
if ( (*it).id() == address.id() ) {
mData->addresses.remove( it );
return;
}
}
}
Address Addressee::address( int type ) const
{
Address address( type );
Address::List::ConstIterator it;
for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
if ( matchBinaryPattern( (*it).type(), type ) ) {
if ( (*it).type() & Address::Pref )
return (*it);
else if ( address.isEmpty() )
address = (*it);
}
}
return address;
}
Address::List Addressee::addresses() const
{
return mData->addresses;
}
Address::List Addressee::addresses( int type ) const
{
Address::List list;
Address::List::ConstIterator it;
for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
if ( matchBinaryPattern( (*it).type(), type ) ) {
list.append( *it );
}
}
return list;
}
Address Addressee::findAddress( const QString &id ) const
{
Address::List::ConstIterator it;
for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
if ( (*it).id() == id ) {
return *it;
}
}
return Address();
}
void Addressee::insertCategory( const QString &c )
{
detach();
mData->empty = false;
if ( mData->categories.contains( c ) ) return;
mData->categories.append( c );
}
void Addressee::removeCategory( const QString &c )
{
detach();
QStringList::Iterator it = mData->categories.find( c );
if ( it == mData->categories.end() ) return;
mData->categories.remove( it );
}
bool Addressee::hasCategory( const QString &c ) const
{
return ( mData->categories.contains( c ) );
}
void Addressee::setCategories( const QStringList &c )
{
detach();
mData->empty = false;
mData->categories = c;
}
QStringList Addressee::categories() const
{
return mData->categories;
}
void Addressee::insertCustom( const QString &app, const QString &name,
const QString &value )
{
if ( value.isNull() || name.isEmpty() || app.isEmpty() ) return;
detach();
mData->empty = false;
QString qualifiedName = app + "-" + name + ":";
QStringList::Iterator it;
for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) {
if ( (*it).startsWith( qualifiedName ) ) {
(*it) = qualifiedName + value;
return;
}
}
mData->custom.append( qualifiedName + value );
}
void Addressee::removeCustom( const QString &app, const QString &name)
{
detach();
QString qualifiedName = app + "-" + name + ":";
QStringList::Iterator it;
for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) {
if ( (*it).startsWith( qualifiedName ) ) {
mData->custom.remove( it );
return;
}
}
}
QString Addressee::custom( const QString &app, const QString &name ) const
{
QString qualifiedName = app + "-" + name + ":";
QString value;
QStringList::ConstIterator it;
for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) {
if ( (*it).startsWith( qualifiedName ) ) {
value = (*it).mid( (*it).find( ":" ) + 1 );
break;
}
}
return value;
}
void Addressee::setCustoms( const QStringList &l )
{
detach();
mData->empty = false;
mData->custom = l;
}
QStringList Addressee::customs() const
{
return mData->custom;
}
void Addressee::parseEmailAddress( const QString &rawEmail, QString &fullName,
QString &email)
{
int startPos, endPos, len;
QString partA, partB, result;
char endCh = '>';
startPos = rawEmail.find('<');
if (startPos < 0)
{
startPos = rawEmail.find('(');
endCh = ')';
}
if (startPos < 0)
{
// We couldn't find any separators, so we assume the whole string
// is the email address
email = rawEmail;
fullName = "";
}
else
{
// We have a start position, try to find an end
endPos = rawEmail.find(endCh, startPos+1);
if (endPos < 0)
{
// We couldn't find the end of the email address. We can only
// assume the entire string is the email address.
email = rawEmail;
fullName = "";
}
else
{
// We have a start and end to the email address
// Grab the name part
fullName = rawEmail.left(startPos).stripWhiteSpace();
// grab the email part
email = rawEmail.mid(startPos+1, endPos-startPos-1).stripWhiteSpace();
// Check that we do not have any extra characters on the end of the
// strings
len = fullName.length();
if (fullName[0]=='"' && fullName[len-1]=='"')
fullName = fullName.mid(1, len-2);
else if (fullName[0]=='<' && fullName[len-1]=='>')
fullName = fullName.mid(1, len-2);
else if (fullName[0]=='(' && fullName[len-1]==')')
fullName = fullName.mid(1, len-2);
}
}
}
void Addressee::setResource( Resource *resource )
{
detach();
mData->resource = resource;
}
Resource *Addressee::resource() const
{
return mData->resource;
}
//US
QString Addressee::resourceLabel()
{
return i18n("Resource");
}
void Addressee::setChanged( bool value )
{
detach();
mData->changed = value;
}
bool Addressee::changed() const
{
return mData->changed;
}
QDataStream &KABC::operator<<( QDataStream &s, const Addressee &a )
{
if (!a.mData) return s;
s << a.uid();
s << a.mData->name;
s << a.mData->formattedName;
s << a.mData->familyName;
s << a.mData->givenName;
s << a.mData->additionalName;
s << a.mData->prefix;
s << a.mData->suffix;
s << a.mData->nickName;
s << a.mData->birthday;
s << a.mData->mailer;
s << a.mData->timeZone;
s << a.mData->geo;
s << a.mData->title;
s << a.mData->role;
s << a.mData->organization;
s << a.mData->note;
s << a.mData->productId;
s << a.mData->revision;
s << a.mData->sortString;
s << a.mData->url;
s << a.mData->secrecy;
s << a.mData->logo;
s << a.mData->photo;
s << a.mData->sound;
s << a.mData->agent;
s << a.mData->phoneNumbers;
s << a.mData->addresses;
s << a.mData->emails;
s << a.mData->categories;
s << a.mData->custom;
s << a.mData->keys;
return s;
}
QDataStream &KABC::operator>>( QDataStream &s, Addressee &a )
{
if (!a.mData) return s;
s >> a.mData->uid;
s >> a.mData->name;
s >> a.mData->formattedName;
s >> a.mData->familyName;
s >> a.mData->givenName;
s >> a.mData->additionalName;
s >> a.mData->prefix;
s >> a.mData->suffix;
s >> a.mData->nickName;
s >> a.mData->birthday;
s >> a.mData->mailer;
s >> a.mData->timeZone;
s >> a.mData->geo;
s >> a.mData->title;
s >> a.mData->role;
s >> a.mData->organization;
s >> a.mData->note;
s >> a.mData->productId;
s >> a.mData->revision;
s >> a.mData->sortString;
s >> a.mData->url;
s >> a.mData->secrecy;
s >> a.mData->logo;
s >> a.mData->photo;
s >> a.mData->sound;
s >> a.mData->agent;
s >> a.mData->phoneNumbers;
s >> a.mData->addresses;
s >> a.mData->emails;
s >> a.mData->categories;
s >> a.mData->custom;
s >> a.mData->keys;
a.mData->empty = false;
return s;
}
bool matchBinaryPattern( int value, int pattern )
{
/**
We want to match all telephonnumbers/addresses which have the bits in the
pattern set. More are allowed.
if pattern == 0 we have a special handling, then we want only those with
exactly no bit set.
*/
if ( pattern == 0 )
return ( value == 0 );
else
return ( pattern == ( pattern & value ) );
}
diff --git a/kabc/addressee.h b/kabc/addressee.h
index 393d1cc..27782f9 100644
--- a/kabc/addressee.h
+++ b/kabc/addressee.h
@@ -1,823 +1,828 @@
/*** Warning! This file has been generated by the script makeaddressee ***/
/*
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$
*/
#ifndef KABC_ADDRESSEE_H
#define KABC_ADDRESSEE_H
#include <qdatetime.h>
#include <qstring.h>
#include <qstringlist.h>
#include <qvaluelist.h>
#include <ksharedptr.h>
#include <kurl.h>
#include "address.h"
#include "agent.h"
#include "geo.h"
#include "key.h"
#include "phonenumber.h"
#include "picture.h"
#include "secrecy.h"
#include "sound.h"
#include "timezone.h"
namespace KABC {
class Resource;
/**
@short address book entry
This class represents an entry in the address book.
The data of this class is implicitly shared. You can pass this class by value.
If you need the name of a field for presenting it to the user you should use
the functions ending in Label(). They return a translated string which can be
used as label for the corresponding field.
About the name fields:
givenName() is the first name and familyName() the last name. In some
countries the family name comes first, that's the reason for the
naming. formattedName() is the full name with the correct formatting.
It is used as an override, when the correct formatting can't be generated
from the other name fields automatically.
realName() returns a fully formatted name(). It uses formattedName, if set,
otherwise it constucts the name from the name fields. As fallback, if
nothing else is set it uses name().
name() is the NAME type of RFC2426. It can be used as internal name for the
data enty, but shouldn't be used for displaying the data to the user.
*/
class Addressee
{
friend QDataStream &operator<<( QDataStream &, const Addressee & );
friend QDataStream &operator>>( QDataStream &, Addressee & );
public:
typedef QValueList<Addressee> List;
/**
Construct an empty address book entry.
*/
Addressee();
~Addressee();
Addressee( const Addressee & );
Addressee &operator=( const Addressee & );
bool operator==( const Addressee & ) const;
bool operator!=( const Addressee & ) const;
/**
Return, if the address book entry is empty.
*/
bool isEmpty() const;
/**
Set unique identifier.
*/
void setUid( const QString &uid );
/**
Return unique identifier.
*/
QString uid() const;
/**
Return translated label for uid field.
*/
static QString uidLabel();
/**
Set name.
*/
void setName( const QString &name );
/**
Return name.
*/
QString name() const;
/**
Return translated label for name field.
*/
static QString nameLabel();
/**
Set formatted name.
*/
void setFormattedName( const QString &formattedName );
/**
Return formatted name.
*/
QString formattedName() const;
/**
Return translated label for formattedName field.
*/
static QString formattedNameLabel();
/**
Set family name.
*/
void setFamilyName( const QString &familyName );
/**
Return family name.
*/
QString familyName() const;
/**
Return translated label for familyName field.
*/
static QString familyNameLabel();
/**
Set given name.
*/
void setGivenName( const QString &givenName );
/**
Return given name.
*/
QString givenName() const;
/**
Return translated label for givenName field.
*/
static QString givenNameLabel();
/**
Set additional names.
*/
void setAdditionalName( const QString &additionalName );
/**
Return additional names.
*/
QString additionalName() const;
/**
Return translated label for additionalName field.
*/
static QString additionalNameLabel();
/**
Set honorific prefixes.
*/
void setPrefix( const QString &prefix );
/**
Return honorific prefixes.
*/
QString prefix() const;
/**
Return translated label for prefix field.
*/
static QString prefixLabel();
/**
Set honorific suffixes.
*/
void setSuffix( const QString &suffix );
/**
Return honorific suffixes.
*/
QString suffix() const;
/**
Return translated label for suffix field.
*/
static QString suffixLabel();
/**
Set nick name.
*/
void setNickName( const QString &nickName );
/**
Return nick name.
*/
QString nickName() const;
/**
Return translated label for nickName field.
*/
static QString nickNameLabel();
/**
Set birthday.
*/
void setBirthday( const QDateTime &birthday );
/**
Return birthday.
*/
QDateTime birthday() const;
/**
Return translated label for birthday field.
*/
static QString birthdayLabel();
/**
Return translated label for homeAddressStreet field.
*/
static QString homeAddressStreetLabel();
/**
Return translated label for homeAddressLocality field.
*/
static QString homeAddressLocalityLabel();
/**
Return translated label for homeAddressRegion field.
*/
static QString homeAddressRegionLabel();
/**
Return translated label for homeAddressPostalCode field.
*/
static QString homeAddressPostalCodeLabel();
/**
Return translated label for homeAddressCountry field.
*/
static QString homeAddressCountryLabel();
/**
Return translated label for homeAddressLabel field.
*/
static QString homeAddressLabelLabel();
/**
Return translated label for businessAddressStreet field.
*/
static QString businessAddressStreetLabel();
/**
Return translated label for businessAddressLocality field.
*/
static QString businessAddressLocalityLabel();
/**
Return translated label for businessAddressRegion field.
*/
static QString businessAddressRegionLabel();
/**
Return translated label for businessAddressPostalCode field.
*/
static QString businessAddressPostalCodeLabel();
/**
Return translated label for businessAddressCountry field.
*/
static QString businessAddressCountryLabel();
/**
Return translated label for businessAddressLabel field.
*/
static QString businessAddressLabelLabel();
/**
Return translated label for homePhone field.
*/
static QString homePhoneLabel();
/**
Return translated label for businessPhone field.
*/
static QString businessPhoneLabel();
/**
Return translated label for mobilePhone field.
*/
static QString mobilePhoneLabel();
/**
Return translated label for homeFax field.
*/
static QString homeFaxLabel();
/**
Return translated label for businessFax field.
*/
static QString businessFaxLabel();
/**
Return translated label for carPhone field.
*/
static QString carPhoneLabel();
/**
Return translated label for isdn field.
*/
static QString isdnLabel();
/**
Return translated label for pager field.
*/
static QString pagerLabel();
/**
+ Return translated label for sip field.
+ */
+ static QString sipLabel();
+
+ /**
Return translated label for email field.
*/
static QString emailLabel();
/**
Set mail client.
*/
void setMailer( const QString &mailer );
/**
Return mail client.
*/
QString mailer() const;
/**
Return translated label for mailer field.
*/
static QString mailerLabel();
/**
Set time zone.
*/
void setTimeZone( const TimeZone &timeZone );
/**
Return time zone.
*/
TimeZone timeZone() const;
/**
Return translated label for timeZone field.
*/
static QString timeZoneLabel();
/**
Set geographic position.
*/
void setGeo( const Geo &geo );
/**
Return geographic position.
*/
Geo geo() const;
/**
Return translated label for geo field.
*/
static QString geoLabel();
/**
Set title.
*/
void setTitle( const QString &title );
/**
Return title.
*/
QString title() const;
/**
Return translated label for title field.
*/
static QString titleLabel();
/**
Set role.
*/
void setRole( const QString &role );
/**
Return role.
*/
QString role() const;
/**
Return translated label for role field.
*/
static QString roleLabel();
/**
Set organization.
*/
void setOrganization( const QString &organization );
/**
Return organization.
*/
QString organization() const;
/**
Return translated label for organization field.
*/
static QString organizationLabel();
/**
Set note.
*/
void setNote( const QString &note );
/**
Return note.
*/
QString note() const;
/**
Return translated label for note field.
*/
static QString noteLabel();
/**
Set product identifier.
*/
void setProductId( const QString &productId );
/**
Return product identifier.
*/
QString productId() const;
/**
Return translated label for productId field.
*/
static QString productIdLabel();
/**
Set revision date.
*/
void setRevision( const QDateTime &revision );
/**
Return revision date.
*/
QDateTime revision() const;
/**
Return translated label for revision field.
*/
static QString revisionLabel();
/**
Set sort string.
*/
void setSortString( const QString &sortString );
/**
Return sort string.
*/
QString sortString() const;
/**
Return translated label for sortString field.
*/
static QString sortStringLabel();
/**
Set URL.
*/
void setUrl( const KURL &url );
/**
Return URL.
*/
KURL url() const;
/**
Return translated label for url field.
*/
static QString urlLabel();
/**
Set security class.
*/
void setSecrecy( const Secrecy &secrecy );
/**
Return security class.
*/
Secrecy secrecy() const;
/**
Return translated label for secrecy field.
*/
static QString secrecyLabel();
/**
Set logo.
*/
void setLogo( const Picture &logo );
/**
Return logo.
*/
Picture logo() const;
/**
Return translated label for logo field.
*/
static QString logoLabel();
/**
Set photo.
*/
void setPhoto( const Picture &photo );
/**
Return photo.
*/
Picture photo() const;
/**
Return translated label for photo field.
*/
static QString photoLabel();
/**
Set sound.
*/
void setSound( const Sound &sound );
/**
Return sound.
*/
Sound sound() const;
/**
Return translated label for sound field.
*/
static QString soundLabel();
/**
Set agent.
*/
void setAgent( const Agent &agent );
/**
Return agent.
*/
Agent agent() const;
/**
Return translated label for agent field.
*/
static QString agentLabel();
/**
Set name fields by parsing the given string and trying to associate the
parts of the string with according fields. This function should probably
be a bit more clever.
*/
void setNameFromString( const QString & );
/**
Return the name of the addressee. This is calculated from all the name
fields.
*/
QString realName() const;
/**
Return the name that consists of all name parts.
*/
QString assembledName() const;
/**
Return email address including real name.
@param email Email address to be used to construct the full email string.
If this is QString::null the preferred email address is used.
*/
QString fullEmail( const QString &email=QString::null ) const;
/**
Insert an email address. If the email address already exists in this
addressee it is not duplicated.
@param email Email address
@param preferred Set to true, if this is the preferred email address of
the addressee.
*/
void insertEmail( const QString &email, bool preferred=false );
/**
Remove email address. If the email address doesn't exist, nothing happens.
*/
void removeEmail( const QString &email );
/**
Return preferred email address. This is the first email address or the
last one added with @ref insertEmail() with a set preferred parameter.
*/
QString preferredEmail() const;
/**
Return list of all email addresses.
*/
QStringList emails() const;
/**
Set the emails to @param.
The first email address gets the preferred one!
@param list The list of email addresses.
*/
void setEmails( const QStringList& list);
/**
Insert a phone number. If a phone number with the same id already exists
in this addressee it is not duplicated.
*/
void insertPhoneNumber( const PhoneNumber &phoneNumber );
/**
Remove phone number. If no phone number with the given id exists for this
addresse nothing happens.
*/
void removePhoneNumber( const PhoneNumber &phoneNumber );
/**
Return phone number, which matches the given type.
*/
PhoneNumber phoneNumber( int type ) const;
/**
Return list of all phone numbers.
*/
PhoneNumber::List phoneNumbers() const;
/**
Return list of phone numbers with a special type.
*/
PhoneNumber::List phoneNumbers( int type ) const;
/**
Return phone number with the given id.
*/
PhoneNumber findPhoneNumber( const QString &id ) const;
/**
Insert a key. If a key with the same id already exists
in this addressee it is not duplicated.
*/
void insertKey( const Key &key );
/**
Remove a key. If no key with the given id exists for this
addresse nothing happens.
*/
void removeKey( const Key &key );
/**
Return key, which matches the given type.
If @p type == Key::Custom you can specify a string
that should match. If you leave the string empty, the first
key with a custom value is returned.
*/
Key key( int type, QString customTypeString = QString::null ) const;
/**
Return list of all keys.
*/
Key::List keys() const;
/**
Set the list of keys
@param keys The keys to be set.
*/
void setKeys( const Key::List& keys);
/**
Return list of keys with a special type.
If @p type == Key::Custom you can specify a string
that should match. If you leave the string empty, all custom
keys will be returned.
*/
Key::List keys( int type, QString customTypeString = QString::null ) const;
/**
Return key with the given id.
*/
Key findKey( const QString &id ) const;
/**
Insert an address. If an address with the same id already exists
in this addressee it is not duplicated.
*/
void insertAddress( const Address &address );
/**
Remove address. If no address with the given id exists for this
addresse nothing happens.
*/
void removeAddress( const Address &address );
/**
Return address, which matches the given type.
*/
Address address( int type ) const;
/**
Return list of all addresses.
*/
Address::List addresses() const;
/**
Return list of addresses with a special type.
*/
Address::List addresses( int type ) const;
/**
Return address with the given id.
*/
Address findAddress( const QString &id ) const;
/**
Insert category. If the category already exists it is not duplicated.
*/
void insertCategory( const QString & );
/**
Remove category.
*/
void removeCategory( const QString & );
/**
Return, if addressee has the given category.
*/
bool hasCategory( const QString & ) const;
/**
Set categories to given value.
*/
void setCategories( const QStringList & );
/**
Return list of all set categories.
*/
QStringList categories() const;
/**
Insert custom entry. The entry is identified by the name of the inserting
application and a unique name. If an entry with the given app and name
already exists its value is replaced with the new given value.
*/
void insertCustom( const QString &app, const QString &name,
const QString &value );
/**
Remove custom entry.
*/
void removeCustom( const QString &app, const QString &name );
/**
Return value of custom entry, identified by app and entry name.
*/
QString custom( const QString &app, const QString &name ) const;
/**
Set all custom entries.
*/
void setCustoms( const QStringList & );
/**
Return list of all custom entries.
*/
QStringList customs() const;
/**
Parse full email address. The result is given back in fullName and email.
*/
static void parseEmailAddress( const QString &rawEmail, QString &fullName,
QString &email );
/**
Debug output.
*/
void dump() const;
/**
Returns string representation of the addressee.
*/
QString asString() const;
/**
Set resource where the addressee is from.
*/
void setResource( Resource *resource );
/**
Return pointer to resource.
*/
Resource *resource() const;
/**
Return resourcelabel.
*/
//US
static QString resourceLabel();
/**
Mark addressee as changed.
*/
void setChanged( bool value );
/**
Return whether the addressee is changed.
*/
bool changed() const;
private:
Addressee copy();
void detach();
struct AddresseeData;
mutable KSharedPtr<AddresseeData> mData;
};
QDataStream &operator<<( QDataStream &, const Addressee & );
QDataStream &operator>>( QDataStream &, Addressee & );
}
#endif
diff --git a/kabc/field.cpp b/kabc/field.cpp
index e27970e..d95cd19 100644
--- a/kabc/field.cpp
+++ b/kabc/field.cpp
@@ -1,566 +1,572 @@
/*** Warning! This file has been generated by the script makeaddressee ***/
/*
This file is part of libkabc.
Copyright (c) 2002 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 <klocale.h>
#include <kconfig.h>
#include <kconfigbase.h>
#include <kglobal.h>
#include "field.h"
#include "resource.h"
using namespace KABC;
class Field::FieldImpl
{
public:
FieldImpl( int fieldId, int category = 0,
const QString &label = QString::null,
const QString &key = QString::null,
const QString &app = QString::null )
: mFieldId( fieldId ), mCategory( category ), mLabel( label ),
mKey( key ), mApp( app ) {}
enum FieldId
{
CustomField,
FormattedName,
FamilyName,
GivenName,
AdditionalName,
Prefix,
Suffix,
NickName,
Birthday,
HomeAddressStreet,
HomeAddressLocality,
HomeAddressRegion,
HomeAddressPostalCode,
HomeAddressCountry,
HomeAddressLabel,
BusinessAddressStreet,
BusinessAddressLocality,
BusinessAddressRegion,
BusinessAddressPostalCode,
BusinessAddressCountry,
BusinessAddressLabel,
HomePhone,
BusinessPhone,
MobilePhone,
HomeFax,
BusinessFax,
CarPhone,
Isdn,
Pager,
Email,
Mailer,
Title,
Role,
Organization,
Note,
Url,
- Resource
+ Resource,
+ Sip
};
int fieldId() { return mFieldId; }
int category() { return mCategory; }
QString label() { return mLabel; }
QString key() { return mKey; }
QString app() { return mApp; }
private:
int mFieldId;
int mCategory;
QString mLabel;
QString mKey;
QString mApp;
};
Field::List Field::mAllFields;
Field::List Field::mDefaultFields;
Field::List Field::mCustomFields;
Field::Field( FieldImpl *impl )
{
mImpl = impl;
}
Field::~Field()
{
delete mImpl;
}
QString Field::label()
{
switch ( mImpl->fieldId() ) {
case FieldImpl::FormattedName:
return Addressee::formattedNameLabel();
case FieldImpl::FamilyName:
return Addressee::familyNameLabel();
case FieldImpl::GivenName:
return Addressee::givenNameLabel();
case FieldImpl::AdditionalName:
return Addressee::additionalNameLabel();
case FieldImpl::Prefix:
return Addressee::prefixLabel();
case FieldImpl::Suffix:
return Addressee::suffixLabel();
case FieldImpl::NickName:
return Addressee::nickNameLabel();
case FieldImpl::Birthday:
return Addressee::birthdayLabel();
case FieldImpl::HomeAddressStreet:
return Addressee::homeAddressStreetLabel();
case FieldImpl::HomeAddressLocality:
return Addressee::homeAddressLocalityLabel();
case FieldImpl::HomeAddressRegion:
return Addressee::homeAddressRegionLabel();
case FieldImpl::HomeAddressPostalCode:
return Addressee::homeAddressPostalCodeLabel();
case FieldImpl::HomeAddressCountry:
return Addressee::homeAddressCountryLabel();
case FieldImpl::HomeAddressLabel:
return Addressee::homeAddressLabelLabel();
case FieldImpl::BusinessAddressStreet:
return Addressee::businessAddressStreetLabel();
case FieldImpl::BusinessAddressLocality:
return Addressee::businessAddressLocalityLabel();
case FieldImpl::BusinessAddressRegion:
return Addressee::businessAddressRegionLabel();
case FieldImpl::BusinessAddressPostalCode:
return Addressee::businessAddressPostalCodeLabel();
case FieldImpl::BusinessAddressCountry:
return Addressee::businessAddressCountryLabel();
case FieldImpl::BusinessAddressLabel:
return Addressee::businessAddressLabelLabel();
case FieldImpl::HomePhone:
return Addressee::homePhoneLabel();
case FieldImpl::BusinessPhone:
return Addressee::businessPhoneLabel();
case FieldImpl::MobilePhone:
return Addressee::mobilePhoneLabel();
case FieldImpl::HomeFax:
return Addressee::homeFaxLabel();
case FieldImpl::BusinessFax:
return Addressee::businessFaxLabel();
case FieldImpl::CarPhone:
return Addressee::carPhoneLabel();
case FieldImpl::Isdn:
return Addressee::isdnLabel();
case FieldImpl::Pager:
return Addressee::pagerLabel();
case FieldImpl::Email:
return Addressee::emailLabel();
case FieldImpl::Mailer:
return Addressee::mailerLabel();
case FieldImpl::Title:
return Addressee::titleLabel();
case FieldImpl::Role:
return Addressee::roleLabel();
case FieldImpl::Organization:
return Addressee::organizationLabel();
case FieldImpl::Note:
return Addressee::noteLabel();
case FieldImpl::Url:
return Addressee::urlLabel();
case FieldImpl::Resource:
return Addressee::resourceLabel();
+ case FieldImpl::Sip:
+ return Addressee::sipLabel();
case FieldImpl::CustomField:
return mImpl->label();
default:
return i18n("Unknown Field");
}
}
int Field::category()
{
return mImpl->category();
}
QString Field::categoryLabel( int category )
{
switch ( category ) {
case All:
return i18n("All");
case Frequent:
return i18n("Frequent");
case Address:
return i18n("Address");
case Email:
return i18n("Email");
case Personal:
return i18n("Personal");
case Organization:
return i18n("Organization");
case CustomCategory:
return i18n("Custom");
default:
return i18n("Undefined");
}
}
QString Field::value( const KABC::Addressee &a )
{
switch ( mImpl->fieldId() ) {
case FieldImpl::FormattedName:
return a.formattedName();
case FieldImpl::FamilyName:
return a.familyName();
case FieldImpl::GivenName:
return a.givenName();
case FieldImpl::AdditionalName:
return a.additionalName();
case FieldImpl::Prefix:
return a.prefix();
case FieldImpl::Suffix:
return a.suffix();
case FieldImpl::NickName:
return a.nickName();
case FieldImpl::Mailer:
return a.mailer();
case FieldImpl::Title:
return a.title();
case FieldImpl::Role:
return a.role();
case FieldImpl::Organization:
return a.organization();
case FieldImpl::Note:
return a.note();
case FieldImpl::Email:
return a.preferredEmail();
case FieldImpl::Birthday:
if ( a.birthday().isValid() ) {
//the generated code had the following format: return a.birthday().date().toString( Qt::ISODate );
// But Qt::IsoDate was not specified.
// QString _oldFormat = KGlobal::locale()->dateFormat();
// KGlobal::locale()->setDateFormat("%Y-%m-%d"); // = Qt::ISODate
QString dt = KGlobal::locale()->formatDate(a.birthday().date(), false, KLocale::ISODate);
// KGlobal::locale()->setDateFormat(_oldFormat);
return dt;
}
else
return QString::null;
case FieldImpl::Url:
return a.url().prettyURL();
//US
case FieldImpl::Resource:
return a.resource()->resourceName();
case FieldImpl::HomePhone:
return a.phoneNumber( PhoneNumber::Home ).number();
case FieldImpl::BusinessPhone:
return a.phoneNumber( PhoneNumber::Work ).number();
case FieldImpl::MobilePhone:
return a.phoneNumber( PhoneNumber::Cell ).number();
case FieldImpl::HomeFax:
return a.phoneNumber( PhoneNumber::Home | PhoneNumber::Fax ).number();
case FieldImpl::BusinessFax:
return a.phoneNumber( PhoneNumber::Work | PhoneNumber::Fax ).number();
case FieldImpl::CarPhone:
return a.phoneNumber( PhoneNumber::Car ).number();
case FieldImpl::Isdn:
return a.phoneNumber( PhoneNumber::Isdn ).number();
case FieldImpl::Pager:
return a.phoneNumber( PhoneNumber::Pager ).number();
+ case FieldImpl::Sip:
+ return a.phoneNumber( PhoneNumber::Sip ).number();
case FieldImpl::HomeAddressStreet:
return a.address( Address::Home ).street();
case FieldImpl::HomeAddressLocality:
return a.address( Address::Home ).locality();
case FieldImpl::HomeAddressRegion:
return a.address( Address::Home ).region();
case FieldImpl::HomeAddressPostalCode:
return a.address( Address::Home ).postalCode();
case FieldImpl::HomeAddressCountry:
return a.address( Address::Home ).country();
case FieldImpl::BusinessAddressStreet:
return a.address( Address::Work ).street();
case FieldImpl::BusinessAddressLocality:
return a.address( Address::Work ).locality();
case FieldImpl::BusinessAddressRegion:
return a.address( Address::Work ).region();
case FieldImpl::BusinessAddressPostalCode:
return a.address( Address::Work ).postalCode();
case FieldImpl::BusinessAddressCountry:
return a.address( Address::Work ).country();
case FieldImpl::CustomField:
return a.custom( mImpl->app(), mImpl->key() );
default:
return QString::null;
}
}
bool Field::setValue( KABC::Addressee &a, const QString &value )
{
switch ( mImpl->fieldId() ) {
case FieldImpl::FormattedName:
a.setFormattedName( value );
return true;
case FieldImpl::FamilyName:
a.setFamilyName( value );
return true;
case FieldImpl::GivenName:
a.setGivenName( value );
return true;
case FieldImpl::AdditionalName:
a.setAdditionalName( value );
return true;
case FieldImpl::Prefix:
a.setPrefix( value );
return true;
case FieldImpl::Suffix:
a.setSuffix( value );
return true;
case FieldImpl::NickName:
a.setNickName( value );
return true;
case FieldImpl::Mailer:
a.setMailer( value );
return true;
case FieldImpl::Title:
a.setTitle( value );
return true;
case FieldImpl::Role:
a.setRole( value );
return true;
case FieldImpl::Organization:
a.setOrganization( value );
return true;
case FieldImpl::Note:
a.setNote( value );
return true;
case FieldImpl::Birthday:
//US
//the generated code had the following format: return a.setBirthday( QDate::fromString( value, Qt::ISODate ) );
// But Qt::IsoDate and QDate::fromString was not specified. Do I have the wrong QT version ?
{
QDate dt = KGlobal::locale()->readDate( value, "%Y-%m-%d"); // = Qt::ISODate
a.setBirthday(dt);
}
return true;
case FieldImpl::CustomField:
a.insertCustom( mImpl->app(), mImpl->key(), value );
//US never copy the resourcename back to the adressee.
case FieldImpl::Resource:
default:
return false;
}
}
bool Field::isCustom()
{
return mImpl->fieldId() == FieldImpl::CustomField;
}
Field::List Field::allFields()
{
if ( mAllFields.isEmpty() ) {
createField( FieldImpl::FormattedName, Frequent );
createField( FieldImpl::FamilyName, Frequent );
createField( FieldImpl::GivenName, Frequent );
createField( FieldImpl::AdditionalName );
createField( FieldImpl::Prefix );
createField( FieldImpl::Suffix );
createField( FieldImpl::NickName, Personal );
createField( FieldImpl::Birthday, Personal );
createField( FieldImpl::HomeAddressStreet, Address|Personal );
createField( FieldImpl::HomeAddressLocality, Address|Personal );
createField( FieldImpl::HomeAddressRegion, Address|Personal );
createField( FieldImpl::HomeAddressPostalCode, Address|Personal );
createField( FieldImpl::HomeAddressCountry, Address|Personal );
createField( FieldImpl::HomeAddressLabel, Address|Personal );
createField( FieldImpl::BusinessAddressStreet, Address|Organization );
createField( FieldImpl::BusinessAddressLocality, Address|Organization );
createField( FieldImpl::BusinessAddressRegion, Address|Organization );
createField( FieldImpl::BusinessAddressPostalCode, Address|Organization );
createField( FieldImpl::BusinessAddressCountry, Address|Organization );
createField( FieldImpl::BusinessAddressLabel, Address|Organization );
createField( FieldImpl::HomePhone, Personal|Frequent );
createField( FieldImpl::BusinessPhone, Organization|Frequent );
createField( FieldImpl::MobilePhone, Frequent );
createField( FieldImpl::HomeFax );
createField( FieldImpl::BusinessFax );
createField( FieldImpl::CarPhone );
createField( FieldImpl::Isdn );
createField( FieldImpl::Pager );
createField( FieldImpl::Email, Email|Frequent );
createField( FieldImpl::Mailer, Email );
createField( FieldImpl::Title, Organization );
createField( FieldImpl::Role, Organization );
createField( FieldImpl::Organization, Organization );
createField( FieldImpl::Note );
createField( FieldImpl::Url );
createField( FieldImpl::Resource );
+ createField( FieldImpl::Sip );
}
return mAllFields;
}
Field::List Field::defaultFields()
{
if ( mDefaultFields.isEmpty() ) {
createDefaultField( FieldImpl::GivenName );
createDefaultField( FieldImpl::FamilyName );
createDefaultField( FieldImpl::Email );
}
return mDefaultFields;
}
void Field::createField( int id, int category )
{
mAllFields.append( new Field( new FieldImpl( id, category ) ) );
}
void Field::createDefaultField( int id, int category )
{
mDefaultFields.append( new Field( new FieldImpl( id, category ) ) );
}
void Field::deleteFields()
{
Field::List::ConstIterator it;
for( it = mAllFields.begin(); it != mAllFields.end(); ++it ) {
delete (*it);
}
mAllFields.clear();
for( it = mDefaultFields.begin(); it != mDefaultFields.end(); ++it ) {
delete (*it);
}
mDefaultFields.clear();
for( it = mCustomFields.begin(); it != mCustomFields.end(); ++it ) {
delete (*it);
}
mCustomFields.clear();
}
void Field::saveFields( const QString &identifier,
const Field::List &fields )
{
KConfig *cfg = KGlobal::config();
KConfigGroupSaver( cfg, "KABCFields" );
saveFields( cfg, identifier, fields );
}
void Field::saveFields( KConfig *cfg, const QString &identifier,
const Field::List &fields )
{
QValueList<int> fieldIds;
//US
// qDebug("Field::saveFields to %s %s", cfg->getFileName().latin1(), identifier.latin1());
int custom = 0;
Field::List::ConstIterator it;
for( it = fields.begin(); it != fields.end(); ++it ) {
//US
// qDebug("Field::saveFields field:%i", (*it)->mImpl->fieldId());
fieldIds.append( (*it)->mImpl->fieldId() );
if( (*it)->isCustom() ) {
QStringList customEntry;
customEntry << (*it)->mImpl->label();
customEntry << (*it)->mImpl->key();
customEntry << (*it)->mImpl->app();
cfg->writeEntry( "KABC_CustomEntry_" + identifier + "_" +
QString::number( custom++ ), customEntry );
}
}
cfg->writeEntry( identifier, fieldIds );
}
Field::List Field::restoreFields( const QString &identifier )
{
//US
// qDebug("Field::restoreFields, identifier: %s", identifier.latin1());
KConfig *cfg = KGlobal::config();
KConfigGroupSaver( cfg, "KABCFields" );
cfg->setGroup( "KABCFields" );
Field::List l = restoreFields( cfg, identifier );
return l;
}
Field::List Field::restoreFields( KConfig *cfg, const QString &identifier )
{
QValueList<int> fieldIds = cfg->readIntListEntry( identifier);
//US
// qDebug("Field::restoreFields from %s, identifier: %s", cfg->getFileName().latin1(), identifier.latin1());
Field::List fields;
int custom = 0;
QValueList<int>::ConstIterator it;
for( it = fieldIds.begin(); it != fieldIds.end(); ++it ) {
FieldImpl *f = 0;
if ( (*it) == FieldImpl::CustomField ) {
QStringList customEntry = cfg->readListEntry( "KABC_CustomEntry_" +
identifier + "_" +
QString::number( custom++ ) );
f = new FieldImpl( *it, CustomCategory, customEntry[ 0 ],
customEntry[ 1 ], customEntry[ 2 ] );
} else {
f = new FieldImpl( *it );
}
fields.append( new Field( f ) );
}
return fields;
}
bool Field::equals( Field *field )
{
bool sameId = ( mImpl->fieldId() == field->mImpl->fieldId() );
if ( !sameId ) return false;
if ( mImpl->fieldId() != FieldImpl::CustomField ) return true;
return mImpl->key() == field->mImpl->key();
}
Field *Field::createCustomField( const QString &label, int category,
const QString &key, const QString &app )
{
Field *field = new Field( new FieldImpl( FieldImpl::CustomField,
category | CustomCategory,
label, key, app ) );
//US
// qDebug("Field::createCustomField label %s", label.latin1() );
mCustomFields.append( field );
return field;
}
diff --git a/kabc/phonenumber.cpp b/kabc/phonenumber.cpp
index 4ad608d..7aeb2ee 100644
--- a/kabc/phonenumber.cpp
+++ b/kabc/phonenumber.cpp
@@ -1,200 +1,202 @@
/*
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 <kapplication.h>
#include <klocale.h>
#include "phonenumber.h"
using namespace KABC;
PhoneNumber::PhoneNumber() :
mType( Home )
{
init();
}
PhoneNumber::PhoneNumber( const QString &number, int type ) :
mType( type ), mNumber( number )
{
init();
}
PhoneNumber::~PhoneNumber()
{
}
void PhoneNumber::init()
{
mId = KApplication::randomString( 8 );
}
bool PhoneNumber::operator==( const PhoneNumber &p ) const
{
if ( mNumber != p.mNumber ) return false;
if ( mType != p.mType ) return false;
return true;
}
bool PhoneNumber::operator!=( const PhoneNumber &p ) const
{
return !( p == *this );
}
void PhoneNumber::setId( const QString &id )
{
mId = id;
}
QString PhoneNumber::id() const
{
return mId;
}
void PhoneNumber::setNumber( const QString &number )
{
mNumber = number;
}
QString PhoneNumber::number() const
{
return mNumber;
}
void PhoneNumber::setType( int type )
{
mType = type;
}
int PhoneNumber::type() const
{
return mType;
}
QString PhoneNumber::typeLabel() const
{
QString label;
bool first = true;
TypeList list = typeList();
TypeList::Iterator it;
for ( it = list.begin(); it != list.end(); ++it ) {
if ( ( type() & (*it) ) && ( (*it) != Pref ) ) {
label.append( ( first ? "" : "/" ) + typeLabel( *it ) );
if ( first )
first = false;
}
}
return label;
}
QString PhoneNumber::label() const
{
return typeLabel( type() );
}
PhoneNumber::TypeList PhoneNumber::typeList()
{
TypeList list;
list << Home << Work << Msg << Pref << Voice << Fax << Cell << Video
- << Bbs << Modem << Car << Isdn << Pcs << Pager;
+ << Bbs << Modem << Car << Isdn << Pcs << Pager << Sip;
return list;
}
QString PhoneNumber::label( int type )
{
return typeLabel( type );
}
QString PhoneNumber::typeLabel( int type )
{
QString typeString;
if ((type & Home) == Home)
typeString += i18n("Home");
else if ((type & Work) == Work)
typeString += i18n("Work");
if (!typeString.isEmpty())
typeString += " ";
if ((type & Cell) == Cell)
typeString += i18n("Mobile");
else if ((type & Fax) == Fax)
typeString += i18n("Fax");
else if ((type & Msg) == Msg)
typeString += i18n("Messenger");
else if ((type & Voice) == Voice) {
// add nothing in case of the Voice flag
// typeString += i18n("Voice");
}
else if ((type & Video) == Video)
typeString += i18n("Video");
else if ((type & Bbs) == Bbs)
typeString += i18n("Mailbox");
else if ((type & Modem) == Modem)
typeString += i18n("Modem");
else if ((type & Car) == Car)
typeString += i18n("Car");
else if ((type & Isdn) == Isdn)
typeString += i18n("ISDN");
else if ((type & Pcs) == Pcs)
typeString += i18n("PCS");
else if ((type & Pager) == Pager)
typeString += i18n("Pager");
+ else if ((type & Sip) == Sip)
+ typeString += i18n("SIP");
// add the prefered flag
if (!typeString.isEmpty())
typeString += " ";
if ((type & Pref) == Pref)
typeString += i18n("(p)");
//if we still have no match, return "other"
if (typeString.isEmpty())
return i18n("Other");
return typeString;
}
QDataStream &KABC::operator<<( QDataStream &s, const PhoneNumber &phone )
{
return s << phone.mId << phone.mType << phone.mNumber;
}
QDataStream &KABC::operator>>( QDataStream &s, PhoneNumber &phone )
{
s >> phone.mId >> phone.mType >> phone.mNumber;
return s;
}
diff --git a/kabc/phonenumber.h b/kabc/phonenumber.h
index 6a9c8cb..1df344f 100644
--- a/kabc/phonenumber.h
+++ b/kabc/phonenumber.h
@@ -1,165 +1,166 @@
/*
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$
*/
#ifndef KABC_PHONENUMBER_H
#define KABC_PHONENUMBER_H
#include <qvaluelist.h>
#include <qstring.h>
namespace KABC {
/**
@short Phonenumber information.
This class provides phone number information. A phone number is classified by
a type. The following types are available, it's possible to use multiple types
@ref Types for a number by combining them through a logical or.
*/
class PhoneNumber
{
friend QDataStream &operator<<( QDataStream &, const PhoneNumber & );
friend QDataStream &operator>>( QDataStream &, PhoneNumber & );
public:
typedef QValueList<PhoneNumber> List;
typedef QValueList<int> TypeList;
/**
@li @p Home - Home number
@li @p Work - Office number
@li @p Msg - Messaging
@li @p Pref - Preferred number
@li @p Voice - Voice
@li @p Fax - Fax machine
@li @p Cell - Cell phone
@li @p Video - Video phone
@li @p Bbs - Mailbox
@li @p Modem - Modem
@li @p Car - Car phone
@li @p Isdn - ISDN connection
@li @p Pcs - Personal Communication Service
@li @p Pager - Pager
+ @li @p SIP - VoIP
*/
enum Types { Home = 1, Work = 2, Msg = 4, Pref = 8, Voice = 16, Fax = 32,
Cell = 64, Video = 128, Bbs = 256, Modem = 512, Car = 1024,
- Isdn = 2048, Pcs = 4096, Pager = 8192 };
+ Isdn = 2048, Pcs = 4096, Pager = 8192, Sip = 16384 };
/**
Create an empty phone number object.
*/
PhoneNumber();
/**
Create a phonenumber object.
@param number Number
@param type Type as defined in enum. Multiple types can be
specified by combining them by a logical or.
*/
PhoneNumber( const QString &number, int type = Home );
/**
Destructor.
*/
~PhoneNumber();
bool operator==( const PhoneNumber & ) const;
bool operator!=( const PhoneNumber & ) const;
/**
Sets the unique identifier.
*/
void setId( const QString &id );
/**
Returns the unique identifier.
*/
QString id() const;
/**
Sets the number.
*/
void setNumber( const QString & );
/**
Returns the number.
*/
QString number() const;
/**
Sets the type. Multiple types can be specified by combining them by
a logical or.
*/
void setType( int );
/**
Returns the type. Can be a multiple types combined by a logical or.
*/
int type() const;
/**
Returns a translated string of all types the address has.
*/
QString typeLabel() const;
/**
Returns the translated label for phone number depending on its type.
*/
QString label() const;
/**
Returns a list of all available types
*/
static TypeList typeList();
/**
Returns the translated label for phone number type.
*/
static QString typeLabel( int type );
/**
Returns the translated label for phone number type.
@obsolete
*/
static QString label( int type );
private:
void init();
QString mId;
int mType;
QString mNumber;
};
QDataStream &operator<<( QDataStream &, const PhoneNumber & );
QDataStream &operator>>( QDataStream &, PhoneNumber & );
}
#endif
diff --git a/kabc/vcard21parser.cpp b/kabc/vcard21parser.cpp
index b02aac4..277de22 100644
--- a/kabc/vcard21parser.cpp
+++ b/kabc/vcard21parser.cpp
@@ -1,606 +1,609 @@
/*
This file is part of libkabc.
Copyright (c) 2001 Mark Westcott <mark@houseoffish.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 <qmap.h>
#include <qregexp.h>
#include <kmdcodec.h>
#include "vcard21parser.h"
#include "vcardconverter.h"
using namespace KABC;
bool VCardLineX::isValid() const
{
// Invalid: if it is "begin:vcard" or "end:vcard"
if ( name == VCARD_BEGIN_N || name == VCARD_END_N )
return false;
if ( name[0] == 'x' && name[1] == '-' ) // A custom x- line
return true;
// This is long but it makes it a bit faster (and saves me from using
// a tree which is probably the ideal situation, but a bit memory heavy)
switch( name[0] ) {
case 'a':
if ( name == VCARD_ADR && qualified &&
(qualifiers.contains(VCARD_ADR_DOM) ||
qualifiers.contains(VCARD_ADR_INTL) ||
qualifiers.contains(VCARD_ADR_POSTAL) ||
qualifiers.contains(VCARD_ADR_HOME) ||
qualifiers.contains(VCARD_ADR_WORK) ||
qualifiers.contains(VCARD_ADR_PREF)
) )
return true;
if ( name == VCARD_AGENT )
return true;
break;
case 'b':
if ( name == VCARD_BDAY )
return true;
break;
case 'c':
if ( name == VCARD_CATEGORIES )
return true;
if ( name == VCARD_CLASS && qualified &&
(qualifiers.contains(VCARD_CLASS_PUBLIC) ||
qualifiers.contains(VCARD_CLASS_PRIVATE) ||
qualifiers.contains(VCARD_CLASS_CONFIDENTIAL)
) )
return true;
break;
case 'e':
if ( name == VCARD_EMAIL && qualified &&
(qualifiers.contains(VCARD_EMAIL_INTERNET) ||
qualifiers.contains(VCARD_EMAIL_PREF) ||
qualifiers.contains(VCARD_EMAIL_X400)
) )
return true;
break;
case 'f':
if ( name == VCARD_FN )
return true;
break;
case 'g':
if ( name == VCARD_GEO )
return true;
break;
case 'k':
if ( name == VCARD_KEY && qualified &&
(qualifiers.contains(VCARD_KEY_X509) ||
qualifiers.contains(VCARD_KEY_PGP)
) )
return true;
break;
case 'l':
if ( name == VCARD_LABEL )
return true;
if ( name == VCARD_LOGO )
return true;
break;
case 'm':
if ( name == VCARD_MAILER )
return true;
break;
case 'n':
if ( name == VCARD_N )
return true;
if ( name == VCARD_NAME )
return true;
if ( name == VCARD_NICKNAME )
return true;
if ( name == VCARD_NOTE )
return true;
break;
case 'o':
if ( name == VCARD_ORG )
return true;
break;
case 'p':
if ( name == VCARD_PHOTO )
return true;
if ( name == VCARD_PROFILE )
return true;
if ( name == VCARD_PRODID )
return true;
break;
case 'r':
if ( name == VCARD_ROLE )
return true;
if ( name == VCARD_REV )
return true;
break;
case 's':
if ( name == VCARD_SOURCE )
return true;
if ( name == VCARD_SOUND )
return true;
break;
case 't':
if ( name == VCARD_TEL && qualified &&
(qualifiers.contains(VCARD_TEL_HOME) ||
qualifiers.contains(VCARD_TEL_WORK) ||
qualifiers.contains(VCARD_TEL_PREF) ||
qualifiers.contains(VCARD_TEL_VOICE) ||
qualifiers.contains(VCARD_TEL_FAX) ||
qualifiers.contains(VCARD_TEL_MSG) ||
qualifiers.contains(VCARD_TEL_CELL) ||
qualifiers.contains(VCARD_TEL_PAGER) ||
qualifiers.contains(VCARD_TEL_BBS) ||
qualifiers.contains(VCARD_TEL_MODEM) ||
qualifiers.contains(VCARD_TEL_CAR) ||
qualifiers.contains(VCARD_TEL_ISDN) ||
qualifiers.contains(VCARD_TEL_VIDEO) ||
- qualifiers.contains(VCARD_TEL_PCS)
+ qualifiers.contains(VCARD_TEL_PCS) ||
+ qualifiers.contains(VCARD_TEL_SIP)
) )
return true;
if ( name == VCARD_TZ )
return true;
if ( name == VCARD_TITLE )
return true;
break;
case 'u':
if ( name == VCARD_URL )
return true;
if ( name == VCARD_UID )
return true;
break;
case 'v':
if ( name == VCARD_VERSION )
return true;
break;
default:
break;
}
return false;
}
VCard21Parser::VCard21Parser()
{
}
VCard21Parser::~VCard21Parser()
{
}
void VCard21Parser::readFromString(KABC::AddressBook *addressbook, const QString &data)
{
KABC::Addressee mAddressee = readFromString(data);
addressbook->insertAddressee(mAddressee);
}
KABC::Addressee VCard21Parser::readFromString( const QString &data)
{
KABC::Addressee addressee;
VCard21ParserImpl *mVCard = VCard21ParserImpl::parseVCard(data);
QString tmpStr;
// Check if parsing failed
if (mVCard == 0)
{
kdDebug() << "Parsing failed" << endl;
return addressee;
}
//set the addressees name and formated name
QStringList tmpList = mVCard->getValues(VCARD_N);
QString formattedName = "";
if (tmpList.count() > 0)
addressee.setFamilyName(tmpList[0]);
if (tmpList.count() > 1)
addressee.setGivenName(tmpList[1]);
if (tmpList.count() > 2)
addressee.setAdditionalName(tmpList[2]);
if (tmpList.count() > 3)
addressee.setPrefix(tmpList[3]);
if (tmpList.count() > 4)
addressee.setSuffix(tmpList[4]);
tmpStr = (mVCard->getValue(VCARD_FN));
if (!tmpStr.isEmpty())
addressee.setFormattedName(tmpStr);
//set the addressee's nick name
tmpStr = mVCard->getValue(VCARD_NICKNAME);
addressee.setNickName(tmpStr);
//set the addressee's organisation
tmpStr = mVCard->getValue(VCARD_ORG);
addressee.setOrganization(tmpStr);
//set the addressee's title
tmpStr = mVCard->getValue(VCARD_TITLE);
addressee.setTitle(tmpStr);
//set the addressee's email - we can only deal with two. The preferenced one and one other.
tmpStr = mVCard->getValue(VCARD_EMAIL, VCARD_EMAIL_INTERNET);
addressee.insertEmail(tmpStr, false);
tmpStr = mVCard->getValue(VCARD_EMAIL,VCARD_EMAIL_PREF);
addressee.insertEmail(tmpStr, true);
//set the addressee's url
tmpStr = mVCard->getValue(VCARD_URL);
if (tmpStr.isEmpty()) tmpStr = mVCard->getValue(VCARD_URL, VCARD_ADR_WORK);
if (tmpStr.isEmpty()) tmpStr = mVCard->getValue(VCARD_URL, VCARD_ADR_HOME);
if (!tmpStr.isEmpty()) {
addressee.setUrl(KURL(tmpStr));
}
//set the addressee's birthday
tmpStr = mVCard->getValue(VCARD_BDAY);
addressee.setBirthday(VCardStringToDate(tmpStr));
//set the addressee's phone numbers
for ( QValueListIterator<VCardLineX> i = mVCard->_vcdata->begin();i != mVCard->_vcdata->end(); ++i ) {
if ( (*i).name == VCARD_TEL ) {
int type = 0;
if ( (*i).qualified ) {
if ( (*i).qualifiers.contains( VCARD_TEL_HOME ) )
type |= PhoneNumber::Home;
if ( (*i).qualifiers.contains( VCARD_TEL_WORK ) )
type |= PhoneNumber::Work;
if ( (*i).qualifiers.contains( VCARD_TEL_PREF ) )
type |= PhoneNumber::Pref;
// if ( (*i).qualifiers.contains( VCARD_TEL_VOICE ) )
// type |= PhoneNumber::Voice;
if ( (*i).qualifiers.contains( VCARD_TEL_FAX ) )
type |= PhoneNumber::Fax;
if ( (*i).qualifiers.contains( VCARD_TEL_MSG ) )
type |= PhoneNumber::Msg;
if ( (*i).qualifiers.contains( VCARD_TEL_CELL ) )
type |= PhoneNumber::Cell;
if ( (*i).qualifiers.contains( VCARD_TEL_PAGER ) )
type |= PhoneNumber::Pager;
if ( (*i).qualifiers.contains( VCARD_TEL_BBS ) )
type |= PhoneNumber::Bbs;
if ( (*i).qualifiers.contains( VCARD_TEL_MODEM ) )
type |= PhoneNumber::Modem;
if ( (*i).qualifiers.contains( VCARD_TEL_CAR ) )
type |= PhoneNumber::Car;
if ( (*i).qualifiers.contains( VCARD_TEL_ISDN ) )
type |= PhoneNumber::Isdn;
if ( (*i).qualifiers.contains( VCARD_TEL_VIDEO ) )
type |= PhoneNumber::Video;
if ( (*i).qualifiers.contains( VCARD_TEL_PCS ) )
type |= PhoneNumber::Pcs;
+ if ( (*i).qualifiers.contains( VCARD_TEL_SIP ) )
+ type |= PhoneNumber::Sip;
}
addressee.insertPhoneNumber( PhoneNumber( (*i).parameters[ 0 ], type ) );
}
}
//set the addressee's addresses
for ( QValueListIterator<VCardLineX> i = mVCard->_vcdata->begin();i != mVCard->_vcdata->end(); ++i ) {
if ( (*i).name == VCARD_ADR ) {
int type = 0;
if ( (*i).qualified ) {
if ( (*i).qualifiers.contains( VCARD_ADR_DOM ) )
type |= Address::Dom;
if ( (*i).qualifiers.contains( VCARD_ADR_INTL ) )
type |= Address::Intl;
if ( (*i).qualifiers.contains( VCARD_ADR_POSTAL ) )
type |= Address::Postal;
if ( (*i).qualifiers.contains( VCARD_ADR_PARCEL ) )
type |= Address::Parcel;
if ( (*i).qualifiers.contains( VCARD_ADR_HOME ) )
type |= Address::Home;
if ( (*i).qualifiers.contains( VCARD_ADR_WORK ) )
type |= Address::Work;
if ( (*i).qualifiers.contains( VCARD_ADR_PREF ) )
type |= Address::Pref;
}
addressee.insertAddress( readAddressFromQStringList( (*i).parameters, type ) );
}
}
//set the addressee's delivery label
tmpStr = mVCard->getValue(VCARD_LABEL);
if (!tmpStr.isEmpty()) {
qDebug("VCard21Parser::readFromString please verify if replace is correct");
//US tmpStr.replace("\r\n","\n");
tmpStr.replace( QRegExp("\r\n"), "\n" );
Address tmpAddress;
tmpAddress.setLabel(tmpStr);
addressee.insertAddress(tmpAddress);
}
//set the addressee's notes
tmpStr = mVCard->getValue(VCARD_NOTE);
qDebug("VCard21Parser::readFromString please verify if correct");
//US tmpStr.replace("\r\n","\n");
tmpStr.replace( QRegExp("\r\n"), "\n" );
addressee.setNote(tmpStr);
//set the addressee's timezone
tmpStr = mVCard->getValue(VCARD_TZ);
TimeZone tmpZone(tmpStr.toInt());
addressee.setTimeZone(tmpZone);
//set the addressee's geographical position
tmpList = mVCard->getValues(VCARD_GEO);
if (tmpList.count()==2)
{
tmpStr = tmpList[0];
float glat = tmpStr.toFloat();
tmpStr = tmpList[1];
float glong = tmpStr.toFloat();
Geo tmpGeo(glat,glong);
addressee.setGeo(tmpGeo);
}
//set the last revision date
tmpStr = mVCard->getValue(VCARD_REV);
addressee.setRevision(VCardStringToDate(tmpStr));
//set the role of the addressee
tmpStr = mVCard->getValue(VCARD_ROLE);
addressee.setRole(tmpStr);
return addressee;
}
KABC::Address VCard21Parser::readAddressFromQStringList ( const QStringList &data, const int type )
{
KABC::Address mAddress;
mAddress.setType( type );
if ( data.count() > 0 )
mAddress.setPostOfficeBox( data[0] );
if ( data.count() > 1 )
mAddress.setExtended( data[1] );
if ( data.count() > 2 )
mAddress.setStreet( data[2] );
if ( data.count() > 3 )
mAddress.setLocality( data[3] );
if ( data.count() > 4 )
mAddress.setRegion( data[4] );
if ( data.count() > 5 )
mAddress.setPostalCode( data[5] );
if ( data.count() > 6 )
mAddress.setCountry( data[6] );
return mAddress;
}
VCard21ParserImpl *VCard21ParserImpl::parseVCard( const QString& vc, int *err )
{
int _err = 0;
int _state = VC_STATE_BEGIN;
QValueList<VCardLineX> *_vcdata;
QValueList<QString> lines;
_vcdata = new QValueList<VCardLineX>;
lines = QStringList::split( QRegExp( "[\x0d\x0a]" ), vc );
// for each line in the vCard
for ( QStringList::Iterator j = lines.begin(); j != lines.end(); ++j ) {
VCardLineX _vcl;
// take spaces off the end - ugly but necessary hack
for ( int g = (*j).length()-1; g > 0 && (*j)[g].isSpace(); --g )
(*j)[g] = 0;
// first token:
// verify state, update if necessary
if ( _state & VC_STATE_BEGIN) {
if ( !qstricmp( (*j).latin1(), VCARD_BEGIN ) ) {
_state = VC_STATE_BODY;
continue;
} else {
_err = VC_ERR_NO_BEGIN;
break;
}
} else if ( _state & VC_STATE_BODY ) {
if ( !qstricmp( (*j).latin1(), VCARD_END ) ) {
_state |= VC_STATE_END;
break;
}
// split into two tokens
int colon = (*j).find( ':' );
if ( colon < 0 ) {
_err = VC_ERR_INVALID_LINE;
break;
}
QString key = (*j).left( colon );
QString value = (*j).mid( colon + 1 );
// check for qualifiers and
// set name, qualified, qualifier(s)
QStringList keyTokens = QStringList::split( ';', key );
bool qp = false, first_pass = true;
bool b64 = false;
if ( keyTokens.count() > 0 ) {
_vcl.qualified = false;
_vcl.name = keyTokens[ 0 ].lower();
for ( QStringList::Iterator z = keyTokens.begin(); z != keyTokens.end(); ++z ) {
QString zz = (*z).lower();
if ( zz == VCARD_QUOTED_PRINTABLE || zz == VCARD_ENCODING_QUOTED_PRINTABLE ) {
qp = true;
} else if ( zz == VCARD_BASE64 ) {
b64 = true;
} else if ( !first_pass ) {
_vcl.qualified = true;
_vcl.qualifiers.append( zz );
}
first_pass = false;
}
} else {
_err = VC_ERR_INVALID_LINE;
}
if ( _err != 0 )
break;
if ( _vcl.name == VCARD_VERSION )
_state |= VC_STATE_HAVE_VERSION;
if ( _vcl.name == VCARD_N || _vcl.name == VCARD_FN )
_state |= VC_STATE_HAVE_N;
// second token:
// split into tokens by ;
// add to parameters vector
if ( b64 ) {
if ( value.at( value.length() - 1 ) != '=' )
do {
value += *( ++j );
} while ( (*j).at( (*j).length() - 1 ) != '=' );
} else {
if ( qp ) { // join any split lines
while ( value.at( value.length() - 1 ) == '=' ) {
value.remove( value.length() - 1, 1 );
value.append(*( ++j ));
}
}
_vcl.parameters = QStringList::split( ';', value, true );
if ( qp ) { // decode the quoted printable
for ( QStringList::Iterator z = _vcl.parameters.begin(); z != _vcl.parameters.end(); ++z )
*z = KCodecs::quotedPrintableDecode( (*z).latin1() );
}
}
} else {
_err = VC_ERR_INTERNAL;
break;
}
// validate VCardLineX
if ( !_vcl.isValid() ) {
_err = VC_ERR_INVALID_LINE;
break;
}
// add to vector
_vcdata->append( _vcl );
}
// errors to check at the last minute (exit state related)
if ( _err == 0 ) {
if ( !( _state & VC_STATE_END ) ) // we have to have an end!!
_err = VC_ERR_NO_END;
if ( !( _state & VC_STATE_HAVE_N ) || // we have to have the mandatories!
!( _state & VC_STATE_HAVE_VERSION ) )
_err = VC_ERR_MISSING_MANDATORY;
}
// set the error message if we can, and only return an object
// if the vCard was valid.
if ( err )
*err = _err;
if ( _err != 0 ) {
delete _vcdata;
return 0;
}
return new VCard21ParserImpl( _vcdata );
}
VCard21ParserImpl::VCard21ParserImpl(QValueList<VCardLineX> *_vcd) : _vcdata(_vcd)
{
}
QString VCard21ParserImpl::getValue(const QString& name, const QString& qualifier)
{
QString failed;
const QString lowname = name.lower();
const QString lowqualifier = qualifier.lower();
for (QValueListIterator<VCardLineX> i = _vcdata->begin();i != _vcdata->end();++i) {
if ((*i).name == lowname && (*i).qualified && (*i).qualifiers.contains(lowqualifier)) {
if ((*i).parameters.count() > 0)
return (*i).parameters[0];
else return failed;
}
}
return failed;
}
QString VCard21ParserImpl::getValue(const QString& name)
{
QString failed;
const QString lowname = name.lower();
for (QValueListIterator<VCardLineX> i = _vcdata->begin();i != _vcdata->end();++i) {
if ((*i).name == lowname && !(*i).qualified) {
if ((*i).parameters.count() > 0)
return (*i).parameters[0];
else return failed;
}
}
return failed;
}
QStringList VCard21ParserImpl::getValues(const QString& name)
{
const QString lowname = name.lower();
for (QValueListIterator<VCardLineX> i = _vcdata->begin();i != _vcdata->end();++i) {
if ((*i).name == lowname && !(*i).qualified)
return (*i).parameters;
}
// failed.
return QStringList();
}
QStringList VCard21ParserImpl::getValues(const QString& name, const QString& qualifier)
{
const QString lowname = name.lower();
const QString lowqualifier = qualifier.lower();
for (QValueListIterator<VCardLineX> i = _vcdata->begin();i != _vcdata->end();++i) {
if ((*i).name == lowname && (*i).qualified && (*i).qualifiers.contains(lowqualifier))
return (*i).parameters;
}
// failed.
return QStringList();
}
diff --git a/kabc/vcard21parser.h b/kabc/vcard21parser.h
index 24b0eb2..77e69b6 100644
--- a/kabc/vcard21parser.h
+++ b/kabc/vcard21parser.h
@@ -1,225 +1,226 @@
/*
This file is part of libkabc.
Copyright (c) 2002 Mark Westcott <mark@houseoffish.org>
Copyright (c) 2000 George Staikos <staikos@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$
*/
#ifndef KABC_VCARD21FORMAT_H
#define KABC_VCARD21FORMAT_H
#include <qdatetime.h>
#include <kdebug.h>
#include <qregexp.h>
#include <qstring.h>
#include <kurl.h>
#include <qvaluelist.h>
#include "addressee.h"
#include "addressbook.h"
#include "phonenumber.h"
#define VCARD_BEGIN "begin:vcard"
#define VCARD_END "end:vcard"
#define VCARD_BEGIN_N "begin"
#define VCARD_END_N "end"
#define VCARD_VERSION "version"
#define VCARD_FN "fn"
#define VCARD_N "n"
// optional
#define VCARD_NAME "name"
#define VCARD_NICKNAME "nickname"
#define VCARD_PHOTO "photo"
#define VCARD_BDAY "bday"
#define VCARD_ADR "adr"
// types
#define VCARD_ADR_DOM "dom"
#define VCARD_ADR_INTL "intl"
#define VCARD_ADR_POSTAL "postal"
#define VCARD_ADR_PARCEL "parcel"
#define VCARD_ADR_HOME "home"
#define VCARD_ADR_WORK "work"
#define VCARD_ADR_PREF "pref"
// values
#define VCARD_ADR_POBOX "PO Box"
#define VCARD_ADR_EXTADR "Extended Address"
#define VCARD_ADR_STREET "Street"
#define VCARD_ADR_LOCALITY "Locality"
#define VCARD_ADR_REGION "Region"
#define VCARD_ADR_POSTCODE "Postal Code"
#define VCARD_ADR_COUNTRY "Country Name"
#define VCARD_LABEL "label"
#define VCARD_PROFILE "profile"
#define VCARD_SOURCE "source"
#define VCARD_TEL "tel"
// types
#define VCARD_TEL_HOME "home"
#define VCARD_TEL_WORK "work"
#define VCARD_TEL_PREF "pref"
#define VCARD_TEL_VOICE "voice"
#define VCARD_TEL_FAX "fax"
#define VCARD_TEL_MSG "msg"
#define VCARD_TEL_CELL "cell"
#define VCARD_TEL_PAGER "pager"
#define VCARD_TEL_BBS "bbs"
#define VCARD_TEL_MODEM "modem"
#define VCARD_TEL_CAR "car"
#define VCARD_TEL_ISDN "isdn"
#define VCARD_TEL_VIDEO "video"
#define VCARD_TEL_PCS "pcs"
+#define VCARD_TEL_SIP "sip"
#define VCARD_EMAIL "email"
// types
#define VCARD_EMAIL_PREF "pref"
#define VCARD_EMAIL_INTERNET "internet"
#define VCARD_EMAIL_X400 "x400"
#define VCARD_TZ "tz"
#define VCARD_GEO "geo"
#define VCARD_MAILER "mailer"
#define VCARD_TITLE "title"
#define VCARD_ROLE "role"
#define VCARD_LOGO "logo"
#define VCARD_AGENT "agent"
#define VCARD_ORG "org"
#define VCARD_CATEGORIES "categories"
#define VCARD_NOTE "note"
#define VCARD_PRODID "prodid"
#define VCARD_REV "rev"
#define VCARD_SOUND "sound"
#define VCARD_UID "uid"
#define VCARD_URL "url"
#define VCARD_CLASS "class"
#define VCARD_CLASS_PUBLIC "public"
#define VCARD_CLASS_PRIVATE "private"
#define VCARD_CLASS_CONFIDENTIAL "confidential"
#define VCARD_KEY "key"
// types
#define VCARD_KEY_X509 "x509"
#define VCARD_KEY_PGP "pgp"
#define VCARD_QUOTED_PRINTABLE "quoted-printable"
// this one is a temporary hack until we support TYPE=VALUE
#define VCARD_ENCODING_QUOTED_PRINTABLE "encoding=quoted-printable"
#define VCARD_BASE64 "base64"
#define VC_STATE_BEGIN 1
#define VC_STATE_BODY 2
#define VC_STATE_END 4
#define VC_STATE_HAVE_N 8
#define VC_STATE_HAVE_VERSION 16
#define VC_ERR_NO_BEGIN 1
#define VC_ERR_NO_END 2
#define VC_ERR_INVALID_LINE 3
#define VC_ERR_INTERNAL 4
#define VC_ERR_INVALID_NAME 5
#define VC_ERR_MISSING_MANDATORY 6
namespace KABC {
class AddressBook;
class VCard21Parser
{
public:
/**
* Constructor.
*/
VCard21Parser();
/**
* Destructor.
*/
virtual ~VCard21Parser();
/**
* Parses a string in vcard2.1 format and saves the single addressees
* to the address book.
*
* @param ab The address book.
* @param str The vcard string.
*/
void readFromString( KABC::AddressBook *ab, const QString &str );
/**
* FIXME: we need a writeToString method
* QString writeToString (KABC::AddressBook *);
*/
/**
* Parses a string in vcard2.1 format and returns the inherent addressee.
*/
KABC::Addressee readFromString( const QString &data);
/**
* Helper method to store a address.
*
* @param data A string list, that is filled with 'street', 'house number' ...
* @param type The type of the returned address.
*/
static KABC::Address readAddressFromQStringList (const QStringList &data, const int type);
};
}
/**
* @short Helper class
*/
class VCardLineX
{
public:
QString name;
bool qualified;
QValueList<QString> qualifiers;
QValueList<QString> parameters;
bool isValid() const;
};
/**
* @short Helper class
*/
class VCard21ParserImpl
{
friend class VCardLineX;
public:
VCard21ParserImpl() { };
virtual ~VCard21ParserImpl() { };
static VCard21ParserImpl *parseVCard(const QString& vc, int *err = NULL);
QString getValue(const QString& name, const QString& qualifier);
QString getValue(const QString& name);
QStringList getValues(const QString& name, const QString& qualifier);
QStringList getValues(const QString& name);
QValueList<VCardLineX> *_vcdata;
private:
VCard21ParserImpl (QValueList<VCardLineX> *_vcd);
};
#endif
diff --git a/kabc/vcardformatimpl.cpp b/kabc/vcardformatimpl.cpp
index bffaa64..2d6eb3d 100644
--- a/kabc/vcardformatimpl.cpp
+++ b/kabc/vcardformatimpl.cpp
@@ -1,1030 +1,1032 @@
/*
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 <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;
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;
}
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);
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 );
}
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;
for ( it = ab->begin(); it != ab->end(); ++it ) {
if ( (*it).resource() == resource ) {
VCard *v = new VCard;
saveAddressee( (*it), v, false );
(*it).setChanged( false );
vcardlist.append( v );
}
}
vcards.setCardList( vcardlist );
QCString vcardData = vcards.asString();
file->writeBlock( (const char*)vcardData, vcardData.length() );
}
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;
case EntityRevision:
addressee.setRevision( readDateTimeValue( cl ) );
break;
case EntityGeo:
addressee.setGeo( readGeoValue( cl ) );
break;
case EntityTimeZone:
addressee.setTimeZone( readUTCValue( cl ) );
break;
case EntityVersion:
break;
case EntityClass:
addressee.setSecrecy( readClassValue( cl ) );
break;
case EntityKey:
addressee.insertKey( readKeyValue( cl ) );
break;
case EntityPhoto:
addressee.setPhoto( readPictureValue( cl, EntityPhoto, addressee ) );
break;
case EntityLogo:
addressee.setLogo( readPictureValue( cl, EntityLogo, addressee ) );
break;
case EntityAgent:
addressee.setAgent( readAgentValue( cl ) );
break;
case EntitySound:
addressee.setSound( readSoundValue( cl, addressee ) );
break;
default:
kdDebug(5700) << "VCardFormat::load(): Unsupported entity: "
<< int( type ) << ": " << cl->asString() << endl;
break;
}
}
for( cl = contentLines.first(); cl; cl = contentLines.next() ) {
EntityType type = cl->entityType();
if ( type == EntityLabel ) {
int type = readAddressParam( cl );
Address address = addressee.address( type );
if ( address.isEmpty() )
address.setType( type );
address.setLabel( QString::fromUtf8( cl->value()->asString() ) );
addressee.insertAddress( address );
}
}
return true;
}
void VCardFormatImpl::saveAddressee( const Addressee &addressee, VCard *v, bool intern )
{
//US ContentLine cl;
//US QString value;
addTextValue( v, EntityName, addressee.name() );
addTextValue( v, EntityUID, addressee.uid() );
addTextValue( v, EntityFullName, addressee.formattedName() );
QStringList emails = addressee.emails();
QStringList::ConstIterator it4;
for( it4 = emails.begin(); it4 != emails.end(); ++it4 ) {
addTextValue( v, EntityEmail, *it4 );
}
QStringList customs = addressee.customs();
QStringList::ConstIterator it5;
for( it5 = customs.begin(); it5 != customs.end(); ++it5 ) {
addCustomValue( v, *it5 );
}
addTextValue( v, EntityURL, addressee.url().url() );
addNValue( v, addressee );
addTextValue( v, EntityNickname, addressee.nickName() );
addTextValue( v, EntityMailer, addressee.mailer() );
addTextValue( v, EntityTitle, addressee.title() );
addTextValue( v, EntityRole, addressee.role() );
addTextValue( v, EntityOrganisation, addressee.organization() );
addTextValue( v, EntityNote, addressee.note() );
addTextValue( v, EntityProductID, addressee.productId() );
addTextValue( v, EntitySortString, addressee.sortString() );
Address::List addresses = addressee.addresses();
Address::List::ConstIterator it3;
for( it3 = addresses.begin(); it3 != addresses.end(); ++it3 ) {
addAddressValue( v, *it3 );
addLabelValue( v, *it3 );
}
PhoneNumber::List phoneNumbers = addressee.phoneNumbers();
PhoneNumber::List::ConstIterator it2;
for( it2 = phoneNumbers.begin(); it2 != phoneNumbers.end(); ++it2 ) {
addTelephoneValue( v, *it2 );
}
Key::List keys = addressee.keys();
Key::List::ConstIterator it6;
for( it6 = keys.begin(); it6 != keys.end(); ++it6 ) {
addKeyValue( v, *it6 );
}
addTextValue( v, EntityCategories, addressee.categories().join(",") );
addDateValue( v, EntityBirthday, addressee.birthday().date() );
addDateTimeValue( v, EntityRevision, addressee.revision() );
addGeoValue( v, addressee.geo() );
addUTCValue( v, addressee.timeZone() );
addClassValue( v, addressee.secrecy() );
addPictureValue( v, EntityPhoto, addressee.photo(), addressee, intern );
addPictureValue( v, EntityLogo, addressee.logo(), addressee, intern );
addAgentValue( v, addressee.agent() );
addSoundValue( v, addressee.sound(), addressee, intern );
}
void VCardFormatImpl::addCustomValue( VCard *v, const QString &txt )
{
if ( txt.isEmpty() ) return;
ContentLine cl;
cl.setName( "X-" + txt.left( txt.find( ":" ) ).utf8() );
QString value = txt.mid( txt.find( ":" ) + 1 );
if ( value.isEmpty() )
return;
cl.setValue( new TextValue( value.utf8() ) );
v->add(cl);
}
void VCardFormatImpl::addTextValue( VCard *v, EntityType type, const QString &txt )
{
if ( txt.isEmpty() ) return;
ContentLine cl;
cl.setName( EntityTypeToParamName( type ) );
cl.setValue( new TextValue( txt.utf8() ) );
v->add(cl);
}
void VCardFormatImpl::addDateValue( VCard *vcard, EntityType type,
const QDate &date )
{
if ( !date.isValid() ) return;
ContentLine cl;
cl.setName( EntityTypeToParamName( type ) );
DateValue *v = new DateValue( date );
cl.setValue( v );
vcard->add(cl);
}
void VCardFormatImpl::addDateTimeValue( VCard *vcard, EntityType type,
const QDateTime &dateTime )
{
if ( !dateTime.isValid() ) return;
ContentLine cl;
cl.setName( EntityTypeToParamName( type ) );
DateValue *v = new DateValue( dateTime );
cl.setValue( v );
vcard->add(cl);
}
void VCardFormatImpl::addAddressValue( VCard *vcard, const Address &a )
{
if ( a.isEmpty() )
return;
ContentLine cl;
cl.setName( EntityTypeToParamName( EntityAddress ) );
AdrValue *v = new AdrValue;
v->setPOBox( a.postOfficeBox().utf8() );
v->setExtAddress( a.extended().utf8() );
v->setStreet( a.street().utf8() );
v->setLocality( a.locality().utf8() );
v->setRegion( a.region().utf8() );
v->setPostCode( a.postalCode().utf8() );
v->setCountryName( a.country().utf8() );
cl.setValue( v );
addAddressParam( &cl, a.type() );
vcard->add( cl );
}
void VCardFormatImpl::addLabelValue( VCard *vcard, const Address &a )
{
if ( a.label().isEmpty() ) return;
ContentLine cl;
cl.setName( EntityTypeToParamName( EntityLabel ) );
cl.setValue( new TextValue( a.label().utf8() ) );
addAddressParam( &cl, a.type() );
vcard->add( cl );
}
void VCardFormatImpl::addAddressParam( ContentLine *cl, int type )
{
ParamList params;
if ( type & Address::Dom ) params.append( new Param( "TYPE", "dom" ) );
if ( type & Address::Intl ) params.append( new Param( "TYPE", "intl" ) );
if ( type & Address::Parcel ) params.append( new Param( "TYPE", "parcel" ) );
if ( type & Address::Postal ) params.append( new Param( "TYPE", "postal" ) );
if ( type & Address::Work ) params.append( new Param( "TYPE", "work" ) );
if ( type & Address::Home ) params.append( new Param( "TYPE", "home" ) );
if ( type & Address::Pref ) params.append( new Param( "TYPE", "pref" ) );
cl->setParamList( params );
}
void VCardFormatImpl::addGeoValue( VCard *vcard, const Geo &geo )
{
if ( !geo.isValid() ) return;
ContentLine cl;
cl.setName( EntityTypeToParamName( EntityGeo ) );
GeoValue *v = new GeoValue;
v->setLatitude( geo.latitude() );
v->setLongitude( geo.longitude() );
cl.setValue( v );
vcard->add(cl);
}
void VCardFormatImpl::addUTCValue( VCard *vcard, const TimeZone &tz )
{
if ( !tz.isValid() ) return;
ContentLine cl;
cl.setName( EntityTypeToParamName( EntityTimeZone ) );
UTCValue *v = new UTCValue;
v->setPositive( tz.offset() >= 0 );
v->setHour( (tz.offset() / 60) * ( tz.offset() >= 0 ? 1 : -1 ) );
v->setMinute( (tz.offset() % 60) * ( tz.offset() >= 0 ? 1 : -1 ) );
cl.setValue( v );
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().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" ) );
+ if( p.type() & PhoneNumber::Sip ) params.append( new Param( "TYPE", "sip" ) );
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" ) {
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;
+ else if ( tmpStr == "sip" ) type |= PhoneNumber::Sip;
}
}
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 )
{
UTCValue *utcValue = (UTCValue *)cl->value();
if ( utcValue ) {
TimeZone tz;
tz.setOffset(((utcValue->hour()*60)+utcValue->minute())*(utcValue->positive() ? 1 : -1));
return tz;
} else
return TimeZone();
}
Secrecy VCardFormatImpl::readClassValue( ContentLine *cl )
{
ClassValue *classValue = (ClassValue *)cl->value();
if ( classValue ) {
Secrecy secrecy;
switch ( classValue->type() ) {
case ClassValue::Public:
secrecy.setType( Secrecy::Public );
break;
case ClassValue::Private:
secrecy.setType( Secrecy::Private );
break;
case ClassValue::Confidential:
secrecy.setType( Secrecy::Confidential );
break;
}
return secrecy;
} else
return Secrecy();
}
void VCardFormatImpl::addKeyValue( VCARD::VCard *vcard, const Key &key )
{
ContentLine cl;
cl.setName( EntityTypeToParamName( EntityKey ) );
ParamList params;
if ( key.isBinary() ) {
cl.setValue( new TextValue( KCodecs::base64Encode( key.binaryData() ) ) );
params.append( new Param( "ENCODING", "b" ) );
} else {
cl.setValue( new TextValue( key.textData().utf8() ) );
}
switch ( key.type() ) {
case Key::X509:
params.append( new Param( "TYPE", "X509" ) );
break;
case Key::PGP:
params.append( new Param( "TYPE", "PGP" ) );
break;
case Key::Custom:
params.append( new Param( "TYPE", key.customTypeString().utf8() ) );
break;
}
cl.setParamList( params );
vcard->add( cl );
}
Key VCardFormatImpl::readKeyValue( VCARD::ContentLine *cl )
{
Key key;
bool isBinary = false;
TextValue *v = (TextValue *)cl->value();
ParamList params = cl->paramList();
ParamListIterator it( params );
for( ; it.current(); ++it ) {
if ( (*it)->name() == "ENCODING" && (*it)->value() == "b" )
isBinary = true;
if ( (*it)->name() == "TYPE" ) {
if ( (*it)->value().isEmpty() )
continue;
if ( (*it)->value() == "X509" )
key.setType( Key::X509 );
else if ( (*it)->value() == "PGP" )
key.setType( Key::PGP );
else {
key.setType( Key::Custom );
key.setCustomTypeString( QString::fromUtf8( (*it)->value() ) );
}
}
}
if ( isBinary ) {
QByteArray data;
KCodecs::base64Decode( v->asString().stripWhiteSpace(), data );
key.setBinaryData( data );
} else {
key.setTextData( QString::fromUtf8( v->asString() ) );
}
return key;
}
void VCardFormatImpl::addAgentValue( VCARD::VCard *vcard, const Agent &agent )
{
if ( agent.isIntern() && !agent.addressee() )
return;
if ( !agent.isIntern() && agent.url().isEmpty() )
return;
ContentLine cl;
cl.setName( EntityTypeToParamName( EntityAgent ) );
ParamList params;
if ( agent.isIntern() ) {
QString vstr;
Addressee *addr = agent.addressee();
if ( addr ) {
writeToString( (*addr), vstr );
qDebug("VCardFormatImpl::addAgentValue please verify if replace is correct");
/*US
vstr.replace( ":", "\\:" );
vstr.replace( ",", "\\," );
vstr.replace( ";", "\\;" );
vstr.replace( "\r\n", "\\n" );
*/
vstr.replace( QRegExp(":"), "\\:" );
vstr.replace( QRegExp(","), "\\," );
vstr.replace( QRegExp(";"), "\\;" );
vstr.replace( QRegExp("\r\n"), "\\n" );
cl.setValue( new TextValue( vstr.utf8() ) );
} else
return;
} else {
cl.setValue( new TextValue( agent.url().utf8() ) );
params.append( new Param( "VALUE", "uri" ) );
}
cl.setParamList( params );
vcard->add( cl );
}
Agent VCardFormatImpl::readAgentValue( VCARD::ContentLine *cl )
{
Agent agent;
bool isIntern = true;
TextValue *v = (TextValue *)cl->value();
ParamList params = cl->paramList();
ParamListIterator it( params );
for( ; it.current(); ++it ) {
if ( (*it)->name() == "VALUE" && (*it)->value() == "uri" )
isIntern = false;
}
if ( isIntern ) {
QString vstr = QString::fromUtf8( v->asString() );
qDebug("VCardFormatImpl::addAgentValue please verify if replace is correct");
/*US
vstr.replace( "\\n", "\r\n" );
vstr.replace( "\\:", ":" );
vstr.replace( "\\,", "," );
vstr.replace( "\\;", ";" );
*/
vstr.replace( QRegExp("\\n"), "\r\n" );
vstr.replace( QRegExp("\\:"), ":" );
vstr.replace( QRegExp("\\,"), "," );
vstr.replace( QRegExp("\\;"), ";" );
Addressee *addr = new Addressee;
readFromString( vstr, *addr );
agent.setAddressee( addr );
} else {
agent.setUrl( QString::fromUtf8( v->asString() ) );
}
return agent;
}
void VCardFormatImpl::addPictureValue( VCARD::VCard *vcard, VCARD::EntityType type, const Picture &pic, const Addressee &addr, bool intern )
{
ContentLine cl;
cl.setName( EntityTypeToParamName( type ) );
if ( pic.isIntern() && pic.data().isNull() )
return;
if ( !pic.isIntern() && pic.url().isEmpty() )
return;
ParamList params;
if ( pic.isIntern() ) {
QImage img = pic.data();
if ( intern ) { // only for vCard export we really write the data inline
QByteArray data;
QDataStream s( data, IO_WriteOnly );
s.setVersion( 4 ); // to produce valid png files
s << img;
cl.setValue( new TextValue( KCodecs::base64Encode( data ) ) );
} else { // save picture in cache
QString dir;
if ( type == EntityPhoto )
dir = "photos";
if ( type == EntityLogo )
dir = "logos";
img.save( locateLocal( "data", "kabc/" + dir + "/" + addr.uid() ), pic.type().utf8() );
cl.setValue( new TextValue( "<dummy>" ) );
}
params.append( new Param( "ENCODING", "b" ) );
if ( !pic.type().isEmpty() )
params.append( new Param( "TYPE", pic.type().utf8() ) );
} else {
cl.setValue( new TextValue( pic.url().utf8() ) );
params.append( new Param( "VALUE", "uri" ) );
}
cl.setParamList( params );
vcard->add( cl );
}
Picture VCardFormatImpl::readPictureValue( VCARD::ContentLine *cl, VCARD::EntityType type, const Addressee &addr )
{
Picture pic;
bool isInline = false;
QString picType;
TextValue *v = (TextValue *)cl->value();
ParamList params = cl->paramList();
ParamListIterator it( params );
for( ; it.current(); ++it ) {
if ( (*it)->name() == "ENCODING" && (*it)->value() == "b" )
isInline = true;
if ( (*it)->name() == "TYPE" && !(*it)->value().isEmpty() )
picType = QString::fromUtf8( (*it)->value() );
}
if ( isInline ) {
QImage img;
if ( v->asString() == "<dummy>" ) { // no picture inline stored => picture is in cache
QString dir;
if ( type == EntityPhoto )
dir = "photos";
if ( type == EntityLogo )
dir = "logos";
img.load( locateLocal( "data", "kabc/" + dir + "/" + addr.uid() ) );
} else {
QByteArray data;
KCodecs::base64Decode( v->asString(), data );
img.loadFromData( data );
}
pic.setData( img );
pic.setType( picType );
} else {
pic.setUrl( QString::fromUtf8( v->asString() ) );
}
return pic;
}
void VCardFormatImpl::addSoundValue( VCARD::VCard *vcard, const Sound &sound, const Addressee &addr, bool intern )
{
ContentLine cl;
cl.setName( EntityTypeToParamName( EntitySound ) );
if ( sound.isIntern() && sound.data().isNull() )
return;
if ( !sound.isIntern() && sound.url().isEmpty() )
return;
ParamList params;
if ( sound.isIntern() ) {
QByteArray data = sound.data();
if ( intern ) { // only for vCard export we really write the data inline
cl.setValue( new TextValue( KCodecs::base64Encode( data ) ) );
} else { // save sound in cache
QFile file( locateLocal( "data", "kabc/sounds/" + addr.uid() ) );
if ( file.open( IO_WriteOnly ) ) {
file.writeBlock( data );
}
cl.setValue( new TextValue( "<dummy>" ) );
}
params.append( new Param( "ENCODING", "b" ) );
} else {
cl.setValue( new TextValue( sound.url().utf8() ) );
params.append( new Param( "VALUE", "uri" ) );
}
cl.setParamList( params );
vcard->add( cl );
}
Sound VCardFormatImpl::readSoundValue( VCARD::ContentLine *cl, const Addressee &addr )
{
Sound sound;
bool isInline = false;
TextValue *v = (TextValue *)cl->value();
ParamList params = cl->paramList();
ParamListIterator it( params );
for( ; it.current(); ++it ) {
if ( (*it)->name() == "ENCODING" && (*it)->value() == "b" )
isInline = true;
}
if ( isInline ) {
QByteArray data;
if ( v->asString() == "<dummy>" ) { // no sound inline stored => sound is in cache
QFile file( locateLocal( "data", "kabc/sounds/" + addr.uid() ) );
if ( file.open( IO_ReadOnly ) ) {
data = file.readAll();
file.close();
}
} else {
KCodecs::base64Decode( v->asString(), data );
}
sound.setData( data );
} else {
sound.setUrl( QString::fromUtf8( v->asString() ) );
}
return sound;
}
bool VCardFormatImpl::readFromString( const QString &vcard, Addressee &addressee )
{
VCardEntity e( vcard.utf8() );
VCardListIterator it( e.cardList() );
if ( it.current() ) {
//US VCard v(*it.current());
//US loadAddressee( addressee, v );
loadAddressee( addressee, it.current() );
return true;
}
return false;
}
bool VCardFormatImpl::writeToString( const Addressee &addressee, QString &vcard )
{
VCardEntity vcards;
VCardList vcardlist;
vcardlist.setAutoDelete( true );
VCard *v = new VCard;
saveAddressee( addressee, v, true );
vcardlist.append( v );
vcards.setCardList( vcardlist );
vcard = QString::fromUtf8( vcards.asString() );
return true;
}
diff --git a/kabc/vcardparser/vcardtool.cpp b/kabc/vcardparser/vcardtool.cpp
index 71f29d7..3fb212e 100644
--- a/kabc/vcardparser/vcardtool.cpp
+++ b/kabc/vcardparser/vcardtool.cpp
@@ -1,897 +1,898 @@
/*
This file is part of libkabc.
Copyright (c) 2003 Tobias Koenig <tokoe@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 <qdatastream.h>
#include <qstring.h>
#include <qregexp.h>
#include <kmdcodec.h>
#include "agent.h"
#include "key.h"
#include "picture.h"
#include "secrecy.h"
#include "sound.h"
#include "vcardtool.h"
using namespace KABC;
VCardTool::VCardTool()
{
mAddressTypeMap.insert( "dom", Address::Dom );
mAddressTypeMap.insert( "intl", Address::Intl );
mAddressTypeMap.insert( "postal", Address::Postal );
mAddressTypeMap.insert( "parcel", Address::Parcel );
mAddressTypeMap.insert( "home", Address::Home );
mAddressTypeMap.insert( "work", Address::Work );
mAddressTypeMap.insert( "pref", Address::Pref );
mPhoneTypeMap.insert( "HOME", PhoneNumber::Home );
mPhoneTypeMap.insert( "WORK", PhoneNumber::Work );
mPhoneTypeMap.insert( "MSG", PhoneNumber::Msg );
mPhoneTypeMap.insert( "PREF", PhoneNumber::Pref );
mPhoneTypeMap.insert( "VOICE", PhoneNumber::Voice );
mPhoneTypeMap.insert( "FAX", PhoneNumber::Fax );
mPhoneTypeMap.insert( "CELL", PhoneNumber::Cell );
mPhoneTypeMap.insert( "VIDEO", PhoneNumber::Video );
mPhoneTypeMap.insert( "BBS", PhoneNumber::Bbs );
mPhoneTypeMap.insert( "MODEM", PhoneNumber::Modem );
mPhoneTypeMap.insert( "CAR", PhoneNumber::Car );
mPhoneTypeMap.insert( "ISDN", PhoneNumber::Isdn );
mPhoneTypeMap.insert( "PCS", PhoneNumber::Pcs );
mPhoneTypeMap.insert( "PAGER", PhoneNumber::Pager );
+ mPhoneTypeMap.insert( "SIP", PhoneNumber::Sip );
}
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 ( 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();
if ( geo.isValid() ) {
QString str;
str.sprintf( "%.6f;%.6f", geo.latitude(), geo.longitude() );
card.addLine( VCardLine( "GEO", str ) );
}
// KEY
Key::List keys = (*addrIt).keys();
Key::List::ConstIterator keyIt;
for ( keyIt = keys.begin(); keyIt != keys.end(); ++keyIt )
card.addLine( createKey( *keyIt ) );
// LOGO
card.addLine( createPicture( "LOGO", (*addrIt).logo() ) );
// MAILER
card.addLine( VCardLine( "MAILER", (*addrIt).mailer() ) );
// N
QStringList name;
//US using the old implementation instead
//qDebug("VCardTool::createVCards has to be verified");
/*US
name.append( (*addrIt).familyName().replace( ';', "\\;" ) );
name.append( (*addrIt).givenName().replace( ';', "\\;" ) );
name.append( (*addrIt).additionalName().replace( ';', "\\;" ) );
name.append( (*addrIt).prefix().replace( ';', "\\;" ) );
name.append( (*addrIt).suffix().replace( ';', "\\;" ) );
*/
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 ) );
}
vCardList.append( card );
}
return VCardParser::createVCards( vCardList );
}
Addressee::List VCardTool::parseVCards( const QString& vcard )
{
QChar semicolonSep( ';' );
QChar commaSep( ',' );
QString identifier;
Addressee::List addrList;
VCard::List vCardList = VCardParser::parseVCards( vcard );
VCard::List::Iterator cardIt;
for ( cardIt = vCardList.begin(); cardIt != vCardList.end(); ++cardIt ) {
Addressee addr;
QStringList idents = (*cardIt).identifiers();
QStringList::ConstIterator identIt;
for ( identIt = idents.begin(); identIt != idents.end(); ++identIt ) {
VCard card = (*cardIt);
VCardLine::List lines = card.lines( (*identIt) );
VCardLine::List::Iterator lineIt;
// iterate over the lines
for ( lineIt = lines.begin(); lineIt != lines.end(); ++lineIt ) {
QStringList params = (*lineIt).parameterList();
identifier = (*lineIt).identifier().lower();
// ADR
if ( identifier == "adr" ) {
Address address;
QStringList addrParts = splitString( semicolonSep, (*lineIt).value().asString() );
if ( addrParts.count() > 0 )
address.setPostOfficeBox( addrParts[ 0 ] );
if ( addrParts.count() > 1 )
address.setExtended( addrParts[ 1 ] );
if ( addrParts.count() > 2 )
address.setStreet( addrParts[ 2 ].replace ( QRegExp("\\\\n") , "\n") );
if ( addrParts.count() > 3 )
address.setLocality( addrParts[ 3 ] );
if ( addrParts.count() > 4 )
address.setRegion( addrParts[ 4 ] );
if ( addrParts.count() > 5 )
address.setPostalCode( addrParts[ 5 ] );
if ( addrParts.count() > 6 )
address.setCountry( addrParts[ 6 ] );
int type = 0;
QStringList types = (*lineIt).parameters( "type" );
for ( QStringList::Iterator it = types.begin(); it != types.end(); ++it )
type += mAddressTypeMap[ (*it).lower() ];
if ( !type )
type = Address::Home; // default
address.setType( type );
addr.insertAddress( address );
}
// AGENT
if ( identifier == "agent" )
addr.setAgent( parseAgent( *lineIt ) );
// BDAY
if ( identifier == "bday" )
addr.setBirthday( parseDateTime( (*lineIt).value().asString() ) );
// CATEGORIES
if ( identifier == "categories" ) {
QStringList categories = splitString( commaSep, (*lineIt).value().asString() );
addr.setCategories( categories );
}
// CLASS
if ( identifier == "class" )
addr.setSecrecy( parseSecrecy( *lineIt ) );
// EMAIL
if ( identifier == "email" ) {
QStringList types = (*lineIt).parameters( "type" );
addr.insertEmail( (*lineIt).value().asString(), types.contains( "PREF" ) );
}
// FN
if ( identifier == "fn" )
addr.setFormattedName( (*lineIt).value().asString() );
// GEO
if ( identifier == "geo" ) {
Geo geo;
QStringList geoParts = QStringList::split( ';', (*lineIt).value().asString(), true );
geo.setLatitude( geoParts[ 0 ].toFloat() );
geo.setLongitude( geoParts[ 1 ].toFloat() );
addr.setGeo( geo );
}
// KEY
if ( identifier == "key" )
addr.insertKey( parseKey( *lineIt ) );
// LABEL
if ( identifier == "label" ) {
int type = 0;
QStringList types = (*lineIt).parameters( "type" );
for ( QStringList::Iterator it = types.begin(); it != types.end(); ++it )
type += mAddressTypeMap[ (*it).lower() ];
if ( !type )
type = Address::Home;
KABC::Address::List addressList = addr.addresses();
KABC::Address::List::Iterator it;
for ( it = addressList.begin(); it != addressList.end(); ++it ) {
if ( (*it).type() == type ) {
(*it).setLabel( (*lineIt).value().asString() );
addr.insertAddress( *it );
}
}
}
// LOGO
if ( identifier == "logo" )
addr.setLogo( parsePicture( *lineIt ) );
// MAILER
if ( identifier == "mailer" )
addr.setMailer( (*lineIt).value().asString() );
// N
if ( identifier == "n" ) {
QStringList nameParts = splitString( semicolonSep, (*lineIt).value().asString() );
if ( nameParts.count() > 0 )
addr.setFamilyName( nameParts[ 0 ] );
if ( nameParts.count() > 1 )
addr.setGivenName( nameParts[ 1 ] );
if ( nameParts.count() > 2 )
addr.setAdditionalName( nameParts[ 2 ] );
if ( nameParts.count() > 3 )
addr.setPrefix( nameParts[ 3 ] );
if ( nameParts.count() > 4 )
addr.setSuffix( nameParts[ 4 ] );
}
// NICKNAME
if ( identifier == "nickname" )
addr.setNickName( (*lineIt).value().asString() );
// NOTE
if ( identifier == "note" ) {
// #ifdef DESKTOP_VERSION
// addr.setNote( (*lineIt).value().asString() );
// #else
QString note = (*lineIt).value().asString();
if ( ! note.isEmpty() )
addr.setNote( note.replace ( QRegExp("\\\\n") , "\n") );
else
addr.setNote( note );
//#endif
}
// ORGANIZATION
if ( identifier == "org" )
addr.setOrganization( (*lineIt).value().asString() );
// PHOTO
if ( identifier == "photo" )
addr.setPhoto( parsePicture( *lineIt ) );
// PROID
if ( identifier == "prodid" )
addr.setProductId( (*lineIt).value().asString() );
// REV
if ( identifier == "rev" )
addr.setRevision( parseDateTime( (*lineIt).value().asString() ) );
// ROLE
if ( identifier == "role" )
addr.setRole( (*lineIt).value().asString() );
// SORT-STRING
if ( identifier == "sort-string" )
addr.setSortString( (*lineIt).value().asString() );
// SOUND
if ( identifier == "sound" )
addr.setSound( parseSound( *lineIt ) );
// TEL
if ( identifier == "tel" ) {
PhoneNumber phone;
phone.setNumber( (*lineIt).value().asString() );
int type = 0;
QStringList types = (*lineIt).parameters( "type" );
for ( QStringList::Iterator it = types.begin(); it != types.end(); ++it )
type += mPhoneTypeMap[(*it).upper()];
if ( !type )
type = PhoneNumber::Home; // default
phone.setType( type );
addr.insertPhoneNumber( phone );
}
// TITLE
if ( identifier == "title" )
addr.setTitle( (*lineIt).value().asString() );
// TZ
if ( identifier == "tz" ) {
TimeZone tz;
QString date = (*lineIt).value().asString();
int hours = date.mid( 1, 2).toInt();
int minutes = date.mid( 4, 2 ).toInt();
int offset = ( hours * 60 ) + minutes;
offset = offset * ( date[ 0 ] == '+' ? 1 : -1 );
tz.setOffset( offset );
addr.setTimeZone( tz );
}
// UID
if ( identifier == "uid" )
addr.setUid( (*lineIt).value().asString() );
// URL
if ( identifier == "url" )
addr.setUrl( (*lineIt).value().asString() );
// X-
if ( identifier.startsWith( "x-" ) ) {
QString key = (*lineIt).identifier().mid( 2 );
int dash = key.find( "-" );
addr.insertCustom( key.left( dash ), key.mid( dash + 1 ), (*lineIt).value().asString() );
}
}
}
addrList.append( addr );
}
return addrList;
}
QDateTime VCardTool::parseDateTime( const QString &str )
{
QDateTime dateTime;
if ( str.find( '-' ) == -1 ) { // is base format (yyyymmdd)
dateTime.setDate( QDate( str.left( 4 ).toInt(), str.mid( 4, 2 ).toInt(),
str.mid( 6, 2 ).toInt() ) );
if ( str.find( 'T' ) ) // has time information yyyymmddThh:mm:ss
dateTime.setTime( QTime( str.mid( 11, 2 ).toInt(), str.mid( 14, 2 ).toInt(),
str.mid( 17, 2 ).toInt() ) );
} else { // is extended format yyyy-mm-dd
dateTime.setDate( QDate( str.left( 4 ).toInt(), str.mid( 5, 2 ).toInt(),
str.mid( 8, 2 ).toInt() ) );
if ( str.find( 'T' ) ) // has time information yyyy-mm-ddThh:mm:ss
dateTime.setTime( QTime( str.mid( 11, 2 ).toInt(), str.mid( 14, 2 ).toInt(),
str.mid( 17, 2 ).toInt() ) );
}
return dateTime;
}
QString VCardTool::createDateTime( const QDateTime &dateTime )
{
QString str;
if ( dateTime.date().isValid() ) {
str.sprintf( "%4d-%02d-%02d", dateTime.date().year(), dateTime.date().month(),
dateTime.date().day() );
if ( dateTime.time().isValid() ) {
QString tmp;
tmp.sprintf( "T%02d:%02d:%02dZ", dateTime.time().hour(), dateTime.time().minute(),
dateTime.time().second() );
str += tmp;
}
}
return str;
}
Picture VCardTool::parsePicture( const VCardLine &line )
{
Picture pic;
QStringList params = line.parameterList();
if ( params.contains( "encoding" ) ) {
QCString cs(line.value().asCString());
QByteArray input, output;
input = line.value().asCString();
if ( line.parameter( "encoding" ).lower() == "b" )
KCodecs::base64Decode( input, output );
else if ( line.parameter( "encoding" ).lower() == "quoted-printable" )
KCodecs::quotedPrintableDecode( input, output );
qDebug("********** DECODING OKAY ************** (picture)");
pic.setData( QImage(output) );
}
else if ( params.contains( "value" ) ) {
if ( line.parameter( "value" ).lower() == "uri" )
pic.setUrl( line.value().asString() );
}
if ( params.contains( "type" ) )
pic.setType( line.parameter( "type" ) );
return pic;
}
VCardLine VCardTool::createPicture( const QString &identifier, const Picture &pic )
{
// LR fixed
VCardLine line( identifier );
if ( pic.isIntern() ) {
if ( !pic.data().isNull() ) {
#if 0
QByteArray input;
QDataStream s( input, IO_WriteOnly );
s.setVersion( 4 );
s << pic.data();
line.setValue( input );
#else
QCString input;
QDataStream s( input, IO_WriteOnly );
s.setVersion( 4 );
s << pic.data();
//QCString cs(line.value().asCString());
//QImage qi(cs);
line.setValue( input );
#endif
line.addParameter( "encoding", "b" );
line.addParameter( "type", "image/png" );
}
} else if ( !pic.url().isEmpty() ) {
line.setValue( pic.url() );
line.addParameter( "value", "URI" );
}
return line;
}
Sound VCardTool::parseSound( const VCardLine &line )
{
Sound snd;
QStringList params = line.parameterList();
if ( params.contains( "encoding" ) ) {
qDebug("VCardTool::parseSound has to be verified");
//US snd.setData( line.value().asByteArray() );
//US I am not sure if this is correct
QCString cs(line.value().asCString());
snd.setData( cs );
}
else if ( params.contains( "value" ) ) {
if ( line.parameter( "value" ).lower() == "uri" )
snd.setUrl( line.value().asString() );
}
/* TODO: support sound types
if ( params.contains( "type" ) )
snd.setType( line.parameter( "type" ) );
*/
return snd;
}
VCardLine VCardTool::createSound( const Sound &snd )
{
VCardLine line( "SOUND" );
if ( snd.isIntern() ) {
if ( !snd.data().isEmpty() ) {
qDebug("VCardTool::createSound has to be verified");
//US line.setValue( snd.data() );
//US I am not sure if this is correct
QCString cs(snd.data());
line.setValue( cs );
line.addParameter( "encoding", "b" );
// TODO: need to store sound type!!!
}
} else if ( !snd.url().isEmpty() ) {
line.setValue( snd.url() );
line.addParameter( "value", "URI" );
}
return line;
}
Key VCardTool::parseKey( const VCardLine &line )
{
Key key;
QStringList params = line.parameterList();
if ( params.contains( "encoding" ) ) {
qDebug("VCardTool::parseKey has to be verified");
//US key.setBinaryData( line.value().asByteArray() );
//US I am not sure if this is correct
QCString cs( line.value().asCString() );
key.setBinaryData( cs );
}
else
key.setTextData( line.value().asString() );
if ( params.contains( "type" ) ) {
if ( line.parameter( "type" ).lower() == "x509" )
key.setType( Key::X509 );
else if ( line.parameter( "type" ).lower() == "pgp" )
key.setType( Key::PGP );
else {
key.setType( Key::Custom );
key.setCustomTypeString( line.parameter( "type" ) );
}
}
return key;
}
VCardLine VCardTool::createKey( const Key &key )
{
VCardLine line( "KEY" );
if ( key.isBinary() ) {
if ( !key.binaryData().isEmpty() ) {
qDebug("VCardTool::createKey has to be verified");
//US line.setValue( key.binaryData() );
//US I am not sure if this is correct
QCString cs(key.binaryData());
line.setValue( cs );
line.addParameter( "encoding", "b" );
}
} else if ( !key.textData().isEmpty() )
line.setValue( key.textData() );
if ( key.type() == Key::X509 )
line.addParameter( "type", "X509" );
else if ( key.type() == Key::PGP )
line.addParameter( "type", "PGP" );
else if ( key.type() == Key::Custom )
line.addParameter( "type", key.customTypeString() );
return line;
}
Secrecy VCardTool::parseSecrecy( const VCardLine &line )
{
Secrecy secrecy;
if ( line.value().asString().lower() == "public" )
secrecy.setType( Secrecy::Public );
if ( line.value().asString().lower() == "private" )
secrecy.setType( Secrecy::Private );
if ( line.value().asString().lower() == "confidential" )
secrecy.setType( Secrecy::Confidential );
return secrecy;
}
VCardLine VCardTool::createSecrecy( const Secrecy &secrecy )
{
VCardLine line( "CLASS" );
int type = secrecy.type();
if ( type == Secrecy::Public )
line.setValue( "PUBLIC" );
else if ( type == Secrecy::Private )
line.setValue( "PRIVATE" );
else if ( type == Secrecy::Confidential )
line.setValue( "CONFIDENTIAL" );
return line;
}
Agent VCardTool::parseAgent( const VCardLine &line )
{
Agent agent;
QStringList params = line.parameterList();
if ( params.contains( "value" ) ) {
if ( line.parameter( "value" ).lower() == "uri" )
agent.setUrl( line.value().asString() );
} else {
QString str = line.value().asString();
//US using the old implementation instead
qDebug("VCardTool::parseAgent has to be verified");
/*US
str.replace( "\\n", "\r\n" );
str.replace( "\\N", "\r\n" );
str.replace( "\\;", ";" );
str.replace( "\\:", ":" );
str.replace( "\\,", "," );
*/
str.replace( QRegExp("\\n") , "\r\n" );
str.replace( QRegExp("\\N") , "\r\n" );
str.replace( QRegExp("\\;") , ";" );
str.replace( QRegExp("\\:") , ":" );
str.replace( QRegExp("\\,") , "," );
Addressee::List list = parseVCards( str );
if ( list.count() > 0 ) {
Addressee *addr = new Addressee;
*addr = list[ 0 ];
agent.setAddressee( addr );
}
}
return agent;
}
VCardLine VCardTool::createAgent( VCard::Version version, const Agent &agent )
{
VCardLine line( "AGENT" );
if ( agent.isIntern() ) {
if ( agent.addressee() != 0 ) {
Addressee::List list;
list.append( *agent.addressee() );
QString str = createVCards( list, version );
//US using the old implementation instead
qDebug("VCardTool::createAgent has to be verified");
/*US
str.replace( "\r\n", "\\n" );
str.replace( ";", "\\;" );
str.replace( ":", "\\:" );
str.replace( ",", "\\," );
*/
str.replace( QRegExp("\r\n"), "\\n" );
str.replace( QRegExp(";"), "\\;" );
str.replace( QRegExp(":"), "\\:" );
str.replace( QRegExp(","), "\\," );
line.setValue( str );
}
} else if ( !agent.url().isEmpty() ) {
line.setValue( agent.url() );
line.addParameter( "value", "URI" );
}
return line;
}
QStringList VCardTool::splitString( const QChar &sep, const QString &str )
{
QStringList list;
QString value( str );
int start = 0;
int pos = value.find( sep, start );
while ( pos != -1 ) {
if ( value[ pos - 1 ] != '\\' ) {
if ( pos > start && pos <= (int)value.length() )
list << value.mid( start, pos - start );
else
list << QString::null;
start = pos + 1;
pos = value.find( sep, start );
} else {
if ( pos != 0 ) {
value.replace( pos - 1, 2, sep );
pos = value.find( sep, pos );
} else
pos = value.find( sep, pos + 1 );
}
}
int l = value.length() - 1;
if ( value.mid( start, l - start + 1 ).length() > 0 )
list << value.mid( start, l - start + 1 );
else
list << QString::null;
return list;
}