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 )
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 )
65 TQBoxLayout *topLayout =
new TQHBoxLayout( topWidget );
66 TQBoxLayout *listLayout =
new TQVBoxLayout;
67 topLayout->addLayout( listLayout );
70 mAddresseeList->
addColumn( i18n(
"Name") );
71 mAddresseeList->
addColumn( i18n(
"Email") );
72 mAddresseeList->setAllColumnsShowFocus(
true );
74 listLayout->addWidget( mAddresseeList );
75 connect( mAddresseeList, TQ_SIGNAL( doubleClicked( TQListViewItem * ) ),
77 connect( mAddresseeList, TQ_SIGNAL( selectionChanged( TQListViewItem * ) ),
78 TQ_SLOT( updateEdit( TQListViewItem * ) ) );
80 mAddresseeEdit =
new KLineEdit( topWidget );
82 connect( mAddresseeEdit->
completionObject(), TQ_SIGNAL( match(
const TQString & ) ),
83 TQ_SLOT( selectItem(
const TQString & ) ) );
84 mAddresseeEdit->setFocus();
86 listLayout->addWidget( mAddresseeEdit );
91 TQBoxLayout *selectedLayout =
new TQVBoxLayout;
92 topLayout->addLayout( selectedLayout );
95 TQGroupBox *selectedGroup =
new TQGroupBox( 1, TQt::Horizontal, i18n(
"Selected"),
97 selectedLayout->addWidget( selectedGroup );
100 mSelectedList->
addColumn( i18n(
"Name") );
101 mSelectedList->
addColumn( i18n(
"Email") );
102 mSelectedList->setAllColumnsShowFocus(
true );
104 connect( mSelectedList, TQ_SIGNAL( doubleClicked( TQListViewItem * ) ),
105 TQ_SLOT( removeSelected() ) );
107 TQPushButton *unselectButton =
new TQPushButton( i18n(
"Unselect"), selectedGroup );
108 connect ( unselectButton, TQ_SIGNAL( clicked() ), TQ_SLOT( removeSelected() ) );
110 connect( mAddresseeList, TQ_SIGNAL( clicked( TQListViewItem * ) ),
111 TQ_SLOT( addSelected( TQListViewItem * ) ) );
117 connect( mAddressBook, TQ_SIGNAL( addressBookChanged(
AddressBook* ) ),
118 TQ_SLOT( addressBookChanged() ) );
119 connect( mAddressBook, TQ_SIGNAL( loadingFinished( Resource* ) ),
120 TQ_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()
void setInitialSize(const TQSize &s, bool noResize=false)
virtual void setText(const TQString &)
virtual void setCompletionMode(TDEGlobalSettings::Completion mode)
ConstIterator begin() const
Returns an iterator pointing to the first addressee of address book.
ConstIterator end() const
Returns an iterator pointing to the last addressee of address book.
Dialog for selecting address book entries.
AddresseeDialog(TQWidget *parent=0, bool multiple=false)
Construct addressbook entry select dialog.
static Addressee getAddressee(TQWidget *parent)
Select a single address book entry.
virtual ~AddresseeDialog()
Destructor.
static Addressee::List getAddressees(TQWidget *parent)
Select multiple address book entries.
Addressee addressee()
Return the address chosen.
Addressee::List addressees()
Return the list of addresses chosen.
Special ListViewItem, that is used by the AddresseeDialog.
Addressee addressee() const
Returns the addressee.
AddresseeItem(TQListView *parent, const Addressee &addressee)
Constructor.
virtual TQString key(int column, bool ascending) const
Method used by TQListView to sort the items.
TQString realName() const
Return the name of the addressee.
TQString uid() const
Return unique identifier.
TQString preferredEmail() const
Return preferred email address.
static StdAddressBook * self()
Returns the standard addressbook object.
TDECompletion * completionObject(bool hsig=true)
virtual void setIgnoreCase(bool ignoreCase)
void addItem(const TQString &item)
virtual int addColumn(const TQString &label, int width=-1)
void setFullWidth() TDE_DEPRECATED
static data, shared by ALL addressee objects