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