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