23 #include "distributionlistpicker.h"
26 #ifdef TDEPIM_NEW_DISTRLISTS
27 #include <libtdepim/distributionlist.h>
30 #include <tdeabc/addressbook.h>
32 #include <tdeapplication.h>
33 #include <kinputdialog.h>
34 #include <tdelistbox.h>
35 #include <tdelocale.h>
36 #include <tdemessagebox.h>
40 #include <tqpushbutton.h>
42 #include <tqvalidator.h>
44 KPIM::DistributionListPickerDialog::DistributionListPickerDialog( TDEABC::AddressBook* book, TQWidget* parent ) : KDialogBase( parent, 0, true, TQString(), Ok | Cancel | User1 ), m_book( book )
48 enableButton( Ok,
false );
49 setButtonText( User1, i18n(
"Add New Distribution List" ) );
50 TQWidget* main =
new TQWidget(
this );
51 TQGridLayout* layout =
new TQGridLayout( main );
52 layout->setSpacing( KDialog::spacingHint() );
53 m_label =
new TQLabel( main );
54 layout->addWidget( m_label, 0, 0 );
55 m_listBox =
new TDEListBox( main );
56 layout->addWidget( m_listBox, 1, 0 );
57 connect( m_listBox, TQ_SIGNAL( highlighted(
const TQString& ) ),
58 this, TQ_SLOT( entrySelected(
const TQString& ) ) );
59 connect( m_listBox, TQ_SIGNAL( selected(
const TQString& ) ),
60 this, TQ_SLOT( entrySelected(
const TQString& ) ) );
61 setMainWidget( main );
62 #ifdef TDEPIM_NEW_DISTRLISTS
63 typedef TQValueList<KPIM::DistributionList> DistListList;
64 const DistListList lists = KPIM::DistributionList::allDistributionLists( m_book );
65 for ( DistListList::ConstIterator it = lists.begin(); it != lists.end(); ++it )
67 m_listBox->insertItem ( (*it).name() );
72 void KPIM::DistributionListPickerDialog::entrySelected(
const TQString& name )
74 actionButton( Ok )->setEnabled( !name.isNull() );
77 void KPIM::DistributionListPickerDialog::setLabelText(
const TQString& text )
79 m_label->setText( text );
82 void KPIM::DistributionListPickerDialog::slotUser1()
84 #ifdef TDEPIM_NEW_DISTRLISTS
85 const TQValueList<KPIM::DistributionList> lists = KPIM::DistributionList::allDistributionLists( m_book );
86 TQStringList listNames;
87 for ( TQValueList<KPIM::DistributionList>::ConstIterator it = lists.begin(); it != lists.end(); ++it )
89 listNames += (*it).name();
92 bool validName =
false;
95 TQRegExpValidator validator( TQRegExp(
"\\S+.*" ), 0 );
96 const TQString name = KInputDialog::getText( i18n(
"Enter Name" ), i18n(
"Enter a name for the new distribution list:" ), TQString(), 0,
this, 0, &validator ).stripWhiteSpace();
100 validName = !listNames.contains( name );
104 KPIM::DistributionList list;
105 list.setName( name );
106 list.setUid( TDEApplication::randomString( 10 ) );
107 m_book->insertAddressee( list );
109 m_listBox->insertItem( name );
110 TQListBoxItem* item = m_listBox->findItem( name );
111 m_listBox->setSelected( item,
true );
115 KMessageBox::error(
this, i18n(
"A distribution list with the the name %1 already exists. Please choose another name" ).arg( name ), i18n(
"Name Exists" ) );
118 while ( !validName );
123 void KPIM::DistributionListPickerDialog::slotOk()
125 TQListBoxItem* item = m_listBox->selectedItem();
126 m_selectedDistributionList = item ? item->text() : TQString();
127 KDialogBase::slotOk();
130 void KPIM::DistributionListPickerDialog::slotCancel()
132 m_selectedDistributionList = TQString();
133 KDialogBase::slotCancel();
136 TQString KPIM::DistributionListPickerDialog::selectedDistributionList()
const
138 return m_selectedDistributionList;
141 #include "distributionlistpicker.moc"