kontact
kcmkontact.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "kcmkontact.h"
00026 #include "prefs.h"
00027
00028 #include <kdemacros.h>
00029 #include <kcomponentdata.h>
00030 #include <kaboutdata.h>
00031 #include <kdebug.h>
00032 #include <k3listview.h>
00033 #include <klocale.h>
00034 #include <kservicetypetrader.h>
00035 #include <kcombobox.h>
00036
00037 #include <q3buttongroup.h>
00038 #include <QCheckBox>
00039 #include <QLabel>
00040 #include <QLayout>
00041 #include <QVBoxLayout>
00042 #include <QHBoxLayout>
00043 #include <QBoxLayout>
00044
00045 extern "C"
00046 {
00047 KDE_EXPORT KCModule *create_kontactconfig( QWidget *parent, const char * ) {
00048 KComponentData inst( "kcmkontact" );
00049 return new KcmKontact( inst, parent );
00050 }
00051 }
00052
00053 class PluginItem : public Q3ListViewItem
00054 {
00055 public:
00056 PluginItem( Q3ListView *parent, const KService::Ptr &ptr )
00057 : Q3ListViewItem( parent, ptr->name(), ptr->comment(), ptr->library() ),
00058 mPtr( ptr )
00059 {
00060 }
00061
00062 KService::Ptr servicePtr() const
00063 {
00064 return mPtr;
00065 }
00066
00067 private:
00068 KService::Ptr mPtr;
00069 };
00070
00071 KcmKontact::KcmKontact( const KComponentData &inst, QWidget *parent )
00072 : KPrefsModule( Kontact::Prefs::self(), inst, parent )
00073 {
00074 QBoxLayout *topLayout = new QVBoxLayout( this );
00075 QBoxLayout *pluginStartupLayout = new QHBoxLayout();
00076 topLayout->addItem( pluginStartupLayout );
00077 topLayout->addStretch();
00078
00079 KPrefsWidBool *forceStartupPlugin =
00080 addWidBool( Kontact::Prefs::self()->forceStartupPluginItem(), this );
00081 pluginStartupLayout->addWidget( forceStartupPlugin->checkBox() );
00082
00083 PluginSelection *selection =
00084 new PluginSelection( Kontact::Prefs::self()->forcedStartupPluginItem(), this );
00085 addWid( selection );
00086
00087 pluginStartupLayout->addWidget( selection->comboBox() );
00088 selection->comboBox()->setEnabled( false );
00089
00090 connect( forceStartupPlugin->checkBox(), SIGNAL(toggled(bool)),
00091 selection->comboBox(), SLOT(setEnabled(bool)) );
00092 load();
00093 }
00094
00095 const KAboutData *KcmKontact::aboutData() const
00096 {
00097 KAboutData *about = new KAboutData( I18N_NOOP( "kontactconfig" ), 0,
00098 ki18n( "KDE Kontact" ),
00099 0, KLocalizedString(), KAboutData::License_GPL,
00100 ki18n( "(c), 2003 Cornelius Schumacher" ) );
00101
00102 about->addAuthor( ki18n( "Cornelius Schumacher" ), KLocalizedString(), "schumacher@kde.org" );
00103 about->addAuthor( ki18n( "Tobias Koenig" ), KLocalizedString(), "tokoe@kde.org" );
00104
00105 return about;
00106 }
00107
00108 PluginSelection::PluginSelection( KConfigSkeleton::ItemString *item, QWidget *parent )
00109 {
00110 mItem = item;
00111 mPluginCombo = new KComboBox( parent );
00112 connect( mPluginCombo, SIGNAL(currentIndexChanged(int)), SIGNAL(changed()) );
00113 }
00114
00115 PluginSelection::~PluginSelection()
00116 {
00117 }
00118
00119 void PluginSelection::readConfig()
00120 {
00121 const KService::List offers = KServiceTypeTrader::self()->query(
00122 QString::fromLatin1( "Kontact/Plugin" ),
00123 QString( "[X-KDE-KontactPluginVersion] == %1" ).arg( KONTACT_PLUGIN_VERSION ) );
00124
00125 int activeComponent = 0;
00126 mPluginCombo->clear();
00127 mPluginList.clear();
00128 for ( KService::List::ConstIterator it = offers.begin(); it != offers.end(); ++it ) {
00129 KService::Ptr service = *it;
00130
00131 QVariant var = service->property( "X-KDE-KontactPluginHasPart" );
00132 if ( var.isValid() && var.toBool() == false ) {
00133 continue;
00134 }
00135 mPluginCombo->addItem( service->name() );
00136 mPluginList.append( service );
00137
00138 if ( service->property( "X-KDE-PluginInfo-Name" ).toString() == mItem->value() ) {
00139 activeComponent = mPluginList.count() - 1;
00140 }
00141 }
00142
00143 mPluginCombo->setCurrentIndex( activeComponent );
00144 }
00145
00146 void PluginSelection::writeConfig()
00147 {
00148 KService::Ptr ptr = mPluginList.at( mPluginCombo->currentIndex() );
00149 mItem->setValue( ptr->property( "X-KDE-PluginInfo-Name" ).toString() );
00150 }
00151
00152 QList<QWidget *> PluginSelection::widgets() const
00153 {
00154 QList<QWidget *> widgets;
00155 widgets.append( mPluginCombo );
00156
00157 return widgets;
00158 }
00159
00160 #include "kcmkontact.moc"