summaryrefslogtreecommitdiffabout
path: root/kaddressbook/kcmconfigs/kabconfigwidget.cpp
authorzautrix <zautrix>2004-06-26 19:01:18 (UTC)
committer zautrix <zautrix>2004-06-26 19:01:18 (UTC)
commitb9aad1f15dc600e4dbe4c62d3fcced6363188ba3 (patch) (unidiff)
tree2c3d4004fb21c72cba65793859f9bcd8ffd3a49c /kaddressbook/kcmconfigs/kabconfigwidget.cpp
downloadkdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.zip
kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.gz
kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.bz2
Initial revision
Diffstat (limited to 'kaddressbook/kcmconfigs/kabconfigwidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/kcmconfigs/kabconfigwidget.cpp357
1 files changed, 357 insertions, 0 deletions
diff --git a/kaddressbook/kcmconfigs/kabconfigwidget.cpp b/kaddressbook/kcmconfigs/kabconfigwidget.cpp
new file mode 100644
index 0000000..7b3e5c6
--- a/dev/null
+++ b/kaddressbook/kcmconfigs/kabconfigwidget.cpp
@@ -0,0 +1,357 @@
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution.
22*/
23
24#include <qcheckbox.h>
25#include <qframe.h>
26#include <qgroupbox.h>
27#include <qlayout.h>
28#include <qpushbutton.h>
29#include <qtabwidget.h>
30
31#include <kconfig.h>
32#include <kdebug.h>
33#include <kdialog.h>
34#include <klistview.h>
35#include <klocale.h>
36#include <kglobal.h>
37#include <kmessagebox.h>
38#include <kstandarddirs.h>
39
40#ifndef KAB_EMBEDDED
41#include <ktrader.h>
42#else // KAB_EMBEDDED
43#include <mergewidget.h>
44#include <distributionlistwidget.h>
45#endif // KAB_EMBEDDED
46
47#include "addresseewidget.h"
48#include "extensionconfigdialog.h"
49#include "extensionwidget.h"
50#include "kabprefs.h"
51
52#include "kabconfigwidget.h"
53
54class ExtensionItem : public QCheckListItem
55{
56 public:
57
58#ifndef KAB_EMBEDDED
59 ExtensionItem( QListView *parent, const QString &text );
60 void setService( const KService::Ptr &ptr );
61#else //KAB_EMBEDDED
62 ExtensionItem( QListView *parent, const QString &text, const QString &name, const QString &comment );
63 void setFactory( ExtensionFactory* fac );
64#endif //KAB_EMBEDDED
65
66 bool configWidgetAvailable() const;
67 ExtensionFactory *factory() const;
68
69 virtual QString text( int column ) const;
70
71 private:
72#ifndef KAB_EMBEDDED
73 KService::Ptr mPtr;
74#else //KAB_EMBEDDED
75 ExtensionFactory* mFactory;
76 QString mName;
77 QString mComment;
78
79#endif //KAB_EMBEDDED
80
81};
82
83KABConfigWidget::KABConfigWidget( QWidget *parent, const char *name )
84 : QWidget( parent, name )
85{
86 QVBoxLayout *topLayout = new QVBoxLayout( this, 0,
87 KDialog::spacingHint() );
88
89 QTabWidget *tabWidget = new QTabWidget( this );
90 topLayout->addWidget( tabWidget );
91
92 // General page
93 QWidget *generalPage = new QWidget( this );
94 QVBoxLayout *layout = new QVBoxLayout( generalPage, KDialog::marginHint(),
95 KDialog::spacingHint() );
96
97 QGroupBox *groupBox = new QGroupBox( 0, Qt::Vertical, i18n( "General" ), generalPage );
98 QVBoxLayout *boxLayout = new QVBoxLayout( groupBox->layout() );
99 boxLayout->setAlignment( Qt::AlignTop );
100
101 mViewsSingleClickBox = new QCheckBox( i18n( "Honor KDE single click" ), groupBox, "msingle" );
102 boxLayout->addWidget( mViewsSingleClickBox );
103
104 mNameParsing = new QCheckBox( i18n( "Automatic name parsing for new addressees" ), groupBox, "mparse" );
105 boxLayout->addWidget( mNameParsing );
106
107 layout->addWidget( groupBox );
108
109 groupBox = new QGroupBox( 0, Qt::Vertical, i18n( "Extensions" ), generalPage );
110 boxLayout = new QVBoxLayout( groupBox->layout() );
111 boxLayout->setAlignment( Qt::AlignTop );
112
113 mExtensionView = new KListView( groupBox );
114 mExtensionView->setAllColumnsShowFocus( true );
115 mExtensionView->addColumn( i18n( "Name" ) );
116 mExtensionView->addColumn( i18n( "Description" ) );
117 mExtensionView->setMaximumHeight(80);
118
119 boxLayout->addWidget( mExtensionView );
120
121 mConfigureButton = new QPushButton( i18n( "Configure..." ), groupBox );
122 mConfigureButton->setEnabled( false );
123 boxLayout->addWidget( mConfigureButton );
124
125 layout->addWidget( groupBox );
126
127 connect( mNameParsing, SIGNAL( toggled( bool ) ), this, SLOT( modified() ) );
128 connect( mViewsSingleClickBox, SIGNAL( toggled( bool ) ), this, SLOT( modified() ) );
129 connect( mExtensionView, SIGNAL( selectionChanged( QListViewItem* ) ),
130 SLOT( selectionChanged( QListViewItem* ) ) );
131 connect( mExtensionView, SIGNAL( clicked( QListViewItem* ) ),
132 SLOT( itemClicked( QListViewItem* ) ) );
133 connect( mConfigureButton, SIGNAL( clicked() ),
134 SLOT( configureExtension() ) );
135
136 tabWidget->addTab( generalPage, i18n( "General" ) );
137
138 // Addressee page
139 mAddresseeWidget = new AddresseeWidget( this );
140 tabWidget->addTab( mAddresseeWidget, i18n( "Contact" ) );
141 connect( mAddresseeWidget, SIGNAL( modified() ), SLOT( modified() ) );
142}
143
144void KABConfigWidget::restoreSettings()
145{
146 bool blocked = signalsBlocked();
147 blockSignals( true );
148
149 mNameParsing->setChecked( KABPrefs::instance()->mAutomaticNameParsing );
150 mViewsSingleClickBox->setChecked( KABPrefs::instance()->mHonorSingleClick );
151 mAddresseeWidget->restoreSettings();
152
153 restoreExtensionSettings();
154
155 blockSignals( blocked );
156
157 emit changed( false );
158}
159
160void KABConfigWidget::saveSettings()
161{
162 KABPrefs::instance()->mAutomaticNameParsing = mNameParsing->isChecked();
163 KABPrefs::instance()->mHonorSingleClick = mViewsSingleClickBox->isChecked();
164 mAddresseeWidget->saveSettings();
165
166 saveExtensionSettings();
167 KABPrefs::instance()->writeConfig();
168
169 emit changed( false );
170}
171
172void KABConfigWidget::defaults()
173{
174 mNameParsing->setChecked( true );
175 mViewsSingleClickBox->setChecked( false );
176
177 emit changed( true );
178}
179
180void KABConfigWidget::modified()
181{
182 emit changed( true );
183}
184
185void KABConfigWidget::restoreExtensionSettings()
186{
187 QStringList activeExtensions = KABPrefs::instance()->mActiveExtensions;
188
189 mExtensionView->clear();
190
191#ifndef KAB_EMBEDDED
192 KTrader::OfferList plugins = KTrader::self()->query( "KAddressBook/Extension" );
193 KTrader::OfferList::ConstIterator it;
194 for ( it = plugins.begin(); it != plugins.end(); ++it ) {
195 if ( !(*it)->hasServiceType( "KAddressBook/Extension" ) )
196 continue;
197
198 ExtensionItem *item = new ExtensionItem( mExtensionView, (*it)->name() );
199 item->setService( *it );
200 if ( activeExtensions.contains( item->factory()->identifier() ) )
201 item->setOn( true );
202 }
203#else //KAB_EMBEDDED
204 ExtensionFactory *extensionFactory = new MergeFactory();
205
206 ExtensionItem *item = new ExtensionItem( mExtensionView, "Merge", "Merge", "Merge contacts");
207
208 item->setFactory( extensionFactory );
209 if ( activeExtensions.contains( extensionFactory->identifier() ) )
210 item->setOn( true );
211
212
213
214 extensionFactory = new DistributionListFactory();
215
216 item = new ExtensionItem( mExtensionView, "Distribution List", "Distribution List", "Manage Distribution Lists");
217
218 item->setFactory( extensionFactory );
219 if ( activeExtensions.contains( extensionFactory->identifier() ) )
220 item->setOn( true );
221
222
223#endif //KAB_EMBEDDED
224
225}
226
227void KABConfigWidget::saveExtensionSettings()
228{
229 QStringList activeExtensions;
230
231 QPtrList<QListViewItem> list;
232 QListViewItemIterator it( mExtensionView );
233 while ( it.current() ) {
234 ExtensionItem *item = static_cast<ExtensionItem*>( it.current() );
235 if ( item ) {
236 if ( item->isOn() )
237 activeExtensions.append( item->factory()->identifier() );
238 }
239 ++it;
240 }
241
242 KABPrefs::instance()->mActiveExtensions = activeExtensions;
243}
244
245void KABConfigWidget::configureExtension()
246{
247 ExtensionItem *item = static_cast<ExtensionItem*>( mExtensionView->currentItem() );
248 if ( !item )
249 return;
250
251#ifndef KAB_EMBEDDED
252 KConfig config( "kaddressbookrc" );
253#else //KAB_EMBEDDED
254 KConfig config( locateLocal("config", "kaddressbookrc") );
255#endif //KAB_EMBEDDED
256 config.setGroup( QString( "Extensions_%1" ).arg( item->factory()->identifier() ) );
257
258 ExtensionConfigDialog dlg( item->factory(), &config, this );
259 dlg.exec();
260
261 config.sync();
262}
263
264void KABConfigWidget::selectionChanged( QListViewItem *i )
265{
266 ExtensionItem *item = static_cast<ExtensionItem*>( i );
267 if ( !item )
268 return;
269
270 mConfigureButton->setEnabled( item->configWidgetAvailable() );
271}
272
273void KABConfigWidget::itemClicked( QListViewItem *item )
274{
275 if ( item != 0 )
276 modified();
277}
278
279#ifndef KAB_EMBEDDED
280ExtensionItem::ExtensionItem( QListView *parent, const QString &text )
281 : QCheckListItem( parent, text, CheckBox )
282{
283}
284
285void ExtensionItem::setService( const KService::Ptr &ptr )
286{
287 mPtr = ptr;
288}
289#else //KAB_EMBEDDED
290ExtensionItem::ExtensionItem( QListView *parent, const QString &text, const QString &name, const QString &comment )
291 : QCheckListItem( parent, text, CheckBox )
292{
293 mName = name;
294 mComment = comment;
295}
296
297
298void ExtensionItem::setFactory( ExtensionFactory* fac )
299{
300 mFactory = fac;
301}
302#endif //KAB_EMBEDDED
303
304bool ExtensionItem::configWidgetAvailable() const
305{
306#ifndef KAB_EMBEDDED
307 KLibFactory *factory = KLibLoader::self()->factory( mPtr->library().latin1() );
308 if ( !factory )
309 return false;
310
311 ExtensionFactory *extensionFactory = static_cast<ExtensionFactory*>( factory );
312 if ( !extensionFactory )
313 return false;
314
315 return extensionFactory->configureWidgetAvailable();
316#else //KAB_EMBEDDED
317 return mFactory->configureWidgetAvailable();
318#endif //KAB_EMBEDDED
319
320}
321
322ExtensionFactory *ExtensionItem::factory() const
323{
324#ifndef KAB_EMBEDDED
325 KLibFactory *factory = KLibLoader::self()->factory( mPtr->library().latin1() );
326 if ( !factory )
327 return 0;
328
329 return static_cast<ExtensionFactory*>( factory );
330#else //KAB_EMBEDDED
331 return mFactory;
332#endif //KAB_EMBEDDED
333}
334
335QString ExtensionItem::text( int column ) const
336{
337#ifndef KAB_EMBEDDED
338 if ( column == 0 )
339 return mPtr->name();
340 else if ( column == 1 )
341 return mPtr->comment();
342 else
343 return QString::null;
344#else //KAB_EMBEDDED
345 if ( column == 0 )
346 return mName;
347 else if ( column == 1 )
348 return mComment;
349 else
350 return QString::null;
351#endif //KAB_EMBEDDED
352}
353
354#ifndef KAB_EMBEDDED
355#include "kabconfigwidget.moc"
356#endif //KAB_EMBEDDED
357