kaddressbook

kabconfigwidget.cpp
1 /*
2  This file is part of KAddressBook.
3  Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 
19  As a special exception, permission is given to link this program
20  with any edition of TQt, and distribute the resulting executable,
21  without including the source code for TQt in the source distribution.
22 */
23 
24 #include <tqcheckbox.h>
25 #include <tqframe.h>
26 #include <tqgroupbox.h>
27 #include <tqlabel.h>
28 #include <tqlayout.h>
29 #include <tqlineedit.h>
30 #include <tqpushbutton.h>
31 #include <tqtabwidget.h>
32 #include <tqtooltip.h>
33 #include <tqcombobox.h>
34 
35 #include <tdeconfig.h>
36 #include <kdebug.h>
37 #include <kdialog.h>
38 #include <tdelistview.h>
39 #include <tdelocale.h>
40 #include <tdemessagebox.h>
41 #include <ktrader.h>
42 
43 #include "addresseewidget.h"
44 #include "kabprefs.h"
45 
46 #include "kabconfigwidget.h"
47 
48 KABConfigWidget::KABConfigWidget( TQWidget *parent, const char *name )
49  : TQWidget( parent, name )
50 {
51  TQVBoxLayout *topLayout = new TQVBoxLayout( this, 0,
52  KDialog::spacingHint() );
53 
54  TQTabWidget *tabWidget = new TQTabWidget( this );
55  topLayout->addWidget( tabWidget );
56 
57  // General page
58  TQWidget *generalPage = new TQWidget( this );
59  TQVBoxLayout *layout = new TQVBoxLayout( generalPage, KDialog::marginHint(),
60  KDialog::spacingHint() );
61 
62  TQGroupBox *groupBox = new TQGroupBox( 0, TQt::Vertical, i18n( "General" ), generalPage );
63  TQBoxLayout *boxLayout = new TQVBoxLayout( groupBox->layout() );
64  boxLayout->setAlignment( TQt::AlignTop );
65 
66  mViewsSingleClickBox = new TQCheckBox( i18n( "Honor TDE single click" ), groupBox, "msingle" );
67  boxLayout->addWidget( mViewsSingleClickBox );
68 
69  mNameParsing = new TQCheckBox( i18n( "Automatic name parsing for new addressees" ), groupBox, "mparse" );
70  boxLayout->addWidget( mNameParsing );
71 
72  mTradeAsFamilyName = new TQCheckBox( i18n( "Trade single name component as family name" ), groupBox, "mtrade" );
73  boxLayout->addWidget( mTradeAsFamilyName );
78  mTradeAsFamilyName->hide();
79 
80  mLimitContactDisplay = new TQCheckBox( i18n( "Limit unfiltered display to 100 contacts" ), groupBox, "mlimit" );
81  boxLayout->addWidget( mLimitContactDisplay );
82 
83  TQBoxLayout *editorLayout = new TQHBoxLayout( boxLayout, KDialog::spacingHint() );
84 
85  TQLabel *label = new TQLabel( i18n( "Addressee editor type:" ), groupBox );
86  editorLayout->addWidget( label );
87 
88  mEditorCombo = new TQComboBox( groupBox );
89  mEditorCombo->insertItem( i18n( "Full Editor" ) );
90  mEditorCombo->insertItem( i18n( "Simple Editor" ) );
91  label->setBuddy( mEditorCombo );
92  editorLayout->addWidget( mEditorCombo );
93 
94  editorLayout->addStretch( 1 );
95 
96 
97  layout->addWidget( groupBox );
98 
99  groupBox = new TQGroupBox( 0, TQt::Vertical, i18n( "Script-Hooks" ), generalPage );
100  TQGridLayout *grid = new TQGridLayout( groupBox->layout(), 3, 2,
101  KDialog::spacingHint() );
102  label = new TQLabel( i18n( "Phone:" ), groupBox );
103  grid->addWidget( label, 0, 0 );
104 
105  mPhoneHook = new TQLineEdit( groupBox );
106  TQToolTip::add( mPhoneHook, i18n( "<ul><li>%N: Phone Number</li></ul>" ) );
107  grid->addWidget( mPhoneHook, 0, 1 );
108 
109  label = new TQLabel( i18n( "Fax:" ), groupBox );
110  grid->addWidget( label, 1, 0 );
111 
112  mFaxHook = new TQLineEdit( groupBox );
113  TQToolTip::add( mFaxHook, i18n( "<ul><li>%N: Fax Number</li></ul>" ) );
114  grid->addWidget( mFaxHook, 1, 1 );
115 
116 
117  label = new TQLabel( i18n( "SMS Text:" ), groupBox );
118  grid->addWidget( label, 2, 0 );
119 
120  mSMSHook = new TQLineEdit( groupBox );
121  TQToolTip::add( mSMSHook, i18n( "<ul><li>%N: Phone Number</li><li>%F: File containing the text message(s)</li></ul>" ) );
122  grid->addWidget( mSMSHook, 2, 1 );
123 
124 
125  grid->setColStretch( 1, 1 );
126 
127  layout->addWidget( groupBox );
128 
129  groupBox = new TQGroupBox( 0, TQt::Vertical, i18n( "Location Map" ), generalPage );
130  boxLayout = new TQVBoxLayout( groupBox->layout(), KDialog::spacingHint() );
131  boxLayout->setAlignment( TQt::AlignTop );
132 
133  mLocationMapURL = new TQComboBox( true, groupBox );
134  mLocationMapURL->setSizePolicy( TQSizePolicy( TQSizePolicy::Preferred, TQSizePolicy::Fixed ) );
135  TQToolTip::add( mLocationMapURL, i18n( "<ul> <li>%s: Street</li>"
136  "<li>%r: Region</li>"
137  "<li>%l: Location</li>"
138  "<li>%z: Zip Code</li>"
139  "<li>%c: Country ISO Code</li> </ul>" ) );
140  mLocationMapURL->insertStringList( KABPrefs::instance()->locationMapURLs() );
141  boxLayout->addWidget( mLocationMapURL );
142  layout->addWidget( groupBox );
143 
144  connect( mNameParsing, TQ_SIGNAL( toggled( bool ) ), TQ_SLOT( modified() ) );
145  connect( mViewsSingleClickBox, TQ_SIGNAL( toggled( bool ) ), TQ_SLOT( modified() ) );
146  connect( mTradeAsFamilyName, TQ_SIGNAL( toggled( bool ) ), TQ_SLOT( modified() ) );
147  connect( mLimitContactDisplay, TQ_SIGNAL( toggled( bool ) ), TQ_SLOT( modified() ) );
148  connect( mPhoneHook, TQ_SIGNAL( textChanged( const TQString& ) ), TQ_SLOT( modified() ) );
149  connect( mSMSHook, TQ_SIGNAL( textChanged( const TQString& ) ), TQ_SLOT( modified() ) );
150  connect( mFaxHook, TQ_SIGNAL( textChanged( const TQString& ) ), TQ_SLOT( modified() ) );
151  connect( mLocationMapURL, TQ_SIGNAL( textChanged( const TQString& ) ), TQ_SLOT( modified() ) );
152  connect( mEditorCombo, TQ_SIGNAL( activated( int ) ), TQ_SLOT( modified() ) );
153 
154  tabWidget->addTab( generalPage, i18n( "General" ) );
155 
156  // Addressee page
157  mAddresseeWidget = new AddresseeWidget( this );
158  tabWidget->addTab( mAddresseeWidget, i18n( "Contact" ) );
159  connect( mAddresseeWidget, TQ_SIGNAL( modified() ), TQ_SLOT( modified() ) );
160 }
161 
162 void KABConfigWidget::restoreSettings()
163 {
164  bool blocked = signalsBlocked();
165  blockSignals( true );
166 
167  mNameParsing->setChecked( KABPrefs::instance()->automaticNameParsing() );
168  mViewsSingleClickBox->setChecked( KABPrefs::instance()->honorSingleClick() );
169  mPhoneHook->setText( KABPrefs::instance()->phoneHookApplication() );
170  mSMSHook->setText( KABPrefs::instance()->sMSHookApplication() );
171  mFaxHook->setText( KABPrefs::instance()->faxHookApplication() );
172  mAddresseeWidget->restoreSettings();
173  mEditorCombo->setCurrentItem( KABPrefs::instance()->editorType() );
174  mLocationMapURL->setCurrentText( KABPrefs::instance()->locationMapURL().arg( TDEGlobal::locale()->country() ) );
175  mLocationMapURL->lineEdit()->setCursorPosition( 0 );
176 
177  TDEConfig config( "tdeabcrc", false, false );
178  config.setGroup( "General" );
179  mTradeAsFamilyName->setChecked( config.readBoolEntry( "TradeAsFamilyName", true ) );
180  mLimitContactDisplay->setChecked( config.readBoolEntry( "LimitContactDisplay", true ) );
181 
182  blockSignals( blocked );
183 
184  emit changed( false );
185 }
186 
187 void KABConfigWidget::saveSettings()
188 {
189  KABPrefs::instance()->setAutomaticNameParsing( mNameParsing->isChecked() );
190  KABPrefs::instance()->setHonorSingleClick( mViewsSingleClickBox->isChecked() );
191  KABPrefs::instance()->setPhoneHookApplication( mPhoneHook->text() );
192  KABPrefs::instance()->setSMSHookApplication( mSMSHook->text() );
193  KABPrefs::instance()->setFaxHookApplication( mFaxHook->text() );
194  KABPrefs::instance()->setEditorType( mEditorCombo->currentItem() );
195  KABPrefs::instance()->setLocationMapURL( mLocationMapURL->currentText() );
196  mAddresseeWidget->saveSettings();
197 
198  KABPrefs::instance()->writeConfig();
199 
200  TDEConfig config( "tdeabcrc", false, false );
201  config.setGroup( "General" );
202  config.writeEntry( "TradeAsFamilyName", mTradeAsFamilyName->isChecked() );
203  config.writeEntry( "LimitContactDisplay", mLimitContactDisplay->isChecked() );
204 
205  emit changed( false );
206 }
207 
208 void KABConfigWidget::defaults()
209 {
210  mNameParsing->setChecked( true );
211  mViewsSingleClickBox->setChecked( false );
212  mEditorCombo->setCurrentItem( 0 );
213  mLimitContactDisplay->setChecked( true );
214 
215  emit changed( true );
216 }
217 
218 void KABConfigWidget::modified()
219 {
220  emit changed( true );
221 }
222 
223 #include "kabconfigwidget.moc"