• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdepim
  • Sitemap
  • Contact Us
 

kaddressbook

addresseditwidget.cpp

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

kaddressbook

Skip menu "kaddressbook"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal