kaddressbook Library API Documentation

nameeditdialog.cpp

00001 /*                                                                      
00002     This file is part of KAddressBook.                                  
00003     Copyright (c) 2002 Mike Pilone <mpilone@slac.com>                   
00004                                                                         
00005     This program is free software; you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation; either version 2 of the License, or   
00008     (at your option) any later version.                                 
00009                                                                         
00010     This program is distributed in the hope that it will be useful,     
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of      
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the        
00013     GNU General Public License for more details.                        
00014                                                                         
00015     You should have received a copy of the GNU General Public License   
00016     along with this program; if not, write to the Free Software         
00017     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.           
00018                                                                         
00019     As a special exception, permission is given to link this program    
00020     with any edition of Qt, and distribute the resulting executable,    
00021     without including the source code for Qt in the source distribution.
00022 */                                                                      
00023 
00024 #include <qlayout.h>
00025 #include <qlabel.h>
00026 #include <qlistbox.h>
00027 #include <qlistview.h>
00028 #include <qtooltip.h>
00029 #include <qpushbutton.h>
00030 #include <qcheckbox.h>
00031 #include <qstring.h>
00032 
00033 #include <kaccelmanager.h>
00034 #include <kapplication.h>
00035 #include <kbuttonbox.h>
00036 #include <kconfig.h>
00037 #include <klineedit.h>
00038 #include <klistview.h>
00039 #include <kcombobox.h>
00040 #include <klocale.h>
00041 #include <kdebug.h>
00042 #include <kiconloader.h>
00043 #include <kmessagebox.h>
00044 
00045 #include "nameeditdialog.h"
00046 
00047 NameEditDialog::NameEditDialog( const KABC::Addressee &addr, QWidget *parent, const char *name )
00048   : KDialogBase(KDialogBase::Plain, i18n("Edit Contact Name"),
00049                 KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok,
00050                 parent, name, true)
00051 {
00052   QWidget *page = plainPage();
00053   QGridLayout *layout = new QGridLayout(page);
00054   layout->setSpacing(spacingHint());
00055   layout->addColSpacing(2, 100);
00056   QLabel *label;
00057   
00058   label = new QLabel(i18n("Honorific prefixes:"), page);
00059   layout->addWidget(label, 0, 0);
00060   mPrefixCombo = new KComboBox(page, "mPrefixCombo");
00061   mPrefixCombo->setDuplicatesEnabled(false);
00062   mPrefixCombo->setEditable(true);
00063   label->setBuddy( mPrefixCombo );
00064   layout->addMultiCellWidget(mPrefixCombo, 0, 0, 1, 2);
00065   
00066   label = new QLabel(i18n("Given name:"), page);
00067   layout->addWidget(label, 1, 0);
00068   mGivenNameEdit = new KLineEdit(page, "mGivenNameEdit");
00069   label->setBuddy( mGivenNameEdit );
00070   layout->addMultiCellWidget(mGivenNameEdit, 1, 1, 1, 2);
00071 
00072   label = new QLabel(i18n("Additional names:"), page);
00073   layout->addWidget(label, 2, 0);
00074   mAdditionalNameEdit = new KLineEdit(page, "mAdditionalNameEdit");
00075   label->setBuddy( mAdditionalNameEdit );
00076   layout->addMultiCellWidget(mAdditionalNameEdit, 2, 2, 1, 2);
00077   
00078   label = new QLabel(i18n("Family names:"), page);
00079   layout->addWidget(label, 3, 0);
00080   mFamilyNameEdit = new KLineEdit(page, "mFamilyNameEdit");
00081   label->setBuddy( mFamilyNameEdit );
00082   layout->addMultiCellWidget(mFamilyNameEdit, 3, 3, 1, 2);
00083   
00084   label = new QLabel(i18n("Honorific suffixes:"), page);
00085   layout->addWidget(label, 4, 0);
00086   mSuffixCombo = new KComboBox(page, "mSuffixCombo");
00087   mSuffixCombo->setDuplicatesEnabled(false);
00088   mSuffixCombo->setEditable(true);
00089   label->setBuddy( mSuffixCombo );
00090   layout->addMultiCellWidget(mSuffixCombo, 4, 4, 1, 2);
00091 
00092   mParseBox = new QCheckBox( i18n( "Parse name automatically" ), page );
00093   connect( mParseBox, SIGNAL( toggled(bool) ), SLOT( parseBoxChanged(bool) ) );
00094   connect( mParseBox, SIGNAL( toggled(bool) ), SLOT( modified() ) );
00095   layout->addMultiCellWidget( mParseBox, 5, 5, 0, 1 );
00096   
00097   // Fill in the values
00098   mFamilyNameEdit->setText(addr.familyName());
00099   mGivenNameEdit->setText(addr.givenName());
00100   mAdditionalNameEdit->setText(addr.additionalName());
00101   
00102   // Prefix and suffix combos
00103   QStringList sTitle;
00104   QStringList sSuffix;
00105 
00106   sTitle += i18n( "Dr." );
00107   sTitle += i18n( "Miss" );
00108   sTitle += i18n( "Mr." );
00109   sTitle += i18n( "Mrs." );
00110   sTitle += i18n( "Ms." );
00111   sTitle += i18n( "Prof." );
00112   sTitle.sort();
00113 
00114   sSuffix += i18n( "I" );
00115   sSuffix += i18n( "II" );
00116   sSuffix += i18n( "III" );
00117   sSuffix += i18n( "Jr." );
00118   sSuffix += i18n( "Sr." );
00119   sSuffix.sort();
00120   
00121   mPrefixCombo->insertStringList(sTitle);
00122   mSuffixCombo->insertStringList(sSuffix);
00123   
00124   mPrefixCombo->setCurrentText(addr.prefix());
00125   mSuffixCombo->setCurrentText(addr.suffix());
00126 
00127   mAddresseeConfig.setAddressee( addr );
00128   mParseBox->setChecked( mAddresseeConfig.automaticNameParsing() );
00129 
00130   KAcceleratorManager::manage( this );
00131 
00132   connect( mPrefixCombo, SIGNAL( textChanged( const QString& ) ), SLOT( modified() ) );
00133   connect( mGivenNameEdit, SIGNAL( textChanged( const QString& ) ), SLOT( modified() ) );
00134   connect( mAdditionalNameEdit, SIGNAL( textChanged( const QString& ) ), SLOT( modified() ) );
00135   connect( mFamilyNameEdit, SIGNAL( textChanged( const QString& ) ), SLOT( modified() ) );
00136   connect( mSuffixCombo, SIGNAL( textChanged( const QString& ) ), SLOT( modified() ) );
00137 
00138   mChanged = false;
00139 }
00140     
00141 NameEditDialog::~NameEditDialog() 
00142 {
00143 }
00144     
00145 QString NameEditDialog::familyName() const
00146 {
00147   return mFamilyNameEdit->text();
00148 }
00149     
00150 QString NameEditDialog::givenName() const
00151 {
00152   return mGivenNameEdit->text();
00153 }
00154     
00155 QString NameEditDialog::prefix() const
00156 {
00157   return mPrefixCombo->currentText();
00158 }
00159     
00160 QString NameEditDialog::suffix() const
00161 {
00162   return mSuffixCombo->currentText();
00163 }
00164     
00165 QString NameEditDialog::additionalName() const
00166 {
00167   return mAdditionalNameEdit->text();
00168 }
00169 
00170 bool NameEditDialog::changed() const
00171 {
00172   return mChanged;
00173 }
00174 
00175 void NameEditDialog::parseBoxChanged( bool value )
00176 {
00177   mAddresseeConfig.setAutomaticNameParsing( value );
00178 }
00179 
00180 void NameEditDialog::modified()
00181 {
00182   mChanged = true;
00183 }
00184 
00185 #include "nameeditdialog.moc"
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sun Feb 15 11:40:37 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001