kontact Library API Documentation

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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00019 
00020     As a special exception, permission is given to link this program
00021     with any edition of Qt, and distribute the resulting executable,
00022     without including the source code for Qt in the source distribution.
00023 */
00024 
00025 #include <kaboutdata.h>
00026 #include <kconfig.h>
00027 #include <kdebug.h>
00028 #include <kdialog.h>
00029 #include <kiconloader.h>
00030 #include <kiconloader.h>
00031 #include <klocale.h>
00032 #include <plugin.h>
00033 #include <kplugininfo.h>
00034 #include <ktrader.h>
00035 
00036 #include <qlayout.h>
00037 #include <qlabel.h>
00038 #include <qpixmap.h>
00039 
00040 #include "kcmkontactsummary.h"
00041 
00042 extern "C"
00043 {
00044   KCModule *create_kontactsummary( QWidget *parent, const char * ) {
00045     return new KCMKontactSummary( parent, "kcmkontactsummary" );
00046   }
00047 }
00048 
00049 class PluginItem : public QCheckListItem
00050 {
00051   public:
00052     PluginItem( KPluginInfo *info, KListView *parent )
00053       : QCheckListItem( parent, QString::null, QCheckListItem::CheckBox ),
00054         mInfo( info )
00055     {
00056       QPixmap pm = KGlobal::iconLoader()->loadIcon( mInfo->icon(), KIcon::Small );
00057       setPixmap( 0, pm );
00058     }
00059 
00060     KPluginInfo* pluginInfo() const
00061     {
00062       return mInfo;
00063     }
00064 
00065     virtual QString text( int column ) const
00066     {
00067       if ( column == 0 )
00068         return mInfo->name();
00069       else if ( column == 1 )
00070         return mInfo->comment();
00071       else
00072         return QString::null;
00073     }
00074 
00075   private:
00076     KPluginInfo *mInfo;
00077 };
00078 
00079 PluginView::PluginView( QWidget *parent, const char *name )
00080   : KListView( parent, name )
00081 {
00082   addColumn( i18n( "Name" ) );
00083   setAllColumnsShowFocus( true );
00084   setFullWidth( true );
00085 }
00086 
00087 PluginView::~PluginView()
00088 {
00089 }
00090 
00091 KCMKontactSummary::KCMKontactSummary( QWidget *parent, const char *name )
00092   : KCModule( parent, name )
00093 {
00094   QVBoxLayout *layout = new QVBoxLayout( this, KDialog::marginHint(), 
00095                                          KDialog::spacingHint() );
00096 
00097   QLabel *label = new QLabel( i18n( "Here you can select which summary plugins to have visible in your summary view." ), this );
00098   layout->addWidget( label );
00099 
00100   mPluginView = new PluginView( this );
00101   layout->addWidget( mPluginView );
00102 
00103   layout->setStretchFactor( mPluginView, 1 );
00104 
00105   connect( mPluginView, SIGNAL( clicked( QListViewItem* ) ),
00106            this, SLOT( itemClicked( QListViewItem* ) ) );
00107   load();
00108 }
00109 
00110 void KCMKontactSummary::load()
00111 {
00112   KTrader::OfferList offers = KTrader::self()->query(
00113       QString::fromLatin1( "Kontact/Plugin" ),
00114       QString( "[X-KDE-KontactPluginVersion] == %1" ).arg( KONTACT_PLUGIN_VERSION ) );
00115 
00116   QStringList activeSummaries;
00117 
00118   KConfig config( "kontact_summaryrc" );
00119   if ( !config.hasKey( "ActiveSummaries" ) ) {
00120     activeSummaries << "kontact_kaddressbookplugin";
00121     activeSummaries << "kontact_korganizerplugin";
00122     activeSummaries << "kontact_todoplugin";
00123     activeSummaries << "kontact_kpilotplugin";
00124     activeSummaries << "kontact_weatherplugin";
00125     activeSummaries << "kontact_newstickerplugin";
00126   } else {
00127     activeSummaries = config.readListEntry( "ActiveSummaries" );
00128   }
00129 
00130   mPluginView->clear();
00131   mPluginList.clear();
00132 
00133   mPluginList = KPluginInfo::fromServices( offers, &config, "Plugins" );
00134   KPluginInfo::List::Iterator it;
00135   for ( it = mPluginList.begin(); it != mPluginList.end(); ++it ) {
00136     (*it)->load();
00137 
00138     if ( !(*it)->isPluginEnabled() )
00139       continue;
00140 
00141     QVariant var = (*it)->property( "X-KDE-KontactPluginHasSummary" );
00142     if ( !var.isValid() )
00143       continue;
00144 
00145     if ( var.toBool() == true ) {
00146       PluginItem *item = new PluginItem( *it, mPluginView );
00147 
00148       if ( activeSummaries.find( (*it)->pluginName() ) != activeSummaries.end() )
00149         item->setOn( true );
00150     }
00151   }
00152 }
00153 
00154 void KCMKontactSummary::save()
00155 {
00156   QStringList activeSummaries;
00157 
00158   QListViewItemIterator it( mPluginView, QListViewItemIterator::Checked );
00159   while ( it.current() ) {
00160     PluginItem *item = static_cast<PluginItem*>( it.current() );
00161     activeSummaries.append( item->pluginInfo()->pluginName() );
00162     ++it;
00163   }
00164 
00165   KConfig config( "kontact_summaryrc" );
00166   config.writeEntry( "ActiveSummaries", activeSummaries );
00167 }
00168 
00169 void KCMKontactSummary::defaults()
00170 {
00171   emit changed( true );
00172 }
00173 
00174 const KAboutData* KCMKontactSummary::aboutData() const
00175 {
00176   KAboutData *about = new KAboutData( I18N_NOOP( "kontactsummary" ),
00177                                       I18N_NOOP( "KDE Kontact Summary" ),
00178                                       0, 0, KAboutData::License_GPL,
00179                                       I18N_NOOP( "(c), 2004 Tobias Koenig" ) );
00180 
00181   about->addAuthor( "Tobias Koenig", 0, "tokoe@kde.org" );
00182 
00183   return about;
00184 }
00185 
00186 void KCMKontactSummary::itemClicked( QListViewItem* )
00187 {
00188   emit changed( true );
00189 }
00190 
00191 #include "kcmkontactsummary.moc"
KDE Logo
This file is part of the documentation for kontact Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Mon Apr 4 04:50:12 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003