00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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, int type,
00048 bool readOnly, QWidget *parent, const char *name )
00049 : KDialogBase( Plain, i18n( "Edit Contact Name" ), Help | Ok | Cancel,
00050 Ok, 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 );
00061 mPrefixCombo->setDuplicatesEnabled( false );
00062 mPrefixCombo->setEditable( true );
00063 mPrefixCombo->setEnabled( !readOnly );
00064 label->setBuddy( mPrefixCombo );
00065 layout->addMultiCellWidget( mPrefixCombo, 0, 0, 1, 2 );
00066
00067 label = new QLabel( i18n( "Given name:" ), page );
00068 layout->addWidget( label, 1, 0 );
00069 mGivenNameEdit = new KLineEdit( page );
00070 mGivenNameEdit->setReadOnly( readOnly );
00071 label->setBuddy( mGivenNameEdit );
00072 layout->addMultiCellWidget( mGivenNameEdit, 1, 1, 1, 2 );
00073
00074 label = new QLabel( i18n( "Additional names:" ), page );
00075 layout->addWidget( label, 2, 0 );
00076 mAdditionalNameEdit = new KLineEdit( page );
00077 mAdditionalNameEdit->setReadOnly( readOnly );
00078 label->setBuddy( mAdditionalNameEdit );
00079 layout->addMultiCellWidget( mAdditionalNameEdit, 2, 2, 1, 2 );
00080
00081 label = new QLabel( i18n( "Family names:" ), page );
00082 layout->addWidget( label, 3, 0 );
00083 mFamilyNameEdit = new KLineEdit( page );
00084 mFamilyNameEdit->setReadOnly( readOnly );
00085 label->setBuddy( mFamilyNameEdit );
00086 layout->addMultiCellWidget( mFamilyNameEdit, 3, 3, 1, 2 );
00087
00088 label = new QLabel( i18n( "Honorific suffixes:" ), page );
00089 layout->addWidget( label, 4, 0 );
00090 mSuffixCombo = new KComboBox( page );
00091 mSuffixCombo->setDuplicatesEnabled( false );
00092 mSuffixCombo->setEditable( true );
00093 mSuffixCombo->setEnabled( !readOnly );
00094 label->setBuddy( mSuffixCombo );
00095 layout->addMultiCellWidget( mSuffixCombo, 4, 4, 1, 2 );
00096
00097 mFormattedNameCombo = new KComboBox( page );
00098 mFormattedNameCombo->setEnabled( !readOnly );
00099 layout->addWidget( mFormattedNameCombo, 5, 0 );
00100 connect( mFormattedNameCombo, SIGNAL( activated( int ) ), SLOT( typeChanged( int ) ) );
00101
00102 mFormattedNameEdit = new KLineEdit( page );
00103 mFormattedNameEdit->setEnabled( type == CustomName && !readOnly );
00104 layout->addWidget( mFormattedNameEdit, 5, 1 );
00105
00106 mParseBox = new QCheckBox( i18n( "Parse name automatically" ), page );
00107 mParseBox->setEnabled( !readOnly );
00108 connect( mParseBox, SIGNAL( toggled(bool) ), SLOT( parseBoxChanged(bool) ) );
00109 connect( mParseBox, SIGNAL( toggled(bool) ), SLOT( modified() ) );
00110 layout->addMultiCellWidget( mParseBox, 6, 6, 0, 1 );
00111
00112
00113 mFamilyNameEdit->setText( addr.familyName() );
00114 mGivenNameEdit->setText( addr.givenName() );
00115 mAdditionalNameEdit->setText( addr.additionalName() );
00116 mFormattedNameEdit->setText( addr.formattedName() );
00117
00118
00119 KConfig config( "kabcrc" );
00120 config.setGroup( "General" );
00121
00122 QStringList sTitle;
00123 sTitle += i18n( "Dr." );
00124 sTitle += i18n( "Miss" );
00125 sTitle += i18n( "Mr." );
00126 sTitle += i18n( "Mrs." );
00127 sTitle += i18n( "Ms." );
00128 sTitle += i18n( "Prof." );
00129 sTitle += config.readListEntry( "Prefixes" );
00130 sTitle.sort();
00131
00132 QStringList sSuffix;
00133 sSuffix += i18n( "I" );
00134 sSuffix += i18n( "II" );
00135 sSuffix += i18n( "III" );
00136 sSuffix += i18n( "Jr." );
00137 sSuffix += i18n( "Sr." );
00138 sSuffix += config.readListEntry( "Suffixes" );
00139 sSuffix.sort();
00140
00141 mPrefixCombo->insertStringList( sTitle );
00142 mSuffixCombo->insertStringList( sSuffix );
00143
00144 mPrefixCombo->setCurrentText( addr.prefix() );
00145 mSuffixCombo->setCurrentText( addr.suffix() );
00146
00147 mAddresseeConfig.setAddressee( addr );
00148 mParseBox->setChecked( mAddresseeConfig.automaticNameParsing() );
00149
00150 KAcceleratorManager::manage( this );
00151
00152 connect( mPrefixCombo, SIGNAL( textChanged( const QString& ) ), SLOT( modified() ) );
00153 connect( mGivenNameEdit, SIGNAL( textChanged( const QString& ) ), SLOT( modified() ) );
00154 connect( mAdditionalNameEdit, SIGNAL( textChanged( const QString& ) ), SLOT( modified() ) );
00155 connect( mFamilyNameEdit, SIGNAL( textChanged( const QString& ) ), SLOT( modified() ) );
00156 connect( mSuffixCombo, SIGNAL( textChanged( const QString& ) ), SLOT( modified() ) );
00157 connect( mFormattedNameCombo, SIGNAL( activated( int ) ), SLOT( modified() ) );
00158 connect( mFormattedNameEdit, SIGNAL( textChanged( const QString& ) ), SLOT( modified() ) );
00159
00160 initTypeCombo();
00161 mFormattedNameCombo->setCurrentItem( type );
00162 mPrefixCombo->lineEdit()->setFocus();
00163 mChanged = false;
00164 }
00165
00166 NameEditDialog::~NameEditDialog()
00167 {
00168 }
00169
00170 QString NameEditDialog::familyName() const
00171 {
00172 return mFamilyNameEdit->text();
00173 }
00174
00175 QString NameEditDialog::givenName() const
00176 {
00177 return mGivenNameEdit->text();
00178 }
00179
00180 QString NameEditDialog::prefix() const
00181 {
00182 return mPrefixCombo->currentText();
00183 }
00184
00185 QString NameEditDialog::suffix() const
00186 {
00187 return mSuffixCombo->currentText();
00188 }
00189
00190 QString NameEditDialog::additionalName() const
00191 {
00192 return mAdditionalNameEdit->text();
00193 }
00194
00195 QString NameEditDialog::customFormattedName() const
00196 {
00197 return mFormattedNameEdit->text();
00198 }
00199
00200 int NameEditDialog::formattedNameType() const
00201 {
00202 return mFormattedNameCombo->currentItem();
00203 }
00204
00205 bool NameEditDialog::changed() const
00206 {
00207 return mChanged;
00208 }
00209
00210 QString NameEditDialog::formattedName( const KABC::Addressee &addr, int type )
00211 {
00212 QString name;
00213
00214 switch ( type ) {
00215 case SimpleName:
00216 name = addr.givenName() + " " + addr.familyName();
00217 break;
00218 case FullName:
00219 name = addr.assembledName();
00220 break;
00221 case ReverseNameWithComma:
00222 name = addr.familyName() + ", " + addr.givenName();
00223 break;
00224 case ReverseName:
00225 name = addr.familyName() + " " + addr.givenName();
00226 break;
00227 case Organization:
00228 name = addr.organization();
00229 break;
00230 default:
00231 name = "";
00232 break;
00233 }
00234
00235 return name.simplifyWhiteSpace();
00236 }
00237
00238 void NameEditDialog::parseBoxChanged( bool value )
00239 {
00240 mAddresseeConfig.setAutomaticNameParsing( value );
00241 }
00242
00243 void NameEditDialog::typeChanged( int pos )
00244 {
00245 mFormattedNameEdit->setEnabled( pos == 0 );
00246 }
00247
00248 void NameEditDialog::modified()
00249 {
00250 mChanged = true;
00251 }
00252
00253 void NameEditDialog::initTypeCombo()
00254 {
00255 int pos = mFormattedNameCombo->currentItem();
00256
00257 mFormattedNameCombo->clear();
00258 mFormattedNameCombo->insertItem( i18n( "Custom" ) );
00259 mFormattedNameCombo->insertItem( i18n( "Simple Name" ) );
00260 mFormattedNameCombo->insertItem( i18n( "Full Name" ) );
00261 mFormattedNameCombo->insertItem( i18n( "Reverse Name with Comma" ) );
00262 mFormattedNameCombo->insertItem( i18n( "Reverse Name" ) );
00263 mFormattedNameCombo->insertItem( i18n( "Organization" ) );
00264
00265 mFormattedNameCombo->setCurrentItem( pos );
00266 }
00267
00268 void NameEditDialog::slotHelp()
00269 {
00270 kapp->invokeHelp( "managing-contacts-automatic-nameparsing" );
00271 }
00272
00273 #include "nameeditdialog.moc"