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

tdeabc

  • tdeabc
distributionlisteditor.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 <tqpushbutton.h>
24#include <tqcombobox.h>
25#include <tqbuttongroup.h>
26#include <tqradiobutton.h>
27
28#include <kinputdialog.h>
29#include <tdelocale.h>
30#include <kdebug.h>
31
32#include "addressbook.h"
33#include "addresseedialog.h"
34#include "distributionlist.h"
35
36#include "distributionlisteditor.h"
37#include "distributionlisteditor.moc"
38
39using namespace TDEABC;
40
41EmailSelectDialog::EmailSelectDialog( const TQStringList &emails, const TQString &current,
42 TQWidget *parent ) :
43 KDialogBase( KDialogBase::Plain, i18n("Select Email Address"), Ok, Ok,
44 parent )
45{
46 TQFrame *topFrame = plainPage();
47 TQBoxLayout *topLayout = new TQVBoxLayout( topFrame );
48
49 mButtonGroup = new TQButtonGroup( 1, TQt::Horizontal, i18n("Email Addresses"),
50 topFrame );
51 mButtonGroup->setRadioButtonExclusive( true );
52 topLayout->addWidget( mButtonGroup );
53
54 TQStringList::ConstIterator it;
55 for( it = emails.begin(); it != emails.end(); ++it ) {
56 TQRadioButton *button = new TQRadioButton( *it, mButtonGroup );
57 if ( (*it) == current ) {
58 button->setDown( true );
59 }
60 }
61}
62
63TQString EmailSelectDialog::selected()
64{
65 TQButton *button = mButtonGroup->selected();
66 if ( button ) return button->text();
67 return TQString::null;
68}
69
70TQString EmailSelectDialog::getEmail( const TQStringList &emails, const TQString &current,
71 TQWidget *parent )
72{
73 EmailSelectDialog *dlg = new EmailSelectDialog( emails, current, parent );
74 dlg->exec();
75
76 TQString result = dlg->selected();
77
78 delete dlg;
79
80 return result;
81}
82
83class EditEntryItem : public TQListViewItem
84{
85 public:
86 EditEntryItem( TQListView *parent, const Addressee &addressee,
87 const TQString &email=TQString::null ) :
88 TQListViewItem( parent ),
89 mAddressee( addressee ),
90 mEmail( email )
91 {
92 setText( 0, addressee.realName() );
93 if( email.isEmpty() ) {
94 setText( 1, addressee.preferredEmail() );
95 setText( 2, i18n("Yes") );
96 } else {
97 setText( 1, email );
98 setText( 2, i18n("No") );
99 }
100 }
101
102 Addressee addressee() const
103 {
104 return mAddressee;
105 }
106
107 TQString email() const
108 {
109 return mEmail;
110 }
111
112 private:
113 Addressee mAddressee;
114 TQString mEmail;
115};
116
117DistributionListEditor::DistributionListEditor( AddressBook *addressBook, TQWidget *parent) :
118 TQWidget( parent ),
119 mAddressBook( addressBook )
120{
121 kdDebug(5700) << "DistributionListEditor()" << endl;
122
123 TQBoxLayout *topLayout = new TQVBoxLayout( this );
124 topLayout->setMargin( KDialog::marginHint() );
125 topLayout->setSpacing( KDialog::spacingHint() );
126
127 TQBoxLayout *nameLayout = new TQHBoxLayout( topLayout) ;
128
129 mNameCombo = new TQComboBox( this );
130 nameLayout->addWidget( mNameCombo );
131 connect( mNameCombo, TQ_SIGNAL( activated( int ) ), TQ_SLOT( updateEntryView() ) );
132
133 newButton = new TQPushButton( i18n("New List"), this );
134 nameLayout->addWidget( newButton );
135 connect( newButton, TQ_SIGNAL( clicked() ), TQ_SLOT( newList() ) );
136
137 removeButton = new TQPushButton( i18n("Remove List"), this );
138 nameLayout->addWidget( removeButton );
139 connect( removeButton, TQ_SIGNAL( clicked() ), TQ_SLOT( removeList() ) );
140
141 mEntryView = new TQListView( this );
142 mEntryView->addColumn( i18n("Name") );
143 mEntryView->addColumn( i18n("Email") );
144 mEntryView->addColumn( i18n("Use Preferred") );
145 topLayout->addWidget( mEntryView );
146 connect(mEntryView,TQ_SIGNAL(selectionChanged ()),this, TQ_SLOT(slotSelectionEntryViewChanged()));
147
148 changeEmailButton = new TQPushButton( i18n("Change Email"), this );
149 topLayout->addWidget( changeEmailButton );
150 connect( changeEmailButton, TQ_SIGNAL( clicked() ), TQ_SLOT( changeEmail() ) );
151
152 removeEntryButton = new TQPushButton( i18n("Remove Entry"), this );
153 topLayout->addWidget( removeEntryButton );
154 connect( removeEntryButton, TQ_SIGNAL( clicked() ), TQ_SLOT( removeEntry() ) );
155
156 addEntryButton = new TQPushButton( i18n("Add Entry"), this );
157 topLayout->addWidget( addEntryButton );
158 connect( addEntryButton, TQ_SIGNAL( clicked() ), TQ_SLOT( addEntry() ) );
159
160 mAddresseeView = new TQListView( this );
161 mAddresseeView->addColumn( i18n("Name") );
162 mAddresseeView->addColumn( i18n("Preferred Email") );
163 topLayout->addWidget( mAddresseeView );
164
165
166 connect(mAddresseeView,TQ_SIGNAL(selectionChanged ()),this, TQ_SLOT(slotSelectionAddresseeViewChanged()));
167
168 mManager = new DistributionListManager( mAddressBook );
169 mManager->load();
170
171 updateAddresseeView();
172 updateNameCombo();
173 removeButton->setEnabled(!mManager->listNames().isEmpty());
174}
175
176DistributionListEditor::~DistributionListEditor()
177{
178 kdDebug(5700) << "~DistributionListEditor()" << endl;
179
180 mManager->save();
181 delete mManager;
182}
183
184void DistributionListEditor::slotSelectionEntryViewChanged()
185{
186 EditEntryItem *entryItem = dynamic_cast<EditEntryItem *>( mEntryView->selectedItem() );
187 bool state = (entryItem != 0L);
188
189 changeEmailButton->setEnabled(state);
190 removeEntryButton->setEnabled(state);
191}
192
193void DistributionListEditor::newList()
194{
195 bool ok = false;
196 TQString name = KInputDialog::getText( i18n("New Distribution List"),
197 i18n("Please enter name:"),
198 TQString::null, &ok, this );
199 if ( !ok )
200 return;
201
202 new DistributionList( mManager, name );
203
204 mNameCombo->insertItem( name );
205 removeButton->setEnabled(true);
206 updateEntryView();
207}
208
209void DistributionListEditor::removeList()
210{
211 mManager->remove( mManager->list( mNameCombo->currentText() ) );
212 mNameCombo->removeItem( mNameCombo->currentItem() );
213 removeButton->setEnabled(!mManager->listNames().isEmpty());
214 addEntryButton->setEnabled( !mNameCombo->currentText().isEmpty());
215 updateEntryView();
216}
217
218void DistributionListEditor::addEntry()
219{
220 AddresseeItem *addresseeItem =
221 dynamic_cast<AddresseeItem *>( mAddresseeView->selectedItem() );
222
223 if( !addresseeItem ) {
224 kdDebug(5700) << "DLE::addEntry(): No addressee selected." << endl;
225 return;
226 }
227
228 DistributionList *list = mManager->list( mNameCombo->currentText() );
229 if ( !list ) {
230 kdDebug(5700) << "DLE::addEntry(): No dist list '" << mNameCombo->currentText() << "'" << endl;
231 return;
232 }
233
234 list->insertEntry( addresseeItem->addressee() );
235 updateEntryView();
236 slotSelectionAddresseeViewChanged();
237}
238
239void DistributionListEditor::removeEntry()
240{
241 DistributionList *list = mManager->list( mNameCombo->currentText() );
242 if ( !list ) return;
243
244 EditEntryItem *entryItem =
245 dynamic_cast<EditEntryItem *>( mEntryView->selectedItem() );
246 if ( !entryItem ) return;
247
248 list->removeEntry( entryItem->addressee(), entryItem->email() );
249 delete entryItem;
250}
251
252void DistributionListEditor::changeEmail()
253{
254 DistributionList *list = mManager->list( mNameCombo->currentText() );
255 if ( !list ) return;
256
257 EditEntryItem *entryItem =
258 dynamic_cast<EditEntryItem *>( mEntryView->selectedItem() );
259 if ( !entryItem ) return;
260
261 TQString email = EmailSelectDialog::getEmail( entryItem->addressee().emails(),
262 entryItem->email(), this );
263 list->removeEntry( entryItem->addressee(), entryItem->email() );
264 list->insertEntry( entryItem->addressee(), email );
265
266 updateEntryView();
267}
268
269void DistributionListEditor::updateEntryView()
270{
271 DistributionList *list = mManager->list( mNameCombo->currentText() );
272 if ( !list ) return;
273
274 mEntryView->clear();
275 DistributionList::Entry::List entries = list->entries();
276 DistributionList::Entry::List::ConstIterator it;
277 for( it = entries.begin(); it != entries.end(); ++it ) {
278 new EditEntryItem( mEntryView, (*it).addressee, (*it).email );
279 }
280 EditEntryItem *entryItem = dynamic_cast<EditEntryItem *>( mEntryView->selectedItem() );
281 bool state = (entryItem != 0L);
282
283 changeEmailButton->setEnabled(state);
284 removeEntryButton->setEnabled(state);
285}
286
287void DistributionListEditor::updateAddresseeView()
288{
289 mAddresseeView->clear();
290
291 AddressBook::Iterator it;
292 for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) {
293 new AddresseeItem( mAddresseeView, *it );
294 }
295}
296
297void DistributionListEditor::updateNameCombo()
298{
299 mNameCombo->insertStringList( mManager->listNames() );
300
301 updateEntryView();
302}
303
304void DistributionListEditor::slotSelectionAddresseeViewChanged()
305{
306 AddresseeItem *addresseeItem =
307 dynamic_cast<AddresseeItem *>( mAddresseeView->selectedItem() );
308 bool state = (addresseeItem != 0L);
309 addEntryButton->setEnabled( state && !mNameCombo->currentText().isEmpty());
310}
KDialogBase
KDialog::marginHint
static int marginHint()
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)
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::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::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
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.