• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeabc
 

tdeabc

  • tdeabc
distributionlistdialog.cpp
1/*
2 This file is part of libtdeabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20
21#include <tqlistview.h>
22#include <tqlayout.h>
23#include <tqlabel.h>
24#include <tqpushbutton.h>
25#include <tqcombobox.h>
26#include <kinputdialog.h>
27#include <tqbuttongroup.h>
28#include <tqradiobutton.h>
29
30#include <tdelocale.h>
31#include <kdebug.h>
32#include <tdemessagebox.h>
33
34#include "addressbook.h"
35#include "addresseedialog.h"
36#include "distributionlist.h"
37
38#include "distributionlistdialog.h"
39#include "distributionlistdialog.moc"
40
41using namespace TDEABC;
42
43DistributionListDialog::DistributionListDialog( AddressBook *addressBook, TQWidget *parent)
44 : KDialogBase( parent, "", true, i18n("Configure Distribution Lists"), Ok, Ok, true)
45{
46 mEditor = new DistributionListEditorWidget( addressBook, this );
47 setMainWidget( mEditor );
48
49 connect( this, TQ_SIGNAL( okClicked() ), mEditor, TQ_SLOT( save() ) );
50}
51
52DistributionListDialog::~DistributionListDialog()
53{
54}
55
56// TODO KDE4: Add d-pointer to EmailSelector, make sEmailMap a member variable
57static TQMap<TQWidget*,TQString> *sEmailMap = 0;
58
59EmailSelector::EmailSelector( const TQStringList &emails, const TQString &current,
60 TQWidget *parent ) :
61 KDialogBase( KDialogBase::Plain, i18n("Select Email Address"), Ok, Ok,
62 parent )
63{
64 if (!sEmailMap)
65 sEmailMap = new TQMap<TQWidget*,TQString>();
66 TQFrame *topFrame = plainPage();
67 TQBoxLayout *topLayout = new TQVBoxLayout( topFrame );
68
69 mButtonGroup = new TQButtonGroup( 1, TQt::Horizontal, i18n("Email Addresses"),
70 topFrame );
71 topLayout->addWidget( mButtonGroup );
72
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));
79 }
80 }
81}
82
83TQString EmailSelector::selected()
84{
85 TQButton *button = mButtonGroup->selected();
86 if ( button ) return (*sEmailMap)[button];
87 return TQString::null;
88}
89
90TQString EmailSelector::getEmail( const TQStringList &emails, const TQString &current,
91 TQWidget *parent )
92{
93 EmailSelector *dlg = new EmailSelector( emails, current, parent );
94 dlg->exec();
95
96 TQString result = dlg->selected();
97
98 delete dlg;
99
100 return result;
101}
102
103class EntryItem : public TQListViewItem
104{
105 public:
106 EntryItem( TQListView *parent, const Addressee &addressee,
107 const TQString &email=TQString::null ) :
108 TQListViewItem( parent ),
109 mAddressee( addressee ),
110 mEmail( email )
111 {
112 setText( 0, addressee.realName() );
113 if( email.isEmpty() ) {
114 setText( 1, addressee.preferredEmail() );
115 setText( 2, i18n("Yes") );
116 } else {
117 setText( 1, email );
118 setText( 2, i18n("No") );
119 }
120 }
121
122 Addressee addressee() const
123 {
124 return mAddressee;
125 }
126
127 TQString email() const
128 {
129 return mEmail;
130 }
131
132 private:
133 Addressee mAddressee;
134 TQString mEmail;
135};
136
137DistributionListEditorWidget::DistributionListEditorWidget( AddressBook *addressBook, TQWidget *parent) :
138 TQWidget( parent ),
139 mAddressBook( addressBook )
140{
141 kdDebug(5700) << "DistributionListEditor()" << endl;
142
143 TQBoxLayout *topLayout = new TQVBoxLayout( this );
144 topLayout->setSpacing( KDialog::spacingHint() );
145
146 TQBoxLayout *nameLayout = new TQHBoxLayout( topLayout) ;
147
148 mNameCombo = new TQComboBox( this );
149 nameLayout->addWidget( mNameCombo );
150 connect( mNameCombo, TQ_SIGNAL( activated( int ) ), TQ_SLOT( updateEntryView() ) );
151
152 mNewButton = new TQPushButton( i18n("New List..."), this );
153 nameLayout->addWidget( mNewButton );
154 connect( mNewButton, TQ_SIGNAL( clicked() ), TQ_SLOT( newList() ) );
155
156 mEditButton = new TQPushButton( i18n("Rename List..."), this );
157 nameLayout->addWidget( mEditButton );
158 connect( mEditButton, TQ_SIGNAL( clicked() ), TQ_SLOT( editList() ) );
159
160 mRemoveButton = new TQPushButton( i18n("Remove List"), this );
161 nameLayout->addWidget( mRemoveButton );
162 connect( mRemoveButton, TQ_SIGNAL( clicked() ), TQ_SLOT( removeList() ) );
163
164 TQGridLayout *gridLayout = new TQGridLayout( topLayout, 3, 3 );
165 gridLayout->setColStretch(1, 1);
166
167 TQLabel *listLabel = new TQLabel( i18n("Available addresses:"), this );
168 gridLayout->addWidget( listLabel, 0, 0 );
169
170 mListLabel = new TQLabel( this );
171 gridLayout->addMultiCellWidget( mListLabel, 0, 0, 1, 2 );
172
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() ) );
182
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() ) );
187
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() ) );
197
198 mChangeEmailButton = new TQPushButton( i18n("Change Email..."), this );
199 gridLayout->addWidget( mChangeEmailButton, 2, 1 );
200 connect( mChangeEmailButton, TQ_SIGNAL( clicked() ), TQ_SLOT( changeEmail() ) );
201
202 mRemoveEntryButton = new TQPushButton( i18n("Remove Entry"), this );
203 gridLayout->addWidget( mRemoveEntryButton, 2, 2 );
204 connect( mRemoveEntryButton, TQ_SIGNAL( clicked() ), TQ_SLOT( removeEntry() ) );
205
206 mManager = new DistributionListManager( mAddressBook );
207 mManager->load();
208
209 updateAddresseeView();
210 updateNameCombo();
211}
212
213DistributionListEditorWidget::~DistributionListEditorWidget()
214{
215 kdDebug(5700) << "~DistributionListEditor()" << endl;
216
217 delete mManager;
218}
219
220void DistributionListEditorWidget::save()
221{
222 mManager->save();
223}
224
225void DistributionListEditorWidget::slotSelectionEntryViewChanged()
226{
227 EntryItem *entryItem = static_cast<EntryItem *>( mEntryView->selectedItem() );
228 bool state=entryItem;
229
230 mChangeEmailButton->setEnabled(state);
231 mRemoveEntryButton->setEnabled(state);
232}
233
234void DistributionListEditorWidget::newList()
235{
236 bool ok;
237 TQString name = KInputDialog::getText( i18n( "New Distribution List" ),
238 i18n( "Please enter &name:" ), TQString::null, &ok );
239 if (!ok) return;
240
241 new DistributionList( mManager, name );
242
243 mNameCombo->clear();
244 mNameCombo->insertStringList( mManager->listNames() );
245 mNameCombo->setCurrentItem( mNameCombo->count() - 1 );
246
247 updateEntryView();
248 slotSelectionAddresseeViewChanged();
249}
250
251void DistributionListEditorWidget::editList()
252{
253 TQString oldName = mNameCombo->currentText();
254 bool ok;
255 TQString name = KInputDialog::getText( i18n( "Distribution List" ),
256 i18n( "Please change &name:" ), oldName, &ok );
257 if (!ok) return;
258
259 DistributionList *list = mManager->list( oldName );
260 list->setName( name );
261
262 mNameCombo->clear();
263 mNameCombo->insertStringList( mManager->listNames() );
264 mNameCombo->setCurrentItem( mNameCombo->count() - 1 );
265
266 updateEntryView();
267 slotSelectionAddresseeViewChanged();
268}
269
270void DistributionListEditorWidget::removeList()
271{
272 int result = KMessageBox::warningContinueCancel( this,
273 i18n("Delete distribution list '%1'?") .arg( mNameCombo->currentText() ),
274 TQString::null, KStdGuiItem::del() );
275
276 if ( result != KMessageBox::Continue ) return;
277
278 mManager->remove( mManager->list( mNameCombo->currentText() ) );
279 mNameCombo->removeItem( mNameCombo->currentItem() );
280
281 updateEntryView();
282 slotSelectionAddresseeViewChanged();
283}
284
285void DistributionListEditorWidget::addEntry()
286{
287 AddresseeItem *addresseeItem =
288 static_cast<AddresseeItem *>( mAddresseeView->selectedItem() );
289
290 if( !addresseeItem ) {
291 kdDebug(5700) << "DLE::addEntry(): No addressee selected." << endl;
292 return;
293 }
294
295 DistributionList *list = mManager->list( mNameCombo->currentText() );
296 if ( !list ) {
297 kdDebug(5700) << "DLE::addEntry(): No dist list '" << mNameCombo->currentText() << "'" << endl;
298 return;
299 }
300
301 list->insertEntry( addresseeItem->addressee() );
302 updateEntryView();
303 slotSelectionAddresseeViewChanged();
304}
305
306void DistributionListEditorWidget::removeEntry()
307{
308 DistributionList *list = mManager->list( mNameCombo->currentText() );
309 if ( !list ) return;
310
311 EntryItem *entryItem =
312 static_cast<EntryItem *>( mEntryView->selectedItem() );
313 if ( !entryItem ) return;
314
315 list->removeEntry( entryItem->addressee(), entryItem->email() );
316 delete entryItem;
317}
318
319void DistributionListEditorWidget::changeEmail()
320{
321 DistributionList *list = mManager->list( mNameCombo->currentText() );
322 if ( !list ) return;
323
324 EntryItem *entryItem =
325 static_cast<EntryItem *>( mEntryView->selectedItem() );
326 if ( !entryItem ) return;
327
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 );
332
333 updateEntryView();
334}
335
336void DistributionListEditorWidget::updateEntryView()
337{
338 if ( mNameCombo->currentText().isEmpty() ) {
339 mListLabel->setText( i18n("Selected addressees:") );
340 } else {
341 mListLabel->setText( i18n("Selected addresses in '%1':")
342 .arg( mNameCombo->currentText() ) );
343 }
344
345 mEntryView->clear();
346
347 DistributionList *list = mManager->list( mNameCombo->currentText() );
348 if ( !list ) {
349 mEditButton->setEnabled(false);
350 mRemoveButton->setEnabled(false);
351 mChangeEmailButton->setEnabled(false);
352 mRemoveEntryButton->setEnabled(false);
353 mAddresseeView->setEnabled(false);
354 mEntryView->setEnabled(false);
355 return;
356 } else {
357 mEditButton->setEnabled(true);
358 mRemoveButton->setEnabled(true);
359 mAddresseeView->setEnabled(true);
360 mEntryView->setEnabled(true);
361 }
362
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 );
367 }
368
369 EntryItem *entryItem = static_cast<EntryItem *>( mEntryView->selectedItem() );
370 bool state=entryItem;
371
372 mChangeEmailButton->setEnabled(state);
373 mRemoveEntryButton->setEnabled(state);
374}
375
376void DistributionListEditorWidget::updateAddresseeView()
377{
378 mAddresseeView->clear();
379
380 AddressBook::Iterator it;
381 for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) {
382 new AddresseeItem( mAddresseeView, *it );
383 }
384}
385
386void DistributionListEditorWidget::updateNameCombo()
387{
388 mNameCombo->insertStringList( mManager->listNames() );
389
390 updateEntryView();
391}
392
393void DistributionListEditorWidget::slotSelectionAddresseeViewChanged()
394{
395 AddresseeItem *addresseeItem =
396 static_cast<AddresseeItem *>( mAddresseeView->selectedItem() );
397 bool state=addresseeItem;
398 mAddEntryButton->setEnabled( state && !mNameCombo->currentText().isEmpty());
399}
KDialogBase
KDialogBase::setMainWidget
void setMainWidget(TQWidget *widget)
KDialogBase::plainPage
TQFrame * plainPage()
KDialogBase::okClicked
void okClicked()
KDialog::spacingHint
static int spacingHint()
KInputDialog::getText
static TQString getText(const TQString &caption, const TQString &label, const TQString &value=TQString::null, bool *ok=0, TQWidget *parent=0, const char *name=0, TQValidator *validator=0, const TQString &mask=TQString::null)
KMessageBox::warningContinueCancel
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)
KStdGuiItem::del
static KGuiItem del()
TDEABC::AddressBook::Iterator
Address Book Iterator.
Definition: addressbook.h:58
TDEABC::AddressBook
Address Book.
Definition: addressbook.h:44
TDEABC::AddressBook::begin
ConstIterator begin() const
Returns an iterator pointing to the first addressee of address book.
Definition: addressbook.cpp:428
TDEABC::AddressBook::end
ConstIterator end() const
Returns an iterator pointing to the last addressee of address book.
Definition: addressbook.cpp:468
TDEABC::AddresseeItem
Special ListViewItem, that is used by the AddresseeDialog.
Definition: addresseedialog.h:38
TDEABC::AddresseeItem::addressee
Addressee addressee() const
Returns the addressee.
Definition: addresseedialog.h:59
TDEABC::Addressee
address book entry
Definition: addressee.src.h:75
TDEABC::Addressee::realName
TQString realName() const
Return the name of the addressee.
Definition: addressee.src.cpp:361
TDEABC::Addressee::preferredEmail
TQString preferredEmail() const
Return preferred email address.
Definition: addressee.src.cpp:445
TDEABC::DistributionListDialog::~DistributionListDialog
virtual ~DistributionListDialog()
Destructor.
Definition: distributionlistdialog.cpp:52
TDEABC::DistributionListEditorWidget
Helper class.
Definition: distributionlistdialog.h:102
TDEABC::DistributionListManager
Manager of distribution lists.
Definition: distributionlist.h:123
TDEABC::DistributionListManager::list
DistributionList * list(const TQString &name)
Return distribution list with given name.
Definition: distributionlist.cpp:135
TDEABC::DistributionListManager::save
bool save()
Save distribution lists to disk.
Definition: distributionlist.cpp:232
TDEABC::DistributionListManager::remove
void remove(DistributionList *)
Remove distribution list.
Definition: distributionlist.cpp:160
TDEABC::DistributionListManager::listNames
TQStringList listNames()
Return names of all distribution lists managed by this manager.
Definition: distributionlist.cpp:174
TDEABC::DistributionList
Distribution list of email addresses.
Definition: distributionlist.h:40
TDEABC::DistributionList::setName
void setName(const TQString &)
Set name of this list.
Definition: distributionlist.cpp:45
TDEABC::DistributionList::insertEntry
void insertEntry(const Addressee &, const TQString &email=TQString::null)
Insert an entry into this distribution list.
Definition: distributionlist.cpp:55
TDEABC::DistributionList::removeEntry
void removeEntry(const Addressee &, const TQString &email=TQString::null)
Remove an entry from this distribution list.
Definition: distributionlist.cpp:77
TDEABC::DistributionList::entries
Entry::List entries() const
Return list of entries belonging to this distribution list.
Definition: distributionlist.cpp:106
TDEABC::EmailSelector
Helper class.
Definition: distributionlistdialog.h:84
endl
kndbgstream & endl(kndbgstream &s)
kdDebug
kdbgstream kdDebug(int area=0)
TDEABC
static data, shared by ALL addressee objects
Definition: address.h:48
TDEStdAccel::name
TQString name(StdAccel id)
tdelocale.h

tdeabc

Skip menu "tdeabc"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdeabc

Skip menu "tdeabc"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeabc by doxygen 1.9.4
This website is maintained by Timothy Pearson.