kutils Library API Documentation

kplugininfo.cpp

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