summaryrefslogtreecommitdiffabout
path: root/kaddressbook
authorzautrix <zautrix>2005-06-03 14:15:57 (UTC)
committer zautrix <zautrix>2005-06-03 14:15:57 (UTC)
commit0207d193bdb6c66201562a17e68872e018ec223c (patch) (side-by-side diff)
treec2b15d8acd9bdc7adee3d074551396d98599966f /kaddressbook
parent7aa43257ffb63e772342f24c1f7945e285171ee6 (diff)
downloadkdepimpi-0207d193bdb6c66201562a17e68872e018ec223c.zip
kdepimpi-0207d193bdb6c66201562a17e68872e018ec223c.tar.gz
kdepimpi-0207d193bdb6c66201562a17e68872e018ec223c.tar.bz2
formateed name fix
Diffstat (limited to 'kaddressbook') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/nameeditdialog.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/kaddressbook/nameeditdialog.cpp b/kaddressbook/nameeditdialog.cpp
index f5dba0f..199f3d6 100644
--- a/kaddressbook/nameeditdialog.cpp
+++ b/kaddressbook/nameeditdialog.cpp
@@ -47,249 +47,254 @@
#include <kdebug.h>
#include <kiconloader.h>
#include <kmessagebox.h>
#include "nameeditdialog.h"
NameEditDialog::NameEditDialog( const KABC::Addressee &addr, int type,
QWidget *parent, const char *name )
: KDialogBase( Plain, i18n( "Edit Contact Name" ), Help | Ok | Cancel,
Ok, parent, name, true )
{
QWidget *page = plainPage();
QGridLayout *layout = new QGridLayout( page, 5, 3 );
layout->setSpacing( spacingHint() );
layout->addColSpacing( 2, 100 );
QLabel *label;
label = new QLabel( i18n( "Honorific prefixes:" ), page );
layout->addWidget( label, 0, 0 );
mPrefixCombo = new KComboBox( page );
mPrefixCombo->setDuplicatesEnabled( false );
mPrefixCombo->setEditable( true );
label->setBuddy( mPrefixCombo );
layout->addMultiCellWidget( mPrefixCombo, 0, 0, 1, 2 );
label = new QLabel( i18n( "Given name:" ), page );
layout->addWidget( label, 1, 0 );
mGivenNameEdit = new KLineEdit( page );
label->setBuddy( mGivenNameEdit );
layout->addMultiCellWidget( mGivenNameEdit, 1, 1, 1, 2 );
label = new QLabel( i18n( "Additional names:" ), page );
layout->addWidget( label, 2, 0 );
mAdditionalNameEdit = new KLineEdit( page );
label->setBuddy( mAdditionalNameEdit );
layout->addMultiCellWidget( mAdditionalNameEdit, 2, 2, 1, 2 );
label = new QLabel( i18n( "Family names:" ), page );
layout->addWidget( label, 3, 0 );
mFamilyNameEdit = new KLineEdit( page );
label->setBuddy( mFamilyNameEdit );
layout->addMultiCellWidget( mFamilyNameEdit, 3, 3, 1, 2 );
label = new QLabel( i18n( "Honorific suffixes:" ), page );
layout->addWidget( label, 4, 0 );
mSuffixCombo = new KComboBox( page );
mSuffixCombo->setDuplicatesEnabled( false );
mSuffixCombo->setEditable( true );
label->setBuddy( mSuffixCombo );
layout->addMultiCellWidget( mSuffixCombo, 4, 4, 1, 2 );
mFormattedNameCombo = new KComboBox( page );
mFormattedNameCombo->setMaximumWidth(100);
layout->addMultiCellWidget( mFormattedNameCombo, 5, 5, 0, 0 );
connect( mFormattedNameCombo, SIGNAL( activated( int ) ), SLOT( typeChanged( int ) ) );
mFormattedNameEdit = new KLineEdit( page );
mFormattedNameEdit->setEnabled( type == CustomName );
layout->addMultiCellWidget( mFormattedNameEdit, 5, 5, 1, 2 );
mParseBox = new QCheckBox( i18n( "Parse name automatically" ), page );
connect( mParseBox, SIGNAL( toggled(bool) ), SLOT( parseBoxChanged(bool) ) );
connect( mParseBox, SIGNAL( toggled(bool) ), SLOT( modified() ) );
layout->addMultiCellWidget( mParseBox, 6, 6, 0, 2 );
// Fill in the values
mFamilyNameEdit->setText( addr.familyName() );
mGivenNameEdit->setText( addr.givenName() );
mAdditionalNameEdit->setText( addr.additionalName() );
mFormattedNameEdit->setText( addr.formattedName() );
// Prefix and suffix combos
//US KConfig config( "kabcrc" );
KConfig config( locateLocal("config", "kabcrc") );
config.setGroup( "General" );
QStringList sTitle;
sTitle += i18n( "Dr." );
sTitle += i18n( "Miss" );
sTitle += i18n( "Mr." );
sTitle += i18n( "Mrs." );
sTitle += i18n( "Ms." );
sTitle += i18n( "Prof." );
sTitle += config.readListEntry( "Prefixes" );
sTitle.sort();
QStringList sSuffix;
sSuffix += i18n( "I" );
sSuffix += i18n( "II" );
sSuffix += i18n( "III" );
sSuffix += i18n( "Jr." );
sSuffix += i18n( "Sr." );
sSuffix += config.readListEntry( "Suffixes" );
sSuffix.sort();
mPrefixCombo->insertStringList( sTitle );
mSuffixCombo->insertStringList( sSuffix );
#ifndef KAB_EMBEDDED
mPrefixCombo->setCurrentText( addr.prefix() );
mSuffixCombo->setCurrentText( addr.suffix() );
#else //KAB_EMBEDDED
mPrefixCombo->setEditText( addr.prefix() );
mSuffixCombo->setEditText( addr.suffix() );
#endif //KAB_EMBEDDED
AddresseeConfig::instance()->setUid( addr.uid() );
mParseBox->setChecked( AddresseeConfig::instance()->automaticNameParsing() );
#ifndef KAB_EMBEDDED
KAcceleratorManager::manage( this );
#endif //KAB_EMBEDDED
connect( mPrefixCombo, SIGNAL( textChanged( const QString& ) ), SLOT( modified() ) );
connect( mPrefixCombo, SIGNAL( textChanged( const QString& ) ), SLOT( updateTypeCombo() ) );
connect( mGivenNameEdit, SIGNAL( textChanged( const QString& ) ), SLOT( modified() ) );
connect( mGivenNameEdit, SIGNAL( textChanged( const QString& ) ), SLOT( updateTypeCombo() ) );
connect( mAdditionalNameEdit, SIGNAL( textChanged( const QString& ) ), SLOT( modified() ) );
connect( mAdditionalNameEdit, SIGNAL( textChanged( const QString& ) ), SLOT( updateTypeCombo() ) );
connect( mFamilyNameEdit, SIGNAL( textChanged( const QString& ) ), SLOT( modified() ) );
connect( mFamilyNameEdit, SIGNAL( textChanged( const QString& ) ), SLOT( updateTypeCombo() ) );
connect( mSuffixCombo, SIGNAL( textChanged( const QString& ) ), SLOT( modified() ) );
connect( mSuffixCombo, SIGNAL( textChanged( const QString& ) ), SLOT( updateTypeCombo() ) );
connect( mFormattedNameCombo, SIGNAL( activated( int ) ), SLOT( modified() ) );
connect( mFormattedNameEdit, SIGNAL( textChanged( const QString& ) ), SLOT( modified() ) );
updateTypeCombo();
mFormattedNameCombo->setCurrentItem( type );
mChanged = false;
}
NameEditDialog::~NameEditDialog()
{
}
QString NameEditDialog::familyName() const
{
return mFamilyNameEdit->text();
}
QString NameEditDialog::givenName() const
{
return mGivenNameEdit->text();
}
QString NameEditDialog::prefix() const
{
return mPrefixCombo->currentText();
}
QString NameEditDialog::suffix() const
{
return mSuffixCombo->currentText();
}
QString NameEditDialog::additionalName() const
{
return mAdditionalNameEdit->text();
}
QString NameEditDialog::customFormattedName() const
{
return mFormattedNameEdit->text();
}
int NameEditDialog::formattedNameType() const
{
return mFormattedNameCombo->currentItem();
}
bool NameEditDialog::changed() const
{
return mChanged;
}
QString NameEditDialog::formattedName( const KABC::Addressee &addr, int type )
{
QString retval;
switch ( type ) {
case SimpleName:
retval = addr.givenName() + " " + addr.familyName();
break;
case FullName:
retval =addr.prefix() + " " + addr.givenName() + " " +
addr.additionalName() + " " + addr.familyName() + " " +
addr.suffix();
break;
case ReverseName:
- retval = addr.familyName() + ", " + addr.givenName();
+ if ( !addr.familyName().isEmpty() ) {
+ retval = addr.familyName();
+ if ( !addr.givenName().isEmpty() )
+ retval += ", " + addr.givenName();
+ } else
+ retval = addr.givenName();
break;
default:
return "";
break;
}
return retval.stripWhiteSpace ();
}
void NameEditDialog::parseBoxChanged( bool value )
{
//AddresseeConfig::instance()->setUid( addr.uid() );
AddresseeConfig::instance()->setAutomaticNameParsing( value );
}
void NameEditDialog::typeChanged( int pos )
{
mFormattedNameEdit->setEnabled( pos == 0 );
}
void NameEditDialog::modified()
{
mChanged = true;
}
void NameEditDialog::updateTypeCombo()
{
KABC::Addressee addr;
addr.setPrefix( mPrefixCombo->currentText() );
addr.setGivenName( mGivenNameEdit->text() );
addr.setAdditionalName( mAdditionalNameEdit->text() );
addr.setFamilyName( mFamilyNameEdit->text() );
addr.setSuffix( mSuffixCombo->currentText() );
int pos = mFormattedNameCombo->currentItem();
mFormattedNameCombo->clear();
mFormattedNameCombo->insertItem( i18n( "Custom" ) );
mFormattedNameCombo->insertItem( formattedName( addr, SimpleName ) );
mFormattedNameCombo->insertItem( formattedName( addr, FullName ) );
mFormattedNameCombo->insertItem( formattedName( addr, ReverseName ) );
mFormattedNameCombo->setCurrentItem( pos );
}
void NameEditDialog::slotHelp()
{
#ifndef KAB_EMBEDDED
kapp->invokeHelp( "managing-contacts-automatic-nameparsing" );
#else //KAB_EMBEDDED
qDebug("NameEditDialog::slotHelp Help is not supported yet");
#endif //KAB_EMBEDDED
}
#ifndef KAB_EMBEDDED
#include "nameeditdialog.moc"
#endif //KAB_EMBEDDED