kaddressbook Library API Documentation

addresseditwidget.cpp

00001 /* 00002 This file is part of KAddressBook. 00003 Copyright (c) 2002 Mike Pilone <mpilone@slac.com> 00004 2003 Tobias Koenig <tokoe@kde.org> 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00019 00020 As a special exception, permission is given to link this program 00021 with any edition of Qt, and distribute the resulting executable, 00022 without including the source code for Qt in the source distribution. 00023 */ 00024 00025 #include <qbuttongroup.h> 00026 #include <qcheckbox.h> 00027 #include <qhbox.h> 00028 #include <qlabel.h> 00029 #include <qlayout.h> 00030 #include <qlistbox.h> 00031 #include <qlistview.h> 00032 #include <qpushbutton.h> 00033 #include <qsignal.h> 00034 #include <qstring.h> 00035 #include <qtextedit.h> 00036 #include <qtoolbutton.h> 00037 #include <qtooltip.h> 00038 00039 #include <kaccelmanager.h> 00040 #include <kapplication.h> 00041 #include <kbuttonbox.h> 00042 #include <kcombobox.h> 00043 #include <kconfig.h> 00044 #include <kdebug.h> 00045 #include <kdialog.h> 00046 #include <kiconloader.h> 00047 #include <klineedit.h> 00048 #include <klistview.h> 00049 #include <klocale.h> 00050 #include <kmessagebox.h> 00051 #include <kseparator.h> 00052 00053 #include "addresseditwidget.h" 00054 00055 class TabPressEater : public QObject 00056 { 00057 public: 00058 TabPressEater( QObject *parent ) 00059 : QObject( parent, "TabPressEater" ) 00060 { 00061 } 00062 00063 protected: 00064 bool eventFilter( QObject*, QEvent *event ) 00065 { 00066 if ( event->type() == QEvent::KeyPress ) { 00067 QKeyEvent *keyEvent = (QKeyEvent*)event; 00068 if ( keyEvent->key() == Qt::Key_Tab ) { 00069 QApplication::sendEvent( parent(), event ); 00070 return true; 00071 } else 00072 return false; 00073 } else { 00074 return false; 00075 } 00076 } 00077 }; 00078 00079 00080 AddressEditWidget::AddressEditWidget( QWidget *parent, const char *name ) 00081 : QWidget( parent, name ) 00082 { 00083 QBoxLayout *layout = new QVBoxLayout( this, 4, 2 ); 00084 layout->setSpacing( KDialog::spacingHint() ); 00085 00086 mTypeCombo = new AddressTypeCombo( mAddressList, this ); 00087 connect( mTypeCombo, SIGNAL( activated( int ) ), 00088 SLOT( updateAddressEdit() ) ); 00089 layout->addWidget( mTypeCombo ); 00090 00091 mAddressField = new QLabel( this ); 00092 mAddressField->setFrameStyle( QFrame::Panel | QFrame::Sunken ); 00093 mAddressField->setMinimumHeight( 20 ); 00094 layout->addWidget( mAddressField ); 00095 00096 mEditButton = new QPushButton( i18n( "&Edit Addresses..." ), this ); 00097 connect( mEditButton, SIGNAL( clicked() ), this, SLOT( edit() ) ); 00098 00099 layout->addWidget( mEditButton ); 00100 } 00101 00102 AddressEditWidget::~AddressEditWidget() 00103 { 00104 } 00105 00106 void AddressEditWidget::setReadOnly( bool readOnly ) 00107 { 00108 mEditButton->setEnabled( !readOnly ); 00109 } 00110 00111 KABC::Address::List AddressEditWidget::addresses() 00112 { 00113 KABC::Address::List retList; 00114 00115 KABC::Address::List::Iterator it; 00116 for ( it = mAddressList.begin(); it != mAddressList.end(); ++it ) 00117 if ( !(*it).isEmpty() ) 00118 retList.append( *it ); 00119 00120 return retList; 00121 } 00122 00123 void AddressEditWidget::setAddresses( const KABC::Addressee &addr, 00124 const KABC::Address::List &list ) 00125 { 00126 mAddressee = addr; 00127 00128 mAddressList.clear(); 00129 00130 // Insert types for existing numbers. 00131 mTypeCombo->insertTypeList( list ); 00132 00133 QValueList<int> defaultTypes; 00134 defaultTypes << KABC::Address::Home; 00135 defaultTypes << KABC::Address::Work; 00136 00137 AddresseeConfig config( mAddressee ); 00138 QValueList<int> configList = config.noDefaultAddrTypes(); 00139 QValueList<int>::ConstIterator it; 00140 for ( it = configList.begin(); it != configList.end(); ++it ) 00141 defaultTypes.remove( *it ); 00142 00143 // Insert default types. 00144 // Doing this for mPrefCombo is enough because the list is shared by all 00145 // combos. 00146 for( it = defaultTypes.begin(); it != defaultTypes.end(); ++it ) { 00147 if ( !mTypeCombo->hasType( *it ) ) 00148 mTypeCombo->insertType( list, *it, Address( *it ) ); 00149 } 00150 00151 mTypeCombo->updateTypes(); 00152 00153 // find preferred address which will be shown 00154 int preferred = KABC::Address::Home; // default if no preferred address set 00155 uint i; 00156 for (i = 0; i < list.count(); i++) 00157 if ( list[i].type() & KABC::Address::Pref ) { 00158 preferred = list[i].type(); 00159 break; 00160 } 00161 00162 mTypeCombo->selectType( preferred ); 00163 00164 updateAddressEdit(); 00165 } 00166 00167 void AddressEditWidget::edit() 00168 { 00169 AddressEditDialog dialog( mAddressList, mTypeCombo->currentItem(), this ); 00170 if ( dialog.exec() ) { 00171 if ( dialog.changed() ) { 00172 mAddressList = dialog.addresses(); 00173 00174 bool hasHome = false, hasWork = false; 00175 KABC::Address::List::Iterator it; 00176 for ( it = mAddressList.begin(); it != mAddressList.end(); ++it ) { 00177 if ( (*it).type() == KABC::Address::Home ) { 00178 if ( !(*it).isEmpty() ) 00179 hasHome = true; 00180 } 00181 if ( (*it).type() == KABC::Address::Work ) { 00182 if ( !(*it).isEmpty() ) 00183 hasWork = true; 00184 } 00185 } 00186 00187 AddresseeConfig config( mAddressee ); 00188 QValueList<int> configList; 00189 if ( !hasHome ) 00190 configList << KABC::Address::Home; 00191 if ( !hasWork ) 00192 configList << KABC::Address::Work; 00193 config.setNoDefaultAddrTypes( configList ); 00194 00195 mTypeCombo->updateTypes(); 00196 updateAddressEdit(); 00197 emit modified(); 00198 } 00199 } 00200 } 00201 00202 void AddressEditWidget::updateAddressEdit() 00203 { 00204 KABC::Address::List::Iterator it = mTypeCombo->selectedElement(); 00205 00206 bool block = signalsBlocked(); 00207 blockSignals( true ); 00208 00209 mAddressField->setText( "" ); 00210 00211 if ( it != mAddressList.end() ) { 00212 KABC::Address a = *it; 00213 if ( !a.isEmpty() ) { 00214 #if KDE_VERSION >= 319 00215 if ( a.type() & KABC::Address::Work ) { 00216 mAddressField->setText( a.formattedAddress( mAddressee.realName(), 00217 mAddressee.organization() ) ); 00218 } else { 00219 mAddressField->setText( a.formattedAddress( mAddressee.realName() ) ); 00220 } 00221 #else 00222 QString text; 00223 if ( !a.street().isEmpty() ) 00224 text += a.street() + "\n"; 00225 00226 if ( !a.postOfficeBox().isEmpty() ) 00227 text += a.postOfficeBox() + "\n"; 00228 00229 text += a.locality() + QString(" ") + a.region(); 00230 00231 if ( !a.postalCode().isEmpty() ) 00232 text += QString(", ") + a.postalCode(); 00233 00234 text += "\n"; 00235 00236 if ( !a.country().isEmpty() ) 00237 text += a.country() + "\n"; 00238 00239 text += a.extended(); 00240 00241 mAddressField->setText( text ); 00242 #endif 00243 } 00244 } 00245 00246 blockSignals( block ); 00247 } 00248 00249 AddressEditDialog::AddressEditDialog( const KABC::Address::List &list, 00250 int selected, QWidget *parent, 00251 const char *name ) 00252 : KDialogBase( Plain, i18n( "Edit Address" ), Ok | Cancel, Ok, 00253 parent, name, true, true ), 00254 mPreviousAddress( 0 ) 00255 { 00256 mAddressList = list; 00257 00258 QWidget *page = plainPage(); 00259 00260 QGridLayout *topLayout = new QGridLayout( page, 8, 2 ); 00261 topLayout->setSpacing( spacingHint() ); 00262 00263 mTypeCombo = new AddressTypeCombo( mAddressList, page ); 00264 topLayout->addMultiCellWidget( mTypeCombo, 0, 0, 0, 1 ); 00265 00266 QLabel *label = new QLabel( KABC::Address::streetLabel() + ":", page ); 00267 label->setAlignment( Qt::AlignTop | Qt::AlignLeft ); 00268 topLayout->addWidget( label, 1, 0 ); 00269 mStreetTextEdit = new QTextEdit( page ); 00270 label->setBuddy( mStreetTextEdit ); 00271 topLayout->addWidget( mStreetTextEdit, 1, 1 ); 00272 00273 TabPressEater *eater = new TabPressEater( this ); 00274 mStreetTextEdit->installEventFilter( eater ); 00275 00276 label = new QLabel( KABC::Address::postOfficeBoxLabel() + ":", page ); 00277 topLayout->addWidget( label, 2 , 0 ); 00278 mPOBoxEdit = new KLineEdit( page ); 00279 label->setBuddy( mPOBoxEdit ); 00280 topLayout->addWidget( mPOBoxEdit, 2, 1 ); 00281 00282 label = new QLabel( KABC::Address::localityLabel() + ":", page ); 00283 topLayout->addWidget( label, 3, 0 ); 00284 mLocalityEdit = new KLineEdit( page ); 00285 label->setBuddy( mLocalityEdit ); 00286 topLayout->addWidget( mLocalityEdit, 3, 1 ); 00287 00288 label = new QLabel( KABC::Address::regionLabel() + ":", page ); 00289 topLayout->addWidget( label, 4, 0 ); 00290 mRegionEdit = new KLineEdit( page ); 00291 label->setBuddy( mRegionEdit ); 00292 topLayout->addWidget( mRegionEdit, 4, 1 ); 00293 00294 label = new QLabel( KABC::Address::postalCodeLabel() + ":", page ); 00295 topLayout->addWidget( label, 5, 0 ); 00296 mPostalCodeEdit = new KLineEdit( page ); 00297 label->setBuddy( mPostalCodeEdit ); 00298 topLayout->addWidget( mPostalCodeEdit, 5, 1 ); 00299 00300 label = new QLabel( KABC::Address::countryLabel() + ":", page ); 00301 topLayout->addWidget( label, 6, 0 ); 00302 mCountryCombo = new KComboBox( page ); 00303 mCountryCombo->setEditable( true ); 00304 mCountryCombo->setDuplicatesEnabled( false ); 00305 00306 fillCountryCombo(); 00307 label->setBuddy( mCountryCombo ); 00308 topLayout->addWidget( mCountryCombo, 6, 1 ); 00309 00310 mPreferredCheckBox = new QCheckBox( i18n( "This is the preferred address" ), page ); 00311 topLayout->addMultiCellWidget( mPreferredCheckBox, 7, 7, 0, 1 ); 00312 00313 KSeparator *sep = new KSeparator( KSeparator::HLine, page ); 00314 topLayout->addMultiCellWidget( sep, 8, 8, 0, 1 ); 00315 00316 QHBox *buttonBox = new QHBox( page ); 00317 buttonBox->setSpacing( spacingHint() ); 00318 topLayout->addMultiCellWidget( buttonBox, 9, 9, 0, 1 ); 00319 00320 QPushButton *addButton = new QPushButton( i18n( "New..." ), buttonBox ); 00321 connect( addButton, SIGNAL( clicked() ), SLOT( addAddress() ) ); 00322 00323 mRemoveButton = new QPushButton( i18n( "Remove" ), buttonBox ); 00324 connect( mRemoveButton, SIGNAL( clicked() ), SLOT( removeAddress() ) ); 00325 00326 mChangeTypeButton = new QPushButton( i18n( "Change Type..." ), buttonBox ); 00327 connect( mChangeTypeButton, SIGNAL( clicked() ), SLOT( changeType() ) ); 00328 00329 mTypeCombo->updateTypes(); 00330 mTypeCombo->setCurrentItem( selected ); 00331 00332 updateAddressEdits(); 00333 00334 connect( mTypeCombo, SIGNAL( activated( int ) ), 00335 SLOT( updateAddressEdits() ) ); 00336 connect( mStreetTextEdit, SIGNAL( textChanged() ), SLOT( modified() ) ); 00337 connect( mPOBoxEdit, SIGNAL( textChanged( const QString& ) ), SLOT( modified() ) ); 00338 connect( mLocalityEdit, SIGNAL( textChanged( const QString& ) ), SLOT( modified() ) ); 00339 connect( mRegionEdit, SIGNAL( textChanged( const QString& ) ), SLOT( modified() ) ); 00340 connect( mPostalCodeEdit, SIGNAL( textChanged( const QString& ) ), SLOT( modified() ) ); 00341 connect( mCountryCombo, SIGNAL( textChanged( const QString& ) ), SLOT( modified() ) ); 00342 connect( mPreferredCheckBox, SIGNAL( toggled( bool ) ), SLOT( modified() ) ); 00343 00344 KAcceleratorManager::manage( this ); 00345 00346 mChanged = false; 00347 00348 bool state = (mAddressList.count() > 0); 00349 mRemoveButton->setEnabled( state ); 00350 mChangeTypeButton->setEnabled( state ); 00351 } 00352 00353 AddressEditDialog::~AddressEditDialog() 00354 { 00355 } 00356 00357 KABC::Address::List AddressEditDialog::addresses() 00358 { 00359 saveAddress( *(mTypeCombo->selectedElement()) ); 00360 00361 return mAddressList; 00362 } 00363 00364 bool AddressEditDialog::changed() const 00365 { 00366 return mChanged; 00367 } 00368 00369 void AddressEditDialog::addAddress() 00370 { 00371 AddressTypeDialog dlg( mTypeCombo->selectedType(), this ); 00372 if ( dlg.exec() ) { 00373 mAddressList.append( Address( dlg.type() ) ); 00374 00375 mTypeCombo->updateTypes(); 00376 mTypeCombo->setCurrentItem( mTypeCombo->count() - 1 ); 00377 updateAddressEdits(); 00378 00379 modified(); 00380 00381 mRemoveButton->setEnabled( true ); 00382 mChangeTypeButton->setEnabled( true ); 00383 } 00384 } 00385 00386 void AddressEditDialog::removeAddress() 00387 { 00388 if ( mAddressList.count() > 0 ) { 00389 KABC::Address::List::Iterator it = mTypeCombo->selectedElement(); 00390 if ( mPreviousAddress && mPreviousAddress->id() == (*it).id() ) 00391 mPreviousAddress = 0; 00392 00393 mAddressList.remove( it ); 00394 mTypeCombo->updateTypes(); 00395 updateAddressEdits(); 00396 00397 modified(); 00398 } 00399 00400 bool state = ( mAddressList.count() > 0 ); 00401 mRemoveButton->setEnabled( state ); 00402 mChangeTypeButton->setEnabled( state ); 00403 } 00404 00405 void AddressEditDialog::changeType() 00406 { 00407 KABC::Address::List::Iterator a = mTypeCombo->selectedElement(); 00408 00409 AddressTypeDialog dlg( (*a).type(), this ); 00410 if ( dlg.exec() ) { 00411 (*a).setType( dlg.type() ); 00412 00413 mTypeCombo->updateTypes(); 00414 00415 modified(); 00416 } 00417 } 00418 00419 void AddressEditDialog::updateAddressEdits() 00420 { 00421 if ( mPreviousAddress ) 00422 saveAddress( *mPreviousAddress ); 00423 00424 KABC::Address::List::Iterator it = mTypeCombo->selectedElement(); 00425 KABC::Address a = *it; 00426 mPreviousAddress = &(*it); 00427 00428 bool tmp = mChanged; 00429 00430 mStreetTextEdit->setText( a.street() ); 00431 mRegionEdit->setText( a.region() ); 00432 mLocalityEdit->setText( a.locality() ); 00433 mPostalCodeEdit->setText( a.postalCode() ); 00434 mPOBoxEdit->setText( a.postOfficeBox() ); 00435 mCountryCombo->setCurrentText( a.country() ); 00436 00437 mPreferredCheckBox->setChecked( a.type() & KABC::Address::Pref ); 00438 00439 if ( a.isEmpty() ) 00440 mCountryCombo->setCurrentText( KGlobal::locale()->twoAlphaToCountryName( KGlobal::locale()->country() ) ); 00441 00442 mStreetTextEdit->setFocus(); 00443 00444 mChanged = tmp; 00445 } 00446 00447 void AddressEditDialog::modified() 00448 { 00449 mChanged = true; 00450 } 00451 00452 void AddressEditDialog::saveAddress( KABC::Address &addr ) 00453 { 00454 addr.setLocality( mLocalityEdit->text() ); 00455 addr.setRegion( mRegionEdit->text() ); 00456 addr.setPostalCode( mPostalCodeEdit->text() ); 00457 addr.setCountry( mCountryCombo->currentText() ); 00458 addr.setPostOfficeBox( mPOBoxEdit->text() ); 00459 addr.setStreet( mStreetTextEdit->text() ); 00460 00461 00462 if ( mPreferredCheckBox->isChecked() ) { 00463 KABC::Address::List::Iterator it; 00464 for ( it = mAddressList.begin(); it != mAddressList.end(); ++it ) 00465 (*it).setType( (*it).type() & ~( KABC::Address::Pref ) ); 00466 00467 addr.setType( addr.type() | KABC::Address::Pref ); 00468 } else 00469 addr.setType( addr.type() & ~( KABC::Address::Pref ) ); 00470 } 00471 00472 void AddressEditDialog::fillCountryCombo() 00473 { 00474 QString country[] = { 00475 i18n( "Afghanistan" ), i18n( "Albania" ), i18n( "Algeria" ), 00476 i18n( "American Samoa" ), i18n( "Andorra" ), i18n( "Angola" ), 00477 i18n( "Anguilla" ), i18n( "Antarctica" ), i18n( "Antigua and Barbuda" ), 00478 i18n( "Argentina" ), i18n( "Armenia" ), i18n( "Aruba" ), 00479 i18n( "Ashmore and Cartier Islands" ), i18n( "Australia" ), 00480 i18n( "Austria" ), i18n( "Azerbaijan" ), i18n( "Bahamas" ), 00481 i18n( "Bahrain" ), i18n( "Bangladesh" ), i18n( "Barbados" ), 00482 i18n( "Belarus" ), i18n( "Belgium" ), i18n( "Belize" ), 00483 i18n( "Benin" ), i18n( "Bermuda" ), i18n( "Bhutan" ), 00484 i18n( "Bolivia" ), i18n( "Bosnia and Herzegovina" ), i18n( "Botswana" ), 00485 i18n( "Brazil" ), i18n( "Brunei" ), i18n( "Bulgaria" ), 00486 i18n( "Burkina Faso" ), i18n( "Burundi" ), i18n( "Cambodia" ), 00487 i18n( "Cameroon" ), i18n( "Canada" ), i18n( "Cape Verde" ), 00488 i18n( "Cayman Islands" ), i18n( "Central African Republic" ), 00489 i18n( "Chad" ), i18n( "Chile" ), i18n( "China" ), i18n( "Colombia" ), 00490 i18n( "Comoros" ), i18n( "Congo" ), i18n( "Congo, Dem. Rep." ), 00491 i18n( "Costa Rica" ), i18n( "Croatia" ), 00492 i18n( "Cuba" ), i18n( "Cyprus" ), i18n( "Czech Republic" ), 00493 i18n( "Denmark" ), i18n( "Djibouti" ), 00494 i18n( "Dominica" ), i18n( "Dominican Republic" ), i18n( "Ecuador" ), 00495 i18n( "Egypt" ), i18n( "El Salvador" ), i18n( "Equatorial Guinea" ), 00496 i18n( "Eritrea" ), i18n( "Estonia" ), i18n( "England" ), 00497 i18n( "Ethiopia" ), i18n( "European Union" ), i18n( "Faroe Islands" ), 00498 i18n( "Fiji" ), i18n( "Finland" ), i18n( "France" ), 00499 i18n( "French Polynesia" ), i18n( "Gabon" ), i18n( "Gambia" ), 00500 i18n( "Georgia" ), i18n( "Germany" ), i18n( "Ghana" ), 00501 i18n( "Greece" ), i18n( "Greenland" ), i18n( "Grenada" ), 00502 i18n( "Guam" ), i18n( "Guatemala" ), i18n( "Guinea" ), 00503 i18n( "Guinea-Bissau" ), i18n( "Guyana" ), i18n( "Haiti" ), 00504 i18n( "Honduras" ), i18n( "Hong Kong" ), i18n( "Hungary" ), 00505 i18n( "Iceland" ), i18n( "India" ), i18n( "Indonesia" ), 00506 i18n( "Iran" ), i18n( "Iraq" ), i18n( "Ireland" ), 00507 i18n( "Israel" ), i18n( "Italy" ), i18n( "Ivory Coast" ), 00508 i18n( "Jamaica" ), i18n( "Japan" ), i18n( "Jordan" ), 00509 i18n( "Kazakhstan" ), i18n( "Kenya" ), i18n( "Kiribati" ), 00510 i18n( "Korea, North" ), i18n( "Korea, South" ), 00511 i18n( "Kuwait" ), i18n( "Kyrgyzstan" ), i18n( "Laos" ), 00512 i18n( "Latvia" ), i18n( "Lebanon" ), i18n( "Lesotho" ), 00513 i18n( "Liberia" ), i18n( "Libya" ), i18n( "Liechtenstein" ), 00514 i18n( "Lithuania" ), i18n( "Luxembourg" ), i18n( "Macau" ), 00515 i18n( "Madagascar" ), i18n( "Malawi" ), i18n( "Malaysia" ), 00516 i18n( "Maldives" ), i18n( "Mali" ), i18n( "Malta" ), 00517 i18n( "Marshall Islands" ), i18n( "Martinique" ), i18n( "Mauritania" ), 00518 i18n( "Mauritius" ), i18n( "Mexico" ), 00519 i18n( "Micronesia, Federated States Of" ), i18n( "Moldova" ), 00520 i18n( "Monaco" ), i18n( "Mongolia" ), i18n( "Montserrat" ), 00521 i18n( "Morocco" ), i18n( "Mozambique" ), i18n( "Myanmar" ), 00522 i18n( "Namibia" ), 00523 i18n( "Nauru" ), i18n( "Nepal" ), i18n( "Netherlands" ), 00524 i18n( "Netherlands Antilles" ), i18n( "New Caledonia" ), 00525 i18n( "New Zealand" ), i18n( "Nicaragua" ), i18n( "Niger" ), 00526 i18n( "Nigeria" ), i18n( "Niue" ), i18n( "North Korea" ), 00527 i18n( "Northern Ireland" ), i18n( "Northern Mariana Islands" ), 00528 i18n( "Norway" ), i18n( "Oman" ), i18n( "Pakistan" ), i18n( "Palau" ), 00529 i18n( "Palestinian" ), i18n( "Panama" ), i18n( "Papua New Guinea" ), 00530 i18n( "Paraguay" ), i18n( "Peru" ), i18n( "Philippines" ), 00531 i18n( "Poland" ), i18n( "Portugal" ), i18n( "Puerto Rico" ), 00532 i18n( "Qatar" ), i18n( "Romania" ), i18n( "Russia" ), i18n( "Rwanda" ), 00533 i18n( "St. Kitts and Nevis" ), i18n( "St. Lucia" ), 00534 i18n( "St. Vincent and the Grenadines" ), i18n( "San Marino" ), 00535 i18n( "Sao Tome and Principe" ), i18n( "Saudi Arabia" ), 00536 i18n( "Senegal" ), i18n( "Serbia & Montenegro" ), i18n( "Seychelles" ), 00537 i18n( "Sierra Leone" ), i18n( "Singapore" ), i18n( "Slovakia" ), 00538 i18n( "Slovenia" ), i18n( "Solomon Islands" ), i18n( "Somalia" ), 00539 i18n( "South Africa" ), i18n( "South Korea" ), i18n( "Spain" ), 00540 i18n( "Sri Lanka" ), i18n( "St. Kitts and Nevis" ), i18n( "Sudan" ), 00541 i18n( "Suriname" ), i18n( "Swaziland" ), i18n( "Sweden" ), 00542 i18n( "Switzerland" ), i18n( "Syria" ), i18n( "Taiwan" ), 00543 i18n( "Tajikistan" ), i18n( "Tanzania" ), i18n( "Thailand" ), 00544 i18n( "Tibet" ), i18n( "Togo" ), i18n( "Tonga" ), 00545 i18n( "Trinidad and Tobago" ), i18n( "Tunisia" ), i18n( "Turkey" ), 00546 i18n( "Turkmenistan" ), i18n( "Turks and Caicos Islands" ), 00547 i18n( "Tuvalu" ), i18n( "Uganda" ), i18n( "Ukraine" ), 00548 i18n( "United Arab Emirates" ), i18n( "United Kingdom" ), 00549 i18n( "United States" ), i18n( "Uruguay" ), i18n( "Uzbekistan" ), 00550 i18n( "Vanuatu" ), i18n( "Vatican City" ), i18n( "Venezuela" ), 00551 i18n( "Vietnam" ), i18n( "Western Samoa" ), i18n( "Yemen" ), 00552 i18n( "Yugoslavia" ), i18n( "Zaire" ), i18n( "Zambia" ), 00553 i18n( "Zimbabwe" ), 00554 "" 00555 }; 00556 00557 QStringList countries; 00558 for ( int i = 0; !country[ i ].isEmpty(); ++i ) 00559 countries.append( country[ i ] ); 00560 00561 countries = sortLocaleAware( countries ); 00562 00563 mCountryCombo->insertStringList( countries ); 00564 mCountryCombo->completionObject()->setItems( countries ); 00565 mCountryCombo->setAutoCompletion( true ); 00566 } 00567 00568 00569 AddressTypeDialog::AddressTypeDialog( int type, QWidget *parent ) 00570 : KDialogBase( Plain, i18n( "Edit Address Type" ), Ok | Cancel, Ok, 00571 parent, "AddressTypeDialog" ) 00572 { 00573 QWidget *page = plainPage(); 00574 QVBoxLayout *layout = new QVBoxLayout( page ); 00575 00576 mGroup = new QButtonGroup( 2, Horizontal, i18n( "Address Types" ), page ); 00577 layout->addWidget( mGroup ); 00578 00579 mTypeList = KABC::Address::typeList(); 00580 mTypeList.remove( KABC::Address::Pref ); 00581 00582 KABC::Address::TypeList::Iterator it; 00583 for ( it = mTypeList.begin(); it != mTypeList.end(); ++it ) 00584 new QCheckBox( KABC::Address::typeLabel( *it ), mGroup ); 00585 00586 for ( int i = 0; i < mGroup->count(); ++i ) { 00587 QCheckBox *box = (QCheckBox*)mGroup->find( i ); 00588 box->setChecked( type & mTypeList[ i ] ); 00589 } 00590 } 00591 00592 AddressTypeDialog::~AddressTypeDialog() 00593 { 00594 } 00595 00596 int AddressTypeDialog::type() const 00597 { 00598 int type = 0; 00599 for ( int i = 0; i < mGroup->count(); ++i ) { 00600 QCheckBox *box = (QCheckBox*)mGroup->find( i ); 00601 if ( box->isChecked() ) 00602 type += mTypeList[ i ]; 00603 } 00604 00605 return type; 00606 } 00607 00612 class LocaleAwareString : public QString 00613 { 00614 public: 00615 LocaleAwareString() : QString() 00616 {} 00617 00618 LocaleAwareString( const QString &str ) : QString( str ) 00619 {} 00620 }; 00621 00622 static bool operator<( const LocaleAwareString &s1, const LocaleAwareString &s2 ) 00623 { 00624 return ( QString::localeAwareCompare( s1, s2 ) < 0 ); 00625 } 00626 00627 QStringList AddressEditDialog::sortLocaleAware( const QStringList &list ) 00628 { 00629 QValueList<LocaleAwareString> sortedList; 00630 00631 QStringList::ConstIterator it; 00632 for ( it = list.begin(); it != list.end(); ++it ) 00633 sortedList.append( LocaleAwareString( *it ) ); 00634 00635 qHeapSort( sortedList ); 00636 00637 QStringList retval; 00638 QValueList<LocaleAwareString>::ConstIterator retIt; 00639 for ( retIt = sortedList.begin(); retIt != sortedList.end(); ++retIt ) 00640 retval.append( *retIt ); 00641 00642 return retval; 00643 } 00644 00645 #include "addresseditwidget.moc"
KDE Logo
This file is part of the documentation for kaddressbook Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Oct 21 19:46:36 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003