kcmkontactsummary.cpp
1/*
2 This file is part of KDE Kontact.
3
4 Copyright (c) 2004 Tobias Koenig <tokoe@kde.org>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
20 As a special exception, permission is given to link this program
21 with any edition of TQt, and distribute the resulting executable,
22 without including the source code for TQt in the source distribution.
23*/
24
25#include <tdeaboutdata.h>
26#include <tdeconfig.h>
27#include <kdebug.h>
28#include <kdialog.h>
29#include <kiconloader.h>
30#include <kiconloader.h>
31#include <tdelocale.h>
32#include <plugin.h>
33#include <kplugininfo.h>
34#include <ktrader.h>
35
36#include <tqlayout.h>
37#include <tqlabel.h>
38#include <tqpixmap.h>
39
40#include "kcmkontactsummary.h"
41
42#include <tdemacros.h>
43
44extern "C"
45{
46 TDE_EXPORT TDECModule *create_kontactsummary( TQWidget *parent, const char * ) {
47 return new KCMKontactSummary( parent, "kcmkontactsummary" );
48 }
49}
50
51class PluginItem : public TQCheckListItem
52{
53 public:
54 PluginItem( KPluginInfo *info, TDEListView *parent )
55 : TQCheckListItem( parent, TQString(), TQCheckListItem::CheckBox ),
56 mInfo( info )
57 {
58 TQPixmap pm = TDEGlobal::iconLoader()->loadIcon( mInfo->icon(), TDEIcon::Small );
59 setPixmap( 0, pm );
60 }
61
62 KPluginInfo* pluginInfo() const
63 {
64 return mInfo;
65 }
66
67 virtual TQString text( int column ) const
68 {
69 if ( column == 0 )
70 return mInfo->name();
71 else if ( column == 1 )
72 return mInfo->comment();
73 else
74 return TQString();
75 }
76
77 private:
78 KPluginInfo *mInfo;
79};
80
81PluginView::PluginView( TQWidget *parent, const char *name )
82 : TDEListView( parent, name )
83{
84 addColumn( i18n( "Name" ) );
85 setAllColumnsShowFocus( true );
86 setFullWidth( true );
87}
88
89PluginView::~PluginView()
90{
91}
92
93KCMKontactSummary::KCMKontactSummary( TQWidget *parent, const char *name )
94 : TDECModule( parent, name )
95{
96 TQVBoxLayout *layout = new TQVBoxLayout( this, 0, KDialog::spacingHint() );
97
98 TQLabel *label = new TQLabel( i18n( "Here you can select which summary plugins to have visible in your summary view." ), this );
99 layout->addWidget( label );
100
101 mPluginView = new PluginView( this );
102 layout->addWidget( mPluginView );
103
104 layout->setStretchFactor( mPluginView, 1 );
105
106 connect( mPluginView, TQ_SIGNAL( clicked( TQListViewItem* ) ),
107 this, TQ_SLOT( itemClicked( TQListViewItem* ) ) );
108 load();
109
110 TDEAboutData *about = new TDEAboutData( I18N_NOOP( "kontactsummary" ),
111 I18N_NOOP( "TDE Kontact Summary" ),
112 0, 0, TDEAboutData::License_GPL,
113 I18N_NOOP( "(c), 2004 Tobias Koenig" ) );
114
115 about->addAuthor( "Tobias Koenig", 0, "tokoe@kde.org" );
116 setAboutData( about );
117}
118
119void KCMKontactSummary::load()
120{
121 TDETrader::OfferList offers = TDETrader::self()->query(
122 TQString::fromLatin1( "Kontact/Plugin" ),
123 TQString( "[X-TDE-KontactPluginVersion] == %1" ).arg( KONTACT_PLUGIN_VERSION ) );
124
125 TQStringList activeSummaries;
126
127 TDEConfig config( "kontact_summaryrc" );
128 if ( !config.hasKey( "ActiveSummaries" ) ) {
129 activeSummaries << "kontact_kaddressbookplugin";
130 activeSummaries << "kontact_specialdatesplugin";
131 activeSummaries << "kontact_korganizerplugin";
132 activeSummaries << "kontact_todoplugin";
133 activeSummaries << "kontact_kpilotplugin";
134 activeSummaries << "kontact_weatherplugin";
135 activeSummaries << "kontact_newstickerplugin";
136 } else {
137 activeSummaries = config.readListEntry( "ActiveSummaries" );
138 }
139
140 mPluginView->clear();
141 mPluginList.clear();
142
143 mPluginList = KPluginInfo::fromServices( offers, &config, "Plugins" );
144 KPluginInfo::List::Iterator it;
145 TDEConfig *conf = new TDEConfig("kontactrc");
146 TDEConfigGroup *cg = new TDEConfigGroup( conf, "Plugins" );
147 for ( it = mPluginList.begin(); it != mPluginList.end(); ++it ) {
148 (*it)->load( cg );
149
150 if ( !(*it)->isPluginEnabled() )
151 continue;
152
153 TQVariant var = (*it)->property( "X-TDE-KontactPluginHasSummary" );
154 if ( !var.isValid() )
155 continue;
156
157 if ( var.toBool() == true ) {
158 PluginItem *item = new PluginItem( *it, mPluginView );
159
160 if ( activeSummaries.find( (*it)->pluginName() ) != activeSummaries.end() )
161 item->setOn( true );
162 }
163 }
164}
165
166void KCMKontactSummary::save()
167{
168 TQStringList activeSummaries;
169
170 TQListViewItemIterator it( mPluginView, TQListViewItemIterator::Checked );
171 while ( it.current() ) {
172 PluginItem *item = static_cast<PluginItem*>( it.current() );
173 activeSummaries.append( item->pluginInfo()->pluginName() );
174 ++it;
175 }
176
177 TDEConfig config( "kontact_summaryrc" );
178 config.writeEntry( "ActiveSummaries", activeSummaries );
179}
180
181void KCMKontactSummary::defaults()
182{
183 emit changed( true );
184}
185
186void KCMKontactSummary::itemClicked( TQListViewItem* )
187{
188 emit changed( true );
189}
190
191#include "kcmkontactsummary.moc"