summaryrefslogtreecommitdiffstats
path: root/kaddressbook/kcmconfigs/kabconfigwidget.cpp
blob: bbed600e81ebaaa06cb0c09a56214ce7d3f54287 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
/*
    This file is part of KAddressBook.
    Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

    As a special exception, permission is given to link this program
    with any edition of TQt, and distribute the resulting executable,
    without including the source code for TQt in the source distribution.
*/

#include <tqcheckbox.h>
#include <tqframe.h>
#include <tqgroupbox.h>
#include <tqlabel.h>
#include <tqlayout.h>
#include <tqlineedit.h>
#include <tqpushbutton.h>
#include <tqtabwidget.h>
#include <tqtooltip.h>
#include <tqcombobox.h>

#include <kconfig.h>
#include <kdebug.h>
#include <kdialog.h>
#include <klistview.h>
#include <klocale.h>
#include <kmessagebox.h>
#include <ktrader.h>

#include "addresseewidget.h"
#include "kabprefs.h"

#include "kabconfigwidget.h"

KABConfigWidget::KABConfigWidget( TQWidget *parent, const char *name )
  : TQWidget( parent, name )
{
  TQVBoxLayout *topLayout = new TQVBoxLayout( this, 0,
                                            KDialog::spacingHint() );

  TQTabWidget *tabWidget = new TQTabWidget( this );
  topLayout->addWidget( tabWidget );

  // General page
  TQWidget *generalPage = new TQWidget( this );
  TQVBoxLayout *layout = new TQVBoxLayout( generalPage, KDialog::marginHint(),
                                            KDialog::spacingHint() );

  TQGroupBox *groupBox = new TQGroupBox( 0, Qt::Vertical, i18n( "General" ), generalPage );
  TQBoxLayout *boxLayout = new TQVBoxLayout( groupBox->layout() );
  boxLayout->setAlignment( TQt::AlignTop );

  mViewsSingleClickBox = new TQCheckBox( i18n( "Honor TDE single click" ), groupBox, "msingle" );
  boxLayout->addWidget( mViewsSingleClickBox );

  mNameParsing = new TQCheckBox( i18n( "Automatic name parsing for new addressees" ), groupBox, "mparse" );
  boxLayout->addWidget( mNameParsing );

  mTradeAsFamilyName = new TQCheckBox( i18n( "Trade single name component as family name" ), groupBox, "mtrade" );
  boxLayout->addWidget( mTradeAsFamilyName );
/**
  TODO: show the checkbox when we can compile agains tdelibs from HEAD, atm it
        doesn't work and would just confuse the users ;)
*/
  mTradeAsFamilyName->hide();

  mLimitContactDisplay = new TQCheckBox( i18n( "Limit unfiltered display to 100 contacts" ), groupBox, "mlimit" );
  boxLayout->addWidget( mLimitContactDisplay );

  TQBoxLayout *editorLayout = new TQHBoxLayout( boxLayout, KDialog::spacingHint() );

  TQLabel *label = new TQLabel( i18n( "Addressee editor type:" ), groupBox );
  editorLayout->addWidget( label );

  mEditorCombo = new TQComboBox( groupBox );
  mEditorCombo->insertItem( i18n( "Full Editor" ) );
  mEditorCombo->insertItem( i18n( "Simple Editor" ) );
  label->setBuddy( mEditorCombo );
  editorLayout->addWidget( mEditorCombo );

  editorLayout->addStretch( 1 );


  layout->addWidget( groupBox );

  groupBox = new TQGroupBox( 0, Qt::Vertical, i18n( "Script-Hooks" ), generalPage );
  TQGridLayout *grid = new TQGridLayout( groupBox->layout(), 3, 2,
                                       KDialog::spacingHint() );
  label = new TQLabel( i18n( "Phone:" ), groupBox );
  grid->addWidget( label, 0, 0 );

  mPhoneHook = new TQLineEdit( groupBox );
  TQToolTip::add( mPhoneHook, i18n( "<ul><li>%N: Phone Number</li></ul>" ) );
  grid->addWidget( mPhoneHook, 0, 1 );

  label = new TQLabel( i18n( "Fax:" ), groupBox );
  grid->addWidget( label, 1, 0 );

  mFaxHook = new TQLineEdit( groupBox );
  TQToolTip::add( mFaxHook, i18n( "<ul><li>%N: Fax Number</li></ul>" ) );
  grid->addWidget( mFaxHook, 1, 1 );


  label = new TQLabel( i18n( "SMS Text:" ), groupBox );
  grid->addWidget( label, 2, 0 );

  mSMSHook = new TQLineEdit( groupBox );
  TQToolTip::add( mSMSHook, i18n( "<ul><li>%N: Phone Number</li><li>%F: File containing the text message(s)</li></ul>" ) );
  grid->addWidget( mSMSHook, 2, 1 );


  grid->setColStretch( 1, 1 );

  layout->addWidget( groupBox );

  groupBox = new TQGroupBox( 0, Qt::Vertical, i18n( "Location Map" ), generalPage );
  boxLayout = new TQVBoxLayout( groupBox->layout(), KDialog::spacingHint() );
  boxLayout->setAlignment( TQt::AlignTop );

  mLocationMapURL = new TQComboBox( true, groupBox );
  mLocationMapURL->setSizePolicy( TQSizePolicy( TQSizePolicy::Preferred, TQSizePolicy::Fixed ) );
  TQToolTip::add( mLocationMapURL, i18n( "<ul> <li>%s: Street</li>"
                                 "<li>%r: Region</li>"
                                 "<li>%l: Location</li>"
                                 "<li>%z: Zip Code</li>"
                                 "<li>%c: Country ISO Code</li> </ul>" ) );
  mLocationMapURL->insertStringList( KABPrefs::instance()->locationMapURLs() );
  boxLayout->addWidget( mLocationMapURL );
  layout->addWidget( groupBox );

  connect( mNameParsing, TQT_SIGNAL( toggled( bool ) ), TQT_SLOT( modified() ) );
  connect( mViewsSingleClickBox, TQT_SIGNAL( toggled( bool ) ), TQT_SLOT( modified() ) );
  connect( mTradeAsFamilyName, TQT_SIGNAL( toggled( bool ) ), TQT_SLOT( modified() ) );
  connect( mLimitContactDisplay, TQT_SIGNAL( toggled( bool ) ), TQT_SLOT( modified() ) );
  connect( mPhoneHook, TQT_SIGNAL( textChanged( const TQString& ) ), TQT_SLOT( modified() ) );
  connect( mSMSHook, TQT_SIGNAL( textChanged( const TQString& ) ), TQT_SLOT( modified() ) );
  connect( mFaxHook, TQT_SIGNAL( textChanged( const TQString& ) ), TQT_SLOT( modified() ) );
  connect( mLocationMapURL, TQT_SIGNAL( textChanged( const TQString& ) ), TQT_SLOT( modified() ) );
  connect( mEditorCombo, TQT_SIGNAL( activated( int ) ), TQT_SLOT( modified() ) );

  tabWidget->addTab( generalPage, i18n( "General" ) );

  // Addressee page
  mAddresseeWidget = new AddresseeWidget( this );
  tabWidget->addTab( mAddresseeWidget, i18n( "Contact" ) );
  connect( mAddresseeWidget, TQT_SIGNAL( modified() ), TQT_SLOT( modified() ) );
}

