summaryrefslogtreecommitdiffabout
path: root/kabc
authorzautrix <zautrix>2005-10-28 03:24:50 (UTC)
committer zautrix <zautrix>2005-10-28 03:24:50 (UTC)
commitf83a59cf4f9d0cff4111b6f5c88e88e6dc96e79e (patch) (side-by-side diff)
tree969e6cf85499e3b1dcaa4dc24c972b65c906cfa9 /kabc
parentcbda16d4966c7483d20d1b6b5a64c8af367ea732 (diff)
downloadkdepimpi-f83a59cf4f9d0cff4111b6f5c88e88e6dc96e79e.zip
kdepimpi-f83a59cf4f9d0cff4111b6f5c88e88e6dc96e79e.tar.gz
kdepimpi-f83a59cf4f9d0cff4111b6f5c88e88e6dc96e79e.tar.bz2
many new bugs...
Diffstat (limited to 'kabc') (more/less context) (show whitespace changes)
-rw-r--r--kabc/addressee.cpp74
-rw-r--r--kabc/addressee.h2
-rw-r--r--kabc/field.cpp10
-rw-r--r--kabc/phonenumber.cpp110
-rw-r--r--kabc/phonenumber.h5
-rw-r--r--kabc/vcard21parser.cpp12
-rw-r--r--kabc/vcardformatimpl.cpp4
-rw-r--r--kabc/vcardparser/vcardtool.cpp2
8 files changed, 194 insertions, 25 deletions
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp
index 7e1e414..661bdf6 100644
--- a/kabc/addressee.cpp
+++ b/kabc/addressee.cpp
@@ -525,129 +525,181 @@ bool Addressee::containsAdr(const Addressee& ad )
bool found = false;
for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) {
bool found = false;
PhoneNumber::List phoneL = ad.phoneNumbers();
PhoneNumber::List::Iterator phoneItL;
for ( phoneItL = phoneL.begin(); phoneItL != phoneL.end(); ++phoneItL ) {
if ( ( *phoneItL ).number() == ( *phoneIt ).number() ) {
found = true;
break;
}
}
if ( ! found )
return false;
}
return true;
}
void Addressee::simplifyAddresses()
{
Address::List list;
Address::List::Iterator it;
Address::List::Iterator it2;
for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
it2 = it;
++it2;
for( ; it2 != mData->addresses.end(); ++it2 ) {
if ( (*it) == (*it2) ) {
list.append( *it );
break;
}
}
}
for( it = list.begin(); it != list.end(); ++it ) {
removeAddress( (*it) );
}
list.clear();
int max = 2;
if ( mData->url.isValid() )
max = 1;
if ( mData->addresses.count() <= max ) return ;
int count = 0;
for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
if ( count >= max )
list.append( *it );
++count;
}
for( it = list.begin(); it != list.end(); ++it ) {
removeAddress( (*it) );
}
}
// removes all emails but the first
// needed by phone sync
void Addressee::simplifyEmails()
{
if ( mData->emails.count() == 0 ) return ;
QString email = mData->emails.first();
detach();
mData->emails.clear();
mData->emails.append( email );
}
+void Addressee::makePhoneNumbersOLcompatible()
+{
+ KABC::PhoneNumber::List::Iterator phoneIter;
+ KABC::PhoneNumber::List::Iterator phoneIter2;
+ for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
+ ++phoneIter ) {
+ ( *phoneIter ).makeCompat();
+ }
+ int hasHome = hasPhoneNumberType( PhoneNumber::Home | PhoneNumber::Pref );
+ int hasHome2 = hasPhoneNumberType( PhoneNumber::Home );
+ int hasWork = hasPhoneNumberType( PhoneNumber::Work | PhoneNumber::Pref );
+ int hasWork2 = hasPhoneNumberType( PhoneNumber::Work );
+ int hasCell = hasPhoneNumberType( PhoneNumber::Cell );
+ int hasCell2 = hasPhoneNumberType( PhoneNumber::Car );
+ for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
+ ++phoneIter ) {
+ if ( (*phoneIter).type() == PhoneNumber::Home && ! hasHome ) {
+ (*phoneIter).setType( PhoneNumber::Home | PhoneNumber::Pref );
+ ++hasHome;
+ if ( hasHome2 ) --hasHome2;
+ } else if ( ( (*phoneIter).type() == PhoneNumber::Home | PhoneNumber::Pref) && hasHome>1 && !hasHome2 ) {
+ (*phoneIter).setType( PhoneNumber::Home );
+ --hasHome;
+ ++hasHome2;
+ } else if ( (*phoneIter).type() == PhoneNumber::Work && ! hasWork ) {
+ (*phoneIter).setType( PhoneNumber::Work | PhoneNumber::Pref );
+ ++hasWork;
+ if ( hasWork2 ) --hasWork2;
+ } else if ( ( (*phoneIter).type() == PhoneNumber::Work | PhoneNumber::Pref) && hasWork > 1 && ! hasWork2 ) {
+ (*phoneIter).setType( PhoneNumber::Work );
+ --hasWork;
+ ++hasWork2;
+ } else if ( (*phoneIter).type() == PhoneNumber::Cell && hasCell > 1 && !hasCell2) {
+ (*phoneIter).setType( PhoneNumber::Car );
+ ++hasCell2;
+ --hasCell;
+ } else if ( (*phoneIter).type() == PhoneNumber::Car && hasCell2 > 1 && !hasCell) {
+ (*phoneIter).setType( PhoneNumber::Cell );
+ ++hasCell;
+ --hasCell2;
+ } else{
+ phoneIter2 = phoneIter;
+ ++phoneIter2;
+ for ( ; phoneIter2 != mData->phoneNumbers.end();
+ ++phoneIter2 ) {
+ if ( (*phoneIter2).type() == (*phoneIter).type() ) {
+ (*phoneIter2).setType( PhoneNumber::Voice );
+ }
+ }
+ }
+ }
+}
void Addressee::simplifyPhoneNumbers()
{
int max = 4;
int inList = mData->phoneNumbers.count();
KABC::PhoneNumber::List removeNumbers;
KABC::PhoneNumber::List::Iterator phoneIter;
if ( inList > max ) {
// delete non-preferred numbers
for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
++phoneIter ) {
if ( inList > max ) {
if ( ! (( *phoneIter ).type() & PhoneNumber::Pref )) {
removeNumbers.append( ( *phoneIter ) );
--inList;
}
} else
break;
}
for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end();
++phoneIter ) {
removePhoneNumber(( *phoneIter ));
}
// delete preferred numbers
if ( inList > max ) {
for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
++phoneIter ) {
if ( inList > max ) {
removeNumbers.append( ( *phoneIter ) );
--inList;
} else
break;
}
for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end();
++phoneIter ) {
removePhoneNumber(( *phoneIter ));
}
}
}
// remove non-numeric characters
for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
++phoneIter ) {
if ( ! ( *phoneIter ).simplifyNumber() )
removeNumbers.append( ( *phoneIter ) );
}
for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end();
++phoneIter ) {
removePhoneNumber(( *phoneIter ));
}
}
void Addressee::simplifyPhoneNumberTypes()
{
KABC::PhoneNumber::List::Iterator phoneIter;
for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
++phoneIter )
( *phoneIter ).simplifyType();
}
void Addressee::removeID(const QString &prof)
{
detach();
if ( prof.isEmpty() )
mData->mExternalId = ":";
else
mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof);
@@ -936,161 +988,161 @@ QString Addressee::homeAddressRegionLabel()
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");
+ return i18n("Work Phone");
}
QString Addressee::mobilePhoneLabel()
{
return i18n("Mobile Phone");
}
QString Addressee::mobileWorkPhoneLabel()
{
- return i18n("Mobile (work)");
+ return i18n("Mobile2 (work)");
}
QString Addressee::mobileHomePhoneLabel()
{
- return i18n("Mobile (home)");
+ return i18n("Mobile");
}
QString Addressee::homeFaxLabel()
{
- return i18n("Home Fax");
+ return i18n("Fax (Home)");
}
QString Addressee::businessFaxLabel()
{
- return i18n("Business Fax");
+ return i18n("Fax (Work)");
}
QString Addressee::carPhoneLabel()
{
- return i18n("Car Phone");
+ return i18n("Mobile2 (work)");
}
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 )
@@ -1591,128 +1643,138 @@ void Addressee::removeEmail( const QString &email )
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 ( matchBinaryPatternP( (*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;
}
+int Addressee::hasPhoneNumberType( int type )
+{
+ int retval = 0;
+ PhoneNumber::List::ConstIterator it;
+ for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
+ if ( (*it).type() == type )
+ ++retval;
+ }
+ return retval;
+}
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);
}
diff --git a/kabc/addressee.h b/kabc/addressee.h
index d1c07cb..0c488eb 100644
--- a/kabc/addressee.h
+++ b/kabc/addressee.h
@@ -61,128 +61,130 @@ class Resource;
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;
// sync stuff
void setTempSyncStat(int id);
int tempSyncStat() const;
void setIDStr( const QString & );
const QString IDStr() const;
void setID( const QString &, const QString & );
const QString getID( const QString & ) const;
void setCsum( const QString &, const QString & );
const QString getCsum( const QString & ) const ;
void removeID(const QString &);
void computeCsum(const QString &dev);
ulong getCsum4List( const QStringList & attList);
/**
Return, if the address book entry is empty.
*/
bool isEmpty() const;
void setExternalUID( const QString &id );
const QString externalUID() const;
void setOriginalExternalUID( const QString &id );
QString originalExternalUID() const;
void mergeContact( const Addressee& ad, bool isSubSet );
void simplifyEmails();
void simplifyAddresses();
void simplifyPhoneNumbers();
void simplifyPhoneNumberTypes();
+ void makePhoneNumbersOLcompatible();
+ int hasPhoneNumberType( int type );
bool removeVoice();
bool containsAdr(const Addressee& addr );
/**
Set unique identifier.
*/
void setUid( const QString &uid );
/**
Return unique identifier.
*/
const 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;
/**
diff --git a/kabc/field.cpp b/kabc/field.cpp
index fd51026..20885de 100644
--- a/kabc/field.cpp
+++ b/kabc/field.cpp
@@ -228,149 +228,149 @@ QString Field::categoryLabel( int category )
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::Category:
return a.categories().join(",");
case FieldImpl::HomePhone:
- return a.phoneNumber( PhoneNumber::Home ).number();
+ return a.phoneNumber( PhoneNumber::Home| PhoneNumber::Pref ).number();
case FieldImpl::BusinessPhone:
- return a.phoneNumber( PhoneNumber::Work ).number();
+ return a.phoneNumber( PhoneNumber::Work| PhoneNumber::Pref ).number();
case FieldImpl::MobilePhone:
return a.phoneNumber( PhoneNumber::Cell ).number();
case FieldImpl::MobileWorkPhone:
- return a.phoneNumber( PhoneNumber::Cell | PhoneNumber::Work ).number();
+ return a.phoneNumber( PhoneNumber::Car ).number();
case FieldImpl::MobileHomePhone:
- return a.phoneNumber( PhoneNumber::Cell | PhoneNumber::Home ).number();
+ 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();
+ return a.phoneNumber( PhoneNumber::Pcs | PhoneNumber::Pref ).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:
diff --git a/kabc/phonenumber.cpp b/kabc/phonenumber.cpp
index 4c6231d..0d46ba7 100644
--- a/kabc/phonenumber.cpp
+++ b/kabc/phonenumber.cpp
@@ -4,232 +4,340 @@
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::makeCompat()
+{
+ mType = getCompatType( mType );
+}
+int PhoneNumber::getCompatType( int type )
+{
+ if ((type & Cell) == Cell) {
+ if ((type & Work) == Work)
+ return Car;
+ return Cell;
+ }
+ if ((type & Home) == Home) {
+ if ((type & Pref) == Pref)
+ return (Home | Pref);
+ if ((type & Fax) == Fax)
+ return (Home | Fax);
+ return (Home);
+ }
+ if ((type & Work) == Work) {
+ if ((type & Pref) == Pref)
+ return (Work| Pref);
+ if ((type & Fax) == Fax)
+ return (Fax |Work);
+ if ((type & Msg) == Msg) {
+ if ((type & Voice) == Voice)
+ return ( Msg | Voice |Work);
+ return ( Msg | Work);
+ }
+ return Work;
+ }
+ if ((type & Pcs) == Pcs) {
+ if ((type & Pref) == Pref)
+ return Pcs | Pref;
+ return Pcs;
+ }
+ if ((type & Car) == Car)
+ return Car;
+ if ((type & Pager) == Pager)
+ return Pager;
+ if ((type & Isdn) == Isdn)
+ return Isdn;
+ if ((type & Video) == Video)
+ return Video;
+
+ if ((type & Msg) == Msg)
+ return Msg;
+ if ((type & Fax) == Fax)
+ return Fax;
+
+ if ((type & Pref) == Pref)
+ return Pref;
+
+ return Voice;
+
+}
bool PhoneNumber::simplifyNumber()
{
QString Number;
int i;
Number = mNumber.stripWhiteSpace ();
mNumber = "";
for ( i = 0; i < Number.length(); ++i) {
if ( Number.at(i).isDigit() || Number.at(i) == '+'|| Number.at(i) == '*'|| Number.at(i) == '#' )
mNumber += Number.at(i);
}
return ( mNumber.length() > 0 );
}
// make cellphone compatible
void PhoneNumber::simplifyType()
{
if ( mType & Fax ) mType = Fax;
else if ( mType & Cell ) mType = Cell;
else if ( mType & Work ) mType = Work ;
else if ( mType & Home ) mType = Home;
else mType = Pref;
}
bool PhoneNumber::contains( const PhoneNumber &p )
{
PhoneNumber myself;
PhoneNumber other;
myself = *this;
other = p;
myself.simplifyNumber();
other.simplifyNumber();
if ( myself.number() != other.number ())
return false;
myself.simplifyType();
other.simplifyType();
if ( myself.type() == other.type())
return true;
return false;
}
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 << Sip;
+ << Bbs << Modem << Car << Isdn << Pcs << Pager;
return list;
}
QString PhoneNumber::label( int type )
{
return typeLabel( type );
}
QString PhoneNumber::typeLabel( int type )
{
+ if ((type & Cell) == Cell)
+ return i18n("Mobile");
+ if ((type & Home) == Home) {
+ if ((type & Pref) == Pref)
+ return i18n("Home");
+ if ((type & Fax) == Fax)
+ return i18n("Fax (Home)");
+ return i18n("Home2");
+ }
+
+ if ((type & Work) == Work) {
+ if ((type & Pref) == Pref)
+ return i18n("Work");
+ if ((type & Fax) == Fax)
+ return i18n("Fax (Work)");
+ if ((type & Msg) == Msg) {
+ if ((type & Voice) == Voice)
+ return i18n("Assistent");
+ return i18n("Company");
+ }
+ return i18n("Work2");
+ }
+ if ((type & Pcs) == Pcs) {
+ if ((type & Pref) == Pref)
+ return i18n("SIP");
+ return i18n("VoIP");
+ }
+ if ((type & Car) == Car)
+ return i18n("Mobile2 (Work)");
+ if ((type & Pager) == Pager)
+ return i18n("Pager");
+ if ((type & Isdn) == Isdn)
+ return i18n("ISDN");
+ if ((type & Video) == Video)
+ return i18n("Video");
+
+ if ((type & Msg) == Msg)
+ return i18n("Callback");
+ if ((type & Fax) == Fax)
+ return i18n("Fax (Other)");
+
+ if ((type & Pref) == Pref)
+ return i18n("Primary");
+
+
+ return i18n("Other");
+
+
+#if 0
+
+
+
QString typeString;
if ((type & Cell) == Cell)
typeString += i18n("Mobile") +" ";
if ((type & Home) == Home)
typeString += i18n("Home")+" ";
else if ((type & Work) == Work)
typeString += i18n("Work")+" ";
if ((type & Sip) == Sip)
typeString += i18n("SIP")+" ";
if ((type & Car) == Car)
typeString += i18n("Car")+" ";
if ((type & Fax) == Fax)
typeString += i18n("Fax");
else if ((type & Msg) == Msg)
typeString += i18n("Messenger");
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 & Isdn) == Isdn)
typeString += i18n("ISDN");
else if ((type & Pcs) == Pcs)
typeString += i18n("PCS");
else if ((type & Pager) == Pager)
typeString += i18n("Pager");
// add the prefered flag
/*
if ((type & Pref) == Pref)
typeString += i18n("(p)");
*/
//if we still have no match, return "other"
if (typeString.isEmpty()) {
if ((type & Voice) == Voice)
return i18n("Voice");
else
return i18n("Other");
}
return typeString.stripWhiteSpace();
+#endif
}
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 2d4d3e0..b9d6a17 100644
--- a/kabc/phonenumber.h
+++ b/kabc/phonenumber.h
@@ -3,167 +3,168 @@
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, Sip = 16384 };
+ Isdn = 2048, Pcs = 4096, Pager = 8192 };
/**
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;
bool contains( const PhoneNumber &p );
/**
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 );
bool simplifyNumber();
void simplifyType();
+ void makeCompat();
+ int getCompatType( 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 277de22..60d02b8 100644
--- a/kabc/vcard21parser.cpp
+++ b/kabc/vcard21parser.cpp
@@ -109,267 +109,265 @@ bool VCardLineX::isValid() const
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_SIP)
+ qualifiers.contains(VCARD_TEL_PCS)
) )
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_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 ) );
}
}
-
+ addressee.makePhoneNumbersOLcompatible();
//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
diff --git a/kabc/vcardformatimpl.cpp b/kabc/vcardformatimpl.cpp
index ec5ed80..26fd4f0 100644
--- a/kabc/vcardformatimpl.cpp
+++ b/kabc/vcardformatimpl.cpp
@@ -220,129 +220,129 @@ bool VCardFormatImpl::loadAddressee( Addressee& addressee, VCard *v )
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;
qDebug("VCardFormat::load(): Unsupported entity: %i: %s ", int(type), (const char*)cl->asString());
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 );
}
}
-
+ addressee.makePhoneNumbersOLcompatible();
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() );
@@ -534,162 +534,160 @@ int VCardFormatImpl::readAddressParam( ContentLine *cl )
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;
qDebug("No value: %s", (const char*)(cl->asString()));
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() ) {
diff --git a/kabc/vcardparser/vcardtool.cpp b/kabc/vcardparser/vcardtool.cpp
index c3d92b6..204326e 100644
--- a/kabc/vcardparser/vcardtool.cpp
+++ b/kabc/vcardparser/vcardtool.cpp
@@ -515,129 +515,129 @@ Addressee::List VCardTool::parseVCards( const QString& vcard )
addr.setRevision( parseDateTime( (*lineIt).valueString() ) );
// ROLE
else if ( identifier == "role" )
addr.setRole( (*lineIt).valueString() );
// SORT-STRING
else if ( identifier == "sort-string" )
addr.setSortString( (*lineIt).valueString() );
// SOUND
else if ( identifier == "sound" )
addr.setSound( parseSound( *lineIt ) );
// TEL
else if ( identifier == "tel" ) {
PhoneNumber phone;
phone.setNumber( (*lineIt).valueString() );
int type = 0;
const QStringList types = (*lineIt).parameters( "type" );
for ( QStringList::ConstIterator it = types.begin(); it != types.end(); ++it )
type += mPhoneTypeMap[(*it).upper()];
phone.setType( type );
addr.insertPhoneNumber( phone );
}
// TITLE
else if ( identifier == "title" )
addr.setTitle( (*lineIt).valueString() );
// TZ
else if ( identifier == "tz" ) {
TimeZone tz;
const QString date = (*lineIt).valueString();
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
else if ( identifier == "uid" )
addr.setUid( (*lineIt).valueString() );
// URL
else if ( identifier == "url" )
addr.setUrl( KURL( (*lineIt).valueString() ) );
// X-
else if ( identifier.startsWith( "x-" ) ) {
const QString key = (*lineIt).identifier().mid( 2 );
int dash = key.find( "-" );
addr.insertCustom( key.left( dash ), key.mid( dash + 1 ), (*lineIt).valueString() );
}
}
}
-
+ addr.makePhoneNumbersOLcompatible();
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;
const QStringList params = line.parameterList();
if ( params.findIndex( "encoding" ) != -1 ) {
QImage img;
img.loadFromData( line.valueBytes() );
pic.setData( img );
} else if ( params.findIndex( "value" ) != -1 ) {
if ( line.parameter( "value" ).lower() == "uri" )
pic.setUrl( line.valueString() );
}
if ( params.findIndex( "type" ) != -1 )
pic.setType( line.parameter( "type" ) );