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>
32#include <QtCore/QPointer>
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()) );
62class EmailSelector::Private
65 QButtonGroup *mButtonGroup;
66 QMap<QWidget *, QString> mEmailMap;
70 : KDialog( parent ), d( new Private )
72 setCaption( i18n(
"Select Email Address" ) );
74 setDefaultButton( Ok );
76 QFrame *topFrame =
new QFrame(
this );
77 setMainWidget( topFrame );
79 QBoxLayout *topLayout =
new QVBoxLayout( topFrame );
81 QGroupBox *box =
new QGroupBox( i18n(
"Email Addresses" ) );
82 d->mButtonGroup =
new QButtonGroup( box );
83 topLayout->addWidget( box );
85 QVBoxLayout *layout =
new QVBoxLayout;
87 QStringList::ConstIterator it;
88 QStringList::ConstIterator end( emails.end() );
89 for ( it = emails.begin(); it != end; ++it ) {
90 QRadioButton *button =
new QRadioButton( *it, box );
91 d->mButtonGroup->addButton( button );
92 d->mEmailMap.insert( button, *it );
93 layout->addWidget( button );
94 if ( ( *it ) == current ) {
95 button->setChecked(
true );
98 layout->addStretch( 1 );
99 box->setLayout( layout );
109 QAbstractButton *button = d->mButtonGroup->checkedButton();
114 return d->mEmailMap[button];
122 QPointer<EmailSelector> dlg =
new EmailSelector( emails, current, parent );
123 if ( dlg->exec() && dlg ) {
124 email = dlg->selected();
132class EntryItem :
public QTreeWidgetItem
135 EntryItem( QTreeWidget *parent,
const Addressee &addressee,
136 const QString &email=QString() ) :
137 QTreeWidgetItem( parent ),
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" ) );
156 QString email()
const
166class 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;
194 QTreeWidget *mEntryView;
195 QTreeWidget *mAddresseeView;
198 QPushButton *mNewButton, *mEditButton, *mRemoveButton;
199 QPushButton *mChangeEmailButton, *mRemoveEntryButton, *mAddEntryButton;
204 : QWidget( parent ), d( new Private( addressBook, this ) )
208 QBoxLayout *topLayout =
new QVBoxLayout(
this );
210 QBoxLayout *nameLayout =
new QHBoxLayout();
211 topLayout->addLayout( topLayout );
213 d->mNameCombo =
new KComboBox(
this );
214 nameLayout->addWidget( d->mNameCombo );
215 connect( d->mNameCombo, SIGNAL(activated(
int)), SLOT(updateEntryView()) );
217 d->mNewButton =
new QPushButton( i18n(
"New List..." ),
this );
218 nameLayout->addWidget( d->mNewButton );
219 connect( d->mNewButton, SIGNAL(clicked()), SLOT(newList()) );
221 d->mEditButton =
new QPushButton( i18n(
"Rename List..." ),
this );
222 nameLayout->addWidget( d->mEditButton );
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()) );
229 QGridLayout *gridLayout =
new QGridLayout();
230 topLayout->addLayout( gridLayout );
231 gridLayout->setColumnStretch( 1, 1 );
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 );
239 d->mAddresseeView =
new QTreeWidget(
this );
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()) );
248 connect( d->mAddresseeView, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,
int)),
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()) );
256 d->mEntryView =
new QTreeWidget(
this );
257 QStringList entryLabels;
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();
283void DistributionListEditorWidget::Private::save()
290void DistributionListEditorWidget::Private::slotSelectionEntryViewChanged()
292 QList<QTreeWidgetItem*> selected = mEntryView->selectedItems();
293 bool state = selected.count() > 0;
294 mChangeEmailButton->setEnabled( state );
295 mRemoveEntryButton->setEnabled( state );
298void 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();
317void 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();
340void 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();
362void DistributionListEditorWidget::Private::addEntry()
364 QList<QTreeWidgetItem*> selected = mAddresseeView->selectedItems();
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();
383void DistributionListEditorWidget::Private::removeEntry()
385 DistributionList *list = mAddressBook->findDistributionListByName( mNameCombo->currentText() );
390 QList<QTreeWidgetItem*> selected = mEntryView->selectedItems();
391 if ( selected.count() == 0 ) {
395 EntryItem *entryItem =
396 static_cast<EntryItem *
>( selected.at( 0 ) );
398 list->
removeEntry( entryItem->addressee(), entryItem->email() );
402void DistributionListEditorWidget::Private::changeEmail()
404 DistributionList *list = mAddressBook->findDistributionListByName( mNameCombo->currentText() );
409 QList<QTreeWidgetItem*> selected = mEntryView->selectedItems();
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 );
425void 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 );
453 DistributionList::Entry::List::ConstIterator it;
454 DistributionList::Entry::List::ConstIterator end( entries.constEnd() );
455 for ( it = entries.constBegin(); it != end; ++it ) {
456 new EntryItem( mEntryView, ( *it ).addressee(), ( *it ).email() );
459 QList<QTreeWidgetItem*> selected = mEntryView->selectedItems();
460 bool state = ( selected.count() != 0 );
462 mChangeEmailButton->setEnabled( state );
463 mRemoveEntryButton->setEnabled( state );
466void DistributionListEditorWidget::Private::updateAddresseeView()
468 mAddresseeView->clear();
472 for ( it = mAddressBook->constBegin(); it != end; ++it ) {
477void DistributionListEditorWidget::Private::updateNameCombo()
479 mNameCombo->addItems( mAddressBook->allDistributionListNames() );
484void DistributionListEditorWidget::Private::slotSelectionAddresseeViewChanged()
486 QList<QTreeWidgetItem*> selected = mAddresseeView->selectedItems();
487 bool state = ( selected.count() != 0 );
488 mAddEntryButton->setEnabled( state && !mNameCombo->currentText().isEmpty() );
491#include "moc_distributionlistdialog.cpp"
Address Book Const Iterator.
Special ListViewItem, that is used by the AddresseeDialog.
Addressee addressee() const
Returns the addressee.
QStringList emails() const
Return list of all email addresses.
QString preferredEmail() const
Return preferred email address.
QString realName() const
Return the name of the addressee.
virtual ~DistributionListDialog()
Destructor.
DistributionListDialog(AddressBook *ab, QWidget *parent=0)
Constructor.
QList< Entry > List
A list of Entry instances.
Distribution list of email addresses.
void insertEntry(const Addressee &, const QString &email=QString())
Insert an entry into this distribution list.
void setName(const QString &)
Set name of this list.
void removeEntry(const Addressee &, const QString &email=QString())
Remove an entry from this distribution list.
Entry::List entries() const
Return list of entries belonging to this distribution list.
static QString getEmail(const QStringList &emails, const QString ¤t, QWidget *parent=0)
Returns the user's choice from a list of possible email addresses.
QString selected() const
Returns the selected email address.
EmailSelector(const QStringList &emails, const QString ¤t, QWidget *parent=0)
Creates a dialog for selecting an email address from a list.
~EmailSelector()
Destroys the dialog instance.
Class that holds a Calendar Url (FBURL/CALADRURI/CALURI)