21 #include <tqlistview.h>
23 #include <tqpushbutton.h>
24 #include <tqcombobox.h>
25 #include <tqbuttongroup.h>
26 #include <tqradiobutton.h>
28 #include <kinputdialog.h>
32 #include "addressbook.h"
33 #include "addresseedialog.h"
34 #include "distributionlist.h"
36 #include "distributionlisteditor.h"
37 #include "distributionlisteditor.moc"
41 EmailSelectDialog::EmailSelectDialog(
const TQStringList &emails,
const TQString ¤t,
46 TQFrame *topFrame = plainPage();
47 TQBoxLayout *topLayout =
new TQVBoxLayout( topFrame );
49 mButtonGroup =
new TQButtonGroup( 1, Qt::Horizontal, i18n(
"Email Addresses"),
51 mButtonGroup->setRadioButtonExclusive(
true );
52 topLayout->addWidget( mButtonGroup );
54 TQStringList::ConstIterator it;
55 for( it = emails.begin(); it != emails.end(); ++it ) {
56 TQRadioButton *button =
new TQRadioButton( *it, mButtonGroup );
57 if ( (*it) == current ) {
58 button->setDown(
true );
63 TQString EmailSelectDialog::selected()
65 TQButton *button = mButtonGroup->selected();
66 if ( button )
return button->text();
67 return TQString::null;
70 TQString EmailSelectDialog::getEmail(
const TQStringList &emails,
const TQString ¤t,
73 EmailSelectDialog *dlg =
new EmailSelectDialog( emails, current, parent );
76 TQString result = dlg->selected();
83 class EditEntryItem :
public TQListViewItem
86 EditEntryItem( TQListView *parent,
const Addressee &addressee,
87 const TQString &email=TQString::null ) :
88 TQListViewItem( parent ),
89 mAddressee( addressee ),
93 if( email.isEmpty() ) {
95 setText( 2, i18n(
"Yes") );
98 setText( 2, i18n(
"No") );
107 TQString email()
const
117 DistributionListEditor::DistributionListEditor(
AddressBook *addressBook, TQWidget *parent) :
119 mAddressBook( addressBook )
121 kdDebug(5700) <<
"DistributionListEditor()" <<
endl;
123 TQBoxLayout *topLayout =
new TQVBoxLayout(
this );
124 topLayout->setMargin( KDialog::marginHint() );
125 topLayout->setSpacing( KDialog::spacingHint() );
127 TQBoxLayout *nameLayout =
new TQHBoxLayout( topLayout) ;
129 mNameCombo =
new TQComboBox(
this );
130 nameLayout->addWidget( mNameCombo );
131 connect( mNameCombo, TQT_SIGNAL( activated(
int ) ), TQT_SLOT( updateEntryView() ) );
133 newButton =
new TQPushButton( i18n(
"New List"),
this );
134 nameLayout->addWidget( newButton );
135 connect( newButton, TQT_SIGNAL( clicked() ), TQT_SLOT( newList() ) );
137 removeButton =
new TQPushButton( i18n(
"Remove List"),
this );
138 nameLayout->addWidget( removeButton );
139 connect( removeButton, TQT_SIGNAL( clicked() ), TQT_SLOT( removeList() ) );
141 mEntryView =
new TQListView(
this );
142 mEntryView->addColumn( i18n(
"Name") );
143 mEntryView->addColumn( i18n(
"Email") );
144 mEntryView->addColumn( i18n(
"Use Preferred") );
145 topLayout->addWidget( mEntryView );
146 connect(mEntryView,TQT_SIGNAL(selectionChanged ()),
this, TQT_SLOT(slotSelectionEntryViewChanged()));
148 changeEmailButton =
new TQPushButton( i18n(
"Change Email"),
this );
149 topLayout->addWidget( changeEmailButton );
150 connect( changeEmailButton, TQT_SIGNAL( clicked() ), TQT_SLOT( changeEmail() ) );
152 removeEntryButton =
new TQPushButton( i18n(
"Remove Entry"),
this );
153 topLayout->addWidget( removeEntryButton );
154 connect( removeEntryButton, TQT_SIGNAL( clicked() ), TQT_SLOT( removeEntry() ) );
156 addEntryButton =
new TQPushButton( i18n(
"Add Entry"),
this );
157 topLayout->addWidget( addEntryButton );
158 connect( addEntryButton, TQT_SIGNAL( clicked() ), TQT_SLOT( addEntry() ) );
160 mAddresseeView =
new TQListView(
this );
161 mAddresseeView->addColumn( i18n(
"Name") );
162 mAddresseeView->addColumn( i18n(
"Preferred Email") );
163 topLayout->addWidget( mAddresseeView );
166 connect(mAddresseeView,TQT_SIGNAL(selectionChanged ()),
this, TQT_SLOT(slotSelectionAddresseeViewChanged()));
171 updateAddresseeView();
173 removeButton->setEnabled(!mManager->
listNames().isEmpty());
176 DistributionListEditor::~DistributionListEditor()
178 kdDebug(5700) <<
"~DistributionListEditor()" <<
endl;
184 void DistributionListEditor::slotSelectionEntryViewChanged()
186 EditEntryItem *entryItem =
dynamic_cast<EditEntryItem *
>( mEntryView->selectedItem() );
187 bool state = (entryItem != 0L);
189 changeEmailButton->setEnabled(state);
190 removeEntryButton->setEnabled(state);
193 void DistributionListEditor::newList()
197 i18n(
"Please enter name:"),
198 TQString::null, &ok,
this );
204 mNameCombo->insertItem( name );
205 removeButton->setEnabled(
true);
209 void DistributionListEditor::removeList()
211 mManager->
remove( mManager->
list( mNameCombo->currentText() ) );
212 mNameCombo->removeItem( mNameCombo->currentItem() );
213 removeButton->setEnabled(!mManager->
listNames().isEmpty());
214 addEntryButton->setEnabled( !mNameCombo->currentText().isEmpty());
218 void DistributionListEditor::addEntry()
221 dynamic_cast<AddresseeItem *
>( mAddresseeView->selectedItem() );
223 if( !addresseeItem ) {
224 kdDebug(5700) <<
"DLE::addEntry(): No addressee selected." <<
endl;
230 kdDebug(5700) <<
"DLE::addEntry(): No dist list '" << mNameCombo->currentText() <<
"'" <<
endl;
236 slotSelectionAddresseeViewChanged();
239 void DistributionListEditor::removeEntry()
244 EditEntryItem *entryItem =
245 dynamic_cast<EditEntryItem *
>( mEntryView->selectedItem() );
246 if ( !entryItem )
return;
248 list->
removeEntry( entryItem->addressee(), entryItem->email() );
252 void DistributionListEditor::changeEmail()
257 EditEntryItem *entryItem =
258 dynamic_cast<EditEntryItem *
>( mEntryView->selectedItem() );
259 if ( !entryItem )
return;
261 TQString email = EmailSelectDialog::getEmail( entryItem->addressee().emails(),
262 entryItem->email(), this );
263 list->
removeEntry( entryItem->addressee(), entryItem->email() );
264 list->
insertEntry( entryItem->addressee(), email );
269 void DistributionListEditor::updateEntryView()
275 DistributionList::Entry::List entries = list->
entries();
276 DistributionList::Entry::List::ConstIterator it;
277 for( it = entries.begin(); it != entries.end(); ++it ) {
278 new EditEntryItem( mEntryView, (*it).addressee, (*it).email );
280 EditEntryItem *entryItem =
dynamic_cast<EditEntryItem *
>( mEntryView->selectedItem() );
281 bool state = (entryItem != 0L);
283 changeEmailButton->setEnabled(state);
284 removeEntryButton->setEnabled(state);
287 void DistributionListEditor::updateAddresseeView()
289 mAddresseeView->clear();
292 for( it = mAddressBook->
begin(); it != mAddressBook->
end(); ++it ) {
297 void DistributionListEditor::updateNameCombo()
299 mNameCombo->insertStringList( mManager->
listNames() );
304 void DistributionListEditor::slotSelectionAddresseeViewChanged()
307 dynamic_cast<AddresseeItem *
>( mAddresseeView->selectedItem() );
308 bool state = (addresseeItem != 0L);
309 addEntryButton->setEnabled( state && !mNameCombo->currentText().isEmpty());
Addressee addressee() const
Returns the addressee.
ConstIterator end() const
Returns an iterator pointing to the last addressee of address book.
Special ListViewItem, that is used by the AddresseeDialog.
kdbgstream kdDebug(int area=0)
Entry::List entries() const
Return list of entries belonging to this distribution list.
TQStringList listNames()
Return names of all distribution lists managed by this manager.
TQString realName() const
Return the name of the addressee.
static data, shared by ALL addressee objects
void removeEntry(const Addressee &, const TQString &email=TQString::null)
Remove an entry from this distribution list.
bool save()
Save distribution lists to disk.
ConstIterator begin() const
Returns an iterator pointing to the first addressee of address book.
Distribution list of email addresses.
bool load()
Load distribution lists form disk.
void remove(DistributionList *)
Remove distribution list.
DistributionList * list(const TQString &name)
Return distribution list with given name.
Manager of distribution lists.
TQString preferredEmail() const
Return preferred email address.
kndbgstream & endl(kndbgstream &s)
void insertEntry(const Addressee &, const TQString &email=TQString::null)
Insert an entry into this distribution list.
TQString name(StdAccel id)