21 #include "addresseedialog.h"
22 #ifndef KDEPIM_NO_KRESOURCES
23 #include "stdaddressbook.h"
27 #include <klocalizedstring.h>
29 #include <QtCore/QPointer>
30 #include <QtCore/QRegExp>
33 #include <QPushButton>
37 class AddresseeItem::Private
64 if ( column ==
Email ) {
67 int match = emailRe.
indexIn( value );
78 class AddresseeDialog::Private
81 Private(
bool multiple )
82 : mMultiple( multiple )
86 void addressBookChanged();
87 void selectItem(
const QString & );
90 void removeSelected();
92 void loadAddressBook();
98 KLineEdit *mAddresseeEdit;
102 #ifndef KDEPIM_NO_KRESOURCES
111 : KDialog( parent ), d( new Private( multiple ) )
113 setCaption( i18nc(
"@title:window",
"Select Addressee" ) );
114 setButtons( Ok | Cancel );
115 setDefaultButton( Ok );
118 setMainWidget( topWidget );
125 d->mAddresseeList->setColumnCount( 2 );
127 headerTitles << i18nc(
"@title:column addressee name",
"Name" )
128 << i18nc(
"@title:column addressee email",
"Email" );
129 d->mAddresseeList->setHeaderItem(
new QTreeWidgetItem( headerTitles ) );
130 listLayout->
addWidget( d->mAddresseeList );
131 connect( d->mAddresseeList, SIGNAL(itemDoubleClicked(
QTreeWidgetItem*,
int)),
133 connect( d->mAddresseeList, SIGNAL(itemSelectionChanged()),
134 SLOT(updateEdit()) );
136 d->mAddresseeEdit =
new KLineEdit( topWidget );
137 d->mAddresseeEdit->setCompletionMode( KGlobalSettings::CompletionAuto );
138 connect( d->mAddresseeEdit->completionObject(), SIGNAL(match(
QString)),
140 d->mAddresseeEdit->setFocus();
141 d->mAddresseeEdit->completionObject()->setIgnoreCase(
true );
142 listLayout->
addWidget( d->mAddresseeEdit );
144 setInitialSize(
QSize( 450, 300 ) );
146 if ( d->mMultiple ) {
151 new QGroupBox( i18nc(
"@title:group selected addressees",
"Selected" ), topWidget );
154 selectedLayout->
addWidget( selectedGroup );
156 d->mSelectedList =
new QTreeWidget( selectedGroup );
157 groupLayout->
addWidget( d->mSelectedList );
158 d->mSelectedList->setColumnCount( 2 );
160 headerTitles << i18nc(
"@title:column addressee name",
"Name" )
161 << i18nc(
"@title:column addressee email",
"Email" );
162 d->mSelectedList->setHeaderItem(
new QTreeWidgetItem( headerTitles ) );
164 connect( d->mSelectedList, SIGNAL(itemDoubleClicked(
QTreeWidgetItem*,
int)),
165 SLOT(removeSelected()) );
168 new QPushButton( i18nc(
"@action:button unselect addressee",
"Unselect" ), selectedGroup );
169 selectedLayout->
addWidget( unselectButton );
170 connect( unselectButton, SIGNAL(clicked()), SLOT(removeSelected()) );
175 setInitialSize(
QSize( 650, 350 ) );
178 #ifndef KDEPIM_NO_KRESOURCES
180 connect( d->mAddressBook, SIGNAL(addressBookChanged(
AddressBook*)),
181 SLOT(addressBookChanged()) );
182 connect( d->mAddressBook, SIGNAL(loadingFinished(
Resource*)),
183 SLOT(addressBookChanged()) );
186 d->loadAddressBook();
198 if ( d->mMultiple ) {
199 aItem =
dynamic_cast<AddresseeItem *
>( d->mSelectedList->topLevelItem( 0 ) );
218 if ( d->mMultiple ) {
219 const int numberOfTopItem( d->mSelectedList->topLevelItemCount() );
220 for (
int i = 0; i < numberOfTopItem; ++i ) {
221 aItem =
dynamic_cast<AddresseeItem *
>( d->mSelectedList->topLevelItem( i ) );
244 if ( dlg->exec() && dlg ) {
245 contact = dlg->addressee();
258 if ( dlg->exec() && dlg ) {
259 contacts = dlg->addressees();
267 void AddresseeDialog::Private::loadAddressBook()
269 mAddresseeList->
clear();
271 mAddresseeEdit->completionObject()->clear();
273 #ifndef KDEPIM_NO_KRESOURCES
275 for ( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) {
277 addCompletionItem( ( *it ).realName(), item );
278 addCompletionItem( ( *it ).preferredEmail(), item );
289 mItemDict.insert( str, item );
290 mAddresseeEdit->completionObject()->addItem( str );
293 void AddresseeDialog::Private::selectItem(
const QString &str )
301 mAddresseeList->blockSignals(
true );
302 mAddresseeList->setItemSelected( item,
true );
303 mAddresseeList->scrollToItem( item );
304 mAddresseeList->blockSignals(
false );
308 void AddresseeDialog::Private::updateEdit()
316 mAddresseeEdit->setSelection( 0, item->
text( 0 ).
length() );
329 if ( !selectedItem ) {
331 mSelectedDict.insert( a.
uid(), selectedItem );
335 void AddresseeDialog::Private::removeSelected()
350 void AddresseeDialog::Private::addressBookChanged()
355 #include "moc_addresseedialog.cpp"
static Addressee::List getAddressees(QWidget *parent)
Select multiple address book entries.
Special ListViewItem, that is used by the AddresseeDialog.
a QValueList of Addressee, with sorting functionality
const T & at(int i) const
~AddresseeItem()
Destroys the item.
QString realName() const
Return the name of the addressee.
QString preferredEmail() const
Return preferred email address.
int matchedLength() const
int indexIn(const QString &str, int offset, CaretMode caretMode) const
void append(const T &value)
Addressee addressee() const
Return the address chosen.
AddresseeItem(QTreeWidget *parent, const Addressee &addressee)
Constructor.
virtual ~AddresseeDialog()
Destructor.
Addressee addressee() const
Returns the addressee.
AddresseeDialog(QWidget *parent=0, bool multiple=false)
Construct addressbook entry select dialog.
QString mid(int position, int n) const
QString uid() const
Return unique identifier.
void setText(int column, const QString &text)
static StdAddressBook * self()
Returns the standard addressbook object.
virtual QString key(int column, bool ascending) const
Method used by QListView to sort the items.
Addressee::List addressees() const
Return the list of addresses chosen.
QString text(int column) const
void addLayout(QLayout *layout, int stretch)
static Addressee getAddressee(QWidget *parent)
Select a single address book entry.