summaryrefslogtreecommitdiffabout
path: root/kabc
Side-by-side diff
Diffstat (limited to 'kabc') (more/less context) (show whitespace changes)
-rw-r--r--kabc/addressee.cpp17
-rw-r--r--kabc/addressee.h3
-rw-r--r--kabc/field.cpp6
3 files changed, 0 insertions, 26 deletions
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp
index 7f592e9..155ce24 100644
--- a/kabc/addressee.cpp
+++ b/kabc/addressee.cpp
@@ -1,1545 +1,1528 @@
/*** 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>
#include <kidmanager.h>
//US
#include <kstandarddirs.h>
#include <libkcal/syncdefines.h>
//US #include "resource.h"
#include "addressee.h"
using namespace KABC;
static bool matchBinaryPattern( int value, int pattern );
static bool matchBinaryPatternA( int value, int pattern );
static bool matchBinaryPatternP( int value, int pattern );
struct Addressee::AddresseeData : public KShared
{
QString uid;
QString name;
QString formattedName;
- QString defaultFormattedName;
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;
QString externalUID;
QString originalExternalUID;
KURL url;
Secrecy secrecy;
Picture logo;
Picture photo;
Sound sound;
Agent agent;
QString mExternalId;
PhoneNumber::List phoneNumbers;
Address::List addresses;
Key::List keys;
QStringList emails;
QStringList categories;
QStringList custom;
int mTempSyncStat;
Resource *resource;
bool empty :1;
bool changed :1;
bool tagged :1;
};
Addressee::Addressee()
{
mData = new AddresseeData;
mData->empty = true;
mData->changed = false;
mData->resource = 0;
mData->mExternalId = ":";
mData->revision = QDateTime ( QDate( 2003,1,1));
mData->mTempSyncStat = SYNC_TEMPSTATE_INITIAL;
}
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;
}
ulong Addressee::getCsum4List( const QStringList & attList)
{
int max = attList.count();
ulong cSum = 0;
int j,k,i;
int add;
for ( i = 0; i < max ; ++i ) {
QString s = attList[i];
if ( ! s.isEmpty() ){
j = s.length();
for ( k = 0; k < j; ++k ) {
int mul = k +1;
add = s[k].unicode ();
if ( k < 16 )
mul = mul * mul;
int ii = i+1;
add = add * mul *ii*ii*ii;
cSum += add;
//qDebug("csum: %d %d %d", i,k,cSum);
}
}
}
//QString dump = attList.join(",");
//qDebug("csum: %d %s", cSum,dump.latin1());
return cSum;
}
void Addressee::computeCsum(const QString &dev)
{
QStringList l;
//if ( !mData->name.isEmpty() ) l.append(mData->name);
//if ( !mData->formattedName.isEmpty() ) l.append(mData->formattedName );
if ( !mData->familyName.isEmpty() ) l.append( mData->familyName );
if ( !mData->givenName.isEmpty() ) l.append(mData->givenName );
if ( !mData->additionalName.isEmpty() ) l.append( mData->additionalName );
if ( !mData->prefix.isEmpty() ) l.append( mData->prefix );
if ( !mData->suffix.isEmpty() ) l.append( mData->suffix );
if ( !mData->nickName.isEmpty() ) l.append( mData->nickName );
if ( mData->birthday.isValid() ) l.append( mData->birthday.toString() );
if ( !mData->mailer.isEmpty() ) l.append( mData->mailer );
if ( mData->timeZone.isValid() ) l.append( mData->timeZone.asString() );
if ( mData->geo.isValid() ) l.append( mData->geo.asString() );
if ( !mData->title .isEmpty() ) l.append( mData->title );
if ( !mData->role.isEmpty() ) l.append( mData->role );
if ( !mData->organization.isEmpty() ) l.append( mData->organization );
if ( !mData->note.isEmpty() ) l.append( mData->note );
if ( !mData->productId.isEmpty() ) l.append(mData->productId );
if ( !mData->sortString.isEmpty() ) l.append( mData->sortString );
if ( mData->secrecy.isValid() ) l.append( mData->secrecy.asString());
if ( !mData->logo.undefined() ) {
if ( !mData->logo.isIntern() )
l.append( mData->logo.url() );
else
l.append( QString::number(mData->logo.data().width()* mData->logo.data().height()));
} else {
l.append( "nologo");
}
if ( !mData->photo.undefined() ) {
if ( !mData->photo.isIntern() )
l.append( mData->photo.url() );
else
l.append( QString::number(mData->photo.data().width()* mData->photo.data().height()));
} else {
l.append( "nophoto");
}
#if 0
if ( !mData->sound.undefined() ) {
if ( !mData->sound.isIntern() )
l.append( mData->sound.url() );
else
l.append( QString(mData->sound.data().with()* mData->sound.data().height()));
} else {
l.append( "nosound");
}
#endif
//if ( !mData->agent.isEmpty() ) l.append( );
if ( mData->url.isValid() )
if ( ! mData->url.path().isEmpty()) l.append( mData->url.path() );
KABC::PhoneNumber::List phoneNumbers;
KABC::PhoneNumber::List::Iterator phoneIter;
QStringList t;
for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
++phoneIter )
t.append( ( *phoneIter ).number()+QString::number( ( *phoneIter ).type() ) );
t.sort();
uint iii;
for ( iii = 0; iii < t.count(); ++iii)
l.append( t[iii] );
t = mData->emails;
t.sort();
for ( iii = 0; iii < t.count(); ++iii)
l.append( t[iii] );
t = mData->categories;
t.sort();
for ( iii = 0; iii < t.count(); ++iii)
l.append( t[iii] );
t = mData->custom;
t.sort();
for ( iii = 0; iii < t.count(); ++iii)
if ( t[iii].left( 25 ) != "KADDRESSBOOK-X-ExternalID" ) {
int find = t[iii].find (':')+1;
//qDebug("lennnn %d %d ", find, t[iii].length());
if ( find < t[iii].length())
l.append( t[iii] );
}
KABC::Address::List::Iterator addressIter;
for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end();
++addressIter ) {
t = (*addressIter).asList();
t.sort();
for ( iii = 0; iii < t.count(); ++iii)
l.append( t[iii] );
}
uint cs = getCsum4List(l);
#if 0
for ( iii = 0; iii < l.count(); ++iii)
qDebug("%d***%s***",iii,l[iii].latin1());
qDebug("CSUM computed %d %s %s", cs,QString::number (cs ).latin1(), uid().latin1() );
#endif
setCsum( dev, QString::number (cs ));
}
void Addressee::mergeContact( const Addressee& ad , bool isSubSet) // = false)
{
// merge all standard non-outlook fields.
//if isSubSet (e.g. mobile phone sync) merge all fields
detach();
if ( isSubSet ) {
if ( mData->name.isEmpty() ) mData->name = ad.mData->name;
if ( mData->formattedName.isEmpty() ) mData->formattedName = ad.mData->formattedName;
if ( mData->familyName.isEmpty() ) mData->familyName = ad.mData->familyName;
if ( mData->givenName.isEmpty() ) mData->givenName = ad.mData->givenName ;
if ( mData->additionalName ) mData->additionalName = ad.mData->additionalName;
if ( mData->prefix.isEmpty() ) mData->prefix = ad.mData->prefix;
if ( mData->suffix.isEmpty() ) mData->suffix = ad.mData->suffix;
if ( mData->title .isEmpty() ) mData->title = ad.mData->title ;
if ( mData->role.isEmpty() ) mData->role = ad.mData->role ;
if ( mData->nickName.isEmpty() ) mData->nickName = ad.mData->nickName;
if ( mData->organization.isEmpty() ) mData->organization = ad.mData->organization ;
if ( mData->note.isEmpty() ) mData->note = ad.mData->note ;
if ( !mData->secrecy.isValid() ) mData->secrecy = ad.mData->secrecy;
if ( ( !mData->url.isValid() && ad.mData->url.isValid() ) ) mData->url = ad.mData->url ;
if ( !mData->birthday.isValid() )
if ( ad.mData->birthday.isValid())
mData->birthday = ad.mData->birthday;
}
if ( mData->mailer.isEmpty() ) mData->mailer = ad.mData->mailer;
if ( !mData->timeZone.isValid() ) mData->timeZone = ad.mData->timeZone;
if ( !mData->geo.isValid() ) mData->geo = ad.mData->geo;
if ( mData->productId.isEmpty() ) mData->productId = ad.mData->productId;
if ( mData->sortString.isEmpty() ) mData->sortString = ad.mData->sortString;
QStringList t;
QStringList tAD;
uint iii;
// ********** phone numbers
if ( isSubSet ) {
PhoneNumber::List phoneAD = ad.phoneNumbers();
PhoneNumber::List::Iterator phoneItAD;
for ( phoneItAD = phoneAD.begin(); phoneItAD != phoneAD.end(); ++phoneItAD ) {
bool found = false;
PhoneNumber::List::Iterator it;
for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
if ( ( *phoneItAD ).contains( (*it) ) ) {
found = true;
(*it).setType( ( *phoneItAD ).type() );
(*it).setNumber( ( *phoneItAD ).number() );
break;
}
}
// if ( isSubSet && ! found )
if ( ! found ) // LR try this one...
mData->phoneNumbers.append( *phoneItAD );
}
} else {
PhoneNumber::List phoneAD = ad.phoneNumbers();
PhoneNumber::List::Iterator phoneItAD;
for ( phoneItAD = phoneAD.begin(); phoneItAD != phoneAD.end(); ++phoneItAD ) {
bool found = false;
PhoneNumber::List::Iterator it;
for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
if ( ( *phoneItAD ).contains( (*it) ) ) {
found = true;
(*it).setType( ( *phoneItAD ).type() );
(*it).setNumber( ( *phoneItAD ).number() );
break;
}
}
if ( ! found ) { // append numbers which do not have work or home type
if ( ! ( ( *phoneItAD ).type() & (PhoneNumber::Work | PhoneNumber::Home) ) )
mData->phoneNumbers.append( *phoneItAD );
}
}
}
if ( isSubSet ) {
// ************* emails;
t = mData->emails;
tAD = ad.mData->emails;
for ( iii = 0; iii < tAD.count(); ++iii)
if ( !t.contains(tAD[iii] ) )
mData->emails.append( tAD[iii] );
}
// ************* categories;
if ( isSubSet ) {
t = mData->categories;
tAD = ad.mData->categories;
for ( iii = 0; iii < tAD.count(); ++iii)
if ( !t.contains(tAD[iii] ) )
mData->categories.append( tAD[iii] );
}
QStringList::ConstIterator it;
for( it = ad.mData->custom.begin(); it != ad.mData->custom.end(); ++it ) {
QString qualifiedName = (*it).left( (*it).find( ":" ));
bool found = false;
QStringList::ConstIterator itL;
for( itL = mData->custom.begin(); itL != mData->custom.end(); ++itL ) {
if ( (*itL).startsWith( qualifiedName ) ) {
found = true;
break;
}
}
if ( ! found ) {
mData->custom.append( *it );
}
}
if ( mData->logo.undefined() && !ad.mData->logo.undefined() ) mData->logo = ad.mData->logo;
if ( mData->photo.undefined() && !ad.mData->photo.undefined() ) mData->photo = ad.mData->photo;
if ( !mData->sound.isIntern() ) {
if ( mData->sound.url().isEmpty() ) {
mData->sound = ad.mData->sound;
}
}
if ( !mData->agent.isIntern() ) {
if ( mData->agent.url().isEmpty() ) {
mData->agent = ad.mData->agent;
}
}
{
Key::List::Iterator itA;
for( itA = ad.mData->keys.begin(); itA != ad.mData->keys.end(); ++itA ) {
bool found = false;
Key::List::Iterator it;
for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
if ( (*it) == (*itA)) {
found = true;
break;
}
}
if ( ! found ) {
mData->keys.append( *itA );
}
}
}
if ( isSubSet ) {
KABC::Address::List::Iterator addressIterA;
for ( addressIterA = ad.mData->addresses.begin(); addressIterA != ad.mData->addresses.end(); ++addressIterA ) {
bool found = false;
KABC::Address::List::Iterator addressIter;
for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end();
++addressIter ) {
if ( (*addressIter) == (*addressIterA)) {
found = true;
(*addressIter).setType( (*addressIterA).type() );
break;
}
}
if ( isSubSet && ! found ) {
mData->addresses.append( *addressIterA );
}
}
}
//qDebug("merge contact %s ", ad.uid().latin1());
setUid( ad.uid() );
setRevision( ad.revision() );
}
bool Addressee::removeVoice()
{
PhoneNumber::List phoneN = phoneNumbers();
PhoneNumber::List::Iterator phoneIt;
bool found = false;
for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) {
if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found
if ((*phoneIt).type() - PhoneNumber::Voice ) {
(*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice );
insertPhoneNumber( (*phoneIt) );
found = true;
}
}
}
return found;
}
bool Addressee::containsAdr(const Addressee& ad )
{
if ( ! ad.mData->familyName.isEmpty() ) if ( mData->familyName != ad.mData->familyName) return false;
if ( ! ad.mData->givenName.isEmpty() )if ( mData->givenName != ad.mData->givenName ) return false;
if ( ad.mData->url.isValid() ) if (mData->url != ad.mData->url) return false ;
if ( ! ad.mData->role.isEmpty() ) if (mData->role != ad.mData->role) return false ;
if ( ! ad.mData->organization.isEmpty() ) if (mData->organization != ad.mData->organization) return false ;
if ( ! ad.mData->note.isEmpty() ) if (mData->note != ad.mData->note) return false ;
if ( ! ad.mData->title .isEmpty() ) if (mData->title != ad.mData->title ) return false ;
// compare phone numbers
PhoneNumber::List phoneN = ad.phoneNumbers();
PhoneNumber::List::Iterator phoneIt;
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::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);
}
void Addressee::setID( const QString & prof , const QString & id )
{
detach();
mData->mExternalId = KIdManager::setId ( mData->mExternalId, prof, id );
//qDebug("setID2 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() );
}
void Addressee::setTempSyncStat( int id )
{
if ( mData->mTempSyncStat == id ) return;
detach();
mData->mTempSyncStat = id;
}
int Addressee::tempSyncStat() const
{
return mData->mTempSyncStat;
}
const QString Addressee::getID( const QString & prof) const
{
return KIdManager::getId ( mData->mExternalId, prof );
}
void Addressee::setCsum( const QString & prof , const QString & id )
{
detach();
//qDebug("setcsum1 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() );
mData->mExternalId = KIdManager::setCsum ( mData->mExternalId, prof, id );
//qDebug("setcsum2 %s ",mData->mExternalId.latin1() );
}
const QString Addressee::getCsum( const QString & prof) const
{
return KIdManager::getCsum ( mData->mExternalId, prof );
}
void Addressee::setIDStr( const QString & s )
{
detach();
mData->mExternalId = s;
}
const QString Addressee::IDStr() const
{
return mData->mExternalId;
}
void Addressee::setExternalUID( const QString &id )
{
if ( id == mData->externalUID ) return;
detach();
mData->empty = false;
mData->externalUID = id;
}
const QString Addressee::externalUID() const
{
return mData->externalUID;
}
void Addressee::setOriginalExternalUID( const QString &id )
{
if ( id == mData->originalExternalUID ) return;
detach();
mData->empty = false;
//qDebug("*******Set orig uid %s ", id.latin1());
mData->originalExternalUID = id;
}
QString Addressee::originalExternalUID() const
{
return mData->originalExternalUID;
}
void Addressee::setUid( const QString &id )
{
if ( id == mData->uid ) return;
detach();
//qDebug("****setuid %s ", id.latin1());
mData->empty = false;
mData->uid = id;
}
const 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;
}
-void Addressee::setDefaultFormattedName( const QString &formattedName )
-{
- if ( formattedName == mData->defaultFormattedName ) return;
- detach();
- mData->empty = false;
- mData->defaultFormattedName = formattedName;
-}
QString Addressee::formattedName() const
{
return mData->formattedName;
}
-QString Addressee::defaultFormattedName() const
-{
- return mData->defaultFormattedName;
-}
QString Addressee::formattedNameLabel()
{
return i18n("Formatted Name");
}
-QString Addressee::defaultFormattedNameLabel()
-{
- return i18n("Def.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::mobileWorkPhoneLabel()
{
return i18n("Mobile (work)");
}
QString Addressee::mobileHomePhoneLabel()
{
return i18n("Mobile (home)");
}
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 = QDateTime( revision.date(),
QTime (revision.time().hour(),
revision.time().minute(),
revision.time().second()));
}
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 );
static bool first = true;
static QStringList titles;
static QStringList suffixes;
static QStringList prefixes;
if ( first ) {
first = false;
titles += i18n( "Dr." );
titles += i18n( "Miss" );
titles += i18n( "Mr." );
titles += i18n( "Mrs." );
titles += i18n( "Ms." );
titles += i18n( "Prof." );
suffixes += i18n( "I" );
suffixes += i18n( "II" );
suffixes += i18n( "III" );
suffixes += i18n( "Jr." );
suffixes += i18n( "Sr." );
prefixes += "van";
prefixes += "von";
prefixes += "de";
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();
if ( n.isEmpty() )
n = organization();
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;
diff --git a/kabc/addressee.h b/kabc/addressee.h
index 0d688f8..a2fbcf5 100644
--- a/kabc/addressee.h
+++ b/kabc/addressee.h
@@ -1,858 +1,855 @@
/*** 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;
// 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();
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 );
- void setDefaultFormattedName( const QString &formattedName );
/**
Return formatted name.
*/
QString formattedName() const;
- QString defaultFormattedName() const;
/**
Return translated label for formattedName field.
*/
static QString formattedNameLabel();
- static QString defaultFormattedNameLabel();
/**
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();
static QString mobileWorkPhoneLabel();
static QString mobileHomePhoneLabel();
/**
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();
static QString categoryLabel();
/**
Mark addressee as changed.
*/
void setChanged( bool value );
/**
Return whether the addressee is changed.
*/
bool changed() const;
void setTagged( bool value );
bool tagged() 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 5c561c3..fd51026 100644
--- a/kabc/field.cpp
+++ b/kabc/field.cpp
@@ -1,596 +1,590 @@
/*** 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,
Category,
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,
Sip,
- DefaultFormattedName,
MobileWorkPhone,
MobileHomePhone
};
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::DefaultFormattedName:
- return Addressee::defaultFormattedNameLabel();
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::MobileHomePhone:
return Addressee::mobileHomePhoneLabel();
case FieldImpl::MobileWorkPhone:
return Addressee::mobileWorkPhoneLabel();
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::Category:
return Addressee::categoryLabel();
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::DefaultFormattedName:
- return a.defaultFormattedName();
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();
case FieldImpl::BusinessPhone:
return a.phoneNumber( PhoneNumber::Work ).number();
case FieldImpl::MobilePhone:
return a.phoneNumber( PhoneNumber::Cell ).number();
case FieldImpl::MobileWorkPhone:
return a.phoneNumber( PhoneNumber::Cell | PhoneNumber::Work ).number();
case FieldImpl::MobileHomePhone:
return a.phoneNumber( PhoneNumber::Cell | PhoneNumber::Home ).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::DefaultFormattedName, 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::Category );
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::MobileHomePhone, Frequent );
createField( FieldImpl::MobileWorkPhone, 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;
}