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

KUtils

kcmoduleinfo.cpp

Go to the documentation of this file.
00001 /*
00002   Copyright (c) 1999 Matthias Hoelzer-Kluepfel <hoelzer@kde.org>
00003   Copyright (c) 2000 Matthias Elter <elter@kde.org>
00004   Copyright (c) 2003 Daniel Molkentin <molkentin@kde.org>
00005   Copyright (c) 2003 Matthias Kretz <kretz@kde.org>
00006 
00007   This file is part of the KDE project
00008   
00009   This library is free software; you can redistribute it and/or
00010   modify it under the terms of the GNU Library General Public
00011   License version 2, as published by the Free Software Foundation.
00012 
00013   This library is distributed in the hope that it will be useful,
00014   but WITHOUT ANY WARRANTY; without even the implied warranty of
00015   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016   Library General Public License for more details.
00017 
00018   You should have received a copy of the GNU Library General Public License
00019   along with this library; see the file COPYING.LIB.  If not, write to
00020   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00021   Boston, MA 02110-1301, USA.
00022 */
00023 
00024 #include <qvariant.h>
00025 
00026 #include <kdesktopfile.h>
00027 #include <kdebug.h>
00028 #include <kglobal.h>
00029 #include <kstandarddirs.h>
00030 #include <klocale.h>
00031 
00032 #include "kcmoduleinfo.h"
00033 
00034 class KCModuleInfo::KCModuleInfoPrivate
00035 {
00036   public:
00037     KCModuleInfoPrivate() :
00038       testModule( false )
00039     {}
00040     ~KCModuleInfoPrivate()
00041     { }
00042 
00043     QString factoryName;
00044     bool testModule;
00045 
00046 };
00047 
00048 KCModuleInfo::KCModuleInfo()
00049 {
00050   _allLoaded = false;
00051   d = new KCModuleInfoPrivate;
00052 }
00053 
00054 KCModuleInfo::KCModuleInfo(const QString& desktopFile)
00055 {
00056   init( KService::serviceByStorageId(desktopFile) );
00057 }
00058 
00059 KCModuleInfo::KCModuleInfo( KService::Ptr moduleInfo )
00060 {
00061   init(moduleInfo);
00062 }
00063 
00064 KCModuleInfo::KCModuleInfo( const KCModuleInfo &rhs )
00065 {
00066     d = new KCModuleInfoPrivate;
00067     ( *this ) = rhs;
00068 }
00069 
00070 // this re-implementation exists to ensure that other code always calls
00071 // our re-implementation, so in case we add data to the d pointer in the future 
00072 // we can be sure that we get called when we are copied.
00073 KCModuleInfo &KCModuleInfo::operator=( const KCModuleInfo &rhs )
00074 {
00075     _keywords = rhs._keywords;
00076     _name = rhs._name;
00077     _icon = rhs._icon;
00078     _lib = rhs._lib;
00079     _handle = rhs._handle;
00080     _fileName = rhs._fileName;
00081     _doc = rhs._doc;
00082     _comment = rhs._comment;
00083     _needsRootPrivileges = rhs._needsRootPrivileges;
00084     _isHiddenByDefault = rhs._isHiddenByDefault;
00085     _allLoaded = rhs._allLoaded;
00086     _service = rhs._service;
00087 
00088     *d = *(rhs.d);
00089 
00090     return *this;
00091 }
00092 
00093 QString KCModuleInfo::factoryName() const
00094 {
00095   if( d->factoryName.isEmpty() )
00096   {
00097     d->factoryName = _service->property("X-KDE-FactoryName", QVariant::String).toString();
00098     if ( d->factoryName.isEmpty() )
00099       d->factoryName = library();
00100   }
00101 
00102   return d->factoryName;
00103 }
00104 
00105 bool KCModuleInfo::operator==( const KCModuleInfo & rhs ) const
00106 {
00107   return ( ( _name == rhs._name ) && ( _lib == rhs._lib ) && ( _fileName == rhs._fileName ) );
00108 }
00109 
00110 bool KCModuleInfo::operator!=( const KCModuleInfo & rhs ) const
00111 {
00112   return ! operator==( rhs );
00113 }
00114 
00115 KCModuleInfo::~KCModuleInfo()
00116 { 
00117   delete d;
00118 }
00119 
00120 void KCModuleInfo::init(KService::Ptr s)
00121 {
00122   _allLoaded = false;
00123   d = new KCModuleInfoPrivate;
00124 
00125   if ( s )
00126     _service = s;
00127   else
00128   {
00129     kdDebug(712) << "Could not find the service." << endl;
00130     return;
00131   }
00132 
00133   // set the modules simple attributes
00134   setName(_service->name());
00135   setComment(_service->comment());
00136   setIcon(_service->icon());
00137 
00138   _fileName = ( _service->desktopEntryPath() );
00139 
00140   // library and factory
00141   setLibrary(_service->library());
00142 
00143   // get the keyword list
00144   setKeywords(_service->keywords());
00145 }
00146 
00147 void
00148 KCModuleInfo::loadAll() 
00149 {
00150   if( !_service ) /* We have a bogus service. All get functions will return empty/zero values */
00151     return;
00152 
00153   _allLoaded = true;
00154 
00155   // library and factory
00156   setHandle(_service->property("X-KDE-FactoryName", QVariant::String).toString());
00157 
00158   QVariant tmp;
00159 
00160   // read weight
00161   tmp = _service->property( "X-KDE-Weight", QVariant::Int );
00162   setWeight( tmp.isValid() ? tmp.toInt() : 100 );
00163 
00164   // does the module need super user privileges?
00165   tmp = _service->property( "X-KDE-RootOnly", QVariant::Bool );
00166   setNeedsRootPrivileges( tmp.isValid() ? tmp.toBool() : false );
00167 
00168   // does the module need to be shown to root only?
00169   // Deprecated ! KDE 4
00170   tmp = _service->property( "X-KDE-IsHiddenByDefault", QVariant::Bool );
00171   setIsHiddenByDefault( tmp.isValid() ? tmp.toBool() : false );
00172 
00173   // get the documentation path
00174   setDocPath( _service->property( "DocPath", QVariant::String ).toString() );
00175 
00176   tmp = _service->property( "X-KDE-Test-Module", QVariant::Bool );
00177   setNeedsTest( tmp.isValid() ? tmp.asBool() : false );
00178 }
00179 
00180 QString
00181 KCModuleInfo::docPath() const
00182 {
00183   if (!_allLoaded) 
00184     const_cast<KCModuleInfo*>(this)->loadAll();
00185 
00186   return _doc;
00187 }
00188 
00189 QString
00190 KCModuleInfo::handle() const
00191 {
00192   if (!_allLoaded) 
00193     const_cast<KCModuleInfo*>(this)->loadAll();
00194 
00195   if (_handle.isEmpty())
00196      return _lib;
00197 
00198   return _handle;
00199 }
00200 
00201 int
00202 KCModuleInfo::weight() const
00203 {
00204   if (!_allLoaded) 
00205     const_cast<KCModuleInfo*>(this)->loadAll();
00206 
00207   return _weight;
00208 }
00209 
00210 bool
00211 KCModuleInfo::needsRootPrivileges() const
00212 {
00213   if (!_allLoaded) 
00214     const_cast<KCModuleInfo*>(this)->loadAll();
00215 
00216   return _needsRootPrivileges;
00217 }
00218 
00219 bool
00220 KCModuleInfo::isHiddenByDefault() const
00221 {
00222   if (!_allLoaded)
00223     const_cast<KCModuleInfo*>(this)->loadAll();
00224 
00225   return _isHiddenByDefault;
00226 }
00227 
00228 bool KCModuleInfo::needsTest() const 
00229 {
00230   return d->testModule;
00231 }
00232 
00233 void KCModuleInfo::setNeedsTest( bool val )
00234 {
00235   d->testModule = val;
00236 }
00237 
00238 
00239 
00240 // vim: ts=2 sw=2 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