-rw-r--r-- | kabc/distributionlistdialog.cpp | 4 |
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,396 +1,394 @@ | |||
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 | ||
44 | using namespace KABC; | 42 | using namespace KABC; |
45 | 43 | ||
46 | DistributionListDialog::DistributionListDialog( AddressBook *addressBook, QWidget *parent) | 44 | DistributionListDialog::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 | ||
55 | DistributionListDialog::~DistributionListDialog() | 53 | DistributionListDialog::~DistributionListDialog() |
56 | { | 54 | { |
57 | } | 55 | } |
58 | 56 | ||
59 | 57 | ||
60 | EmailSelector::EmailSelector( const QStringList &emails, const QString ¤t, | 58 | EmailSelector::EmailSelector( const QStringList &emails, const QString ¤t, |
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 | ||
81 | QString EmailSelector::selected() | 79 | QString 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 | ||
88 | QString EmailSelector::getEmail( const QStringList &emails, const QString ¤t, | 86 | QString EmailSelector::getEmail( const QStringList &emails, const QString ¤t, |
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 | ||
101 | class EntryItem : public QListViewItem | 99 | class 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 | ||
135 | DistributionListEditorWidget::DistributionListEditorWidget( AddressBook *addressBook, QWidget *parent) : | 133 | DistributionListEditorWidget::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 | ||
211 | DistributionListEditorWidget::~DistributionListEditorWidget() | 209 | DistributionListEditorWidget::~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 | ||
218 | void DistributionListEditorWidget::save() | 216 | void DistributionListEditorWidget::save() |
219 | { | 217 | { |
220 | mManager->save(); | 218 | mManager->save(); |
221 | } | 219 | } |
222 | 220 | ||
223 | void DistributionListEditorWidget::slotSelectionEntryViewChanged() | 221 | void 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 | ||
232 | void DistributionListEditorWidget::newList() | 230 | void 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 | ||
248 | void DistributionListEditorWidget::editList() | 246 | void 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 | ||
267 | void DistributionListEditorWidget::removeList() | 265 | void 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 | ||
282 | void DistributionListEditorWidget::addEntry() | 280 | void 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() ); |
299 | updateEntryView(); | 297 | updateEntryView(); |
300 | slotSelectionAddresseeViewChanged(); | 298 | slotSelectionAddresseeViewChanged(); |
301 | } | 299 | } |
302 | 300 | ||
303 | void DistributionListEditorWidget::removeEntry() | 301 | void DistributionListEditorWidget::removeEntry() |
304 | { | 302 | { |
305 | DistributionList *list = mManager->list( mNameCombo->currentText() ); | 303 | DistributionList *list = mManager->list( mNameCombo->currentText() ); |
306 | if ( !list ) return; | 304 | if ( !list ) return; |
307 | 305 | ||
308 | EntryItem *entryItem = | 306 | EntryItem *entryItem = |
309 | static_cast<EntryItem *>( mEntryView->selectedItem() ); | 307 | static_cast<EntryItem *>( mEntryView->selectedItem() ); |
310 | if ( !entryItem ) return; | 308 | if ( !entryItem ) return; |
311 | 309 | ||
312 | list->removeEntry( entryItem->addressee(), entryItem->email() ); | 310 | list->removeEntry( entryItem->addressee(), entryItem->email() ); |
313 | delete entryItem; | 311 | delete entryItem; |
314 | } | 312 | } |
315 | 313 | ||
316 | void DistributionListEditorWidget::changeEmail() | 314 | void DistributionListEditorWidget::changeEmail() |
317 | { | 315 | { |
318 | DistributionList *list = mManager->list( mNameCombo->currentText() ); | 316 | DistributionList *list = mManager->list( mNameCombo->currentText() ); |
319 | if ( !list ) return; | 317 | if ( !list ) return; |
320 | 318 | ||
321 | EntryItem *entryItem = | 319 | EntryItem *entryItem = |
322 | static_cast<EntryItem *>( mEntryView->selectedItem() ); | 320 | static_cast<EntryItem *>( mEntryView->selectedItem() ); |
323 | if ( !entryItem ) return; | 321 | if ( !entryItem ) return; |
324 | 322 | ||
325 | QString email = EmailSelector::getEmail( entryItem->addressee().emails(), | 323 | QString email = EmailSelector::getEmail( entryItem->addressee().emails(), |
326 | entryItem->email(), this ); | 324 | entryItem->email(), this ); |
327 | list->removeEntry( entryItem->addressee(), entryItem->email() ); | 325 | list->removeEntry( entryItem->addressee(), entryItem->email() ); |
328 | list->insertEntry( entryItem->addressee(), email ); | 326 | list->insertEntry( entryItem->addressee(), email ); |
329 | 327 | ||
330 | updateEntryView(); | 328 | updateEntryView(); |
331 | } | 329 | } |
332 | 330 | ||
333 | void DistributionListEditorWidget::updateEntryView() | 331 | void DistributionListEditorWidget::updateEntryView() |
334 | { | 332 | { |
335 | if ( mNameCombo->currentText().isEmpty() ) { | 333 | if ( mNameCombo->currentText().isEmpty() ) { |
336 | mListLabel->setText( i18n("Selected addressees:") ); | 334 | mListLabel->setText( i18n("Selected addressees:") ); |
337 | } else { | 335 | } else { |
338 | mListLabel->setText( i18n("Selected addresses in '%1':") | 336 | mListLabel->setText( i18n("Selected addresses in '%1':") |
339 | .arg( mNameCombo->currentText() ) ); | 337 | .arg( mNameCombo->currentText() ) ); |
340 | } | 338 | } |
341 | 339 | ||
342 | mEntryView->clear(); | 340 | mEntryView->clear(); |
343 | 341 | ||
344 | DistributionList *list = mManager->list( mNameCombo->currentText() ); | 342 | DistributionList *list = mManager->list( mNameCombo->currentText() ); |
345 | if ( !list ) { | 343 | if ( !list ) { |
346 | mEditButton->setEnabled(false); | 344 | mEditButton->setEnabled(false); |
347 | mRemoveButton->setEnabled(false); | 345 | mRemoveButton->setEnabled(false); |
348 | mChangeEmailButton->setEnabled(false); | 346 | mChangeEmailButton->setEnabled(false); |
349 | mRemoveEntryButton->setEnabled(false); | 347 | mRemoveEntryButton->setEnabled(false); |
350 | mAddresseeView->setEnabled(false); | 348 | mAddresseeView->setEnabled(false); |
351 | mEntryView->setEnabled(false); | 349 | mEntryView->setEnabled(false); |
352 | return; | 350 | return; |
353 | } else { | 351 | } else { |
354 | mEditButton->setEnabled(true); | 352 | mEditButton->setEnabled(true); |
355 | mRemoveButton->setEnabled(true); | 353 | mRemoveButton->setEnabled(true); |
356 | mAddresseeView->setEnabled(true); | 354 | mAddresseeView->setEnabled(true); |
357 | mEntryView->setEnabled(true); | 355 | mEntryView->setEnabled(true); |
358 | } | 356 | } |
359 | 357 | ||
360 | DistributionList::Entry::List entries = list->entries(); | 358 | DistributionList::Entry::List entries = list->entries(); |
361 | DistributionList::Entry::List::ConstIterator it; | 359 | DistributionList::Entry::List::ConstIterator it; |
362 | for( it = entries.begin(); it != entries.end(); ++it ) { | 360 | for( it = entries.begin(); it != entries.end(); ++it ) { |
363 | new EntryItem( mEntryView, (*it).addressee, (*it).email ); | 361 | new EntryItem( mEntryView, (*it).addressee, (*it).email ); |
364 | } | 362 | } |
365 | 363 | ||
366 | EntryItem *entryItem = static_cast<EntryItem *>( mEntryView->selectedItem() ); | 364 | EntryItem *entryItem = static_cast<EntryItem *>( mEntryView->selectedItem() ); |
367 | bool state=entryItem; | 365 | bool state=entryItem; |
368 | 366 | ||
369 | mChangeEmailButton->setEnabled(state); | 367 | mChangeEmailButton->setEnabled(state); |
370 | mRemoveEntryButton->setEnabled(state); | 368 | mRemoveEntryButton->setEnabled(state); |
371 | } | 369 | } |
372 | 370 | ||
373 | void DistributionListEditorWidget::updateAddresseeView() | 371 | void DistributionListEditorWidget::updateAddresseeView() |
374 | { | 372 | { |
375 | mAddresseeView->clear(); | 373 | mAddresseeView->clear(); |
376 | 374 | ||
377 | AddressBook::Iterator it; | 375 | AddressBook::Iterator it; |
378 | for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) { | 376 | for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) { |
379 | new AddresseeItem( mAddresseeView, *it ); | 377 | new AddresseeItem( mAddresseeView, *it ); |
380 | } | 378 | } |
381 | } | 379 | } |
382 | 380 | ||
383 | void DistributionListEditorWidget::updateNameCombo() | 381 | void DistributionListEditorWidget::updateNameCombo() |
384 | { | 382 | { |
385 | mNameCombo->insertStringList( mManager->listNames() ); | 383 | mNameCombo->insertStringList( mManager->listNames() ); |
386 | 384 | ||
387 | updateEntryView(); | 385 | updateEntryView(); |
388 | } | 386 | } |
389 | 387 | ||
390 | void DistributionListEditorWidget::slotSelectionAddresseeViewChanged() | 388 | void DistributionListEditorWidget::slotSelectionAddresseeViewChanged() |
391 | { | 389 | { |
392 | AddresseeItem *addresseeItem = | 390 | AddresseeItem *addresseeItem = |
393 | static_cast<AddresseeItem *>( mAddresseeView->selectedItem() ); | 391 | static_cast<AddresseeItem *>( mAddresseeView->selectedItem() ); |
394 | bool state=addresseeItem; | 392 | bool state=addresseeItem; |
395 | mAddEntryButton->setEnabled( state && !mNameCombo->currentText().isEmpty()); | 393 | mAddEntryButton->setEnabled( state && !mNameCombo->currentText().isEmpty()); |
396 | } | 394 | } |