kplugininfo.cpp
/* This file is part of the KDE project
Copyright (C) 2003 Matthias Kretz <kretz@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2 as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "kplugininfo.h"
#include <ksimpleconfig.h>
#include <ktrader.h>
#include <kdebug.h>
#include <kconfigbase.h>
#include <kglobal.h>
#include <kstandarddirs.h>
#include <kdesktopfile.h>
#include <kservice.h>
class KPluginInfo::KPluginInfoPrivate
{
public:
KPluginInfoPrivate()
: hidden( false )
, enabledbydefault( false )
, pluginenabled( false )
, config( 0 )
, kcmservicesCached( false )
{}
~KPluginInfoPrivate()
{
delete config;
}
QString specfile; // the filename of the file containing all the info
QString name;
QString comment;
QString icon;
QString author;
QString email;
QString pluginName; // the name attribute in the .rc file
QString version;
QString website; // URL to the website of the plugin/author
QString category;
QString license;
QStringList dependencies;
bool hidden;
bool enabledbydefault;
bool pluginenabled;
KConfig * config;
QString configgroup;
KService::Ptr service;
QValueList<KService::Ptr> kcmservices;
bool kcmservicesCached;
};
KPluginInfo::KPluginInfo( const QString & filename, const char* resource )
: d( new KPluginInfoPrivate )
{
KDesktopFile file( filename, true, resource );
d->specfile = filename;
if( filename.endsWith( QString::fromAscii( ".desktop" ) ) )
{
file.setDesktopGroup();
d->hidden = file.readBoolEntry( "Hidden", false );
if( d->hidden )
return;
d->name = file.readName();
d->comment = file.readComment();
d->icon = file.readEntry( "Icon" );
d->author = file.readEntry( "X-KDE-PluginInfo-Author" );
d->email = file.readEntry( "X-KDE-PluginInfo-Email" );
d->pluginName = file.readEntry( "X-KDE-PluginInfo-Name" );
d->version = file.readEntry( "X-KDE-PluginInfo-Version" );
d->website = file.readEntry( "X-KDE-PluginInfo-Website" );
d->category = file.readEntry( "X-KDE-PluginInfo-Category" );
d->license = file.readEntry( "X-KDE-PluginInfo-License" );
d->dependencies = file.readListEntry( "X-KDE-PluginInfo-Depends" );
d->enabledbydefault = file.readBoolEntry(
"X-KDE-PluginInfo-EnabledByDefault", false );
}
else if( filename.endsWith( QString::fromAscii( ".plugin" ) ) )
{ // provided for noatun style .plugin files compatibility
d->name = file.readName();
d->comment = file.readComment();
d->icon = file.readEntry( "Icon" );
d->author = file.readEntry( "Author" );
d->email = file.readEntry( "Email" );
d->pluginName = file.readPathEntry( "Filename" );
// no version
d->website = file.readEntry( "Site" );
d->category = file.readEntry( "Type" );
d->license = file.readEntry( "License" );
d->dependencies = file.readListEntry( "Require" );
}
}
KPluginInfo::KPluginInfo( const KService::Ptr service )
: d( new KPluginInfoPrivate )
{
d->service = service;
d->specfile = service->desktopEntryPath();
if ( service->isDeleted() )
{
d->hidden = true;
return;
}
d->name = service->name();
d->comment = service->comment();
d->icon = service->icon();
d->author = service->property( "X-KDE-PluginInfo-Author" ).toString();
d->email = service->property( "X-KDE-PluginInfo-Email" ).toString();
d->pluginName = service->property( "X-KDE-PluginInfo-Name" ).toString();
d->version = service->property( "X-KDE-PluginInfo-Version" ).toString();
d->website = service->property( "X-KDE-PluginInfo-Website" ).toString();
d->category = service->property( "X-KDE-PluginInfo-Category" ).toString();
d->license = service->property( "X-KDE-PluginInfo-License" ).toString();
d->dependencies =
service->property( "X-KDE-PluginInfo-Depends" ).toStringList();
QVariant tmp = service->property( "X-KDE-PluginInfo-EnabledByDefault" );
d->enabledbydefault = tmp.isValid() ? tmp.toBool() : false;
}
//X KPluginInfo::KPluginInfo()
//X : d( new KPluginInfoPrivate )
//X {
//X d->hidden = true;
//X }
KPluginInfo::~KPluginInfo()
{
delete d;
}
QValueList<KPluginInfo*> KPluginInfo::fromServices( const KService::List & services, KConfig * config, const QString & group )
{
QValueList<KPluginInfo*> infolist;
KPluginInfo * info;
for( KService::List::ConstIterator it = services.begin();
it != services.end(); ++it )
{
info = new KPluginInfo( *it );
info->setConfig( config, group );
infolist += info;
}
return infolist;
}
QValueList<KPluginInfo*> KPluginInfo::fromFiles( const QStringList & files, KConfig * config, const QString & group )
{
QValueList<KPluginInfo*> infolist;
for( QStringList::ConstIterator it = files.begin(); it != files.end(); ++it )
{
KPluginInfo * info = new KPluginInfo( *it );
info->setConfig( config, group );
infolist += info;
}
return infolist;
}
QValueList<KPluginInfo*> KPluginInfo::fromKPartsInstanceName( const QString & name, KConfig * config, const QString & group )
{
QStringList files = KGlobal::dirs()->findAllResources( "data", name +
"/kpartplugins/*.desktop", true, false );
return fromFiles( files, config, group );
}
bool KPluginInfo::isHidden() const
{
return d->hidden;
}
void KPluginInfo::setPluginEnabled( bool enabled )
{
kdDebug( 703 ) << k_funcinfo << endl;
d->pluginenabled = enabled;
}
bool KPluginInfo::isPluginEnabled() const
{
kdDebug( 703 ) << k_funcinfo << endl;
return d->pluginenabled;
}
bool KPluginInfo::isPluginEnabledByDefault() const
{
kdDebug( 703 ) << k_funcinfo << endl;
return d->enabledbydefault;
}
const QString & KPluginInfo::name() const
{
return d->name;
}
const QString & KPluginInfo::comment() const
{
return d->comment;
}
const QString & KPluginInfo::icon() const
{
return d->icon;
}
const QString & KPluginInfo::specfile() const
{
return d->specfile;
}
const QString & KPluginInfo::author() const
{
return d->author;
}
const QString & KPluginInfo::email() const
{
return d->email;
}
const QString & KPluginInfo::category() const
{
return d->category;
}
const QString & KPluginInfo::pluginName() const
{
return d->pluginName;
}
const QString & KPluginInfo::version() const
{
return d->version;
}
const QString & KPluginInfo::website() const
{
return d->website;
}
const QString & KPluginInfo::license() const
{
return d->license;
}
const QStringList & KPluginInfo::dependencies() const
{
return d->dependencies;
}
KService::Ptr KPluginInfo::service() const
{
return d->service;
}
const QValueList<KService::Ptr> & KPluginInfo::kcmServices() const
{
if ( !d->kcmservicesCached )
{
d->kcmservices = KTrader::self()->query( "KCModule", "'" + d->pluginName +
"' in [X-KDE-ParentComponents]" );
kdDebug( 703 ) << "found " << d->kcmservices.count() << " offers for " <<
d->pluginName << endl;
d->kcmservicesCached = true;
}
return d->kcmservices;
}
void KPluginInfo::setConfig( KConfig * config, const QString & group )
{
d->config = config;
d->configgroup = group;
}
KConfig * KPluginInfo::config() const
{
return d->config;
}
const QString & KPluginInfo::configgroup() const
{
return d->configgroup;
}
QVariant KPluginInfo::property( const QString & key ) const
{
if( d->service )
return d->service->property( key );
else
return QVariant();
}
QVariant KPluginInfo::operator[]( const QString & key ) const
{
return property( key );
}
void KPluginInfo::save( KConfigGroup * config )
{
kdDebug( 703 ) << k_funcinfo << endl;
if( 0 == config )
{
if( 0 == d->config )
{
kdWarning( 703 ) << "no KConfigGroup, cannot save" << endl;
return;
}
d->config->setGroup( d->configgroup );
d->config->writeEntry( d->pluginName + "Enabled", isPluginEnabled() );
}
else
config->writeEntry( d->pluginName + "Enabled", isPluginEnabled() );
}
void KPluginInfo::load( KConfigGroup * config )
{
kdDebug( 703 ) << k_funcinfo << endl;
if( 0 == config )
{
if( 0 == d->config )
{
kdWarning( 703 ) << "no KConfigGroup, cannot load" << endl;
return;
}
d->config->setGroup( d->configgroup );
setPluginEnabled( d->config->readBoolEntry( d->pluginName + "Enabled", isPluginEnabledByDefault() ) );
}
else
setPluginEnabled( config->readBoolEntry( d->pluginName + "Enabled", isPluginEnabledByDefault() ) );
}
void KPluginInfo::defaults()
{
kdDebug( 703 ) << k_funcinfo << endl;
setPluginEnabled( isPluginEnabledByDefault() );
}
// vim: sw=4 sts=4 et
KPluginInfo::kcmServices
const QValueList< KService::Ptr > & kcmServices() const
Definition: kplugininfo.cpp:275
KPluginInfo
Information about a plugin.
Definition: kplugininfo.h:42
KConfig::readListEntry
int readListEntry(const QString &pKey, QStrList &list, char sep= ',') const
KPluginInfo::property
QVariant property(const QString &key) const
Definition: kplugininfo.cpp:306
KPluginInfo::license
const QString & license() const
Definition: kplugininfo.cpp:260
KPluginInfo::fromFiles
static KPluginInfo::List fromFiles(const QStringList &files, KConfig *config=0, const QString &group=QString::null)
Definition: kplugininfo.cpp:168
KPluginInfo::email
const QString & email() const
Definition: kplugininfo.cpp:235
KDesktopFile::readComment
QString readComment() const
KPluginInfo::isPluginEnabled
virtual bool isPluginEnabled() const
Definition: kplugininfo.cpp:198
KPluginInfo::service
KService::Ptr service() const
Definition: kplugininfo.cpp:270
KPluginInfo::setConfig
void setConfig(KConfig *config, const QString &group)
Set the KConfigGroup to use for load()ing and save()ing the configuration.
Definition: kplugininfo.cpp:290
KPluginInfo::icon
const QString & icon() const
Definition: kplugininfo.cpp:220
kdDebug
kdbgstream kdDebug(int area=0)
KPluginInfo::save
virtual void save(KConfigGroup *config=0)
Save state of the plugin - enabled or not.
Definition: kplugininfo.cpp:319
KPluginInfo::load
virtual void load(KConfigGroup *config=0)
Load the state of the plugin - enabled or not.
Definition: kplugininfo.cpp:336
KConfig::readPathEntry
QString readPathEntry(const QString &pKey, const QString &aDefault=QString::null) const
KGlobal::dirs
static KStandardDirs * dirs()
KPluginInfo::name
const QString & name() const
Definition: kplugininfo.cpp:210
KPluginInfo::setPluginEnabled
virtual void setPluginEnabled(bool enabled)
Set whether the plugin is currently loaded.
Definition: kplugininfo.cpp:192
KPluginInfo::defaults
virtual void defaults()
Restore defaults (enabled or not).
Definition: kplugininfo.cpp:353
kdWarning
kdbgstream kdWarning(int area=0)
KPluginInfo::pluginName
const QString & pluginName() const
Definition: kplugininfo.cpp:245
KPluginInfo::KPluginInfo
KPluginInfo(const QString &filename, const char *resource=0)
Read plugin info from filename.
Definition: kplugininfo.cpp:70
KConfig::setDesktopGroup
void setDesktopGroup()
KPluginInfo::configgroup
const QString & configgroup() const
Definition: kplugininfo.cpp:301
KStandardDirs::findAllResources
QStringList findAllResources(const char *type, const QString &filter=QString::null, bool recursive=false, bool unique=false) const
KPluginInfo::website
const QString & website() const
Definition: kplugininfo.cpp:255
KPluginInfo::isPluginEnabledByDefault
bool isPluginEnabledByDefault() const
Definition: kplugininfo.cpp:204
KDesktopFile
KPluginInfo::author
const QString & author() const
Definition: kplugininfo.cpp:230
KConfigGroup
KPluginInfo::specfile
const QString & specfile() const
Definition: kplugininfo.cpp:225
KConfig
KConfig::readEntry
QString readEntry(const QString &pKey, const QString &aDefault=QString::null) const
KPluginInfo::operator[]
QVariant operator[](const QString &key) const
This is the same as property().
Definition: kplugininfo.cpp:314
KConfig::readBoolEntry
bool readBoolEntry(const QString &pKey, bool bDefault=false) const
KPluginInfo::isHidden
bool isHidden() const
Definition: kplugininfo.cpp:187
KPluginInfo::version
const QString & version() const
Definition: kplugininfo.cpp:250
KPluginInfo::comment
const QString & comment() const
Definition: kplugininfo.cpp:215
KPluginInfo::fromKPartsInstanceName
static KPluginInfo::List fromKPartsInstanceName(const QString &, KConfig *config=0, const QString &group=QString::null)
Definition: kplugininfo.cpp:180
endl
kndbgstream & endl(kndbgstream &s)
KPluginInfo::dependencies
const QStringList & dependencies() const
Definition: kplugininfo.cpp:265
KPluginInfo::config
KConfig * config() const
Definition: kplugininfo.cpp:296
KPluginInfo::category
const QString & category() const
Definition: kplugininfo.cpp:240
KDesktopFile::readName
QString readName() const
KPluginInfo::fromServices
static KPluginInfo::List fromServices(const KService::List &services, KConfig *config=0, const QString &group=QString::null)
Definition: kplugininfo.cpp:154

KDE Home | KDE Accessibility Home | Description of Access Keys