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