summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/distributionlistdialog.cpp4
1 files changed, 1 insertions, 3 deletions
diff --git a/kabc/distributionlistdialog.cpp b/kabc/distributionlistdialog.cpp
index 31d5944..d2e1144 100644
--- a/kabc/distributionlistdialog.cpp
+++ b/kabc/distributionlistdialog.cpp
@@ -1,298 +1,296 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 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 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21#include <qlistview.h> 21#include <qlistview.h>
22#include <qlayout.h> 22#include <qlayout.h>
23#include <qlabel.h> 23#include <qlabel.h>
24#include <qpushbutton.h> 24#include <qpushbutton.h>
25#include <qcombobox.h> 25#include <qcombobox.h>
26#include <klineeditdlg.h> 26#include <klineeditdlg.h>
27#include <qbuttongroup.h> 27#include <qbuttongroup.h>
28#include <qradiobutton.h> 28#include <qradiobutton.h>
29 29
30#include <klocale.h> 30#include <klocale.h>
31#include <kdebug.h> 31#include <kdebug.h>
32#include <kmessagebox.h> 32#include <kmessagebox.h>
33 33
34#include "addressbook.h" 34#include "addressbook.h"
35#include "addresseedialog.h" 35#include "addresseedialog.h"
36#include "distributionlist.h" 36#include "distributionlist.h"
37 37
38#include "distributionlistdialog.h" 38#include "distributionlistdialog.h"
39 39
40#ifndef KAB_EMBEDDED 40//US #include "distributionlistdialog.moc"
41#include "distributionlistdialog.moc"
42#endif //KAB_EMBEDDED
43 41
44using namespace KABC; 42using namespace KABC;
45 43
46DistributionListDialog::DistributionListDialog( AddressBook *addressBook, QWidget *parent) 44DistributionListDialog::DistributionListDialog( AddressBook *addressBook, QWidget *parent)
47 : KDialogBase( parent, "", true, i18n("Configure Distribution Lists"), Ok, Ok, true) 45 : KDialogBase( parent, "", true, i18n("Configure Distribution Lists"), Ok, Ok, true)
48{ 46{
49 mEditor = new DistributionListEditorWidget( addressBook, this ); 47 mEditor = new DistributionListEditorWidget( addressBook, this );
50 setMainWidget( mEditor ); 48 setMainWidget( mEditor );
51 49
52 connect( this, SIGNAL( okClicked() ), mEditor, SLOT( save() ) ); 50 connect( this, SIGNAL( okClicked() ), mEditor, SLOT( save() ) );
53} 51}
54 52
55DistributionListDialog::~DistributionListDialog() 53DistributionListDialog::~DistributionListDialog()
56{ 54{
57} 55}
58 56
59 57
60EmailSelector::EmailSelector( const QStringList &emails, const QString &current, 58EmailSelector::EmailSelector( const QStringList &emails, const QString &current,
61 QWidget *parent ) : 59 QWidget *parent ) :
62 KDialogBase( KDialogBase::Plain, i18n("Select Email Address"), Ok, Ok, 60 KDialogBase( KDialogBase::Plain, i18n("Select Email Address"), Ok, Ok,
63 parent ) 61 parent )
64{ 62{
65 QFrame *topFrame = plainPage(); 63 QFrame *topFrame = plainPage();
66 QBoxLayout *topLayout = new QVBoxLayout( topFrame ); 64 QBoxLayout *topLayout = new QVBoxLayout( topFrame );
67 65
68 mButtonGroup = new QButtonGroup( 1, Horizontal, i18n("Email Addresses"), 66 mButtonGroup = new QButtonGroup( 1, Horizontal, i18n("Email Addresses"),
69 topFrame ); 67 topFrame );
70 topLayout->addWidget( mButtonGroup ); 68 topLayout->addWidget( mButtonGroup );
71 69
72 QStringList::ConstIterator it; 70 QStringList::ConstIterator it;
73 for( it = emails.begin(); it != emails.end(); ++it ) { 71 for( it = emails.begin(); it != emails.end(); ++it ) {
74 QRadioButton *button = new QRadioButton( *it, mButtonGroup ); 72 QRadioButton *button = new QRadioButton( *it, mButtonGroup );
75 if ( (*it) == current ) { 73 if ( (*it) == current ) {
76 button->setDown( true ); 74 button->setDown( true );
77 } 75 }
78 } 76 }
79} 77}
80 78
81QString EmailSelector::selected() 79QString EmailSelector::selected()
82{ 80{
83 QButton *button = mButtonGroup->selected(); 81 QButton *button = mButtonGroup->selected();
84 if ( button ) return button->text(); 82 if ( button ) return button->text();
85 return QString::null; 83 return QString::null;
86} 84}
87 85
88QString EmailSelector::getEmail( const QStringList &emails, const QString &current, 86QString EmailSelector::getEmail( const QStringList &emails, const QString &current,
89 QWidget *parent ) 87 QWidget *parent )
90{ 88{
91 EmailSelector *dlg = new EmailSelector( emails, current, parent ); 89 EmailSelector *dlg = new EmailSelector( emails, current, parent );
92 dlg->exec(); 90 dlg->exec();
93 91
94 QString result = dlg->selected(); 92 QString result = dlg->selected();
95 93
96 delete dlg; 94 delete dlg;
97 95
98 return result; 96 return result;
99} 97}
100 98
101class EntryItem : public QListViewItem 99class EntryItem : public QListViewItem
102{ 100{
103 public: 101 public:
104 EntryItem( QListView *parent, const Addressee &addressee, 102 EntryItem( QListView *parent, const Addressee &addressee,
105 const QString &email=QString::null ) : 103 const QString &email=QString::null ) :
106 QListViewItem( parent ), 104 QListViewItem( parent ),
107 mAddressee( addressee ), 105 mAddressee( addressee ),
108 mEmail( email ) 106 mEmail( email )
109 { 107 {
110 setText( 0, addressee.realName() ); 108 setText( 0, addressee.realName() );
111 if( email.isEmpty() ) { 109 if( email.isEmpty() ) {
112 setText( 1, addressee.preferredEmail() ); 110 setText( 1, addressee.preferredEmail() );
113 setText( 2, i18n("Yes") ); 111 setText( 2, i18n("Yes") );
114 } else { 112 } else {
115 setText( 1, email ); 113 setText( 1, email );
116 setText( 2, i18n("No") ); 114 setText( 2, i18n("No") );
117 } 115 }
118 } 116 }
119 117
120 Addressee addressee() const 118 Addressee addressee() const
121 { 119 {
122 return mAddressee; 120 return mAddressee;
123 } 121 }
124 122
125 QString email() const 123 QString email() const
126 { 124 {
127 return mEmail; 125 return mEmail;
128 } 126 }
129 127
130 private: 128 private:
131 Addressee mAddressee; 129 Addressee mAddressee;
132 QString mEmail; 130 QString mEmail;
133}; 131};
134 132
135DistributionListEditorWidget::DistributionListEditorWidget( AddressBook *addressBook, QWidget *parent) : 133DistributionListEditorWidget::DistributionListEditorWidget( AddressBook *addressBook, QWidget *parent) :
136 QWidget( parent ), 134 QWidget( parent ),
137 mAddressBook( addressBook ) 135 mAddressBook( addressBook )
138{ 136{
139 kdDebug(5700) << "DistributionListEditor()" << endl; 137 kdDebug(5700) << "DistributionListEditor()" << endl;
140 138
141 QBoxLayout *topLayout = new QVBoxLayout( this ); 139 QBoxLayout *topLayout = new QVBoxLayout( this );
142 topLayout->setSpacing( KDialog::spacingHint() ); 140 topLayout->setSpacing( KDialog::spacingHint() );
143 141
144 QBoxLayout *nameLayout = new QHBoxLayout( topLayout) ; 142 QBoxLayout *nameLayout = new QHBoxLayout( topLayout) ;
145 143
146 mNameCombo = new QComboBox( this ); 144 mNameCombo = new QComboBox( this );
147 nameLayout->addWidget( mNameCombo ); 145 nameLayout->addWidget( mNameCombo );
148 connect( mNameCombo, SIGNAL( activated( int ) ), SLOT( updateEntryView() ) ); 146 connect( mNameCombo, SIGNAL( activated( int ) ), SLOT( updateEntryView() ) );
149 147
150 mNewButton = new QPushButton( i18n("New List..."), this ); 148 mNewButton = new QPushButton( i18n("New List..."), this );
151 nameLayout->addWidget( mNewButton ); 149 nameLayout->addWidget( mNewButton );
152 connect( mNewButton, SIGNAL( clicked() ), SLOT( newList() ) ); 150 connect( mNewButton, SIGNAL( clicked() ), SLOT( newList() ) );
153 151
154 mEditButton = new QPushButton( i18n("Rename List..."), this ); 152 mEditButton = new QPushButton( i18n("Rename List..."), this );
155 nameLayout->addWidget( mEditButton ); 153 nameLayout->addWidget( mEditButton );
156 connect( mEditButton, SIGNAL( clicked() ), SLOT( editList() ) ); 154 connect( mEditButton, SIGNAL( clicked() ), SLOT( editList() ) );
157 155
158 mRemoveButton = new QPushButton( i18n("Remove List"), this ); 156 mRemoveButton = new QPushButton( i18n("Remove List"), this );
159 nameLayout->addWidget( mRemoveButton ); 157 nameLayout->addWidget( mRemoveButton );
160 connect( mRemoveButton, SIGNAL( clicked() ), SLOT( removeList() ) ); 158 connect( mRemoveButton, SIGNAL( clicked() ), SLOT( removeList() ) );
161 159
162 QGridLayout *gridLayout = new QGridLayout( topLayout, 3, 3 ); 160 QGridLayout *gridLayout = new QGridLayout( topLayout, 3, 3 );
163 gridLayout->setColStretch(1, 1); 161 gridLayout->setColStretch(1, 1);
164 162
165 QLabel *listLabel = new QLabel( i18n("Available addresses:"), this ); 163 QLabel *listLabel = new QLabel( i18n("Available addresses:"), this );
166 gridLayout->addWidget( listLabel, 0, 0 ); 164 gridLayout->addWidget( listLabel, 0, 0 );
167 165
168 mListLabel = new QLabel( this ); 166 mListLabel = new QLabel( this );
169 gridLayout->addMultiCellWidget( mListLabel, 0, 0, 1, 2 ); 167 gridLayout->addMultiCellWidget( mListLabel, 0, 0, 1, 2 );
170 168
171 mAddresseeView = new QListView( this ); 169 mAddresseeView = new QListView( this );
172 mAddresseeView->addColumn( i18n("Name") ); 170 mAddresseeView->addColumn( i18n("Name") );
173 mAddresseeView->addColumn( i18n("Preferred Email") ); 171 mAddresseeView->addColumn( i18n("Preferred Email") );
174 mAddresseeView->setAllColumnsShowFocus( true ); 172 mAddresseeView->setAllColumnsShowFocus( true );
175 gridLayout->addWidget( mAddresseeView, 1, 0 ); 173 gridLayout->addWidget( mAddresseeView, 1, 0 );
176 connect( mAddresseeView, SIGNAL( selectionChanged() ), 174 connect( mAddresseeView, SIGNAL( selectionChanged() ),
177 SLOT( slotSelectionAddresseeViewChanged() ) ); 175 SLOT( slotSelectionAddresseeViewChanged() ) );
178 connect( mAddresseeView, SIGNAL( doubleClicked( QListViewItem * ) ), 176 connect( mAddresseeView, SIGNAL( doubleClicked( QListViewItem * ) ),
179 SLOT( addEntry() ) ); 177 SLOT( addEntry() ) );
180 178
181 mAddEntryButton = new QPushButton( i18n("Add Entry"), this ); 179 mAddEntryButton = new QPushButton( i18n("Add Entry"), this );
182 mAddEntryButton->setEnabled(false); 180 mAddEntryButton->setEnabled(false);
183 gridLayout->addWidget( mAddEntryButton, 2, 0 ); 181 gridLayout->addWidget( mAddEntryButton, 2, 0 );
184 connect( mAddEntryButton, SIGNAL( clicked() ), SLOT( addEntry() ) ); 182 connect( mAddEntryButton, SIGNAL( clicked() ), SLOT( addEntry() ) );
185 183
186 mEntryView = new QListView( this ); 184 mEntryView = new QListView( this );
187 mEntryView->addColumn( i18n("Name") ); 185 mEntryView->addColumn( i18n("Name") );
188 mEntryView->addColumn( i18n("Email") ); 186 mEntryView->addColumn( i18n("Email") );
189 mEntryView->addColumn( i18n("Use Preferred") ); 187 mEntryView->addColumn( i18n("Use Preferred") );
190 mEntryView->setEnabled(false); 188 mEntryView->setEnabled(false);
191 mEntryView->setAllColumnsShowFocus( true ); 189 mEntryView->setAllColumnsShowFocus( true );
192 gridLayout->addMultiCellWidget( mEntryView, 1, 1, 1, 2 ); 190 gridLayout->addMultiCellWidget( mEntryView, 1, 1, 1, 2 );
193 connect( mEntryView, SIGNAL( selectionChanged() ), 191 connect( mEntryView, SIGNAL( selectionChanged() ),
194 SLOT( slotSelectionEntryViewChanged() ) ); 192 SLOT( slotSelectionEntryViewChanged() ) );
195 193
196 mChangeEmailButton = new QPushButton( i18n("Change Email..."), this ); 194 mChangeEmailButton = new QPushButton( i18n("Change Email..."), this );
197 gridLayout->addWidget( mChangeEmailButton, 2, 1 ); 195 gridLayout->addWidget( mChangeEmailButton, 2, 1 );
198 connect( mChangeEmailButton, SIGNAL( clicked() ), SLOT( changeEmail() ) ); 196 connect( mChangeEmailButton, SIGNAL( clicked() ), SLOT( changeEmail() ) );
199 197
200 mRemoveEntryButton = new QPushButton( i18n("Remove Entry"), this ); 198 mRemoveEntryButton = new QPushButton( i18n("Remove Entry"), this );
201 gridLayout->addWidget( mRemoveEntryButton, 2, 2 ); 199 gridLayout->addWidget( mRemoveEntryButton, 2, 2 );
202 connect( mRemoveEntryButton, SIGNAL( clicked() ), SLOT( removeEntry() ) ); 200 connect( mRemoveEntryButton, SIGNAL( clicked() ), SLOT( removeEntry() ) );
203 201
204 mManager = new DistributionListManager( mAddressBook ); 202 mManager = new DistributionListManager( mAddressBook );
205 mManager->load(); 203 mManager->load();
206 204
207 updateAddresseeView(); 205 updateAddresseeView();
208 updateNameCombo(); 206 updateNameCombo();
209} 207}
210 208
211DistributionListEditorWidget::~DistributionListEditorWidget() 209DistributionListEditorWidget::~DistributionListEditorWidget()
212{ 210{
213 kdDebug(5700) << "~DistributionListEditor()" << endl; 211 kdDebug(5700) << "~DistributionListEditor()" << endl;
214 212
215 delete mManager; 213 delete mManager;
216} 214}
217 215
218void DistributionListEditorWidget::save() 216void DistributionListEditorWidget::save()
219{ 217{
220 mManager->save(); 218 mManager->save();
221} 219}
222 220
223void DistributionListEditorWidget::slotSelectionEntryViewChanged() 221void DistributionListEditorWidget::slotSelectionEntryViewChanged()
224{ 222{
225 EntryItem *entryItem = static_cast<EntryItem *>( mEntryView->selectedItem() ); 223 EntryItem *entryItem = static_cast<EntryItem *>( mEntryView->selectedItem() );
226 bool state=entryItem; 224 bool state=entryItem;
227 225
228 mChangeEmailButton->setEnabled(state); 226 mChangeEmailButton->setEnabled(state);
229 mRemoveEntryButton->setEnabled(state); 227 mRemoveEntryButton->setEnabled(state);
230} 228}
231 229
232void DistributionListEditorWidget::newList() 230void DistributionListEditorWidget::newList()
233{ 231{
234 KLineEditDlg dlg(i18n("Please enter name:"), QString::null, this); 232 KLineEditDlg dlg(i18n("Please enter name:"), QString::null, this);
235 dlg.setCaption(i18n("New Distribution List")); 233 dlg.setCaption(i18n("New Distribution List"));
236 if (!dlg.exec()) return; 234 if (!dlg.exec()) return;
237 235
238 new DistributionList( mManager, dlg.text() ); 236 new DistributionList( mManager, dlg.text() );
239 237
240 mNameCombo->clear(); 238 mNameCombo->clear();
241 mNameCombo->insertStringList( mManager->listNames() ); 239 mNameCombo->insertStringList( mManager->listNames() );
242 mNameCombo->setCurrentItem( mNameCombo->count() - 1 ); 240 mNameCombo->setCurrentItem( mNameCombo->count() - 1 );
243 241
244 updateEntryView(); 242 updateEntryView();
245 slotSelectionAddresseeViewChanged(); 243 slotSelectionAddresseeViewChanged();
246} 244}
247 245
248void DistributionListEditorWidget::editList() 246void DistributionListEditorWidget::editList()
249{ 247{
250 QString oldName = mNameCombo->currentText(); 248 QString oldName = mNameCombo->currentText();
251 249
252 KLineEditDlg dlg(i18n("Please change name:"), oldName, this); 250 KLineEditDlg dlg(i18n("Please change name:"), oldName, this);
253 dlg.setCaption(i18n("Distribution List")); 251 dlg.setCaption(i18n("Distribution List"));
254 if (!dlg.exec()) return; 252 if (!dlg.exec()) return;
255 253
256 DistributionList *list = mManager->list( oldName ); 254 DistributionList *list = mManager->list( oldName );
257 list->setName( dlg.text() ); 255 list->setName( dlg.text() );
258 256
259 mNameCombo->clear(); 257 mNameCombo->clear();
260 mNameCombo->insertStringList( mManager->listNames() ); 258 mNameCombo->insertStringList( mManager->listNames() );
261 mNameCombo->setCurrentItem( mNameCombo->count() - 1 ); 259 mNameCombo->setCurrentItem( mNameCombo->count() - 1 );
262 260
263 updateEntryView(); 261 updateEntryView();
264 slotSelectionAddresseeViewChanged(); 262 slotSelectionAddresseeViewChanged();
265} 263}
266 264
267void DistributionListEditorWidget::removeList() 265void DistributionListEditorWidget::removeList()
268{ 266{
269 int result = KMessageBox::warningContinueCancel( this, 267 int result = KMessageBox::warningContinueCancel( this,
270 i18n("Delete distribution list '%1'?") .arg( mNameCombo->currentText() ), 268 i18n("Delete distribution list '%1'?") .arg( mNameCombo->currentText() ),
271 QString::null, i18n("Delete") ); 269 QString::null, i18n("Delete") );
272 270
273 if ( result != KMessageBox::Continue ) return; 271 if ( result != KMessageBox::Continue ) return;
274 272
275 delete mManager->list( mNameCombo->currentText() ); 273 delete mManager->list( mNameCombo->currentText() );
276 mNameCombo->removeItem( mNameCombo->currentItem() ); 274 mNameCombo->removeItem( mNameCombo->currentItem() );
277 275
278 updateEntryView(); 276 updateEntryView();
279 slotSelectionAddresseeViewChanged(); 277 slotSelectionAddresseeViewChanged();
280} 278}
281 279
282void DistributionListEditorWidget::addEntry() 280void DistributionListEditorWidget::addEntry()
283{ 281{
284 AddresseeItem *addresseeItem = 282 AddresseeItem *addresseeItem =
285 static_cast<AddresseeItem *>( mAddresseeView->selectedItem() ); 283 static_cast<AddresseeItem *>( mAddresseeView->selectedItem() );
286 284
287 if( !addresseeItem ) { 285 if( !addresseeItem ) {
288 kdDebug(5700) << "DLE::addEntry(): No addressee selected." << endl; 286 kdDebug(5700) << "DLE::addEntry(): No addressee selected." << endl;
289 return; 287 return;
290 } 288 }
291 289
292 DistributionList *list = mManager->list( mNameCombo->currentText() ); 290 DistributionList *list = mManager->list( mNameCombo->currentText() );
293 if ( !list ) { 291 if ( !list ) {
294 kdDebug(5700) << "DLE::addEntry(): No dist list '" << mNameCombo->currentText() << "'" << endl; 292 kdDebug(5700) << "DLE::addEntry(): No dist list '" << mNameCombo->currentText() << "'" << endl;
295 return; 293 return;
296 } 294 }
297 295
298 list->insertEntry( addresseeItem->addressee() ); 296 list->insertEntry( addresseeItem->addressee() );