void KABConfigWidget::restoreSettings()
{
  bool blocked = signalsBlocked();
  blockSignals( true );

  mNameParsing->setChecked( KABPrefs::instance()->automaticNameParsing() );
  mViewsSingleClickBox->setChecked( KABPrefs::instance()->honorSingleClick() );
  mPhoneHook->setText( KABPrefs::instance()->phoneHookApplication() );
  mSMSHook->setText( KABPrefs::instance()->sMSHookApplication() );
  mFaxHook->setText( KABPrefs::instance()->faxHookApplication() );
  mAddresseeWidget->restoreSettings();
  mEditorCombo->setCurrentItem( KABPrefs::instance()->editorType() );
  mLocationMapURL->setCurrentText( KABPrefs::instance()->locationMapURL().arg( KGlobal::locale()->country() ) );
  mLocationMapURL->lineEdit()->setCursorPosition( 0 );

  KConfig config( "kabcrc", false, false );
  config.setGroup( "General" );
  mTradeAsFamilyName->setChecked( config.readBoolEntry( "TradeAsFamilyName", true ) );
  mLimitContactDisplay->setChecked( config.readBoolEntry( "LimitContactDisplay", true ) );

  blockSignals( blocked );

  emit changed( false );
}

void KABConfigWidget::saveSettings()
{
  KABPrefs::instance()->setAutomaticNameParsing( mNameParsing->isChecked() );
  KABPrefs::instance()->setHonorSingleClick( mViewsSingleClickBox->isChecked() );
  KABPrefs::instance()->setPhoneHookApplication( mPhoneHook->text() );
  KABPrefs::instance()->setSMSHookApplication( mSMSHook->text() );
  KABPrefs::instance()->setFaxHookApplication( mFaxHook->text() );
  KABPrefs::instance()->setEditorType( mEditorCombo->currentItem() );
  KABPrefs::instance()->setLocationMapURL( mLocationMapURL->currentText() );
  mAddresseeWidget->saveSettings();

  KABPrefs::instance()->writeConfig();

  KConfig config( "kabcrc", false, false );
  config.setGroup( "General" );
  config.writeEntry( "TradeAsFamilyName", mTradeAsFamilyName->isChecked() );
  config.writeEntry( "LimitContactDisplay", mLimitContactDisplay->isChecked() );

  emit changed( false );
}

void KABConfigWidget::defaults()
{
  mNameParsing->setChecked( true );
  mViewsSingleClickBox->setChecked( false );
  mEditorCombo->setCurrentItem( 0 );
  mLimitContactDisplay->setChecked( true );

  emit changed( true );
}

void KABConfigWidget::modified()
{
  emit changed( true );
}

#include "kabconfigwidget.moc"