author | zautrix <zautrix> | 2006-02-24 18:49:56 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2006-02-24 18:49:56 (UTC) |
commit | d7738fdfc685192eb2f8317db6ffad3c246001c8 (patch) (unidiff) | |
tree | d9aae6ca97851fd1b53c4d9e74740a5ee2b69ea9 /kaddressbook/phoneeditwidget.cpp | |
parent | 987757f168bbae56100f2aff763b865e81ceec18 (diff) | |
download | kdepimpi-d7738fdfc685192eb2f8317db6ffad3c246001c8.zip kdepimpi-d7738fdfc685192eb2f8317db6ffad3c246001c8.tar.gz kdepimpi-d7738fdfc685192eb2f8317db6ffad3c246001c8.tar.bz2 |
kapi sync
Diffstat (limited to 'kaddressbook/phoneeditwidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kaddressbook/phoneeditwidget.cpp | 11 |
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,728 +1,731 @@ | |||
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 | ||
56 | PhoneEditWidget::PhoneEditWidget( QWidget *parent, const char *name ) | 57 | PhoneEditWidget::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 | ||
104 | PhoneEditWidget::~PhoneEditWidget() | 105 | PhoneEditWidget::~PhoneEditWidget() |
105 | { | 106 | { |
106 | } | 107 | } |
107 | void PhoneEditWidget::setDefaults() | 108 | void 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 | } |
122 | void PhoneEditWidget::addNumberInt( int index ) | 125 | void 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 | } |
131 | void PhoneEditWidget::bottomVisible() | 134 | void PhoneEditWidget::bottomVisible() |
132 | { | 135 | { |
133 | sv->setContentsPos ( 0, 1024 ); | 136 | sv->setContentsPos ( 0, 1024 ); |
134 | } | 137 | } |
135 | void PhoneEditWidget::addNumber() | 138 | void 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 | } |
150 | PhoneTypeNumberEdit* PhoneEditWidget::appendEditCombo() | 153 | PhoneTypeNumberEdit* 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 | ||
163 | void PhoneEditWidget::deleteEdit( PhoneTypeNumberEdit* ew ) | 166 | void 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 | } |
168 | void PhoneEditWidget::pendingDelete() | 171 | void PhoneEditWidget::pendingDelete() |
169 | { | 172 | { |
170 | mTypeNumberEditList.removeRef( mPendingDelete ); | 173 | mTypeNumberEditList.removeRef( mPendingDelete ); |
171 | emit modified(); | 174 | emit modified(); |
172 | } | 175 | } |
173 | 176 | ||
174 | void PhoneEditWidget::setPhoneNumbers( const KABC::PhoneNumber::List &li ) | 177 | void 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 | } |
207 | KABC::PhoneNumber::List PhoneEditWidget::phoneNumbers() | 210 | KABC::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 |
223 | PhoneEditWidget::PhoneEditWidget( QWidget *parent, const char *name ) | 226 | PhoneEditWidget::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 | ||
316 | PhoneEditWidget::~PhoneEditWidget() | 319 | PhoneEditWidget::~PhoneEditWidget() |
317 | { | 320 | { |
318 | } | 321 | } |
319 | 322 | ||
320 | void PhoneEditWidget::setPhoneNumbers( const KABC::PhoneNumber::List &list ) | 323 | void 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 | ||
353 | void PhoneEditWidget::updateLineEdits() | 356 | void PhoneEditWidget::updateLineEdits() |
354 | { | 357 | { |
355 | updatePrefEdit(); | 358 | updatePrefEdit(); |
356 | updateSecondEdit(); | 359 | updateSecondEdit(); |
357 | updateThirdEdit(); | 360 | updateThirdEdit(); |
358 | updateFourthEdit(); | 361 | updateFourthEdit(); |
359 | } | 362 | } |
360 | 363 | ||
361 | void PhoneEditWidget::updateCombos() | 364 | void 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 | ||
369 | KABC::PhoneNumber::List PhoneEditWidget::phoneNumbers() | 372 | KABC::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 | ||
381 | void PhoneEditWidget::edit() | 384 | void 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 | ||
396 | void PhoneEditWidget::updatePrefEdit() | 399 | void PhoneEditWidget::updatePrefEdit() |
397 | { | 400 | { |
398 | updateEdit( mPrefCombo ); | 401 | updateEdit( mPrefCombo ); |
399 | } | 402 | } |
400 | 403 | ||
401 | void PhoneEditWidget::updateSecondEdit() | 404 | void PhoneEditWidget::updateSecondEdit() |
402 | { | 405 | { |
403 | updateEdit( mSecondCombo ); | 406 | updateEdit( mSecondCombo ); |
404 | } | 407 | } |
405 | 408 | ||
406 | void PhoneEditWidget::updateThirdEdit() | 409 | void PhoneEditWidget::updateThirdEdit() |
407 | { | 410 | { |
408 | updateEdit( mThirdCombo ); | 411 | updateEdit( mThirdCombo ); |
409 | } | 412 | } |
410 | 413 | ||
411 | void PhoneEditWidget::updateFourthEdit() | 414 | void PhoneEditWidget::updateFourthEdit() |
412 | { | 415 | { |
413 | updateEdit( mFourthCombo ); | 416 | updateEdit( mFourthCombo ); |
414 | } | 417 | } |
415 | 418 | ||
416 | void PhoneEditWidget::updateEdit( PhoneTypeCombo *combo ) | 419 | void 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 | ||
437 | void PhoneEditWidget::slotPrefEditChanged() | 440 | void PhoneEditWidget::slotPrefEditChanged() |
438 | { | 441 | { |
439 | updatePhoneNumber( mPrefCombo ); | 442 | updatePhoneNumber( mPrefCombo ); |
440 | } | 443 | } |
441 | 444 | ||
442 | void PhoneEditWidget::slotSecondEditChanged() | 445 | void PhoneEditWidget::slotSecondEditChanged() |
443 | { | 446 | { |
444 | updatePhoneNumber( mSecondCombo ); | 447 | updatePhoneNumber( mSecondCombo ); |
445 | } | 448 | } |
446 | 449 | ||
447 | void PhoneEditWidget::slotThirdEditChanged() | 450 | void PhoneEditWidget::slotThirdEditChanged() |
448 | { | 451 | { |
449 | updatePhoneNumber( mThirdCombo ); | 452 | updatePhoneNumber( mThirdCombo ); |
450 | } | 453 | } |
451 | 454 | ||
452 | void PhoneEditWidget::slotFourthEditChanged() | 455 | void PhoneEditWidget::slotFourthEditChanged() |
453 | { | 456 | { |
454 | updatePhoneNumber( mFourthCombo ); | 457 | updatePhoneNumber( mFourthCombo ); |
455 | } | 458 | } |
456 | 459 | ||
457 | void PhoneEditWidget::updatePhoneNumber( PhoneTypeCombo *combo ) | 460 | void 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 | ||
475 | void PhoneEditWidget::updateOtherEdit( PhoneTypeCombo *combo, PhoneTypeCombo *otherCombo ) | 478 | void 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 | ||
487 | class PhoneViewItem : public QListViewItem | 490 | class PhoneViewItem : public QListViewItem |
488 | { | 491 | { |
489 | public: | 492 | public: |
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; } |
504 | 507 | ||
505 | private: | 508 | private: |
506 | void makeText(); | 509 | void makeText(); |
507 | 510 | ||
508 | KABC::PhoneNumber mPhoneNumber; | 511 | KABC::PhoneNumber mPhoneNumber; |
509 | }; | 512 | }; |
510 | 513 | ||
511 | PhoneViewItem::PhoneViewItem( QListView *parent, const KABC::PhoneNumber &number ) | 514 | PhoneViewItem::PhoneViewItem( QListView *parent, const KABC::PhoneNumber &number ) |
512 | : QListViewItem( parent ), mPhoneNumber( number ) | 515 | : QListViewItem( parent ), mPhoneNumber( number ) |
513 | { | 516 | { |
514 | #ifdef DESKTOP_VERSION | 517 | #ifdef DESKTOP_VERSION |
515 | setRenameEnabled ( 0, true ); | 518 | setRenameEnabled ( 0, true ); |
516 | #endif | 519 | #endif |
517 | makeText(); | 520 | makeText(); |
518 | } | 521 | } |
519 | 522 | ||
520 | void PhoneViewItem::makeText() | 523 | void PhoneViewItem::makeText() |
521 | { | 524 | { |
522 | /** | 525 | /** |
523 | * Will be used in future versions of kaddressbook/libkabc | 526 | * Will be used in future versions of kaddressbook/libkabc |
524 | 527 | ||
525 | setText( 0, mPhoneNumber.country() ); | 528 | setText( 0, mPhoneNumber.country() ); |
526 | setText( 1, mPhoneNumber.region() ); | 529 | setText( 1, mPhoneNumber.region() ); |
527 | setText( 2, mPhoneNumber.number() ); | 530 | setText( 2, mPhoneNumber.number() ); |
528 | setText( 3, mPhoneNumber.typeLabel() ); | 531 | setText( 3, mPhoneNumber.typeLabel() ); |
529 | */ | 532 | */ |
530 | 533 | ||
531 | setText( 0, mPhoneNumber.number() ); | 534 | setText( 0, mPhoneNumber.number() ); |
532 | setText( 1, mPhoneNumber.typeLabel() ); | 535 | setText( 1, mPhoneNumber.typeLabel() ); |
533 | } | 536 | } |
534 | 537 | ||
535 | PhoneEditDialog::PhoneEditDialog( const KABC::PhoneNumber::List &list, QWidget *parent, const char *name ) | 538 | PhoneEditDialog::PhoneEditDialog( const KABC::PhoneNumber::List &list, QWidget *parent, const char *name ) |
536 | : KDialogBase( KDialogBase::Plain, i18n( "Edit Phone Numbers" ), | 539 | : KDialogBase( KDialogBase::Plain, i18n( "Edit Phone Numbers" ), |
537 | KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok, | 540 | KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok, |
538 | parent, name, true) | 541 | parent, name, true) |
539 | { | 542 | { |
540 | mPhoneNumberList = list; | 543 | mPhoneNumberList = list; |
541 | 544 | ||
542 | QWidget *page = plainPage(); | 545 | QWidget *page = plainPage(); |
543 | 546 | ||
544 | QGridLayout *layout = new QGridLayout( page, 1, 2 ); | 547 | QGridLayout *layout = new QGridLayout( page, 1, 2 ); |
545 | layout->setSpacing( spacingHint() ); | 548 | layout->setSpacing( spacingHint() ); |
546 | 549 | ||
547 | mListView = new KListView( page ); | 550 | mListView = new KListView( page ); |
548 | mListView->setAllColumnsShowFocus( true ); | 551 | mListView->setAllColumnsShowFocus( true ); |
549 | mListView->addColumn( i18n( "Number" ) ); | 552 | mListView->addColumn( i18n( "Number" ) ); |
550 | mListView->addColumn( i18n( "Type" ) ); | 553 | mListView->addColumn( i18n( "Type" ) ); |
551 | 554 | ||
552 | KButtonBox *buttonBox = new KButtonBox( page, Vertical ); | 555 | KButtonBox *buttonBox = new KButtonBox( page, Vertical ); |
553 | 556 | ||
554 | buttonBox->addButton( i18n( "&Add..." ), this, SLOT( slotAddPhoneNumber() ) ); | 557 | buttonBox->addButton( i18n( "&Add..." ), this, SLOT( slotAddPhoneNumber() ) ); |
555 | mEditButton = buttonBox->addButton( i18n( "&Edit..." ), this, SLOT( slotEditPhoneNumber() ) ); | 558 | mEditButton = buttonBox->addButton( i18n( "&Edit..." ), this, SLOT( slotEditPhoneNumber() ) ); |
556 | mEditButton->setEnabled( false ); | 559 | mEditButton->setEnabled( false ); |
557 | mRemoveButton = buttonBox->addButton( i18n( "&Remove" ), this, SLOT( slotRemovePhoneNumber() ) ); | 560 | mRemoveButton = buttonBox->addButton( i18n( "&Remove" ), this, SLOT( slotRemovePhoneNumber() ) ); |
558 | mRemoveButton->setEnabled( false ); | 561 | mRemoveButton->setEnabled( false ); |
559 | buttonBox->layout(); | 562 | buttonBox->layout(); |
560 | 563 | ||
561 | layout->addWidget( mListView, 0, 0 ); | 564 | layout->addWidget( mListView, 0, 0 ); |
562 | layout->addWidget( buttonBox, 0, 1 ); | 565 | layout->addWidget( buttonBox, 0, 1 ); |
563 | 566 | ||
564 | connect( mListView, SIGNAL(selectionChanged()), SLOT(slotSelectionChanged()) ); | 567 | connect( mListView, SIGNAL(selectionChanged()), SLOT(slotSelectionChanged()) ); |
565 | connect( mListView, SIGNAL(doubleClicked( QListViewItem *, const QPoint &, int )), this, SLOT( slotEditPhoneNumber())); | 568 | connect( mListView, SIGNAL(doubleClicked( QListViewItem *, const QPoint &, int )), this, SLOT( slotEditPhoneNumber())); |
566 | 569 | ||
567 | KABC::PhoneNumber::List::Iterator it; | 570 | KABC::PhoneNumber::List::Iterator it; |
568 | for ( it = mPhoneNumberList.begin(); it != mPhoneNumberList.end(); ++it ) | 571 | for ( it = mPhoneNumberList.begin(); it != mPhoneNumberList.end(); ++it ) |
569 | new PhoneViewItem( mListView, *it ); | 572 | new PhoneViewItem( mListView, *it ); |
570 | if (QApplication::desktop()->width() < 480 ) | 573 | if (QApplication::desktop()->width() < 480 ) |
571 | showMaximized(); | 574 | showMaximized(); |
572 | else | 575 | else |
573 | resize( 400, 400 ); | 576 | resize( 400, 400 ); |
574 | mChanged = false; | 577 | mChanged = false; |
575 | } | 578 | } |
576 | 579 | ||
577 | PhoneEditDialog::~PhoneEditDialog() | 580 | PhoneEditDialog::~PhoneEditDialog() |
578 | { | 581 | { |
579 | qDebug("PhoneEditDialog::~PhoneEditDialog() "); | 582 | qDebug("PhoneEditDialog::~PhoneEditDialog() "); |
580 | } | 583 | } |
581 | 584 | ||
582 | void PhoneEditDialog::slotAddPhoneNumber() | 585 | void PhoneEditDialog::slotAddPhoneNumber() |
583 | { | 586 | { |
584 | KABC::PhoneNumber tmp( "", 0 ); | 587 | KABC::PhoneNumber tmp( "", 0 ); |
585 | PhoneTypeDialog dlg( tmp, this ); | 588 | PhoneTypeDialog dlg( tmp, this ); |
586 | 589 | ||
587 | if ( dlg.exec() ) { | 590 | if ( dlg.exec() ) { |
588 | QListViewItem* i = mListView->firstChild(); | 591 | QListViewItem* i = mListView->firstChild(); |
589 | KABC::PhoneNumber phoneNumber = dlg.phoneNumber(); | 592 | KABC::PhoneNumber phoneNumber = dlg.phoneNumber(); |
590 | bool insert = true; | 593 | bool insert = true; |
591 | while ( i ) { | 594 | while ( i ) { |
592 | PhoneViewItem* p = ( PhoneViewItem* ) i; | 595 | PhoneViewItem* p = ( PhoneViewItem* ) i; |
593 | KABC::PhoneNumber pn = p->phoneNumber(); | 596 | KABC::PhoneNumber pn = p->phoneNumber(); |
594 | if ( (pn.type() | KABC::PhoneNumber::Pref) == (phoneNumber.type() | KABC::PhoneNumber::Pref) ) { | 597 | if ( (pn.type() | KABC::PhoneNumber::Pref) == (phoneNumber.type() | KABC::PhoneNumber::Pref) ) { |
595 | if ( p->text(0).isEmpty()) { | 598 | if ( p->text(0).isEmpty()) { |
596 | p->setPhoneNumber( phoneNumber ); | 599 | p->setPhoneNumber( phoneNumber ); |
597 | mPhoneNumberList.remove( pn ); | 600 | mPhoneNumberList.remove( pn ); |
598 | mPhoneNumberList.append( phoneNumber ); | 601 | mPhoneNumberList.append( phoneNumber ); |
599 | insert = false; | 602 | insert = false; |
600 | break; | 603 | break; |
601 | } | 604 | } |
602 | } | 605 | } |
603 | i = i->nextSibling(); | 606 | i = i->nextSibling(); |
604 | } | 607 | } |
605 | if ( insert ) { | 608 | if ( insert ) { |
606 | mPhoneNumberList.append( phoneNumber ); | 609 | mPhoneNumberList.append( phoneNumber ); |
607 | new PhoneViewItem( mListView, phoneNumber ); | 610 | new PhoneViewItem( mListView, phoneNumber ); |
608 | } | 611 | } |
609 | mChanged = true; | 612 | mChanged = true; |
610 | } | 613 | } |
611 | } | 614 | } |
612 | 615 | ||
613 | void PhoneEditDialog::slotRemovePhoneNumber() | 616 | void PhoneEditDialog::slotRemovePhoneNumber() |
614 | { | 617 | { |
615 | PhoneViewItem *item = static_cast<PhoneViewItem*>( mListView->currentItem() ); | 618 | PhoneViewItem *item = static_cast<PhoneViewItem*>( mListView->currentItem() ); |
616 | if ( !item ) | 619 | if ( !item ) |
617 | return; | 620 | return; |
618 | 621 | ||
619 | mPhoneNumberList.remove( item->phoneNumber() ); | 622 | mPhoneNumberList.remove( item->phoneNumber() ); |
620 | QListViewItem *currItem = mListView->currentItem(); | 623 | QListViewItem *currItem = mListView->currentItem(); |
621 | mListView->takeItem( currItem ); | 624 | mListView->takeItem( currItem ); |
622 | delete currItem; | 625 | delete currItem; |
623 | 626 | ||
624 | mChanged = true; | 627 | mChanged = true; |
625 | } | 628 | } |
626 | 629 | ||
627 | void PhoneEditDialog::slotEditPhoneNumber() | 630 | void PhoneEditDialog::slotEditPhoneNumber() |
628 | { | 631 | { |
629 | PhoneViewItem *item = static_cast<PhoneViewItem*>( mListView->currentItem() ); | 632 | PhoneViewItem *item = static_cast<PhoneViewItem*>( mListView->currentItem() ); |
630 | if ( !item ) | 633 | if ( !item ) |
631 | return; | 634 | return; |
632 | 635 | ||
633 | PhoneTypeDialog dlg( item->phoneNumber(), this ); | 636 | PhoneTypeDialog dlg( item->phoneNumber(), this ); |
634 | 637 | ||
635 | if ( dlg.exec() ) { | 638 | if ( dlg.exec() ) { |
636 | slotRemovePhoneNumber(); | 639 | slotRemovePhoneNumber(); |
637 | KABC::PhoneNumber phoneNumber = dlg.phoneNumber(); | 640 | KABC::PhoneNumber phoneNumber = dlg.phoneNumber(); |
638 | mPhoneNumberList.append( phoneNumber ); | 641 | mPhoneNumberList.append( phoneNumber ); |
639 | new PhoneViewItem( mListView, phoneNumber ); | 642 | new PhoneViewItem( mListView, phoneNumber ); |
640 | 643 | ||
641 | mChanged = true; | 644 | mChanged = true; |
642 | } | 645 | } |
643 | } | 646 | } |
644 | 647 | ||
645 | void PhoneEditDialog::slotSelectionChanged() | 648 | void PhoneEditDialog::slotSelectionChanged() |
646 | { | 649 | { |
647 | bool state = ( mListView->currentItem() != 0 ); | 650 | bool state = ( mListView->currentItem() != 0 ); |
648 | 651 | ||
649 | mRemoveButton->setEnabled( state ); | 652 | mRemoveButton->setEnabled( state ); |
650 | mEditButton->setEnabled( state ); | 653 | mEditButton->setEnabled( state ); |
651 | } | 654 | } |
652 | 655 | ||
653 | const KABC::PhoneNumber::List &PhoneEditDialog::phoneNumbers() | 656 | const KABC::PhoneNumber::List &PhoneEditDialog::phoneNumbers() |
654 | { | 657 | { |
655 | return mPhoneNumberList; | 658 | return mPhoneNumberList; |
656 | } | 659 | } |
657 | 660 | ||
658 | bool PhoneEditDialog::changed() const | 661 | bool PhoneEditDialog::changed() const |
659 | { | 662 | { |
660 | return mChanged; | 663 | return mChanged; |
661 | } | 664 | } |
662 | 665 | ||
663 | /////////////////////////////////////////// | 666 | /////////////////////////////////////////// |
664 | // PhoneTypeDialog | 667 | // PhoneTypeDialog |
665 | PhoneTypeDialog::PhoneTypeDialog( const KABC::PhoneNumber &phoneNumber, | 668 | PhoneTypeDialog::PhoneTypeDialog( const KABC::PhoneNumber &phoneNumber, |
666 | QWidget *parent, const char *name) | 669 | QWidget *parent, const char *name) |
667 | : KDialogBase( KDialogBase::Plain, i18n( "Edit Phone Number" ), | 670 | : KDialogBase( KDialogBase::Plain, i18n( "Edit Phone Number" ), |
668 | KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok, | 671 | KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok, |
669 | parent, name, true), mPhoneNumber( phoneNumber ) | 672 | parent, name, true), mPhoneNumber( phoneNumber ) |
670 | { | 673 | { |
671 | QWidget *page = plainPage(); | 674 | QWidget *page = plainPage(); |
672 | QLabel *label = 0; | 675 | QLabel *label = 0; |
673 | QGridLayout *layout = new QGridLayout( page, 3, 2, marginHint(), spacingHint() ); | 676 | QGridLayout *layout = new QGridLayout( page, 3, 2, marginHint(), spacingHint() ); |
674 | 677 | ||
675 | label = new QLabel( i18n( "Number:" ), page ); | 678 | label = new QLabel( i18n( "Number:" ), page ); |
676 | layout->addWidget( label, 0, 0 ); | 679 | layout->addWidget( label, 0, 0 ); |
677 | mNumber = new KLineEdit( page ); | 680 | mNumber = new KLineEdit( page ); |
678 | layout->addWidget( mNumber, 0, 1 ); | 681 | layout->addWidget( mNumber, 0, 1 ); |
679 | 682 | ||
680 | mPreferredBox = new QCheckBox( i18n( "This is the preferred phone number" ), page ); | 683 | mPreferredBox = new QCheckBox( i18n( "This is the preferred phone number" ), page ); |
681 | layout->addMultiCellWidget( mPreferredBox, 1, 1, 0, 1 ); | 684 | layout->addMultiCellWidget( mPreferredBox, 1, 1, 0, 1 ); |
682 | 685 | ||
683 | mGroup = new QButtonGroup( 2, Horizontal, i18n( "Types" ), page ); | 686 | mGroup = new QButtonGroup( 2, Horizontal, i18n( "Types" ), page ); |
684 | layout->addMultiCellWidget( mGroup, 2, 2, 0, 1 ); | 687 | layout->addMultiCellWidget( mGroup, 2, 2, 0, 1 ); |
685 | 688 | ||
686 | // fill widgets | 689 | // fill widgets |
687 | mNumber->setText( mPhoneNumber.number() ); | 690 | mNumber->setText( mPhoneNumber.number() ); |
688 | 691 | ||
689 | mTypeList = KABC::PhoneNumber::typeList(); | 692 | mTypeList = KABC::PhoneNumber::typeList(); |
690 | mTypeList.remove( KABC::PhoneNumber::Pref ); | 693 | mTypeList.remove( KABC::PhoneNumber::Pref ); |
691 | 694 | ||
692 | KABC::PhoneNumber::TypeList::Iterator it; | 695 | KABC::PhoneNumber::TypeList::Iterator it; |
693 | for ( it = mTypeList.begin(); it != mTypeList.end(); ++it ) | 696 | for ( it = mTypeList.begin(); it != mTypeList.end(); ++it ) |
694 | new QCheckBox( KABC::PhoneNumber::typeLabel( *it ), mGroup ); | 697 | new QCheckBox( KABC::PhoneNumber::typeLabel( *it ), mGroup ); |
695 | 698 | ||
696 | for ( int i = 0; i < mGroup->count(); ++i ) { | 699 | for ( int i = 0; i < mGroup->count(); ++i ) { |
697 | int type = mPhoneNumber.type(); | 700 | int type = mPhoneNumber.type(); |
698 | QCheckBox *box = (QCheckBox*)mGroup->find( i ); | 701 | QCheckBox *box = (QCheckBox*)mGroup->find( i ); |
699 | box->setChecked( type & mTypeList[ i ] ); | 702 | box->setChecked( type & mTypeList[ i ] ); |
700 | } | 703 | } |
701 | 704 | ||
702 | mPreferredBox->setChecked( mPhoneNumber.type() & KABC::PhoneNumber::Pref ); | 705 | mPreferredBox->setChecked( mPhoneNumber.type() & KABC::PhoneNumber::Pref ); |
703 | mNumber->setFocus(); | 706 | mNumber->setFocus(); |
704 | mNumber->setSelection( 0, 1024); | 707 | mNumber->setSelection( 0, 1024); |
705 | } | 708 | } |
706 | 709 | ||
707 | KABC::PhoneNumber PhoneTypeDialog::phoneNumber() | 710 | KABC::PhoneNumber PhoneTypeDialog::phoneNumber() |
708 | { | 711 | { |
709 | mPhoneNumber.setNumber( mNumber->text() ); | 712 | mPhoneNumber.setNumber( mNumber->text() ); |
710 | 713 | ||
711 | int type = 0; | 714 | int type = 0; |
712 | for ( int i = 0; i < mGroup->count(); ++i ) { | 715 | for ( int i = 0; i < mGroup->count(); ++i ) { |
713 | QCheckBox *box = (QCheckBox*)mGroup->find( i ); | 716 | QCheckBox *box = (QCheckBox*)mGroup->find( i ); |
714 | if ( box->isChecked() ) | 717 | if ( box->isChecked() ) |
715 | type += mTypeList[ i ]; | 718 | type += mTypeList[ i ]; |
716 | } | 719 | } |
717 | 720 | ||
718 | if ( mPreferredBox->isChecked() ) | 721 | if ( mPreferredBox->isChecked() ) |
719 | mPhoneNumber.setType( type | KABC::PhoneNumber::Pref ); | 722 | mPhoneNumber.setType( type | KABC::PhoneNumber::Pref ); |
720 | else | 723 | else |
721 | mPhoneNumber.setType( type & ~KABC::PhoneNumber::Pref ); | 724 | mPhoneNumber.setType( type & ~KABC::PhoneNumber::Pref ); |
722 | 725 | ||
723 | return mPhoneNumber; | 726 | return mPhoneNumber; |
724 | } | 727 | } |
725 | #endif | 728 | #endif |
726 | #ifndef KAB_EMBEDDED | 729 | #ifndef KAB_EMBEDDED |
727 | #include "phoneeditwidget.moc" | 730 | #include "phoneeditwidget.moc" |
728 | #endif //KAB_EMBEDDED | 731 | #endif //KAB_EMBEDDED |