kontact

kcmkontactsummary.cpp
00001 /*
00002     This file is part of KDE Kontact.
00003 
00004     Copyright (c) 2004 Tobias Koenig <tokoe@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 <tdeaboutdata.h>
00026 #include <tdeconfig.h>
00027 #include <kdebug.h>
00028 #include <kdialog.h>
00029 #include <kiconloader.h>
00030 #include <kiconloader.h>
00031 #include <tdelocale.h>
00032 #include <plugin.h>
00033 #include <kplugininfo.h>
00034 #include <ktrader.h>
00035 
00036 #include <tqlayout.h>
00037 #include <tqlabel.h>
00038 #include <tqpixmap.h>
00039 
00040 #include "kcmkontactsummary.h"
00041 
00042 #include <tdepimmacros.h>
00043 
00044 extern "C"
00045 {
00046   KDE_EXPORT TDECModule *create_kontactsummary( TQWidget *parent, const char * ) {
00047     return new KCMKontactSummary( parent, "kcmkontactsummary" );
00048   }
00049 }
00050 
00051 class PluginItem : public TQCheckListItem
00052 {
00053   public:
00054     PluginItem( KPluginInfo *info, TDEListView *parent )
00055       : TQCheckListItem( parent, TQString(), TQCheckListItem::CheckBox ),
00056         mInfo( info )
00057     {
00058       TQPixmap pm = TDEGlobal::iconLoader()->loadIcon( mInfo->icon(), TDEIcon::Small );
00059       setPixmap( 0, pm );
00060     }
00061 
00062     KPluginInfo* pluginInfo() const
00063     {
00064       return mInfo;
00065     }
00066 
00067     virtual TQString text( int column ) const
00068     {
00069       if ( column == 0 )
00070         return mInfo->name();
00071       else if ( column == 1 )
00072         return mInfo->comment();
00073       else
00074         return TQString();
00075     }
00076 
00077   private:
00078     KPluginInfo *mInfo;
00079 };
00080 
00081 PluginView::PluginView( TQWidget *parent, const char *name )
00082   : TDEListView( parent, name )
00083 {
00084   addColumn( i18n( "Name" ) );
00085   setAllColumnsShowFocus( true );
00086   setFullWidth( true );
00087 }
00088 
00089 PluginView::~PluginView()
00090 {
00091 }
00092 
00093 KCMKontactSummary::KCMKontactSummary( TQWidget *parent, const char *name )
00094   : TDECModule( parent, name )
00095 {
00096   TQVBoxLayout *layout = new TQVBoxLayout( this, 0, KDialog::spacingHint() );
00097 
00098   TQLabel *label = new TQLabel( i18n( "Here you can select which summary plugins to have visible in your summary view." ), this );
00099   layout->addWidget( label );
00100 
00101   mPluginView = new PluginView( this );
00102   layout->addWidget( mPluginView );
00103 
00104   layout->setStretchFactor( mPluginView, 1 );
00105 
00106   connect( mPluginView, TQT_SIGNAL( clicked( TQListViewItem* ) ),
00107            this, TQT_SLOT( itemClicked( TQListViewItem* ) ) );
00108   load();
00109 
00110   TDEAboutData *about = new TDEAboutData( I18N_NOOP( "kontactsummary" ),
00111                                       I18N_NOOP( "TDE Kontact Summary" ),
00112                                       0, 0, TDEAboutData::License_GPL,
00113                                       I18N_NOOP( "(c), 2004 Tobias Koenig" ) );
00114 
00115   about->addAuthor( "Tobias Koenig", 0, "tokoe@kde.org" );
00116   setAboutData( about );
00117 }
00118 
00119 void KCMKontactSummary::load()
00120 {
00121   TDETrader::OfferList offers = TDETrader::self()->query(
00122       TQString::fromLatin1( "Kontact/Plugin" ),
00123       TQString( "[X-TDE-KontactPluginVersion] == %1" ).arg( KONTACT_PLUGIN_VERSION ) );
00124 
00125   TQStringList activeSummaries;
00126 
00127   TDEConfig config( "kontact_summaryrc" );
00128   if ( !config.hasKey( "ActiveSummaries" ) ) {
00129     activeSummaries << "kontact_kaddressbookplugin";
00130     activeSummaries << "kontact_specialdatesplugin";
00131     activeSummaries << "kontact_korganizerplugin";
00132     activeSummaries << "kontact_todoplugin";
00133     activeSummaries << "kontact_kpilotplugin";
00134     activeSummaries << "kontact_weatherplugin";
00135     activeSummaries << "kontact_newstickerplugin";
00136   } else {
00137     activeSummaries = config.readListEntry( "ActiveSummaries" );
00138   }
00139 
00140   mPluginView->clear();
00141   mPluginList.clear();
00142 
00143   mPluginList = KPluginInfo::fromServices( offers, &config, "Plugins" );
00144   KPluginInfo::List::Iterator it;
00145   TDEConfig *conf = new TDEConfig("kontactrc");
00146   TDEConfigGroup *cg = new TDEConfigGroup( conf, "Plugins" );
00147   for ( it = mPluginList.begin(); it != mPluginList.end(); ++it ) {
00148       (*it)->load( cg );
00149 
00150     if ( !(*it)->isPluginEnabled() )
00151       continue;
00152 
00153     TQVariant var = (*it)->property( "X-TDE-KontactPluginHasSummary" );
00154     if ( !var.isValid() )
00155       continue;
00156 
00157     if ( var.toBool() == true ) {
00158       PluginItem *item = new PluginItem( *it, mPluginView );
00159 
00160       if ( activeSummaries.find( (*it)->pluginName() ) != activeSummaries.end() )
00161         item->setOn( true );
00162     }
00163   }
00164 }
00165 
00166 void KCMKontactSummary::save()
00167 {
00168   TQStringList activeSummaries;
00169 
00170   TQListViewItemIterator it( mPluginView, TQListViewItemIterator::Checked );
00171   while ( it.current() ) {
00172     PluginItem *item = static_cast<PluginItem*>( it.current() );
00173     activeSummaries.append( item->pluginInfo()->pluginName() );
00174     ++it;
00175   }
00176 
00177   TDEConfig config( "kontact_summaryrc" );
00178   config.writeEntry( "ActiveSummaries", activeSummaries );
00179 }
00180 
00181 void KCMKontactSummary::defaults()
00182 {
00183   emit changed( true );
00184 }
00185 
00186 void KCMKontactSummary::itemClicked( TQListViewItem* )
00187 {
00188   emit changed( true );
00189 }
00190 
00191 #include "kcmkontactsummary.moc"