kontact
kcmkontactsummary.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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"