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