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.

kabconfigwidget.cpp 8.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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 <tqcheckbox.h>
  20. #include <tqframe.h>
  21. #include <tqgroupbox.h>
  22. #include <tqlabel.h>
  23. #include <tqlayout.h>
  24. #include <tqlineedit.h>
  25. #include <tqpushbutton.h>
  26. #include <tqtabwidget.h>
  27. #include <tqtooltip.h>
  28. #include <tqcombobox.h>
  29. #include <tdeconfig.h>
  30. #include <kdebug.h>
  31. #include <kdialog.h>
  32. #include <tdelistview.h>
  33. #include <tdelocale.h>
  34. #include <tdemessagebox.h>
  35. #include <ktrader.h>
  36. #include "addresseewidget.h"
  37. #include "kabprefs.h"
  38. #include "kabconfigwidget.h"
  39. KABConfigWidget::KABConfigWidget( TQWidget *parent, const char *name )
  40. : TQWidget( parent, name )
  41. {
  42. TQVBoxLayout *topLayout = new TQVBoxLayout( this, 0,
  43. KDialog::spacingHint() );
  44. TQTabWidget *tabWidget = new TQTabWidget( this );
  45. topLayout->addWidget( tabWidget );
  46. // General page
  47. TQWidget *generalPage = new TQWidget( this );
  48. TQVBoxLayout *layout = new TQVBoxLayout( generalPage, KDialog::marginHint(),
  49. KDialog::spacingHint() );
  50. TQGroupBox *groupBox = new TQGroupBox( 0, Qt::Vertical, i18n( "General" ), generalPage );
  51. TQBoxLayout *boxLayout = new TQVBoxLayout( groupBox->layout() );
  52. boxLayout->setAlignment( TQt::AlignTop );
  53. mViewsSingleClickBox = new TQCheckBox( i18n( "Honor TDE single click" ), groupBox, "msingle" );
  54. boxLayout->addWidget( mViewsSingleClickBox );
  55. mNameParsing = new TQCheckBox( i18n( "Automatic name parsing for new addressees" ), groupBox, "mparse" );
  56. boxLayout->addWidget( mNameParsing );
  57. mTradeAsFamilyName = new TQCheckBox( i18n( "Trade single name component as family name" ), groupBox, "mtrade" );
  58. boxLayout->addWidget( mTradeAsFamilyName );
  59. /**
  60. TODO: show the checkbox when we can compile agains tdelibs from HEAD, atm it
  61. doesn't work and would just confuse the users ;)
  62. */
  63. mTradeAsFamilyName->hide();
  64. mLimitContactDisplay = new TQCheckBox( i18n( "Limit unfiltered display to 100 contacts" ), groupBox, "mlimit" );
  65. boxLayout->addWidget( mLimitContactDisplay );
  66. TQBoxLayout *editorLayout = new TQHBoxLayout( boxLayout, KDialog::spacingHint() );
  67. TQLabel *label = new TQLabel( i18n( "Addressee editor type:" ), groupBox );
  68. editorLayout->addWidget( label );
  69. mEditorCombo = new TQComboBox( groupBox );
  70. mEditorCombo->insertItem( i18n( "Full Editor" ) );
  71. mEditorCombo->insertItem( i18n( "Simple Editor" ) );
  72. label->setBuddy( mEditorCombo );
  73. editorLayout->addWidget( mEditorCombo );
  74. editorLayout->addStretch( 1 );
  75. layout->addWidget( groupBox );
  76. groupBox = new TQGroupBox( 0, Qt::Vertical, i18n( "Script-Hooks" ), generalPage );
  77. TQGridLayout *grid = new TQGridLayout( groupBox->layout(), 3, 2,
  78. KDialog::spacingHint() );
  79. label = new TQLabel( i18n( "Phone:" ), groupBox );
  80. grid->addWidget( label, 0, 0 );
  81. mPhoneHook = new TQLineEdit( groupBox );
  82. TQToolTip::add( mPhoneHook, i18n( "<ul><li>%N: Phone Number</li></ul>" ) );
  83. grid->addWidget( mPhoneHook, 0, 1 );
  84. label = new TQLabel( i18n( "Fax:" ), groupBox );
  85. grid->addWidget( label, 1, 0 );
  86. mFaxHook = new TQLineEdit( groupBox );
  87. TQToolTip::add( mFaxHook, i18n( "<ul><li>%N: Fax Number</li></ul>" ) );
  88. grid->addWidget( mFaxHook, 1, 1 );
  89. label = new TQLabel( i18n( "SMS Text:" ), groupBox );
  90. grid->addWidget( label, 2, 0 );
  91. mSMSHook = new TQLineEdit( groupBox );
  92. TQToolTip::add( mSMSHook, i18n( "<ul><li>%N: Phone Number</li><li>%F: File containing the text message(s)</li></ul>" ) );
  93. grid->addWidget( mSMSHook, 2, 1 );
  94. grid->setColStretch( 1, 1 );
  95. layout->addWidget( groupBox );
  96. groupBox = new TQGroupBox( 0, Qt::Vertical, i18n( "Location Map" ), generalPage );
  97. boxLayout = new TQVBoxLayout( groupBox->layout(), KDialog::spacingHint() );
  98. boxLayout->setAlignment( TQt::AlignTop );
  99. mLocationMapURL = new TQComboBox( true, groupBox );
  100. mLocationMapURL->setSizePolicy( TQSizePolicy( TQSizePolicy::Preferred, TQSizePolicy::Fixed ) );
  101. TQToolTip::add( mLocationMapURL, i18n( "<ul> <li>%s: Street</li>"
  102. "<li>%r: Region</li>"
  103. "<li>%l: Location</li>"
  104. "<li>%z: Zip Code</li>"
  105. "<li>%c: Country ISO Code</li> </ul>" ) );
  106. mLocationMapURL->insertStringList( KABPrefs::instance()->locationMapURLs() );
  107. boxLayout->addWidget( mLocationMapURL );
  108. layout->addWidget( groupBox );
  109. connect( mNameParsing, TQT_SIGNAL( toggled( bool ) ), TQT_SLOT( modified() ) );
  110. connect( mViewsSingleClickBox, TQT_SIGNAL( toggled( bool ) ), TQT_SLOT( modified() ) );
  111. connect( mTradeAsFamilyName, TQT_SIGNAL( toggled( bool ) ), TQT_SLOT( modified() ) );
  112. connect( mLimitContactDisplay, TQT_SIGNAL( toggled( bool ) ), TQT_SLOT( modified() ) );
  113. connect( mPhoneHook, TQT_SIGNAL( textChanged( const TQString& ) ), TQT_SLOT( modified() ) );
  114. connect( mSMSHook, TQT_SIGNAL( textChanged( const TQString& ) ), TQT_SLOT( modified() ) );
  115. connect( mFaxHook, TQT_SIGNAL( textChanged( const TQString& ) ), TQT_SLOT( modified() ) );
  116. connect( mLocationMapURL, TQT_SIGNAL( textChanged( const TQString& ) ), TQT_SLOT( modified() ) );
  117. connect( mEditorCombo, TQT_SIGNAL( activated( int ) ), TQT_SLOT( modified() ) );
  118. tabWidget->addTab( generalPage, i18n( "General" ) );
  119. // Addressee page
  120. mAddresseeWidget = new AddresseeWidget( this );
  121. tabWidget->addTab( mAddresseeWidget, i18n( "Contact" ) );
  122. connect( mAddresseeWidget, TQT_SIGNAL( modified() ), TQT_SLOT( modified() ) );
  123. }
  124. void KABConfigWidget::restoreSettings()
  125. {
  126. bool blocked = signalsBlocked();
  127. blockSignals( true );
  128. mNameParsing->setChecked( KABPrefs::instance()->automaticNameParsing() );
  129. mViewsSingleClickBox->setChecked( KABPrefs::instance()->honorSingleClick() );
  130. mPhoneHook->setText( KABPrefs::instance()->phoneHookApplication() );
  131. mSMSHook->setText( KABPrefs::instance()->sMSHookApplication() );
  132. mFaxHook->setText( KABPrefs::instance()->faxHookApplication() );
  133. mAddresseeWidget->restoreSettings();
  134. mEditorCombo->setCurrentItem( KABPrefs::instance()->editorType() );
  135. mLocationMapURL->setCurrentText( KABPrefs::instance()->locationMapURL().arg( TDEGlobal::locale()->country() ) );
  136. mLocationMapURL->lineEdit()->setCursorPosition( 0 );
  137. TDEConfig config( "tdeabcrc", false, false );
  138. config.setGroup( "General" );
  139. mTradeAsFamilyName->setChecked( config.readBoolEntry( "TradeAsFamilyName", true ) );
  140. mLimitContactDisplay->setChecked( config.readBoolEntry( "LimitContactDisplay", true ) );
  141. blockSignals( blocked );
  142. emit changed( false );
  143. }
  144. void KABConfigWidget::saveSettings()
  145. {
  146. KABPrefs::instance()->setAutomaticNameParsing( mNameParsing->isChecked() );
  147. KABPrefs::instance()->setHonorSingleClick( mViewsSingleClickBox->isChecked() );
  148. KABPrefs::instance()->setPhoneHookApplication( mPhoneHook->text() );
  149. KABPrefs::instance()->setSMSHookApplication( mSMSHook->text() );
  150. KABPrefs::instance()->setFaxHookApplication( mFaxHook->text() );
  151. KABPrefs::instance()->setEditorType( mEditorCombo->currentItem() );
  152. KABPrefs::instance()->setLocationMapURL( mLocationMapURL->currentText() );
  153. mAddresseeWidget->saveSettings();
  154. KABPrefs::instance()->writeConfig();
  155. TDEConfig config( "tdeabcrc", false, false );
  156. config.setGroup( "General" );
  157. config.writeEntry( "TradeAsFamilyName", mTradeAsFamilyName->isChecked() );
  158. config.writeEntry( "LimitContactDisplay", mLimitContactDisplay->isChecked() );
  159. emit changed( false );
  160. }
  161. void KABConfigWidget::defaults()
  162. {
  163. mNameParsing->setChecked( true );
  164. mViewsSingleClickBox->setChecked( false );
  165. mEditorCombo->setCurrentItem( 0 );
  166. mLimitContactDisplay->setChecked( true );
  167. emit changed( true );
  168. }
  169. void KABConfigWidget::modified()
  170. {
  171. emit changed( true );
  172. }
  173. #include "kabconfigwidget.moc"