kutils Library API Documentation

kcmoduleinfo.cpp

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., 59 Temple Place - Suite 330,
00021   Boston, MA 02111-1307, USA.
00022 */
00023 
00024 
00025 #include "kcmoduleinfo.h"
00026 
00027 #include <kdesktopfile.h>
00028 #include <kdebug.h>
00029 #include <kglobal.h>
00030 #include <kstandarddirs.h>
00031 #include <klocale.h>
00032 
00033 KCModuleInfo::KCModuleInfo(const QString& desktopFile)
00034   : _fileName(desktopFile), d(0L)
00035 {
00036   _allLoaded = false;
00037 
00038   //kdDebug(1208) << "desktopFile = " << desktopFile << endl;
00039   KService::Ptr sptr = KService::serviceByStorageId(desktopFile);
00040   if ( !sptr )
00041   {
00042     kdWarning() << "Could not find the service " << desktopFile << endl;
00043     return;
00044   }
00045   init( sptr );
00046 }
00047 
00048 KCModuleInfo::KCModuleInfo( KService::Ptr moduleInfo )
00049   : _fileName( moduleInfo->desktopEntryPath() )
00050 {
00051   kdDebug() << k_funcinfo << _fileName << endl;
00052   _allLoaded = false;
00053 
00054   init(moduleInfo);
00055 }
00056 
00057 KCModuleInfo::KCModuleInfo( const KCModuleInfo &rhs )
00058     : d( 0 )
00059 {
00060     ( *this ) = rhs;
00061 }
00062 
00063 // this re-implementation exists to ensure that other code always calls
00064 // our re-implementation, so in case we add data to the d pointer in the future 
00065 // we can be sure that we get called when we are copied.
00066 KCModuleInfo &KCModuleInfo::operator=( const KCModuleInfo &rhs )
00067 {
00068     _keywords = rhs._keywords;
00069     _name = rhs._name;
00070     _icon = rhs._icon;
00071     _lib = rhs._lib;
00072     _handle = rhs._handle;
00073     _fileName = rhs._fileName;
00074     _doc = rhs._doc;
00075     _comment = rhs._comment;
00076     _needsRootPrivileges = rhs._needsRootPrivileges;
00077     _isHiddenByDefault = rhs._isHiddenByDefault;
00078     _allLoaded = rhs._allLoaded;
00079     _service = rhs._service;
00080 
00081     // d pointer ... once used.
00082 
00083     return *this;
00084 }
00085 
00086 bool KCModuleInfo::operator==( const KCModuleInfo & rhs ) const
00087 {
00088   return ( ( _name == rhs._name ) && ( _lib == rhs._lib ) && ( _fileName == rhs._fileName ) );
00089 }
00090 
00091 bool KCModuleInfo::operator!=( const KCModuleInfo & rhs ) const
00092 {
00093   return ! operator==( rhs );
00094 }
00095 
00096 KCModuleInfo::~KCModuleInfo() { }
00097 
00098 void KCModuleInfo::init(KService::Ptr s)
00099 {
00100   if ( !s )
00101     return;
00102 
00103   _service = s;
00104   // set the modules simple attributes
00105   setName(_service->name());
00106   setComment(_service->comment());
00107   setIcon(_service->icon());
00108 
00109   // library and factory
00110   setLibrary(_service->library());
00111 
00112   // get the keyword list
00113   setKeywords(_service->keywords());
00114 }
00115 
00116 void
00117 KCModuleInfo::loadAll() 
00118 {
00119   if( !_service ) /* We have a bogus service. All get functions will return empty/zero values */
00120     return;
00121 
00122   _allLoaded = true;
00123 
00124   // library and factory
00125   setHandle(_service->property("X-KDE-FactoryName", QVariant::String).toString());
00126 
00127   QVariant tmp;
00128 
00129   // read weight
00130   tmp = _service->property( "X-KDE-Weight", QVariant::Int );
00131   setWeight( tmp.isValid() ? tmp.toInt() : 100 );
00132 
00133   // does the module need super user privileges?
00134   tmp = _service->property( "X-KDE-RootOnly", QVariant::Bool );
00135   setNeedsRootPrivileges( tmp.isValid() ? tmp.toBool() : false );
00136 
00137   // does the module need to be shown to root only?
00138   // Deprecated !
00139   tmp = _service->property( "X-KDE-IsHiddenByDefault", QVariant::Bool );
00140   setIsHiddenByDefault( tmp.isValid() ? tmp.toBool() : false );
00141 
00142   // get the documentation path
00143   setDocPath( _service->property( "DocPath", QVariant::String ).toString() );
00144 }
00145 
00146 QString
00147 KCModuleInfo::docPath() const
00148 {
00149   if (!_allLoaded) 
00150     const_cast<KCModuleInfo*>(this)->loadAll();
00151 
00152   return _doc;
00153 }
00154 
00155 QString
00156 KCModuleInfo::handle() const
00157 {
00158   if (!_allLoaded) 
00159     const_cast<KCModuleInfo*>(this)->loadAll();
00160 
00161   if (_handle.isEmpty())
00162      return _lib;
00163 
00164   return _handle;
00165 }
00166 
00167 int
00168 KCModuleInfo::weight() const
00169 {
00170   if (!_allLoaded) 
00171     const_cast<KCModuleInfo*>(this)->loadAll();
00172 
00173   return _weight;
00174 }
00175 
00176 bool
00177 KCModuleInfo::needsRootPrivileges() const
00178 {
00179   if (!_allLoaded) 
00180     const_cast<KCModuleInfo*>(this)->loadAll();
00181 
00182   return _needsRootPrivileges;
00183 }
00184 
00185 bool
00186 KCModuleInfo::isHiddenByDefault() const
00187 {
00188   if (!_allLoaded)
00189     const_cast<KCModuleInfo*>(this)->loadAll();
00190 
00191   return _isHiddenByDefault;
00192 }
00193 
00194 // vim: ts=2 sw=2 et
KDE Logo
This file is part of the documentation for kutils Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sun Jan 15 13:33:54 2006 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003