21 #include "distributionlistdialog.h"
22 #include "distributionlist.h"
23 #include "addressbook.h"
24 #include "addresseedialog.h"
26 #include <kinputdialog.h>
27 #include <klocalizedstring.h>
29 #include <kmessagebox.h>
30 #include <kcombobox.h>
32 #include <QtCore/QPointer>
33 #include <QTreeWidget>
36 #include <QPushButton>
38 #include <QButtonGroup>
39 #include <QRadioButton>
44 : KDialog( parent ), d( 0 )
47 setCaption( i18n(
"Configure Distribution Lists" ) );
49 setDefaultButton( Ok );
50 showButtonSeparator(
true );
53 setMainWidget( editor );
55 connect(
this, SIGNAL(okClicked()), editor, SLOT(save()) );
62 class EmailSelector::Private
70 : KDialog( parent ), d( new Private )
72 setCaption( i18n(
"Select Email Address" ) );
74 setDefaultButton( Ok );
77 setMainWidget( topFrame );
89 for ( it = emails.
begin(); it != end; ++it ) {
91 d->mButtonGroup->addButton( button );
92 d->mEmailMap.insert( button, *it );
94 if ( ( *it ) == current ) {
114 return d->mEmailMap[button];
123 if ( dlg->exec() && dlg ) {
124 email = dlg->selected();
138 mAddressee( addressee ),
142 if ( email.isEmpty() ) {
144 setText( 2, i18nc(
"this the preferred email address",
"Yes" ) );
147 setText( 2, i18nc(
"this is not the preferred email address",
"No" ) );
166 class DistributionListEditorWidget::Private
170 : mParent( parent ), mAddressBook( addressBook )
184 void updateEntryView();
185 void updateAddresseeView();
186 void updateNameCombo();
187 void slotSelectionEntryViewChanged();
188 void slotSelectionAddresseeViewChanged();
192 KComboBox *mNameCombo;
198 QPushButton *mNewButton, *mEditButton, *mRemoveButton;
199 QPushButton *mChangeEmailButton, *mRemoveEntryButton, *mAddEntryButton;
204 :
QWidget( parent ), d( new Private( addressBook, this ) )
213 d->mNameCombo =
new KComboBox(
this );
215 connect( d->mNameCombo, SIGNAL(activated(
int)), SLOT(updateEntryView()) );
217 d->mNewButton =
new QPushButton( i18n(
"New List..." ),
this );
219 connect( d->mNewButton, SIGNAL(clicked()), SLOT(newList()) );
221 d->mEditButton =
new QPushButton( i18n(
"Rename List..." ),
this );
223 connect( d->mEditButton, SIGNAL(clicked()), SLOT(editList()) );
225 d->mRemoveButton =
new QPushButton( i18n(
"Remove List" ),
this );
226 nameLayout->
addWidget( d->mRemoveButton );
227 connect( d->mRemoveButton, SIGNAL(clicked()), SLOT(removeList()) );
233 QLabel *listLabel =
new QLabel( i18n(
"Available addresses:" ),
this );
234 gridLayout->
addWidget( listLabel, 0, 0 );
236 d->mListLabel =
new QLabel(
this );
237 gridLayout->
addWidget( d->mListLabel, 0, 0, 1, 2 );
240 d->mAddresseeView->setColumnCount( 2 );
242 labels << i18nc(
"@title:column addressee name",
"Name" )
243 << i18nc(
"@title:column addressee preferred email",
"Preferred Email" );
244 d->mAddresseeView->setHeaderLabels( labels );
245 gridLayout->
addWidget( d->mAddresseeView, 1, 0 );
246 connect( d->mAddresseeView, SIGNAL(itemSelectionChanged()),
247 SLOT(slotSelectionAddresseeViewChanged()) );
251 d->mAddEntryButton =
new QPushButton( i18n(
"Add Entry" ),
this );
252 d->mAddEntryButton->setEnabled(
false );
253 gridLayout->
addWidget( d->mAddEntryButton, 2, 0 );
254 connect( d->mAddEntryButton, SIGNAL(clicked()), SLOT(addEntry()) );
258 entryLabels << i18nc(
"@title:column addressee name",
"Name" )
259 << i18nc(
"@title:column addressee preferred email",
"Email" )
260 << i18nc(
"@title:column use preferred email",
"Use Preferred" );
261 d->mEntryView->setEnabled(
false );
262 gridLayout->
addWidget( d->mEntryView, 1, 1, 1, 2 );
263 connect( d->mEntryView, SIGNAL(itemSelectionChanged()),
264 SLOT(slotSelectionEntryViewChanged()) );
266 d->mChangeEmailButton =
new QPushButton( i18n(
"Change Email..." ),
this );
267 gridLayout->
addWidget( d->mChangeEmailButton, 2, 1 );
268 connect( d->mChangeEmailButton, SIGNAL(clicked()), SLOT(changeEmail()) );
270 d->mRemoveEntryButton =
new QPushButton( i18n(
"Remove Entry" ),
this );
271 gridLayout->
addWidget( d->mRemoveEntryButton, 2, 2 );
272 connect( d->mRemoveEntryButton, SIGNAL(clicked()), SLOT(removeEntry()) );
274 d->updateAddresseeView();
275 d->updateNameCombo();
283 void DistributionListEditorWidget::Private::save()
290 void DistributionListEditorWidget::Private::slotSelectionEntryViewChanged()
293 bool state = selected.
count() > 0;
294 mChangeEmailButton->setEnabled( state );
295 mRemoveEntryButton->setEnabled( state );
298 void DistributionListEditorWidget::Private::newList()
301 QString name = KInputDialog::getText( i18n(
"New Distribution List" ),
302 i18n(
"Please enter &name:" ),
QString(), &ok );
307 mAddressBook->createDistributionList( name );
310 mNameCombo->addItems( mAddressBook->allDistributionListNames() );
311 mNameCombo->setCurrentIndex( mNameCombo->count() - 1 );
314 slotSelectionAddresseeViewChanged();
317 void DistributionListEditorWidget::Private::editList()
319 QString oldName = mNameCombo->currentText();
321 QString name = KInputDialog::getText( i18n(
"Distribution List" ),
322 i18n(
"Please change &name:" ), oldName, &ok );
327 DistributionList *list = mAddressBook->findDistributionListByName( oldName );
333 mNameCombo->addItems( mAddressBook->allDistributionListNames() );
334 mNameCombo->setCurrentIndex( mNameCombo->count() - 1 );
337 slotSelectionAddresseeViewChanged();
340 void DistributionListEditorWidget::Private::removeList()
342 int result = KMessageBox::warningContinueCancel( mParent,
343 i18n(
"Delete distribution list '%1'?", mNameCombo->currentText() ),
344 QString(), KStandardGuiItem::del() );
346 if ( result != KMessageBox::Continue ) {
350 DistributionList *list = mAddressBook->findDistributionListByName( mNameCombo->currentText() );
354 mAddressBook->removeDistributionList( list );
355 mNameCombo->removeItem( mNameCombo->currentIndex() );
359 slotSelectionAddresseeViewChanged();
362 void DistributionListEditorWidget::Private::addEntry()
365 if ( selected.
count() == 0 ) {
366 kDebug() <<
"No addressee selected.";
372 DistributionList *list = mAddressBook->findDistributionListByName( mNameCombo->currentText() );
374 kDebug() <<
"No dist list '" << mNameCombo->currentText() <<
"'";
380 slotSelectionAddresseeViewChanged();
383 void DistributionListEditorWidget::Private::removeEntry()
385 DistributionList *list = mAddressBook->findDistributionListByName( mNameCombo->currentText() );
391 if ( selected.
count() == 0 ) {
395 EntryItem *entryItem =
396 static_cast<EntryItem *
>( selected.
at( 0 ) );
398 list->
removeEntry( entryItem->addressee(), entryItem->email() );
402 void DistributionListEditorWidget::Private::changeEmail()
404 DistributionList *list = mAddressBook->findDistributionListByName( mNameCombo->currentText() );
410 if ( selected.
count() == 0 ) {
414 EntryItem *entryItem =
415 static_cast<EntryItem *
>( selected.
at( 0 ) );
418 entryItem->email(), mParent );
419 list->
removeEntry( entryItem->addressee(), entryItem->email() );
420 list->
insertEntry( entryItem->addressee(), email );
425 void DistributionListEditorWidget::Private::updateEntryView()
427 if ( mNameCombo->currentText().isEmpty() ) {
428 mListLabel->setText( i18n(
"Selected addressees:" ) );
430 mListLabel->setText( i18n(
"Selected addresses in '%1':",
431 mNameCombo->currentText() ) );
436 DistributionList *list = mAddressBook->findDistributionListByName( mNameCombo->currentText() );
438 mEditButton->setEnabled(
false );
439 mRemoveButton->setEnabled(
false );
440 mChangeEmailButton->setEnabled(
false );
441 mRemoveEntryButton->setEnabled(
false );
442 mAddresseeView->setEnabled(
false );
443 mEntryView->setEnabled(
false );
446 mEditButton->setEnabled(
true );
447 mRemoveButton->setEnabled(
true );
448 mAddresseeView->setEnabled(
true );
449 mEntryView->setEnabled(
true );
455 for ( it = entries.
constBegin(); it != end; ++it ) {
456 new EntryItem( mEntryView, ( *it ).addressee(), ( *it ).email() );
460 bool state = ( selected.
count() != 0 );
462 mChangeEmailButton->setEnabled( state );
463 mRemoveEntryButton->setEnabled( state );
466 void DistributionListEditorWidget::Private::updateAddresseeView()
468 mAddresseeView->
clear();
472 for ( it = mAddressBook->constBegin(); it != end; ++it ) {
477 void DistributionListEditorWidget::Private::updateNameCombo()
479 mNameCombo->addItems( mAddressBook->allDistributionListNames() );
484 void DistributionListEditorWidget::Private::slotSelectionAddresseeViewChanged()
487 bool state = ( selected.
count() != 0 );
488 mAddEntryButton->setEnabled( state && !mNameCombo->currentText().isEmpty() );
491 #include "moc_distributionlistdialog.cpp"
Entry::List entries() const
Return list of entries belonging to this distribution list.
Special ListViewItem, that is used by the AddresseeDialog.
EmailSelector(const QStringList &emails, const QString ¤t, QWidget *parent=0)
Creates a dialog for selecting an email address from a list.
void removeEntry(const Addressee &, const QString &email=QString())
Remove an entry from this distribution list.
DistributionListDialog(AddressBook *ab, QWidget *parent=0)
Constructor.
void insertEntry(const Addressee &, const QString &email=QString())
Insert an entry into this distribution list.
const T & at(int i) const
Distribution list of email addresses.
QString realName() const
Return the name of the addressee.
QString preferredEmail() const
Return preferred email address.
static QString getEmail(const QStringList &emails, const QString ¤t, QWidget *parent=0)
Returns the user's choice from a list of possible email addresses.
int count(const T &value) const
Address Book Const Iterator.
Addressee addressee() const
Returns the addressee.
void addStretch(int stretch)
void setColumnStretch(int column, int stretch)
virtual ~DistributionListDialog()
Destructor.
~EmailSelector()
Destroys the dialog instance.
const_iterator constEnd() const
const_iterator constBegin() const
void setName(const QString &)
Set name of this list.
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QString selected() const
Returns the selected email address.
void addLayout(QLayout *layout, int stretch)