TDE personal information management applications
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

nameeditdialog.cpp 9.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. /*
  2. This file is part of KAddressBook.
  3. Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  15. As a special exception, permission is given to link this program
  16. with any edition of TQt, and distribute the resulting executable,
  17. without including the source code for TQt in the source distribution.
  18. */
  19. #include <tqlayout.h>
  20. #include <tqlabel.h>
  21. #include <tqlistbox.h>
  22. #include <tqlistview.h>
  23. #include <tqtooltip.h>
  24. #include <tqpushbutton.h>
  25. #include <tqcheckbox.h>
  26. #include <tqstring.h>
  27. #include <tqwhatsthis.h>
  28. #include <kaccelmanager.h>
  29. #include <kapplication.h>
  30. #include <kbuttonbox.h>
  31. #include <tdeconfig.h>
  32. #include <klineedit.h>
  33. #include <klistview.h>
  34. #include <kcombobox.h>
  35. #include <klocale.h>
  36. #include <kdebug.h>
  37. #include <kiconloader.h>
  38. #include <kmessagebox.h>
  39. #include "nameeditdialog.h"
  40. NameEditDialog::NameEditDialog( const KABC::Addressee &addr, int type,
  41. bool readOnly, TQWidget *parent, const char *name )
  42. : KDialogBase( Plain, i18n( "Edit Contact Name" ), Help | Ok | Cancel,
  43. Ok, parent, name, true ), mAddressee( addr )
  44. {
  45. TQWidget *page = plainPage();
  46. TQGridLayout *layout = new TQGridLayout( page );
  47. layout->setSpacing( spacingHint() );
  48. layout->addColSpacing( 2, 100 );
  49. TQLabel *label;
  50. label = new TQLabel( i18n( "Honorific prefixes:" ), page );
  51. layout->addWidget( label, 0, 0 );
  52. mPrefixCombo = new KComboBox( page );
  53. mPrefixCombo->setDuplicatesEnabled( false );
  54. mPrefixCombo->setEditable( true );
  55. mPrefixCombo->setEnabled( !readOnly );
  56. label->setBuddy( mPrefixCombo );
  57. layout->addMultiCellWidget( mPrefixCombo, 0, 0, 1, 2 );
  58. TQWhatsThis::add( mPrefixCombo, i18n( "The predefined honorific prefixes can be extended in the settings dialog." ) );
  59. label = new TQLabel( i18n( "Given name:" ), page );
  60. layout->addWidget( label, 1, 0 );
  61. mGivenNameEdit = new KLineEdit( page );
  62. mGivenNameEdit->setReadOnly( readOnly );
  63. label->setBuddy( mGivenNameEdit );
  64. layout->addMultiCellWidget( mGivenNameEdit, 1, 1, 1, 2 );
  65. label = new TQLabel( i18n( "Additional names:" ), page );
  66. layout->addWidget( label, 2, 0 );
  67. mAdditionalNameEdit = new KLineEdit( page );
  68. mAdditionalNameEdit->setReadOnly( readOnly );
  69. label->setBuddy( mAdditionalNameEdit );
  70. layout->addMultiCellWidget( mAdditionalNameEdit, 2, 2, 1, 2 );
  71. label = new TQLabel( i18n( "Family names:" ), page );
  72. layout->addWidget( label, 3, 0 );
  73. mFamilyNameEdit = new KLineEdit( page );
  74. mFamilyNameEdit->setReadOnly( readOnly );
  75. label->setBuddy( mFamilyNameEdit );
  76. layout->addMultiCellWidget( mFamilyNameEdit, 3, 3, 1, 2 );
  77. label = new TQLabel( i18n( "Honorific suffixes:" ), page );
  78. layout->addWidget( label, 4, 0 );
  79. mSuffixCombo = new KComboBox( page );
  80. mSuffixCombo->setDuplicatesEnabled( false );
  81. mSuffixCombo->setEditable( true );
  82. mSuffixCombo->setEnabled( !readOnly );
  83. label->setBuddy( mSuffixCombo );
  84. layout->addMultiCellWidget( mSuffixCombo, 4, 4, 1, 2 );
  85. TQWhatsThis::add( mSuffixCombo, i18n( "The predefined honorific suffixes can be extended in the settings dialog." ) );
  86. label = new TQLabel( i18n( "Formatted name:" ), page );
  87. layout->addWidget( label, 5, 0 );
  88. mFormattedNameCombo = new KComboBox( page );
  89. mFormattedNameCombo->setEnabled( !readOnly );
  90. layout->addWidget( mFormattedNameCombo, 5, 1 );
  91. connect( mFormattedNameCombo, TQT_SIGNAL( activated( int ) ), TQT_SLOT( typeChanged( int ) ) );
  92. mFormattedNameEdit = new KLineEdit( page );
  93. mFormattedNameEdit->setEnabled( type == CustomName && !readOnly );
  94. layout->addWidget( mFormattedNameEdit, 5, 2 );
  95. mParseBox = new TQCheckBox( i18n( "Parse name automatically" ), page );
  96. mParseBox->setEnabled( !readOnly );
  97. connect( mParseBox, TQT_SIGNAL( toggled(bool) ), TQT_SLOT( parseBoxChanged(bool) ) );
  98. connect( mParseBox, TQT_SIGNAL( toggled(bool) ), TQT_SLOT( modified() ) );
  99. layout->addMultiCellWidget( mParseBox, 6, 6, 0, 1 );
  100. // Fill in the values
  101. mFamilyNameEdit->setText( addr.familyName() );
  102. mGivenNameEdit->setText( addr.givenName() );
  103. mAdditionalNameEdit->setText( addr.additionalName() );
  104. mFormattedNameEdit->setText( addr.formattedName() );
  105. // Prefix and suffix combos
  106. TDEConfig config( "kabcrc" );
  107. config.setGroup( "General" );
  108. TQStringList sTitle;
  109. sTitle += "";
  110. sTitle += i18n( "Dr." );
  111. sTitle += i18n( "Miss" );
  112. sTitle += i18n( "Mr." );
  113. sTitle += i18n( "Mrs." );
  114. sTitle += i18n( "Ms." );
  115. sTitle += i18n( "Prof." );
  116. sTitle += config.readListEntry( "Prefixes" );
  117. sTitle.sort();
  118. TQStringList sSuffix;
  119. sSuffix += "";
  120. sSuffix += i18n( "I" );
  121. sSuffix += i18n( "II" );
  122. sSuffix += i18n( "III" );
  123. sSuffix += i18n( "Jr." );
  124. sSuffix += i18n( "Sr." );
  125. sSuffix += config.readListEntry( "Suffixes" );
  126. sSuffix.sort();
  127. mPrefixCombo->insertStringList( sTitle );
  128. mSuffixCombo->insertStringList( sSuffix );
  129. mPrefixCombo->setCurrentText( addr.prefix() );
  130. mSuffixCombo->setCurrentText( addr.suffix() );
  131. mAddresseeConfig.setAddressee( addr );
  132. mParseBox->setChecked( mAddresseeConfig.automaticNameParsing() );
  133. KAcceleratorManager::manage( this );
  134. connect( mPrefixCombo, TQT_SIGNAL( textChanged( const TQString& ) ),
  135. this, TQT_SLOT( modified() ) );
  136. connect( mGivenNameEdit, TQT_SIGNAL( textChanged( const TQString& ) ),
  137. this, TQT_SLOT( modified() ) );
  138. connect( mAdditionalNameEdit, TQT_SIGNAL( textChanged( const TQString& ) ),
  139. this, TQT_SLOT( modified() ) );
  140. connect( mFamilyNameEdit, TQT_SIGNAL( textChanged( const TQString& ) ),
  141. this, TQT_SLOT( modified() ) );
  142. connect( mSuffixCombo, TQT_SIGNAL( textChanged( const TQString& ) ),
  143. this, TQT_SLOT( modified() ) );
  144. connect( mFormattedNameCombo, TQT_SIGNAL( activated( int ) ),
  145. this, TQT_SLOT( modified() ) );
  146. connect( mFormattedNameCombo, TQT_SIGNAL( activated( int ) ),
  147. this, TQT_SLOT( formattedNameTypeChanged() ) );
  148. connect( mFormattedNameEdit, TQT_SIGNAL( textChanged( const TQString& ) ),
  149. this, TQT_SLOT( modified() ) );
  150. connect( mFormattedNameEdit, TQT_SIGNAL( textChanged( const TQString& ) ),
  151. this, TQT_SLOT( formattedNameChanged( const TQString& ) ) );
  152. initTypeCombo();
  153. mFormattedNameCombo->setCurrentItem( type );
  154. mPrefixCombo->lineEdit()->setFocus();
  155. mChanged = false;
  156. }
  157. NameEditDialog::~NameEditDialog()
  158. {
  159. }
  160. TQString NameEditDialog::familyName() const
  161. {
  162. return mFamilyNameEdit->text();
  163. }
  164. TQString NameEditDialog::givenName() const
  165. {
  166. return mGivenNameEdit->text();
  167. }
  168. TQString NameEditDialog::prefix() const
  169. {
  170. return mPrefixCombo->currentText();
  171. }
  172. TQString NameEditDialog::suffix() const
  173. {
  174. return mSuffixCombo->currentText();
  175. }
  176. TQString NameEditDialog::additionalName() const
  177. {
  178. return mAdditionalNameEdit->text();
  179. }
  180. TQString NameEditDialog::customFormattedName() const
  181. {
  182. return mFormattedNameEdit->text();
  183. }
  184. int NameEditDialog::formattedNameType() const
  185. {
  186. return mFormattedNameCombo->currentItem();
  187. }
  188. bool NameEditDialog::changed() const
  189. {
  190. return mChanged;
  191. }
  192. void NameEditDialog::formattedNameTypeChanged()
  193. {
  194. TQString name;
  195. if ( formattedNameType() == CustomName )
  196. name = mCustomFormattedName;
  197. else {
  198. KABC::Addressee addr;
  199. addr.setPrefix( prefix() );
  200. addr.setFamilyName( familyName() );
  201. addr.setAdditionalName( additionalName() );
  202. addr.setGivenName( givenName() );
  203. addr.setSuffix( suffix() );
  204. addr.setOrganization( mAddressee.organization() );
  205. name = formattedName( addr, formattedNameType() );
  206. }
  207. mFormattedNameEdit->setText( name );
  208. }
  209. TQString NameEditDialog::formattedName( const KABC::Addressee &addr, int type )
  210. {
  211. TQString name;
  212. switch ( type ) {
  213. case SimpleName:
  214. name = addr.givenName() + " " + addr.familyName();
  215. break;
  216. case FullName:
  217. name = addr.assembledName();
  218. break;
  219. case ReverseNameWithComma:
  220. name = addr.familyName() + ", " + addr.givenName();
  221. break;
  222. case ReverseName:
  223. name = addr.familyName() + " " + addr.givenName();
  224. break;
  225. case Organization:
  226. name = addr.organization();
  227. break;
  228. default:
  229. name = "";
  230. break;
  231. }
  232. return name.simplifyWhiteSpace();
  233. }
  234. void NameEditDialog::parseBoxChanged( bool value )
  235. {
  236. mAddresseeConfig.setAutomaticNameParsing( value );
  237. }
  238. void NameEditDialog::typeChanged( int pos )
  239. {
  240. mFormattedNameEdit->setEnabled( pos == 0 );
  241. }
  242. void NameEditDialog::formattedNameChanged( const TQString &name )
  243. {
  244. if ( formattedNameType() == CustomName )
  245. mCustomFormattedName = name;
  246. }
  247. void NameEditDialog::modified()
  248. {
  249. mChanged = true;
  250. }
  251. void NameEditDialog::initTypeCombo()
  252. {
  253. int pos = mFormattedNameCombo->currentItem();
  254. mFormattedNameCombo->clear();
  255. mFormattedNameCombo->insertItem( i18n( "Custom" ) );
  256. mFormattedNameCombo->insertItem( i18n( "Simple Name" ) );
  257. mFormattedNameCombo->insertItem( i18n( "Full Name" ) );
  258. mFormattedNameCombo->insertItem( i18n( "Reverse Name with Comma" ) );
  259. mFormattedNameCombo->insertItem( i18n( "Reverse Name" ) );
  260. mFormattedNameCombo->insertItem( i18n( "Organization" ) );
  261. mFormattedNameCombo->setCurrentItem( pos );
  262. }
  263. void NameEditDialog::slotHelp()
  264. {
  265. kapp->invokeHelp( "managing-contacts-automatic-nameparsing" );
  266. }
  267. #include "nameeditdialog.moc"