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