21#include <tqlistview.h>
24#include <tqpushbutton.h>
25#include <tqcombobox.h>
26#include <kinputdialog.h>
27#include <tqbuttongroup.h>
28#include <tqradiobutton.h>
32#include <tdemessagebox.h>
34#include "addressbook.h"
35#include "addresseedialog.h"
36#include "distributionlist.h"
38#include "distributionlistdialog.h"
39#include "distributionlistdialog.moc"
44 :
KDialogBase( parent,
"", true, i18n(
"Configure Distribution Lists"),
Ok,
Ok, true)
49 connect(
this, TQ_SIGNAL(
okClicked() ), mEditor, TQ_SLOT( save() ) );
57static TQMap<TQWidget*,TQString> *sEmailMap = 0;
59EmailSelector::EmailSelector(
const TQStringList &emails,
const TQString ¤t,
65 sEmailMap =
new TQMap<TQWidget*,TQString>();
67 TQBoxLayout *topLayout =
new TQVBoxLayout( topFrame );
69 mButtonGroup =
new TQButtonGroup( 1, TQt::Horizontal, i18n(
"Email Addresses"),
71 topLayout->addWidget( mButtonGroup );
73 TQStringList::ConstIterator it;
74 for( it = emails.begin(); it != emails.end(); ++it ) {
75 TQRadioButton *button =
new TQRadioButton( *it, mButtonGroup );
76 sEmailMap->insert( button, *it );
77 if ( (*it) == current ) {
78 mButtonGroup->setButton(mButtonGroup->id(button));
83TQString EmailSelector::selected()
85 TQButton *button = mButtonGroup->selected();
86 if ( button )
return (*sEmailMap)[button];
87 return TQString::null;
90TQString EmailSelector::getEmail(
const TQStringList &emails,
const TQString ¤t,
93 EmailSelector *dlg =
new EmailSelector( emails, current, parent );
96 TQString result = dlg->selected();
103class EntryItem :
public TQListViewItem
106 EntryItem( TQListView *parent,
const Addressee &addressee,
107 const TQString &email=TQString::null ) :
108 TQListViewItem( parent ),
109 mAddressee( addressee ),
113 if( email.isEmpty() ) {
115 setText( 2, i18n(
"Yes") );
118 setText( 2, i18n(
"No") );
122 Addressee addressee()
const
127 TQString email()
const
133 Addressee mAddressee;
137DistributionListEditorWidget::DistributionListEditorWidget(
AddressBook *addressBook, TQWidget *parent) :
139 mAddressBook( addressBook )
141 kdDebug(5700) <<
"DistributionListEditor()" <<
endl;
143 TQBoxLayout *topLayout =
new TQVBoxLayout(
this );
146 TQBoxLayout *nameLayout =
new TQHBoxLayout( topLayout) ;
148 mNameCombo =
new TQComboBox(
this );
149 nameLayout->addWidget( mNameCombo );
150 connect( mNameCombo, TQ_SIGNAL( activated(
int ) ), TQ_SLOT( updateEntryView() ) );
152 mNewButton =
new TQPushButton( i18n(
"New List..."),
this );
153 nameLayout->addWidget( mNewButton );
154 connect( mNewButton, TQ_SIGNAL( clicked() ), TQ_SLOT( newList() ) );
156 mEditButton =
new TQPushButton( i18n(
"Rename List..."),
this );
157 nameLayout->addWidget( mEditButton );
158 connect( mEditButton, TQ_SIGNAL( clicked() ), TQ_SLOT( editList() ) );
160 mRemoveButton =
new TQPushButton( i18n(
"Remove List"),
this );
161 nameLayout->addWidget( mRemoveButton );
162 connect( mRemoveButton, TQ_SIGNAL( clicked() ), TQ_SLOT( removeList() ) );
164 TQGridLayout *gridLayout =
new TQGridLayout( topLayout, 3, 3 );
165 gridLayout->setColStretch(1, 1);
167 TQLabel *listLabel =
new TQLabel( i18n(
"Available addresses:"),
this );
168 gridLayout->addWidget( listLabel, 0, 0 );
170 mListLabel =
new TQLabel(
this );
171 gridLayout->addMultiCellWidget( mListLabel, 0, 0, 1, 2 );
173 mAddresseeView =
new TQListView(
this );
174 mAddresseeView->addColumn( i18n(
"Name") );
175 mAddresseeView->addColumn( i18n(
"Preferred Email") );
176 mAddresseeView->setAllColumnsShowFocus(
true );
177 gridLayout->addWidget( mAddresseeView, 1, 0 );
178 connect( mAddresseeView, TQ_SIGNAL( selectionChanged() ),
179 TQ_SLOT( slotSelectionAddresseeViewChanged() ) );
180 connect( mAddresseeView, TQ_SIGNAL( doubleClicked( TQListViewItem * ) ),
181 TQ_SLOT( addEntry() ) );
183 mAddEntryButton =
new TQPushButton( i18n(
"Add Entry"),
this );
184 mAddEntryButton->setEnabled(
false);
185 gridLayout->addWidget( mAddEntryButton, 2, 0 );
186 connect( mAddEntryButton, TQ_SIGNAL( clicked() ), TQ_SLOT( addEntry() ) );
188 mEntryView =
new TQListView(
this );
189 mEntryView->addColumn( i18n(
"Name") );
190 mEntryView->addColumn( i18n(
"Email") );
191 mEntryView->addColumn( i18n(
"Use Preferred") );
192 mEntryView->setEnabled(
false);
193 mEntryView->setAllColumnsShowFocus(
true );
194 gridLayout->addMultiCellWidget( mEntryView, 1, 1, 1, 2 );
195 connect( mEntryView, TQ_SIGNAL( selectionChanged() ),
196 TQ_SLOT( slotSelectionEntryViewChanged() ) );
198 mChangeEmailButton =
new TQPushButton( i18n(
"Change Email..."),
this );
199 gridLayout->addWidget( mChangeEmailButton, 2, 1 );
200 connect( mChangeEmailButton, TQ_SIGNAL( clicked() ), TQ_SLOT( changeEmail() ) );
202 mRemoveEntryButton =
new TQPushButton( i18n(
"Remove Entry"),
this );
203 gridLayout->addWidget( mRemoveEntryButton, 2, 2 );
204 connect( mRemoveEntryButton, TQ_SIGNAL( clicked() ), TQ_SLOT( removeEntry() ) );
206 mManager =
new DistributionListManager( mAddressBook );
209 updateAddresseeView();
213DistributionListEditorWidget::~DistributionListEditorWidget()
215 kdDebug(5700) <<
"~DistributionListEditor()" <<
endl;
220void DistributionListEditorWidget::save()
225void DistributionListEditorWidget::slotSelectionEntryViewChanged()
227 EntryItem *entryItem =
static_cast<EntryItem *
>( mEntryView->selectedItem() );
228 bool state=entryItem;
230 mChangeEmailButton->setEnabled(state);
231 mRemoveEntryButton->setEnabled(state);
234void DistributionListEditorWidget::newList()
238 i18n(
"Please enter &name:" ), TQString::null, &ok );
241 new DistributionList( mManager, name );
244 mNameCombo->insertStringList( mManager->listNames() );
245 mNameCombo->setCurrentItem( mNameCombo->count() - 1 );
248 slotSelectionAddresseeViewChanged();
251void DistributionListEditorWidget::editList()
253 TQString oldName = mNameCombo->currentText();
256 i18n(
"Please change &name:" ), oldName, &ok );
259 DistributionList *list = mManager->list( oldName );
263 mNameCombo->insertStringList( mManager->listNames() );
264 mNameCombo->setCurrentItem( mNameCombo->count() - 1 );
267 slotSelectionAddresseeViewChanged();
270void DistributionListEditorWidget::removeList()
273 i18n(
"Delete distribution list '%1'?") .arg( mNameCombo->currentText() ),
276 if ( result != KMessageBox::Continue )
return;
278 mManager->remove( mManager->list( mNameCombo->currentText() ) );
279 mNameCombo->removeItem( mNameCombo->currentItem() );
282 slotSelectionAddresseeViewChanged();
285void DistributionListEditorWidget::addEntry()
287 AddresseeItem *addresseeItem =
288 static_cast<AddresseeItem *
>( mAddresseeView->selectedItem() );
290 if( !addresseeItem ) {
291 kdDebug(5700) <<
"DLE::addEntry(): No addressee selected." <<
endl;
295 DistributionList *list = mManager->list( mNameCombo->currentText() );
297 kdDebug(5700) <<
"DLE::addEntry(): No dist list '" << mNameCombo->currentText() <<
"'" <<
endl;
303 slotSelectionAddresseeViewChanged();
306void DistributionListEditorWidget::removeEntry()
308 DistributionList *list = mManager->list( mNameCombo->currentText() );
311 EntryItem *entryItem =
312 static_cast<EntryItem *
>( mEntryView->selectedItem() );
313 if ( !entryItem )
return;
315 list->
removeEntry( entryItem->addressee(), entryItem->email() );
319void DistributionListEditorWidget::changeEmail()
321 DistributionList *list = mManager->list( mNameCombo->currentText() );
324 EntryItem *entryItem =
325 static_cast<EntryItem *
>( mEntryView->selectedItem() );
326 if ( !entryItem )
return;
328 TQString email = EmailSelector::getEmail( entryItem->addressee().
emails(),
329 entryItem->email(),
this );
330 list->
removeEntry( entryItem->addressee(), entryItem->email() );
331 list->
insertEntry( entryItem->addressee(), email );
336void DistributionListEditorWidget::updateEntryView()
338 if ( mNameCombo->currentText().isEmpty() ) {
339 mListLabel->setText( i18n(
"Selected addressees:") );
341 mListLabel->setText( i18n(
"Selected addresses in '%1':")
342 .arg( mNameCombo->currentText() ) );
347 DistributionList *list = mManager->list( mNameCombo->currentText() );
349 mEditButton->setEnabled(
false);
350 mRemoveButton->setEnabled(
false);
351 mChangeEmailButton->setEnabled(
false);
352 mRemoveEntryButton->setEnabled(
false);
353 mAddresseeView->setEnabled(
false);
354 mEntryView->setEnabled(
false);
357 mEditButton->setEnabled(
true);
358 mRemoveButton->setEnabled(
true);
359 mAddresseeView->setEnabled(
true);
360 mEntryView->setEnabled(
true);
363 DistributionList::Entry::List entries = list->
entries();
364 DistributionList::Entry::List::ConstIterator it;
365 for( it = entries.begin(); it != entries.end(); ++it ) {
366 new EntryItem( mEntryView, (*it).addressee, (*it).email );
369 EntryItem *entryItem =
static_cast<EntryItem *
>( mEntryView->selectedItem() );
370 bool state=entryItem;
372 mChangeEmailButton->setEnabled(state);
373 mRemoveEntryButton->setEnabled(state);
376void DistributionListEditorWidget::updateAddresseeView()
378 mAddresseeView->clear();
380 AddressBook::Iterator it;
381 for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) {
382 new AddresseeItem( mAddresseeView, *it );
386void DistributionListEditorWidget::updateNameCombo()
388 mNameCombo->insertStringList( mManager->listNames() );
393void DistributionListEditorWidget::slotSelectionAddresseeViewChanged()
395 AddresseeItem *addresseeItem =
396 static_cast<AddresseeItem *
>( mAddresseeView->selectedItem() );
397 bool state=addresseeItem;
398 mAddEntryButton->setEnabled( state && !mNameCombo->currentText().isEmpty());
void setMainWidget(TQWidget *widget)
KDialogBase(TQWidget *parent=0, const char *name=0, bool modal=true, const TQString &caption=TQString::null, int buttonMask=Ok|Apply|Cancel, ButtonCode defaultButton=Ok, bool separator=false, const KGuiItem &user1=KGuiItem(), const KGuiItem &user2=KGuiItem(), const KGuiItem &user3=KGuiItem())
static int warningContinueCancel(TQWidget *parent, const TQString &text, const TQString &caption=TQString::null, const KGuiItem &buttonContinue=KStdGuiItem::cont(), const TQString &dontAskAgainName=TQString::null, int options=Notify)
Addressee addressee() const
Returns the addressee.
TQStringList emails() const
Return list of all email addresses.
TQString realName() const
Return the name of the addressee.
TQString preferredEmail() const
Return preferred email address.
DistributionListDialog(AddressBook *ab, TQWidget *parent)
Constructor.
virtual ~DistributionListDialog()
Destructor.
void setName(const TQString &)
Set name of this list.
void insertEntry(const Addressee &, const TQString &email=TQString::null)
Insert an entry into this distribution list.
void removeEntry(const Addressee &, const TQString &email=TQString::null)
Remove an entry from this distribution list.
Entry::List entries() const
Return list of entries belonging to this distribution list.
kndbgstream & endl(kndbgstream &s)
kdbgstream kdDebug(int area=0)
static data, shared by ALL addressee objects
TQString name(StdAccel id)