diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp index b1063b273..5a7b94d1b 100644 --- a/kabc/addressee.cpp +++ b/kabc/addressee.cpp @@ -1,650 +1,675 @@ /* This file is part of libkabc. Copyright (c) 2001 Cornelius Schumacher This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include #include #include #include "phonenumber.h" #include "addressee.h" using namespace KABC; Addressee::Addressee() { mData = new AddresseeData; mData->uid = KApplication::randomString( 10 ); } 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 = new AddresseeData; *(a.mData) = *mData; return a; } void Addressee::detach() { *this = copy(); } bool Addressee::isEmpty() { if ( mData->name.isEmpty() && mData->formattedName.isEmpty() && mData->emails.isEmpty() ) return true; return false; } void Addressee::setUid( const QString &uid ) { if ( uid == mData->uid ) return; detach(); mData->uid = uid; } QString Addressee::uid() const { return mData->uid; } void Addressee::setName( const QString &name ) { if ( name == mData->name ) return; detach(); mData->name = name; } QString Addressee::name() const { return mData->name; } void Addressee::setFormattedName( const QString &formattedName ) { if ( formattedName == mData->formattedName ) return; detach(); mData->formattedName = formattedName; } QString Addressee::formattedName() const { return mData->formattedName; } void Addressee::setFamilyName( const QString &familyName ) { if ( familyName == mData->familyName ) return; detach(); mData->familyName = familyName; } QString Addressee::familyName() const { return mData->familyName; } void Addressee::setGivenName( const QString &givenName ) { if ( givenName == mData->givenName ) return; detach(); mData->givenName = givenName; } QString Addressee::givenName() const { return mData->givenName; } void Addressee::setAdditionalName( const QString &additionalName ) { if ( additionalName == mData->additionalName ) return; detach(); mData->additionalName = additionalName; } QString Addressee::additionalName() const { return mData->additionalName; } void Addressee::setPrefix( const QString &prefix ) { if ( prefix == mData->prefix ) return; detach(); mData->prefix = prefix; } QString Addressee::prefix() const { return mData->prefix; } void Addressee::setSuffix( const QString &suffix ) { if ( suffix == mData->suffix ) return; detach(); mData->suffix = suffix; } QString Addressee::suffix() const { return mData->suffix; } void Addressee::setNickName( const QString &nickName ) { if ( nickName == mData->nickName ) return; detach(); mData->nickName = nickName; } QString Addressee::nickName() const { return mData->nickName; } void Addressee::setBirthday( const QDateTime &birthday ) { if ( birthday == mData->birthday ) return; detach(); mData->birthday = birthday; } QDateTime Addressee::birthday() const { return mData->birthday; } void Addressee::setMailer( const QString &mailer ) { if ( mailer == mData->mailer ) return; detach(); mData->mailer = mailer; } QString Addressee::mailer() const { return mData->mailer; } void Addressee::setTimeZone( const TimeZone &timeZone ) { if ( timeZone == mData->timeZone ) return; detach(); mData->timeZone = timeZone; } TimeZone Addressee::timeZone() const { return mData->timeZone; } void Addressee::setGeo( const Geo &geo ) { if ( geo == mData->geo ) return; detach(); mData->geo = geo; } Geo Addressee::geo() const { return mData->geo; } void Addressee::setTitle( const QString &title ) { if ( title == mData->title ) return; detach(); mData->title = title; } QString Addressee::title() const { return mData->title; } void Addressee::setRole( const QString &role ) { if ( role == mData->role ) return; detach(); mData->role = role; } QString Addressee::role() const { return mData->role; } void Addressee::setOrganization( const QString &organization ) { if ( organization == mData->organization ) return; detach(); mData->organization = organization; } QString Addressee::organization() const { return mData->organization; } void Addressee::setNote( const QString ¬e ) { if ( note == mData->note ) return; detach(); mData->note = note; } QString Addressee::note() const { return mData->note; } void Addressee::setProductId( const QString &productId ) { if ( productId == mData->productId ) return; detach(); mData->productId = productId; } QString Addressee::productId() const { return mData->productId; } void Addressee::setRevision( const QDateTime &revision ) { if ( revision == mData->revision ) return; detach(); mData->revision = revision; } QDateTime Addressee::revision() const { return mData->revision; } void Addressee::setSortString( const QString &sortString ) { if ( sortString == mData->sortString ) return; detach(); mData->sortString = sortString; } QString Addressee::sortString() const { return mData->sortString; } void Addressee::setUrl( const KURL &url ) { if ( url == mData->url ) return; detach(); mData->url = url; } KURL Addressee::url() const { return mData->url; } QString Addressee::realName() const { if ( !formattedName().isEmpty() ) return formattedName(); QString n = prefix() + " " + givenName() + " " + additionalName() + " " + familyName() + " " + suffix(); n = n.simplifyWhiteSpace(); if ( n.isEmpty() ) n = name(); return n; } +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 = realName() + " "; + text.append( "<" + 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::insertPhoneNumber( const PhoneNumber &phoneNumber ) { detach(); 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::List::ConstIterator it; for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { if ( (*it).type() == type ) { return *it; } } return PhoneNumber(); } PhoneNumber::List Addressee::phoneNumbers() const { return mData->phoneNumbers; } 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::dump() const { kdDebug(5700) << "Addressee {" << endl; - kdDebug() << " Uid: '" << uid() << "'" << endl; - kdDebug() << " Name: '" << name() << "'" << endl; - kdDebug() << " FormattedName: '" << formattedName() << "'" << endl; - kdDebug() << " FamilyName: '" << familyName() << "'" << endl; - kdDebug() << " GivenName: '" << givenName() << "'" << endl; - kdDebug() << " AdditionalName: '" << additionalName() << "'" << endl; - kdDebug() << " Prefix: '" << prefix() << "'" << endl; - kdDebug() << " Suffix: '" << suffix() << "'" << endl; - kdDebug() << " NickName: '" << nickName() << "'" << endl; - kdDebug() << " Birthday: '" << birthday().toString() << "'" << endl; - kdDebug() << " Mailer: '" << mailer() << "'" << endl; - kdDebug() << " TimeZone: '" << timeZone().asString() << "'" << endl; - kdDebug() << " Geo: '" << geo().asString() << "'" << endl; - kdDebug() << " Title: '" << title() << "'" << endl; - kdDebug() << " Role: '" << role() << "'" << endl; - kdDebug() << " Organization: '" << organization() << "'" << endl; - kdDebug() << " Note: '" << note() << "'" << endl; - kdDebug() << " ProductId: '" << productId() << "'" << endl; - kdDebug() << " Revision: '" << revision().toString() << "'" << endl; - kdDebug() << " SortString: '" << sortString() << "'" << endl; - kdDebug() << " Url: '" << url().url() << "'" << 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) << " 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 it; - for( it = p.begin(); it != p.end(); ++it ) { - kdDebug(5700) << " Type: " << int((*it).type()) << " Number: " << (*it).number() << endl; + 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 it2; - for( it2 = a.begin(); it2 != a.end(); ++it2 ) { - (*it2).dump(); + Address::List::ConstIterator it3; + for( it3 = a.begin(); it3 != a.end(); ++it3 ) { + (*it3).dump(); } kdDebug(5700) << "}" << endl; } void Addressee::insertAddress( const Address &address ) { detach(); 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::List::ConstIterator it; for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { if ( (*it).type() == type ) { return *it; } } return Address(); } Address::List Addressee::addresses() const { return mData->addresses; } 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(); 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.find( c ) != mData->categories.end() ); } void Addressee::setCategories( const QStringList &c ) { detach(); 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(); 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->custom = l; } QStringList Addressee::customs() const { return mData->custom; } diff --git a/kabc/addressee.h b/kabc/addressee.h index 73b761f31..096dbdb78 100644 --- a/kabc/addressee.h +++ b/kabc/addressee.h @@ -1,420 +1,428 @@ /*** Warning! This file has been generated by the script makeaddressee ***/ /* This file is part of libkabc. Copyright (c) 2001 Cornelius Schumacher 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. */ #ifndef KABC_ADDRESSEE_H #define KABC_ADDRESSEE_H // $Id$ #include #include #include #include #include #include #include "phonenumber.h" #include "address.h" #include "geo.h" #include "timezone.h" namespace KABC { struct AddresseeData : public KShared { QString uid; QString name; QString formattedName; QString familyName; QString givenName; QString additionalName; QString prefix; QString suffix; QString nickName; QDateTime birthday; QString mailer; TimeZone timeZone; Geo geo; QString title; QString role; QString organization; QString note; QString productId; QDateTime revision; QString sortString; KURL url; PhoneNumber::List phoneNumbers; Address::List addresses; QStringList emails; QStringList categories; QStringList custom; }; /** @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. */ class Addressee { public: typedef QValueList List; /** Construct an empty address book entry. */ Addressee(); ~Addressee(); Addressee( const Addressee & ); Addressee &operator=( const Addressee & ); /** Return, if the address book entry is empty. */ bool isEmpty(); /* Set unique identifier. */ void setUid( const QString &uid ); /* Return unique identifier. */ QString uid() const; /* Set name. */ void setName( const QString &name ); /* Return name. */ QString name() const; /* Set formatted name. */ void setFormattedName( const QString &formattedName ); /* Return formatted name. */ QString formattedName() const; /* Set family name. */ void setFamilyName( const QString &familyName ); /* Return family name. */ QString familyName() const; /* Set given name. */ void setGivenName( const QString &givenName ); /* Return given name. */ QString givenName() const; /* Set additional names. */ void setAdditionalName( const QString &additionalName ); /* Return additional names. */ QString additionalName() const; /* Set honorific prefixes. */ void setPrefix( const QString &prefix ); /* Return honorific prefixes. */ QString prefix() const; /* Set honorific suffixes. */ void setSuffix( const QString &suffix ); /* Return honorific suffixes. */ QString suffix() const; /* Set nick name. */ void setNickName( const QString &nickName ); /* Return nick name. */ QString nickName() const; /* Set birthday. */ void setBirthday( const QDateTime &birthday ); /* Return birthday. */ QDateTime birthday() const; /* Set mail client. */ void setMailer( const QString &mailer ); /* Return mail client. */ QString mailer() const; /* Set time zone. */ void setTimeZone( const TimeZone &timeZone ); /* Return time zone. */ TimeZone timeZone() const; /* Set geographic position. */ void setGeo( const Geo &geo ); /* Return geographic position. */ Geo geo() const; /* Set title. */ void setTitle( const QString &title ); /* Return title. */ QString title() const; /* Set role. */ void setRole( const QString &role ); /* Return role. */ QString role() const; /* Set organization. */ void setOrganization( const QString &organization ); /* Return organization. */ QString organization() const; /* Set note. */ void setNote( const QString ¬e ); /* Return note. */ QString note() const; /* Set product identifier. */ void setProductId( const QString &productId ); /* Return product identifier. */ QString productId() const; /* Set revision date. */ void setRevision( const QDateTime &revision ); /* Return revision date. */ QDateTime revision() const; /* Set sort string. */ void setSortString( const QString &sortString ); /* Return sort string. */ QString sortString() const; /* Set URL. */ void setUrl( const KURL &url ); /* Return URL. */ KURL url() const; /** Return the name of the addressee. This is calculated from all the name fields. */ QString realName() 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 isnertEmail() with a set preferred parameter. */ QString preferredEmail() const; /** Return list of all email addresses. */ QStringList emails() const; /** Insert a phone number. If a phoen 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 phone number with the given id. */ PhoneNumber findPhoneNumber( 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 address with the given id. */ Address findAddress( const QString &id ) const; /** Insert category. If the category already exists it is not dulicated. */ 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 ne 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; /** Debug output. */ void dump() const; private: Addressee copy(); void detach(); KSharedPtr mData; }; } #endif diff --git a/kabc/addresseedialog.cpp b/kabc/addresseedialog.cpp index 61713b032..ae6f9bef2 100644 --- a/kabc/addresseedialog.cpp +++ b/kabc/addresseedialog.cpp @@ -1,117 +1,189 @@ /* This file is part of libkabc. Copyright (c) 2001 Cornelius Schumacher This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include +#include +#include #include #include #include "stdaddressbook.h" #include "addresseedialog.h" #include "addresseedialog.moc" using namespace KABC; -AddresseeDialog::AddresseeDialog( QWidget *parent ) : +AddresseeDialog::AddresseeDialog( QWidget *parent, bool multiple ) : KDialogBase( KDialogBase::Plain, i18n("Select Addressee"), - Ok|Cancel, Ok, parent ) + Ok|Cancel, Ok, parent ), mMultiple( multiple ) { QWidget *topWidget = plainPage(); - QBoxLayout *topLayout = new QVBoxLayout( topWidget ); + + QBoxLayout *topLayout = new QHBoxLayout( topWidget ); + QBoxLayout *listLayout = new QVBoxLayout; + topLayout->addLayout( listLayout ); mAddresseeList = new KListView( topWidget ); mAddresseeList->addColumn( i18n("Name") ); mAddresseeList->addColumn( i18n("Email") ); mAddresseeList->setAllColumnsShowFocus( true ); - topLayout->addWidget( mAddresseeList ); + listLayout->addWidget( mAddresseeList ); connect( mAddresseeList, SIGNAL( doubleClicked( QListViewItem * ) ), SLOT( slotOk() ) ); connect( mAddresseeList, SIGNAL( selectionChanged( QListViewItem * ) ), SLOT( updateEdit( QListViewItem * ) ) ); - + mAddresseeEdit = new KLineEdit( topWidget ); mAddresseeEdit->setCompletionMode( KGlobalSettings::CompletionAuto ); connect( mAddresseeEdit->completionObject(), SIGNAL( match( const QString & ) ), SLOT( selectItem( const QString & ) ) ); mAddresseeEdit->setFocus(); - topLayout->addWidget( mAddresseeEdit ); + listLayout->addWidget( mAddresseeEdit ); + + if ( mMultiple ) { + QBoxLayout *selectedLayout = new QVBoxLayout; + topLayout->addLayout( selectedLayout ); + topLayout->setSpacing( spacingHint() ); +// selectedLayout->addSpacing( spacingHint() ); + + QGroupBox *selectedGroup = new QGroupBox( 1, Horizontal, i18n("Selected: "), + topWidget ); + selectedLayout->addWidget( selectedGroup ); + + mSelectedList = new KListView( selectedGroup ); + mSelectedList->addColumn( i18n("Name") ); + mSelectedList->addColumn( i18n("Email") ); + connect( mSelectedList, SIGNAL( doubleClicked( QListViewItem * ) ), + SLOT( removeSelected() ) ); + + QPushButton *unselectButton = new QPushButton( i18n("Unselect"), selectedGroup ); + connect ( unselectButton, SIGNAL( clicked() ), SLOT( removeSelected() ) ); + + connect( mAddresseeList, SIGNAL( selectionChanged( QListViewItem * ) ), + SLOT( addSelected( QListViewItem * ) ) ); + } mAddressBook = StdAddressBook::self(); loadAddressBook(); } AddresseeDialog::~AddresseeDialog() { } void AddresseeDialog::loadAddressBook() { mAddresseeList->clear(); mItemDict.clear(); mAddresseeEdit->completionObject()->clear(); AddressBook::Iterator it; for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) { AddresseeItem *item = new AddresseeItem( mAddresseeList, (*it) ); addCompletionItem( (*it).realName(), item ); addCompletionItem( (*it).preferredEmail(), item ); } } void AddresseeDialog::addCompletionItem( const QString &str, QListViewItem *item ) { QString s = str.lower(); mItemDict.insert( s, item ); mAddresseeEdit->completionObject()->addItem( s ); } void AddresseeDialog::selectItem( const QString &str ) { if ( str.isEmpty() ) return; QListViewItem *item = mItemDict.find( str ); if ( item ) { mAddresseeList->blockSignals( true ); mAddresseeList->setSelected( item, true ); mAddresseeList->blockSignals( false ); } } void AddresseeDialog::updateEdit( QListViewItem *item ) { mAddresseeEdit->setText( item->text( 0 ) ); mAddresseeEdit->setSelection( 0, item->text( 0 ).length() ); } +void AddresseeDialog::addSelected( QListViewItem *item ) +{ + AddresseeItem *addrItem = dynamic_cast( item ); + if ( !addrItem ) return; + + Addressee a = addrItem->addressee(); + + QListViewItem *selectedItem = mSelectedDict.find( a.uid() ); + if ( !selectedItem ) { + selectedItem = new AddresseeItem( mSelectedList, a ); + mSelectedDict.insert( a.uid(), selectedItem ); + } +} + +void AddresseeDialog::removeSelected() +{ + QListViewItem *item = mSelectedList->selectedItem(); + AddresseeItem *addrItem = dynamic_cast( item ); + if ( !addrItem ) return; + + mSelectedDict.remove( addrItem->addressee().uid() ); + delete addrItem; +} + Addressee AddresseeDialog::getAddressee( QWidget *parent ) { AddresseeDialog *dlg = new AddresseeDialog( parent ); int result = dlg->exec(); if ( result == QDialog::Accepted ) { QListViewItem *item = dlg->mAddresseeList->selectedItem(); AddresseeItem *aItem = dynamic_cast( item ); if ( !aItem ) return Addressee(); return aItem->addressee(); } return Addressee(); } + +Addressee::List AddresseeDialog::getAddressees( QWidget *parent ) +{ + AddresseeDialog *dlg = new AddresseeDialog( parent, true ); + int result = dlg->exec(); + if ( result == QDialog::Accepted ) { + Addressee::List al; + + QListViewItem *item = dlg->mSelectedList->firstChild(); + while( item ) { + AddresseeItem *aItem = dynamic_cast( item ); + if ( aItem ) al.append( aItem->addressee() ); + item = item->nextSibling(); + } + + return al; + } + + return Addressee::List(); +} diff --git a/kabc/addresseedialog.h b/kabc/addresseedialog.h index b5e3104f7..28baa3fee 100644 --- a/kabc/addresseedialog.h +++ b/kabc/addresseedialog.h @@ -1,103 +1,121 @@ /* This file is part of libkabc. Copyright (c) 2001 Cornelius Schumacher 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. */ #ifndef KABC_ADDRESSEEDIALOG_H #define KABC_ADDRESSEEDIALOG_H // $Id$ #include #include #include #include #include "addressbook.h" namespace KABC { class AddresseeItem : public QListViewItem { public: AddresseeItem( QListView *parent, const Addressee &addressee ) : QListViewItem( parent ), mAddressee( addressee ) { setText( 0, addressee.realName() ); setText( 1, addressee.preferredEmail() ); } Addressee addressee() const { return mAddressee; } private: Addressee mAddressee; }; /** @short Dialog for selecting address book entries. This class provides a dialog for selecting entries from the standard KDE address book. Use the @ref getAddressee() function to open a modal dialog, returning an address book entry. In the dialog you can select an entry from the list with the mouse or type in the first letters of the name or email address you are searching for. The entry matching best is automatically selected. Use double click, pressing return or pressing the ok button to return the selected addressee to the application. */ class AddresseeDialog : public KDialogBase { Q_OBJECT public: /** Construct addressbook entry select dialog. @param parent parent widget */ - AddresseeDialog( QWidget *parent ); + AddresseeDialog( QWidget *parent, bool multiple=false ); virtual ~AddresseeDialog(); /** + Select a single address book entry. + Open addressee select dialog and return the entry selected by the user. - If the user doesn't selectan entry or presses cancel, the returned + If the user doesn't select an entry or presses cancel, the returned addressee is empty. */ static Addressee getAddressee( QWidget *parent ); + /** + Select multiple adress book entries. + + Open addressee select dialog and return the entries selected by the user. + If the user doesn't select an entry or presses cancel, the returned + addressee list is empty. + */ + static Addressee::List getAddressees( QWidget *parent ); + private slots: void selectItem( const QString & ); void updateEdit( QListViewItem *item ); + void addSelected( QListViewItem *item ); + void removeSelected(); private: void loadAddressBook(); void addCompletionItem( const QString &str, QListViewItem *item ); + bool mMultiple; + KListView *mAddresseeList; KLineEdit *mAddresseeEdit; + KListView *mSelectedList; + AddressBook *mAddressBook; QDict mItemDict; + QDict mSelectedDict; }; } #endif diff --git a/kabc/distributionlist.cpp b/kabc/distributionlist.cpp index e86a55628..83e0505b5 100644 --- a/kabc/distributionlist.cpp +++ b/kabc/distributionlist.cpp @@ -1,219 +1,214 @@ /* This file is part of libkabc. Copyright (c) 2001 Cornelius Schumacher This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include #include #include #include "distributionlist.h" using namespace KABC; DistributionList::DistributionList( DistributionListManager *manager, const QString &name ) : mManager( manager ), mName( name ) { mManager->insert( this ); } DistributionList::~DistributionList() { mManager->remove( this ); } void DistributionList::setName( const QString &name ) { mName = name; } QString DistributionList::name() const { return mName; } void DistributionList::insertEntry( const Addressee &a, const QString &email ) { Entry e( a, email ); QValueList::Iterator it; for( it = mEntries.begin(); it != mEntries.end(); ++it ) { if ( (*it).addressee.uid() == a.uid() && (*it).email == email ) { *it = e; return; } } mEntries.append( e ); } void DistributionList::removeEntry( const Addressee &a, const QString &email ) { QValueList::Iterator it; for( it = mEntries.begin(); it != mEntries.end(); ++it ) { if ( (*it).addressee.uid() == a.uid() && (*it).email == email ) { mEntries.remove( it ); return; } } } QStringList DistributionList::emails() const { QStringList emails; Entry::List::ConstIterator it; for( it = mEntries.begin(); it != mEntries.end(); ++it ) { Addressee a = (*it).addressee; - QString email = (*it).email; + QString email = a.fullEmail(); - if ( email.isEmpty() ) email = a.preferredEmail(); - if ( email.isEmpty() ) continue; - - QString text; - if ( !a.realName().isEmpty() ) text = a.realName() + " "; - text.append( "<" + email + ">" ); - - emails.append( text ); + if ( !email.isEmpty() ) { + emails.append( email ); + } } return emails; } DistributionList::Entry::List DistributionList::entries() const { return mEntries; } DistributionListManager::DistributionListManager( AddressBook *ab ) : mAddressBook( ab ) { } DistributionList *DistributionListManager::list( const QString &name ) { DistributionList *list; for( list = mLists.first(); list; list = mLists.next() ) { if ( list->name() == name ) return list; } return 0; } void DistributionListManager::insert( DistributionList *l ) { DistributionList *list; for( list = mLists.first(); list; list = mLists.next() ) { if ( list->name() == l->name() ) { mLists.remove( list ); break; } } mLists.append( l ); } void DistributionListManager::remove( DistributionList *l ) { DistributionList *list; for( list = mLists.first(); list; list = mLists.next() ) { if ( list->name() == l->name() ) { mLists.remove( list ); return; } } } QStringList DistributionListManager::listNames() { QStringList names; DistributionList *list; for( list = mLists.first(); list; list = mLists.next() ) { names.append( list->name() ); } return names; } bool DistributionListManager::load() { KSimpleConfig cfg( locateLocal( "data", "kabc/distlists" ) ); QMap entryMap = cfg.entryMap( mAddressBook->fileName() ); if ( entryMap.isEmpty() ) { kdDebug() << "No distlists for '" << mAddressBook->fileName() << "'" << endl; return false; } cfg.setGroup( mAddressBook->fileName() ); QMap::ConstIterator it; for( it = entryMap.begin(); it != entryMap.end(); ++it ) { QString name = it.key(); QStringList value = cfg.readListEntry( name ); kdDebug() << "DLM::load(): " << name << ": " << value.join(",") << endl; DistributionList *list = new DistributionList( this, name ); QStringList::ConstIterator it2 = value.begin(); while( it2 != value.end() ) { QString id = *it2++; QString email = *it2; kdDebug() << "----- Entry " << id << endl; Addressee a = mAddressBook->findByUid( id ); if ( !a.isEmpty() ) { list->insertEntry( a, email ); } if ( it2 == value.end() ) break; ++it2; } } return true; } bool DistributionListManager::save() { kdDebug() << "DistListManager::save()" << endl; KSimpleConfig cfg( locateLocal( "data", "kabc/distlists" ) ); cfg.setGroup( mAddressBook->fileName() ); DistributionList *list; for( list = mLists.first(); list; list = mLists.next() ) { kdDebug() << " Saving '" << list->name() << "'" << endl; QStringList value; DistributionList::Entry::List entries = list->entries(); DistributionList::Entry::List::ConstIterator it; for( it = entries.begin(); it != entries.end(); ++it ) { value.append( (*it).addressee.uid() ); value.append( (*it).email ); } cfg.writeEntry( list->name(), value ); } cfg.sync(); return true; } diff --git a/kabc/distributionlisteditor.cpp b/kabc/distributionlisteditor.cpp index 16b52de75..a6098e0b9 100644 --- a/kabc/distributionlisteditor.cpp +++ b/kabc/distributionlisteditor.cpp @@ -1,279 +1,281 @@ /* This file is part of libkabc. Copyright (c) 2001 Cornelius Schumacher This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include #include #include #include #include #include #include #include #include #include "addressbook.h" #include "addresseedialog.h" #include "distributionlist.h" #include "distributionlisteditor.h" #include "distributionlisteditor.moc" using namespace KABC; EmailSelectDialog::EmailSelectDialog( const QStringList &emails, const QString ¤t, QWidget *parent ) : KDialogBase( KDialogBase::Plain, i18n("Select Email Address"), Ok, Ok, parent ) { QFrame *topFrame = plainPage(); QBoxLayout *topLayout = new QVBoxLayout( topFrame ); mButtonGroup = new QButtonGroup( 1, Horizontal, i18n("Email Addresses"), topFrame ); topLayout->addWidget( mButtonGroup ); QStringList::ConstIterator it; for( it = emails.begin(); it != emails.end(); ++it ) { QRadioButton *button = new QRadioButton( *it, mButtonGroup ); if ( (*it) == current ) { button->setDown( true ); } } } QString EmailSelectDialog::selected() { QButton *button = mButtonGroup->selected(); if ( button ) return button->text(); return QString::null; } QString EmailSelectDialog::getEmail( const QStringList &emails, const QString ¤t, QWidget *parent ) { EmailSelectDialog *dlg = new EmailSelectDialog( emails, current, parent ); dlg->exec(); QString result = dlg->selected(); delete dlg; return result; } class EntryItem : public QListViewItem { public: EntryItem( QListView *parent, const Addressee &addressee, const QString &email=QString::null ) : QListViewItem( parent ), mAddressee( addressee ), mEmail( email ) { setText( 0, addressee.realName() ); if( email.isEmpty() ) { setText( 1, addressee.preferredEmail() ); setText( 2, i18n("Yes") ); } else { setText( 1, email ); setText( 2, i18n("No") ); } } Addressee addressee() const { return mAddressee; } QString email() const { return mEmail; } private: Addressee mAddressee; QString mEmail; }; DistributionListEditor::DistributionListEditor( AddressBook *addressBook, QWidget *parent) : QWidget( parent ), mAddressBook( addressBook ) { kdDebug() << "DistributionListEditor()" << endl; QBoxLayout *topLayout = new QVBoxLayout( this ); + topLayout->setMargin( KDialog::marginHint() ); + topLayout->setSpacing( KDialog::spacingHint() ); QBoxLayout *nameLayout = new QHBoxLayout( topLayout) ; mNameCombo = new QComboBox( this ); nameLayout->addWidget( mNameCombo ); connect( mNameCombo, SIGNAL( activated( int ) ), SLOT( updateEntryView() ) ); QPushButton *newButton = new QPushButton( i18n("New Argl List"), this ); nameLayout->addWidget( newButton ); connect( newButton, SIGNAL( clicked() ), SLOT( newList() ) ); QPushButton *removeButton = new QPushButton( i18n("Remove List"), this ); nameLayout->addWidget( removeButton ); connect( removeButton, SIGNAL( clicked() ), SLOT( removeList() ) ); mEntryView = new QListView( this ); mEntryView->addColumn( i18n("Name") ); mEntryView->addColumn( i18n("Email") ); mEntryView->addColumn( i18n("Use preferred") ); topLayout->addWidget( mEntryView ); QPushButton *changeEmailButton = new QPushButton( i18n("Change Email"), this ); topLayout->addWidget( changeEmailButton ); connect( changeEmailButton, SIGNAL( clicked() ), SLOT( changeEmail() ) ); QPushButton *removeEntryButton = new QPushButton( i18n("Remove Entry"), this ); topLayout->addWidget( removeEntryButton ); connect( removeEntryButton, SIGNAL( clicked() ), SLOT( removeEntry() ) ); QPushButton *addEntryButton = new QPushButton( i18n("Add Entry"), this ); topLayout->addWidget( addEntryButton ); connect( addEntryButton, SIGNAL( clicked() ), SLOT( addEntry() ) ); mAddresseeView = new QListView( this ); mAddresseeView->addColumn( i18n("Name") ); mAddresseeView->addColumn( i18n("Preferred Email") ); topLayout->addWidget( mAddresseeView ); mManager = new DistributionListManager( mAddressBook ); mManager->load(); updateAddresseeView(); updateNameCombo(); } DistributionListEditor::~DistributionListEditor() { kdDebug() << "~DistributionListEditor()" << endl; mManager->save(); delete mManager; } void DistributionListEditor::newList() { bool ok = false; QString name = QInputDialog::getText( i18n("New Distribution List"), i18n("Please enter name."), QLineEdit::Normal, QString::null, &ok, this ); if ( !ok || name.isEmpty() ) return; new DistributionList( mManager, name ); mNameCombo->insertItem( name ); updateEntryView(); } void DistributionListEditor::removeList() { delete mManager->list( mNameCombo->currentText() ); mNameCombo->removeItem( mNameCombo->currentItem() ); updateEntryView(); } void DistributionListEditor::addEntry() { AddresseeItem *addresseeItem = dynamic_cast( mAddresseeView->selectedItem() ); if( !addresseeItem ) { kdDebug() << "DLE::addEntry(): No addressee selected." << endl; return; } DistributionList *list = mManager->list( mNameCombo->currentText() ); if ( !list ) { kdDebug() << "DLE::addEntry(): No dist list '" << mNameCombo->currentText() << "'" << endl; return; } list->insertEntry( addresseeItem->addressee() ); updateEntryView(); } void DistributionListEditor::removeEntry() { DistributionList *list = mManager->list( mNameCombo->currentText() ); if ( !list ) return; EntryItem *entryItem = dynamic_cast( mEntryView->selectedItem() ); if ( !entryItem ) return; list->removeEntry( entryItem->addressee(), entryItem->email() ); delete entryItem; } void DistributionListEditor::changeEmail() { DistributionList *list = mManager->list( mNameCombo->currentText() ); if ( !list ) return; EntryItem *entryItem = dynamic_cast( mEntryView->selectedItem() ); if ( !entryItem ) return; QString email = EmailSelectDialog::getEmail( entryItem->addressee().emails(), entryItem->email(), this ); list->removeEntry( entryItem->addressee(), entryItem->email() ); list->insertEntry( entryItem->addressee(), email ); updateEntryView(); } void DistributionListEditor::updateEntryView() { DistributionList *list = mManager->list( mNameCombo->currentText() ); if ( !list ) return; mEntryView->clear(); DistributionList::Entry::List entries = list->entries(); DistributionList::Entry::List::ConstIterator it; for( it = entries.begin(); it != entries.end(); ++it ) { new EntryItem( mEntryView, (*it).addressee, (*it).email ); } } void DistributionListEditor::updateAddresseeView() { mAddresseeView->clear(); AddressBook::Iterator it; for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) { new AddresseeItem( mAddresseeView, *it ); } } void DistributionListEditor::updateNameCombo() { mNameCombo->insertStringList( mManager->listNames() ); updateEntryView(); } diff --git a/kabc/scripts/addressee.src.cpp b/kabc/scripts/addressee.src.cpp index ce4fd2cdd..84603855b 100644 --- a/kabc/scripts/addressee.src.cpp +++ b/kabc/scripts/addressee.src.cpp @@ -1,358 +1,383 @@ /* This file is part of libkabc. Copyright (c) 2001 Cornelius Schumacher This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include #include #include #include "phonenumber.h" #include "addressee.h" using namespace KABC; Addressee::Addressee() { mData = new AddresseeData; mData->uid = KApplication::randomString( 10 ); } 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 = new AddresseeData; *(a.mData) = *mData; return a; } void Addressee::detach() { *this = copy(); } bool Addressee::isEmpty() { if ( mData->name.isEmpty() && mData->formattedName.isEmpty() && mData->emails.isEmpty() ) return true; return false; } --DEFINITIONS-- QString Addressee::realName() const { if ( !formattedName().isEmpty() ) return formattedName(); QString n = prefix() + " " + givenName() + " " + additionalName() + " " + familyName() + " " + suffix(); n = n.simplifyWhiteSpace(); if ( n.isEmpty() ) n = name(); return n; } +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 = realName() + " "; + text.append( "<" + 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::insertPhoneNumber( const PhoneNumber &phoneNumber ) { detach(); 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::List::ConstIterator it; for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { if ( (*it).type() == type ) { return *it; } } return PhoneNumber(); } PhoneNumber::List Addressee::phoneNumbers() const { return mData->phoneNumbers; } 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::dump() const { kdDebug(5700) << "Addressee {" << endl; --DEBUG-- + 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 it; - for( it = p.begin(); it != p.end(); ++it ) { - kdDebug(5700) << " Type: " << int((*it).type()) << " Number: " << (*it).number() << endl; + 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 it2; - for( it2 = a.begin(); it2 != a.end(); ++it2 ) { - (*it2).dump(); + Address::List::ConstIterator it3; + for( it3 = a.begin(); it3 != a.end(); ++it3 ) { + (*it3).dump(); } kdDebug(5700) << "}" << endl; } void Addressee::insertAddress( const Address &address ) { detach(); 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::List::ConstIterator it; for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { if ( (*it).type() == type ) { return *it; } } return Address(); } Address::List Addressee::addresses() const { return mData->addresses; } 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(); 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.find( c ) != mData->categories.end() ); } void Addressee::setCategories( const QStringList &c ) { detach(); 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(); 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->custom = l; } QStringList Addressee::customs() const { return mData->custom; } diff --git a/kabc/scripts/addressee.src.h b/kabc/scripts/addressee.src.h index b91d76603..c1014854d 100644 --- a/kabc/scripts/addressee.src.h +++ b/kabc/scripts/addressee.src.h @@ -1,211 +1,219 @@ /* This file is part of libkabc. Copyright (c) 2001 Cornelius Schumacher 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. */ #ifndef KABC_ADDRESSEE_H #define KABC_ADDRESSEE_H // $Id$ #include #include #include #include #include #include #include "phonenumber.h" #include "address.h" #include "geo.h" #include "timezone.h" namespace KABC { struct AddresseeData : public KShared { --VARIABLES-- PhoneNumber::List phoneNumbers; Address::List addresses; QStringList emails; QStringList categories; QStringList custom; }; /** @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. */ class Addressee { public: typedef QValueList List; /** Construct an empty address book entry. */ Addressee(); ~Addressee(); Addressee( const Addressee & ); Addressee &operator=( const Addressee & ); /** Return, if the address book entry is empty. */ bool isEmpty(); --DECLARATIONS-- /** Return the name of the addressee. This is calculated from all the name fields. */ QString realName() 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 isnertEmail() with a set preferred parameter. */ QString preferredEmail() const; /** Return list of all email addresses. */ QStringList emails() const; /** Insert a phone number. If a phoen 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 phone number with the given id. */ PhoneNumber findPhoneNumber( 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 address with the given id. */ Address findAddress( const QString &id ) const; /** Insert category. If the category already exists it is not dulicated. */ 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 ne 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; /** Debug output. */ void dump() const; private: Addressee copy(); void detach(); KSharedPtr mData; }; } #endif diff --git a/kabc/scripts/makeaddressee b/kabc/scripts/makeaddressee index d8c00bfb0..30573b857 100755 --- a/kabc/scripts/makeaddressee +++ b/kabc/scripts/makeaddressee @@ -1,88 +1,88 @@ #!/usr/bin/perl if (!open( ENTRIES, "entrylist" ) ) { print "Can't open entrylist\n"; exit 1; } while() { if (/^#/) { next; } chop; @entries = split /,/; if (!/^.+,(\w+),(\w+)/) { next; } push @entryRealNames, @entries[0]; push @entryTypes, @entries[1]; push @entryNames, @entries[2]; push @entryDebug, @entries[3]; } close ENTRIES; if (!open( H_IN, "addressee.src.h" ) ) { print "Can't open addressee.src.h\n"; exit 1; } if (!open( H_OUT, ">../addressee.h" ) ) { print "Can't open addressee.h\n"; exit 1; } print H_OUT "/*** Warning! This file has been generated by the script makeaddressee ***/\n"; while( ) { if (/--VARIABLES--/) { for( $i=0; $i<@entryNames; ++$i ) { print H_OUT " $entryTypes[$i] $entryNames[$i];\n"; } } elsif (/--DECLARATIONS--/) { for( $i=0; $i<@entryNames; ++$i ) { print H_OUT " /*\n"; print H_OUT " Set $entryRealNames[$i].\n"; print H_OUT " */\n"; print H_OUT " void set" . ucfirst($entryNames[$i]); print H_OUT "( const $entryTypes[$i] &$entryNames[$i] );\n"; print H_OUT " /*\n"; print H_OUT " Return $entryRealNames[$i].\n"; print H_OUT " */\n"; print H_OUT " $entryTypes[$i] $entryNames[$i]() const;\n\n"; } } else { print H_OUT; } } close H_OUT; close H_IN; if (!open( CPP_IN, "addressee.src.cpp" ) ) { print "Can't open addressee.src.cpp\n"; exit 1; } if (!open( CPP_OUT, ">../addressee.cpp" ) ) { print "Can't open addressee.cpp\n"; exit 1; } print H_OUT "/*** Warning! This file has been generated by the script makeaddressee ***/\n"; while( ) { if (/--DEFINITIONS--/) { for( $i=0; $i<@entryNames; ++$i ) { print CPP_OUT "void Addressee::set" . ucfirst($entryNames[$i]); print CPP_OUT "( const $entryTypes[$i] &$entryNames[$i] )\n{\n"; print CPP_OUT " if ( $entryNames[$i] == mData->$entryNames[$i] ) return;\n"; print CPP_OUT " detach();\n mData->$entryNames[$i] = $entryNames[$i];\n}\n\n"; print CPP_OUT "$entryTypes[$i] Addressee::$entryNames[$i]() const\n{\n"; print CPP_OUT " return mData->$entryNames[$i];\n}\n\n\n"; } } elsif (/--DEBUG--/) { for( $i=0; $i<@entryNames; ++$i ) { - print CPP_OUT " kdDebug() << \" " . ucfirst($entryNames[$i]); + print CPP_OUT " kdDebug(5700) << \" " . ucfirst($entryNames[$i]); print CPP_OUT ": '\" << $entryNames[$i]()$entryDebug[$i] << \"'\" << endl;\n"; } } else { print CPP_OUT; } } close CPP_OUT; close CPP_IN; diff --git a/kabc/testdistlist.cpp b/kabc/testdistlist.cpp index cf053fa8f..461837cbf 100644 --- a/kabc/testdistlist.cpp +++ b/kabc/testdistlist.cpp @@ -1,58 +1,58 @@ #include #include #include #include #include #include #include "stdaddressbook.h" #include "distributionlisteditor.h" #include "distributionlist.h" using namespace KABC; static const KCmdLineOptions options[] = { {"list ", I18N_NOOP("Show distribution list with name "), 0}, {0,0,0} }; int main(int argc,char **argv) { KAboutData aboutData("testdistlist",I18N_NOOP("Test Distribution Lists"),"0.1"); KCmdLineArgs::init(argc,argv,&aboutData); KCmdLineArgs::addCmdLineOptions( options ); KApplication app; KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); if (args->isSet("list")) { QString name = args->getOption("list"); DistributionListManager *manager = new DistributionListManager( StdAddressBook::self() ); manager->load(); DistributionList *list = manager->list( name ); if ( !list ) { kdDebug() << "No list with name '" << name << "'" << endl; return 1; } else { - kdDebug() << list->emails().join(", ") << endl; + kdDebug() << "RESULT: " << list->emails().join(", ") << endl; return 0; } } DistributionListEditor *editor = new DistributionListEditor( StdAddressBook::self(), 0 ); editor->show(); QObject::connect( &app, SIGNAL( lastWindowClosed() ), &app, SLOT( quit() ) ); app.exec(); delete editor; } diff --git a/kabc/testkabcdlg.cpp b/kabc/testkabcdlg.cpp index a5e40b73a..110fd984b 100644 --- a/kabc/testkabcdlg.cpp +++ b/kabc/testkabcdlg.cpp @@ -1,28 +1,45 @@ #include #include #include #include #include #include #include "addresseedialog.h" using namespace KABC; +static const KCmdLineOptions options[] = +{ + {"multiple", I18N_NOOP("Allow selection of multiple addressees."), 0}, + {0,0,0} +}; + int main(int argc,char **argv) { KAboutData aboutData("testkabc",I18N_NOOP("TestKabc"),"0.1"); KCmdLineArgs::init(argc,argv,&aboutData); + KCmdLineArgs::addCmdLineOptions( options ); KApplication app; - Addressee a = AddresseeDialog::getAddressee( 0 ); - - if ( !a.isEmpty() ) { - kdDebug() << "Selected Addressee:" << endl; - a.dump(); + KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); + if (args->isSet("multiple")) { + Addressee::List al = AddresseeDialog::getAddressees( 0 ); + Addressee::List::ConstIterator it; + kdDebug() << "Selected Addressees:" << endl; + for( it = al.begin(); it != al.end(); ++it ) { + kdDebug() << " " << (*it).fullEmail() << endl; + } } else { - kdDebug() << "No Addressee selected." << endl; + Addressee a = AddresseeDialog::getAddressee( 0 ); + + if ( !a.isEmpty() ) { + kdDebug() << "Selected Addressee:" << endl; + a.dump(); + } else { + kdDebug() << "No Addressee selected." << endl; + } } } diff --git a/kabc/vcard/testread.cpp b/kabc/vcard/testread.cpp index 638485608..9c429b16d 100644 --- a/kabc/vcard/testread.cpp +++ b/kabc/vcard/testread.cpp @@ -1,126 +1,127 @@ #include #include +#include #include #include #include int main(int argc, char * argv[]) { if (argc != 2) { cerr << "Usage: " << argv[0] << " " << endl; exit(1); } QFile f(argv[1]); QCString str; if (!f.open(IO_ReadOnly)) { cerr << "Couldn't open file \"" << argv[1] << endl; exit(1); } QTextStream t(&f); while (!t.eof()) - str += t.readLine() + '\n'; + str += t.readLine().utf8() + '\n'; using namespace VCARD; // Iterate through all vCards in the file. cout << "--------- begin ----------" << endl; cout << str.data(); cout << "--------- end ----------" << endl; VCardEntity e(str); VCardListIterator it(e.cardList()); for (; it.current(); ++it) { cerr << "****************** VCARD ********************" << endl; // Create a vcard using the string representation. VCard & v (*it.current()); if (v.has(EntityEmail)) { cerr << "Email parameter found" << endl; QCString s = v.contentLine(EntityEmail)->value()->asString(); cerr << "Email value == " << s << endl; } if (v.has(EntityNickname)) { cerr << "Nickname parameter found" << endl; cerr << "Nickname value == " << v.contentLine(EntityNickname)->value()->asString() << endl; } if (v.has(EntityRevision)) { cerr << "Revision parameter found" << endl; DateValue * d = (DateValue *) v.contentLine(EntityRevision)->value(); - ASSERT(d != 0); + assert(d != 0); cerr << "Revision date: " << endl; cerr << "Day : " << d->day() << endl; cerr << "Month : " << d->month() << endl; cerr << "Year : " << d->year() << endl; if (d->hasTime()) { cerr << "Revision date has a time component" << endl; cerr << "Revision time: " << endl; cerr << "Hour : " << d->hour() << endl; cerr << "Minute : " << d->minute() << endl; cerr << "Second : " << d->second() << endl; } else cerr << "Revision date does NOT have a time component" << endl; } if (v.has(EntityURL)) { cerr << "URL Parameter found" << endl; cerr << "URL Value == " << v.contentLine(EntityURL)->value()->asString() << endl; URIValue * urlVal = (URIValue *)v.contentLine(EntityURL)->value(); - ASSERT(urlVal != 0); + assert(urlVal != 0); cerr << "URL scheme == " << urlVal->scheme() << endl; cerr << "URL scheme specific part == " << urlVal->schemeSpecificPart() << endl; } if (v.has(EntityN)) { cerr << "N Parameter found" << endl; NValue * n = (NValue *)(v.contentLine(EntityN)->value()); cerr << "Family name == " << n->family() << endl; cerr << "Given name == " << n->given() << endl; cerr << "Middle name == " << n->middle() << endl; cerr << "Prefix == " << n->prefix() << endl; cerr << "Suffix == " << n->suffix() << endl; } cerr << "***************** END VCARD ******************" << endl; } }