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

KDECore

kplugininfo.cpp

Go to the documentation of this file.
00001 /*  This file is part of the KDE project
00002     Copyright (C) 2003,2007 Matthias Kretz <kretz@kde.org>
00003 
00004     This library is free software; you can redistribute it and/or
00005     modify it under the terms of the GNU Library General Public
00006     License version 2 as published by the Free Software Foundation.
00007 
00008     This library is distributed in the hope that it will be useful,
00009     but WITHOUT ANY WARRANTY; without even the implied warranty of
00010     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011     Library General Public License for more details.
00012 
00013     You should have received a copy of the GNU Library General Public License
00014     along with this library; see the file COPYING.LIB.  If not, write to
00015     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00016     Boston, MA 02110-1301, USA.
00017 
00018 */
00019 
00020 #include "kplugininfo.h"
00021 #include <kservicetypetrader.h>
00022 #include <kdebug.h>
00023 #include <kglobal.h>
00024 #include <kstandarddirs.h>
00025 #include <kdesktopfile.h>
00026 #include <kservice.h>
00027 #include <QList>
00028 #include <kconfiggroup.h>
00029 
00030 //#ifndef NDEBUG
00031 #define KPLUGININFO_ISVALID_ASSERTION \
00032     do { \
00033         if (!d) { \
00034             kFatal(703) << "Accessed invalid KPluginInfo object"; \
00035         } \
00036     } while (false)
00037 //#else
00038 //#define KPLUGININFO_ISVALID_ASSERTION
00039 //#endif
00040 
00041 class KPluginInfoPrivate : public QSharedData
00042 {
00043     public:
00044         KPluginInfoPrivate()
00045             : hidden( false )
00046             , enabledbydefault( false )
00047             , pluginenabled( false )
00048             , kcmservicesCached( false )
00049             {}
00050 
00051         QString entryPath; // the filename of the file containing all the info
00052         QString name;
00053         QString comment;
00054         QString icon;
00055         QString author;
00056         QString email;
00057         QString pluginName; // the name attribute in the .rc file
00058         QString version;
00059         QString website; // URL to the website of the plugin/author
00060         QString category;
00061         QString license;
00062         QStringList dependencies;
00063 
00064         bool hidden : 1;
00065         bool enabledbydefault : 1;
00066         bool pluginenabled : 1;
00067         mutable bool kcmservicesCached : 1;
00068 
00069         KConfigGroup config;
00070         KService::Ptr service;
00071         mutable QList<KService::Ptr> kcmservices;
00072 };
00073 
00074 KPluginInfo::KPluginInfo( const QString & filename, const char* resource )
00075 : d( new KPluginInfoPrivate )
00076 {
00077     KDesktopFile file( resource, filename );
00078 
00079     d->entryPath = filename;
00080 
00081     KConfigGroup cg = file.desktopGroup();
00082     d->hidden = cg.readEntry("Hidden", false);
00083     if( d->hidden )
00084         return;
00085 
00086     d->name = file.readName();
00087     d->comment = file.readComment();
00088     d->icon = cg.readEntryUntranslated( "Icon" );
00089     d->author = cg.readEntryUntranslated( "X-KDE-PluginInfo-Author" );
00090     d->email = cg.readEntryUntranslated( "X-KDE-PluginInfo-Email" );
00091     d->pluginName = cg.readEntryUntranslated( "X-KDE-PluginInfo-Name" );
00092     d->version = cg.readEntryUntranslated( "X-KDE-PluginInfo-Version" );
00093     d->website = cg.readEntryUntranslated( "X-KDE-PluginInfo-Website" );
00094     d->category = cg.readEntryUntranslated( "X-KDE-PluginInfo-Category" );
00095     d->license = cg.readEntryUntranslated( "X-KDE-PluginInfo-License" );
00096     d->dependencies = cg.readEntry( "X-KDE-PluginInfo-Depends", QStringList() );
00097     d->enabledbydefault = cg.readEntry(
00098             "X-KDE-PluginInfo-EnabledByDefault", false);
00099 }
00100 
00101 KPluginInfo::KPluginInfo( const KService::Ptr service )
00102 : d( new KPluginInfoPrivate )
00103 {
00104     if (!service) {
00105         d = 0; // isValid() == false
00106         return;
00107     }
00108     d->service = service;
00109     d->entryPath = service->entryPath();
00110 
00111     if ( service->isDeleted() )
00112     {
00113         d->hidden = true;
00114         return;
00115     }
00116 
00117     d->name = service->name();
00118     d->comment = service->comment();
00119     d->icon = service->icon();
00120     d->author = service->property( "X-KDE-PluginInfo-Author" ).toString();
00121     d->email = service->property( "X-KDE-PluginInfo-Email" ).toString();
00122     d->pluginName = service->property( "X-KDE-PluginInfo-Name" ).toString();
00123     d->version = service->property( "X-KDE-PluginInfo-Version" ).toString();
00124     d->website = service->property( "X-KDE-PluginInfo-Website" ).toString();
00125     d->category = service->property( "X-KDE-PluginInfo-Category" ).toString();
00126     d->license = service->property( "X-KDE-PluginInfo-License" ).toString();
00127     d->dependencies =
00128         service->property( "X-KDE-PluginInfo-Depends" ).toStringList();
00129     QVariant tmp = service->property( "X-KDE-PluginInfo-EnabledByDefault" );
00130     d->enabledbydefault = tmp.isValid() ? tmp.toBool() : false;
00131 }
00132 
00133 KPluginInfo::KPluginInfo()
00134     : d(0) // isValid() == false
00135 {
00136 }
00137 
00138 bool KPluginInfo::isValid() const
00139 {
00140     return d.data() != 0;
00141 }
00142 
00143 KPluginInfo::KPluginInfo(const KPluginInfo &rhs)
00144     : d(rhs.d)
00145 {
00146 }
00147 
00148 KPluginInfo &KPluginInfo::operator=(const KPluginInfo &rhs)
00149 {
00150     d = rhs.d;
00151     return *this;
00152 }
00153 
00154 bool KPluginInfo::operator==(const KPluginInfo &rhs) const
00155 {
00156     return d == rhs.d;
00157 }
00158 
00159 bool KPluginInfo::operator!=(const KPluginInfo &rhs) const
00160 {
00161     return d != rhs.d;
00162 }
00163 
00164 bool KPluginInfo::operator<(const KPluginInfo &rhs) const
00165 {
00166     if (category() < rhs.category()) {
00167         return true;
00168     }
00169     if (category() == rhs.category()) {
00170         return name() < rhs.name();
00171     }
00172     return false;
00173 }
00174 
00175 bool KPluginInfo::operator>(const KPluginInfo &rhs) const
00176 {
00177     if (category() > rhs.category()) {
00178         return true;
00179     }
00180     if (category() == rhs.category()) {
00181         return name() > rhs.name();
00182     }
00183     return false;
00184 }
00185 
00186 KPluginInfo::~KPluginInfo()
00187 {
00188 }
00189 
00190 QList<KPluginInfo> KPluginInfo::fromServices(const KService::List &services, const KConfigGroup &config)
00191 {
00192     QList<KPluginInfo> infolist;
00193     for( KService::List::ConstIterator it = services.begin();
00194             it != services.end(); ++it )
00195     {
00196         KPluginInfo info(*it);
00197         info.setConfig(config);
00198         infolist += info;
00199     }
00200     return infolist;
00201 }
00202 
00203 QList<KPluginInfo> KPluginInfo::fromFiles(const QStringList &files, const KConfigGroup &config)
00204 {
00205     QList<KPluginInfo> infolist;
00206     for( QStringList::ConstIterator it = files.begin(); it != files.end(); ++it )
00207     {
00208         KPluginInfo info(*it);
00209         info.setConfig(config);
00210         infolist += info;
00211     }
00212     return infolist;
00213 }
00214 
00215 QList<KPluginInfo> KPluginInfo::fromKPartsInstanceName(const QString &name, const KConfigGroup &config)
00216 {
00217     QStringList files = KGlobal::dirs()->findAllResources( "data",
00218                                                            name + "/kpartplugins/*.desktop",
00219                                                            KStandardDirs::Recursive );
00220     return fromFiles(files, config);
00221 }
00222 
00223 bool KPluginInfo::isHidden() const
00224 {
00225     KPLUGININFO_ISVALID_ASSERTION;
00226     return d->hidden;
00227 }
00228 
00229 void KPluginInfo::setPluginEnabled( bool enabled )
00230 {
00231     KPLUGININFO_ISVALID_ASSERTION;
00232     //kDebug( 703 ) ;
00233     d->pluginenabled = enabled;
00234 }
00235 
00236 bool KPluginInfo::isPluginEnabled() const
00237 {
00238     KPLUGININFO_ISVALID_ASSERTION;
00239     //kDebug( 703 ) ;
00240     return d->pluginenabled;
00241 }
00242 
00243 bool KPluginInfo::isPluginEnabledByDefault() const
00244 {
00245     KPLUGININFO_ISVALID_ASSERTION;
00246     //kDebug( 703 ) ;
00247     return d->enabledbydefault;
00248 }
00249 
00250 QString KPluginInfo::name() const
00251 {
00252     KPLUGININFO_ISVALID_ASSERTION;
00253     return d->name;
00254 }
00255 
00256 QString KPluginInfo::comment() const
00257 {
00258     KPLUGININFO_ISVALID_ASSERTION;
00259     return d->comment;
00260 }
00261 
00262 QString KPluginInfo::icon() const
00263 {
00264     KPLUGININFO_ISVALID_ASSERTION;
00265     return d->icon;
00266 }
00267 
00268 QString KPluginInfo::entryPath() const
00269 {
00270     KPLUGININFO_ISVALID_ASSERTION;
00271     return d->entryPath;
00272 }
00273 
00274 QString KPluginInfo::author() const
00275 {
00276     KPLUGININFO_ISVALID_ASSERTION;
00277     return d->author;
00278 }
00279 
00280 QString KPluginInfo::email() const
00281 {
00282     KPLUGININFO_ISVALID_ASSERTION;
00283     return d->email;
00284 }
00285 
00286 QString KPluginInfo::category() const
00287 {
00288     KPLUGININFO_ISVALID_ASSERTION;
00289     return d->category;
00290 }
00291 
00292 QString KPluginInfo::pluginName() const
00293 {
00294     KPLUGININFO_ISVALID_ASSERTION;
00295     return d->pluginName;
00296 }
00297 
00298 QString KPluginInfo::version() const
00299 {
00300     KPLUGININFO_ISVALID_ASSERTION;
00301     return d->version;
00302 }
00303 
00304 QString KPluginInfo::website() const
00305 {
00306     KPLUGININFO_ISVALID_ASSERTION;
00307     return d->website;
00308 }
00309 
00310 QString KPluginInfo::license() const
00311 {
00312     KPLUGININFO_ISVALID_ASSERTION;
00313     return d->license;
00314 }
00315 
00316 KAboutLicense KPluginInfo::fullLicense() const
00317 {
00318     KPLUGININFO_ISVALID_ASSERTION;
00319     return KAboutLicense::byKeyword(d->license);
00320 }
00321 
00322 QStringList KPluginInfo::dependencies() const
00323 {
00324     KPLUGININFO_ISVALID_ASSERTION;
00325     return d->dependencies;
00326 }
00327 
00328 KService::Ptr KPluginInfo::service() const
00329 {
00330     KPLUGININFO_ISVALID_ASSERTION;
00331     return d->service;
00332 }
00333 
00334 QList<KService::Ptr> KPluginInfo::kcmServices() const
00335 {
00336     KPLUGININFO_ISVALID_ASSERTION;
00337     if ( !d->kcmservicesCached )
00338     {
00339         d->kcmservices = KServiceTypeTrader::self()->query( "KCModule", '\'' + d->pluginName +
00340             "' in [X-KDE-ParentComponents]" );
00341         kDebug( 703 ) << "found " << d->kcmservices.count() << " offers for " <<
00342             d->pluginName << endl;
00343 
00344         d->kcmservicesCached = true;
00345     }
00346 
00347     return d->kcmservices;
00348 }
00349 
00350 void KPluginInfo::setConfig(const KConfigGroup &config)
00351 {
00352     KPLUGININFO_ISVALID_ASSERTION;
00353     d->config = config;
00354 }
00355 
00356 KConfigGroup KPluginInfo::config() const
00357 {
00358     KPLUGININFO_ISVALID_ASSERTION;
00359     return d->config;
00360 }
00361 
00362 QVariant KPluginInfo::property( const QString & key ) const
00363 {
00364     KPLUGININFO_ISVALID_ASSERTION;
00365     if( d->service )
00366         return d->service->property( key );
00367     else
00368         return QVariant();
00369 }
00370 
00371 void KPluginInfo::save(KConfigGroup config)
00372 {
00373     KPLUGININFO_ISVALID_ASSERTION;
00374     //kDebug( 703 ) ;
00375     if (config.isValid()) {
00376         config.writeEntry(d->pluginName + "Enabled", isPluginEnabled());
00377     } else {
00378         if (!d->config.isValid()) {
00379             kWarning( 703 ) << "no KConfigGroup, cannot save";
00380             return;
00381         }
00382         d->config.writeEntry(d->pluginName + "Enabled", isPluginEnabled());
00383     }
00384 }
00385 
00386 void KPluginInfo::load(const KConfigGroup &config)
00387 {
00388     KPLUGININFO_ISVALID_ASSERTION;
00389     //kDebug( 703 ) ;
00390     if (config.isValid()) {
00391         setPluginEnabled(config.readEntry(d->pluginName + "Enabled", isPluginEnabledByDefault()));
00392     } else {
00393         if (!d->config.isValid()) {
00394             kWarning( 703 ) << "no KConfigGroup, cannot load";
00395             return;
00396         }
00397         setPluginEnabled(d->config.readEntry(d->pluginName + "Enabled", isPluginEnabledByDefault()));
00398     }
00399 }
00400 
00401 void KPluginInfo::defaults()
00402 {
00403     //kDebug( 703 ) ;
00404     setPluginEnabled( isPluginEnabledByDefault() );
00405 }
00406 
00407 uint qHash(const KPluginInfo &p)
00408 {
00409     return qHash(reinterpret_cast<quint64>(p.d.data()));
00410 }
00411 
00412 #undef KPLUGININFO_ISVALID_ASSERTION
00413 
00414 // vim: sw=4 sts=4 et

KDECore

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal