summaryrefslogtreecommitdiffabout
path: root/kaddressbook/nameeditdialog.cpp
Unidiff
Diffstat (limited to 'kaddressbook/nameeditdialog.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/nameeditdialog.cpp296
1 files changed, 296 insertions, 0 deletions
diff --git a/kaddressbook/nameeditdialog.cpp b/kaddressbook/nameeditdialog.cpp
new file mode 100644
index 0000000..fb7eb22
--- a/dev/null
+++ b/kaddressbook/nameeditdialog.cpp
@@ -0,0 +1,296 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution.
22*/
23
24#include <qlayout.h>
25#include <qlabel.h>
26#include <qlistbox.h>
27#include <qlistview.h>
28#include <qtooltip.h>
29#include <qpushbutton.h>
30#include <qcheckbox.h>
31#include <qstring.h>
32
33#ifndef KAB_EMBEDDED
34#include <kaccelmanager.h>
35#else //KAB_EMBEDDED
36#include <kstandarddirs.h>
37#endif //KAB_EMBEDDED
38
39#include <kapplication.h>
40#include <kbuttonbox.h>
41#include <kconfig.h>
42#include <klineedit.h>
43#include <klistview.h>
44#include <kcombobox.h>
45#include <klocale.h>
46#include <kglobal.h>
47#include <kdebug.h>
48#include <kiconloader.h>
49#include <kmessagebox.h>
50
51#include "nameeditdialog.h"
52
53NameEditDialog::NameEditDialog( const KABC::Addressee &addr, int type,
54 QWidget *parent, const char *name )
55 : KDialogBase( Plain, i18n( "Edit Contact Name" ), Help | Ok | Cancel,
56 Ok, parent, name, true )
57{
58
59 QWidget *page = plainPage();
60 QGridLayout *layout = new QGridLayout( page, 5, 3 );
61 layout->setSpacing( spacingHint() );
62 layout->addColSpacing( 2, 100 );
63 QLabel *label;
64
65 label = new QLabel( i18n( "Honorific prefixes:" ), page );
66 layout->addWidget( label, 0, 0 );
67 mPrefixCombo = new KComboBox( page );
68 mPrefixCombo->setDuplicatesEnabled( false );
69 mPrefixCombo->setEditable( true );
70 label->setBuddy( mPrefixCombo );
71 layout->addMultiCellWidget( mPrefixCombo, 0, 0, 1, 2 );
72
73 label = new QLabel( i18n( "Given name:" ), page );
74 layout->addWidget( label, 1, 0 );
75 mGivenNameEdit = new KLineEdit( page );
76 label->setBuddy( mGivenNameEdit );
77 layout->addMultiCellWidget( mGivenNameEdit, 1, 1, 1, 2 );
78
79 label = new QLabel( i18n( "Additional names:" ), page );
80 layout->addWidget( label, 2, 0 );
81 mAdditionalNameEdit = new KLineEdit( page );
82 label->setBuddy( mAdditionalNameEdit );
83 layout->addMultiCellWidget( mAdditionalNameEdit, 2, 2, 1, 2 );
84
85 label = new QLabel( i18n( "Family names:" ), page );
86 layout->addWidget( label, 3, 0 );
87 mFamilyNameEdit = new KLineEdit( page );
88 label->setBuddy( mFamilyNameEdit );
89 layout->addMultiCellWidget( mFamilyNameEdit, 3, 3, 1, 2 );
90
91 label = new QLabel( i18n( "Honorific suffixes:" ), page );
92 layout->addWidget( label, 4, 0 );
93 mSuffixCombo = new KComboBox( page );
94 mSuffixCombo->setDuplicatesEnabled( false );
95 mSuffixCombo->setEditable( true );
96 label->setBuddy( mSuffixCombo );
97 layout->addMultiCellWidget( mSuffixCombo, 4, 4, 1, 2 );
98
99 mFormattedNameCombo = new KComboBox( page );
100 mFormattedNameCombo->setMaximumWidth(100);
101
102 layout->addMultiCellWidget( mFormattedNameCombo, 5, 5, 0, 0 );
103 connect( mFormattedNameCombo, SIGNAL( activated( int ) ), SLOT( typeChanged( int ) ) );
104
105 mFormattedNameEdit = new KLineEdit( page );
106 mFormattedNameEdit->setEnabled( type == CustomName );
107 layout->addMultiCellWidget( mFormattedNameEdit, 5, 5, 1, 2 );
108
109 mParseBox = new QCheckBox( i18n( "Parse name automatically" ), page );
110 connect( mParseBox, SIGNAL( toggled(bool) ), SLOT( parseBoxChanged(bool) ) );
111 connect( mParseBox, SIGNAL( toggled(bool) ), SLOT( modified() ) );
112 layout->addMultiCellWidget( mParseBox, 6, 6, 0, 1 );
113
114 // Fill in the values
115 mFamilyNameEdit->setText( addr.familyName() );
116 mGivenNameEdit->setText( addr.givenName() );
117 mAdditionalNameEdit->setText( addr.additionalName() );
118 mFormattedNameEdit->setText( addr.formattedName() );
119
120 // Prefix and suffix combos
121//US KConfig config( "kabcrc" );
122 KConfig config( locateLocal("config", "kabcrc") );
123 config.setGroup( "General" );
124
125 QStringList sTitle;
126 sTitle += i18n( "Dr." );
127 sTitle += i18n( "Miss" );
128 sTitle += i18n( "Mr." );
129 sTitle += i18n( "Mrs." );
130 sTitle += i18n( "Ms." );
131 sTitle += i18n( "Prof." );
132 sTitle += config.readListEntry( "Prefixes" );
133 sTitle.sort();
134
135 QStringList sSuffix;
136 sSuffix += i18n( "I" );
137 sSuffix += i18n( "II" );
138 sSuffix += i18n( "III" );
139 sSuffix += i18n( "Jr." );
140 sSuffix += i18n( "Sr." );
141 sSuffix += config.readListEntry( "Suffixes" );
142 sSuffix.sort();
143
144 mPrefixCombo->insertStringList( sTitle );
145 mSuffixCombo->insertStringList( sSuffix );
146
147#ifndef KAB_EMBEDDED
148 mPrefixCombo->setCurrentText( addr.prefix() );
149 mSuffixCombo->setCurrentText( addr.suffix() );
150#else //KAB_EMBEDDED
151 mPrefixCombo->setEditText( addr.prefix() );
152 mSuffixCombo->setEditText( addr.suffix() );
153#endif //KAB_EMBEDDED
154
155 AddresseeConfig::instance()->setUid( addr.uid() );
156 mParseBox->setChecked( AddresseeConfig::instance()->automaticNameParsing() );
157
158#ifndef KAB_EMBEDDED
159 KAcceleratorManager::manage( this );
160#endif //KAB_EMBEDDED
161
162 connect( mPrefixCombo, SIGNAL( textChanged( const QString& ) ), SLOT( modified() ) );
163 connect( mPrefixCombo, SIGNAL( textChanged( const QString& ) ), SLOT( updateTypeCombo() ) );
164 connect( mGivenNameEdit, SIGNAL( textChanged( const QString& ) ), SLOT( modified() ) );
165 connect( mGivenNameEdit, SIGNAL( textChanged( const QString& ) ), SLOT( updateTypeCombo() ) );
166 connect( mAdditionalNameEdit, SIGNAL( textChanged( const QString& ) ), SLOT( modified() ) );
167 connect( mAdditionalNameEdit, SIGNAL( textChanged( const QString& ) ), SLOT( updateTypeCombo() ) );
168 connect( mFamilyNameEdit, SIGNAL( textChanged( const QString& ) ), SLOT( modified() ) );
169 connect( mFamilyNameEdit, SIGNAL( textChanged( const QString& ) ), SLOT( updateTypeCombo() ) );
170 connect( mSuffixCombo, SIGNAL( textChanged( const QString& ) ), SLOT( modified() ) );
171 connect( mSuffixCombo, SIGNAL( textChanged( const QString& ) ), SLOT( updateTypeCombo() ) );
172 connect( mFormattedNameCombo, SIGNAL( activated( int ) ), SLOT( modified() ) );
173 connect( mFormattedNameEdit, SIGNAL( textChanged( const QString& ) ), SLOT( modified() ) );
174
175 updateTypeCombo();
176 mFormattedNameCombo->setCurrentItem( type );
177
178#ifdef KAB_EMBEDDED
179 resize( KMIN(KGlobal::getDesktopWidth()-10, 490), KMIN(KGlobal::getDesktopHeight()-50, 300));
180#endif //KAB_EMBEDDED
181
182 mChanged = false;
183}
184
185NameEditDialog::~NameEditDialog()
186{
187}
188
189QString NameEditDialog::familyName() const
190{
191 return mFamilyNameEdit->text();
192}
193
194QString NameEditDialog::givenName() const
195{
196 return mGivenNameEdit->text();
197}
198
199QString NameEditDialog::prefix() const
200{
201 return mPrefixCombo->currentText();
202}
203
204QString NameEditDialog::suffix() const
205{
206 return mSuffixCombo->currentText();
207}
208
209QString NameEditDialog::additionalName() const
210{
211 return mAdditionalNameEdit->text();
212}
213
214QString NameEditDialog::customFormattedName() const
215{
216 return mFormattedNameEdit->text();
217}
218
219int NameEditDialog::formattedNameType() const
220{
221 return mFormattedNameCombo->currentItem();
222}
223
224bool NameEditDialog::changed() const
225{
226 return mChanged;
227}
228
229QString NameEditDialog::formattedName( const KABC::Addressee &addr, int type )
230{
231 switch ( type ) {
232 case SimpleName:
233 return addr.givenName() + " " + addr.familyName();
234 break;
235 case FullName:
236 return addr.prefix() + " " + addr.givenName() + " " +
237 addr.additionalName() + " " + addr.familyName() + " " +
238 addr.suffix();
239 break;
240 case ReverseName:
241 return addr.familyName() + ", " + addr.givenName();
242 break;
243 default:
244 return "";
245 break;
246 }
247}
248
249void NameEditDialog::parseBoxChanged( bool value )
250{
251 //AddresseeConfig::instance()->setUid( addr.uid() );
252 AddresseeConfig::instance()->setAutomaticNameParsing( value );
253}
254
255void NameEditDialog::typeChanged( int pos )
256{
257 mFormattedNameEdit->setEnabled( pos == 0 );
258}
259
260void NameEditDialog::modified()
261{
262 mChanged = true;
263}
264
265void NameEditDialog::updateTypeCombo()
266{
267 KABC::Addressee addr;
268 addr.setPrefix( mPrefixCombo->currentText() );
269 addr.setGivenName( mGivenNameEdit->text() );
270 addr.setAdditionalName( mAdditionalNameEdit->text() );
271 addr.setFamilyName( mFamilyNameEdit->text() );
272 addr.setSuffix( mSuffixCombo->currentText() );
273
274 int pos = mFormattedNameCombo->currentItem();
275
276 mFormattedNameCombo->clear();
277 mFormattedNameCombo->insertItem( i18n( "Custom" ) );
278 mFormattedNameCombo->insertItem( formattedName( addr, SimpleName ) );
279 mFormattedNameCombo->insertItem( formattedName( addr, FullName ) );
280 mFormattedNameCombo->insertItem( formattedName( addr, ReverseName ) );
281
282 mFormattedNameCombo->setCurrentItem( pos );
283}
284
285void NameEditDialog::slotHelp()
286{
287#ifndef KAB_EMBEDDED
288 kapp->invokeHelp( "managing-contacts-automatic-nameparsing" );
289#else //KAB_EMBEDDED
290qDebug("NameEditDialog::slotHelp Help is not supported yet");
291#endif //KAB_EMBEDDED
292}
293
294#ifndef KAB_EMBEDDED
295#include "nameeditdialog.moc"
296#endif //KAB_EMBEDDED