summaryrefslogtreecommitdiffabout
path: root/kaddressbook/phoneeditwidget.cpp
Unidiff
Diffstat (limited to 'kaddressbook/phoneeditwidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/phoneeditwidget.cpp6
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
@@ -1,532 +1,530 @@
1/* 1/*
2 This file is part of KAddressBook. 2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com> 3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program 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 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23 23
24#include <qlayout.h> 24#include <qlayout.h>
25#include <qlabel.h> 25#include <qlabel.h>
26#include <qtooltip.h> 26#include <qtooltip.h>
27#include <qpushbutton.h> 27#include <qpushbutton.h>
28#include <qcheckbox.h> 28#include <qcheckbox.h>
29#include <qstring.h> 29#include <qstring.h>
30#include <qlistbox.h> 30#include <qlistbox.h>
31#include <qlistview.h> 31#include <qlistview.h>
32#include <qbuttongroup.h> 32#include <qbuttongroup.h>
33 33
34#include <kbuttonbox.h> 34#include <kbuttonbox.h>
35#include <klistview.h> 35#include <klistview.h>
36#include <kapplication.h> 36#include <kapplication.h>
37#include <qapplication.h> 37#include <qapplication.h>
38#include <kconfig.h> 38#include <kconfig.h>
39#include <klineedit.h> 39#include <klineedit.h>
40#include <kcombobox.h> 40#include <kcombobox.h>
41#include <klocale.h> 41#include <klocale.h>
42#include <kdebug.h> 42#include <kdebug.h>
43#include <kglobal.h> 43#include <kglobal.h>
44#include <kiconloader.h> 44#include <kiconloader.h>
45 45
46#include <kabc/phonenumber.h> 46#include <kabc/phonenumber.h>
47 47
48#include "typecombo.h" 48#include "typecombo.h"
49 49
50#include "phoneeditwidget.h" 50#include "phoneeditwidget.h"
51 51
52PhoneEditWidget::PhoneEditWidget( QWidget *parent, const char *name ) 52PhoneEditWidget::PhoneEditWidget( QWidget *parent, const char *name )
53 : QWidget( parent, name ) 53 : QWidget( parent, name )
54{ 54{
55 QGridLayout *layout = new QGridLayout( this, 4, 1 ); 55 QGridLayout *layout = new QGridLayout( this, 4, 1 );
56//US layout->setSpacing( KDialog::spacingHint() ); 56//US layout->setSpacing( KDialog::spacingHint() );
57 layout->setSpacing( KDialogBase::spacingHintSmall() ); 57 layout->setSpacing( KDialogBase::spacingHintSmall() );
58 58
59 59
60 60
61 QLabel* label = new QLabel( this ); 61 QLabel* label = new QLabel( this );
62//US loadIcon call is ambiguous. Add one more parameter 62//US loadIcon call is ambiguous. Add one more parameter
63//US label->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop ) ); 63//US label->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop ) );
64 label->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop, 0 ) ); 64 label->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop, 0 ) );
65 label->setAlignment( AlignCenter ); 65 label->setAlignment( AlignCenter );
66//US layout->addMultiCellWidget( label, 0, 1, 3, 3 ); 66//US layout->addMultiCellWidget( label, 0, 1, 3, 3 );
67 layout->addWidget( label, 0, 0 ); 67 layout->addWidget( label, 0, 0 );
68 68
69 QPushButton *editButton = new QPushButton( i18n( "Edit Phone Numbers..." ), 69 QPushButton *editButton = new QPushButton( i18n( "Edit Phone Numbers..." ),
70 this ); 70 this );
71 if ( QApplication::desktop()->width() < 640 ) 71 if ( QApplication::desktop()->width() < 640 )
72 layout->addWidget( editButton, 0, 1 ); 72 layout->addWidget( editButton, 0, 1 );
73 else 73 else
74 layout->addMultiCellWidget( editButton, 0, 0, 1, 3); 74 layout->addMultiCellWidget( editButton, 0, 0, 1, 3);
75 75
76 mPrefCombo = new PhoneTypeCombo( mPhoneList, this ); 76 mPrefCombo = new PhoneTypeCombo( mPhoneList, this );
77 mPrefEdit = new KLineEdit( this ); 77 mPrefEdit = new KLineEdit( this );
78 //mPrefEdit->setMinimumWidth( int(mPrefEdit->sizeHint().width() * 1.5) ); 78 //mPrefEdit->setMinimumWidth( int(mPrefEdit->sizeHint().width() * 1.5) );
79 mPrefCombo->setLineEdit( mPrefEdit ); 79 mPrefCombo->setLineEdit( mPrefEdit );
80 layout->addWidget( mPrefCombo, 1, 0 ); 80 layout->addWidget( mPrefCombo, 1, 0 );
81 layout->addWidget( mPrefEdit, 1, 1 ); 81 layout->addWidget( mPrefEdit, 1, 1 );
82 int x = 1, y = 2; 82 int x = 1, y = 2;
83 if ( QApplication::desktop()->width() < 640 ) { 83 if ( QApplication::desktop()->width() < 640 ) {
84 ++x; 84 ++x;
85 y = 0; 85 y = 0;
86 } 86 }
87 mSecondCombo = new PhoneTypeCombo( mPhoneList, this ); 87 mSecondCombo = new PhoneTypeCombo( mPhoneList, this );
88 mSecondEdit = new KLineEdit( this ); 88 mSecondEdit = new KLineEdit( this );
89 mSecondCombo->setLineEdit( mSecondEdit ); 89 mSecondCombo->setLineEdit( mSecondEdit );
90 layout->addWidget( mSecondCombo, x, y++ ); 90 layout->addWidget( mSecondCombo, x, y++ );
91 layout->addWidget( mSecondEdit, x, y++ ); 91 layout->addWidget( mSecondEdit, x, y++ );
92 92
93 y = 0; 93 y = 0;
94 ++x; 94 ++x;
95 mThirdCombo = new PhoneTypeCombo( mPhoneList, this ); 95 mThirdCombo = new PhoneTypeCombo( mPhoneList, this );
96 mThirdEdit = new KLineEdit( this ); 96 mThirdEdit = new KLineEdit( this );
97 mThirdCombo->setLineEdit( mThirdEdit ); 97 mThirdCombo->setLineEdit( mThirdEdit );
98 layout->addWidget( mThirdCombo, x, y++ ); 98 layout->addWidget( mThirdCombo, x, y++ );
99 layout->addWidget( mThirdEdit, x, y++ ); 99 layout->addWidget( mThirdEdit, x, y++ );
100 if ( QApplication::desktop()->width() < 640 ) { 100 if ( QApplication::desktop()->width() < 640 ) {
101 ++x; 101 ++x;
102 y = 0; 102 y = 0;
103 } 103 }
104 mFourthCombo = new PhoneTypeCombo( mPhoneList, this ); 104 mFourthCombo = new PhoneTypeCombo( mPhoneList, this );
105 mFourthEdit = new KLineEdit( this ); 105 mFourthEdit = new KLineEdit( this );
106 mFourthCombo->setLineEdit( mFourthEdit ); 106 mFourthCombo->setLineEdit( mFourthEdit );
107 layout->addWidget( mFourthCombo, x, y++ ); 107 layout->addWidget( mFourthCombo, x, y++ );
108 layout->addWidget( mFourthEdit, x, y++ ); 108 layout->addWidget( mFourthEdit, x, y++ );
109 109
110 // Four numbers don't fit in the current dialog 110 // Four numbers don't fit in the current dialog
111 if ( QApplication::desktop()->width() < 640 ) { 111 if ( QApplication::desktop()->width() < 640 ) {
112 mFourthCombo->hide(); 112 mFourthCombo->hide();
113 mFourthEdit->hide(); 113 mFourthEdit->hide();
114 } else { 114 } else {
115 QFontMetrics fm ( font () ) ; 115 QFontMetrics fm ( font () ) ;
116 int wid = fm.width( "Messenger" ) +60; 116 int wid = fm.width( "Messenger" ) +60;
117 mPrefCombo->setMaximumWidth( wid ); 117 mPrefCombo->setMaximumWidth( wid );
118 mSecondCombo->setMaximumWidth( wid ); 118 mSecondCombo->setMaximumWidth( wid );
119 mThirdCombo->setMaximumWidth( wid ); 119 mThirdCombo->setMaximumWidth( wid );
120 mFourthCombo->setMaximumWidth( wid ); 120 mFourthCombo->setMaximumWidth( wid );
121 } 121 }
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
145PhoneEditWidget::~PhoneEditWidget() 145PhoneEditWidget::~PhoneEditWidget()
146{ 146{
147} 147}
148 148
149void PhoneEditWidget::setPhoneNumbers( const KABC::PhoneNumber::List &list ) 149void 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
182void PhoneEditWidget::updateLineEdits() 182void PhoneEditWidget::updateLineEdits()
183{ 183{
184 updatePrefEdit(); 184 updatePrefEdit();
185 updateSecondEdit(); 185 updateSecondEdit();
186 updateThirdEdit(); 186 updateThirdEdit();
187 updateFourthEdit(); 187 updateFourthEdit();
188} 188}
189 189
190void PhoneEditWidget::updateCombos() 190void 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
198KABC::PhoneNumber::List PhoneEditWidget::phoneNumbers() 198KABC::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
210void PhoneEditWidget::edit() 210void 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
223void PhoneEditWidget::updatePrefEdit() 224void PhoneEditWidget::updatePrefEdit()
224{ 225{
225 updateEdit( mPrefCombo ); 226 updateEdit( mPrefCombo );
226} 227}
227 228
228void PhoneEditWidget::updateSecondEdit() 229void PhoneEditWidget::updateSecondEdit()
229{ 230{
230 updateEdit( mSecondCombo ); 231 updateEdit( mSecondCombo );
231} 232}
232 233
233void PhoneEditWidget::updateThirdEdit() 234void PhoneEditWidget::updateThirdEdit()
234{ 235{
235 updateEdit( mThirdCombo ); 236 updateEdit( mThirdCombo );
236} 237}
237 238
238void PhoneEditWidget::updateFourthEdit() 239void PhoneEditWidget::updateFourthEdit()
239{ 240{
240 updateEdit( mFourthCombo ); 241 updateEdit( mFourthCombo );
241} 242}
242 243
243void PhoneEditWidget::updateEdit( PhoneTypeCombo *combo ) 244void 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
264void PhoneEditWidget::slotPrefEditChanged() 265void PhoneEditWidget::slotPrefEditChanged()
265{ 266{
266 updatePhoneNumber( mPrefCombo ); 267 updatePhoneNumber( mPrefCombo );
267} 268}
268 269
269void PhoneEditWidget::slotSecondEditChanged() 270void PhoneEditWidget::slotSecondEditChanged()
270{ 271{
271 updatePhoneNumber( mSecondCombo ); 272 updatePhoneNumber( mSecondCombo );
272} 273}
273 274
274void PhoneEditWidget::slotThirdEditChanged() 275void PhoneEditWidget::slotThirdEditChanged()
275{ 276{
276 updatePhoneNumber( mThirdCombo ); 277 updatePhoneNumber( mThirdCombo );
277} 278}
278 279
279void PhoneEditWidget::slotFourthEditChanged() 280void PhoneEditWidget::slotFourthEditChanged()
280{ 281{
281 updatePhoneNumber( mFourthCombo ); 282 updatePhoneNumber( mFourthCombo );
282} 283}
283 284
284void PhoneEditWidget::updatePhoneNumber( PhoneTypeCombo *combo ) 285void 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
305void PhoneEditWidget::updateOtherEdit( PhoneTypeCombo *combo, PhoneTypeCombo *otherCombo ) 303void 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
317class PhoneViewItem : public QListViewItem 315class PhoneViewItem : public QListViewItem
318{ 316{
319public: 317public:
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
335private: 333private:
336 void makeText(); 334 void makeText();
337 335
338 KABC::PhoneNumber mPhoneNumber; 336 KABC::PhoneNumber mPhoneNumber;
339}; 337};
340 338
341PhoneViewItem::PhoneViewItem( QListView *parent, const KABC::PhoneNumber &number ) 339PhoneViewItem::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
347void PhoneViewItem::makeText() 345void 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
362PhoneEditDialog::PhoneEditDialog( const KABC::PhoneNumber::List &list, QWidget *parent, const char *name ) 360PhoneEditDialog::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()) );
392 connect( mListView, SIGNAL(doubleClicked( QListViewItem *, const QPoint &, int )), this, SLOT( slotEditPhoneNumber())); 390 connect( mListView, SIGNAL(doubleClicked( QListViewItem *, const QPoint &, int )), this, SLOT( slotEditPhoneNumber()));
393 391
394 KABC::PhoneNumber::List::Iterator it; 392 KABC::PhoneNumber::List::Iterator it;
395 for ( it = mPhoneNumberList.begin(); it != mPhoneNumberList.end(); ++it ) 393 for ( it = mPhoneNumberList.begin(); it != mPhoneNumberList.end(); ++it )
396 new PhoneViewItem( mListView, *it ); 394 new PhoneViewItem( mListView, *it );
397 395
398 mChanged = false; 396 mChanged = false;
399} 397}
400 398
401PhoneEditDialog::~PhoneEditDialog() 399PhoneEditDialog::~PhoneEditDialog()
402{ 400{
403} 401}
404 402
405void PhoneEditDialog::slotAddPhoneNumber() 403void PhoneEditDialog::slotAddPhoneNumber()
406{ 404{
407 KABC::PhoneNumber tmp( "", 0 ); 405 KABC::PhoneNumber tmp( "", 0 );
408 PhoneTypeDialog dlg( tmp, this ); 406 PhoneTypeDialog dlg( tmp, this );
409 407
410 if ( dlg.exec() ) { 408 if ( dlg.exec() ) {
411 KABC::PhoneNumber phoneNumber = dlg.phoneNumber(); 409 KABC::PhoneNumber phoneNumber = dlg.phoneNumber();
412 mPhoneNumberList.append( phoneNumber ); 410 mPhoneNumberList.append( phoneNumber );
413 new PhoneViewItem( mListView, phoneNumber ); 411 new PhoneViewItem( mListView, phoneNumber );
414 412
415 mChanged = true; 413 mChanged = true;
416 } 414 }
417} 415}
418 416
419void PhoneEditDialog::slotRemovePhoneNumber() 417void PhoneEditDialog::slotRemovePhoneNumber()
420{ 418{
421 PhoneViewItem *item = static_cast<PhoneViewItem*>( mListView->currentItem() ); 419 PhoneViewItem *item = static_cast<PhoneViewItem*>( mListView->currentItem() );
422 if ( !item ) 420 if ( !item )
423 return; 421 return;
424 422
425 mPhoneNumberList.remove( item->phoneNumber() ); 423 mPhoneNumberList.remove( item->phoneNumber() );
426 QListViewItem *currItem = mListView->currentItem(); 424 QListViewItem *currItem = mListView->currentItem();
427 mListView->takeItem( currItem ); 425 mListView->takeItem( currItem );
428 delete currItem; 426 delete currItem;
429 427
430 mChanged = true; 428 mChanged = true;
431} 429}
432 430
433void PhoneEditDialog::slotEditPhoneNumber() 431void PhoneEditDialog::slotEditPhoneNumber()
434{ 432{
435 PhoneViewItem *item = static_cast<PhoneViewItem*>( mListView->currentItem() ); 433 PhoneViewItem *item = static_cast<PhoneViewItem*>( mListView->currentItem() );
436 if ( !item ) 434 if ( !item )
437 return; 435 return;
438 436
439 PhoneTypeDialog dlg( item->phoneNumber(), this ); 437 PhoneTypeDialog dlg( item->phoneNumber(), this );
440 438
441 if ( dlg.exec() ) { 439 if ( dlg.exec() ) {
442 slotRemovePhoneNumber(); 440 slotRemovePhoneNumber();
443 KABC::PhoneNumber phoneNumber = dlg.phoneNumber(); 441 KABC::PhoneNumber phoneNumber = dlg.phoneNumber();
444 mPhoneNumberList.append( phoneNumber ); 442 mPhoneNumberList.append( phoneNumber );
445 new PhoneViewItem( mListView, phoneNumber ); 443 new PhoneViewItem( mListView, phoneNumber );
446 444
447 mChanged = true; 445 mChanged = true;
448 } 446 }
449} 447}
450 448
451void PhoneEditDialog::slotSelectionChanged() 449void PhoneEditDialog::slotSelectionChanged()
452{ 450{
453 bool state = ( mListView->currentItem() != 0 ); 451 bool state = ( mListView->currentItem() != 0 );
454 452
455 mRemoveButton->setEnabled( state ); 453 mRemoveButton->setEnabled( state );
456 mEditButton->setEnabled( state ); 454 mEditButton->setEnabled( state );
457} 455}
458 456
459const KABC::PhoneNumber::List &PhoneEditDialog::phoneNumbers() 457const KABC::PhoneNumber::List &PhoneEditDialog::phoneNumbers()
460{ 458{
461 return mPhoneNumberList; 459 return mPhoneNumberList;
462} 460}
463 461
464bool PhoneEditDialog::changed() const 462bool PhoneEditDialog::changed() const
465{ 463{
466 return mChanged; 464 return mChanged;
467} 465}
468 466
469/////////////////////////////////////////// 467///////////////////////////////////////////
470// PhoneTypeDialog 468// PhoneTypeDialog
471PhoneTypeDialog::PhoneTypeDialog( const KABC::PhoneNumber &phoneNumber, 469PhoneTypeDialog::PhoneTypeDialog( const KABC::PhoneNumber &phoneNumber,
472 QWidget *parent, const char *name) 470 QWidget *parent, const char *name)
473 : KDialogBase( KDialogBase::Plain, i18n( "Edit Phone Number" ), 471 : KDialogBase( KDialogBase::Plain, i18n( "Edit Phone Number" ),
474 KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok, 472 KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok,
475 parent, name, true), mPhoneNumber( phoneNumber ) 473 parent, name, true), mPhoneNumber( phoneNumber )
476{ 474{
477 QWidget *page = plainPage(); 475 QWidget *page = plainPage();
478 QLabel *label = 0; 476 QLabel *label = 0;
479 QGridLayout *layout = new QGridLayout( page, 3, 2, marginHint(), spacingHint() ); 477 QGridLayout *layout = new QGridLayout( page, 3, 2, marginHint(), spacingHint() );
480 478
481 label = new QLabel( i18n( "Number:" ), page ); 479 label = new QLabel( i18n( "Number:" ), page );
482 layout->addWidget( label, 0, 0 ); 480 layout->addWidget( label, 0, 0 );
483 mNumber = new KLineEdit( page ); 481 mNumber = new KLineEdit( page );
484 layout->addWidget( mNumber, 0, 1 ); 482 layout->addWidget( mNumber, 0, 1 );
485 483
486 mPreferredBox = new QCheckBox( i18n( "This is the preferred phone number" ), page ); 484 mPreferredBox = new QCheckBox( i18n( "This is the preferred phone number" ), page );
487 layout->addMultiCellWidget( mPreferredBox, 1, 1, 0, 1 ); 485 layout->addMultiCellWidget( mPreferredBox, 1, 1, 0, 1 );
488 486
489 mGroup = new QButtonGroup( 2, Horizontal, i18n( "Types" ), page ); 487 mGroup = new QButtonGroup( 2, Horizontal, i18n( "Types" ), page );
490 layout->addMultiCellWidget( mGroup, 2, 2, 0, 1 ); 488 layout->addMultiCellWidget( mGroup, 2, 2, 0, 1 );
491 489
492 // fill widgets 490 // fill widgets
493 mNumber->setText( mPhoneNumber.number() ); 491 mNumber->setText( mPhoneNumber.number() );
494 492
495 mTypeList = KABC::PhoneNumber::typeList(); 493 mTypeList = KABC::PhoneNumber::typeList();
496 mTypeList.remove( KABC::PhoneNumber::Pref ); 494 mTypeList.remove( KABC::PhoneNumber::Pref );
497 495
498 KABC::PhoneNumber::TypeList::Iterator it; 496 KABC::PhoneNumber::TypeList::Iterator it;
499 for ( it = mTypeList.begin(); it != mTypeList.end(); ++it ) 497 for ( it = mTypeList.begin(); it != mTypeList.end(); ++it )
500 new QCheckBox( KABC::PhoneNumber::typeLabel( *it ), mGroup ); 498 new QCheckBox( KABC::PhoneNumber::typeLabel( *it ), mGroup );
501 499
502 for ( int i = 0; i < mGroup->count(); ++i ) { 500 for ( int i = 0; i < mGroup->count(); ++i ) {
503 int type = mPhoneNumber.type(); 501 int type = mPhoneNumber.type();
504 QCheckBox *box = (QCheckBox*)mGroup->find( i ); 502 QCheckBox *box = (QCheckBox*)mGroup->find( i );
505 box->setChecked( type & mTypeList[ i ] ); 503 box->setChecked( type & mTypeList[ i ] );
506 } 504 }
507 505
508 mPreferredBox->setChecked( mPhoneNumber.type() & KABC::PhoneNumber::Pref ); 506 mPreferredBox->setChecked( mPhoneNumber.type() & KABC::PhoneNumber::Pref );
509} 507}
510 508
511KABC::PhoneNumber PhoneTypeDialog::phoneNumber() 509KABC::PhoneNumber PhoneTypeDialog::phoneNumber()
512{ 510{
513 mPhoneNumber.setNumber( mNumber->text() ); 511 mPhoneNumber.setNumber( mNumber->text() );
514 512
515 int type = 0; 513 int type = 0;
516 for ( int i = 0; i < mGroup->count(); ++i ) { 514 for ( int i = 0; i < mGroup->count(); ++i ) {
517 QCheckBox *box = (QCheckBox*)mGroup->find( i ); 515 QCheckBox *box = (QCheckBox*)mGroup->find( i );
518 if ( box->isChecked() ) 516 if ( box->isChecked() )
519 type += mTypeList[ i ]; 517 type += mTypeList[ i ];
520 } 518 }
521 519
522 if ( mPreferredBox->isChecked() ) 520 if ( mPreferredBox->isChecked() )
523 mPhoneNumber.setType( type | KABC::PhoneNumber::Pref ); 521 mPhoneNumber.setType( type | KABC::PhoneNumber::Pref );
524 else 522 else
525 mPhoneNumber.setType( type & ~KABC::PhoneNumber::Pref ); 523 mPhoneNumber.setType( type & ~KABC::PhoneNumber::Pref );
526 524
527 return mPhoneNumber; 525 return mPhoneNumber;
528} 526}
529 527
530#ifndef KAB_EMBEDDED 528#ifndef KAB_EMBEDDED
531#include "phoneeditwidget.moc" 529#include "phoneeditwidget.moc"
532#endif //KAB_EMBEDDED 530#endif //KAB_EMBEDDED