Diffstat (limited to 'kaddressbook/phoneeditwidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kaddressbook/phoneeditwidget.cpp | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/kaddressbook/phoneeditwidget.cpp b/kaddressbook/phoneeditwidget.cpp index 78b9941..19bb676 100644 --- a/kaddressbook/phoneeditwidget.cpp +++ b/kaddressbook/phoneeditwidget.cpp | |||
@@ -122,270 +122,268 @@ PhoneEditWidget::PhoneEditWidget( QWidget *parent, const char *name ) | |||
122 | 122 | ||
123 | 123 | ||
124 | connect( mPrefEdit, SIGNAL( textChanged( const QString& ) ), | 124 | connect( mPrefEdit, SIGNAL( textChanged( const QString& ) ), |
125 | SLOT( slotPrefEditChanged() ) ); | 125 | SLOT( slotPrefEditChanged() ) ); |
126 | connect( mSecondEdit, SIGNAL( textChanged( const QString& ) ), | 126 | connect( mSecondEdit, SIGNAL( textChanged( const QString& ) ), |
127 | SLOT( slotSecondEditChanged() ) ); | 127 | SLOT( slotSecondEditChanged() ) ); |
128 | connect( mThirdEdit, SIGNAL( textChanged( const QString& ) ), | 128 | connect( mThirdEdit, SIGNAL( textChanged( const QString& ) ), |
129 | SLOT( slotThirdEditChanged() ) ); | 129 | SLOT( slotThirdEditChanged() ) ); |
130 | connect( mFourthEdit, SIGNAL( textChanged( const QString& ) ), | 130 | connect( mFourthEdit, SIGNAL( textChanged( const QString& ) ), |
131 | SLOT( slotFourthEditChanged() ) ); | 131 | SLOT( slotFourthEditChanged() ) ); |
132 | 132 | ||
133 | connect( editButton, SIGNAL( clicked() ), SLOT( edit() ) ); | 133 | connect( editButton, SIGNAL( clicked() ), SLOT( edit() ) ); |
134 | 134 | ||
135 | connect( mPrefCombo, SIGNAL( activated( int ) ), | 135 | connect( mPrefCombo, SIGNAL( activated( int ) ), |
136 | SLOT( updatePrefEdit() ) ); | 136 | SLOT( updatePrefEdit() ) ); |
137 | connect( mSecondCombo, SIGNAL( activated( int ) ), | 137 | connect( mSecondCombo, SIGNAL( activated( int ) ), |
138 | SLOT( updateSecondEdit() ) ); | 138 | SLOT( updateSecondEdit() ) ); |
139 | connect( mThirdCombo, SIGNAL( activated( int ) ), | 139 | connect( mThirdCombo, SIGNAL( activated( int ) ), |
140 | SLOT( updateThirdEdit() ) ); | 140 | SLOT( updateThirdEdit() ) ); |
141 | connect( mFourthCombo, SIGNAL( activated( int ) ), | 141 | connect( mFourthCombo, SIGNAL( activated( int ) ), |
142 | SLOT( updateFourthEdit() ) ); | 142 | SLOT( updateFourthEdit() ) ); |
143 | } | 143 | } |
144 | 144 | ||
145 | PhoneEditWidget::~PhoneEditWidget() | 145 | PhoneEditWidget::~PhoneEditWidget() |
146 | { | 146 | { |
147 | } | 147 | } |
148 | 148 | ||
149 | void PhoneEditWidget::setPhoneNumbers( const KABC::PhoneNumber::List &list ) | 149 | void PhoneEditWidget::setPhoneNumbers( const KABC::PhoneNumber::List &list ) |
150 | { | 150 | { |
151 | mPhoneList.clear(); | 151 | mPhoneList.clear(); |
152 | 152 | ||
153 | // Insert types for existing numbers. | 153 | // Insert types for existing numbers. |
154 | mPrefCombo->insertTypeList( list ); | 154 | mPrefCombo->insertTypeList( list ); |
155 | 155 | ||
156 | QValueList<int> defaultTypes; | 156 | QValueList<int> defaultTypes; |
157 | defaultTypes << KABC::PhoneNumber::Home; | 157 | defaultTypes << KABC::PhoneNumber::Home; |
158 | defaultTypes << KABC::PhoneNumber::Work; | 158 | defaultTypes << KABC::PhoneNumber::Work; |
159 | defaultTypes << KABC::PhoneNumber::Cell; | 159 | defaultTypes << KABC::PhoneNumber::Cell; |
160 | defaultTypes << ( KABC::PhoneNumber::Work | KABC::PhoneNumber::Fax ); | 160 | defaultTypes << ( KABC::PhoneNumber::Work | KABC::PhoneNumber::Fax ); |
161 | defaultTypes << ( KABC::PhoneNumber::Home | KABC::PhoneNumber::Fax ); | 161 | defaultTypes << ( KABC::PhoneNumber::Home | KABC::PhoneNumber::Fax ); |
162 | 162 | ||
163 | // Insert default types. | 163 | // Insert default types. |
164 | // Doing this for mPrefCombo is enough because the list is shared by all | 164 | // Doing this for mPrefCombo is enough because the list is shared by all |
165 | // combos. | 165 | // combos. |
166 | QValueList<int>::ConstIterator it; | 166 | QValueList<int>::ConstIterator it; |
167 | for( it = defaultTypes.begin(); it != defaultTypes.end(); ++it ) { | 167 | for( it = defaultTypes.begin(); it != defaultTypes.end(); ++it ) { |
168 | if ( !mPrefCombo->hasType( *it ) ) | 168 | if ( !mPrefCombo->hasType( *it ) ) |
169 | mPrefCombo->insertType( list, *it, PhoneNumber( "", *it ) ); | 169 | mPrefCombo->insertType( list, *it, PhoneNumber( "", *it ) ); |
170 | } | 170 | } |
171 | 171 | ||
172 | updateCombos(); | 172 | updateCombos(); |
173 | 173 | ||
174 | mPrefCombo->selectType( defaultTypes[ 0 ] ); | 174 | mPrefCombo->selectType( defaultTypes[ 0 ] ); |
175 | mSecondCombo->selectType( defaultTypes[ 1 ] ); | 175 | mSecondCombo->selectType( defaultTypes[ 1 ] ); |
176 | mThirdCombo->selectType( defaultTypes[ 2 ] ); | 176 | mThirdCombo->selectType( defaultTypes[ 2 ] ); |
177 | mFourthCombo->selectType( defaultTypes[ 3 ] ); | 177 | mFourthCombo->selectType( defaultTypes[ 3 ] ); |
178 | 178 | ||
179 | updateLineEdits(); | 179 | updateLineEdits(); |
180 | } | 180 | } |
181 | 181 | ||
182 | void PhoneEditWidget::updateLineEdits() | 182 | void PhoneEditWidget::updateLineEdits() |
183 | { | 183 | { |
184 | updatePrefEdit(); | 184 | updatePrefEdit(); |
185 | updateSecondEdit(); | 185 | updateSecondEdit(); |
186 | updateThirdEdit(); | 186 | updateThirdEdit(); |
187 | updateFourthEdit(); | 187 | updateFourthEdit(); |
188 | } | 188 | } |
189 | 189 | ||
190 | void PhoneEditWidget::updateCombos() | 190 | void PhoneEditWidget::updateCombos() |
191 | { | 191 | { |
192 | mPrefCombo->updateTypes(); | 192 | mPrefCombo->updateTypes(); |
193 | mSecondCombo->updateTypes(); | 193 | mSecondCombo->updateTypes(); |
194 | mThirdCombo->updateTypes(); | 194 | mThirdCombo->updateTypes(); |
195 | mFourthCombo->updateTypes(); | 195 | mFourthCombo->updateTypes(); |
196 | } | 196 | } |
197 | 197 | ||
198 | KABC::PhoneNumber::List PhoneEditWidget::phoneNumbers() | 198 | KABC::PhoneNumber::List PhoneEditWidget::phoneNumbers() |
199 | { | 199 | { |
200 | KABC::PhoneNumber::List retList; | 200 | KABC::PhoneNumber::List retList; |
201 | 201 | ||
202 | KABC::PhoneNumber::List::Iterator it; | 202 | KABC::PhoneNumber::List::Iterator it; |
203 | for ( it = mPhoneList.begin(); it != mPhoneList.end(); ++it ) | 203 | for ( it = mPhoneList.begin(); it != mPhoneList.end(); ++it ) |
204 | if ( !(*it).number().isEmpty() ) | 204 | if ( !(*it).number().isEmpty() ) |
205 | retList.append( *it ); | 205 | retList.append( *it ); |
206 | 206 | ||
207 | return retList; | 207 | return retList; |
208 | } | 208 | } |
209 | 209 | ||
210 | void PhoneEditWidget::edit() | 210 | void PhoneEditWidget::edit() |
211 | { | 211 | { |
212 | PhoneEditDialog dlg( mPhoneList, this ); | 212 | PhoneEditDialog dlg( mPhoneList, this ); |
213 | 213 | ||
214 | if ( dlg.exec() ) { | 214 | if ( dlg.exec() ) { |
215 | if ( dlg.changed() ) { | 215 | if ( dlg.changed() ) { |
216 | mPhoneList = dlg.phoneNumbers(); | 216 | mPhoneList = dlg.phoneNumbers(); |
217 | updateCombos(); | 217 | updateCombos(); |
218 | updateLineEdits(); | ||
218 | emit modified(); | 219 | emit modified(); |
219 | } | 220 | } |
220 | } | 221 | } |
221 | } | 222 | } |
222 | 223 | ||
223 | void PhoneEditWidget::updatePrefEdit() | 224 | void PhoneEditWidget::updatePrefEdit() |
224 | { | 225 | { |
225 | updateEdit( mPrefCombo ); | 226 | updateEdit( mPrefCombo ); |
226 | } | 227 | } |
227 | 228 | ||
228 | void PhoneEditWidget::updateSecondEdit() | 229 | void PhoneEditWidget::updateSecondEdit() |
229 | { | 230 | { |
230 | updateEdit( mSecondCombo ); | 231 | updateEdit( mSecondCombo ); |
231 | } | 232 | } |
232 | 233 | ||
233 | void PhoneEditWidget::updateThirdEdit() | 234 | void PhoneEditWidget::updateThirdEdit() |
234 | { | 235 | { |
235 | updateEdit( mThirdCombo ); | 236 | updateEdit( mThirdCombo ); |
236 | } | 237 | } |
237 | 238 | ||
238 | void PhoneEditWidget::updateFourthEdit() | 239 | void PhoneEditWidget::updateFourthEdit() |
239 | { | 240 | { |
240 | updateEdit( mFourthCombo ); | 241 | updateEdit( mFourthCombo ); |
241 | } | 242 | } |
242 | 243 | ||
243 | void PhoneEditWidget::updateEdit( PhoneTypeCombo *combo ) | 244 | void PhoneEditWidget::updateEdit( PhoneTypeCombo *combo ) |
244 | { | 245 | { |
245 | QLineEdit *edit = combo->lineEdit(); | 246 | QLineEdit *edit = combo->lineEdit(); |
246 | if ( !edit ) | 247 | if ( !edit ) |
247 | return; | 248 | return; |
248 | 249 | ||
249 | #if 0 | 250 | #if 0 |
250 | if ( edit == mPrefEdit ) kdDebug(5720) << " prefEdit" << endl; | 251 | if ( edit == mPrefEdit ) kdDebug(5720) << " prefEdit" << endl; |
251 | if ( edit == mSecondEdit ) kdDebug(5720) << " secondEdit" << endl; | 252 | if ( edit == mSecondEdit ) kdDebug(5720) << " secondEdit" << endl; |
252 | if ( edit == mThirdEdit ) kdDebug(5720) << " thirdEdit" << endl; | 253 | if ( edit == mThirdEdit ) kdDebug(5720) << " thirdEdit" << endl; |
253 | if ( edit == mFourthEdit ) kdDebug(5720) << " fourthEdit" << endl; | 254 | if ( edit == mFourthEdit ) kdDebug(5720) << " fourthEdit" << endl; |
254 | #endif | 255 | #endif |
255 | 256 | ||
256 | PhoneNumber::List::Iterator it = combo->selectedElement(); | 257 | PhoneNumber::List::Iterator it = combo->selectedElement(); |
257 | if ( it != mPhoneList.end() ) { | 258 | if ( it != mPhoneList.end() ) { |
258 | edit->setText( (*it).number() ); | 259 | edit->setText( (*it).number() ); |
259 | } else { | 260 | } else { |
260 | kdDebug(5720) << "PhoneEditWidget::updateEdit(): no selected element" << endl; | 261 | kdDebug(5720) << "PhoneEditWidget::updateEdit(): no selected element" << endl; |
261 | } | 262 | } |
262 | } | 263 | } |
263 | 264 | ||
264 | void PhoneEditWidget::slotPrefEditChanged() | 265 | void PhoneEditWidget::slotPrefEditChanged() |
265 | { | 266 | { |
266 | updatePhoneNumber( mPrefCombo ); | 267 | updatePhoneNumber( mPrefCombo ); |
267 | } | 268 | } |
268 | 269 | ||
269 | void PhoneEditWidget::slotSecondEditChanged() | 270 | void PhoneEditWidget::slotSecondEditChanged() |
270 | { | 271 | { |
271 | updatePhoneNumber( mSecondCombo ); | 272 | updatePhoneNumber( mSecondCombo ); |
272 | } | 273 | } |
273 | 274 | ||
274 | void PhoneEditWidget::slotThirdEditChanged() | 275 | void PhoneEditWidget::slotThirdEditChanged() |
275 | { | 276 | { |
276 | updatePhoneNumber( mThirdCombo ); | 277 | updatePhoneNumber( mThirdCombo ); |
277 | } | 278 | } |
278 | 279 | ||
279 | void PhoneEditWidget::slotFourthEditChanged() | 280 | void PhoneEditWidget::slotFourthEditChanged() |
280 | { | 281 | { |
281 | updatePhoneNumber( mFourthCombo ); | 282 | updatePhoneNumber( mFourthCombo ); |
282 | } | 283 | } |
283 | 284 | ||
284 | void PhoneEditWidget::updatePhoneNumber( PhoneTypeCombo *combo ) | 285 | void PhoneEditWidget::updatePhoneNumber( PhoneTypeCombo *combo ) |
285 | { | 286 | { |
286 | QLineEdit *edit = combo->lineEdit(); | 287 | QLineEdit *edit = combo->lineEdit(); |
287 | if ( !edit ) return; | 288 | if ( !edit ) return; |
288 | 289 | ||
289 | PhoneNumber::List::Iterator it = combo->selectedElement(); | 290 | PhoneNumber::List::Iterator it = combo->selectedElement(); |
290 | if ( it != mPhoneList.end() ) { | 291 | if ( it != mPhoneList.end() ) { |
291 | (*it).setNumber( edit->text() ); | 292 | (*it).setNumber( edit->text() ); |
292 | } else { | 293 | } |
293 | kdDebug(5720) << "PhoneEditWidget::updatePhoneNumber(): no selected element" | ||
294 | << endl; | ||
295 | } | ||
296 | 294 | ||
297 | updateOtherEdit( combo, mPrefCombo ); | 295 | updateOtherEdit( combo, mPrefCombo ); |
298 | updateOtherEdit( combo, mSecondCombo ); | 296 | updateOtherEdit( combo, mSecondCombo ); |
299 | updateOtherEdit( combo, mThirdCombo ); | 297 | updateOtherEdit( combo, mThirdCombo ); |
300 | updateOtherEdit( combo, mFourthCombo ); | 298 | updateOtherEdit( combo, mFourthCombo ); |
301 | 299 | ||
302 | emit modified(); | 300 | emit modified(); |
303 | } | 301 | } |
304 | 302 | ||
305 | void PhoneEditWidget::updateOtherEdit( PhoneTypeCombo *combo, PhoneTypeCombo *otherCombo ) | 303 | void PhoneEditWidget::updateOtherEdit( PhoneTypeCombo *combo, PhoneTypeCombo *otherCombo ) |
306 | { | 304 | { |
307 | if ( combo == otherCombo ) return; | 305 | if ( combo == otherCombo ) return; |
308 | 306 | ||
309 | if ( combo->currentItem() == otherCombo->currentItem() ) { | 307 | if ( combo->currentItem() == otherCombo->currentItem() ) { |
310 | updateEdit( otherCombo ); | 308 | updateEdit( otherCombo ); |
311 | } | 309 | } |
312 | } | 310 | } |
313 | 311 | ||
314 | /////////////////////////////////////////// | 312 | /////////////////////////////////////////// |
315 | // PhoneEditDialog | 313 | // PhoneEditDialog |
316 | 314 | ||
317 | class PhoneViewItem : public QListViewItem | 315 | class PhoneViewItem : public QListViewItem |
318 | { | 316 | { |
319 | public: | 317 | public: |
320 | PhoneViewItem( QListView *parent, const KABC::PhoneNumber &number ); | 318 | PhoneViewItem( QListView *parent, const KABC::PhoneNumber &number ); |
321 | 319 | ||
322 | void setPhoneNumber( const KABC::PhoneNumber &number ) | 320 | void setPhoneNumber( const KABC::PhoneNumber &number ) |
323 | { | 321 | { |
324 | mPhoneNumber = number; | 322 | mPhoneNumber = number; |
325 | makeText(); | 323 | makeText(); |
326 | } | 324 | } |
327 | 325 | ||
328 | QString key() { return mPhoneNumber.id(); } | 326 | QString key() { return mPhoneNumber.id(); } |
329 | QString country() { return ""; } | 327 | QString country() { return ""; } |
330 | QString region() { return ""; } | 328 | QString region() { return ""; } |
331 | QString number() { return ""; } | 329 | QString number() { return ""; } |
332 | 330 | ||
333 | KABC::PhoneNumber phoneNumber() { return mPhoneNumber; } | 331 | KABC::PhoneNumber phoneNumber() { return mPhoneNumber; } |
334 | 332 | ||
335 | private: | 333 | private: |
336 | void makeText(); | 334 | void makeText(); |
337 | 335 | ||
338 | KABC::PhoneNumber mPhoneNumber; | 336 | KABC::PhoneNumber mPhoneNumber; |
339 | }; | 337 | }; |
340 | 338 | ||
341 | PhoneViewItem::PhoneViewItem( QListView *parent, const KABC::PhoneNumber &number ) | 339 | PhoneViewItem::PhoneViewItem( QListView *parent, const KABC::PhoneNumber &number ) |
342 | : QListViewItem( parent ), mPhoneNumber( number ) | 340 | : QListViewItem( parent ), mPhoneNumber( number ) |
343 | { | 341 | { |
344 | makeText(); | 342 | makeText(); |
345 | } | 343 | } |
346 | 344 | ||
347 | void PhoneViewItem::makeText() | 345 | void PhoneViewItem::makeText() |
348 | { | 346 | { |
349 | /** | 347 | /** |
350 | * Will be used in future versions of kaddressbook/libkabc | 348 | * Will be used in future versions of kaddressbook/libkabc |
351 | 349 | ||
352 | setText( 0, mPhoneNumber.country() ); | 350 | setText( 0, mPhoneNumber.country() ); |
353 | setText( 1, mPhoneNumber.region() ); | 351 | setText( 1, mPhoneNumber.region() ); |
354 | setText( 2, mPhoneNumber.number() ); | 352 | setText( 2, mPhoneNumber.number() ); |
355 | setText( 3, mPhoneNumber.typeLabel() ); | 353 | setText( 3, mPhoneNumber.typeLabel() ); |
356 | */ | 354 | */ |
357 | 355 | ||
358 | setText( 0, mPhoneNumber.number() ); | 356 | setText( 0, mPhoneNumber.number() ); |
359 | setText( 1, mPhoneNumber.typeLabel() ); | 357 | setText( 1, mPhoneNumber.typeLabel() ); |
360 | } | 358 | } |
361 | 359 | ||
362 | PhoneEditDialog::PhoneEditDialog( const KABC::PhoneNumber::List &list, QWidget *parent, const char *name ) | 360 | PhoneEditDialog::PhoneEditDialog( const KABC::PhoneNumber::List &list, QWidget *parent, const char *name ) |
363 | : KDialogBase( KDialogBase::Plain, i18n( "Edit Phone Numbers" ), | 361 | : KDialogBase( KDialogBase::Plain, i18n( "Edit Phone Numbers" ), |
364 | KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok, | 362 | KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok, |
365 | parent, name, true) | 363 | parent, name, true) |
366 | { | 364 | { |
367 | mPhoneNumberList = list; | 365 | mPhoneNumberList = list; |
368 | 366 | ||
369 | QWidget *page = plainPage(); | 367 | QWidget *page = plainPage(); |
370 | 368 | ||
371 | QGridLayout *layout = new QGridLayout( page, 1, 2 ); | 369 | QGridLayout *layout = new QGridLayout( page, 1, 2 ); |
372 | layout->setSpacing( spacingHint() ); | 370 | layout->setSpacing( spacingHint() ); |
373 | 371 | ||
374 | mListView = new KListView( page ); | 372 | mListView = new KListView( page ); |
375 | mListView->setAllColumnsShowFocus( true ); | 373 | mListView->setAllColumnsShowFocus( true ); |
376 | mListView->addColumn( i18n( "Number" ) ); | 374 | mListView->addColumn( i18n( "Number" ) ); |
377 | mListView->addColumn( i18n( "Type" ) ); | 375 | mListView->addColumn( i18n( "Type" ) ); |
378 | 376 | ||
379 | KButtonBox *buttonBox = new KButtonBox( page, Vertical ); | 377 | KButtonBox *buttonBox = new KButtonBox( page, Vertical ); |
380 | 378 | ||
381 | buttonBox->addButton( i18n( "&Add..." ), this, SLOT( slotAddPhoneNumber() ) ); | 379 | buttonBox->addButton( i18n( "&Add..." ), this, SLOT( slotAddPhoneNumber() ) ); |
382 | mEditButton = buttonBox->addButton( i18n( "&Edit..." ), this, SLOT( slotEditPhoneNumber() ) ); | 380 | mEditButton = buttonBox->addButton( i18n( "&Edit..." ), this, SLOT( slotEditPhoneNumber() ) ); |
383 | mEditButton->setEnabled( false ); | 381 | mEditButton->setEnabled( false ); |
384 | mRemoveButton = buttonBox->addButton( i18n( "&Remove" ), this, SLOT( slotRemovePhoneNumber() ) ); | 382 | mRemoveButton = buttonBox->addButton( i18n( "&Remove" ), this, SLOT( slotRemovePhoneNumber() ) ); |
385 | mRemoveButton->setEnabled( false ); | 383 | mRemoveButton->setEnabled( false ); |
386 | buttonBox->layout(); | 384 | buttonBox->layout(); |
387 | 385 | ||
388 | layout->addWidget( mListView, 0, 0 ); | 386 | layout->addWidget( mListView, 0, 0 ); |
389 | layout->addWidget( buttonBox, 0, 1 ); | 387 | layout->addWidget( buttonBox, 0, 1 ); |
390 | 388 | ||
391 | connect( mListView, SIGNAL(selectionChanged()), SLOT(slotSelectionChanged()) ); | 389 | connect( mListView, SIGNAL(selectionChanged()), SLOT(slotSelectionChanged()) ); |