summaryrefslogtreecommitdiffabout
path: root/kaddressbook/phoneeditwidget.cpp
Unidiff
Diffstat (limited to 'kaddressbook/phoneeditwidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/phoneeditwidget.cpp37
1 files changed, 22 insertions, 15 deletions
diff --git a/kaddressbook/phoneeditwidget.cpp b/kaddressbook/phoneeditwidget.cpp
index b20275d..997fc05 100644
--- a/kaddressbook/phoneeditwidget.cpp
+++ b/kaddressbook/phoneeditwidget.cpp
@@ -1,666 +1,673 @@
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#include <qhbox.h> 33#include <qhbox.h>
34 34
35#include <kbuttonbox.h> 35#include <kbuttonbox.h>
36#include <klistview.h> 36#include <klistview.h>
37#include <kapplication.h> 37#include <kapplication.h>
38#include <qapplication.h> 38#include <qapplication.h>
39#include <kconfig.h> 39#include <kconfig.h>
40#include <klineedit.h> 40#include <klineedit.h>
41#include <kcombobox.h> 41#include <kcombobox.h>
42#include <klocale.h> 42#include <klocale.h>
43#include <kdebug.h> 43#include <kdebug.h>
44#include <kglobal.h> 44#include <kglobal.h>
45#include <kiconloader.h> 45#include <kiconloader.h>
46 46
47#include <kabc/phonenumber.h> 47#include <kabc/phonenumber.h>
48 48
49#include "typecombo.h" 49#include "typecombo.h"
50 50
51#include "phoneeditwidget.h" 51#include "phoneeditwidget.h"
52 52
53PhoneEditWidget::PhoneEditWidget( QWidget *parent, const char *name ) 53PhoneEditWidget::PhoneEditWidget( QWidget *parent, const char *name )
54 : QScrollView(parent,name) 54 : QScrollView(parent,name)
55{ 55{
56 setFrameStyle ( QFrame::Panel | QFrame::Plain ); 56 setFrameStyle ( QFrame::Panel | QFrame::Plain );
57 setLineWidth ( 1 ); 57 setLineWidth ( 1 );
58 setMidLineWidth ( 1 ); 58 setMidLineWidth ( 1 );
59 mw = new QWidget ( viewport() ); 59 mw = new QWidget ( viewport() );
60 addChild(mw); 60 addChild(mw);
61 setResizePolicy( AutoOneFit ); 61 setResizePolicy( AutoOneFit );
62 mainLayout = new QVBoxLayout ( mw ); 62 mainLayout = new QVBoxLayout ( mw );
63 mainLayout->setMargin( 2 ); 63 mainLayout->setMargin( 2 );
64 mainLayout->setSpacing( 2 ); 64 mainLayout->setSpacing( 2 );
65 QWidget* hb = new QWidget ( mw ); 65 QWidget* hb = new QWidget ( mw );
66 mainLayout->add( hb ); 66 mainLayout->add( hb );
67 QHBoxLayout* hbLayout = new QHBoxLayout ( hb ); 67 QHBoxLayout* hbLayout = new QHBoxLayout ( hb );
68 QPushButton *addBut = new QPushButton ( "add", hb ); 68 QPushButton *addBut = new QPushButton ( "add", hb );
69 hbLayout->add( addBut ); 69 hbLayout->add( addBut );
70 addBut->setPixmap ( SmallIcon("plus")); 70 addBut->setPixmap ( SmallIcon("plus"));
71 addBut->setMaximumSize( addBut->sizeHint().height(),addBut->sizeHint().height() ); 71 addBut->setMaximumSize( addBut->sizeHint().height(),addBut->sizeHint().height() );
72 connect(addBut,SIGNAL(clicked()),SLOT(addNumber())); 72 connect(addBut,SIGNAL(clicked()),SLOT(addNumber()));
73 //QLabel * temp = new QLabel( i18n("Phone Type"), hb ); 73 //QLabel * temp = new QLabel( i18n("Phone Type"), hb );
74 QLabel *temp = new QLabel( i18n("Phone Number"),hb ); 74 QLabel *temp = new QLabel( i18n("Phone Number"),hb );
75 temp->setAlignment( Qt::AlignCenter ); 75 temp->setAlignment( Qt::AlignCenter );
76 temp->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop, 0 ) ); 76 temp->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop, 0 ) );
77 hbLayout->add( temp ); 77 hbLayout->add( temp );
78 appendEditCombo();
79 appendEditCombo();
80 appendEditCombo();
81 setDefaults(); 78 setDefaults();
79 mTypeNumberEditList.setAutoDelete( true );
82} 80}
83 81
84PhoneEditWidget::~PhoneEditWidget() 82PhoneEditWidget::~PhoneEditWidget()
85{ 83{
86} 84}
87void PhoneEditWidget::setDefaults() 85void PhoneEditWidget::setDefaults()
88{ 86{
89 PhoneTypeNumberEdit* edit = mTypeNumberEditList.first(); 87 mTypeNumberEditList.clear();
88 PhoneTypeNumberEdit* edit = appendEditCombo();
90 KABC::PhoneNumber phoneNumber; 89 KABC::PhoneNumber phoneNumber;
91 phoneNumber.setType( KABC::PhoneNumber::Home | KABC::PhoneNumber::Pref ); 90 phoneNumber.setType( KABC::PhoneNumber::Home | KABC::PhoneNumber::Pref );
92 edit->setPhoneNumber( phoneNumber ); 91 edit->setPhoneNumber( phoneNumber );
93 edit = mTypeNumberEditList.next(); 92 edit = appendEditCombo();
94 phoneNumber.setType( KABC::PhoneNumber::Work | KABC::PhoneNumber::Pref ); 93 phoneNumber.setType( KABC::PhoneNumber::Work | KABC::PhoneNumber::Pref );
95 edit->setPhoneNumber( phoneNumber ); 94 edit->setPhoneNumber( phoneNumber );
96 edit = mTypeNumberEditList.next(); 95 edit = appendEditCombo();
97 phoneNumber.setType( KABC::PhoneNumber::Cell ); 96 phoneNumber.setType( KABC::PhoneNumber::Cell );
98 edit->setPhoneNumber( phoneNumber ); 97 edit->setPhoneNumber( phoneNumber );
99 edit = mTypeNumberEditList.next(); 98
100 while ( edit ) {
101 edit->hide();
102 edit = mTypeNumberEditList.next();
103 }
104} 99}
105void PhoneEditWidget::addNumber() 100void PhoneEditWidget::addNumber()
106{ 101{
107 102
108} 103}
109PhoneTypeNumberEdit* PhoneEditWidget::appendEditCombo() 104PhoneTypeNumberEdit* PhoneEditWidget::appendEditCombo()
110{ 105{
111 PhoneTypeNumberEdit* edit = new PhoneTypeNumberEdit( mw ); 106 PhoneTypeNumberEdit* edit = new PhoneTypeNumberEdit( mw );
112 connect ( edit, SIGNAL ( typeChange( int , int) ), this, SIGNAL ( typeChange( int , int)) ); 107 connect ( edit, SIGNAL ( typeChange( int , int) ), this, SIGNAL ( typeChange( int , int)) );
113 connect ( edit, SIGNAL ( modified() ), this, SIGNAL ( modified() ) ); 108 connect ( edit, SIGNAL ( modified() ), this, SIGNAL ( modified() ) );
109 connect ( edit, SIGNAL ( deleteMe( PhoneTypeNumberEdit* ) ), this, SLOT ( deleteEdit( PhoneTypeNumberEdit*) ) );
114 connect ( this, SIGNAL ( typeChange( int , int)), edit, SLOT ( typeExternalChanged( int, int)) ); 110 connect ( this, SIGNAL ( typeChange( int , int)), edit, SLOT ( typeExternalChanged( int, int)) );
115 111
116 mainLayout->add( edit ); 112 mainLayout->add( edit );
117 mTypeNumberEditList.append( edit ); 113 mTypeNumberEditList.append( edit );
118 return edit; 114 return edit;
119} 115}
120 116
117void PhoneEditWidget::deleteEdit( PhoneTypeNumberEdit* ew )
118{
119 mPendingDelete = ew;
120 QTimer::singleShot( 0, this, SLOT ( pendingDelete() ) );
121}
122void PhoneEditWidget::pendingDelete()
123{
124 mTypeNumberEditList.removeRef( mPendingDelete );
125 emit modified();
126}
127
121void PhoneEditWidget::setPhoneNumbers( const KABC::PhoneNumber::List &li ) 128void PhoneEditWidget::setPhoneNumbers( const KABC::PhoneNumber::List &li )
122{ 129{
123 if ( li.isEmpty() ) { 130 if ( li.isEmpty() ) {
124 setDefaults(); 131 setDefaults();
125 return; 132 return;
126 } 133 }
134 mTypeNumberEditList.clear();
127 KABC::PhoneNumber::List::Iterator it; 135 KABC::PhoneNumber::List::Iterator it;
128 KABC::PhoneNumber::List list = li; 136 KABC::PhoneNumber::List list = li;
129 PhoneTypeNumberEdit* edit = mTypeNumberEditList.first(); 137 PhoneTypeNumberEdit* edit = 0;//mTypeNumberEditList.first();
130 for ( it = list.begin(); it != list.end(); ++it ) { 138 for ( it = list.begin(); it != list.end(); ++it ) {
131 if ( edit ) { 139 if ( edit ) {
132 edit->setPhoneNumber( (*it ) ); 140 edit->setPhoneNumber( (*it ) );
133 edit = mTypeNumberEditList.next(); 141 edit = mTypeNumberEditList.next();
134 } else { 142 } else {
135 PhoneTypeNumberEdit* editNew = appendEditCombo(); 143 PhoneTypeNumberEdit* editNew = appendEditCombo();
136 editNew->setPhoneNumber( (*it ) ); 144 editNew->setPhoneNumber( (*it ) );
137 } 145 }
138 } 146 }
139 while ( edit ) { 147 while ( edit ) {
140 edit->hide(); 148 edit->hide();
141 edit = mTypeNumberEditList.next(); 149 edit = mTypeNumberEditList.next();
142 } 150 }
143 //mainLayout->invalidate ();
144 mw->update();
145} 151}
146KABC::PhoneNumber::List PhoneEditWidget::phoneNumbers() 152KABC::PhoneNumber::List PhoneEditWidget::phoneNumbers()
147{ 153{
148 KABC::PhoneNumber::List retList; 154 KABC::PhoneNumber::List retList;
149 155
150 PhoneTypeNumberEdit* edit = mTypeNumberEditList.first(); 156 PhoneTypeNumberEdit* edit = mTypeNumberEditList.first();
151 while ( edit ) { 157 while ( edit ) {
152 if ( edit->isValid() ) { 158 if ( edit->isValid() ) {
153 retList.append( edit->phoneNumber()); 159 retList.append( edit->phoneNumber());
154 } 160 }
155 edit = mTypeNumberEditList.next(); 161 edit = mTypeNumberEditList.next();
156 162
157 } 163 }
158 return retList; 164 return retList;
159} 165}
160 166
161#if 0 167#if 0
162PhoneEditWidget::PhoneEditWidget( QWidget *parent, const char *name ) 168PhoneEditWidget::PhoneEditWidget( QWidget *parent, const char *name )
163 : QWidget( parent, name ) 169 : QWidget( parent, name )
164{ 170{
165 QGridLayout *layout = new QGridLayout( this, 4, 1 ); 171 QGridLayout *layout = new QGridLayout( this, 4, 1 );
166//US layout->setSpacing( KDialog::spacingHint() ); 172//US layout->setSpacing( KDialog::spacingHint() );
167 layout->setSpacing( KDialogBase::spacingHintSmall() ); 173 layout->setSpacing( KDialogBase::spacingHintSmall() );
168 174
169 175
170 176
171 QLabel* label = new QLabel( this ); 177 QLabel* label = new QLabel( this );
172//US loadIcon call is ambiguous. Add one more parameter 178//US loadIcon call is ambiguous. Add one more parameter
173//US label->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop ) ); 179//US label->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop ) );
174 label->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop, 0 ) ); 180 label->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop, 0 ) );
175 label->setAlignment( AlignCenter ); 181 label->setAlignment( AlignCenter );
176//US layout->addMultiCellWidget( label, 0, 1, 3, 3 ); 182//US layout->addMultiCellWidget( label, 0, 1, 3, 3 );
177 layout->addWidget( label, 0, 0 ); 183 layout->addWidget( label, 0, 0 );
178 184
179 QPushButton *editButton = new QPushButton( i18n( "Edit Phone Numbers..." ), 185 QPushButton *editButton = new QPushButton( i18n( "Edit Phone Numbers..." ),
180 this ); 186 this );
181 if ( QApplication::desktop()->width() < 640 ) 187 if ( QApplication::desktop()->width() < 640 )
182 layout->addWidget( editButton, 0, 1 ); 188 layout->addWidget( editButton, 0, 1 );
183 else 189 else
184 layout->addMultiCellWidget( editButton, 0, 0, 1, 3); 190 layout->addMultiCellWidget( editButton, 0, 0, 1, 3);
185 191
186 mPrefCombo = new PhoneTypeCombo( mPhoneList, this ); 192 mPrefCombo = new PhoneTypeCombo( mPhoneList, this );
187 mPrefEdit = new KLineEdit( this ); 193 mPrefEdit = new KLineEdit( this );
188 //mPrefEdit->setMinimumWidth( int(mPrefEdit->sizeHint().width() * 1.5) ); 194 //mPrefEdit->setMinimumWidth( int(mPrefEdit->sizeHint().width() * 1.5) );
189 mPrefCombo->setLineEdit( mPrefEdit ); 195 mPrefCombo->setLineEdit( mPrefEdit );
190 layout->addWidget( mPrefCombo, 1, 0 ); 196 layout->addWidget( mPrefCombo, 1, 0 );
191 layout->addWidget( mPrefEdit, 1, 1 ); 197 layout->addWidget( mPrefEdit, 1, 1 );
192 int x = 1, y = 2; 198 int x = 1, y = 2;
193 if ( QApplication::desktop()->width() < 640 ) { 199 if ( QApplication::desktop()->width() < 640 ) {
194 ++x; 200 ++x;
195 y = 0; 201 y = 0;
196 } 202 }
197 mSecondCombo = new PhoneTypeCombo( mPhoneList, this ); 203 mSecondCombo = new PhoneTypeCombo( mPhoneList, this );
198 mSecondEdit = new KLineEdit( this ); 204 mSecondEdit = new KLineEdit( this );
199 mSecondCombo->setLineEdit( mSecondEdit ); 205 mSecondCombo->setLineEdit( mSecondEdit );
200 layout->addWidget( mSecondCombo, x, y++ ); 206 layout->addWidget( mSecondCombo, x, y++ );
201 layout->addWidget( mSecondEdit, x, y++ ); 207 layout->addWidget( mSecondEdit, x, y++ );
202 208
203 y = 0; 209 y = 0;
204 ++x; 210 ++x;
205 mThirdCombo = new PhoneTypeCombo( mPhoneList, this ); 211 mThirdCombo = new PhoneTypeCombo( mPhoneList, this );
206 mThirdEdit = new KLineEdit( this ); 212 mThirdEdit = new KLineEdit( this );
207 mThirdCombo->setLineEdit( mThirdEdit ); 213 mThirdCombo->setLineEdit( mThirdEdit );
208 layout->addWidget( mThirdCombo, x, y++ ); 214 layout->addWidget( mThirdCombo, x, y++ );
209 layout->addWidget( mThirdEdit, x, y++ ); 215 layout->addWidget( mThirdEdit, x, y++ );
210 if ( QApplication::desktop()->width() < 640 ) { 216 if ( QApplication::desktop()->width() < 640 ) {
211 ++x; 217 ++x;
212 y = 0; 218 y = 0;
213 } 219 }
214 mFourthCombo = new PhoneTypeCombo( mPhoneList, this ); 220 mFourthCombo = new PhoneTypeCombo( mPhoneList, this );
215 mFourthEdit = new KLineEdit( this ); 221 mFourthEdit = new KLineEdit( this );
216 mFourthCombo->setLineEdit( mFourthEdit ); 222 mFourthCombo->setLineEdit( mFourthEdit );
217 layout->addWidget( mFourthCombo, x, y++ ); 223 layout->addWidget( mFourthCombo, x, y++ );
218 layout->addWidget( mFourthEdit, x, y++ ); 224 layout->addWidget( mFourthEdit, x, y++ );
219 225
220 // Four numbers don't fit in the current dialog 226 // Four numbers don't fit in the current dialog
221 if ( QApplication::desktop()->width() < 640 ) { 227 if ( QApplication::desktop()->width() < 640 ) {
222 mFourthCombo->hide(); 228 mFourthCombo->hide();
223 mFourthEdit->hide(); 229 mFourthEdit->hide();
224 } else { 230 } else {
225 QFontMetrics fm ( font () ) ; 231 QFontMetrics fm ( font () ) ;
226 int wid = fm.width( "Messenger" ) +60; 232 int wid = fm.width( "Messenger" ) +60;
227 mPrefCombo->setMaximumWidth( wid ); 233 mPrefCombo->setMaximumWidth( wid );
228 mSecondCombo->setMaximumWidth( wid ); 234 mSecondCombo->setMaximumWidth( wid );
229 mThirdCombo->setMaximumWidth( wid ); 235 mThirdCombo->setMaximumWidth( wid );
230 mFourthCombo->setMaximumWidth( wid ); 236 mFourthCombo->setMaximumWidth( wid );
231 } 237 }
232 238
233 239
234 connect( mPrefEdit, SIGNAL( textChanged( const QString& ) ), 240 connect( mPrefEdit, SIGNAL( textChanged( const QString& ) ),
235 SLOT( slotPrefEditChanged() ) ); 241 SLOT( slotPrefEditChanged() ) );
236 connect( mSecondEdit, SIGNAL( textChanged( const QString& ) ), 242 connect( mSecondEdit, SIGNAL( textChanged( const QString& ) ),
237 SLOT( slotSecondEditChanged() ) ); 243 SLOT( slotSecondEditChanged() ) );
238 connect( mThirdEdit, SIGNAL( textChanged( const QString& ) ), 244 connect( mThirdEdit, SIGNAL( textChanged( const QString& ) ),
239 SLOT( slotThirdEditChanged() ) ); 245 SLOT( slotThirdEditChanged() ) );
240 connect( mFourthEdit, SIGNAL( textChanged( const QString& ) ), 246 connect( mFourthEdit, SIGNAL( textChanged( const QString& ) ),
241 SLOT( slotFourthEditChanged() ) ); 247 SLOT( slotFourthEditChanged() ) );
242 248
243 connect( editButton, SIGNAL( clicked() ), SLOT( edit() ) ); 249 connect( editButton, SIGNAL( clicked() ), SLOT( edit() ) );
244 250
245 connect( mPrefCombo, SIGNAL( activated( int ) ), 251 connect( mPrefCombo, SIGNAL( activated( int ) ),
246 SLOT( updatePrefEdit() ) ); 252 SLOT( updatePrefEdit() ) );
247 connect( mSecondCombo, SIGNAL( activated( int ) ), 253 connect( mSecondCombo, SIGNAL( activated( int ) ),
248 SLOT( updateSecondEdit() ) ); 254 SLOT( updateSecondEdit() ) );
249 connect( mThirdCombo, SIGNAL( activated( int ) ), 255 connect( mThirdCombo, SIGNAL( activated( int ) ),
250 SLOT( updateThirdEdit() ) ); 256 SLOT( updateThirdEdit() ) );
251 connect( mFourthCombo, SIGNAL( activated( int ) ), 257 connect( mFourthCombo, SIGNAL( activated( int ) ),
252 SLOT( updateFourthEdit() ) ); 258 SLOT( updateFourthEdit() ) );
253} 259}
254 260
255PhoneEditWidget::~PhoneEditWidget() 261PhoneEditWidget::~PhoneEditWidget()
256{ 262{
257} 263}
258 264
259void PhoneEditWidget::setPhoneNumbers( const KABC::PhoneNumber::List &list ) 265void PhoneEditWidget::setPhoneNumbers( const KABC::PhoneNumber::List &list )
260{ 266{
261 mPhoneList.clear(); 267 mPhoneList.clear();
262 268
263 // Insert types for existing numbers. 269 // Insert types for existing numbers.
264 mPrefCombo->insertTypeList( list ); 270 mPrefCombo->insertTypeList( list );
265 271
266 QValueList<int> defaultTypes; 272 QValueList<int> defaultTypes;
267 defaultTypes << KABC::PhoneNumber::Home; 273 defaultTypes << KABC::PhoneNumber::Home;
268 defaultTypes << KABC::PhoneNumber::Work; 274 defaultTypes << KABC::PhoneNumber::Work;
269 defaultTypes << KABC::PhoneNumber::Cell; 275 defaultTypes << KABC::PhoneNumber::Cell;
270 defaultTypes << ( KABC::PhoneNumber::Work | KABC::PhoneNumber::Fax ); 276 defaultTypes << ( KABC::PhoneNumber::Work | KABC::PhoneNumber::Fax );
271 defaultTypes << ( KABC::PhoneNumber::Home | KABC::PhoneNumber::Fax ); 277 defaultTypes << ( KABC::PhoneNumber::Home | KABC::PhoneNumber::Fax );
272 278
273 // Insert default types. 279 // Insert default types.
274 // Doing this for mPrefCombo is enough because the list is shared by all 280 // Doing this for mPrefCombo is enough because the list is shared by all
275 // combos. 281 // combos.
276 QValueList<int>::ConstIterator it; 282 QValueList<int>::ConstIterator it;
277 for( it = defaultTypes.begin(); it != defaultTypes.end(); ++it ) { 283 for( it = defaultTypes.begin(); it != defaultTypes.end(); ++it ) {
278 if ( !mPrefCombo->hasType( *it ) ) 284 if ( !mPrefCombo->hasType( *it ) )
279 mPrefCombo->insertType( list, *it, PhoneNumber( "", *it ) ); 285 mPrefCombo->insertType( list, *it, PhoneNumber( "", *it ) );
280 } 286 }
281 287
282 updateCombos(); 288 updateCombos();
283 289
284 mPrefCombo->selectType( defaultTypes[ 0 ] ); 290 mPrefCombo->selectType( defaultTypes[ 0 ] );
285 mSecondCombo->selectType( defaultTypes[ 1 ] ); 291 mSecondCombo->selectType( defaultTypes[ 1 ] );
286 mThirdCombo->selectType( defaultTypes[ 2 ] ); 292 mThirdCombo->selectType( defaultTypes[ 2 ] );
287 mFourthCombo->selectType( defaultTypes[ 3 ] ); 293 mFourthCombo->selectType( defaultTypes[ 3 ] );
288 294
289 updateLineEdits(); 295 updateLineEdits();
290} 296}
291 297
292void PhoneEditWidget::updateLineEdits() 298void PhoneEditWidget::updateLineEdits()
293{ 299{
294 updatePrefEdit(); 300 updatePrefEdit();
295 updateSecondEdit(); 301 updateSecondEdit();
296 updateThirdEdit(); 302 updateThirdEdit();
297 updateFourthEdit(); 303 updateFourthEdit();
298} 304}
299 305
300void PhoneEditWidget::updateCombos() 306void PhoneEditWidget::updateCombos()
301{ 307{
302 mPrefCombo->updateTypes(); 308 mPrefCombo->updateTypes();
303 mSecondCombo->updateTypes(); 309 mSecondCombo->updateTypes();
304 mThirdCombo->updateTypes(); 310 mThirdCombo->updateTypes();
305 mFourthCombo->updateTypes(); 311 mFourthCombo->updateTypes();
306} 312}
307 313
308KABC::PhoneNumber::List PhoneEditWidget::phoneNumbers() 314KABC::PhoneNumber::List PhoneEditWidget::phoneNumbers()
309{ 315{
310 KABC::PhoneNumber::List retList; 316 KABC::PhoneNumber::List retList;
311 317
312 KABC::PhoneNumber::List::Iterator it; 318 KABC::PhoneNumber::List::Iterator it;
313 for ( it = mPhoneList.begin(); it != mPhoneList.end(); ++it ) 319 for ( it = mPhoneList.begin(); it != mPhoneList.end(); ++it )
314 if ( !(*it).number().isEmpty() ) 320 if ( !(*it).number().isEmpty() )
315 retList.append( *it ); 321 retList.append( *it );
316 322
317 return retList; 323 return retList;
318} 324}
319 325
320void PhoneEditWidget::edit() 326void PhoneEditWidget::edit()
321{ 327{
322 PhoneEditDialog dlg( mPhoneList, this ); 328 PhoneEditDialog dlg( mPhoneList, this );
323 329
324 if ( dlg.exec() ) { 330 if ( dlg.exec() ) {
325 if ( dlg.changed() ) { 331 if ( dlg.changed() ) {
326 KABC::PhoneNumber::List list = dlg.phoneNumbers(); 332 KABC::PhoneNumber::List list = dlg.phoneNumbers();
327 setPhoneNumbers( list ); 333 setPhoneNumbers( list );
328 updateCombos(); 334 updateCombos();
329 updateLineEdits(); 335 updateLineEdits();
330 emit modified(); 336 emit modified();
331 } 337 }
332 } 338 }
333} 339}
334 340
335void PhoneEditWidget::updatePrefEdit() 341void PhoneEditWidget::updatePrefEdit()
336{ 342{
337 updateEdit( mPrefCombo ); 343 updateEdit( mPrefCombo );
338} 344}
339 345
340void PhoneEditWidget::updateSecondEdit() 346void PhoneEditWidget::updateSecondEdit()
341{ 347{
342 updateEdit( mSecondCombo ); 348 updateEdit( mSecondCombo );
343} 349}
344 350
345void PhoneEditWidget::updateThirdEdit() 351void PhoneEditWidget::updateThirdEdit()
346{ 352{
347 updateEdit( mThirdCombo ); 353 updateEdit( mThirdCombo );
348} 354}
349 355
350void PhoneEditWidget::updateFourthEdit() 356void PhoneEditWidget::updateFourthEdit()
351{ 357{
352 updateEdit( mFourthCombo ); 358 updateEdit( mFourthCombo );
353} 359}
354 360
355void PhoneEditWidget::updateEdit( PhoneTypeCombo *combo ) 361void PhoneEditWidget::updateEdit( PhoneTypeCombo *combo )
356{ 362{
357 QLineEdit *edit = combo->lineEdit(); 363 QLineEdit *edit = combo->lineEdit();
358 if ( !edit ) 364 if ( !edit )
359 return; 365 return;
360 366
361#if 0 367#if 0
362 if ( edit == mPrefEdit ) kdDebug(5720) << " prefEdit" << endl; 368 if ( edit == mPrefEdit ) kdDebug(5720) << " prefEdit" << endl;
363 if ( edit == mSecondEdit ) kdDebug(5720) << " secondEdit" << endl; 369 if ( edit == mSecondEdit ) kdDebug(5720) << " secondEdit" << endl;
364 if ( edit == mThirdEdit ) kdDebug(5720) << " thirdEdit" << endl; 370 if ( edit == mThirdEdit ) kdDebug(5720) << " thirdEdit" << endl;
365 if ( edit == mFourthEdit ) kdDebug(5720) << " fourthEdit" << endl; 371 if ( edit == mFourthEdit ) kdDebug(5720) << " fourthEdit" << endl;
366#endif 372#endif
367 373
368 PhoneNumber::List::Iterator it = combo->selectedElement(); 374 PhoneNumber::List::Iterator it = combo->selectedElement();
369 if ( it != mPhoneList.end() ) { 375 if ( it != mPhoneList.end() ) {
370 edit->setText( (*it).number() ); 376 edit->setText( (*it).number() );
371 } else { 377 } else {
372 kdDebug(5720) << "PhoneEditWidget::updateEdit(): no selected element" << endl; 378 kdDebug(5720) << "PhoneEditWidget::updateEdit(): no selected element" << endl;
373 } 379 }
374} 380}
375 381
376void PhoneEditWidget::slotPrefEditChanged() 382void PhoneEditWidget::slotPrefEditChanged()
377{ 383{
378 updatePhoneNumber( mPrefCombo ); 384 updatePhoneNumber( mPrefCombo );
379} 385}
380 386
381void PhoneEditWidget::slotSecondEditChanged() 387void PhoneEditWidget::slotSecondEditChanged()
382{ 388{
383 updatePhoneNumber( mSecondCombo ); 389 updatePhoneNumber( mSecondCombo );
384} 390}
385 391
386void PhoneEditWidget::slotThirdEditChanged() 392void PhoneEditWidget::slotThirdEditChanged()
387{ 393{
388 updatePhoneNumber( mThirdCombo ); 394 updatePhoneNumber( mThirdCombo );
389} 395}
390 396
391void PhoneEditWidget::slotFourthEditChanged() 397void PhoneEditWidget::slotFourthEditChanged()
392{ 398{
393 updatePhoneNumber( mFourthCombo ); 399 updatePhoneNumber( mFourthCombo );
394} 400}
395 401
396void PhoneEditWidget::updatePhoneNumber( PhoneTypeCombo *combo ) 402void PhoneEditWidget::updatePhoneNumber( PhoneTypeCombo *combo )
397{ 403{
398 QLineEdit *edit = combo->lineEdit(); 404 QLineEdit *edit = combo->lineEdit();
399 if ( !edit ) return; 405 if ( !edit ) return;
400 406
401 PhoneNumber::List::Iterator it = combo->selectedElement(); 407 PhoneNumber::List::Iterator it = combo->selectedElement();
402 if ( it != mPhoneList.end() ) { 408 if ( it != mPhoneList.end() ) {
403 (*it).setNumber( edit->text() ); 409 (*it).setNumber( edit->text() );
404 } 410 }
405 411
406 updateOtherEdit( combo, mPrefCombo ); 412 updateOtherEdit( combo, mPrefCombo );
407 updateOtherEdit( combo, mSecondCombo ); 413 updateOtherEdit( combo, mSecondCombo );
408 updateOtherEdit( combo, mThirdCombo ); 414 updateOtherEdit( combo, mThirdCombo );
409 updateOtherEdit( combo, mFourthCombo ); 415 updateOtherEdit( combo, mFourthCombo );
410 416
411 emit modified(); 417 emit modified();
412} 418}
413 419
414void PhoneEditWidget::updateOtherEdit( PhoneTypeCombo *combo, PhoneTypeCombo *otherCombo ) 420void PhoneEditWidget::updateOtherEdit( PhoneTypeCombo *combo, PhoneTypeCombo *otherCombo )
415{ 421{
416 if ( combo == otherCombo ) return; 422 if ( combo == otherCombo ) return;
417 423
418 if ( combo->currentItem() == otherCombo->currentItem() ) { 424 if ( combo->currentItem() == otherCombo->currentItem() ) {
419 updateEdit( otherCombo ); 425 updateEdit( otherCombo );
420 } 426 }
421} 427}
422 428
423/////////////////////////////////////////// 429///////////////////////////////////////////
424// PhoneEditDialog 430// PhoneEditDialog
425 431
426class PhoneViewItem : public QListViewItem 432class PhoneViewItem : public QListViewItem
427{ 433{
428public: 434public:
429 PhoneViewItem( QListView *parent, const KABC::PhoneNumber &number ); 435 PhoneViewItem( QListView *parent, const KABC::PhoneNumber &number );
430 436
431 void setPhoneNumber( const KABC::PhoneNumber &number ) 437 void setPhoneNumber( const KABC::PhoneNumber &number )
432 { 438 {
433 mPhoneNumber = number; 439 mPhoneNumber = number;
434 makeText(); 440 makeText();
435 } 441 }
436 442
437 QString key() { return mPhoneNumber.id(); } 443 QString key() { return mPhoneNumber.id(); }
438 QString country() { return ""; } 444 QString country() { return ""; }
439 QString region() { return ""; } 445 QString region() { return ""; }
440 QString number() { return ""; } 446 QString number() { return ""; }
441 447
442 KABC::PhoneNumber phoneNumber() { return mPhoneNumber; } 448 KABC::PhoneNumber phoneNumber() { return mPhoneNumber; }
443 449
444private: 450private:
445 void makeText(); 451 void makeText();
446 452
447 KABC::PhoneNumber mPhoneNumber; 453 KABC::PhoneNumber mPhoneNumber;
448}; 454};
449 455
450PhoneViewItem::PhoneViewItem( QListView *parent, const KABC::PhoneNumber &number ) 456PhoneViewItem::PhoneViewItem( QListView *parent, const KABC::PhoneNumber &number )
451 : QListViewItem( parent ), mPhoneNumber( number ) 457 : QListViewItem( parent ), mPhoneNumber( number )
452{ 458{
453#ifdef DESKTOP_VERSION 459#ifdef DESKTOP_VERSION
454 setRenameEnabled ( 0, true ); 460 setRenameEnabled ( 0, true );
455#endif 461#endif
456 makeText(); 462 makeText();
457} 463}
458 464
459void PhoneViewItem::makeText() 465void PhoneViewItem::makeText()
460{ 466{
461 /** 467 /**
462 * Will be used in future versions of kaddressbook/libkabc 468 * Will be used in future versions of kaddressbook/libkabc
463 469
464 setText( 0, mPhoneNumber.country() ); 470 setText( 0, mPhoneNumber.country() );
465 setText( 1, mPhoneNumber.region() ); 471 setText( 1, mPhoneNumber.region() );
466 setText( 2, mPhoneNumber.number() ); 472 setText( 2, mPhoneNumber.number() );
467 setText( 3, mPhoneNumber.typeLabel() ); 473 setText( 3, mPhoneNumber.typeLabel() );
468 */ 474 */
469 475
470 setText( 0, mPhoneNumber.number() ); 476 setText( 0, mPhoneNumber.number() );
471 setText( 1, mPhoneNumber.typeLabel() ); 477 setText( 1, mPhoneNumber.typeLabel() );
472} 478}
473 479
474PhoneEditDialog::PhoneEditDialog( const KABC::PhoneNumber::List &list, QWidget *parent, const char *name ) 480PhoneEditDialog::PhoneEditDialog( const KABC::PhoneNumber::List &list, QWidget *parent, const char *name )
475 : KDialogBase( KDialogBase::Plain, i18n( "Edit Phone Numbers" ), 481 : KDialogBase( KDialogBase::Plain, i18n( "Edit Phone Numbers" ),
476 KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok, 482 KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok,
477 parent, name, true) 483 parent, name, true)
478{ 484{
479 mPhoneNumberList = list; 485 mPhoneNumberList = list;
480 486
481 QWidget *page = plainPage(); 487 QWidget *page = plainPage();
482 488
483 QGridLayout *layout = new QGridLayout( page, 1, 2 ); 489 QGridLayout *layout = new QGridLayout( page, 1, 2 );
484 layout->setSpacing( spacingHint() ); 490 layout->setSpacing( spacingHint() );
485 491
486 mListView = new KListView( page ); 492 mListView = new KListView( page );
487 mListView->setAllColumnsShowFocus( true ); 493 mListView->setAllColumnsShowFocus( true );
488 mListView->addColumn( i18n( "Number" ) ); 494 mListView->addColumn( i18n( "Number" ) );
489 mListView->addColumn( i18n( "Type" ) ); 495 mListView->addColumn( i18n( "Type" ) );
490 496
491 KButtonBox *buttonBox = new KButtonBox( page, Vertical ); 497 KButtonBox *buttonBox = new KButtonBox( page, Vertical );
492 498
493 buttonBox->addButton( i18n( "&Add..." ), this, SLOT( slotAddPhoneNumber() ) ); 499 buttonBox->addButton( i18n( "&Add..." ), this, SLOT( slotAddPhoneNumber() ) );
494 mEditButton = buttonBox->addButton( i18n( "&Edit..." ), this, SLOT( slotEditPhoneNumber() ) ); 500 mEditButton = buttonBox->addButton( i18n( "&Edit..." ), this, SLOT( slotEditPhoneNumber() ) );
495 mEditButton->setEnabled( false ); 501 mEditButton->setEnabled( false );
496 mRemoveButton = buttonBox->addButton( i18n( "&Remove" ), this, SLOT( slotRemovePhoneNumber() ) ); 502 mRemoveButton = buttonBox->addButton( i18n( "&Remove" ), this, SLOT( slotRemovePhoneNumber() ) );
497 mRemoveButton->setEnabled( false ); 503 mRemoveButton->setEnabled( false );
498 buttonBox->layout(); 504 buttonBox->layout();
499 505
500 layout->addWidget( mListView, 0, 0 ); 506 layout->addWidget( mListView, 0, 0 );
501 layout->addWidget( buttonBox, 0, 1 ); 507 layout->addWidget( buttonBox, 0, 1 );
502 508
503 connect( mListView, SIGNAL(selectionChanged()), SLOT(slotSelectionChanged()) ); 509 connect( mListView, SIGNAL(selectionChanged()), SLOT(slotSelectionChanged()) );
504 connect( mListView, SIGNAL(doubleClicked( QListViewItem *, const QPoint &, int )), this, SLOT( slotEditPhoneNumber())); 510 connect( mListView, SIGNAL(doubleClicked( QListViewItem *, const QPoint &, int )), this, SLOT( slotEditPhoneNumber()));
505 511
506 KABC::PhoneNumber::List::Iterator it; 512 KABC::PhoneNumber::List::Iterator it;
507 for ( it = mPhoneNumberList.begin(); it != mPhoneNumberList.end(); ++it ) 513 for ( it = mPhoneNumberList.begin(); it != mPhoneNumberList.end(); ++it )
508 new PhoneViewItem( mListView, *it ); 514 new PhoneViewItem( mListView, *it );
509 if (QApplication::desktop()->width() < 480 ) 515 if (QApplication::desktop()->width() < 480 )
510 showMaximized(); 516 showMaximized();
511 else 517 else
512 resize( 400, 400 ); 518 resize( 400, 400 );
513 mChanged = false; 519 mChanged = false;
514} 520}
515 521
516PhoneEditDialog::~PhoneEditDialog() 522PhoneEditDialog::~PhoneEditDialog()
517{ 523{
524 qDebug("PhoneEditDialog::~PhoneEditDialog() ");
518} 525}
519 526
520void PhoneEditDialog::slotAddPhoneNumber() 527void PhoneEditDialog::slotAddPhoneNumber()
521{ 528{
522 KABC::PhoneNumber tmp( "", 0 ); 529 KABC::PhoneNumber tmp( "", 0 );
523 PhoneTypeDialog dlg( tmp, this ); 530 PhoneTypeDialog dlg( tmp, this );
524 531
525 if ( dlg.exec() ) { 532 if ( dlg.exec() ) {
526 QListViewItem* i = mListView->firstChild(); 533 QListViewItem* i = mListView->firstChild();
527 KABC::PhoneNumber phoneNumber = dlg.phoneNumber(); 534 KABC::PhoneNumber phoneNumber = dlg.phoneNumber();
528 bool insert = true; 535 bool insert = true;
529 while ( i ) { 536 while ( i ) {
530 PhoneViewItem* p = ( PhoneViewItem* ) i; 537 PhoneViewItem* p = ( PhoneViewItem* ) i;
531 KABC::PhoneNumber pn = p->phoneNumber(); 538 KABC::PhoneNumber pn = p->phoneNumber();
532 if ( (pn.type() | KABC::PhoneNumber::Pref) == (phoneNumber.type() | KABC::PhoneNumber::Pref) ) { 539 if ( (pn.type() | KABC::PhoneNumber::Pref) == (phoneNumber.type() | KABC::PhoneNumber::Pref) ) {
533 if ( p->text(0).isEmpty()) { 540 if ( p->text(0).isEmpty()) {
534 p->setPhoneNumber( phoneNumber ); 541 p->setPhoneNumber( phoneNumber );
535 mPhoneNumberList.remove( pn ); 542 mPhoneNumberList.remove( pn );
536 mPhoneNumberList.append( phoneNumber ); 543 mPhoneNumberList.append( phoneNumber );
537 insert = false; 544 insert = false;
538 break; 545 break;
539 } 546 }
540 } 547 }
541 i = i->nextSibling(); 548 i = i->nextSibling();
542 } 549 }
543 if ( insert ) { 550 if ( insert ) {
544 mPhoneNumberList.append( phoneNumber ); 551 mPhoneNumberList.append( phoneNumber );
545 new PhoneViewItem( mListView, phoneNumber ); 552 new PhoneViewItem( mListView, phoneNumber );
546 } 553 }
547 mChanged = true; 554 mChanged = true;
548 } 555 }
549} 556}
550 557
551void PhoneEditDialog::slotRemovePhoneNumber() 558void PhoneEditDialog::slotRemovePhoneNumber()
552{ 559{
553 PhoneViewItem *item = static_cast<PhoneViewItem*>( mListView->currentItem() ); 560 PhoneViewItem *item = static_cast<PhoneViewItem*>( mListView->currentItem() );
554 if ( !item ) 561 if ( !item )
555 return; 562 return;
556 563
557 mPhoneNumberList.remove( item->phoneNumber() ); 564 mPhoneNumberList.remove( item->phoneNumber() );
558 QListViewItem *currItem = mListView->currentItem(); 565 QListViewItem *currItem = mListView->currentItem();
559 mListView->takeItem( currItem ); 566 mListView->takeItem( currItem );
560 delete currItem; 567 delete currItem;
561 568
562 mChanged = true; 569 mChanged = true;
563} 570}
564 571
565void PhoneEditDialog::slotEditPhoneNumber() 572void PhoneEditDialog::slotEditPhoneNumber()
566{ 573{
567 PhoneViewItem *item = static_cast<PhoneViewItem*>( mListView->currentItem() ); 574 PhoneViewItem *item = static_cast<PhoneViewItem*>( mListView->currentItem() );
568 if ( !item ) 575 if ( !item )
569 return; 576 return;
570 577
571 PhoneTypeDialog dlg( item->phoneNumber(), this ); 578 PhoneTypeDialog dlg( item->phoneNumber(), this );
572 579
573 if ( dlg.exec() ) { 580 if ( dlg.exec() ) {
574 slotRemovePhoneNumber(); 581 slotRemovePhoneNumber();
575 KABC::PhoneNumber phoneNumber = dlg.phoneNumber(); 582 KABC::PhoneNumber phoneNumber = dlg.phoneNumber();
576 mPhoneNumberList.append( phoneNumber ); 583 mPhoneNumberList.append( phoneNumber );
577 new PhoneViewItem( mListView, phoneNumber ); 584 new PhoneViewItem( mListView, phoneNumber );
578 585
579 mChanged = true; 586 mChanged = true;
580 } 587 }
581} 588}
582 589
583void PhoneEditDialog::slotSelectionChanged() 590void PhoneEditDialog::slotSelectionChanged()
584{ 591{
585 bool state = ( mListView->currentItem() != 0 ); 592 bool state = ( mListView->currentItem() != 0 );
586 593
587 mRemoveButton->setEnabled( state ); 594 mRemoveButton->setEnabled( state );
588 mEditButton->setEnabled( state ); 595 mEditButton->setEnabled( state );
589} 596}
590 597
591const KABC::PhoneNumber::List &PhoneEditDialog::phoneNumbers() 598const KABC::PhoneNumber::List &PhoneEditDialog::phoneNumbers()
592{ 599{
593 return mPhoneNumberList; 600 return mPhoneNumberList;
594} 601}
595 602
596bool PhoneEditDialog::changed() const 603bool PhoneEditDialog::changed() const
597{ 604{
598 return mChanged; 605 return mChanged;
599} 606}
600 607
601/////////////////////////////////////////// 608///////////////////////////////////////////
602// PhoneTypeDialog 609// PhoneTypeDialog
603PhoneTypeDialog::PhoneTypeDialog( const KABC::PhoneNumber &phoneNumber, 610PhoneTypeDialog::PhoneTypeDialog( const KABC::PhoneNumber &phoneNumber,
604 QWidget *parent, const char *name) 611 QWidget *parent, const char *name)
605 : KDialogBase( KDialogBase::Plain, i18n( "Edit Phone Number" ), 612 : KDialogBase( KDialogBase::Plain, i18n( "Edit Phone Number" ),
606 KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok, 613 KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok,
607 parent, name, true), mPhoneNumber( phoneNumber ) 614 parent, name, true), mPhoneNumber( phoneNumber )
608{ 615{
609 QWidget *page = plainPage(); 616 QWidget *page = plainPage();
610 QLabel *label = 0; 617 QLabel *label = 0;
611 QGridLayout *layout = new QGridLayout( page, 3, 2, marginHint(), spacingHint() ); 618 QGridLayout *layout = new QGridLayout( page, 3, 2, marginHint(), spacingHint() );
612 619
613 label = new QLabel( i18n( "Number:" ), page ); 620 label = new QLabel( i18n( "Number:" ), page );
614 layout->addWidget( label, 0, 0 ); 621 layout->addWidget( label, 0, 0 );
615 mNumber = new KLineEdit( page ); 622 mNumber = new KLineEdit( page );
616 layout->addWidget( mNumber, 0, 1 ); 623 layout->addWidget( mNumber, 0, 1 );
617 624
618 mPreferredBox = new QCheckBox( i18n( "This is the preferred phone number" ), page ); 625 mPreferredBox = new QCheckBox( i18n( "This is the preferred phone number" ), page );
619 layout->addMultiCellWidget( mPreferredBox, 1, 1, 0, 1 ); 626 layout->addMultiCellWidget( mPreferredBox, 1, 1, 0, 1 );
620 627
621 mGroup = new QButtonGroup( 2, Horizontal, i18n( "Types" ), page ); 628 mGroup = new QButtonGroup( 2, Horizontal, i18n( "Types" ), page );
622 layout->addMultiCellWidget( mGroup, 2, 2, 0, 1 ); 629 layout->addMultiCellWidget( mGroup, 2, 2, 0, 1 );
623 630
624 // fill widgets 631 // fill widgets
625 mNumber->setText( mPhoneNumber.number() ); 632 mNumber->setText( mPhoneNumber.number() );
626 633
627 mTypeList = KABC::PhoneNumber::typeList(); 634 mTypeList = KABC::PhoneNumber::typeList();
628 mTypeList.remove( KABC::PhoneNumber::Pref ); 635 mTypeList.remove( KABC::PhoneNumber::Pref );
629 636
630 KABC::PhoneNumber::TypeList::Iterator it; 637 KABC::PhoneNumber::TypeList::Iterator it;
631 for ( it = mTypeList.begin(); it != mTypeList.end(); ++it ) 638 for ( it = mTypeList.begin(); it != mTypeList.end(); ++it )
632 new QCheckBox( KABC::PhoneNumber::typeLabel( *it ), mGroup ); 639 new QCheckBox( KABC::PhoneNumber::typeLabel( *it ), mGroup );
633 640
634 for ( int i = 0; i < mGroup->count(); ++i ) { 641 for ( int i = 0; i < mGroup->count(); ++i ) {
635 int type = mPhoneNumber.type(); 642 int type = mPhoneNumber.type();
636 QCheckBox *box = (QCheckBox*)mGroup->find( i ); 643 QCheckBox *box = (QCheckBox*)mGroup->find( i );
637 box->setChecked( type & mTypeList[ i ] ); 644 box->setChecked( type & mTypeList[ i ] );
638 } 645 }
639 646
640 mPreferredBox->setChecked( mPhoneNumber.type() & KABC::PhoneNumber::Pref ); 647 mPreferredBox->setChecked( mPhoneNumber.type() & KABC::PhoneNumber::Pref );
641 mNumber->setFocus(); 648 mNumber->setFocus();
642 mNumber->setSelection( 0, 1024); 649 mNumber->setSelection( 0, 1024);
643} 650}
644 651
645KABC::PhoneNumber PhoneTypeDialog::phoneNumber() 652KABC::PhoneNumber PhoneTypeDialog::phoneNumber()
646{ 653{
647 mPhoneNumber.setNumber( mNumber->text() ); 654 mPhoneNumber.setNumber( mNumber->text() );
648 655
649 int type = 0; 656 int type = 0;
650 for ( int i = 0; i < mGroup->count(); ++i ) { 657 for ( int i = 0; i < mGroup->count(); ++i ) {
651 QCheckBox *box = (QCheckBox*)mGroup->find( i ); 658 QCheckBox *box = (QCheckBox*)mGroup->find( i );
652 if ( box->isChecked() ) 659 if ( box->isChecked() )
653 type += mTypeList[ i ]; 660 type += mTypeList[ i ];
654 } 661 }
655 662
656 if ( mPreferredBox->isChecked() ) 663 if ( mPreferredBox->isChecked() )
657 mPhoneNumber.setType( type | KABC::PhoneNumber::Pref ); 664 mPhoneNumber.setType( type | KABC::PhoneNumber::Pref );
658 else 665 else
659 mPhoneNumber.setType( type & ~KABC::PhoneNumber::Pref ); 666 mPhoneNumber.setType( type & ~KABC::PhoneNumber::Pref );
660 667
661 return mPhoneNumber; 668 return mPhoneNumber;
662} 669}
663#endif 670#endif
664#ifndef KAB_EMBEDDED 671#ifndef KAB_EMBEDDED
665#include "phoneeditwidget.moc" 672#include "phoneeditwidget.moc"
666#endif //KAB_EMBEDDED 673#endif //KAB_EMBEDDED