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