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, TQt::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 );
127 TQBoxLayout *nameLayout =
new TQHBoxLayout( topLayout) ;
129 mNameCombo =
new TQComboBox(
this );
130 nameLayout->addWidget( mNameCombo );
131 connect( mNameCombo, TQ_SIGNAL( activated(
int ) ), TQ_SLOT( updateEntryView() ) );
133 newButton =
new TQPushButton( i18n(
"New List"),
this );
134 nameLayout->addWidget( newButton );
135 connect( newButton, TQ_SIGNAL( clicked() ), TQ_SLOT( newList() ) );
137 removeButton =
new TQPushButton( i18n(
"Remove List"),
this );
138 nameLayout->addWidget( removeButton );
139 connect( removeButton, TQ_SIGNAL( clicked() ), TQ_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,TQ_SIGNAL(selectionChanged ()),
this, TQ_SLOT(slotSelectionEntryViewChanged()));
148 changeEmailButton =
new TQPushButton( i18n(
"Change Email"),
this );
149 topLayout->addWidget( changeEmailButton );
150 connect( changeEmailButton, TQ_SIGNAL( clicked() ), TQ_SLOT( changeEmail() ) );
152 removeEntryButton =
new TQPushButton( i18n(
"Remove Entry"),
this );
153 topLayout->addWidget( removeEntryButton );
154 connect( removeEntryButton, TQ_SIGNAL( clicked() ), TQ_SLOT( removeEntry() ) );
156 addEntryButton =
new TQPushButton( i18n(
"Add Entry"),
this );
157 topLayout->addWidget( addEntryButton );
158 connect( addEntryButton, TQ_SIGNAL( clicked() ), TQ_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,TQ_SIGNAL(selectionChanged ()),
this, TQ_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());