2014-11-13 01:04:59 +02:00
|
|
|
/*
|
|
|
|
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,2006 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 "kcmoduleinfo.h"
|
|
|
|
|
|
|
|
#include <QtCore/QVariant>
|
|
|
|
|
|
|
|
#include <kdesktopfile.h>
|
|
|
|
#include <kdebug.h>
|
|
|
|
#include <kglobal.h>
|
|
|
|
#include <kstandarddirs.h>
|
|
|
|
#include <klocale.h>
|
|
|
|
|
|
|
|
class KCModuleInfo::Private
|
|
|
|
{
|
2023-07-30 09:44:43 +03:00
|
|
|
public:
|
2014-11-13 01:04:59 +02:00
|
|
|
Private();
|
2023-07-30 09:44:43 +03:00
|
|
|
Private(KService::Ptr s);
|
2014-11-13 01:04:59 +02:00
|
|
|
|
|
|
|
QStringList keywords;
|
2023-07-30 09:44:43 +03:00
|
|
|
QString name;
|
|
|
|
QString icon;
|
|
|
|
QString lib;
|
|
|
|
QString fileName;
|
|
|
|
QString doc;
|
|
|
|
QString comment;
|
|
|
|
bool allLoaded;
|
|
|
|
int weight;
|
2014-11-13 01:04:59 +02:00
|
|
|
|
|
|
|
KService::Ptr service;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reads the service entries specific for KCModule from the desktop file.
|
|
|
|
* The usual desktop entries are read in the Private ctor.
|
|
|
|
*/
|
|
|
|
void loadAll();
|
|
|
|
};
|
|
|
|
|
|
|
|
KCModuleInfo::Private::Private()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-07-30 09:44:43 +03:00
|
|
|
KCModuleInfo::Private::Private(KService::Ptr s)
|
|
|
|
: allLoaded(false),
|
|
|
|
service(s)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2023-07-30 09:44:43 +03:00
|
|
|
if (!service) {
|
|
|
|
kDebug(712) << "Could not find the service.";
|
|
|
|
return;
|
|
|
|
}
|
2014-11-13 01:04:59 +02:00
|
|
|
|
2023-07-30 09:44:43 +03:00
|
|
|
// set the modules simple attributes
|
|
|
|
name = service->name();
|
|
|
|
comment = service->comment();
|
|
|
|
icon = service->icon();
|
|
|
|
fileName = service->entryPath();
|
|
|
|
lib = service->library();
|
|
|
|
keywords = service->keywords();
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
KCModuleInfo::KCModuleInfo()
|
2023-07-30 09:44:43 +03:00
|
|
|
: d(new Private())
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-07-30 09:44:43 +03:00
|
|
|
KCModuleInfo::KCModuleInfo(const QString &desktopFile)
|
|
|
|
: d(new Private(KService::serviceByStorageId(desktopFile)))
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-07-30 09:44:43 +03:00
|
|
|
KCModuleInfo::KCModuleInfo(KService::Ptr moduleInfo)
|
|
|
|
: d(new Private(moduleInfo))
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-07-30 09:44:43 +03:00
|
|
|
KCModuleInfo::KCModuleInfo(const KCModuleInfo &rhs)
|
|
|
|
: d(new Private())
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2023-07-30 09:44:43 +03:00
|
|
|
(*this) = rhs;
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
2023-07-30 09:44:43 +03:00
|
|
|
KCModuleInfo &KCModuleInfo::operator=(const KCModuleInfo &rhs)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
|
|
|
*d = *(rhs.d);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2023-07-30 09:44:43 +03:00
|
|
|
bool KCModuleInfo::operator==(const KCModuleInfo &rhs) const
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2023-07-30 09:44:43 +03:00
|
|
|
return ((d->name == rhs.d->name) && (d->lib == rhs.d->lib) && (d->fileName == rhs.d->fileName));
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
2023-07-30 09:44:43 +03:00
|
|
|
bool KCModuleInfo::operator!=(const KCModuleInfo &rhs) const
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2023-07-30 09:44:43 +03:00
|
|
|
return !operator==(rhs);
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
KCModuleInfo::~KCModuleInfo()
|
|
|
|
{
|
2023-07-30 09:44:43 +03:00
|
|
|
delete d;
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void KCModuleInfo::Private::loadAll()
|
|
|
|
{
|
2023-07-30 09:44:43 +03:00
|
|
|
allLoaded = true;
|
2014-11-13 01:04:59 +02:00
|
|
|
|
2023-07-30 09:44:43 +03:00
|
|
|
if (!service) {
|
|
|
|
/* We have a bogus service. All get functions will return empty/zero values */
|
|
|
|
return;
|
|
|
|
}
|
2014-11-13 01:04:59 +02:00
|
|
|
|
2023-07-30 09:44:43 +03:00
|
|
|
// get the documentation path
|
|
|
|
doc = service->property("X-DocPath", QVariant::String).toString();
|
2014-11-13 01:04:59 +02:00
|
|
|
|
2023-07-30 09:44:43 +03:00
|
|
|
// read weight
|
|
|
|
QVariant tmp = service->property("X-KDE-Weight", QVariant::Int);
|
|
|
|
weight = tmp.isValid() ? tmp.toInt() : 100;
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QString KCModuleInfo::fileName() const
|
|
|
|
{
|
2023-07-30 09:44:43 +03:00
|
|
|
return d->fileName;
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QStringList KCModuleInfo::keywords() const
|
|
|
|
{
|
2023-07-30 09:44:43 +03:00
|
|
|
return d->keywords;
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QString KCModuleInfo::moduleName() const
|
|
|
|
{
|
2023-07-30 09:44:43 +03:00
|
|
|
return d->name;
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
KService::Ptr KCModuleInfo::service() const
|
|
|
|
{
|
2023-07-30 09:44:43 +03:00
|
|
|
return d->service;
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QString KCModuleInfo::comment() const
|
|
|
|
{
|
2023-07-30 09:44:43 +03:00
|
|
|
return d->comment;
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QString KCModuleInfo::icon() const
|
|
|
|
{
|
2023-07-30 09:44:43 +03:00
|
|
|
return d->icon;
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QString KCModuleInfo::library() const
|
|
|
|
{
|
2023-07-30 09:44:43 +03:00
|
|
|
return d->lib;
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QString KCModuleInfo::docPath() const
|
|
|
|
{
|
2023-07-30 09:44:43 +03:00
|
|
|
if (!d->allLoaded) {
|
|
|
|
d->loadAll();
|
|
|
|
}
|
|
|
|
return d->doc;
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int KCModuleInfo::weight() const
|
|
|
|
{
|
2023-07-30 09:44:43 +03:00
|
|
|
if (!d->allLoaded) {
|
|
|
|
d->loadAll();
|
|
|
|
}
|
|
|
|
return d->weight;
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|