kcmoduleinfo.cpp
/*
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.
*/
#include <qvariant.h>
#include <kdesktopfile.h>
#include <kdebug.h>
#include <kglobal.h>
#include <kstandarddirs.h>
#include <klocale.h>
#include "kcmoduleinfo.h"
class KCModuleInfo::KCModuleInfoPrivate
{
public:
KCModuleInfoPrivate() :
testModule( false )
{}
~KCModuleInfoPrivate()
{ }
QString factoryName;
bool testModule;
};
KCModuleInfo::KCModuleInfo()
{
_allLoaded = false;
d = new KCModuleInfoPrivate;
}
KCModuleInfo::KCModuleInfo(const QString& desktopFile)
{
init( KService::serviceByStorageId(desktopFile) );
}
KCModuleInfo::KCModuleInfo( KService::Ptr moduleInfo )
{
init(moduleInfo);
}
KCModuleInfo::KCModuleInfo( const KCModuleInfo &rhs )
{
d = new KCModuleInfoPrivate;
( *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.
KCModuleInfo &KCModuleInfo::operator=( const KCModuleInfo &rhs )
{
_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;
}
QString KCModuleInfo::factoryName() const
{
if( d->factoryName.isEmpty() )
{
d->factoryName = _service->property("X-KDE-FactoryName", QVariant::String).toString();
if ( d->factoryName.isEmpty() )
d->factoryName = library();
}
return d->factoryName;
}
bool KCModuleInfo::operator==( const KCModuleInfo & rhs ) const
{
return ( ( _name == rhs._name ) && ( _lib == rhs._lib ) && ( _fileName == rhs._fileName ) );
}
bool KCModuleInfo::operator!=( const KCModuleInfo & rhs ) const
{
return ! operator==( rhs );
}
KCModuleInfo::~KCModuleInfo()
{
delete d;
}
void KCModuleInfo::init(KService::Ptr s)
{
_allLoaded = false;
d = new KCModuleInfoPrivate;
if ( s )
_service = s;
else
{
kdDebug(712) << "Could not find the service." << endl;
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
KCModuleInfo::loadAll()
{
if( !_service ) /* We have a bogus service. All get functions will return empty/zero values */
return;
_allLoaded = true;
// library and factory
setHandle(_service->property("X-KDE-FactoryName", QVariant::String).toString());
QVariant tmp;
// read weight
tmp = _service->property( "X-KDE-Weight", QVariant::Int );
setWeight( tmp.isValid() ? tmp.toInt() : 100 );
// does the module need super user privileges?
tmp = _service->property( "X-KDE-RootOnly", QVariant::Bool );
setNeedsRootPrivileges( tmp.isValid() ? tmp.toBool() : false );
// does the module need to be shown to root only?
// Deprecated ! KDE 4
tmp = _service->property( "X-KDE-IsHiddenByDefault", QVariant::Bool );
setIsHiddenByDefault( tmp.isValid() ? tmp.toBool() : false );
// get the documentation path
setDocPath( _service->property( "DocPath", QVariant::String ).toString() );
tmp = _service->property( "X-KDE-Test-Module", QVariant::Bool );
setNeedsTest( tmp.isValid() ? tmp.asBool() : false );
}
QString
KCModuleInfo::docPath() const
{
if (!_allLoaded)
const_cast<KCModuleInfo*>(this)->loadAll();
return _doc;
}
QString
KCModuleInfo::handle() const
{
if (!_allLoaded)
const_cast<KCModuleInfo*>(this)->loadAll();
if (_handle.isEmpty())
return _lib;
return _handle;
}
int
KCModuleInfo::weight() const
{
if (!_allLoaded)
const_cast<KCModuleInfo*>(this)->loadAll();
return _weight;
}
bool
KCModuleInfo::needsRootPrivileges() const
{
if (!_allLoaded)
const_cast<KCModuleInfo*>(this)->loadAll();
return _needsRootPrivileges;
}
bool
KCModuleInfo::isHiddenByDefault() const
{
if (!_allLoaded)
const_cast<KCModuleInfo*>(this)->loadAll();
return _isHiddenByDefault;
}
bool KCModuleInfo::needsTest() const
{
return d->testModule;
}
void KCModuleInfo::setNeedsTest( bool val )
{
d->testModule = val;
}
// vim: ts=2 sw=2 et
KCModuleInfo::setComment
void setComment(const QString &comment)
Sets the object's name.
Definition: kcmoduleinfo.h:208
KCModuleInfo::setHandle
void setHandle(const QString &handle)
Sets the factory name.
Definition: kcmoduleinfo.h:226
KCModuleInfo::setName
void setName(const QString &name)
Sets the object's name.
Definition: kcmoduleinfo.h:202
KCModuleInfo::loadAll
void loadAll()
Reads the service entries specific for KCModule from the desktop file.
Definition: kcmoduleinfo.cpp:148
KCModuleInfo::weight
int weight() const
Definition: kcmoduleinfo.cpp:202
KCModuleInfo::~KCModuleInfo
~KCModuleInfo()
Default destructor.
Definition: kcmoduleinfo.cpp:115
KCModuleInfo::factoryName
QString factoryName() const
Returns the module's factory name, if it's set.
Definition: kcmoduleinfo.cpp:93
kdDebug
kdbgstream kdDebug(int area=0)
KCModuleInfo::setKeywords
void setKeywords(const QStringList &keyword)
Sets the object's keywords.
Definition: kcmoduleinfo.h:196
klocale.h
KCModuleInfo::setLibrary
void setLibrary(const QString &lib)
Set the object's library.
Definition: kcmoduleinfo.h:220
KCModuleInfo::setDocPath
void setDocPath(const QString &p)
Sets the object's documentation path.
Definition: kcmoduleinfo.h:262
KCModuleInfo::isHiddenByDefault
bool isHiddenByDefault() const KDE_DEPRECATED
Definition: kcmoduleinfo.cpp:220
KCModuleInfo::setIsHiddenByDefault
void setIsHiddenByDefault(bool isHiddenByDefault)
Definition: kcmoduleinfo.h:255
KCModuleInfo::setNeedsTest
void setNeedsTest(bool val)
Sets if the module should be tested for loading.
Definition: kcmoduleinfo.cpp:233
KCModuleInfo::setWeight
void setWeight(int weight)
Sets the object's weight property which determines in what order modules will be displayed.
Definition: kcmoduleinfo.h:234
KCModuleInfo::needsRootPrivileges
bool needsRootPrivileges() const
Definition: kcmoduleinfo.cpp:211
KCModuleInfo::setNeedsRootPrivileges
void setNeedsRootPrivileges(bool needsRootPrivileges)
Toggles whether the represented module needs root privileges.
Definition: kcmoduleinfo.h:249
KCModuleInfo::library
QString library() const
Definition: kcmoduleinfo.h:157
KCModuleInfo
A class that provides information about a KCModule.
Definition: kcmoduleinfo.h:49
KCModuleInfo::setIcon
void setIcon(const QString &icon)
Sets the object's icon.
Definition: kcmoduleinfo.h:214
KCModuleInfo::KCModuleInfo
KCModuleInfo()
Same as above but creates an empty KCModuleInfo.
Definition: kcmoduleinfo.cpp:48
KCModuleInfo::operator=
KCModuleInfo & operator=(const KCModuleInfo &rhs)
Assignment operator.
Definition: kcmoduleinfo.cpp:73
KCModuleInfo::needsTest
bool needsTest() const
Definition: kcmoduleinfo.cpp:228
KCModuleInfo::operator!=
bool operator!=(const KCModuleInfo &rhs) const
Definition: kcmoduleinfo.cpp:110
endl
kndbgstream & endl(kndbgstream &s)
KCModuleInfo::docPath
QString docPath() const
Definition: kcmoduleinfo.cpp:181
KCModuleInfo::handle
QString handle() const
Definition: kcmoduleinfo.cpp:190
KCModuleInfo::operator==
bool operator==(const KCModuleInfo &rhs) const
Equal operator.
Definition: kcmoduleinfo.cpp:105

KDE Home | KDE Accessibility Home | Description of Access Keys