• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeutils
 

tdeutils

tdecmoduleinfo.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., 51 Franklin Street, Fifth Floor,
00021   Boston, MA 02110-1301, USA.
00022 */
00023 
00024 #include <tqvariant.h>
00025 
00026 #include <kdesktopfile.h>
00027 #include <kdebug.h>
00028 #include <tdeglobal.h>
00029 #include <kstandarddirs.h>
00030 #include <tdelocale.h>
00031 
00032 #include "tdecmoduleinfo.h"
00033 
00034 class TDECModuleInfo::TDECModuleInfoPrivate
00035 {
00036   public:
00037     TDECModuleInfoPrivate() :
00038       testModule( false )
00039     {}
00040     ~TDECModuleInfoPrivate()
00041     { }
00042 
00043     TQString factoryName;
00044     bool testModule;
00045 
00046 };
00047 
00048 TDECModuleInfo::TDECModuleInfo()
00049 {
00050   _allLoaded = false;
00051   d = new TDECModuleInfoPrivate;
00052 }
00053 
00054 TDECModuleInfo::TDECModuleInfo(const TQString& desktopFile)
00055 {
00056   KService::Ptr service = KService::serviceByStorageId(desktopFile);
00057   if(!service) setName(desktopFile);
00058   init(service);
00059 }
00060 
00061 TDECModuleInfo::TDECModuleInfo( KService::Ptr moduleInfo )
00062 {
00063   init(moduleInfo);
00064 }
00065 
00066 TDECModuleInfo::TDECModuleInfo( const TDECModuleInfo &rhs )
00067 {
00068     d = new TDECModuleInfoPrivate;
00069     ( *this ) = rhs;
00070 }
00071 
00072 // this re-implementation exists to ensure that other code always calls
00073 // our re-implementation, so in case we add data to the d pointer in the future 
00074 // we can be sure that we get called when we are copied.
00075 TDECModuleInfo &TDECModuleInfo::operator=( const TDECModuleInfo &rhs )
00076 {
00077     _keywords = rhs._keywords;
00078     _name = rhs._name;
00079     _icon = rhs._icon;
00080     _lib = rhs._lib;
00081     _handle = rhs._handle;
00082     _fileName = rhs._fileName;
00083     _doc = rhs._doc;
00084     _comment = rhs._comment;
00085     _needsRootPrivileges = rhs._needsRootPrivileges;
00086     _isHiddenByDefault = rhs._isHiddenByDefault;
00087     _allLoaded = rhs._allLoaded;
00088     _service = rhs._service;
00089 
00090     *d = *(rhs.d);
00091 
00092     return *this;
00093 }
00094 
00095 TQString TDECModuleInfo::factoryName() const
00096 {
00097   if( d->factoryName.isEmpty() )
00098   {
00099     d->factoryName = _service->property("X-TDE-FactoryName", TQVariant::String).toString();
00100     if ( d->factoryName.isEmpty() )
00101       d->factoryName = library();
00102   }
00103 
00104   return d->factoryName;
00105 }
00106 
00107 bool TDECModuleInfo::operator==( const TDECModuleInfo & rhs ) const
00108 {
00109   return ( ( _name == rhs._name ) && ( _lib == rhs._lib ) && ( _fileName == rhs._fileName ) );
00110 }
00111 
00112 bool TDECModuleInfo::operator!=( const TDECModuleInfo & rhs ) const
00113 {
00114   return ! operator==( rhs );
00115 }
00116 
00117 TDECModuleInfo::~TDECModuleInfo()
00118 { 
00119   delete d;
00120 }
00121 
00122 void TDECModuleInfo::init(KService::Ptr s)
00123 {
00124   _allLoaded = false;
00125   d = new TDECModuleInfoPrivate;
00126 
00127   if ( s )
00128     _service = s;
00129   else
00130   {
00131     kdDebug(712) << "Could not find the service." << endl;
00132     return;
00133   }
00134 
00135   // set the modules simple attributes
00136   setName(_service->name());
00137   setComment(_service->comment());
00138   setIcon(_service->icon());
00139 
00140   _fileName = ( _service->desktopEntryPath() );
00141 
00142   // library and factory
00143   setLibrary(_service->library());
00144 
00145   // get the keyword list
00146   setKeywords(_service->keywords());
00147 }
00148 
00149 void
00150 TDECModuleInfo::loadAll() 
00151 {
00152   if( !_service ) /* We have a bogus service. All get functions will return empty/zero values */
00153     return;
00154 
00155   _allLoaded = true;
00156 
00157   // library and factory
00158   setHandle(_service->property("X-TDE-FactoryName", TQVariant::String).toString());
00159 
00160   TQVariant tmp;
00161 
00162   // read weight
00163   tmp = _service->property( "X-TDE-Weight", TQVariant::Int );
00164   setWeight( tmp.isValid() ? tmp.toInt() : 100 );
00165 
00166   // does the module need super user privileges?
00167   tmp = _service->property( "X-TDE-RootOnly", TQVariant::Bool );
00168   setNeedsRootPrivileges( tmp.isValid() ? tmp.toBool() : false );
00169 
00170   // does the module need to be shown to root only?
00171   // Deprecated ! KDE 4
00172   tmp = _service->property( "X-TDE-IsHiddenByDefault", TQVariant::Bool );
00173   setIsHiddenByDefault( tmp.isValid() ? tmp.toBool() : false );
00174 
00175   // get the documentation path
00176   setDocPath( _service->property( "X-DocPath", TQVariant::String ).toString() );
00177 
00178   tmp = _service->property( "X-TDE-Test-Module", TQVariant::Bool );
00179   setNeedsTest( tmp.isValid() ? tmp.asBool() : false );
00180 }
00181 
00182 TQString
00183 TDECModuleInfo::docPath() const
00184 {
00185   if (!_allLoaded) 
00186     const_cast<TDECModuleInfo*>(this)->loadAll();
00187 
00188   return _doc;
00189 }
00190 
00191 TQString
00192 TDECModuleInfo::handle() const
00193 {
00194   if (!_allLoaded) 
00195     const_cast<TDECModuleInfo*>(this)->loadAll();
00196 
00197   if (_handle.isEmpty())
00198      return _lib;
00199 
00200   return _handle;
00201 }
00202 
00203 int
00204 TDECModuleInfo::weight() const
00205 {
00206   if (!_allLoaded) 
00207     const_cast<TDECModuleInfo*>(this)->loadAll();
00208 
00209   return _weight;
00210 }
00211 
00212 bool
00213 TDECModuleInfo::needsRootPrivileges() const
00214 {
00215   if (!_allLoaded) 
00216     const_cast<TDECModuleInfo*>(this)->loadAll();
00217 
00218   return _needsRootPrivileges;
00219 }
00220 
00221 bool
00222 TDECModuleInfo::isHiddenByDefault() const
00223 {
00224   if (!_allLoaded)
00225     const_cast<TDECModuleInfo*>(this)->loadAll();
00226 
00227   return _isHiddenByDefault;
00228 }
00229 
00230 bool TDECModuleInfo::needsTest() const 
00231 {
00232   return d->testModule;
00233 }
00234 
00235 void TDECModuleInfo::setNeedsTest( bool val )
00236 {
00237   d->testModule = val;
00238 }
00239 
00240 
00241 
00242 // vim: ts=2 sw=2 et

tdeutils

Skip menu "tdeutils"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

tdeutils

Skip menu "tdeutils"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeutils by doxygen 1.6.3
This website is maintained by Timothy Pearson.