You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
243 lines
5.5 KiB
243 lines
5.5 KiB
15 years ago
|
/*
|
||
|
Copyright (c) 1999 Matthias Hoelzer-Kluepfel <hoelzer@kde.org>
|
||
|
Copyright (c) 2000 Matthias Elter <elter@kde.org>
|
||
|
Copyright (c) 2003 Daniel Molkentin <molkentin@kde.org>
|
||
|
Copyright (c) 2003 Matthias Kretz <kretz@kde.org>
|
||
|
|
||
|
This file is part of the KDE project
|
||
|
|
||
|
This library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU Library General Public
|
||
|
License version 2, as published by the Free Software Foundation.
|
||
|
|
||
|
This library is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
Library General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
15 years ago
|
#include <tqvariant.h>
|
||
15 years ago
|
|
||
|
#include <kdesktopfile.h>
|
||
|
#include <kdebug.h>
|
||
|
#include <kglobal.h>
|
||
|
#include <kstandarddirs.h>
|
||
|
#include <klocale.h>
|
||
|
|
||
12 years ago
|
#include "tdecmoduleinfo.h"
|
||
15 years ago
|
|
||
12 years ago
|
class TDECModuleInfo::TDECModuleInfoPrivate
|
||
15 years ago
|
{
|
||
|
public:
|
||
12 years ago
|
TDECModuleInfoPrivate() :
|
||
15 years ago
|
testModule( false )
|
||
|
{}
|
||
12 years ago
|
~TDECModuleInfoPrivate()
|
||
15 years ago
|
{ }
|
||
|
|
||
15 years ago
|
TQString factoryName;
|
||
15 years ago
|
bool testModule;
|
||
|
|
||
|
};
|
||
|
|
||
12 years ago
|
TDECModuleInfo::TDECModuleInfo()
|
||
15 years ago
|
{
|
||
|
_allLoaded = false;
|
||
12 years ago
|
d = new TDECModuleInfoPrivate;
|
||
15 years ago
|
}
|
||
|
|
||
12 years ago
|
TDECModuleInfo::TDECModuleInfo(const TQString& desktopFile)
|
||
15 years ago
|
{
|
||
15 years ago
|
KService::Ptr service = KService::serviceByStorageId(desktopFile);
|
||
|
if(!service) setName(desktopFile);
|
||
|
init(service);
|
||
15 years ago
|
}
|
||
|
|
||
12 years ago
|
TDECModuleInfo::TDECModuleInfo( KService::Ptr moduleInfo )
|
||
15 years ago
|
{
|
||
|
init(moduleInfo);
|
||
|
}
|
||
|
|
||
12 years ago
|
TDECModuleInfo::TDECModuleInfo( const TDECModuleInfo &rhs )
|
||
15 years ago
|
{
|
||
12 years ago
|
d = new TDECModuleInfoPrivate;
|
||
15 years ago
|
( *this ) = rhs;
|
||
|
}
|
||
|
|
||
|
// this re-implementation exists to ensure that other code always calls
|
||
|
// our re-implementation, so in case we add data to the d pointer in the future
|
||
|
// we can be sure that we get called when we are copied.
|
||
12 years ago
|
TDECModuleInfo &TDECModuleInfo::operator=( const TDECModuleInfo &rhs )
|
||
15 years ago
|
{
|
||
|
_keywords = rhs._keywords;
|
||
|
_name = rhs._name;
|
||
|
_icon = rhs._icon;
|
||
|
_lib = rhs._lib;
|
||
|
_handle = rhs._handle;
|
||
|
_fileName = rhs._fileName;
|
||
|
_doc = rhs._doc;
|
||
|
_comment = rhs._comment;
|
||
|
_needsRootPrivileges = rhs._needsRootPrivileges;
|
||
|
_isHiddenByDefault = rhs._isHiddenByDefault;
|
||
|
_allLoaded = rhs._allLoaded;
|
||
|
_service = rhs._service;
|
||
|
|
||
|
*d = *(rhs.d);
|
||
|
|
||
|
return *this;
|
||
|
}
|
||
|
|
||
12 years ago
|
TQString TDECModuleInfo::factoryName() const
|
||
15 years ago
|
{
|
||
|
if( d->factoryName.isEmpty() )
|
||
|
{
|
||
13 years ago
|
d->factoryName = _service->property("X-TDE-FactoryName", TQVariant::String).toString();
|
||
15 years ago
|
if ( d->factoryName.isEmpty() )
|
||
|
d->factoryName = library();
|
||
|
}
|
||
|
|
||
|
return d->factoryName;
|
||
|
}
|
||
|
|
||
12 years ago
|
bool TDECModuleInfo::operator==( const TDECModuleInfo & rhs ) const
|
||
15 years ago
|
{
|
||
|
return ( ( _name == rhs._name ) && ( _lib == rhs._lib ) && ( _fileName == rhs._fileName ) );
|
||
|
}
|
||
|
|
||
12 years ago
|
bool TDECModuleInfo::operator!=( const TDECModuleInfo & rhs ) const
|
||
15 years ago
|
{
|
||
|
return ! operator==( rhs );
|
||
|
}
|
||
|
|
||
12 years ago
|
TDECModuleInfo::~TDECModuleInfo()
|
||
15 years ago
|
{
|
||
|
delete d;
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDECModuleInfo::init(KService::Ptr s)
|
||
15 years ago
|
{
|
||
|
_allLoaded = false;
|
||
12 years ago
|
d = new TDECModuleInfoPrivate;
|
||
15 years ago
|
|
||
|
if ( s )
|
||
|
_service = s;
|
||
|
else
|
||
|
{
|
||
14 years ago
|
kdDebug(712) << "Could not find the service." << endl;
|
||
15 years ago
|
return;
|
||
|
}
|
||
|
|
||
|
// set the modules simple attributes
|
||
|
setName(_service->name());
|
||
|
setComment(_service->comment());
|
||
|
setIcon(_service->icon());
|
||
|
|
||
|
_fileName = ( _service->desktopEntryPath() );
|
||
|
|
||
|
// library and factory
|
||
|
setLibrary(_service->library());
|
||
|
|
||
|
// get the keyword list
|
||
|
setKeywords(_service->keywords());
|
||
|
}
|
||
|
|
||
|
void
|
||
12 years ago
|
TDECModuleInfo::loadAll()
|
||
15 years ago
|
{
|
||
|
if( !_service ) /* We have a bogus service. All get functions will return empty/zero values */
|
||
|
return;
|
||
|
|
||
|
_allLoaded = true;
|
||
|
|
||
|
// library and factory
|
||
13 years ago
|
setHandle(_service->property("X-TDE-FactoryName", TQVariant::String).toString());
|
||
15 years ago
|
|
||
15 years ago
|
TQVariant tmp;
|
||
15 years ago
|
|
||
|
// read weight
|
||
13 years ago
|
tmp = _service->property( "X-TDE-Weight", TQVariant::Int );
|
||
15 years ago
|
setWeight( tmp.isValid() ? tmp.toInt() : 100 );
|
||
|
|
||
|
// does the module need super user privileges?
|
||
13 years ago
|
tmp = _service->property( "X-TDE-RootOnly", TQVariant::Bool );
|
||
15 years ago
|
setNeedsRootPrivileges( tmp.isValid() ? tmp.toBool() : false );
|
||
|
|
||
|
// does the module need to be shown to root only?
|
||
|
// Deprecated ! KDE 4
|
||
13 years ago
|
tmp = _service->property( "X-TDE-IsHiddenByDefault", TQVariant::Bool );
|
||
15 years ago
|
setIsHiddenByDefault( tmp.isValid() ? tmp.toBool() : false );
|
||
|
|
||
|
// get the documentation path
|
||
15 years ago
|
setDocPath( _service->property( "DocPath", TQVariant::String ).toString() );
|
||
15 years ago
|
|
||
13 years ago
|
tmp = _service->property( "X-TDE-Test-Module", TQVariant::Bool );
|
||
15 years ago
|
setNeedsTest( tmp.isValid() ? tmp.asBool() : false );
|
||
|
}
|
||
|
|
||
14 years ago
|
TQString
|
||
12 years ago
|
TDECModuleInfo::docPath() const
|
||
15 years ago
|
{
|
||
|
if (!_allLoaded)
|
||
12 years ago
|
const_cast<TDECModuleInfo*>(this)->loadAll();
|
||
15 years ago
|
|
||
|
return _doc;
|
||
|
}
|
||
|
|
||
14 years ago
|
TQString
|
||
12 years ago
|
TDECModuleInfo::handle() const
|
||
15 years ago
|
{
|
||
|
if (!_allLoaded)
|
||
12 years ago
|
const_cast<TDECModuleInfo*>(this)->loadAll();
|
||
15 years ago
|
|
||
|
if (_handle.isEmpty())
|
||
|
return _lib;
|
||
|
|
||
|
return _handle;
|
||
|
}
|
||
|
|
||
|
int
|
||
12 years ago
|
TDECModuleInfo::weight() const
|
||
15 years ago
|
{
|
||
|
if (!_allLoaded)
|
||
12 years ago
|
const_cast<TDECModuleInfo*>(this)->loadAll();
|
||
15 years ago
|
|
||
|
return _weight;
|
||
|
}
|
||
|
|
||
|
bool
|
||
12 years ago
|
TDECModuleInfo::needsRootPrivileges() const
|
||
15 years ago
|
{
|
||
|
if (!_allLoaded)
|
||
12 years ago
|
const_cast<TDECModuleInfo*>(this)->loadAll();
|
||
15 years ago
|
|
||
|
return _needsRootPrivileges;
|
||
|
}
|
||
|
|
||
|
bool
|
||
12 years ago
|
TDECModuleInfo::isHiddenByDefault() const
|
||
15 years ago
|
{
|
||
|
if (!_allLoaded)
|
||
12 years ago
|
const_cast<TDECModuleInfo*>(this)->loadAll();
|
||
15 years ago
|
|
||
|
return _isHiddenByDefault;
|
||
|
}
|
||
|
|
||
12 years ago
|
bool TDECModuleInfo::needsTest() const
|
||
15 years ago
|
{
|
||
|
return d->testModule;
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDECModuleInfo::setNeedsTest( bool val )
|
||
15 years ago
|
{
|
||
|
d->testModule = val;
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
// vim: ts=2 sw=2 et
|