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