• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdepim
  • Sitemap
  • Contact Us
 

kontact

kcmkontactsummary.cpp

Go to the documentation of this file.
00001 /*
00002   This file is part of KDE Kontact.
00003 
00004   Copyright (c) 2004 Tobias Koenig <tokoe@kde.org>
00005   Copyright (c) 2008 Allen Winter <winter@kde.org>
00006 
00007   This program is free software; you can redistribute it and/or modify
00008   it under the terms of the GNU General Public License as published by
00009   the Free Software Foundation; either version 2 of the License, or
00010   (at your option) any later version.
00011 
00012   This program is distributed in the hope that it will be useful,
00013   but WITHOUT ANY WARRANTY; without even the implied warranty of
00014   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00015   GNU General Public License for more details.
00016 
00017   You should have received a copy of the GNU General Public License along
00018   with this program; if not, write to the Free Software Foundation, Inc.,
00019   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020 
00021   As a special exception, permission is given to link this program
00022   with any edition of Qt, and distribute the resulting executable,
00023   without including the source code for Qt in the source distribution.
00024 */
00025 
00026 #include "kcmkontactsummary.h"
00027 
00028 #include <kontactinterfaces/plugin.h>
00029 
00030 #include <kaboutdata.h>
00031 #include <kcomponentdata.h>
00032 #include <kconfig.h>
00033 #include <kdebug.h>
00034 #include <kdeversion.h>
00035 #include <kdialog.h>
00036 #include <kiconloader.h>
00037 #include <klocale.h>
00038 #include <kdemacros.h>
00039 #include <kplugininfo.h>
00040 #include <kservicetypetrader.h>
00041 
00042 #include <QLabel>
00043 #include <QVBoxLayout>
00044 #include <QTreeWidgetItem>
00045 
00046 extern "C"
00047 {
00048   KDE_EXPORT KCModule *create_kontactsummary( QWidget *parent, const char * ) {
00049     KComponentData inst( "kcmkontactsummary" );
00050     return new KCMKontactSummary( inst, parent );
00051   }
00052 }
00053 
00054 class PluginItem : public QTreeWidgetItem
00055 {
00056   public:
00057     PluginItem( const KPluginInfo &info, QTreeWidget *parent )
00058       : QTreeWidgetItem( parent ), mInfo( info )
00059     {
00060       setIcon( 0, KIcon( mInfo.icon() ) );
00061       setText( 0, mInfo.name() );
00062       setToolTip( 0, mInfo.comment() );
00063       setFlags( Qt::ItemIsEnabled | Qt::ItemIsUserCheckable );
00064     }
00065 
00066     KPluginInfo pluginInfo() const
00067     {
00068       return mInfo;
00069     }
00070 
00071     virtual QString text( int column ) const
00072     {
00073       if ( column == 0 ) {
00074         return mInfo.name();
00075       } else if ( column == 1 ) {
00076         return mInfo.comment();
00077       } else {
00078         return QString();
00079       }
00080     }
00081 
00082   private:
00083     KPluginInfo mInfo;
00084 };
00085 
00086 PluginView::PluginView( QWidget *parent )
00087   : QTreeWidget( parent )
00088 {
00089   setColumnCount( 1 );
00090   setHeaderLabel( i18nc( "@title:column plugin name", "Summary Plugin Name" ) );
00091 }
00092 
00093 PluginView::~PluginView()
00094 {
00095 }
00096 
00097 KCMKontactSummary::KCMKontactSummary( const KComponentData &inst, QWidget *parent )
00098   : KCModule( inst, parent )
00099 {
00100 #if KDE_IS_VERSION(4,0,71 )
00101   setButtons( NoAdditionalButton );
00102 #endif
00103   QVBoxLayout *layout = new QVBoxLayout( this );
00104   layout->setSpacing( KDialog::spacingHint() );
00105   layout->setMargin( 0 );
00106 
00107   QLabel *label =
00108     new QLabel( i18n( "Select the plugin summaries to show on the summary page." ), this );
00109   layout->addWidget( label );
00110 
00111   mPluginView = new PluginView( this );
00112   layout->addWidget( mPluginView );
00113 
00114   layout->setStretchFactor( mPluginView, 1 );
00115 
00116   load();
00117   connect( mPluginView, SIGNAL(itemChanged(QTreeWidgetItem*,int)),
00118            this, SLOT(changed()) );
00119 
00120   KAboutData *about = new KAboutData( I18N_NOOP( "kontactsummary" ), 0,
00121                                       ki18n( "KDE Kontact Summary" ),
00122                                       0, KLocalizedString(), KAboutData::License_GPL,
00123                                       ki18n( "(c), 2004 Tobias Koenig" ) );
00124 
00125   about->addAuthor( ki18n( "Tobias Koenig" ), KLocalizedString(), "tokoe@kde.org" );
00126   setAboutData( about );
00127 }
00128 
00129 void KCMKontactSummary::load()
00130 {
00131   KService::List offers = KServiceTypeTrader::self()->query(
00132       QString::fromLatin1( "Kontact/Plugin" ),
00133       QString( "[X-KDE-KontactPluginVersion] == %1" ).arg( KONTACT_PLUGIN_VERSION ) );
00134 
00135   QStringList activeSummaries;
00136 
00137   KConfig config( "kontact_summaryrc" );
00138   KConfigGroup grp( &config, QString() );
00139   if ( !grp.hasKey( "ActiveSummaries" ) ) {
00140     activeSummaries << "kontact_kaddressbookplugin";
00141     activeSummaries << "kontact_specialdatesplugin";
00142     activeSummaries << "kontact_korganizerplugin";
00143     activeSummaries << "kontact_todoplugin";
00144     activeSummaries << "kontact_knotesplugin";
00145     activeSummaries << "kontact_kmailplugin";
00146     activeSummaries << "kontact_weatherplugin";
00147     activeSummaries << "kontact_newstickerplugin";
00148     activeSummaries << "kontact_plannerplugin";
00149   } else {
00150     activeSummaries = grp.readEntry( "ActiveSummaries", QStringList() );
00151   }
00152 
00153   mPluginView->clear();
00154 
00155   KPluginInfo::List pluginList =
00156     KPluginInfo::fromServices( offers, KConfigGroup( &config, "Plugins" ) );
00157   KPluginInfo::List::Iterator it;
00158   for ( it = pluginList.begin(); it != pluginList.end(); ++it ) {
00159     it->load();
00160 
00161     if ( !it->isPluginEnabled() ) {
00162       continue;
00163     }
00164 
00165     QVariant var = it->property( "X-KDE-KontactPluginHasSummary" );
00166     if ( var.isValid() && var.toBool() == true ) {
00167       PluginItem *item = new PluginItem( *it, mPluginView );
00168 
00169       if ( activeSummaries.contains( it->pluginName() ) ) {
00170         item->setCheckState( 0, Qt::Checked );
00171       } else {
00172         item->setCheckState( 0, Qt::Unchecked );
00173       }
00174     }
00175   }
00176 }
00177 
00178 void KCMKontactSummary::save()
00179 {
00180   kDebug();
00181   QStringList activeSummaries;
00182 
00183   QTreeWidgetItemIterator it( mPluginView );
00184   while ( *it ) {
00185     PluginItem *item = static_cast<PluginItem *>( *it );
00186     if ( item->checkState( 0 ) == Qt::Checked ) {
00187       activeSummaries.append( item->pluginInfo().pluginName() );
00188     }
00189     ++it;
00190   }
00191 
00192   KConfig config( "kontact_summaryrc" );
00193   KConfigGroup grp( &config, QString() );
00194   kDebug() << "saving activesummaries " << activeSummaries;
00195   grp.writeEntry( "ActiveSummaries", activeSummaries );
00196 }
00197 
00198 #include "kcmkontactsummary.moc"

kontact

Skip menu "kontact"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal