26 #include <tqlistbox.h>
27 #include <tqlistview.h>
28 #include <tqtooltip.h>
29 #include <tqpushbutton.h>
30 #include <tqcheckbox.h>
32 #include <tqwhatsthis.h>
34 #include <tdeaccelmanager.h>
35 #include <tdeapplication.h>
36 #include <kbuttonbox.h>
37 #include <tdeconfig.h>
38 #include <klineedit.h>
39 #include <tdelistview.h>
40 #include <kcombobox.h>
41 #include <tdelocale.h>
43 #include <kiconloader.h>
44 #include <tdemessagebox.h>
46 #include "nameeditdialog.h"
48 NameEditDialog::NameEditDialog(
const TDEABC::Addressee &addr,
int type,
49 bool readOnly, TQWidget *parent,
const char *name )
50 : KDialogBase( Plain, i18n(
"Edit Contact Name" ), Help | Ok | Cancel,
51 Ok, parent, name, true ), mAddressee( addr )
53 TQWidget *page = plainPage();
54 TQGridLayout *layout =
new TQGridLayout( page );
55 layout->setSpacing( spacingHint() );
56 layout->addColSpacing( 2, 100 );
59 label =
new TQLabel( i18n(
"Honorific prefixes:" ), page );
60 layout->addWidget( label, 0, 0 );
61 mPrefixCombo =
new KComboBox( page );
62 mPrefixCombo->setDuplicatesEnabled(
false );
63 mPrefixCombo->setEditable(
true );
64 mPrefixCombo->setEnabled( !readOnly );
65 label->setBuddy( mPrefixCombo );
66 layout->addMultiCellWidget( mPrefixCombo, 0, 0, 1, 2 );
68 TQWhatsThis::add( mPrefixCombo, i18n(
"The predefined honorific prefixes can be extended in the settings dialog." ) );
70 label =
new TQLabel( i18n(
"Given name:" ), page );
71 layout->addWidget( label, 1, 0 );
72 mGivenNameEdit =
new KLineEdit( page );
73 mGivenNameEdit->setReadOnly( readOnly );
74 label->setBuddy( mGivenNameEdit );
75 layout->addMultiCellWidget( mGivenNameEdit, 1, 1, 1, 2 );
77 label =
new TQLabel( i18n(
"Additional names:" ), page );
78 layout->addWidget( label, 2, 0 );
79 mAdditionalNameEdit =
new KLineEdit( page );
80 mAdditionalNameEdit->setReadOnly( readOnly );
81 label->setBuddy( mAdditionalNameEdit );
82 layout->addMultiCellWidget( mAdditionalNameEdit, 2, 2, 1, 2 );
84 label =
new TQLabel( i18n(
"Family names:" ), page );
85 layout->addWidget( label, 3, 0 );
86 mFamilyNameEdit =
new KLineEdit( page );
87 mFamilyNameEdit->setReadOnly( readOnly );
88 label->setBuddy( mFamilyNameEdit );
89 layout->addMultiCellWidget( mFamilyNameEdit, 3, 3, 1, 2 );
91 label =
new TQLabel( i18n(
"Honorific suffixes:" ), page );
92 layout->addWidget( label, 4, 0 );
93 mSuffixCombo =
new KComboBox( page );
94 mSuffixCombo->setDuplicatesEnabled(
false );
95 mSuffixCombo->setEditable(
true );
96 mSuffixCombo->setEnabled( !readOnly );
97 label->setBuddy( mSuffixCombo );
98 layout->addMultiCellWidget( mSuffixCombo, 4, 4, 1, 2 );
100 TQWhatsThis::add( mSuffixCombo, i18n(
"The predefined honorific suffixes can be extended in the settings dialog." ) );
102 label =
new TQLabel( i18n(
"Formatted name:" ), page );
103 layout->addWidget( label, 5, 0 );
105 mFormattedNameCombo =
new KComboBox( page );
106 mFormattedNameCombo->setEnabled( !readOnly );
107 layout->addWidget( mFormattedNameCombo, 5, 1 );
108 connect( mFormattedNameCombo, TQ_SIGNAL( activated(
int ) ), TQ_SLOT( typeChanged(
int ) ) );
110 mFormattedNameEdit =
new KLineEdit( page );
111 mFormattedNameEdit->setEnabled( type == CustomName && !readOnly );
112 layout->addWidget( mFormattedNameEdit, 5, 2 );
114 mParseBox =
new TQCheckBox( i18n(
"Parse name automatically" ), page );
115 mParseBox->setEnabled( !readOnly );
116 connect( mParseBox, TQ_SIGNAL( toggled(
bool) ), TQ_SLOT( parseBoxChanged(
bool) ) );
117 connect( mParseBox, TQ_SIGNAL( toggled(
bool) ), TQ_SLOT( modified() ) );
118 layout->addMultiCellWidget( mParseBox, 6, 6, 0, 1 );
121 mFamilyNameEdit->setText( addr.familyName() );
122 mGivenNameEdit->setText( addr.givenName() );
123 mAdditionalNameEdit->setText( addr.additionalName() );
124 mFormattedNameEdit->setText( addr.formattedName() );
127 TDEConfig config(
"tdeabcrc" );
128 config.setGroup(
"General" );
132 sTitle += i18n(
"Dr." );
133 sTitle += i18n(
"Miss" );
134 sTitle += i18n(
"Mr." );
135 sTitle += i18n(
"Mrs." );
136 sTitle += i18n(
"Ms." );
137 sTitle += i18n(
"Prof." );
138 sTitle += config.readListEntry(
"Prefixes" );
141 TQStringList sSuffix;
143 sSuffix += i18n(
"I" );
144 sSuffix += i18n(
"II" );
145 sSuffix += i18n(
"III" );
146 sSuffix += i18n(
"Jr." );
147 sSuffix += i18n(
"Sr." );
148 sSuffix += config.readListEntry(
"Suffixes" );
151 mPrefixCombo->insertStringList( sTitle );
152 mSuffixCombo->insertStringList( sSuffix );
154 mPrefixCombo->setCurrentText( addr.prefix() );
155 mSuffixCombo->setCurrentText( addr.suffix() );
157 mAddresseeConfig.setAddressee( addr );
158 mParseBox->setChecked( mAddresseeConfig.automaticNameParsing() );
160 TDEAcceleratorManager::manage(
this );
162 connect( mPrefixCombo, TQ_SIGNAL( textChanged(
const TQString& ) ),
163 this, TQ_SLOT( modified() ) );
164 connect( mGivenNameEdit, TQ_SIGNAL( textChanged(
const TQString& ) ),
165 this, TQ_SLOT( modified() ) );
166 connect( mAdditionalNameEdit, TQ_SIGNAL( textChanged(
const TQString& ) ),
167 this, TQ_SLOT( modified() ) );
168 connect( mFamilyNameEdit, TQ_SIGNAL( textChanged(
const TQString& ) ),
169 this, TQ_SLOT( modified() ) );
170 connect( mSuffixCombo, TQ_SIGNAL( textChanged(
const TQString& ) ),
171 this, TQ_SLOT( modified() ) );
172 connect( mFormattedNameCombo, TQ_SIGNAL( activated(
int ) ),
173 this, TQ_SLOT( modified() ) );
174 connect( mFormattedNameCombo, TQ_SIGNAL( activated(
int ) ),
175 this, TQ_SLOT( formattedNameTypeChanged() ) );
176 connect( mFormattedNameEdit, TQ_SIGNAL( textChanged(
const TQString& ) ),
177 this, TQ_SLOT( modified() ) );
178 connect( mFormattedNameEdit, TQ_SIGNAL( textChanged(
const TQString& ) ),
179 this, TQ_SLOT( formattedNameChanged(
const TQString& ) ) );
182 mFormattedNameCombo->setCurrentItem( type );
183 mPrefixCombo->lineEdit()->setFocus();
187 NameEditDialog::~NameEditDialog()
191 TQString NameEditDialog::familyName()
const
193 return mFamilyNameEdit->text();
196 TQString NameEditDialog::givenName()
const
198 return mGivenNameEdit->text();
201 TQString NameEditDialog::prefix()
const
203 return mPrefixCombo->currentText();
206 TQString NameEditDialog::suffix()
const
208 return mSuffixCombo->currentText();
211 TQString NameEditDialog::additionalName()
const
213 return mAdditionalNameEdit->text();
216 TQString NameEditDialog::customFormattedName()
const
218 return mFormattedNameEdit->text();
221 int NameEditDialog::formattedNameType()
const
223 return mFormattedNameCombo->currentItem();
226 bool NameEditDialog::changed()
const
231 void NameEditDialog::formattedNameTypeChanged()
235 if ( formattedNameType() == CustomName )
236 name = mCustomFormattedName;
238 TDEABC::Addressee addr;
239 addr.setPrefix( prefix() );
240 addr.setFamilyName( familyName() );
241 addr.setAdditionalName( additionalName() );
242 addr.setGivenName( givenName() );
243 addr.setSuffix( suffix() );
244 addr.setOrganization( mAddressee.organization() );
246 name = formattedName( addr, formattedNameType() );
249 mFormattedNameEdit->setText( name );
252 TQString NameEditDialog::formattedName(
const TDEABC::Addressee &addr,
int type )
258 name = addr.givenName() +
" " + addr.familyName();
261 name = addr.assembledName();
263 case ReverseNameWithComma:
264 name = addr.familyName() +
", " + addr.givenName();
267 name = addr.familyName() +
" " + addr.givenName();
270 name = addr.organization();
277 return name.simplifyWhiteSpace();
280 void NameEditDialog::parseBoxChanged(
bool value )
282 mAddresseeConfig.setAutomaticNameParsing( value );
285 void NameEditDialog::typeChanged(
int pos )
287 mFormattedNameEdit->setEnabled( pos == 0 );
290 void NameEditDialog::formattedNameChanged(
const TQString &name )
292 if ( formattedNameType() == CustomName )
293 mCustomFormattedName = name;
296 void NameEditDialog::modified()
301 void NameEditDialog::initTypeCombo()
303 int pos = mFormattedNameCombo->currentItem();
305 mFormattedNameCombo->clear();
306 mFormattedNameCombo->insertItem( i18n(
"Custom" ) );
307 mFormattedNameCombo->insertItem( i18n(
"Simple Name" ) );
308 mFormattedNameCombo->insertItem( i18n(
"Full Name" ) );
309 mFormattedNameCombo->insertItem( i18n(
"Reverse Name with Comma" ) );
310 mFormattedNameCombo->insertItem( i18n(
"Reverse Name" ) );
311 mFormattedNameCombo->insertItem( i18n(
"Organization" ) );
313 mFormattedNameCombo->setCurrentItem( pos );
316 void NameEditDialog::slotHelp()
318 kapp->invokeHelp(
"managing-contacts-automatic-nameparsing" );
321 #include "nameeditdialog.moc"