kaddressbook

addresseditwidget.cpp
1 /*
2  This file is part of KAddressBook.
3  Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
4  2003 Tobias Koenig <tokoe@kde.org>
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 
20  As a special exception, permission is given to link this program
21  with any edition of TQt, and distribute the resulting executable,
22  without including the source code for TQt in the source distribution.
23 */
24 
25 #include <tqbuttongroup.h>
26 #include <tqcheckbox.h>
27 #include <tqhbox.h>
28 #include <tqlabel.h>
29 #include <tqlayout.h>
30 #include <tqlistbox.h>
31 #include <tqlistview.h>
32 #include <tqpushbutton.h>
33 #include <tqsignal.h>
34 #include <tqstring.h>
35 #include <tqtextedit.h>
36 #include <tqtoolbutton.h>
37 #include <tqtooltip.h>
38 
39 #include <tdeaccelmanager.h>
40 #include <kactivelabel.h>
41 #include <tdeapplication.h>
42 #include <kbuttonbox.h>
43 #include <kcombobox.h>
44 #include <tdeconfig.h>
45 #include <kdebug.h>
46 #include <kdialog.h>
47 #include <kiconloader.h>
48 #include <kinputdialog.h>
49 #include <klineedit.h>
50 #include <tdelistview.h>
51 #include <tdelocale.h>
52 #include <tdemessagebox.h>
53 #include <kseparator.h>
54 
55 #include "addresseditwidget.h"
56 
57 class TabPressEater : public TQObject
58 {
59  public:
60  TabPressEater( TQObject *parent )
61  : TQObject( parent, "TabPressEater" )
62  {
63  }
64 
65  protected:
66  bool eventFilter( TQObject*, TQEvent *event )
67  {
68  if ( event->type() == TQEvent::KeyPress ) {
69  TQKeyEvent *keyEvent = (TQKeyEvent*)event;
70  if ( keyEvent->key() == TQt::Key_Tab ) {
71  TQApplication::sendEvent( parent(), event );
72  return true;
73  } else
74  return false;
75  } else {
76  return false;
77  }
78  }
79 };
80 
81 
82 AddressEditWidget::AddressEditWidget( TQWidget *parent, const char *name )
83  : TQWidget( parent, name )
84 {
85  TQBoxLayout *layout = new TQVBoxLayout( this, 4, 2 );
86  layout->setSpacing( KDialog::spacingHint() );
87 
88  mTypeCombo = new AddressTypeCombo( mAddressList, this );
89  connect( mTypeCombo, TQ_SIGNAL( activated( int ) ),
90  TQ_SLOT( updateAddressEdit() ) );
91  layout->addWidget( mTypeCombo );
92 
93  mAddressField = new KActiveLabel( this );
94  mAddressField->setFrameStyle( TQFrame::Panel | TQFrame::Sunken );
95  mAddressField->setMinimumHeight( 20 );
96  mAddressField->setAlignment( TQt::AlignTop );
97  mAddressField->setTextFormat( TQt::PlainText );
98  layout->addWidget( mAddressField );
99 
100  mEditButton = new TQPushButton( i18n( "street/postal", "&Edit Addresses..." ), this );
101  connect( mEditButton, TQ_SIGNAL( clicked() ), this, TQ_SLOT( edit() ) );
102 
103  layout->addWidget( mEditButton );
104 }
105 
106 AddressEditWidget::~AddressEditWidget()
107 {
108 }
109 
110 void AddressEditWidget::setReadOnly( bool readOnly )
111 {
112  mEditButton->setEnabled( !readOnly );
113 }
114 
115 TDEABC::Address::List AddressEditWidget::addresses()
116 {
117  TDEABC::Address::List retList;
118 
119  TDEABC::Address::List::ConstIterator it;
120  for ( it = mAddressList.begin(); it != mAddressList.end(); ++it )
121  if ( !(*it).isEmpty() )
122  retList.append( *it );
123 
124  return retList;
125 }
126 
127 void AddressEditWidget::setAddresses( const TDEABC::Addressee &addr,
128  const TDEABC::Address::List &list )
129 {
130  mAddressee = addr;
131 
132  mAddressList.clear();
133 
134  // Insert types for existing numbers.
135  mTypeCombo->insertTypeList( list );
136 
137  TQValueList<int> defaultTypes;
138  defaultTypes << TDEABC::Address::Home;
139  defaultTypes << TDEABC::Address::Work;
140 
141  AddresseeConfig config( mAddressee );
142  const TQValueList<int> configList = config.noDefaultAddrTypes();
143  TQValueList<int>::ConstIterator it;
144  for ( it = configList.begin(); it != configList.end(); ++it )
145  defaultTypes.remove( *it );
146 
147  // Insert default types.
148  // Doing this for mPrefCombo is enough because the list is shared by all
149  // combos.
150  for ( it = defaultTypes.begin(); it != defaultTypes.end(); ++it ) {
151  if ( !mTypeCombo->hasType( *it ) )
152  mTypeCombo->insertType( list, *it, Address( *it ) );
153  }
154 
155  mTypeCombo->updateTypes();
156 
157  // find preferred address which will be shown
158  int preferred = TDEABC::Address::Home; // default if no preferred address set
159  TDEABC::Address::List::ConstIterator addrIt;
160  for ( addrIt = list.begin(); addrIt != list.end(); ++addrIt )
161  if ( (*addrIt).type() & TDEABC::Address::Pref ) {
162  preferred = (*addrIt).type();
163  break;
164  }
165 
166  mTypeCombo->selectType( preferred );
167 
168  updateAddressEdit();
169 }
170 
171 void AddressEditWidget::updateAddressee( const TDEABC::Addressee &addr )
172 {
173  mAddressee = addr;
174  updateAddressEdit();
175 }
176 
177 void AddressEditWidget::edit()
178 {
179  AddressEditDialog dialog( mAddressList, mTypeCombo->currentItem(), this );
180  if ( dialog.exec() ) {
181  if ( dialog.changed() ) {
182  mAddressList = dialog.addresses();
183 
184  bool hasHome = false, hasWork = false;
185  TDEABC::Address::List::ConstIterator it;
186  for ( it = mAddressList.begin(); it != mAddressList.end(); ++it ) {
187  if ( (*it).type() == TDEABC::Address::Home ) {
188  if ( !(*it).isEmpty() )
189  hasHome = true;
190  }
191  if ( (*it).type() == TDEABC::Address::Work ) {
192  if ( !(*it).isEmpty() )
193  hasWork = true;
194  }
195  }
196 
197  AddresseeConfig config( mAddressee );
198  TQValueList<int> configList;
199  if ( !hasHome )
200  configList << TDEABC::Address::Home;
201  if ( !hasWork )
202  configList << TDEABC::Address::Work;
203  config.setNoDefaultAddrTypes( configList );
204 
205  mTypeCombo->updateTypes();
206  updateAddressEdit();
207  emit modified();
208  }
209  }
210 }
211 
212 void AddressEditWidget::updateAddressEdit()
213 {
214  TDEABC::Address::List::Iterator it = mTypeCombo->selectedElement();
215 
216  bool block = signalsBlocked();
217  blockSignals( true );
218 
219  mAddressField->setText( "" );
220 
221  if ( it != mAddressList.end() ) {
222  TDEABC::Address a = *it;
223  if ( !a.isEmpty() ) {
224  if ( a.type() & TDEABC::Address::Work && mAddressee.realName() != mAddressee.organization() ) {
225  mAddressField->setText( a.formattedAddress( mAddressee.realName(),
226  mAddressee.organization() ) );
227  } else {
228  mAddressField->setText( a.formattedAddress( mAddressee.realName() ) );
229  }
230  }
231  }
232 
233  blockSignals( block );
234 }
235 
236 AddressEditDialog::AddressEditDialog( const TDEABC::Address::List &list,
237  int selected, TQWidget *parent,
238  const char *name )
239  : KDialogBase( Plain, i18n( "street/postal", "Edit Address" ), Ok | Cancel, Ok,
240  parent, name, true, true ),
241  mPreviousAddress( 0 )
242 {
243  mAddressList = list;
244 
245  TQWidget *page = plainPage();
246 
247  TQGridLayout *topLayout = new TQGridLayout( page, 8, 2 );
248  topLayout->setSpacing( spacingHint() );
249 
250  mTypeCombo = new AddressTypeCombo( mAddressList, page );
251  topLayout->addMultiCellWidget( mTypeCombo, 0, 0, 0, 1 );
252 
253  TQLabel *label = new TQLabel( i18n( "<streetLabel>:", "%1:" ).arg( TDEABC::Address::streetLabel() ), page );
254  label->setAlignment( TQt::AlignTop | TQt::AlignLeft );
255  topLayout->addWidget( label, 1, 0 );
256  mStreetTextEdit = new TQTextEdit( page );
257  mStreetTextEdit->setTextFormat( TQt::PlainText );
258  label->setBuddy( mStreetTextEdit );
259  topLayout->addWidget( mStreetTextEdit, 1, 1 );
260 
261  TabPressEater *eater = new TabPressEater( this );
262  mStreetTextEdit->installEventFilter( eater );
263 
264  label = new TQLabel( i18n( "<postOfficeBoxLabel>:", "%1:" ).arg( TDEABC::Address::postOfficeBoxLabel() ), page );
265  topLayout->addWidget( label, 2 , 0 );
266  mPOBoxEdit = new KLineEdit( page );
267  label->setBuddy( mPOBoxEdit );
268  topLayout->addWidget( mPOBoxEdit, 2, 1 );
269 
270  label = new TQLabel( i18n( "<localityLabel>:", "%1:" ).arg( TDEABC::Address::localityLabel() ), page );
271  topLayout->addWidget( label, 3, 0 );
272  mLocalityEdit = new KLineEdit( page );
273  label->setBuddy( mLocalityEdit );
274  topLayout->addWidget( mLocalityEdit, 3, 1 );
275 
276  label = new TQLabel( i18n( "<regionLabel>:", "%1:" ).arg( TDEABC::Address::regionLabel() ), page );
277  topLayout->addWidget( label, 4, 0 );
278  mRegionEdit = new KLineEdit( page );
279  label->setBuddy( mRegionEdit );
280  topLayout->addWidget( mRegionEdit, 4, 1 );
281 
282  label = new TQLabel( i18n( "<postalCodeLabel>:", "%1:" ).arg( TDEABC::Address::postalCodeLabel() ), page );
283  topLayout->addWidget( label, 5, 0 );
284  mPostalCodeEdit = new KLineEdit( page );
285  label->setBuddy( mPostalCodeEdit );
286  topLayout->addWidget( mPostalCodeEdit, 5, 1 );
287 
288  label = new TQLabel( i18n( "<countryLabel>:", "%1:" ).arg( TDEABC::Address::countryLabel() ), page );
289  topLayout->addWidget( label, 6, 0 );
290  mCountryCombo = new KComboBox( page );
291  mCountryCombo->setEditable( true );
292  mCountryCombo->setDuplicatesEnabled( false );
293 
294  TQPushButton *labelButton = new TQPushButton( i18n( "Edit Label..." ), page );
295  topLayout->addMultiCellWidget( labelButton, 7, 7, 0, 1 );
296  connect( labelButton, TQ_SIGNAL( clicked() ), TQ_SLOT( editLabel() ) );
297 
298  fillCountryCombo();
299  label->setBuddy( mCountryCombo );
300  topLayout->addWidget( mCountryCombo, 6, 1 );
301 
302  mPreferredCheckBox = new TQCheckBox( i18n( "street/postal", "This is the preferred address" ), page );
303  topLayout->addMultiCellWidget( mPreferredCheckBox, 8, 8, 0, 1 );
304 
305  KSeparator *sep = new KSeparator( KSeparator::HLine, page );
306  topLayout->addMultiCellWidget( sep, 9, 9, 0, 1 );
307 
308  TQHBox *buttonBox = new TQHBox( page );
309  buttonBox->setSpacing( spacingHint() );
310  topLayout->addMultiCellWidget( buttonBox, 10, 10, 0, 1 );
311 
312  TQPushButton *addButton = new TQPushButton( i18n( "New..." ), buttonBox );
313  connect( addButton, TQ_SIGNAL( clicked() ), TQ_SLOT( addAddress() ) );
314 
315  mRemoveButton = new TQPushButton( i18n( "Remove" ), buttonBox );
316  connect( mRemoveButton, TQ_SIGNAL( clicked() ), TQ_SLOT( removeAddress() ) );
317 
318  mChangeTypeButton = new TQPushButton( i18n( "Change Type..." ), buttonBox );
319  connect( mChangeTypeButton, TQ_SIGNAL( clicked() ), TQ_SLOT( changeType() ) );
320 
321  mTypeCombo->updateTypes();
322  mTypeCombo->setCurrentItem( selected );
323 
324  updateAddressEdits();
325 
326  connect( mTypeCombo, TQ_SIGNAL( activated( int ) ),
327  TQ_SLOT( updateAddressEdits() ) );
328  connect( mStreetTextEdit, TQ_SIGNAL( textChanged() ), TQ_SLOT( modified() ) );
329  connect( mPOBoxEdit, TQ_SIGNAL( textChanged( const TQString& ) ), TQ_SLOT( modified() ) );
330  connect( mLocalityEdit, TQ_SIGNAL( textChanged( const TQString& ) ), TQ_SLOT( modified() ) );
331  connect( mRegionEdit, TQ_SIGNAL( textChanged( const TQString& ) ), TQ_SLOT( modified() ) );
332  connect( mPostalCodeEdit, TQ_SIGNAL( textChanged( const TQString& ) ), TQ_SLOT( modified() ) );
333  connect( mCountryCombo, TQ_SIGNAL( textChanged( const TQString& ) ), TQ_SLOT( modified() ) );
334  connect( mPreferredCheckBox, TQ_SIGNAL( toggled( bool ) ), TQ_SLOT( modified() ) );
335 
336  TDEAcceleratorManager::manage( this );
337 
338  mChanged = false;
339 
340  bool state = (mAddressList.count() > 0);
341  mRemoveButton->setEnabled( state );
342  mChangeTypeButton->setEnabled( state );
343 }
344 
345 AddressEditDialog::~AddressEditDialog()
346 {
347 }
348 
349 TDEABC::Address::List AddressEditDialog::addresses()
350 {
351  saveAddress( *(mTypeCombo->selectedElement()) );
352 
353  return mAddressList;
354 }
355 
356 bool AddressEditDialog::changed() const
357 {
358  return mChanged;
359 }
360 
361 void AddressEditDialog::addAddress()
362 {
363  AddressTypeDialog dlg( mTypeCombo->selectedType(), this );
364  if ( dlg.exec() ) {
365  mAddressList.append( Address( dlg.type() ) );
366 
367  mTypeCombo->updateTypes();
368  mTypeCombo->setCurrentItem( mTypeCombo->count() - 1 );
369  updateAddressEdits();
370 
371  modified();
372 
373  mRemoveButton->setEnabled( true );
374  mChangeTypeButton->setEnabled( true );
375  }
376 }
377 
378 void AddressEditDialog::removeAddress()
379 {
380  if ( mAddressList.count() > 0 ) {
381  TDEABC::Address::List::Iterator it = mTypeCombo->selectedElement();
382  if ( mPreviousAddress && mPreviousAddress->id() == (*it).id() )
383  mPreviousAddress = 0;
384 
385  mAddressList.remove( it );
386  mTypeCombo->updateTypes();
387  updateAddressEdits();
388 
389  modified();
390  }
391 
392  bool state = ( mAddressList.count() > 0 );
393  mRemoveButton->setEnabled( state );
394  mChangeTypeButton->setEnabled( state );
395 }
396 
397 void AddressEditDialog::changeType()
398 {
399  TDEABC::Address::List::Iterator a = mTypeCombo->selectedElement();
400 
401  AddressTypeDialog dlg( (*a).type(), this );
402  if ( dlg.exec() ) {
403  (*a).setType( dlg.type() );
404 
405  mTypeCombo->updateTypes();
406 
407  modified();
408  }
409 }
410 
411 void AddressEditDialog::editLabel()
412 {
413  bool ok = false;
414  TQString result = KInputDialog::getMultiLineText( TDEABC::Address::labelLabel(),
415  TDEABC::Address::labelLabel(),
416  mLabel, &ok, this );
417  if ( ok ) {
418  mLabel = result;
419  modified();
420  }
421 }
422 
423 void AddressEditDialog::updateAddressEdits()
424 {
425  if ( mPreviousAddress )
426  saveAddress( *mPreviousAddress );
427 
428  TDEABC::Address::List::Iterator it = mTypeCombo->selectedElement();
429  TDEABC::Address a = *it;
430  mPreviousAddress = &(*it);
431 
432  bool tmp = mChanged;
433 
434  mStreetTextEdit->setText( a.street() );
435  mRegionEdit->setText( a.region() );
436  mLocalityEdit->setText( a.locality() );
437  mPostalCodeEdit->setText( a.postalCode() );
438  mPOBoxEdit->setText( a.postOfficeBox() );
439  mCountryCombo->setCurrentText( a.country() );
440  mLabel = a.label();
441 
442  mPreferredCheckBox->setChecked( a.type() & TDEABC::Address::Pref );
443 
444  if ( a.isEmpty() )
445  mCountryCombo->setCurrentText( TDEGlobal::locale()->twoAlphaToCountryName( TDEGlobal::locale()->country() ) );
446 
447  mStreetTextEdit->setFocus();
448 
449  mChanged = tmp;
450 }
451 
452 void AddressEditDialog::modified()
453 {
454  mChanged = true;
455 }
456 
457 void AddressEditDialog::saveAddress( TDEABC::Address &addr )
458 {
459  addr.setLocality( mLocalityEdit->text() );
460  addr.setRegion( mRegionEdit->text() );
461  addr.setPostalCode( mPostalCodeEdit->text() );
462  addr.setCountry( mCountryCombo->currentText() );
463  addr.setPostOfficeBox( mPOBoxEdit->text() );
464  addr.setStreet( mStreetTextEdit->text() );
465  addr.setLabel( mLabel );
466 
467 
468  if ( mPreferredCheckBox->isChecked() ) {
469  TDEABC::Address::List::Iterator it;
470  for ( it = mAddressList.begin(); it != mAddressList.end(); ++it )
471  (*it).setType( (*it).type() & ~( TDEABC::Address::Pref ) );
472 
473  addr.setType( addr.type() | TDEABC::Address::Pref );
474  } else
475  addr.setType( addr.type() & ~( TDEABC::Address::Pref ) );
476 }
477 
478 void AddressEditDialog::fillCountryCombo()
479 {
480  TQString country[] = {
481  i18n( "Afghanistan" ), i18n( "Albania" ), i18n( "Algeria" ),
482  i18n( "American Samoa" ), i18n( "Andorra" ), i18n( "Angola" ),
483  i18n( "Anguilla" ), i18n( "Antarctica" ), i18n( "Antigua and Barbuda" ),
484  i18n( "Argentina" ), i18n( "Armenia" ), i18n( "Aruba" ),
485  i18n( "Ashmore and Cartier Islands" ), i18n( "Australia" ),
486  i18n( "Austria" ), i18n( "Azerbaijan" ), i18n( "Bahamas" ),
487  i18n( "Bahrain" ), i18n( "Bangladesh" ), i18n( "Barbados" ),
488  i18n( "Belarus" ), i18n( "Belgium" ), i18n( "Belize" ),
489  i18n( "Benin" ), i18n( "Bermuda" ), i18n( "Bhutan" ),
490  i18n( "Bolivia" ), i18n( "Bosnia and Herzegovina" ), i18n( "Botswana" ),
491  i18n( "Brazil" ), i18n( "Brunei" ), i18n( "Bulgaria" ),
492  i18n( "Burkina Faso" ), i18n( "Burundi" ), i18n( "Cambodia" ),
493  i18n( "Cameroon" ), i18n( "Canada" ), i18n( "Cape Verde" ),
494  i18n( "Cayman Islands" ), i18n( "Central African Republic" ),
495  i18n( "Chad" ), i18n( "Chile" ), i18n( "China" ), i18n( "Colombia" ),
496  i18n( "Comoros" ), i18n( "Congo" ), i18n( "Congo, Dem. Rep." ),
497  i18n( "Costa Rica" ), i18n( "Croatia" ),
498  i18n( "Cuba" ), i18n( "Cyprus" ), i18n( "Czech Republic" ),
499  i18n( "Denmark" ), i18n( "Djibouti" ),
500  i18n( "Dominica" ), i18n( "Dominican Republic" ), i18n( "Ecuador" ),
501  i18n( "Egypt" ), i18n( "El Salvador" ), i18n( "Equatorial Guinea" ),
502  i18n( "Eritrea" ), i18n( "Estonia" ), i18n( "England" ),
503  i18n( "Ethiopia" ), i18n( "European Union" ), i18n( "Faroe Islands" ),
504  i18n( "Fiji" ), i18n( "Finland" ), i18n( "France" ),
505  i18n( "French Polynesia" ), i18n( "Gabon" ), i18n( "Gambia" ),
506  i18n( "Georgia" ), i18n( "Germany" ), i18n( "Ghana" ),
507  i18n( "Greece" ), i18n( "Greenland" ), i18n( "Grenada" ),
508  i18n( "Guam" ), i18n( "Guatemala" ), i18n( "Guinea" ),
509  i18n( "Guinea-Bissau" ), i18n( "Guyana" ), i18n( "Haiti" ),
510  i18n( "Honduras" ), i18n( "Hong Kong" ), i18n( "Hungary" ),
511  i18n( "Iceland" ), i18n( "India" ), i18n( "Indonesia" ),
512  i18n( "Iran" ), i18n( "Iraq" ), i18n( "Ireland" ),
513  i18n( "Israel" ), i18n( "Italy" ), i18n( "Ivory Coast" ),
514  i18n( "Jamaica" ), i18n( "Japan" ), i18n( "Jordan" ),
515  i18n( "Kazakhstan" ), i18n( "Kenya" ), i18n( "Kiribati" ),
516  i18n( "Korea, North" ), i18n( "Korea, South" ),
517  i18n( "Kuwait" ), i18n( "Kyrgyzstan" ), i18n( "Laos" ),
518  i18n( "Latvia" ), i18n( "Lebanon" ), i18n( "Lesotho" ),
519  i18n( "Liberia" ), i18n( "Libya" ), i18n( "Liechtenstein" ),
520  i18n( "Lithuania" ), i18n( "Luxembourg" ), i18n( "Macau" ),
521  i18n( "Madagascar" ), i18n( "Malawi" ), i18n( "Malaysia" ),
522  i18n( "Maldives" ), i18n( "Mali" ), i18n( "Malta" ),
523  i18n( "Marshall Islands" ), i18n( "Martinique" ), i18n( "Mauritania" ),
524  i18n( "Mauritius" ), i18n( "Mexico" ),
525  i18n( "Micronesia, Federated States Of" ), i18n( "Moldova" ),
526  i18n( "Monaco" ), i18n( "Mongolia" ), i18n( "Montserrat" ),
527  i18n( "Morocco" ), i18n( "Mozambique" ), i18n( "Myanmar" ),
528  i18n( "Namibia" ),
529  i18n( "Nauru" ), i18n( "Nepal" ), i18n( "Netherlands" ),
530  i18n( "Netherlands Antilles" ), i18n( "New Caledonia" ),
531  i18n( "New Zealand" ), i18n( "Nicaragua" ), i18n( "Niger" ),
532  i18n( "Nigeria" ), i18n( "Niue" ), i18n( "North Korea" ),
533  i18n( "Northern Ireland" ), i18n( "Northern Mariana Islands" ),
534  i18n( "Norway" ), i18n( "Oman" ), i18n( "Pakistan" ), i18n( "Palau" ),
535  i18n( "Palestinian" ), i18n( "Panama" ), i18n( "Papua New Guinea" ),
536  i18n( "Paraguay" ), i18n( "Peru" ), i18n( "Philippines" ),
537  i18n( "Poland" ), i18n( "Portugal" ), i18n( "Puerto Rico" ),
538  i18n( "Qatar" ), i18n( "Romania" ), i18n( "Russia" ), i18n( "Rwanda" ),
539  i18n( "St. Kitts and Nevis" ), i18n( "St. Lucia" ),
540  i18n( "St. Vincent and the Grenadines" ), i18n( "San Marino" ),
541  i18n( "Sao Tome and Principe" ), i18n( "Saudi Arabia" ),
542  i18n( "Senegal" ), i18n( "Serbia & Montenegro" ), i18n( "Seychelles" ),
543  i18n( "Sierra Leone" ), i18n( "Singapore" ), i18n( "Slovakia" ),
544  i18n( "Slovenia" ), i18n( "Solomon Islands" ), i18n( "Somalia" ),
545  i18n( "South Africa" ), i18n( "South Korea" ), i18n( "Spain" ),
546  i18n( "Sri Lanka" ), i18n( "St. Kitts and Nevis" ), i18n( "Sudan" ),
547  i18n( "Suriname" ), i18n( "Swaziland" ), i18n( "Sweden" ),
548  i18n( "Switzerland" ), i18n( "Syria" ), i18n( "Taiwan" ),
549  i18n( "Tajikistan" ), i18n( "Tanzania" ), i18n( "Thailand" ),
550  i18n( "Tibet" ), i18n( "Togo" ), i18n( "Tonga" ),
551  i18n( "Trinidad and Tobago" ), i18n( "Tunisia" ), i18n( "Turkey" ),
552  i18n( "Turkmenistan" ), i18n( "Turks and Caicos Islands" ),
553  i18n( "Tuvalu" ), i18n( "Uganda" ), i18n( "Ukraine" ),
554  i18n( "United Arab Emirates" ), i18n( "United Kingdom" ),
555  i18n( "United States" ), i18n( "Uruguay" ), i18n( "Uzbekistan" ),
556  i18n( "Vanuatu" ), i18n( "Vatican City" ), i18n( "Venezuela" ),
557  i18n( "Vietnam" ), i18n( "Western Samoa" ), i18n( "Yemen" ),
558  i18n( "Yugoslavia" ), i18n( "Zaire" ), i18n( "Zambia" ),
559  i18n( "Zimbabwe" ),
560  ""
561  };
562 
563  TQStringList countries;
564  for ( int i = 0; !country[ i ].isEmpty(); ++i )
565  countries.append( country[ i ] );
566 
567  countries = sortLocaleAware( countries );
568 
569  mCountryCombo->insertStringList( countries );
570  mCountryCombo->completionObject()->setItems( countries );
571  mCountryCombo->setAutoCompletion( true );
572 }
573 
574 
575 AddressTypeDialog::AddressTypeDialog( int type, TQWidget *parent )
576  : KDialogBase( Plain, i18n( "street/postal", "Edit Address Type" ), Ok | Cancel, Ok,
577  parent, "AddressTypeDialog" )
578 {
579  TQWidget *page = plainPage();
580  TQVBoxLayout *layout = new TQVBoxLayout( page );
581 
582  mGroup = new TQButtonGroup( 2, TQt::Horizontal, i18n( "street/postal", "Address Types" ), page );
583  layout->addWidget( mGroup );
584 
585  mTypeList = TDEABC::Address::typeList();
586  mTypeList.remove( TDEABC::Address::Pref );
587 
588  TDEABC::Address::TypeList::ConstIterator it;
589  for ( it = mTypeList.begin(); it != mTypeList.end(); ++it )
590  new TQCheckBox( TDEABC::Address::typeLabel( *it ), mGroup );
591 
592  for ( int i = 0; i < mGroup->count(); ++i ) {
593  TQCheckBox *box = (TQCheckBox*)mGroup->find( i );
594  box->setChecked( type & mTypeList[ i ] );
595  }
596 }
597 
598 AddressTypeDialog::~AddressTypeDialog()
599 {
600 }
601 
602 int AddressTypeDialog::type() const
603 {
604  int type = 0;
605  for ( int i = 0; i < mGroup->count(); ++i ) {
606  TQCheckBox *box = (TQCheckBox*)mGroup->find( i );
607  if ( box->isChecked() )
608  type += mTypeList[ i ];
609  }
610 
611  return type;
612 }
613 
618 class LocaleAwareString : public TQString
619 {
620  public:
621  LocaleAwareString() : TQString()
622  {}
623 
624  LocaleAwareString( const TQString &str ) : TQString( str )
625  {}
626 };
627 
628 static bool operator<( const LocaleAwareString &s1, const LocaleAwareString &s2 )
629 {
630  return ( TQString::localeAwareCompare( s1, s2 ) < 0 );
631 }
632 
633 TQStringList AddressEditDialog::sortLocaleAware( const TQStringList &list )
634 {
635  TQValueList<LocaleAwareString> sortedList;
636 
637  TQStringList::ConstIterator it;
638  for ( it = list.begin(); it != list.end(); ++it )
639  sortedList.append( LocaleAwareString( *it ) );
640 
641  qHeapSort( sortedList );
642 
643  TQStringList retval;
644  TQValueList<LocaleAwareString>::ConstIterator retIt;
645  for ( retIt = sortedList.begin(); retIt != sortedList.end(); ++retIt )
646  retval.append( *retIt );
647 
648  return retval;
649 }
650 
651 #include "addresseditwidget.moc"
Dialog for editing address details.
Dialog for selecting an address type.
Combo box for type information of Addresses and Phone numbers.
Definition: typecombo.h:35