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_knotesplugin";
00124     activeSummaries << "kontact_kmailplugin";
00125     activeSummaries << "kontact_weatherplugin";
00126     activeSummaries << "kontact_newstickerplugin";
00127   } else {
00128     activeSummaries = config.readListEntry( "ActiveSummaries" );
00129   }
00130 
00131   mPluginView->clear();
00132   mPluginList.clear();
00133 
00134   mPluginList = KPluginInfo::fromServices( offers, &config, "Plugins" );
00135   KPluginInfo::List::Iterator it;
00136   for ( it = mPluginList.begin(); it != mPluginList.end(); ++it ) {
00137     (*it)->load();
00138 
00139     if ( !(*it)->isPluginEnabled() )
00140       continue;
00141 
00142     QVariant var = (*it)->property( "X-KDE-KontactPluginHasSummary" );
00143     if ( !var.isValid() )
00144       continue;
00145 
00146     if ( var.toBool() == true ) {
00147       PluginItem *item = new PluginItem( *it, mPluginView );
00148 
00149       if ( activeSummaries.find( (*it)->pluginName() ) != activeSummaries.end() )
00150         item->setOn( true );
00151     }
00152   }
00153 }
00154 
00155 void KCMKontactSummary::save()
00156 {
00157   QStringList activeSummaries;
00158 
00159   QListViewItemIterator it( mPluginView, QListViewItemIterator::Checked );
00160   while ( it.current() ) {
00161     PluginItem *item = static_cast<PluginItem*>( it.current() );
00162     activeSummaries.append( item->pluginInfo()->pluginName() );
00163     ++it;
00164   }
00165 
00166   KConfig config( "kontact_summaryrc" );
00167   config.writeEntry( "ActiveSummaries", activeSummaries );
00168 }
00169 
00170 void KCMKontactSummary::defaults()
00171 {
00172   emit changed( true );
00173 }
00174 
00175 const KAboutData* KCMKontactSummary::aboutData() const
00176 {
00177   KAboutData *about = new KAboutData( I18N_NOOP( "kontactsummary" ),
00178                                       I18N_NOOP( "KDE Kontact Summary" ),
00179                                       0, 0, KAboutData::License_GPL,
00180                                       I18N_NOOP( "(c), 2004 Tobias Koenig" ) );
00181 
00182   about->addAuthor( "Tobias Koenig", 0, "tokoe@kde.org" );
00183 
00184   return about;
00185 }
00186 
00187 void KCMKontactSummary::itemClicked( QListViewItem* )
00188 {
00189   emit changed( true );
00190 }
00191 
00192 #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 Wed Oct 17 09:56:56 2007 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003