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