kcmkontact.cpp
00001 /* 00002 This file is part of KDE Kontact. 00003 00004 Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 00020 As a special exception, permission is given to link this program 00021 with any edition of TQt, and distribute the resulting executable, 00022 without including the source code for TQt in the source distribution. 00023 */ 00024 00025 #include "kcmkontact.h" 00026 #include "prefs.h" 00027 00028 00029 #include <kaboutdata.h> 00030 #include <kdebug.h> 00031 #include <klistview.h> 00032 #include <klocale.h> 00033 #include <ktrader.h> 00034 00035 #include <tqbuttongroup.h> 00036 #include <tqcheckbox.h> 00037 #include <tqcombobox.h> 00038 #include <tqlabel.h> 00039 #include <tqlayout.h> 00040 00041 #include <kdepimmacros.h> 00042 00043 extern "C" 00044 { 00045 KDE_EXPORT KCModule *create_kontactconfig( TQWidget *parent, const char * ) { 00046 return new KcmKontact( parent, "kcmkontact" ); 00047 } 00048 } 00049 00050 class PluginItem : public TQListViewItem 00051 { 00052 public: 00053 PluginItem( TQListView *parent, const KService::Ptr &ptr ) 00054 : TQListViewItem( parent, ptr->name(), ptr->comment(), ptr->library() ), 00055 mPtr( ptr ) 00056 { 00057 } 00058 00059 KService::Ptr servicePtr() const 00060 { 00061 return mPtr; 00062 } 00063 00064 private: 00065 KService::Ptr mPtr; 00066 }; 00067 00068 KcmKontact::KcmKontact( TQWidget *parent, const char *name ) 00069 : KPrefsModule( Kontact::Prefs::self(), parent, name ) 00070 { 00071 TQBoxLayout *topLayout = new TQVBoxLayout( this ); 00072 TQBoxLayout *pluginStartupLayout = new TQHBoxLayout( topLayout ); 00073 topLayout->addStretch(); 00074 00075 KPrefsWidBool *forceStartupPlugin = addWidBool( Kontact::Prefs::self()->forceStartupPluginItem(), this ); 00076 pluginStartupLayout->addWidget( forceStartupPlugin->checkBox() ); 00077 00078 PluginSelection *selection = new PluginSelection( Kontact::Prefs::self()->forcedStartupPluginItem(), this ); 00079 addWid( selection ); 00080 00081 pluginStartupLayout->addWidget( selection->comboBox() ); 00082 selection->comboBox()->setEnabled( false ); 00083 00084 connect( forceStartupPlugin->checkBox(), TQT_SIGNAL( toggled( bool ) ), 00085 selection->comboBox(), TQT_SLOT( setEnabled( bool ) ) ); 00086 load(); 00087 } 00088 00089 const KAboutData* KcmKontact::aboutData() const 00090 { 00091 KAboutData *about = new KAboutData( I18N_NOOP( "kontactconfig" ), 00092 I18N_NOOP( "KDE Kontact" ), 00093 0, 0, KAboutData::License_GPL, 00094 I18N_NOOP( "(c), 2003 Cornelius Schumacher" ) ); 00095 00096 about->addAuthor( "Cornelius Schumacher", 0, "schumacher@kde.org" ); 00097 about->addAuthor( "Tobias Koenig", 0, "tokoe@kde.org" ); 00098 00099 return about; 00100 } 00101 00102 00103 PluginSelection::PluginSelection( KConfigSkeleton::ItemString *item, TQWidget *parent ) 00104 { 00105 mItem = item; 00106 mPluginCombo = new TQComboBox( parent ); 00107 connect( mPluginCombo, TQT_SIGNAL( activated( int ) ), TQT_SIGNAL( changed() ) ); 00108 } 00109 00110 PluginSelection::~PluginSelection() 00111 { 00112 } 00113 00114 void PluginSelection::readConfig() 00115 { 00116 const KTrader::OfferList offers = KTrader::self()->query( 00117 TQString::fromLatin1( "Kontact/Plugin" ), 00118 TQString( "[X-KDE-KontactPluginVersion] == %1" ).arg( KONTACT_PLUGIN_VERSION ) ); 00119 00120 int activeComponent = 0; 00121 mPluginCombo->clear(); 00122 for ( KService::List::ConstIterator it = offers.begin(); it != offers.end(); ++it ) { 00123 KService::Ptr service = *it; 00124 // skip summary only plugins 00125 TQVariant var = service->property( "X-KDE-KontactPluginHasPart" ); 00126 if ( var.isValid() && var.toBool() == false ) 00127 continue; 00128 mPluginCombo->insertItem( service->name() ); 00129 mPluginList.append( service ); 00130 00131 if ( service->property("X-KDE-PluginInfo-Name").toString() == mItem->value() ) 00132 activeComponent = mPluginList.count() - 1; 00133 } 00134 00135 mPluginCombo->setCurrentItem( activeComponent ); 00136 } 00137 00138 void PluginSelection::writeConfig() 00139 { 00140 KService::Ptr ptr = *( mPluginList.at( mPluginCombo->currentItem() ) ); 00141 mItem->setValue( ptr->property("X-KDE-PluginInfo-Name").toString() ); 00142 } 00143 00144 TQValueList<TQWidget *> PluginSelection::widgets() const 00145 { 00146 TQValueList<TQWidget *> widgets; 00147 widgets.append( mPluginCombo ); 00148 00149 return widgets; 00150 } 00151 00152 #include "kcmkontact.moc"