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 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 #include <kdepimmacros.h>
00043 
00044 extern "C"
00045 {
00046   KDE_EXPORT KCModule *create_kontactsummary( QWidget *parent, const char * ) {
00047     return new KCMKontactSummary( parent, "kcmkontactsummary" );
00048   }
00049 }
00050 
00051 class PluginItem : public QCheckListItem
00052 {
00053   public:
00054     PluginItem( KPluginInfo *info, KListView *parent )
00055       : QCheckListItem( parent, QString::null, QCheckListItem::CheckBox ),
00056         mInfo( info )
00057     {
00058       QPixmap pm = KGlobal::iconLoader()->loadIcon( mInfo->icon(), KIcon::Small );
00059       setPixmap( 0, pm );
00060     }
00061 
00062     KPluginInfo* pluginInfo() const
00063     {
00064       return mInfo;
00065     }
00066 
00067     virtual QString 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 QString::null;
00075     }
00076 
00077   private:
00078     KPluginInfo *mInfo;
00079 };
00080 
00081 PluginView::PluginView( QWidget *parent, const char *name )
00082   : KListView( parent, name )
00083 {
00084   addColumn( i18n( "Name" ) );
00085   setAllColumnsShowFocus( true );
00086   setFullWidth( true );
00087 }
00088 
00089 PluginView::~PluginView()
00090 {
00091 }
00092 
00093 KCMKontactSummary::KCMKontactSummary( QWidget *parent, const char *name )
00094   : KCModule( parent, name )
00095 {
00096   QVBoxLayout *layout = new QVBoxLayout( this, 0, KDialog::spacingHint() );
00097 
00098   QLabel *label = new QLabel( 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, SIGNAL( clicked( QListViewItem* ) ),
00107            this, SLOT( itemClicked( QListViewItem* ) ) );
00108   load();
00109 
00110   KAboutData *about = new KAboutData( I18N_NOOP( "kontactsummary" ),
00111                                       I18N_NOOP( "KDE Kontact Summary" ),
00112                                       0, 0, KAboutData::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   KTrader::OfferList offers = KTrader::self()->query(
00122       QString::fromLatin1( "Kontact/Plugin" ),
00123       QString( "[X-KDE-KontactPluginVersion] == %1" ).arg( KONTACT_PLUGIN_VERSION ) );
00124 
00125   QStringList activeSummaries;
00126 
00127   KConfig 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   for ( it = mPluginList.begin(); it != mPluginList.end(); ++it ) {
00146     (*it)->load();
00147 
00148     if ( !(*it)->isPluginEnabled() )
00149       continue;
00150 
00151     QVariant var = (*it)->property( "X-KDE-KontactPluginHasSummary" );
00152     if ( !var.isValid() )
00153       continue;
00154 
00155     if ( var.toBool() == true ) {
00156       PluginItem *item = new PluginItem( *it, mPluginView );
00157 
00158       if ( activeSummaries.find( (*it)->pluginName() ) != activeSummaries.end() )
00159         item->setOn( true );
00160     }
00161   }
00162 }
00163 
00164 void KCMKontactSummary::save()
00165 {
00166   QStringList activeSummaries;
00167 
00168   QListViewItemIterator it( mPluginView, QListViewItemIterator::Checked );
00169   while ( it.current() ) {
00170     PluginItem *item = static_cast<PluginItem*>( it.current() );
00171     activeSummaries.append( item->pluginInfo()->pluginName() );
00172     ++it;
00173   }
00174 
00175   KConfig config( "kontact_summaryrc" );
00176   config.writeEntry( "ActiveSummaries", activeSummaries );
00177 }
00178 
00179 void KCMKontactSummary::defaults()
00180 {
00181   emit changed( true );
00182 }
00183 
00184 void KCMKontactSummary::itemClicked( QListViewItem* )
00185 {
00186   emit changed( true );
00187 }
00188 
00189 #include "kcmkontactsummary.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys