22 #include <tqpushbutton.h>
23 #include <tqgroupbox.h>
29 #include "stdaddressbook.h"
31 #include "addresseedialog.h"
32 #include "addresseedialog.moc"
37 TQListViewItem( parent ),
38 mAddressee( addressee )
40 setText( Name, addressee.
realName() );
46 if (column == Email) {
47 TQString value = text(Email);
48 TQRegExp emailRe(
"<\\S*>");
49 int match = emailRe.search(value);
51 value = value.mid(match + 1, emailRe.matchedLength() - 2);
56 return text(column).lower();
61 Ok|Cancel, Ok, parent ), mMultiple( multiple )
63 TQWidget *topWidget = plainPage();
65 TQBoxLayout *topLayout =
new TQHBoxLayout( topWidget );
66 TQBoxLayout *listLayout =
new TQVBoxLayout;
67 topLayout->addLayout( listLayout );
69 mAddresseeList =
new KListView( topWidget );
70 mAddresseeList->
addColumn( i18n(
"Name") );
71 mAddresseeList->
addColumn( i18n(
"Email") );
72 mAddresseeList->setAllColumnsShowFocus(
true );
74 listLayout->addWidget( mAddresseeList );
75 connect( mAddresseeList, TQT_SIGNAL( doubleClicked( TQListViewItem * ) ),
76 TQT_SLOT( slotOk() ) );
77 connect( mAddresseeList, TQT_SIGNAL( selectionChanged( TQListViewItem * ) ),
78 TQT_SLOT( updateEdit( TQListViewItem * ) ) );
80 mAddresseeEdit =
new KLineEdit( topWidget );
82 connect( mAddresseeEdit->
completionObject(), TQT_SIGNAL( match(
const TQString & ) ),
83 TQT_SLOT( selectItem(
const TQString & ) ) );
84 mAddresseeEdit->setFocus();
86 listLayout->addWidget( mAddresseeEdit );
88 setInitialSize( TQSize( 450, 300 ) );
91 TQBoxLayout *selectedLayout =
new TQVBoxLayout;
92 topLayout->addLayout( selectedLayout );
93 topLayout->setSpacing( spacingHint() );
95 TQGroupBox *selectedGroup =
new TQGroupBox( 1, Qt::Horizontal, i18n(
"Selected"),
97 selectedLayout->addWidget( selectedGroup );
99 mSelectedList =
new KListView( selectedGroup );
100 mSelectedList->
addColumn( i18n(
"Name") );
101 mSelectedList->
addColumn( i18n(
"Email") );
102 mSelectedList->setAllColumnsShowFocus(
true );
104 connect( mSelectedList, TQT_SIGNAL( doubleClicked( TQListViewItem * ) ),
105 TQT_SLOT( removeSelected() ) );
107 TQPushButton *unselectButton =
new TQPushButton( i18n(
"Unselect"), selectedGroup );
108 connect ( unselectButton, TQT_SIGNAL( clicked() ), TQT_SLOT( removeSelected() ) );
110 connect( mAddresseeList, TQT_SIGNAL( clicked( TQListViewItem * ) ),
111 TQT_SLOT( addSelected( TQListViewItem * ) ) );
113 setInitialSize( TQSize( 650, 350 ) );
117 connect( mAddressBook, TQT_SIGNAL( addressBookChanged(
AddressBook* ) ),
118 TQT_SLOT( addressBookChanged() ) );
119 connect( mAddressBook, TQT_SIGNAL( loadingFinished( Resource* ) ),
120 TQT_SLOT( addressBookChanged() ) );
129 void AddresseeDialog::loadAddressBook()
131 mAddresseeList->clear();
136 for( it = mAddressBook->
begin(); it != mAddressBook->
end(); ++it ) {
138 addCompletionItem( (*it).realName(), item );
139 addCompletionItem( (*it).preferredEmail(), item );
143 void AddresseeDialog::addCompletionItem(
const TQString &str, TQListViewItem *item )
145 if ( str.isEmpty() )
return;
147 mItemDict.insert( str, item );
151 void AddresseeDialog::selectItem(
const TQString &str )
153 if ( str.isEmpty() )
return;
155 TQListViewItem *item = mItemDict.find( str );
157 mAddresseeList->blockSignals(
true );
158 mAddresseeList->setSelected( item,
true );
159 mAddresseeList->ensureItemVisible( item );
160 mAddresseeList->blockSignals(
false );
164 void AddresseeDialog::updateEdit( TQListViewItem *item )
166 mAddresseeEdit->setText( item->text( 0 ) );
167 mAddresseeEdit->setSelection( 0, item->text( 0 ).length() );
170 void AddresseeDialog::addSelected( TQListViewItem *item )
173 if ( !addrItem )
return;
177 TQListViewItem *selectedItem = mSelectedDict.find( a.
uid() );
178 if ( !selectedItem ) {
180 mSelectedDict.insert( a.
uid(), selectedItem );
184 void AddresseeDialog::removeSelected()
186 TQListViewItem *item = mSelectedList->selectedItem();
188 if ( !addrItem )
return;
199 aItem =
dynamic_cast<AddresseeItem *
>( mSelectedList->firstChild() );
201 aItem =
dynamic_cast<AddresseeItem *
>( mAddresseeList->selectedItem() );
213 TQListViewItem *item = mSelectedList->firstChild();
216 if ( aItem ) al.append( aItem->
addressee() );
217 item = item->nextSibling();
222 aItem =
dynamic_cast<AddresseeItem *
>( mAddresseeList->selectedItem() );
223 if (aItem) al.append( aItem->
addressee() );
233 int result = dlg->exec();
235 if ( result == TQDialog::Accepted ) {
247 int result = dlg->exec();
248 if ( result == TQDialog::Accepted ) {
256 void AddresseeDialog::addressBookChanged()
ConstIterator end() const
Returns an iterator pointing to the last addressee of address book.
Special ListViewItem, that is used by the AddresseeDialog.
void setFullWidth() KDE_DEPRECATED
static Addressee::List getAddressees(TQWidget *parent)
Select multiple address book entries.
Addressee addressee()
Return the address chosen.
AddresseeDialog(TQWidget *parent=0, bool multiple=false)
Construct addressbook entry select dialog.
TQString realName() const
Return the name of the addressee.
AddresseeItem(TQListView *parent, const Addressee &addressee)
Constructor.
ConstIterator begin() const
Returns an iterator pointing to the first addressee of address book.
static Addressee getAddressee(TQWidget *parent)
Select a single address book entry.
virtual TQString key(int column, bool ascending) const
Method used by TQListView to sort the items.
virtual void setCompletionMode(KGlobalSettings::Completion mode)
virtual void setIgnoreCase(bool ignoreCase)
Addressee addressee() const
Returns the addressee.
virtual int addColumn(const TQString &label, int width=-1)
Addressee::List addressees()
Return the list of addresses chosen.
virtual ~AddresseeDialog()
Destructor.
KCompletion * completionObject(bool hsig=true)
void addItem(const TQString &item)
static StdAddressBook * self()
Returns the standard addressbook object.
TQString uid() const
Return unique identifier.
Dialog for selecting address book entries.
TQString preferredEmail() const
Return preferred email address.