-rw-r--r-- | kabc/addressee.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp index 5cb194a..d484073 100644 --- a/kabc/addressee.cpp +++ b/kabc/addressee.cpp @@ -998,619 +998,625 @@ void Addressee::insertEmail( const QString &email, bool preferred ) if ( preferred ) { mData->emails.prepend( email ); } else { mData->emails.append( email ); } } } void Addressee::removeEmail( const QString &email ) { detach(); QStringList::Iterator it = mData->emails.find( email ); if ( it == mData->emails.end() ) return; mData->emails.remove( it ); } QString Addressee::preferredEmail() const { if ( mData->emails.count() == 0 ) return QString::null; else return mData->emails.first(); } QStringList Addressee::emails() const { return mData->emails; } void Addressee::setEmails( const QStringList& emails ) { detach(); mData->emails = emails; } void Addressee::insertPhoneNumber( const PhoneNumber &phoneNumber ) { detach(); mData->empty = false; PhoneNumber::List::Iterator it; for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { if ( (*it).id() == phoneNumber.id() ) { *it = phoneNumber; return; } } mData->phoneNumbers.append( phoneNumber ); } void Addressee::removePhoneNumber( const PhoneNumber &phoneNumber ) { detach(); PhoneNumber::List::Iterator it; for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { if ( (*it).id() == phoneNumber.id() ) { mData->phoneNumbers.remove( it ); return; } } } PhoneNumber Addressee::phoneNumber( int type ) const { PhoneNumber phoneNumber( "", type ); PhoneNumber::List::ConstIterator it; for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { if ( matchBinaryPattern( (*it).type(), type ) ) { if ( (*it).type() & PhoneNumber::Pref ) return (*it); else if ( phoneNumber.number().isEmpty() ) phoneNumber = (*it); } } return phoneNumber; } PhoneNumber::List Addressee::phoneNumbers() const { return mData->phoneNumbers; } PhoneNumber::List Addressee::phoneNumbers( int type ) const { PhoneNumber::List list; PhoneNumber::List::ConstIterator it; for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { if ( matchBinaryPattern( (*it).type(), type ) ) { list.append( *it ); } } return list; } PhoneNumber Addressee::findPhoneNumber( const QString &id ) const { PhoneNumber::List::ConstIterator it; for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { if ( (*it).id() == id ) { return *it; } } return PhoneNumber(); } void Addressee::insertKey( const Key &key ) { detach(); mData->empty = false; Key::List::Iterator it; for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { if ( (*it).id() == key.id() ) { *it = key; return; } } mData->keys.append( key ); } void Addressee::removeKey( const Key &key ) { detach(); Key::List::Iterator it; for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { if ( (*it).id() == key.id() ) { mData->keys.remove( key ); return; } } } Key Addressee::key( int type, QString customTypeString ) const { Key::List::ConstIterator it; for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { if ( (*it).type() == type ) { if ( type == Key::Custom ) { if ( customTypeString.isEmpty() ) { return *it; } else { if ( (*it).customTypeString() == customTypeString ) return (*it); } } else { return *it; } } } return Key( QString(), type ); } void Addressee::setKeys( const Key::List& list ) { detach(); mData->keys = list; } Key::List Addressee::keys() const { return mData->keys; } Key::List Addressee::keys( int type, QString customTypeString ) const { Key::List list; Key::List::ConstIterator it; for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { if ( (*it).type() == type ) { if ( type == Key::Custom ) { if ( customTypeString.isEmpty() ) { list.append(*it); } else { if ( (*it).customTypeString() == customTypeString ) list.append(*it); } } else { list.append(*it); } } } return list; } Key Addressee::findKey( const QString &id ) const { Key::List::ConstIterator it; for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { if ( (*it).id() == id ) { return *it; } } return Key(); } QString Addressee::asString() const { return "Smith, agent Smith..."; } void Addressee::dump() const { return; kdDebug(5700) << "Addressee {" << endl; kdDebug(5700) << " Uid: '" << uid() << "'" << endl; kdDebug(5700) << " Name: '" << name() << "'" << endl; kdDebug(5700) << " FormattedName: '" << formattedName() << "'" << endl; kdDebug(5700) << " FamilyName: '" << familyName() << "'" << endl; kdDebug(5700) << " GivenName: '" << givenName() << "'" << endl; kdDebug(5700) << " AdditionalName: '" << additionalName() << "'" << endl; kdDebug(5700) << " Prefix: '" << prefix() << "'" << endl; kdDebug(5700) << " Suffix: '" << suffix() << "'" << endl; kdDebug(5700) << " NickName: '" << nickName() << "'" << endl; kdDebug(5700) << " Birthday: '" << birthday().toString() << "'" << endl; kdDebug(5700) << " Mailer: '" << mailer() << "'" << endl; kdDebug(5700) << " TimeZone: '" << timeZone().asString() << "'" << endl; kdDebug(5700) << " Geo: '" << geo().asString() << "'" << endl; kdDebug(5700) << " Title: '" << title() << "'" << endl; kdDebug(5700) << " Role: '" << role() << "'" << endl; kdDebug(5700) << " Organization: '" << organization() << "'" << endl; kdDebug(5700) << " Note: '" << note() << "'" << endl; kdDebug(5700) << " ProductId: '" << productId() << "'" << endl; kdDebug(5700) << " Revision: '" << revision().toString() << "'" << endl; kdDebug(5700) << " SortString: '" << sortString() << "'" << endl; kdDebug(5700) << " Url: '" << url().url() << "'" << endl; kdDebug(5700) << " Secrecy: '" << secrecy().asString() << "'" << endl; kdDebug(5700) << " Logo: '" << logo().asString() << "'" << endl; kdDebug(5700) << " Photo: '" << photo().asString() << "'" << endl; kdDebug(5700) << " Sound: '" << sound().asString() << "'" << endl; kdDebug(5700) << " Agent: '" << agent().asString() << "'" << endl; kdDebug(5700) << " Emails {" << endl; QStringList e = emails(); QStringList::ConstIterator it; for( it = e.begin(); it != e.end(); ++it ) { kdDebug(5700) << " " << (*it) << endl; } kdDebug(5700) << " }" << endl; kdDebug(5700) << " PhoneNumbers {" << endl; PhoneNumber::List p = phoneNumbers(); PhoneNumber::List::ConstIterator it2; for( it2 = p.begin(); it2 != p.end(); ++it2 ) { kdDebug(5700) << " Type: " << int((*it2).type()) << " Number: " << (*it2).number() << endl; } kdDebug(5700) << " }" << endl; Address::List a = addresses(); Address::List::ConstIterator it3; for( it3 = a.begin(); it3 != a.end(); ++it3 ) { (*it3).dump(); } kdDebug(5700) << " Keys {" << endl; Key::List k = keys(); Key::List::ConstIterator it4; for( it4 = k.begin(); it4 != k.end(); ++it4 ) { kdDebug(5700) << " Type: " << int((*it4).type()) << " Key: " << (*it4).textData() << " CustomString: " << (*it4).customTypeString() << endl; } kdDebug(5700) << " }" << endl; kdDebug(5700) << "}" << endl; } void Addressee::insertAddress( const Address &address ) { detach(); mData->empty = false; Address::List::Iterator it; for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { if ( (*it).id() == address.id() ) { *it = address; return; } } mData->addresses.append( address ); } void Addressee::removeAddress( const Address &address ) { detach(); Address::List::Iterator it; for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { if ( (*it).id() == address.id() ) { mData->addresses.remove( it ); return; } } } Address Addressee::address( int type ) const { Address address( type ); Address::List::ConstIterator it; for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { if ( matchBinaryPattern( (*it).type(), type ) ) { if ( (*it).type() & Address::Pref ) return (*it); else if ( address.isEmpty() ) address = (*it); } } return address; } Address::List Addressee::addresses() const { return mData->addresses; } Address::List Addressee::addresses( int type ) const { Address::List list; Address::List::ConstIterator it; for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { if ( matchBinaryPattern( (*it).type(), type ) ) { list.append( *it ); } } return list; } Address Addressee::findAddress( const QString &id ) const { Address::List::ConstIterator it; for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { if ( (*it).id() == id ) { return *it; } } return Address(); } void Addressee::insertCategory( const QString &c ) { detach(); mData->empty = false; if ( mData->categories.contains( c ) ) return; mData->categories.append( c ); } void Addressee::removeCategory( const QString &c ) { detach(); QStringList::Iterator it = mData->categories.find( c ); if ( it == mData->categories.end() ) return; mData->categories.remove( it ); } bool Addressee::hasCategory( const QString &c ) const { return ( mData->categories.contains( c ) ); } void Addressee::setCategories( const QStringList &c ) { detach(); mData->empty = false; mData->categories = c; } QStringList Addressee::categories() const { return mData->categories; } void Addressee::insertCustom( const QString &app, const QString &name, const QString &value ) { if ( value.isNull() || name.isEmpty() || app.isEmpty() ) return; detach(); mData->empty = false; QString qualifiedName = app + "-" + name + ":"; QStringList::Iterator it; for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { if ( (*it).startsWith( qualifiedName ) ) { (*it) = qualifiedName + value; return; } } mData->custom.append( qualifiedName + value ); } void Addressee::removeCustom( const QString &app, const QString &name) { detach(); QString qualifiedName = app + "-" + name + ":"; QStringList::Iterator it; for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { if ( (*it).startsWith( qualifiedName ) ) { mData->custom.remove( it ); return; } } } QString Addressee::custom( const QString &app, const QString &name ) const { QString qualifiedName = app + "-" + name + ":"; QString value; QStringList::ConstIterator it; for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { if ( (*it).startsWith( qualifiedName ) ) { value = (*it).mid( (*it).find( ":" ) + 1 ); break; } } return value; } void Addressee::setCustoms( const QStringList &l ) { detach(); mData->empty = false; mData->custom = l; } QStringList Addressee::customs() const { return mData->custom; } void Addressee::parseEmailAddress( const QString &rawEmail, QString &fullName, QString &email) { int startPos, endPos, len; QString partA, partB, result; char endCh = '>'; startPos = rawEmail.find('<'); if (startPos < 0) { startPos = rawEmail.find('('); endCh = ')'; } if (startPos < 0) { // We couldn't find any separators, so we assume the whole string // is the email address email = rawEmail; fullName = ""; } else { // We have a start position, try to find an end endPos = rawEmail.find(endCh, startPos+1); if (endPos < 0) { // We couldn't find the end of the email address. We can only // assume the entire string is the email address. email = rawEmail; fullName = ""; } else { // We have a start and end to the email address // Grab the name part fullName = rawEmail.left(startPos).stripWhiteSpace(); // grab the email part email = rawEmail.mid(startPos+1, endPos-startPos-1).stripWhiteSpace(); // Check that we do not have any extra characters on the end of the // strings len = fullName.length(); if (fullName[0]=='"' && fullName[len-1]=='"') fullName = fullName.mid(1, len-2); else if (fullName[0]=='<' && fullName[len-1]=='>') fullName = fullName.mid(1, len-2); else if (fullName[0]=='(' && fullName[len-1]==')') fullName = fullName.mid(1, len-2); } } } void Addressee::setResource( Resource *resource ) { detach(); mData->resource = resource; } Resource *Addressee::resource() const { return mData->resource; } +//US +QString Addressee::resourceLabel() +{ + return i18n("Resource"); +} + void Addressee::setChanged( bool value ) { detach(); mData->changed = value; } bool Addressee::changed() const { return mData->changed; } QDataStream &KABC::operator<<( QDataStream &s, const Addressee &a ) { if (!a.mData) return s; s << a.uid(); s << a.mData->name; s << a.mData->formattedName; s << a.mData->familyName; s << a.mData->givenName; s << a.mData->additionalName; s << a.mData->prefix; s << a.mData->suffix; s << a.mData->nickName; s << a.mData->birthday; s << a.mData->mailer; s << a.mData->timeZone; s << a.mData->geo; s << a.mData->title; s << a.mData->role; s << a.mData->organization; s << a.mData->note; s << a.mData->productId; s << a.mData->revision; s << a.mData->sortString; s << a.mData->url; s << a.mData->secrecy; s << a.mData->logo; s << a.mData->photo; s << a.mData->sound; s << a.mData->agent; s << a.mData->phoneNumbers; s << a.mData->addresses; s << a.mData->emails; s << a.mData->categories; s << a.mData->custom; s << a.mData->keys; return s; } QDataStream &KABC::operator>>( QDataStream &s, Addressee &a ) { if (!a.mData) return s; s >> a.mData->uid; s >> a.mData->name; s >> a.mData->formattedName; s >> a.mData->familyName; s >> a.mData->givenName; s >> a.mData->additionalName; s >> a.mData->prefix; s >> a.mData->suffix; s >> a.mData->nickName; s >> a.mData->birthday; s >> a.mData->mailer; s >> a.mData->timeZone; s >> a.mData->geo; s >> a.mData->title; s >> a.mData->role; s >> a.mData->organization; s >> a.mData->note; s >> a.mData->productId; s >> a.mData->revision; s >> a.mData->sortString; s >> a.mData->url; s >> a.mData->secrecy; s >> a.mData->logo; s >> a.mData->photo; s >> a.mData->sound; s >> a.mData->agent; s >> a.mData->phoneNumbers; s >> a.mData->addresses; s >> a.mData->emails; s >> a.mData->categories; s >> a.mData->custom; s >> a.mData->keys; a.mData->empty = false; return s; } bool matchBinaryPattern( int value, int pattern ) { /** We want to match all telephonnumbers/addresses which have the bits in the pattern set. More are allowed. if pattern == 0 we have a special handling, then we want only those with exactly no bit set. */ if ( pattern == 0 ) return ( value == 0 ); else return ( pattern == ( pattern & value ) ); } |