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

KUtils

kplugininfo.cpp

Go to the documentation of this file.
00001 /*  This file is part of the KDE project
00002     Copyright (C) 2003 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 <ksimpleconfig.h>
00022 #include <ktrader.h>
00023 #include <kdebug.h>
00024 #include <kconfigbase.h>
00025 #include <kglobal.h>
00026 #include <kstandarddirs.h>
00027 #include <kdesktopfile.h>
00028 #include <kservice.h>
00029 
00030 class KPluginInfo::KPluginInfoPrivate
00031 {
00032     public:
00033         KPluginInfoPrivate()
00034             : hidden( false )
00035             , enabledbydefault( false )
00036             , pluginenabled( false )
00037             , config( 0 )
00038             , kcmservicesCached( false )
00039             {}
00040 
00041         ~KPluginInfoPrivate()
00042         {
00043             delete config;
00044         }
00045 
00046         QString specfile; // the filename of the file containing all the info
00047         QString name;
00048         QString comment;
00049         QString icon;
00050         QString author;
00051         QString email;
00052         QString pluginName; // the name attribute in the .rc file
00053         QString version;
00054         QString website; // URL to the website of the plugin/author
00055         QString category;
00056         QString license;
00057         QStringList dependencies;
00058 
00059         bool hidden;
00060         bool enabledbydefault;
00061         bool pluginenabled;
00062 
00063         KConfig * config;
00064         QString configgroup;
00065         KService::Ptr service;
00066         QValueList<KService::Ptr> kcmservices;
00067         bool kcmservicesCached;
00068 };
00069 
00070 KPluginInfo::KPluginInfo( const QString & filename, const char* resource )
00071 : d( new KPluginInfoPrivate )
00072 {
00073     KDesktopFile file( filename, true, resource );
00074 
00075     d->specfile = filename;
00076 
00077     if( filename.endsWith( QString::fromAscii( ".desktop" ) ) )
00078     {
00079         file.setDesktopGroup();
00080         d->hidden = file.readBoolEntry( "Hidden", false );
00081         if( d->hidden )
00082             return;
00083 
00084         d->name = file.readName();
00085         d->comment = file.readComment();
00086         d->icon = file.readEntry( "Icon" );
00087         d->author = file.readEntry( "X-KDE-PluginInfo-Author" );
00088         d->email = file.readEntry( "X-KDE-PluginInfo-Email" );
00089         d->pluginName = file.readEntry( "X-KDE-PluginInfo-Name" );
00090         d->version = file.readEntry( "X-KDE-PluginInfo-Version" );
00091         d->website = file.readEntry( "X-KDE-PluginInfo-Website" );
00092         d->category = file.readEntry( "X-KDE-PluginInfo-Category" );
00093         d->license = file.readEntry( "X-KDE-PluginInfo-License" );
00094         d->dependencies = file.readListEntry( "X-KDE-PluginInfo-Depends" );
00095         d->enabledbydefault = file.readBoolEntry(
00096                 "X-KDE-PluginInfo-EnabledByDefault", false );
00097     }
00098     else if( filename.endsWith( QString::fromAscii( ".plugin" ) ) )
00099     { // provided for noatun style .plugin files compatibility
00100 
00101         d->name = file.readName();
00102         d->comment = file.readComment();
00103         d->icon = file.readEntry( "Icon" );
00104         d->author = file.readEntry( "Author" );
00105         d->email = file.readEntry( "Email" );
00106         d->pluginName = file.readPathEntry( "Filename" );
00107         // no version
00108         d->website = file.readEntry( "Site" );
00109         d->category = file.readEntry( "Type" );
00110         d->license = file.readEntry( "License" );
00111         d->dependencies = file.readListEntry( "Require" );
00112     }
00113 }
00114 
00115 KPluginInfo::KPluginInfo( const KService::Ptr service )
00116 : d( new KPluginInfoPrivate )
00117 {
00118     d->service = service;
00119     d->specfile = service->desktopEntryPath();
00120 
00121     if ( service->isDeleted() )
00122     {
00123         d->hidden = true;
00124         return;
00125     }
00126 
00127     d->name = service->name();
00128     d->comment = service->comment();
00129     d->icon = service->icon();
00130     d->author = service->property( "X-KDE-PluginInfo-Author" ).toString();
00131     d->email = service->property( "X-KDE-PluginInfo-Email" ).toString();
00132     d->pluginName = service->property( "X-KDE-PluginInfo-Name" ).toString();
00133     d->version = service->property( "X-KDE-PluginInfo-Version" ).toString();
00134     d->website = service->property( "X-KDE-PluginInfo-Website" ).toString();
00135     d->category = service->property( "X-KDE-PluginInfo-Category" ).toString();
00136     d->license = service->property( "X-KDE-PluginInfo-License" ).toString();
00137     d->dependencies =
00138         service->property( "X-KDE-PluginInfo-Depends" ).toStringList();
00139     QVariant tmp = service->property( "X-KDE-PluginInfo-EnabledByDefault" );
00140     d->enabledbydefault = tmp.isValid() ? tmp.toBool() : false;
00141 }
00142 
00143 //X KPluginInfo::KPluginInfo()
00144 //X : d( new KPluginInfoPrivate )
00145 //X {
00146 //X     d->hidden = true;
00147 //X }
00148 
00149 KPluginInfo::~KPluginInfo()
00150 {
00151     delete d;
00152 }
00153 
00154 QValueList<KPluginInfo*> KPluginInfo::fromServices( const KService::List & services, KConfig * config, const QString & group )
00155 {
00156     QValueList<KPluginInfo*> infolist;
00157     KPluginInfo * info;
00158     for( KService::List::ConstIterator it = services.begin();
00159             it != services.end(); ++it )
00160     {
00161         info = new KPluginInfo( *it );
00162         info->setConfig( config, group );
00163         infolist += info;
00164     }
00165     return infolist;
00166 }
00167 
00168 QValueList<KPluginInfo*> KPluginInfo::fromFiles( const QStringList & files, KConfig * config, const QString & group )
00169 {
00170     QValueList<KPluginInfo*> infolist;
00171     for( QStringList::ConstIterator it = files.begin(); it != files.end(); ++it )
00172     {
00173         KPluginInfo * info = new KPluginInfo( *it );
00174         info->setConfig( config, group );
00175         infolist += info;
00176     }
00177     return infolist;
00178 }
00179 
00180 QValueList<KPluginInfo*> KPluginInfo::fromKPartsInstanceName( const QString & name, KConfig * config, const QString & group )
00181 {
00182     QStringList files = KGlobal::dirs()->findAllResources( "data", name +
00183             "/kpartplugins/*.desktop", true, false );
00184     return fromFiles( files, config, group );
00185 }
00186 
00187 bool KPluginInfo::isHidden() const
00188 {
00189     return d->hidden;
00190 }
00191 
00192 void KPluginInfo::setPluginEnabled( bool enabled )
00193 {
00194     kdDebug( 703 ) << k_funcinfo << endl;
00195     d->pluginenabled = enabled;
00196 }
00197 
00198 bool KPluginInfo::isPluginEnabled() const
00199 {
00200     kdDebug( 703 ) << k_funcinfo << endl;
00201     return d->pluginenabled;
00202 }
00203 
00204 bool KPluginInfo::isPluginEnabledByDefault() const
00205 {
00206     kdDebug( 703 ) << k_funcinfo << endl;
00207     return d->enabledbydefault;
00208 }
00209 
00210 const QString & KPluginInfo::name() const
00211 {
00212     return d->name;
00213 }
00214 
00215 const QString & KPluginInfo::comment() const
00216 {
00217     return d->comment;
00218 }
00219 
00220 const QString & KPluginInfo::icon() const
00221 {
00222     return d->icon;
00223 }
00224 
00225 const QString & KPluginInfo::specfile() const
00226 {
00227     return d->specfile;
00228 }
00229 
00230 const QString & KPluginInfo::author() const
00231 {
00232     return d->author;
00233 }
00234 
00235 const QString & KPluginInfo::email() const
00236 {
00237     return d->email;
00238 }
00239 
00240 const QString & KPluginInfo::category() const
00241 {
00242     return d->category;
00243 }
00244 
00245 const QString & KPluginInfo::pluginName() const
00246 {
00247     return d->pluginName;
00248 }
00249 
00250 const QString & KPluginInfo::version() const
00251 {
00252     return d->version;
00253 }
00254 
00255 const QString & KPluginInfo::website() const
00256 {
00257     return d->website;
00258 }
00259 
00260 const QString & KPluginInfo::license() const
00261 {
00262     return d->license;
00263 }
00264 
00265 const QStringList & KPluginInfo::dependencies() const
00266 {
00267     return d->dependencies;
00268 }
00269 
00270 KService::Ptr KPluginInfo::service() const
00271 {
00272     return d->service;
00273 }
00274 
00275 const QValueList<KService::Ptr> & KPluginInfo::kcmServices() const
00276 {
00277     if ( !d->kcmservicesCached )
00278     {
00279         d->kcmservices = KTrader::self()->query( "KCModule", "'" + d->pluginName +
00280             "' in [X-KDE-ParentComponents]" );
00281         kdDebug( 703 ) << "found " << d->kcmservices.count() << " offers for " <<
00282             d->pluginName << endl;
00283 
00284         d->kcmservicesCached = true;
00285     }
00286 
00287     return d->kcmservices;
00288 }
00289 
00290 void KPluginInfo::setConfig( KConfig * config, const QString & group )
00291 {
00292     d->config = config;
00293     d->configgroup = group;
00294 }
00295 
00296 KConfig * KPluginInfo::config() const
00297 {
00298     return d->config;
00299 }
00300 
00301 const QString & KPluginInfo::configgroup() const
00302 {
00303     return d->configgroup;
00304 }
00305 
00306 QVariant KPluginInfo::property( const QString & key ) const
00307 {
00308     if( d->service )
00309         return d->service->property( key );
00310     else
00311         return QVariant();
00312 }
00313 
00314 QVariant KPluginInfo::operator[]( const QString & key ) const
00315 {
00316     return property( key );
00317 }
00318 
00319 void KPluginInfo::save( KConfigGroup * config )
00320 {
00321     kdDebug( 703 ) << k_funcinfo << endl;
00322     if( 0 == config )
00323     {
00324         if( 0 == d->config )
00325         {
00326             kdWarning( 703 ) << "no KConfigGroup, cannot save" << endl;
00327             return;
00328         }
00329         d->config->setGroup( d->configgroup );
00330         d->config->writeEntry( d->pluginName + "Enabled", isPluginEnabled() );
00331     }
00332     else
00333         config->writeEntry( d->pluginName + "Enabled", isPluginEnabled() );
00334 }
00335 
00336 void KPluginInfo::load( KConfigGroup * config )
00337 {
00338     kdDebug( 703 ) << k_funcinfo << endl;
00339     if( 0 == config )
00340     {
00341         if( 0 == d->config )
00342         {
00343             kdWarning( 703 ) << "no KConfigGroup, cannot load" << endl;
00344             return;
00345         }
00346         d->config->setGroup( d->configgroup );
00347         setPluginEnabled( d->config->readBoolEntry( d->pluginName + "Enabled", isPluginEnabledByDefault() ) );
00348     }
00349     else
00350         setPluginEnabled( config->readBoolEntry( d->pluginName + "Enabled", isPluginEnabledByDefault() ) );
00351 }
00352 
00353 void KPluginInfo::defaults()
00354 {
00355     kdDebug( 703 ) << k_funcinfo << endl;
00356     setPluginEnabled( isPluginEnabledByDefault() );
00357 }
00358 
00359 // vim: sw=4 sts=4 et

KUtils

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

API Reference

Skip menu "API Reference"
  • dcop
  • DNSSD
  • interfaces
  • Kate
  • kconf_update
  • KDECore
  • KDED
  • kdefx
  • KDEsu
  • kdeui
  • KDocTools
  • KHTML
  • KImgIO
  • KInit
  • kio
  • kioslave
  • KJS
  • KNewStuff
  • KParts
  • KUtils
Generated for API Reference by doxygen 1.5.9
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