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.

addresseewidget.cpp 6.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /*
  2. This file is part of KAddressBook.
  3. Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
  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 <tqcstring.h>
  20. #include <tqgroupbox.h>
  21. #include <tqlabel.h>
  22. #include <tqlayout.h>
  23. #include <tqlistbox.h>
  24. #include <tqpushbutton.h>
  25. #include <dcopclient.h>
  26. #include <kbuttonbox.h>
  27. #include <kcombobox.h>
  28. #include <tdeconfig.h>
  29. #include <kdialog.h>
  30. #include <kinputdialog.h>
  31. #include <tdelocale.h>
  32. #include <klineedit.h>
  33. #include "addresseewidget.h"
  34. NamePartWidget::NamePartWidget( const TQString &title, const TQString &label,
  35. TQWidget *parent, const char *name )
  36. : TQWidget( parent, name ), mTitle( title ), mLabel( label )
  37. {
  38. TQHBoxLayout *layout = new TQHBoxLayout( this );
  39. TQGroupBox *group = new TQGroupBox( 0, Qt::Vertical, title, this );
  40. TQGridLayout *groupLayout = new TQGridLayout( group->layout(), 2, 2,
  41. KDialog::spacingHint() );
  42. mBox = new TQListBox( group );
  43. connect( mBox, TQT_SIGNAL( selectionChanged( TQListBoxItem* ) ),
  44. TQT_SLOT( selectionChanged( TQListBoxItem* ) ) );
  45. groupLayout->addWidget( mBox, 0, 0 );
  46. KButtonBox *bbox = new KButtonBox( group, Qt::Vertical );
  47. mAddButton = bbox->addButton( i18n( "Add..." ), TQT_TQOBJECT(this), TQT_SLOT( add() ) );
  48. mEditButton = bbox->addButton( i18n( "Edit..." ), TQT_TQOBJECT(this), TQT_SLOT( edit() ) );
  49. mEditButton->setEnabled( false );
  50. mRemoveButton = bbox->addButton( i18n( "Remove" ), TQT_TQOBJECT(this), TQT_SLOT( remove() ) );
  51. mRemoveButton->setEnabled( false );
  52. bbox->layout();
  53. groupLayout->addWidget( bbox, 0, 1 );
  54. layout->addWidget( group );
  55. }
  56. NamePartWidget::~NamePartWidget()
  57. {
  58. }
  59. void NamePartWidget::setNameParts( const TQStringList &list )
  60. {
  61. mBox->clear();
  62. mBox->insertStringList( list );
  63. }
  64. TQStringList NamePartWidget::nameParts() const
  65. {
  66. TQStringList parts;
  67. for ( uint i = 0; i < mBox->count(); ++i )
  68. parts.append( mBox->text( i ) );
  69. return parts;
  70. }
  71. void NamePartWidget::add()
  72. {
  73. bool ok;
  74. TQString namePart = KInputDialog::getText( i18n( "New" ), mLabel,
  75. TQString(), &ok );
  76. if ( ok && !namePart.isEmpty() ) {
  77. mBox->insertItem( namePart );
  78. emit modified();
  79. }
  80. }
  81. void NamePartWidget::edit()
  82. {
  83. bool ok;
  84. int index = mBox->currentItem();
  85. if ( index == -1 )
  86. return;
  87. TQString namePart = KInputDialog::getText( i18n( "Edit" ), mLabel,
  88. mBox->text( index ), &ok );
  89. if ( ok && !namePart.isEmpty() ) {
  90. mBox->changeItem( namePart, index );
  91. emit modified();
  92. }
  93. }
  94. void NamePartWidget::remove()
  95. {
  96. mBox->removeItem( mBox->currentItem() );
  97. if ( mBox->count() == 0 )
  98. selectionChanged( 0 );
  99. emit modified();
  100. }
  101. void NamePartWidget::selectionChanged( TQListBoxItem *item )
  102. {
  103. mEditButton->setEnabled( item != 0 );
  104. mRemoveButton->setEnabled( item != 0 );
  105. }
  106. AddresseeWidget::AddresseeWidget( TQWidget *parent, const char *name )
  107. : TQWidget( parent, name )
  108. {
  109. TQGridLayout *layout = new TQGridLayout( this, 2, 3, KDialog::marginHint(),
  110. KDialog::spacingHint() );
  111. mPrefix = new NamePartWidget( i18n( "Prefixes"), i18n( "Enter prefix:" ), this );
  112. layout->addWidget( mPrefix, 0, 0 );
  113. mInclusion = new NamePartWidget( i18n( "Inclusions"), i18n( "Enter inclusion:" ), this );
  114. layout->addWidget( mInclusion, 0, 1 );
  115. mSuffix = new NamePartWidget( i18n( "Suffixes" ), i18n( "Enter suffix:" ), this );
  116. layout->addWidget( mSuffix, 0, 2 );
  117. TQLabel *label = new TQLabel( i18n( "Default formatted name:" ), this );
  118. layout->addWidget( label, 1, 0 );
  119. mFormattedNameCombo = new KComboBox( this );
  120. mFormattedNameCombo->insertItem( i18n( "Empty" ) );
  121. mFormattedNameCombo->insertItem( i18n( "Simple Name" ) );
  122. mFormattedNameCombo->insertItem( i18n( "Full Name" ) );
  123. mFormattedNameCombo->insertItem( i18n( "Reverse Name with Comma" ) );
  124. mFormattedNameCombo->insertItem( i18n( "Reverse Name" ) );
  125. layout->addMultiCellWidget( mFormattedNameCombo, 1, 1, 1, 2 );
  126. connect( mPrefix, TQT_SIGNAL( modified() ), TQT_SIGNAL( modified() ) );
  127. connect( mInclusion, TQT_SIGNAL( modified() ), TQT_SIGNAL( modified() ) );
  128. connect( mSuffix, TQT_SIGNAL( modified() ), TQT_SIGNAL( modified() ) );
  129. connect( mFormattedNameCombo, TQT_SIGNAL( activated( int ) ), TQT_SIGNAL( modified() ) );
  130. }
  131. AddresseeWidget::~AddresseeWidget()
  132. {
  133. }
  134. void AddresseeWidget::restoreSettings()
  135. {
  136. TDEConfig config( "tdeabcrc" );
  137. config.setGroup( "General" );
  138. mPrefix->setNameParts( config.readListEntry( "Prefixes" ) );
  139. mInclusion->setNameParts( config.readListEntry( "Inclusions" ) );
  140. mSuffix->setNameParts( config.readListEntry( "Suffixes" ) );
  141. TDEConfig cfg( "kaddressbookrc" );
  142. cfg.setGroup( "General" );
  143. mFormattedNameCombo->setCurrentItem( cfg.readNumEntry( "FormattedNameType", 1 ) );
  144. }
  145. void AddresseeWidget::saveSettings()
  146. {
  147. TDEConfig config( "tdeabcrc" );
  148. config.setGroup( "General" );
  149. config.writeEntry( "Prefixes", mPrefix->nameParts() );
  150. config.writeEntry( "Inclusions", mInclusion->nameParts() );
  151. config.writeEntry( "Suffixes", mSuffix->nameParts() );
  152. TDEConfig cfg( "kaddressbookrc" );
  153. cfg.setGroup( "General" );
  154. cfg.writeEntry( "FormattedNameType", mFormattedNameCombo->currentItem() );
  155. DCOPClient *client = DCOPClient::mainClient();
  156. if ( client )
  157. client->emitDCOPSignal( "TDEABC::AddressBookConfig", "changed()", TQByteArray() );
  158. }
  159. #include "addresseewidget.moc"