summaryrefslogtreecommitdiffabout
path: root/kaddressbook/phoneeditwidget.cpp
Unidiff
Diffstat (limited to 'kaddressbook/phoneeditwidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/phoneeditwidget.cpp11
1 files changed, 7 insertions, 4 deletions
diff --git a/kaddressbook/phoneeditwidget.cpp b/kaddressbook/phoneeditwidget.cpp
index 5639aa2..df3b551 100644
--- a/kaddressbook/phoneeditwidget.cpp
+++ b/kaddressbook/phoneeditwidget.cpp
@@ -1,503 +1,506 @@
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 <kmessagebox.h>
43#include <klineedit.h> 44#include <klineedit.h>
44#include <kcombobox.h> 45#include <kcombobox.h>
45#include <klocale.h> 46#include <klocale.h>
46#include <kdebug.h> 47#include <kdebug.h>
47#include <kglobal.h> 48#include <kglobal.h>
48#include <kiconloader.h> 49#include <kiconloader.h>
49 50
50#include <kabc/phonenumber.h> 51#include <kabc/phonenumber.h>
51 52
52#include "typecombo.h" 53#include "typecombo.h"
53 54
54#include "phoneeditwidget.h" 55#include "phoneeditwidget.h"
55 56
56PhoneEditWidget::PhoneEditWidget( QWidget *parent, const char *name ) 57PhoneEditWidget::PhoneEditWidget( QWidget *parent, const char *name )
57 : QWidget(parent,name) 58 : QWidget(parent,name)
58{ 59{
59 QGridLayout* gridLayout = new QGridLayout ( this, 2,2 ); 60 QGridLayout* gridLayout = new QGridLayout ( this, 2,2 );
60 61
61 QLabel *temp = new QLabel( "", this ); 62 QLabel *temp = new QLabel( "", this );
62 temp->setAlignment( Qt::AlignCenter ); 63 temp->setAlignment( Qt::AlignCenter );
63 temp->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop, 0 ) ); 64 temp->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop, 0 ) );
64 QPushButton *addBut = new QPushButton ( "add", this ); 65 QPushButton *addBut = new QPushButton ( "add", this );
65 addBut->setPixmap ( SmallIcon("plus")); 66 addBut->setPixmap ( SmallIcon("plus"));
66 addBut->setMaximumSize( addBut->sizeHint().height(),addBut->sizeHint().height() ); 67 addBut->setMaximumSize( addBut->sizeHint().height(),addBut->sizeHint().height() );
67 connect(addBut,SIGNAL(clicked ()),SLOT(addNumber())); 68 connect(addBut,SIGNAL(clicked ()),SLOT(addNumber()));
68 69
69 sv = new QScrollView( this ); 70 sv = new QScrollView( this );
70 sv->setFrameStyle ( QFrame::Plain ); 71 sv->setFrameStyle ( QFrame::Plain );
71 sv->setLineWidth ( 0 ); 72 sv->setLineWidth ( 0 );
72 sv->setMidLineWidth ( 0 ); 73 sv->setMidLineWidth ( 0 );
73 mw = new QWidget ( sv->viewport() ); 74 mw = new QWidget ( sv->viewport() );
74 sv->addChild(mw); 75 sv->addChild(mw);
75 sv->setResizePolicy( QScrollView::AutoOneFit ); 76 sv->setResizePolicy( QScrollView::AutoOneFit );
76 mainLayout = new QVBoxLayout ( mw ); 77 mainLayout = new QVBoxLayout ( mw );
77 mainLayout->setMargin( 0 ); 78 mainLayout->setMargin( 0 );
78 mainLayout->setSpacing( 0 ); 79 mainLayout->setSpacing( 0 );
79 gridLayout->setMargin( 2 ); 80 gridLayout->setMargin( 2 );
80 gridLayout->setSpacing( 4 ); 81 gridLayout->setSpacing( 4 );
81 if ( QApplication::desktop()->width() == 240 || QApplication::desktop()->width() == 480 ) { 82 if ( QApplication::desktop()->width() == 240 || QApplication::desktop()->width() == 480 ) {
82 gridLayout->addWidget( addBut, 0, 0 ); 83 gridLayout->addWidget( addBut, 0, 0 );
83 gridLayout->addWidget( temp, 0, 1 ); 84 gridLayout->addWidget( temp, 0, 1 );
84 gridLayout->addMultiCellWidget( sv, 1,1 , 0,1 ); 85 gridLayout->addMultiCellWidget( sv, 1,1 , 0,1 );
85 } else { 86 } else {
86 gridLayout->addWidget( temp, 1, 0 ); 87 gridLayout->addWidget( temp, 1, 0 );
87 gridLayout->addWidget( addBut, 0, 0 ); 88 gridLayout->addWidget( addBut, 0, 0 );
88 gridLayout->addMultiCellWidget( sv, 0, 1, 1,1 ); 89 gridLayout->addMultiCellWidget( sv, 0, 1, 1,1 );
89 } 90 }
90 setDefaults(); 91 setDefaults();
91 mTypeNumberEditList.setAutoDelete( true ); 92 mTypeNumberEditList.setAutoDelete( true );
92 mPopup = new QPopupMenu( this ); 93 mPopup = new QPopupMenu( this );
93 QStringList list = PhoneNumber::supportedTypeListNames(); 94 QStringList list = PhoneNumber::supportedTypeListNames();
94 mPopupCount = list.count(); 95 mPopupCount = list.count();
95 int i = 0; 96 int i = 0;
96 while ( i < mPopupCount ) { 97 while ( i < mPopupCount ) {
97 mPopup->insertItem( list[ i ], i ); 98 mPopup->insertItem( list[ i ], i );
98 ++i; 99 ++i;
99 } 100 }
100 connect(mPopup,SIGNAL(activated(int)),this,SLOT(addNumberInt( int))); 101 connect(mPopup,SIGNAL(activated(int)),this,SLOT(addNumberInt( int)));
101 102
102} 103}
103 104
104PhoneEditWidget::~PhoneEditWidget() 105PhoneEditWidget::~PhoneEditWidget()
105{ 106{
106} 107}
107void PhoneEditWidget::setDefaults() 108void PhoneEditWidget::setDefaults()
108{ 109{
109 mTypeNumberEditList.clear(); 110 mTypeNumberEditList.clear();
110 PhoneTypeNumberEdit* edit = appendEditCombo(); 111 PhoneTypeNumberEdit* edit = appendEditCombo();
111 KABC::PhoneNumber phoneNumber; 112 KABC::PhoneNumber phoneNumber;
112 phoneNumber.setType( KABC::PhoneNumber::Home | KABC::PhoneNumber::Pref ); 113 phoneNumber.setType( KABC::PhoneNumber::Home | KABC::PhoneNumber::Pref );
113 edit->setPhoneNumber( phoneNumber ); 114 edit->setPhoneNumber( phoneNumber );
114 edit = appendEditCombo(); 115 edit = appendEditCombo();
115 phoneNumber.setType( KABC::PhoneNumber::Work | KABC::PhoneNumber::Pref ); 116 KABC::PhoneNumber phoneNumber2;
116 edit->setPhoneNumber( phoneNumber ); 117 phoneNumber2.setType( KABC::PhoneNumber::Work | KABC::PhoneNumber::Pref );
118 edit->setPhoneNumber( phoneNumber2 );
117 edit = appendEditCombo(); 119 edit = appendEditCombo();
118 phoneNumber.setType( KABC::PhoneNumber::Cell ); 120 KABC::PhoneNumber phoneNumber3;
119 edit->setPhoneNumber( phoneNumber ); 121 phoneNumber3.setType( KABC::PhoneNumber::Cell );
122 edit->setPhoneNumber( phoneNumber3 );
120 123
121} 124}
122void PhoneEditWidget::addNumberInt( int index ) 125void PhoneEditWidget::addNumberInt( int index )
123{ 126{
124 PhoneTypeNumberEdit* edit = appendEditCombo(); 127 PhoneTypeNumberEdit* edit = appendEditCombo();
125 KABC::PhoneNumber phoneNumber; 128 KABC::PhoneNumber phoneNumber;
126 phoneNumber.setType( PhoneNumber::supportedTypeList()[index] ); 129 phoneNumber.setType( PhoneNumber::supportedTypeList()[index] );
127 edit->setPhoneNumber( phoneNumber ); 130 edit->setPhoneNumber( phoneNumber );
128 //verticalScrollBar()->setValue( 1024); 131 //verticalScrollBar()->setValue( 1024);
129 QTimer::singleShot( 0, this, SLOT ( bottomVisible() ) ); 132 QTimer::singleShot( 0, this, SLOT ( bottomVisible() ) );
130} 133}
131void PhoneEditWidget::bottomVisible() 134void PhoneEditWidget::bottomVisible()
132{ 135{
133 sv->setContentsPos ( 0, 1024 ); 136 sv->setContentsPos ( 0, 1024 );
134} 137}
135void PhoneEditWidget::addNumber() 138void PhoneEditWidget::addNumber()
136{ 139{
137 int i = 0; 140 int i = 0;
138 while ( i < mPopupCount ) { 141 while ( i < mPopupCount ) {
139 mPopup->setItemEnabled( i, true ); 142 mPopup->setItemEnabled( i, true );
140 ++i; 143 ++i;
141 } 144 }
142 PhoneTypeNumberEdit* edit = mTypeNumberEditList.first(); 145 PhoneTypeNumberEdit* edit = mTypeNumberEditList.first();
143 while ( edit ) { 146 while ( edit ) {
144 if ( edit->currentType() < mPopupCount -1 ) 147 if ( edit->currentType() < mPopupCount -1 )
145 mPopup->setItemEnabled( edit->currentType(), false ); 148 mPopup->setItemEnabled( edit->currentType(), false );
146 edit = mTypeNumberEditList.next(); 149 edit = mTypeNumberEditList.next();
147 } 150 }
148 mPopup->popup( QCursor::pos() ); 151 mPopup->popup( QCursor::pos() );
149} 152}
150PhoneTypeNumberEdit* PhoneEditWidget::appendEditCombo() 153PhoneTypeNumberEdit* PhoneEditWidget::appendEditCombo()
151{ 154{
152 PhoneTypeNumberEdit* edit = new PhoneTypeNumberEdit( mw ); 155 PhoneTypeNumberEdit* edit = new PhoneTypeNumberEdit( mw );
153 connect ( edit, SIGNAL ( typeChange( int , int) ), this, SIGNAL ( typeChange( int , int)) ); 156 connect ( edit, SIGNAL ( typeChange( int , int) ), this, SIGNAL ( typeChange( int , int)) );
154 connect ( edit, SIGNAL ( modified() ), this, SIGNAL ( modified() ) ); 157 connect ( edit, SIGNAL ( modified() ), this, SIGNAL ( modified() ) );
155 connect ( edit, SIGNAL ( deleteMe( PhoneTypeNumberEdit* ) ), this, SLOT ( deleteEdit( PhoneTypeNumberEdit*) ) ); 158 connect ( edit, SIGNAL ( deleteMe( PhoneTypeNumberEdit* ) ), this, SLOT ( deleteEdit( PhoneTypeNumberEdit*) ) );
156 connect ( this, SIGNAL ( typeChange( int , int)), edit, SLOT ( typeExternalChanged( int, int)) ); 159 connect ( this, SIGNAL ( typeChange( int , int)), edit, SLOT ( typeExternalChanged( int, int)) );
157 160
158 mainLayout->add( edit ); 161 mainLayout->add( edit );
159 mTypeNumberEditList.append( edit ); 162 mTypeNumberEditList.append( edit );
160 return edit; 163 return edit;
161} 164}
162 165
163void PhoneEditWidget::deleteEdit( PhoneTypeNumberEdit* ew ) 166void PhoneEditWidget::deleteEdit( PhoneTypeNumberEdit* ew )
164{ 167{
165 mPendingDelete = ew; 168 mPendingDelete = ew;
166 QTimer::singleShot( 0, this, SLOT ( pendingDelete() ) ); 169 QTimer::singleShot( 0, this, SLOT ( pendingDelete() ) );
167} 170}
168void PhoneEditWidget::pendingDelete() 171void PhoneEditWidget::pendingDelete()
169{ 172{
170 mTypeNumberEditList.removeRef( mPendingDelete ); 173 mTypeNumberEditList.removeRef( mPendingDelete );
171 emit modified(); 174 emit modified();
172} 175}
173 176
174void PhoneEditWidget::setPhoneNumbers( const KABC::PhoneNumber::List &li ) 177void PhoneEditWidget::setPhoneNumbers( const KABC::PhoneNumber::List &li )
175{ 178{
176 if ( li.isEmpty() ) { 179 if ( li.isEmpty() ) {
177 setDefaults(); 180 setDefaults();
178 return; 181 return;
179 } 182 }
180 mTypeNumberEditList.clear(); 183 mTypeNumberEditList.clear();
181 KABC::PhoneNumber::List::Iterator it; 184 KABC::PhoneNumber::List::Iterator it;
182 KABC::PhoneNumber::List list2 = li; 185 KABC::PhoneNumber::List list2 = li;
183 KABC::PhoneNumber::List list ; 186 KABC::PhoneNumber::List list ;
184 187
185 PhoneNumber::TypeList tList = PhoneNumber::supportedTypeList(); 188 PhoneNumber::TypeList tList = PhoneNumber::supportedTypeList();
186 int i = 0; 189 int i = 0;
187 int max = tList.count(); 190 int max = tList.count();
188 while ( i < max-1 ) { 191 while ( i < max-1 ) {
189 for ( it = list2.begin(); it != list2.end(); ++it ) { 192 for ( it = list2.begin(); it != list2.end(); ++it ) {
190 if ( (*it).type() == tList[i] ) { 193 if ( (*it).type() == tList[i] ) {
191 list.append( (*it ) ); 194 list.append( (*it ) );
192 break; 195 break;
193 } 196 }
194 } 197 }
195 ++i; 198 ++i;
196 } 199 }
197 for ( it = list2.begin(); it != list2.end(); ++it ) { 200 for ( it = list2.begin(); it != list2.end(); ++it ) {
198 if ( (*it).type() == tList[ max-1 ] ) 201 if ( (*it).type() == tList[ max-1 ] )
199 list.append( (*it ) ); 202 list.append( (*it ) );
200 } 203 }
201 for ( it = list.begin(); it != list.end(); ++it ) { 204 for ( it = list.begin(); it != list.end(); ++it ) {
202 PhoneTypeNumberEdit* editNew = appendEditCombo(); 205 PhoneTypeNumberEdit* editNew = appendEditCombo();
203 editNew->setPhoneNumber( (*it ) ); 206 editNew->setPhoneNumber( (*it ) );
204 } 207 }
205 208
206} 209}
207KABC::PhoneNumber::List PhoneEditWidget::phoneNumbers() 210KABC::PhoneNumber::List PhoneEditWidget::phoneNumbers()
208{ 211{
209 KABC::PhoneNumber::List retList; 212 KABC::PhoneNumber::List retList;
210 213
211 PhoneTypeNumberEdit* edit = mTypeNumberEditList.first(); 214 PhoneTypeNumberEdit* edit = mTypeNumberEditList.first();
212 while ( edit ) { 215 while ( edit ) {
213 if ( edit->isValid() ) { 216 if ( edit->isValid() ) {
214 retList.append( edit->phoneNumber()); 217 retList.append( edit->phoneNumber());
215 } 218 }
216 edit = mTypeNumberEditList.next(); 219 edit = mTypeNumberEditList.next();
217 220
218 } 221 }
219 return retList; 222 return retList;
220} 223}
221 224
222#if 0 225#if 0
223PhoneEditWidget::PhoneEditWidget( QWidget *parent, const char *name ) 226PhoneEditWidget::PhoneEditWidget( QWidget *parent, const char *name )
224 : QWidget( parent, name ) 227 : QWidget( parent, name )
225{ 228{
226 QGridLayout *layout = new QGridLayout( this, 4, 1 ); 229 QGridLayout *layout = new QGridLayout( this, 4, 1 );
227//US layout->setSpacing( KDialog::spacingHint() ); 230//US layout->setSpacing( KDialog::spacingHint() );
228 layout->setSpacing( KDialogBase::spacingHintSmall() ); 231 layout->setSpacing( KDialogBase::spacingHintSmall() );
229 232
230 233
231 234
232 QLabel* label = new QLabel( this ); 235 QLabel* label = new QLabel( this );
233//US loadIcon call is ambiguous. Add one more parameter 236//US loadIcon call is ambiguous. Add one more parameter
234//US label->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop ) ); 237//US label->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop ) );
235 label->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop, 0 ) ); 238 label->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop, 0 ) );
236 label->setAlignment( AlignCenter ); 239 label->setAlignment( AlignCenter );
237//US layout->addMultiCellWidget( label, 0, 1, 3, 3 ); 240//US layout->addMultiCellWidget( label, 0, 1, 3, 3 );
238 layout->addWidget( label, 0, 0 ); 241 layout->addWidget( label, 0, 0 );
239 242
240 QPushButton *editButton = new QPushButton( i18n( "Edit Phone Numbers..." ), 243 QPushButton *editButton = new QPushButton( i18n( "Edit Phone Numbers..." ),
241 this ); 244 this );
242 if ( QApplication::desktop()->width() < 640 ) 245 if ( QApplication::desktop()->width() < 640 )
243 layout->addWidget( editButton, 0, 1 ); 246 layout->addWidget( editButton, 0, 1 );
244 else 247 else
245 layout->addMultiCellWidget( editButton, 0, 0, 1, 3); 248 layout->addMultiCellWidget( editButton, 0, 0, 1, 3);
246 249
247 mPrefCombo = new PhoneTypeCombo( mPhoneList, this ); 250 mPrefCombo = new PhoneTypeCombo( mPhoneList, this );
248 mPrefEdit = new KLineEdit( this ); 251 mPrefEdit = new KLineEdit( this );
249 //mPrefEdit->setMinimumWidth( int(mPrefEdit->sizeHint().width() * 1.5) ); 252 //mPrefEdit->setMinimumWidth( int(mPrefEdit->sizeHint().width() * 1.5) );
250 mPrefCombo->setLineEdit( mPrefEdit ); 253 mPrefCombo->setLineEdit( mPrefEdit );
251 layout->addWidget( mPrefCombo, 1, 0 ); 254 layout->addWidget( mPrefCombo, 1, 0 );
252 layout->addWidget( mPrefEdit, 1, 1 ); 255 layout->addWidget( mPrefEdit, 1, 1 );
253 int x = 1, y = 2; 256 int x = 1, y = 2;
254 if ( QApplication::desktop()->width() < 640 ) { 257 if ( QApplication::desktop()->width() < 640 ) {
255 ++x; 258 ++x;
256 y = 0; 259 y = 0;
257 } 260 }
258 mSecondCombo = new PhoneTypeCombo( mPhoneList, this ); 261 mSecondCombo = new PhoneTypeCombo( mPhoneList, this );
259 mSecondEdit = new KLineEdit( this ); 262 mSecondEdit = new KLineEdit( this );
260 mSecondCombo->setLineEdit( mSecondEdit ); 263 mSecondCombo->setLineEdit( mSecondEdit );
261 layout->addWidget( mSecondCombo, x, y++ ); 264 layout->addWidget( mSecondCombo, x, y++ );
262 layout->addWidget( mSecondEdit, x, y++ ); 265 layout->addWidget( mSecondEdit, x, y++ );
263 266
264 y = 0; 267 y = 0;
265 ++x; 268 ++x;
266 mThirdCombo = new PhoneTypeCombo( mPhoneList, this ); 269 mThirdCombo = new PhoneTypeCombo( mPhoneList, this );
267 mThirdEdit = new KLineEdit( this ); 270 mThirdEdit = new KLineEdit( this );
268 mThirdCombo->setLineEdit( mThirdEdit ); 271 mThirdCombo->setLineEdit( mThirdEdit );
269 layout->addWidget( mThirdCombo, x, y++ ); 272 layout->addWidget( mThirdCombo, x, y++ );
270 layout->addWidget( mThirdEdit, x, y++ ); 273 layout->addWidget( mThirdEdit, x, y++ );
271 if ( QApplication::desktop()->width() < 640 ) { 274 if ( QApplication::desktop()->width() < 640 ) {
272 ++x; 275 ++x;
273 y = 0; 276 y = 0;
274 } 277 }
275 mFourthCombo = new PhoneTypeCombo( mPhoneList, this ); 278 mFourthCombo = new PhoneTypeCombo( mPhoneList, this );
276 mFourthEdit = new KLineEdit( this ); 279 mFourthEdit = new KLineEdit( this );
277 mFourthCombo->setLineEdit( mFourthEdit ); 280 mFourthCombo->setLineEdit( mFourthEdit );
278 layout->addWidget( mFourthCombo, x, y++ ); 281 layout->addWidget( mFourthCombo, x, y++ );
279 layout->addWidget( mFourthEdit, x, y++ ); 282 layout->addWidget( mFourthEdit, x, y++ );
280 283
281 // Four numbers don't fit in the current dialog 284 // Four numbers don't fit in the current dialog
282 if ( QApplication::desktop()->width() < 640 ) { 285 if ( QApplication::desktop()->width() < 640 ) {
283 mFourthCombo->hide(); 286 mFourthCombo->hide();
284 mFourthEdit->hide(); 287 mFourthEdit->hide();
285 } else { 288 } else {
286 QFontMetrics fm ( font () ) ; 289 QFontMetrics fm ( font () ) ;
287 int wid = fm.width( "Messenger" ) +60; 290 int wid = fm.width( "Messenger" ) +60;
288 mPrefCombo->setMaximumWidth( wid ); 291 mPrefCombo->setMaximumWidth( wid );
289 mSecondCombo->setMaximumWidth( wid ); 292 mSecondCombo->setMaximumWidth( wid );
290 mThirdCombo->setMaximumWidth( wid ); 293 mThirdCombo->setMaximumWidth( wid );
291 mFourthCombo->setMaximumWidth( wid ); 294 mFourthCombo->setMaximumWidth( wid );
292 } 295 }
293 296
294 297
295 connect( mPrefEdit, SIGNAL( textChanged( const QString& ) ), 298 connect( mPrefEdit, SIGNAL( textChanged( const QString& ) ),
296 SLOT( slotPrefEditChanged() ) ); 299 SLOT( slotPrefEditChanged() ) );
297 connect( mSecondEdit, SIGNAL( textChanged( const QString& ) ), 300 connect( mSecondEdit, SIGNAL( textChanged( const QString& ) ),
298 SLOT( slotSecondEditChanged() ) ); 301 SLOT( slotSecondEditChanged() ) );
299 connect( mThirdEdit, SIGNAL( textChanged( const QString& ) ), 302 connect( mThirdEdit, SIGNAL( textChanged( const QString& ) ),
300 SLOT( slotThirdEditChanged() ) ); 303 SLOT( slotThirdEditChanged() ) );
301 connect( mFourthEdit, SIGNAL( textChanged( const QString& ) ), 304 connect( mFourthEdit, SIGNAL( textChanged( const QString& ) ),
302 SLOT( slotFourthEditChanged() ) ); 305 SLOT( slotFourthEditChanged() ) );
303 306
304 connect( editButton, SIGNAL( clicked() ), SLOT( edit() ) ); 307 connect( editButton, SIGNAL( clicked() ), SLOT( edit() ) );
305 308
306 connect( mPrefCombo, SIGNAL( activated( int ) ), 309 connect( mPrefCombo, SIGNAL( activated( int ) ),
307 SLOT( updatePrefEdit() ) ); 310 SLOT( updatePrefEdit() ) );
308 connect( mSecondCombo, SIGNAL( activated( int ) ), 311 connect( mSecondCombo, SIGNAL( activated( int ) ),
309 SLOT( updateSecondEdit() ) ); 312 SLOT( updateSecondEdit() ) );
310 connect( mThirdCombo, SIGNAL( activated( int ) ), 313 connect( mThirdCombo, SIGNAL( activated( int ) ),
311 SLOT( updateThirdEdit() ) ); 314 SLOT( updateThirdEdit() ) );
312 connect( mFourthCombo, SIGNAL( activated( int ) ), 315 connect( mFourthCombo, SIGNAL( activated( int ) ),
313 SLOT( updateFourthEdit() ) ); 316 SLOT( updateFourthEdit() ) );
314} 317}
315 318
316PhoneEditWidget::~PhoneEditWidget() 319PhoneEditWidget::~PhoneEditWidget()
317{ 320{
318} 321}
319 322
320void PhoneEditWidget::setPhoneNumbers( const KABC::PhoneNumber::List &list ) 323void PhoneEditWidget::setPhoneNumbers( const KABC::PhoneNumber::List &list )
321{ 324{
322 mPhoneList.clear(); 325 mPhoneList.clear();
323 326
324 // Insert types for existing numbers. 327 // Insert types for existing numbers.
325 mPrefCombo->insertTypeList( list ); 328 mPrefCombo->insertTypeList( list );
326 329
327 QValueList<int> defaultTypes; 330 QValueList<int> defaultTypes;
328 defaultTypes << KABC::PhoneNumber::Home; 331 defaultTypes << KABC::PhoneNumber::Home;
329 defaultTypes << KABC::PhoneNumber::Work; 332 defaultTypes << KABC::PhoneNumber::Work;
330 defaultTypes << KABC::PhoneNumber::Cell; 333 defaultTypes << KABC::PhoneNumber::Cell;
331 defaultTypes << ( KABC::PhoneNumber::Work | KABC::PhoneNumber::Fax ); 334 defaultTypes << ( KABC::PhoneNumber::Work | KABC::PhoneNumber::Fax );
332 defaultTypes << ( KABC::PhoneNumber::Home | KABC::PhoneNumber::Fax ); 335 defaultTypes << ( KABC::PhoneNumber::Home | KABC::PhoneNumber::Fax );
333 336
334 // Insert default types. 337 // Insert default types.
335 // Doing this for mPrefCombo is enough because the list is shared by all 338 // Doing this for mPrefCombo is enough because the list is shared by all
336 // combos. 339 // combos.
337 QValueList<int>::ConstIterator it; 340 QValueList<int>::ConstIterator it;
338 for( it = defaultTypes.begin(); it != defaultTypes.end(); ++it ) { 341 for( it = defaultTypes.begin(); it != defaultTypes.end(); ++it ) {
339 if ( !mPrefCombo->hasType( *it ) ) 342 if ( !mPrefCombo->hasType( *it ) )
340 mPrefCombo->insertType( list, *it, PhoneNumber( "", *it ) ); 343 mPrefCombo->insertType( list, *it, PhoneNumber( "", *it ) );
341 } 344 }
342 345
343 updateCombos(); 346 updateCombos();
344 347
345 mPrefCombo->selectType( defaultTypes[ 0 ] ); 348 mPrefCombo->selectType( defaultTypes[ 0 ] );
346 mSecondCombo->selectType( defaultTypes[ 1 ] ); 349 mSecondCombo->selectType( defaultTypes[ 1 ] );
347 mThirdCombo->selectType( defaultTypes[ 2 ] ); 350 mThirdCombo->selectType( defaultTypes[ 2 ] );
348 mFourthCombo->selectType( defaultTypes[ 3 ] ); 351 mFourthCombo->selectType( defaultTypes[ 3 ] );
349 352
350 updateLineEdits(); 353 updateLineEdits();
351} 354}
352 355
353void PhoneEditWidget::updateLineEdits() 356void PhoneEditWidget::updateLineEdits()
354{ 357{
355 updatePrefEdit(); 358 updatePrefEdit();
356 updateSecondEdit(); 359 updateSecondEdit();
357 updateThirdEdit(); 360 updateThirdEdit();
358 updateFourthEdit(); 361 updateFourthEdit();
359} 362}
360 363
361void PhoneEditWidget::updateCombos() 364void PhoneEditWidget::updateCombos()
362{ 365{
363 mPrefCombo->updateTypes(); 366 mPrefCombo->updateTypes();
364 mSecondCombo->updateTypes(); 367 mSecondCombo->updateTypes();
365 mThirdCombo->updateTypes(); 368 mThirdCombo->updateTypes();
366 mFourthCombo->updateTypes(); 369 mFourthCombo->updateTypes();
367} 370}
368 371
369KABC::PhoneNumber::List PhoneEditWidget::phoneNumbers() 372KABC::PhoneNumber::List PhoneEditWidget::phoneNumbers()
370{ 373{
371 KABC::PhoneNumber::List retList; 374 KABC::PhoneNumber::List retList;
372 375
373 KABC::PhoneNumber::List::Iterator it; 376 KABC::PhoneNumber::List::Iterator it;
374 for ( it = mPhoneList.begin(); it != mPhoneList.end(); ++it ) 377 for ( it = mPhoneList.begin(); it != mPhoneList.end(); ++it )
375 if ( !(*it).number().isEmpty() ) 378 if ( !(*it).number().isEmpty() )
376 retList.append( *it ); 379 retList.append( *it );
377 380
378 return retList; 381 return retList;
379} 382}
380 383
381void PhoneEditWidget::edit() 384void PhoneEditWidget::edit()
382{ 385{
383 PhoneEditDialog dlg( mPhoneList, this ); 386 PhoneEditDialog dlg( mPhoneList, this );
384 387
385 if ( dlg.exec() ) { 388 if ( dlg.exec() ) {
386 if ( dlg.changed() ) { 389 if ( dlg.changed() ) {
387 KABC::PhoneNumber::List list = dlg.phoneNumbers(); 390 KABC::PhoneNumber::List list = dlg.phoneNumbers();
388 setPhoneNumbers( list ); 391 setPhoneNumbers( list );
389 updateCombos(); 392 updateCombos();
390 updateLineEdits(); 393 updateLineEdits();
391 emit modified(); 394 emit modified();
392 } 395 }
393 } 396 }
394} 397}
395 398
396void PhoneEditWidget::updatePrefEdit() 399void PhoneEditWidget::updatePrefEdit()
397{ 400{
398 updateEdit( mPrefCombo ); 401 updateEdit( mPrefCombo );
399} 402}
400 403
401void PhoneEditWidget::updateSecondEdit() 404void PhoneEditWidget::updateSecondEdit()
402{ 405{
403 updateEdit( mSecondCombo ); 406 updateEdit( mSecondCombo );
404} 407}
405 408
406void PhoneEditWidget::updateThirdEdit() 409void PhoneEditWidget::updateThirdEdit()
407{ 410{
408 updateEdit( mThirdCombo ); 411 updateEdit( mThirdCombo );
409} 412}
410 413
411void PhoneEditWidget::updateFourthEdit() 414void PhoneEditWidget::updateFourthEdit()
412{ 415{
413 updateEdit( mFourthCombo ); 416 updateEdit( mFourthCombo );
414} 417}
415 418
416void PhoneEditWidget::updateEdit( PhoneTypeCombo *combo ) 419void PhoneEditWidget::updateEdit( PhoneTypeCombo *combo )
417{ 420{
418 QLineEdit *edit = combo->lineEdit(); 421 QLineEdit *edit = combo->lineEdit();
419 if ( !edit ) 422 if ( !edit )
420 return; 423 return;
421 424
422#if 0 425#if 0
423 if ( edit == mPrefEdit ) kdDebug(5720) << " prefEdit" << endl; 426 if ( edit == mPrefEdit ) kdDebug(5720) << " prefEdit" << endl;
424 if ( edit == mSecondEdit ) kdDebug(5720) << " secondEdit" << endl; 427 if ( edit == mSecondEdit ) kdDebug(5720) << " secondEdit" << endl;
425 if ( edit == mThirdEdit ) kdDebug(5720) << " thirdEdit" << endl; 428 if ( edit == mThirdEdit ) kdDebug(5720) << " thirdEdit" << endl;
426 if ( edit == mFourthEdit ) kdDebug(5720) << " fourthEdit" << endl; 429 if ( edit == mFourthEdit ) kdDebug(5720) << " fourthEdit" << endl;
427#endif 430#endif
428 431
429 PhoneNumber::List::Iterator it = combo->selectedElement(); 432 PhoneNumber::List::Iterator it = combo->selectedElement();
430 if ( it != mPhoneList.end() ) { 433 if ( it != mPhoneList.end() ) {
431 edit->setText( (*it).number() ); 434 edit->setText( (*it).number() );
432 } else { 435 } else {
433 kdDebug(5720) << "PhoneEditWidget::updateEdit(): no selected element" << endl; 436 kdDebug(5720) << "PhoneEditWidget::updateEdit(): no selected element" << endl;
434 } 437 }
435} 438}
436 439
437void PhoneEditWidget::slotPrefEditChanged() 440void PhoneEditWidget::slotPrefEditChanged()
438{ 441{
439 updatePhoneNumber( mPrefCombo ); 442 updatePhoneNumber( mPrefCombo );
440} 443}
441 444
442void PhoneEditWidget::slotSecondEditChanged() 445void PhoneEditWidget::slotSecondEditChanged()
443{ 446{
444 updatePhoneNumber( mSecondCombo ); 447 updatePhoneNumber( mSecondCombo );
445} 448}
446 449
447void PhoneEditWidget::slotThirdEditChanged() 450void PhoneEditWidget::slotThirdEditChanged()
448{ 451{
449 updatePhoneNumber( mThirdCombo ); 452 updatePhoneNumber( mThirdCombo );
450} 453}
451 454
452void PhoneEditWidget::slotFourthEditChanged() 455void PhoneEditWidget::slotFourthEditChanged()
453{ 456{
454 updatePhoneNumber( mFourthCombo ); 457 updatePhoneNumber( mFourthCombo );
455} 458}
456 459
457void PhoneEditWidget::updatePhoneNumber( PhoneTypeCombo *combo ) 460void PhoneEditWidget::updatePhoneNumber( PhoneTypeCombo *combo )
458{ 461{
459 QLineEdit *edit = combo->lineEdit(); 462 QLineEdit *edit = combo->lineEdit();
460 if ( !edit ) return; 463 if ( !edit ) return;
461 464
462 PhoneNumber::List::Iterator it = combo->selectedElement(); 465 PhoneNumber::List::Iterator it = combo->selectedElement();
463 if ( it != mPhoneList.end() ) { 466 if ( it != mPhoneList.end() ) {
464 (*it).setNumber( edit->text() ); 467 (*it).setNumber( edit->text() );
465 } 468 }
466 469
467 updateOtherEdit( combo, mPrefCombo ); 470 updateOtherEdit( combo, mPrefCombo );
468 updateOtherEdit( combo, mSecondCombo ); 471 updateOtherEdit( combo, mSecondCombo );
469 updateOtherEdit( combo, mThirdCombo ); 472 updateOtherEdit( combo, mThirdCombo );
470 updateOtherEdit( combo, mFourthCombo ); 473 updateOtherEdit( combo, mFourthCombo );
471 474
472 emit modified(); 475 emit modified();
473} 476}
474 477
475void PhoneEditWidget::updateOtherEdit( PhoneTypeCombo *combo, PhoneTypeCombo *otherCombo ) 478void PhoneEditWidget::updateOtherEdit( PhoneTypeCombo *combo, PhoneTypeCombo *otherCombo )
476{ 479{
477 if ( combo == otherCombo ) return; 480 if ( combo == otherCombo ) return;
478 481
479 if ( combo->currentItem() == otherCombo->currentItem() ) { 482 if ( combo->currentItem() == otherCombo->currentItem() ) {
480 updateEdit( otherCombo ); 483 updateEdit( otherCombo );
481 } 484 }
482} 485}
483 486
484/////////////////////////////////////////// 487///////////////////////////////////////////
485// PhoneEditDialog 488// PhoneEditDialog
486 489
487class PhoneViewItem : public QListViewItem 490class PhoneViewItem : public QListViewItem
488{ 491{
489public: 492public:
490 PhoneViewItem( QListView *parent, const KABC::PhoneNumber &number ); 493 PhoneViewItem( QListView *parent, const KABC::PhoneNumber &number );
491 494
492 void setPhoneNumber( const KABC::PhoneNumber &number ) 495 void setPhoneNumber( const KABC::PhoneNumber &number )
493 { 496 {
494 mPhoneNumber = number; 497 mPhoneNumber = number;
495 makeText(); 498 makeText();
496 } 499 }
497 500
498 QString key() { return mPhoneNumber.id(); } 501 QString key() { return mPhoneNumber.id(); }
499 QString country() { return ""; } 502 QString country() { return ""; }
500 QString region() { return ""; } 503 QString region() { return ""; }
501 QString number() { return ""; } 504 QString number() { return ""; }
502 505
503 KABC::PhoneNumber phoneNumber() { return mPhoneNumber; } 506 KABC::PhoneNumber phoneNumber() { return mPhoneNumber; }