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

KDECore

  • sources
  • kde-4.14
  • kdelibs
  • kdecore
  • services
kplugininfo.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE project
2  Copyright (C) 2003,2007 Matthias Kretz <kretz@kde.org>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License version 2 as published by the Free Software Foundation.
7 
8  This library is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  Library General Public License for more details.
12 
13  You should have received a copy of the GNU Library General Public License
14  along with this library; see the file COPYING.LIB. If not, write to
15  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16  Boston, MA 02110-1301, USA.
17 
18 */
19 
20 #include "kplugininfo.h"
21 #include <kservicetypetrader.h>
22 #include <kdebug.h>
23 #include <kglobal.h>
24 #include <kstandarddirs.h>
25 #include <kdesktopfile.h>
26 #include <kservice.h>
27 #include <QList>
28 #include <kconfiggroup.h>
29 
30 //#ifndef NDEBUG
31 #define KPLUGININFO_ISVALID_ASSERTION \
32  do { \
33  if (!d) { \
34  kFatal(703) << "Accessed invalid KPluginInfo object"; \
35  } \
36  } while (false)
37 //#else
38 //#define KPLUGININFO_ISVALID_ASSERTION
39 //#endif
40 
41 class KPluginInfoPrivate : public QSharedData
42 {
43  public:
44  KPluginInfoPrivate()
45  : hidden( false )
46  , enabledbydefault( false )
47  , pluginenabled( false )
48  , kcmservicesCached( false )
49  {}
50 
51  QString entryPath; // the filename of the file containing all the info
52  QString name;
53  QString comment;
54  QString icon;
55  QString author;
56  QString email;
57  QString pluginName; // the name attribute in the .rc file
58  QString version;
59  QString website; // URL to the website of the plugin/author
60  QString category;
61  QString license;
62  QStringList dependencies;
63 
64  bool hidden : 1;
65  bool enabledbydefault : 1;
66  bool pluginenabled : 1;
67  mutable bool kcmservicesCached : 1;
68 
69  KConfigGroup config;
70  KService::Ptr service;
71  mutable QList<KService::Ptr> kcmservices;
72 
73  static int debugArea() {
74  static int s_area = KDebug::registerArea("kdecore (KPluginInfo)");
75  return s_area;
76  }
77 };
78 
79 KPluginInfo::KPluginInfo( const QString & filename, const char* resource )
80 : d( new KPluginInfoPrivate )
81 {
82  KDesktopFile file( resource, filename );
83 
84  d->entryPath = filename;
85 
86  KConfigGroup cg = file.desktopGroup();
87  d->hidden = cg.readEntry("Hidden", false);
88  if( d->hidden )
89  return;
90 
91  d->name = file.readName();
92  d->comment = file.readComment();
93  d->icon = cg.readEntryUntranslated( "Icon" );
94  d->author = cg.readEntryUntranslated( "X-KDE-PluginInfo-Author" );
95  d->email = cg.readEntryUntranslated( "X-KDE-PluginInfo-Email" );
96  d->pluginName = cg.readEntryUntranslated( "X-KDE-PluginInfo-Name" );
97  d->version = cg.readEntryUntranslated( "X-KDE-PluginInfo-Version" );
98  d->website = cg.readEntryUntranslated( "X-KDE-PluginInfo-Website" );
99  d->category = cg.readEntryUntranslated( "X-KDE-PluginInfo-Category" );
100  d->license = cg.readEntryUntranslated( "X-KDE-PluginInfo-License" );
101  d->dependencies = cg.readEntry( "X-KDE-PluginInfo-Depends", QStringList() );
102  d->enabledbydefault = cg.readEntry(
103  "X-KDE-PluginInfo-EnabledByDefault", false);
104 }
105 
106 KPluginInfo::KPluginInfo( const KService::Ptr service )
107 : d( new KPluginInfoPrivate )
108 {
109  if (!service) {
110  d = 0; // isValid() == false
111  return;
112  }
113  d->service = service;
114  d->entryPath = service->entryPath();
115 
116  if ( service->isDeleted() )
117  {
118  d->hidden = true;
119  return;
120  }
121 
122  d->name = service->name();
123  d->comment = service->comment();
124  d->icon = service->icon();
125  d->author = service->property( QLatin1String("X-KDE-PluginInfo-Author") ).toString();
126  d->email = service->property( QLatin1String("X-KDE-PluginInfo-Email") ).toString();
127  d->pluginName = service->property( QLatin1String("X-KDE-PluginInfo-Name") ).toString();
128  d->version = service->property( QLatin1String("X-KDE-PluginInfo-Version") ).toString();
129  d->website = service->property( QLatin1String("X-KDE-PluginInfo-Website") ).toString();
130  d->category = service->property( QLatin1String("X-KDE-PluginInfo-Category") ).toString();
131  d->license = service->property( QLatin1String("X-KDE-PluginInfo-License") ).toString();
132  d->dependencies =
133  service->property( QLatin1String("X-KDE-PluginInfo-Depends") ).toStringList();
134  QVariant tmp = service->property( QLatin1String("X-KDE-PluginInfo-EnabledByDefault") );
135  d->enabledbydefault = tmp.isValid() ? tmp.toBool() : false;
136 }
137 
138 KPluginInfo::KPluginInfo()
139  : d(0) // isValid() == false
140 {
141 }
142 
143 bool KPluginInfo::isValid() const
144 {
145  return d.data() != 0;
146 }
147 
148 KPluginInfo::KPluginInfo(const KPluginInfo &rhs)
149  : d(rhs.d)
150 {
151 }
152 
153 KPluginInfo &KPluginInfo::operator=(const KPluginInfo &rhs)
154 {
155  d = rhs.d;
156  return *this;
157 }
158 
159 bool KPluginInfo::operator==(const KPluginInfo &rhs) const
160 {
161  return d == rhs.d;
162 }
163 
164 bool KPluginInfo::operator!=(const KPluginInfo &rhs) const
165 {
166  return d != rhs.d;
167 }
168 
169 bool KPluginInfo::operator<(const KPluginInfo &rhs) const
170 {
171  if (category() < rhs.category()) {
172  return true;
173  }
174  if (category() == rhs.category()) {
175  return name() < rhs.name();
176  }
177  return false;
178 }
179 
180 bool KPluginInfo::operator>(const KPluginInfo &rhs) const
181 {
182  if (category() > rhs.category()) {
183  return true;
184  }
185  if (category() == rhs.category()) {
186  return name() > rhs.name();
187  }
188  return false;
189 }
190 
191 KPluginInfo::~KPluginInfo()
192 {
193 }
194 
195 QList<KPluginInfo> KPluginInfo::fromServices(const KService::List &services, const KConfigGroup &config)
196 {
197  QList<KPluginInfo> infolist;
198  for( KService::List::ConstIterator it = services.begin();
199  it != services.end(); ++it )
200  {
201  KPluginInfo info(*it);
202  info.setConfig(config);
203  infolist += info;
204  }
205  return infolist;
206 }
207 
208 QList<KPluginInfo> KPluginInfo::fromFiles(const QStringList &files, const KConfigGroup &config)
209 {
210  QList<KPluginInfo> infolist;
211  for( QStringList::ConstIterator it = files.begin(); it != files.end(); ++it )
212  {
213  KPluginInfo info(*it);
214  info.setConfig(config);
215  infolist += info;
216  }
217  return infolist;
218 }
219 
220 QList<KPluginInfo> KPluginInfo::fromKPartsInstanceName(const QString &name, const KConfigGroup &config)
221 {
222  const QStringList files = KGlobal::dirs()->findAllResources(
223  "data", name + QString::fromLatin1("/kpartplugins/*.desktop"),
224  KStandardDirs::Recursive );
225  return fromFiles(files, config);
226 }
227 
228 bool KPluginInfo::isHidden() const
229 {
230  KPLUGININFO_ISVALID_ASSERTION;
231  return d->hidden;
232 }
233 
234 void KPluginInfo::setPluginEnabled( bool enabled )
235 {
236  KPLUGININFO_ISVALID_ASSERTION;
237  //kDebug( d->debugArea() ) ;
238  d->pluginenabled = enabled;
239 }
240 
241 bool KPluginInfo::isPluginEnabled() const
242 {
243  KPLUGININFO_ISVALID_ASSERTION;
244  //kDebug( d->debugArea() ) ;
245  return d->pluginenabled;
246 }
247 
248 bool KPluginInfo::isPluginEnabledByDefault() const
249 {
250  KPLUGININFO_ISVALID_ASSERTION;
251  //kDebug( d->debugArea() ) ;
252  return d->enabledbydefault;
253 }
254 
255 QString KPluginInfo::name() const
256 {
257  KPLUGININFO_ISVALID_ASSERTION;
258  return d->name;
259 }
260 
261 QString KPluginInfo::comment() const
262 {
263  KPLUGININFO_ISVALID_ASSERTION;
264  return d->comment;
265 }
266 
267 QString KPluginInfo::icon() const
268 {
269  KPLUGININFO_ISVALID_ASSERTION;
270  return d->icon;
271 }
272 
273 QString KPluginInfo::entryPath() const
274 {
275  KPLUGININFO_ISVALID_ASSERTION;
276  return d->entryPath;
277 }
278 
279 QString KPluginInfo::author() const
280 {
281  KPLUGININFO_ISVALID_ASSERTION;
282  return d->author;
283 }
284 
285 QString KPluginInfo::email() const
286 {
287  KPLUGININFO_ISVALID_ASSERTION;
288  return d->email;
289 }
290 
291 QString KPluginInfo::category() const
292 {
293  KPLUGININFO_ISVALID_ASSERTION;
294  return d->category;
295 }
296 
297 QString KPluginInfo::pluginName() const
298 {
299  KPLUGININFO_ISVALID_ASSERTION;
300  return d->pluginName;
301 }
302 
303 QString KPluginInfo::version() const
304 {
305  KPLUGININFO_ISVALID_ASSERTION;
306  return d->version;
307 }
308 
309 QString KPluginInfo::website() const
310 {
311  KPLUGININFO_ISVALID_ASSERTION;
312  return d->website;
313 }
314 
315 QString KPluginInfo::license() const
316 {
317  KPLUGININFO_ISVALID_ASSERTION;
318  return d->license;
319 }
320 
321 KAboutLicense KPluginInfo::fullLicense() const
322 {
323  KPLUGININFO_ISVALID_ASSERTION;
324  return KAboutLicense::byKeyword(d->license);
325 }
326 
327 QStringList KPluginInfo::dependencies() const
328 {
329  KPLUGININFO_ISVALID_ASSERTION;
330  return d->dependencies;
331 }
332 
333 KService::Ptr KPluginInfo::service() const
334 {
335  KPLUGININFO_ISVALID_ASSERTION;
336  return d->service;
337 }
338 
339 QList<KService::Ptr> KPluginInfo::kcmServices() const
340 {
341  KPLUGININFO_ISVALID_ASSERTION;
342  if ( !d->kcmservicesCached )
343  {
344  d->kcmservices = KServiceTypeTrader::self()->query( QLatin1String("KCModule"), QLatin1Char('\'') + d->pluginName +
345  QString::fromLatin1("' in [X-KDE-ParentComponents]") );
346  kDebug(d->debugArea()) << "found" << d->kcmservices.count() << "offers for" << d->pluginName;
347 
348  d->kcmservicesCached = true;
349  }
350 
351  return d->kcmservices;
352 }
353 
354 void KPluginInfo::setConfig(const KConfigGroup &config)
355 {
356  KPLUGININFO_ISVALID_ASSERTION;
357  d->config = config;
358 }
359 
360 KConfigGroup KPluginInfo::config() const
361 {
362  KPLUGININFO_ISVALID_ASSERTION;
363  return d->config;
364 }
365 
366 QVariant KPluginInfo::property( const QString & key ) const
367 {
368  KPLUGININFO_ISVALID_ASSERTION;
369  if( d->service )
370  return d->service->property( key );
371  else
372  return QVariant();
373 }
374 
375 void KPluginInfo::save(KConfigGroup config)
376 {
377  KPLUGININFO_ISVALID_ASSERTION;
378  //kDebug( d->debugArea() ) ;
379  if (config.isValid()) {
380  config.writeEntry(d->pluginName + QString::fromLatin1("Enabled"), isPluginEnabled());
381  } else {
382  if (!d->config.isValid()) {
383  kWarning( d->debugArea() ) << "no KConfigGroup, cannot save";
384  return;
385  }
386  d->config.writeEntry(d->pluginName + QString::fromLatin1("Enabled"), isPluginEnabled());
387  }
388 }
389 
390 void KPluginInfo::load(const KConfigGroup &config)
391 {
392  KPLUGININFO_ISVALID_ASSERTION;
393  //kDebug( d->debugArea() ) ;
394  if (config.isValid()) {
395  setPluginEnabled(config.readEntry(d->pluginName + QString::fromLatin1("Enabled"), isPluginEnabledByDefault()));
396  } else {
397  if (!d->config.isValid()) {
398  kWarning( d->debugArea() ) << "no KConfigGroup, cannot load";
399  return;
400  }
401  setPluginEnabled(d->config.readEntry(d->pluginName + QString::fromLatin1("Enabled"), isPluginEnabledByDefault()));
402  }
403 }
404 
405 void KPluginInfo::defaults()
406 {
407  //kDebug( d->debugArea() ) ;
408  setPluginEnabled( isPluginEnabledByDefault() );
409 }
410 
411 uint qHash(const KPluginInfo &p)
412 {
413  return qHash(reinterpret_cast<quint64>(p.d.data()));
414 }
415 
416 #undef KPLUGININFO_ISVALID_ASSERTION
417 
418 // vim: sw=4 sts=4 et
KAboutLicense
This class is used to store information about a license.
Definition: kaboutdata.h:894
KPLUGININFO_ISVALID_ASSERTION
#define KPLUGININFO_ISVALID_ASSERTION
Definition: kplugininfo.cpp:31
KPluginInfo::KPluginInfo
KPluginInfo()
Creates an invalid plugin.
Definition: kplugininfo.cpp:138
KSharedPtr< KService >
KPluginInfo
Information about a plugin.
Definition: kplugininfo.h:43
KPluginInfo::category
QString category() const
Definition: kplugininfo.cpp:291
KPluginInfo::property
QVariant property(const QString &key) const
Definition: kplugininfo.cpp:366
kdebug.h
KPluginInfo::email
QString email() const
Definition: kplugininfo.cpp:285
KPluginInfo::fromFiles
static KPluginInfo::List fromFiles(const QStringList &files, const KConfigGroup &config=KConfigGroup())
Definition: kplugininfo.cpp:208
KPluginInfo::~KPluginInfo
~KPluginInfo()
Definition: kplugininfo.cpp:191
KServiceTypeTrader::self
static KServiceTypeTrader * self()
This is a static pointer to the KServiceTypeTrader singleton.
Definition: kservicetypetrader.cpp:37
KDesktopFile::readComment
QString readComment() const
Returns the value of the "Comment=" entry.
Definition: kdesktopfile.cpp:198
KPluginInfo::isPluginEnabled
bool isPluginEnabled() const
Definition: kplugininfo.cpp:241
KPluginInfo::service
KService::Ptr service() const
Definition: kplugininfo.cpp:333
KPluginInfo::entryPath
QString entryPath() const
Definition: kplugininfo.cpp:273
QExplicitlySharedDataPointer::data
T * data() const
KPluginInfo::fromKPartsInstanceName
static KPluginInfo::List fromKPartsInstanceName(const QString &componentName, const KConfigGroup &config=KConfigGroup())
Definition: kplugininfo.cpp:220
KService::property
QVariant property(const QString &_name, QVariant::Type t) const
Returns the requested property.
Definition: kservice.cpp:498
KPluginInfo::isValid
bool isValid() const
Returns whether the object is valid.
Definition: kplugininfo.cpp:143
KGlobal::dirs
KStandardDirs * dirs()
Returns the application standard dirs object.
KPluginInfo::license
QString license() const
Definition: kplugininfo.cpp:315
KPluginInfo::comment
QString comment() const
Definition: kplugininfo.cpp:261
KConfigGroup::writeEntry
void writeEntry(const QString &key, const QVariant &value, WriteConfigFlags pFlags=Normal)
Writes a value to the configuration object.
Definition: kconfiggroup.cpp:1037
KPluginInfo::operator<
bool operator<(const KPluginInfo &rhs) const
Less than relation comparing the categories and if they are the same using the names.
Definition: kplugininfo.cpp:169
KPluginInfo::version
QString version() const
Definition: kplugininfo.cpp:303
KConfigGroup::isValid
bool isValid() const
Whether the group is valid.
Definition: kconfiggroup.cpp:445
KService::comment
QString comment() const
Returns the descriptive comment for the service, if there is one.
Definition: kservice.cpp:907
kdesktopfile.h
kplugininfo.h
KGlobal::config
KSharedConfigPtr config()
Returns the general config object.
Definition: kglobal.cpp:139
kservicetypetrader.h
KPluginInfo::dependencies
QStringList dependencies() const
Definition: kplugininfo.cpp:327
kglobal.h
KPluginInfo::load
void load(const KConfigGroup &config=KConfigGroup())
Load the state of the plugin - enabled or not.
Definition: kplugininfo.cpp:390
QSharedData
KSycocaEntry::entryPath
QString entryPath() const
Definition: ksycocaentry.cpp:104
KConfigGroup::readEntryUntranslated
QString readEntryUntranslated(const QString &pKey, const QString &aDefault=QString()) const
Reads an untranslated string entry.
Definition: kconfiggroup.cpp:637
KStandardDirs::Recursive
Definition: kstandarddirs.h:191
KPluginInfo::operator!=
bool operator!=(const KPluginInfo &rhs) const
Compares two objects whether they don't share the same data.
Definition: kplugininfo.cpp:164
KPluginInfo::setPluginEnabled
void setPluginEnabled(bool enabled)
Set whether the plugin is currently loaded.
Definition: kplugininfo.cpp:234
KPluginInfo::kcmServices
QList< KService::Ptr > kcmServices() const
Definition: kplugininfo.cpp:339
KPluginInfo::defaults
void defaults()
Restore defaults (enabled or not).
Definition: kplugininfo.cpp:405
KDebug::registerArea
static int registerArea(const QByteArray &areaName, bool enabled=true)
Definition: kdebug.cpp:856
KPluginInfo::operator==
bool operator==(const KPluginInfo &rhs) const
Compares two objects whether they share the same data.
Definition: kplugininfo.cpp:159
QString
QList< KService::Ptr >
KPluginInfo::config
KConfigGroup config() const
Definition: kplugininfo.cpp:360
QStringList
kservice.h
QList::end
iterator end()
KPluginInfo::name
QString name() const
Definition: kplugininfo.cpp:255
KService::icon
QString icon() const
Returns the name of the icon.
Definition: kservice.cpp:863
KPluginInfo::website
QString website() const
Definition: kplugininfo.cpp:309
QLatin1Char
KPluginInfo::operator>
bool operator>(const KPluginInfo &rhs) const
Greater than relation comparing the categories and if they are the same using the names...
Definition: kplugininfo.cpp:180
kWarning
#define kWarning
Definition: kdebug.h:322
KPluginInfo::isPluginEnabledByDefault
bool isPluginEnabledByDefault() const
Definition: kplugininfo.cpp:248
KPluginInfo::fullLicense
KAboutLicense fullLicense() const
Definition: kplugininfo.cpp:321
KDesktopFile
KDE Desktop File Management.
Definition: kdesktopfile.h:38
qHash
uint qHash(const KPluginInfo &p)
Definition: kplugininfo.cpp:411
KPluginInfo::save
void save(KConfigGroup config=KConfigGroup())
Save state of the plugin - enabled or not.
Definition: kplugininfo.cpp:375
KConfigGroup
A class for one specific group in a KConfig object.
Definition: kconfiggroup.h:53
KServiceTypeTrader::query
KService::List query(const QString &servicetype, const QString &constraint=QString()) const
The main function in the KServiceTypeTrader class.
Definition: kservicetypetrader.cpp:134
QVariant::toStringList
QStringList toStringList() const
QLatin1String
KPluginInfo::icon
QString icon() const
Definition: kplugininfo.cpp:267
kstandarddirs.h
KDE::version
unsigned int version()
Returns the encoded number of KDE's version, see the KDE_VERSION macro.
Definition: kdeversion.cpp:24
KPluginInfo::setConfig
void setConfig(const KConfigGroup &config)
Set the KConfigGroup to use for load()ing and save()ing the configuration.
Definition: kplugininfo.cpp:354
KAboutLicense::byKeyword
static KAboutLicense byKeyword(const QString &keyword)
Fetch a known license by a keyword.
Definition: kaboutdata.cpp:357
QList::ConstIterator
typedef ConstIterator
KSycocaEntry::isDeleted
bool isDeleted() const
Definition: ksycocaentry.cpp:116
QVariant::toBool
bool toBool() const
QString::fromLatin1
QString fromLatin1(const char *str, int size)
QVariant::isValid
bool isValid() const
kDebug
#define kDebug
Definition: kdebug.h:316
KPluginInfo::isHidden
bool isHidden() const
Definition: kplugininfo.cpp:228
KStandardDirs::findAllResources
QStringList findAllResources(const char *type, const QString &filter=QString(), SearchOptions options=NoSearchOptions) const
Tries to find all resources with the specified type.
Definition: kstandarddirs.cpp:900
KPluginInfo::operator=
KPluginInfo & operator=(const KPluginInfo &rhs)
Copies the KPluginInfo object to share the data with copy.
Definition: kplugininfo.cpp:153
KPluginInfo::author
QString author() const
Definition: kplugininfo.cpp:279
QVariant::toString
QString toString() const
KConfigGroup::readEntry
T readEntry(const QString &key, const T &aDefault) const
Reads the value of an entry specified by pKey in the current group.
Definition: kconfiggroup.h:248
KSycocaEntry::name
QString name() const
Definition: ksycocaentry.cpp:157
KDesktopFile::desktopGroup
KConfigGroup desktopGroup() const
Definition: kdesktopfile.cpp:73
QList::begin
iterator begin()
KPluginInfo::fromServices
static KPluginInfo::List fromServices(const KService::List &services, const KConfigGroup &config=KConfigGroup())
Definition: kplugininfo.cpp:195
KDesktopFile::readName
QString readName() const
Returns the value of the "Name=" entry.
Definition: kdesktopfile.cpp:192
kconfiggroup.h
KPluginInfo::pluginName
QString pluginName() const
Definition: kplugininfo.cpp:297
QVariant
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:22:11 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDECore

Skip menu "KDECore"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

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