kontact

kcmkontact.cpp
1/*
2 This file is part of KDE Kontact.
3
4 Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
20 As a special exception, permission is given to link this program
21 with any edition of TQt, and distribute the resulting executable,
22 without including the source code for TQt in the source distribution.
23*/
24
25#include "kcmkontact.h"
26#include "prefs.h"
27
28
29#include <tdeaboutdata.h>
30#include <kdebug.h>
31#include <tdelistview.h>
32#include <tdelocale.h>
33#include <ktrader.h>
34
35#include <tqbuttongroup.h>
36#include <tqcheckbox.h>
37#include <tqcombobox.h>
38#include <tqlabel.h>
39#include <tqlayout.h>
40
41#include <tdemacros.h>
42
43extern "C"
44{
45 TDE_EXPORT TDECModule *create_kontactconfig( TQWidget *parent, const char * ) {
46 return new KcmKontact( parent, "kcmkontact" );
47 }
48}
49
50class PluginItem : public TQListViewItem
51{
52 public:
53 PluginItem( TQListView *parent, const KService::Ptr &ptr )
54 : TQListViewItem( parent, ptr->name(), ptr->comment(), ptr->library() ),
55 mPtr( ptr )
56 {
57 }
58
59 KService::Ptr servicePtr() const
60 {
61 return mPtr;
62 }
63
64 private:
65 KService::Ptr mPtr;
66};
67
68KcmKontact::KcmKontact( TQWidget *parent, const char *name )
69 : KPrefsModule( Kontact::Prefs::self(), parent, name )
70{
71 TQBoxLayout *topLayout = new TQVBoxLayout( this );
72 TQBoxLayout *pluginStartupLayout = new TQHBoxLayout( topLayout );
73 topLayout->addStretch();
74
75 KPrefsWidBool *forceStartupPlugin = addWidBool( Kontact::Prefs::self()->forceStartupPluginItem(), this );
76 pluginStartupLayout->addWidget( forceStartupPlugin->checkBox() );
77
78 PluginSelection *selection = new PluginSelection( Kontact::Prefs::self()->forcedStartupPluginItem(), this );
79 addWid( selection );
80
81 pluginStartupLayout->addWidget( selection->comboBox() );
82 selection->comboBox()->setEnabled( false );
83
84 connect( forceStartupPlugin->checkBox(), TQ_SIGNAL( toggled( bool ) ),
85 selection->comboBox(), TQ_SLOT( setEnabled( bool ) ) );
86 load();
87}
88
89const TDEAboutData* KcmKontact::aboutData() const
90{
91 TDEAboutData *about = new TDEAboutData( I18N_NOOP( "kontactconfig" ),
92 I18N_NOOP( "TDE Kontact" ),
93 0, 0, TDEAboutData::License_GPL,
94 I18N_NOOP( "(c), 2003 Cornelius Schumacher" ) );
95
96 about->addAuthor( "Cornelius Schumacher", 0, "schumacher@kde.org" );
97 about->addAuthor( "Tobias Koenig", 0, "tokoe@kde.org" );
98
99 return about;
100}
101
102
103PluginSelection::PluginSelection( TDEConfigSkeleton::ItemString *item, TQWidget *parent )
104{
105 mItem = item;
106 mPluginCombo = new TQComboBox( parent );
107 connect( mPluginCombo, TQ_SIGNAL( activated( int ) ), TQ_SIGNAL( changed() ) );
108}
109
110PluginSelection::~PluginSelection()
111{
112}
113
114void PluginSelection::readConfig()
115{
116 const TDETrader::OfferList offers = TDETrader::self()->query(
117 TQString::fromLatin1( "Kontact/Plugin" ),
118 TQString( "[X-TDE-KontactPluginVersion] == %1" ).arg( KONTACT_PLUGIN_VERSION ) );
119
120 int activeComponent = 0;
121 mPluginCombo->clear();
122 for ( KService::List::ConstIterator it = offers.begin(); it != offers.end(); ++it ) {
123 KService::Ptr service = *it;
124 // skip summary only plugins
125 TQVariant var = service->property( "X-TDE-KontactPluginHasPart" );
126 if ( var.isValid() && var.toBool() == false )
127 continue;
128 mPluginCombo->insertItem( service->name() );
129 mPluginList.append( service );
130
131 if ( service->property("X-TDE-PluginInfo-Name").toString() == mItem->value() )
132 activeComponent = mPluginList.count() - 1;
133 }
134
135 mPluginCombo->setCurrentItem( activeComponent );
136}
137
138void PluginSelection::writeConfig()
139{
140 KService::Ptr ptr = *( mPluginList.at( mPluginCombo->currentItem() ) );
141 mItem->setValue( ptr->property("X-TDE-PluginInfo-Name").toString() );
142}
143
144TQValueList<TQWidget *> PluginSelection::widgets() const
145{
146 TQValueList<TQWidget *> widgets;
147 widgets.append( mPluginCombo );
148
149 return widgets;
150}
151
152#include "kcmkontact.moc"