summaryrefslogtreecommitdiffabout
path: root/kabc/addressee.cpp
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/addressee.cpp
parentcbda16d4966c7483d20d1b6b5a64c8af367ea732 (diff)
downloadkdepimpi-f83a59cf4f9d0cff4111b6f5c88e88e6dc96e79e.zip
kdepimpi-f83a59cf4f9d0cff4111b6f5c88e88e6dc96e79e.tar.gz
kdepimpi-f83a59cf4f9d0cff4111b6f5c88e88e6dc96e79e.tar.bz2
many new bugs...
Diffstat (limited to 'kabc/addressee.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressee.cpp74
1 files changed, 68 insertions, 6 deletions
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp
index 7e1e414..661bdf6 100644
--- a/kabc/addressee.cpp
+++ b/kabc/addressee.cpp
@@ -461,257 +461,309 @@ void Addressee::mergeContact( const Addressee& ad , bool isSubSet) // = false)
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::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);
}
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;
@@ -872,289 +924,289 @@ 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");
+ 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 )
{
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;
}
@@ -1527,256 +1579,266 @@ QString Addressee::realName() const
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;
QString text;
if ( realName().isEmpty() )
text = e;
else
text = assembledName() + " <" + e + ">";
return text;
}
void Addressee::insertEmail( const QString &email, bool preferred )
{
detach();
QStringList::Iterator it = mData->emails.find( email );
if ( it != mData->emails.end() ) {
if ( !preferred || it == mData->emails.begin() ) return;
mData->emails.remove( it );
mData->emails.prepend( email );
} else {
if ( preferred ) {
mData->emails.prepend( email );
} else {
mData->emails.append( email );
}
}
}
void Addressee::removeEmail( const QString &email )
{
detach();
QStringList::Iterator it = mData->emails.find( email );
if ( it == mData->emails.end() ) return;
mData->emails.remove( it );
}
QString Addressee::preferredEmail() const
{
if ( mData->emails.count() == 0 ) return QString::null;
else return mData->emails.first();
}
QStringList Addressee::emails() const
{
return mData->emails;
}
void Addressee::setEmails( const QStringList& emails ) {
detach();
mData->emails = emails;
}
void Addressee::insertPhoneNumber( const PhoneNumber &phoneNumber )
{
detach();
mData->empty = false;
PhoneNumber::List::Iterator it;
for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
if ( (*it).id() == phoneNumber.id() ) {
*it = phoneNumber;
return;
}
}
mData->phoneNumbers.append( phoneNumber );
}
void Addressee::removePhoneNumber( const PhoneNumber &phoneNumber )
{
detach();
PhoneNumber::List::Iterator it;
for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
if ( (*it).id() == phoneNumber.id() ) {
mData->phoneNumbers.remove( it );
return;
}
}
}
PhoneNumber Addressee::phoneNumber( int type ) const
{
PhoneNumber phoneNumber( "", type );
PhoneNumber::List::ConstIterator it;
for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
if ( 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);
}
} else {
return *it;
}
}
}
return Key( QString(), type );
}
void Addressee::setKeys( const Key::List& list ) {
detach();
mData->keys = list;
}
Key::List Addressee::keys() const
{
return mData->keys;
}
Key::List Addressee::keys( int type, QString customTypeString ) const
{
Key::List list;
Key::List::ConstIterator it;
for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
if ( (*it).type() == type ) {
if ( type == Key::Custom ) {
if ( customTypeString.isEmpty() ) {
list.append(*it);
} else {
if ( (*it).customTypeString() == customTypeString )
list.append(*it);
}
} else {
list.append(*it);
}
}
}
return list;
}
Key Addressee::findKey( const QString &id ) const
{
Key::List::ConstIterator it;
for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
if ( (*it).id() == id ) {
return *it;
}
}
return Key();
}
QString Addressee::asString() const
{
return "Smith, agent Smith...";
}
void Addressee::dump() const
{
return;
#if 0
kdDebug(5700) << "Addressee {" << endl;
kdDebug(5700) << " Uid: '" << uid() << "'" << endl;
kdDebug(5700) << " Name: '" << name() << "'" << endl;