2
This file is part of Akonadi Contact.
4
Copyright (c) 2010 Tobias Koenig <tokoe@kde.org>
6
This library is free software; you can redistribute it and/or modify it
7
under the terms of the GNU Library General Public License as published by
8
the Free Software Foundation; either version 2 of the License, or (at your
9
option) any later version.
11
This library is distributed in the hope that it will be useful, but WITHOUT
12
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
14
License for more details.
16
You should have received a copy of the GNU Library General Public License
17
along with this library; see the file COPYING.LIB. If not, write to the
18
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23
#include "namepartseditwidget.h"
25
#include <QtGui/QFormLayout>
27
#include <kcombobox.h>
28
#include <klineedit.h>
31
NamePartsEditWidget::NamePartsEditWidget( QWidget *parent )
34
QFormLayout *layout = new QFormLayout( this );
35
layout->setLabelAlignment( Qt::AlignLeft );
37
mPrefixCombo = new KComboBox( this );
38
mPrefixCombo->setDuplicatesEnabled( false );
40
mPrefixCombo->setEditable( true );
43
mGivenNameEdit = new KLineEdit( this );
45
mAdditionalNameEdit = new KLineEdit( this );
47
mFamilyNameEdit = new KLineEdit( this );
49
mSuffixCombo = new KComboBox( this );
50
mSuffixCombo->setDuplicatesEnabled( false );
52
mSuffixCombo->setEditable( true );
55
layout->addRow( i18n( "Honorific prefixes:" ), mPrefixCombo );
56
layout->addRow( i18n( "Given name:" ), mGivenNameEdit );
57
layout->addRow( i18n( "Additional names:" ), mAdditionalNameEdit );
58
layout->addRow( i18n( "Family names:" ), mFamilyNameEdit );
59
layout->addRow( i18n( "Honorific suffixes:" ), mSuffixCombo );
61
QStringList prefixList;
62
prefixList += QString();
63
prefixList += i18n( "Dr." );
64
prefixList += i18n( "Miss" );
65
prefixList += i18n( "Mr." );
66
prefixList += i18n( "Mrs." );
67
prefixList += i18n( "Ms." );
68
prefixList += i18n( "Prof." );
71
QStringList suffixList;
72
suffixList += QString();
73
suffixList += i18n( "I" );
74
suffixList += i18n( "II" );
75
suffixList += i18n( "III" );
76
suffixList += i18n( "Jr." );
77
suffixList += i18n( "Sr." );
80
mPrefixCombo->addItems( prefixList );
81
mSuffixCombo->addItems( suffixList );
84
mPrefixCombo->lineEdit()->setFocus();
87
connect( mSuffixCombo, SIGNAL( activated( int ) ), this, SLOT( inputChanged() ) );
88
connect( mSuffixCombo, SIGNAL( editTextChanged( const QString& ) ), this, SLOT( inputChanged() ) );
89
connect( mPrefixCombo, SIGNAL( activated( int ) ), this, SLOT( inputChanged() ) );
90
connect( mPrefixCombo, SIGNAL( editTextChanged( const QString& ) ), this, SLOT( inputChanged() ) );
91
connect( mFamilyNameEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( inputChanged() ) );
92
connect( mGivenNameEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( inputChanged() ) );
93
connect( mAdditionalNameEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( inputChanged() ) );
96
void NamePartsEditWidget::loadContact( const KABC::Addressee &contact )
100
disconnect( mSuffixCombo, SIGNAL( activated( int ) ), this, SLOT( inputChanged() ) );
101
disconnect( mSuffixCombo, SIGNAL( editTextChanged( const QString& ) ), this, SLOT( inputChanged() ) );
102
disconnect( mPrefixCombo, SIGNAL( activated( int ) ), this, SLOT( inputChanged() ) );
103
disconnect( mPrefixCombo, SIGNAL( editTextChanged( const QString& ) ), this, SLOT( inputChanged() ) );
104
disconnect( mFamilyNameEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( inputChanged() ) );
105
disconnect( mGivenNameEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( inputChanged() ) );
106
disconnect( mAdditionalNameEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( inputChanged() ) );
108
mPrefixCombo->setItemText( mPrefixCombo->currentIndex(), mContact.prefix() );
109
mGivenNameEdit->setText( mContact.givenName() );
110
mAdditionalNameEdit->setText( mContact.additionalName() );
111
mFamilyNameEdit->setText( mContact.familyName() );
112
mSuffixCombo->setItemText( mSuffixCombo->currentIndex(), mContact.suffix() );
114
connect( mSuffixCombo, SIGNAL( activated( int ) ), this, SLOT( inputChanged() ) );
115
connect( mSuffixCombo, SIGNAL( editTextChanged( const QString& ) ), this, SLOT( inputChanged() ) );
116
connect( mPrefixCombo, SIGNAL( activated( int ) ), this, SLOT( inputChanged() ) );
117
connect( mPrefixCombo, SIGNAL( editTextChanged( const QString& ) ), this, SLOT( inputChanged() ) );
118
connect( mFamilyNameEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( inputChanged() ) );
119
connect( mGivenNameEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( inputChanged() ) );
120
connect( mAdditionalNameEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( inputChanged() ) );
123
void NamePartsEditWidget::storeContact( KABC::Addressee &contact ) const
125
contact.setPrefix( mPrefixCombo->currentText() );
126
contact.setGivenName( mGivenNameEdit->text() );
127
contact.setAdditionalName( mAdditionalNameEdit->text() );
128
contact.setFamilyName( mFamilyNameEdit->text() );
129
contact.setSuffix( mSuffixCombo->currentText() );
132
void NamePartsEditWidget::inputChanged()
134
storeContact( mContact );
135
emit nameChanged( mContact );