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

kontact

  • sources
  • kde-4.12
  • kdepim
  • kontact
  • plugins
  • summary
kcmkontactsummary.cpp
Go to the documentation of this file.
1 /*
2  This file is part of KDE Kontact.
3 
4  Copyright (c) 2004 Tobias Koenig <tokoe@kde.org>
5  Copyright (c) 2008 Allen Winter <winter@kde.org>
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License along
18  with this program; if not, write to the Free Software Foundation, Inc.,
19  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 
21  As a special exception, permission is given to link this program
22  with any edition of Qt, and distribute the resulting executable,
23  without including the source code for Qt in the source distribution.
24 */
25 
26 #include "kcmkontactsummary.h"
27 
28 #include <KontactInterface/Plugin>
29 
30 #include <KAboutData>
31 #include <KComponentData>
32 #include <KDialog>
33 #include <KIcon>
34 #include <KLocale>
35 #include <KPluginInfo>
36 #include <KService>
37 #include <KServiceTypeTrader>
38 
39 #include <QLabel>
40 #include <QVBoxLayout>
41 
42 extern "C"
43 {
44  KDE_EXPORT KCModule *create_kontactsummary( QWidget *parent, const char * ) {
45  KComponentData inst( "kcmkontactsummary" );
46  return new KCMKontactSummary( inst, parent );
47  }
48 }
49 
50 class PluginItem : public QTreeWidgetItem
51 {
52  public:
53  PluginItem( const KPluginInfo &info, QTreeWidget *parent )
54  : QTreeWidgetItem( parent ), mInfo( info )
55  {
56  setIcon( 0, KIcon( mInfo.icon() ) );
57  setText( 0, mInfo.name() );
58  setToolTip( 0, mInfo.comment() );
59  setFlags( Qt::ItemIsEnabled | Qt::ItemIsUserCheckable );
60  }
61 
62  KPluginInfo pluginInfo() const
63  {
64  return mInfo;
65  }
66 
67  virtual QString 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 QString();
75  }
76  }
77 
78  private:
79  KPluginInfo mInfo;
80 };
81 
82 PluginView::PluginView( QWidget *parent )
83  : QTreeWidget( parent )
84 {
85  setColumnCount( 1 );
86  setHeaderLabel( i18nc( "@title:column plugin name", "Summary Plugin Name" ) );
87  setRootIsDecorated(false);
88 }
89 
90 PluginView::~PluginView()
91 {
92 }
93 
94 KCMKontactSummary::KCMKontactSummary( const KComponentData &inst, QWidget *parent )
95  : KCModule( inst, parent )
96 {
97  setButtons( NoAdditionalButton );
98  QVBoxLayout *layout = new QVBoxLayout( this );
99  layout->setSpacing( KDialog::spacingHint() );
100  layout->setMargin( 0 );
101 
102  QLabel *label =
103  new QLabel( i18n( "Select the plugin summaries to show on the summary page." ), this );
104  layout->addWidget( label );
105 
106  mPluginView = new PluginView( this );
107  layout->addWidget( mPluginView );
108 
109  layout->setStretchFactor( mPluginView, 1 );
110 
111  load();
112  connect( mPluginView, SIGNAL(itemChanged(QTreeWidgetItem*,int)),
113  this, SLOT(changed()) );
114 
115  KAboutData *about = new KAboutData( I18N_NOOP( "kontactsummary" ), 0,
116  ki18n( "KDE Kontact Summary" ),
117  0, KLocalizedString(), KAboutData::License_GPL,
118  ki18n( "(c), 2004 Tobias Koenig" ) );
119 
120  about->addAuthor( ki18n( "Tobias Koenig" ), KLocalizedString(), "tokoe@kde.org" );
121  setAboutData( about );
122 }
123 
124 void KCMKontactSummary::load()
125 {
126  KService::List offers = KServiceTypeTrader::self()->query(
127  QString::fromLatin1( "Kontact/Plugin" ),
128  QString::fromLatin1( "[X-KDE-KontactPluginVersion] == %1" ).arg( KONTACT_PLUGIN_VERSION ) );
129 
130  QStringList activeSummaries;
131 
132  KConfig config( QLatin1String("kontact_summaryrc") );
133  KConfigGroup grp( &config, QString() );
134  if ( !grp.hasKey( "ActiveSummaries" ) ) {
135  activeSummaries << QLatin1String("kontact_kaddressbookplugin");
136  activeSummaries << QLatin1String("kontact_specialdatesplugin");
137  activeSummaries << QLatin1String("kontact_korganizerplugin");
138  activeSummaries << QLatin1String("kontact_todoplugin");
139  activeSummaries << QLatin1String("kontact_knotesplugin");
140  activeSummaries << QLatin1String("kontact_kmailplugin");
141  activeSummaries << QLatin1String("kontact_weatherplugin");
142  activeSummaries << QLatin1String("kontact_newstickerplugin");
143  activeSummaries << QLatin1String("kontact_plannerplugin");
144  } else {
145  activeSummaries = grp.readEntry( "ActiveSummaries", QStringList() );
146  }
147 
148  mPluginView->clear();
149 
150  KPluginInfo::List pluginList =
151  KPluginInfo::fromServices( offers, KConfigGroup( &config, "Plugins" ) );
152  KPluginInfo::List::Iterator it;
153  KPluginInfo::List::Iterator end(pluginList.end());
154  for ( it = pluginList.begin(); it != end; ++it ) {
155  it->load();
156 
157  if ( !it->isPluginEnabled() ) {
158  continue;
159  }
160 
161  QVariant var = it->property( QLatin1String("X-KDE-KontactPluginHasSummary") );
162  if ( var.isValid() && var.toBool() == true ) {
163  PluginItem *item = new PluginItem( *it, mPluginView );
164 
165  if ( activeSummaries.contains( it->pluginName() ) ) {
166  item->setCheckState( 0, Qt::Checked );
167  } else {
168  item->setCheckState( 0, Qt::Unchecked );
169  }
170  }
171  }
172 }
173 
174 void KCMKontactSummary::save()
175 {
176  QStringList activeSummaries;
177 
178  QTreeWidgetItemIterator it( mPluginView );
179  while ( *it ) {
180  PluginItem *item = static_cast<PluginItem *>( *it );
181  if ( item->checkState( 0 ) == Qt::Checked ) {
182  activeSummaries.append( item->pluginInfo().pluginName() );
183  }
184  ++it;
185  }
186 
187  KConfig config( QLatin1String("kontact_summaryrc") );
188  KConfigGroup grp( &config, QString() );
189  grp.writeEntry( "ActiveSummaries", activeSummaries );
190 }
191 
192 #include "kcmkontactsummary.moc"
kcmkontactsummary.h
PluginView
Definition: kcmkontactsummary.h:33
QTreeWidget
PluginView::~PluginView
~PluginView()
Definition: kcmkontactsummary.cpp:90
text
virtual QByteArray text(quint32 serialNumber) const =0
KCMKontactSummary::save
void save()
Definition: kcmkontactsummary.cpp:174
QWidget
PluginView::PluginView
PluginView(QWidget *parent)
Definition: kcmkontactsummary.cpp:82
KCMKontactSummary::KCMKontactSummary
KCMKontactSummary(const KComponentData &inst, QWidget *parent=0)
Definition: kcmkontactsummary.cpp:94
QLabel
create_kontactsummary
KCModule * create_kontactsummary(QWidget *parent, const char *)
Definition: kcmkontactsummary.cpp:44
KCMKontactSummary::load
void load()
Definition: kcmkontactsummary.cpp:124
KCModule
KCMKontactSummary
Definition: kcmkontactsummary.h:42
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:58:30 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kontact

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

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal