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

KDECore

  • 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
41class 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
79KPluginInfo::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
106KPluginInfo::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
138KPluginInfo::KPluginInfo()
139 : d(0) // isValid() == false
140{
141}
142
143bool KPluginInfo::isValid() const
144{
145 return d.data() != 0;
146}
147
148KPluginInfo::KPluginInfo(const KPluginInfo &rhs)
149 : d(rhs.d)
150{
151}
152
153KPluginInfo &KPluginInfo::operator=(const KPluginInfo &rhs)
154{
155 d = rhs.d;
156 return *this;
157}
158
159bool KPluginInfo::operator==(const KPluginInfo &rhs) const
160{
161 return d == rhs.d;
162}
163
164bool KPluginInfo::operator!=(const KPluginInfo &rhs) const
165{
166 return d != rhs.d;
167}
168
169bool 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
180bool 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
191KPluginInfo::~KPluginInfo()
192{
193}
194
195QList<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
208QList<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
220QList<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
228bool KPluginInfo::isHidden() const
229{
230 KPLUGININFO_ISVALID_ASSERTION;
231 return d->hidden;
232}
233
234void KPluginInfo::setPluginEnabled( bool enabled )
235{
236 KPLUGININFO_ISVALID_ASSERTION;
237 //kDebug( d->debugArea() ) ;
238 d->pluginenabled = enabled;
239}
240
241bool KPluginInfo::isPluginEnabled() const
242{
243 KPLUGININFO_ISVALID_ASSERTION;
244 //kDebug( d->debugArea() ) ;
245 return d->pluginenabled;
246}
247
248bool KPluginInfo::isPluginEnabledByDefault() const
249{
250 KPLUGININFO_ISVALID_ASSERTION;
251 //kDebug( d->debugArea() ) ;
252 return d->enabledbydefault;
253}
254
255QString KPluginInfo::name() const
256{
257 KPLUGININFO_ISVALID_ASSERTION;
258 return d->name;
259}
260
261QString KPluginInfo::comment() const
262{
263 KPLUGININFO_ISVALID_ASSERTION;
264 return d->comment;
265}
266
267QString KPluginInfo::icon() const
268{
269 KPLUGININFO_ISVALID_ASSERTION;
270 return d->icon;
271}
272
273QString KPluginInfo::entryPath() const
274{
275 KPLUGININFO_ISVALID_ASSERTION;
276 return d->entryPath;
277}
278
279QString KPluginInfo::author() const
280{
281 KPLUGININFO_ISVALID_ASSERTION;
282 return d->author;
283}
284
285QString KPluginInfo::email() const
286{
287 KPLUGININFO_ISVALID_ASSERTION;
288 return d->email;
289}
290
291QString KPluginInfo::category() const
292{
293 KPLUGININFO_ISVALID_ASSERTION;
294 return d->category;
295}
296
297QString KPluginInfo::pluginName() const
298{
299 KPLUGININFO_ISVALID_ASSERTION;
300 return d->pluginName;
301}
302
303QString KPluginInfo::version() const
304{
305 KPLUGININFO_ISVALID_ASSERTION;
306 return d->version;
307}
308
309QString KPluginInfo::website() const
310{
311 KPLUGININFO_ISVALID_ASSERTION;
312 return d->website;
313}
314
315QString KPluginInfo::license() const
316{
317 KPLUGININFO_ISVALID_ASSERTION;
318 return d->license;
319}
320
321KAboutLicense KPluginInfo::fullLicense() const
322{
323 KPLUGININFO_ISVALID_ASSERTION;
324 return KAboutLicense::byKeyword(d->license);
325}
326
327QStringList KPluginInfo::dependencies() const
328{
329 KPLUGININFO_ISVALID_ASSERTION;
330 return d->dependencies;
331}
332
333KService::Ptr KPluginInfo::service() const
334{
335 KPLUGININFO_ISVALID_ASSERTION;
336 return d->service;
337}
338
339QList<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
354void KPluginInfo::setConfig(const KConfigGroup &config)
355{
356 KPLUGININFO_ISVALID_ASSERTION;
357 d->config = config;
358}
359
360KConfigGroup KPluginInfo::config() const
361{
362 KPLUGININFO_ISVALID_ASSERTION;
363 return d->config;
364}
365
366QVariant 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
375void 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
390void 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
405void KPluginInfo::defaults()
406{
407 //kDebug( d->debugArea() ) ;
408 setPluginEnabled( isPluginEnabledByDefault() );
409}
410
411uint 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:895
KAboutLicense::byKeyword
static KAboutLicense byKeyword(const QString &keyword)
Fetch a known license by a keyword.
Definition: kaboutdata.cpp:357
KConfigGroup
A class for one specific group in a KConfig object.
Definition: kconfiggroup.h:54
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
KConfigGroup::readEntryUntranslated
QString readEntryUntranslated(const QString &pKey, const QString &aDefault=QString()) const
Reads an untranslated string entry.
Definition: kconfiggroup.cpp:637
KDebug::registerArea
static int registerArea(const QByteArray &areaName, bool enabled=true)
Definition: kdebug.cpp:856
KDesktopFile
KDE Desktop File Management.
Definition: kdesktopfile.h:39
KDesktopFile::readName
QString readName() const
Returns the value of the "Name=" entry.
Definition: kdesktopfile.cpp:192
KDesktopFile::readComment
QString readComment() const
Returns the value of the "Comment=" entry.
Definition: kdesktopfile.cpp:198
KDesktopFile::desktopGroup
KConfigGroup desktopGroup() const
Definition: kdesktopfile.cpp:73
KPluginInfo
Information about a plugin.
Definition: kplugininfo.h:44
KPluginInfo::category
QString category() const
Definition: kplugininfo.cpp:291
KPluginInfo::save
void save(KConfigGroup config=KConfigGroup())
Save state of the plugin - enabled or not.
Definition: kplugininfo.cpp:375
KPluginInfo::isHidden
bool isHidden() const
Definition: kplugininfo.cpp:228
KPluginInfo::isPluginEnabledByDefault
bool isPluginEnabledByDefault() const
Definition: kplugininfo.cpp:248
KPluginInfo::isValid
bool isValid() const
Returns whether the object is valid.
Definition: kplugininfo.cpp:143
KPluginInfo::pluginName
QString pluginName() const
Definition: kplugininfo.cpp:297
KPluginInfo::fromFiles
static KPluginInfo::List fromFiles(const QStringList &files, const KConfigGroup &config=KConfigGroup())
Definition: kplugininfo.cpp:208
KPluginInfo::icon
QString icon() const
Definition: kplugininfo.cpp:267
KPluginInfo::operator=
KPluginInfo & operator=(const KPluginInfo &rhs)
Copies the KPluginInfo object to share the data with copy.
Definition: kplugininfo.cpp:153
KPluginInfo::version
QString version() const
Definition: kplugininfo.cpp:303
KPluginInfo::property
QVariant property(const QString &key) const
Definition: kplugininfo.cpp:366
KPluginInfo::kcmServices
QList< KService::Ptr > kcmServices() const
Definition: kplugininfo.cpp:339
KPluginInfo::setConfig
void setConfig(const KConfigGroup &config)
Set the KConfigGroup to use for load()ing and save()ing the configuration.
Definition: kplugininfo.cpp:354
KPluginInfo::website
QString website() const
Definition: kplugininfo.cpp:309
KPluginInfo::fromServices
static KPluginInfo::List fromServices(const KService::List &services, const KConfigGroup &config=KConfigGroup())
Definition: kplugininfo.cpp:195
KPluginInfo::license
QString license() const
Definition: kplugininfo.cpp:315
KPluginInfo::operator!=
bool operator!=(const KPluginInfo &rhs) const
Compares two objects whether they don't share the same data.
Definition: kplugininfo.cpp:164
KPluginInfo::comment
QString comment() const
Definition: kplugininfo.cpp:261
KPluginInfo::service
KService::Ptr service() const
Definition: kplugininfo.cpp:333
KPluginInfo::author
QString author() const
Definition: kplugininfo.cpp:279
KPluginInfo::name
QString name() const
Definition: kplugininfo.cpp:255
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
KPluginInfo::operator==
bool operator==(const KPluginInfo &rhs) const
Compares two objects whether they share the same data.
Definition: kplugininfo.cpp:159
KPluginInfo::~KPluginInfo
~KPluginInfo()
Definition: kplugininfo.cpp:191
KPluginInfo::isPluginEnabled
bool isPluginEnabled() const
Definition: kplugininfo.cpp:241
KPluginInfo::entryPath
QString entryPath() const
Definition: kplugininfo.cpp:273
KPluginInfo::load
void load(const KConfigGroup &config=KConfigGroup())
Load the state of the plugin - enabled or not.
Definition: kplugininfo.cpp:390
KPluginInfo::fromKPartsInstanceName
static KPluginInfo::List fromKPartsInstanceName(const QString &componentName, const KConfigGroup &config=KConfigGroup())
Definition: kplugininfo.cpp:220
KPluginInfo::defaults
void defaults()
Restore defaults (enabled or not).
Definition: kplugininfo.cpp:405
KPluginInfo::config
KConfigGroup config() const
Definition: kplugininfo.cpp:360
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::setPluginEnabled
void setPluginEnabled(bool enabled)
Set whether the plugin is currently loaded.
Definition: kplugininfo.cpp:234
KPluginInfo::fullLicense
KAboutLicense fullLicense() const
Definition: kplugininfo.cpp:321
KPluginInfo::email
QString email() const
Definition: kplugininfo.cpp:285
KPluginInfo::KPluginInfo
KPluginInfo()
Creates an invalid plugin.
Definition: kplugininfo.cpp:138
KPluginInfo::dependencies
QStringList dependencies() const
Definition: kplugininfo.cpp:327
KServiceTypeTrader::self
static KServiceTypeTrader * self()
This is a static pointer to the KServiceTypeTrader singleton.
Definition: kservicetypetrader.cpp:37
KServiceTypeTrader::query
KService::List query(const QString &servicetype, const QString &constraint=QString()) const
The main function in the KServiceTypeTrader class.
Definition: kservicetypetrader.cpp:134
KService::property
QVariant property(const QString &_name, QVariant::Type t) const
Returns the requested property.
Definition: kservice.cpp:498
KService::comment
QString comment() const
Returns the descriptive comment for the service, if there is one.
Definition: kservice.cpp:907
KService::icon
QString icon() const
Returns the name of the icon.
Definition: kservice.cpp:863
KSharedPtr< KService >
KStandardDirs::Recursive
@ Recursive
Definition: kstandarddirs.h:191
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
KSycocaEntry::name
QString name() const
Definition: ksycocaentry.cpp:157
KSycocaEntry::isDeleted
bool isDeleted() const
Definition: ksycocaentry.cpp:116
KSycocaEntry::entryPath
QString entryPath() const
Definition: ksycocaentry.cpp:104
QList
Definition: kaboutdata.h:33
QStringList
QString
QVariant
quint64
kDebug
#define kDebug
Definition: kdebug.h:316
kWarning
#define kWarning
Definition: kdebug.h:322
kconfiggroup.h
kdebug.h
kdesktopfile.h
kglobal.h
KPLUGININFO_ISVALID_ASSERTION
#define KPLUGININFO_ISVALID_ASSERTION
Definition: kplugininfo.cpp:31
qHash
uint qHash(const KPluginInfo &p)
Definition: kplugininfo.cpp:411
kplugininfo.h
kservice.h
kservicetypetrader.h
kstandarddirs.h
KGlobal::dirs
KStandardDirs * dirs()
Returns the application standard dirs object.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 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-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 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
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