Make QCA2 an optional dependency for libplasma, so QCA2 can remain optional for all of kdelibs. Just disable remote widgets functionality if QCA2 is missing.

svn path=/trunk/KDE/kdelibs/; revision=1021543
This commit is contained in:
Rob Scheepmaker 2009-09-09 13:40:16 +00:00
parent 020c8b65c6
commit 34b9e01ac4
8 changed files with 75 additions and 11 deletions

View File

@ -15,10 +15,11 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}
${KDE4_INCLUDES} ${KDE4_INCLUDES}
) )
find_package(QCA2 REQUIRED) if(QCA2_FOUND)
include_directories(${QCA2_INCLUDE_DIR})
set(ENABLE_REMOTE_WIDGETS TRUE)
include_directories(${QCA2_INCLUDE_DIR}) endif(QCA2_FOUND)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
if(QT_QTOPENGL_FOUND AND OPENGL_FOUND) if(QT_QTOPENGL_FOUND AND OPENGL_FOUND)
# libGL needs dlopen() and friends from the dl library # libGL needs dlopen() and friends from the dl library

View File

@ -100,6 +100,8 @@
#include "private/toolbox_p.h" #include "private/toolbox_p.h"
#include "ui_publish.h" #include "ui_publish.h"
#include "config.h"
namespace Plasma namespace Plasma
{ {
@ -1649,7 +1651,9 @@ void Applet::showConfigurationInterface()
} }
d->addGlobalShortcutsPage(dialog); d->addGlobalShortcutsPage(dialog);
#ifdef ENABLE_REMOTE_WIDGETS
d->addPublishPage(dialog); d->addPublishPage(dialog);
#endif
dialog->show(); dialog->show();
} else if (d->script) { } else if (d->script) {
d->script->showConfigurationInterface(); d->script->showConfigurationInterface();
@ -1708,7 +1712,9 @@ KConfigDialog *AppletPrivate::generateGenericConfigDialog()
dialog->setAttribute(Qt::WA_DeleteOnClose, true); dialog->setAttribute(Qt::WA_DeleteOnClose, true);
q->createConfigurationInterface(dialog); q->createConfigurationInterface(dialog);
addGlobalShortcutsPage(dialog); addGlobalShortcutsPage(dialog);
#ifdef ENABLE_REMOTE_WIDGETS
addPublishPage(dialog); addPublishPage(dialog);
#endif
//TODO: Apply button does not correctly work for now, so do not show it //TODO: Apply button does not correctly work for now, so do not show it
dialog->showButton(KDialog::Apply, false); dialog->showButton(KDialog::Apply, false);
QObject::connect(dialog, SIGNAL(applyClicked()), q, SLOT(configDialogFinished())); QObject::connect(dialog, SIGNAL(applyClicked()), q, SLOT(configDialogFinished()));

2
config.h.in Normal file
View File

@ -0,0 +1,2 @@
#cmakedefine ENABLE_REMOTE_WIDGETS

View File

@ -23,6 +23,8 @@
#include "servicejob.h" #include "servicejob.h"
#include "applet.h" #include "applet.h"
#include "config.h"
#include <kzip.h> #include <kzip.h>
#include <kdebug.h> #include <kdebug.h>
#include <ktempdir.h> #include <ktempdir.h>
@ -147,10 +149,17 @@ Applet *AccessAppletJob::applet() const
void AccessAppletJob::start() void AccessAppletJob::start()
{ {
#ifdef ENABLE_REMOTE_WIDGETS
kDebug() << "fetching a plasmoid from location = " << d->location.prettyUrl(); kDebug() << "fetching a plasmoid from location = " << d->location.prettyUrl();
Service *service = Service::access(d->location); Service *service = Service::access(d->location);
connect(service, SIGNAL(serviceReady(Plasma::Service*)), connect(service, SIGNAL(serviceReady(Plasma::Service*)),
this, SLOT(slotServiceReady(Plasma::Service*))); this, SLOT(slotServiceReady(Plasma::Service*)));
#else
kWarning() << "libplasma was compiled without support for remote services. Accessing remote applet failed because of that.";
setError(-1);
setErrorText(i18n("Your system doesn't provide support for the 'remote widgets' feature. Access Failed."));
emitResult();
#endif
} }
} // namespace Plasma } // namespace Plasma

View File

@ -25,6 +25,8 @@
#include "serviceaccessjob.h" #include "serviceaccessjob.h"
#include "private/authorizationmanager_p.h" #include "private/authorizationmanager_p.h"
#include "config.h"
#include <QtCore/QMap> #include <QtCore/QMap>
#include <QtCore/QTimer> #include <QtCore/QTimer>
@ -96,11 +98,15 @@ AccessManagerPrivate::AccessManagerPrivate(AccessManager *manager)
: q(manager), : q(manager),
browser(new DNSSD::ServiceBrowser("_plasma._tcp")) browser(new DNSSD::ServiceBrowser("_plasma._tcp"))
{ {
#ifdef ENABLE_REMOTE_WIDGETS
q->connect(browser, SIGNAL(serviceAdded(DNSSD::RemoteService::Ptr)), q->connect(browser, SIGNAL(serviceAdded(DNSSD::RemoteService::Ptr)),
q, SLOT(slotAddService(DNSSD::RemoteService::Ptr))); q, SLOT(slotAddService(DNSSD::RemoteService::Ptr)));
q->connect(browser, SIGNAL(serviceRemoved(DNSSD::RemoteService::Ptr)), q->connect(browser, SIGNAL(serviceRemoved(DNSSD::RemoteService::Ptr)),
q, SLOT(slotRemoveService(DNSSD::RemoteService::Ptr))); q, SLOT(slotRemoveService(DNSSD::RemoteService::Ptr)));
browser->startBrowse(); browser->startBrowse();
#else
kWarning() << "libplasma is compiled without support for remote widgets. not monitoring remote widgets on the network";
#endif
} }
AccessManagerPrivate::~AccessManagerPrivate() AccessManagerPrivate::~AccessManagerPrivate()

View File

@ -162,9 +162,6 @@ void AuthorizationManagerPrivate::prepareForServiceAccess()
void AuthorizationManagerPrivate::prepareForServicePublication() void AuthorizationManagerPrivate::prepareForServicePublication()
{ {
if (!server) { if (!server) {
//Let's set up plasma for remote service support. Since most of the set up involves crypto,
//AuthorizationManager seems the sensible place.
//First, let's start the JOLIE server:
server = new Jolie::Server(4000); server = new Jolie::Server(4000);
} }
} }

View File

@ -17,11 +17,16 @@
#include "credentials.h" #include "credentials.h"
#include "authorizationmanager.h"
#include "config.h"
#include <QObject> #include <QObject>
#ifdef ENABLE_REMOTE_WIDGETS
#include <QtCrypto> #include <QtCrypto>
#endif
#include <kdebug.h> #include <kdebug.h>
#include "authorizationmanager.h"
#include <kstandarddirs.h> #include <kstandarddirs.h>
namespace Plasma { namespace Plasma {
@ -37,12 +42,14 @@ public:
: id(id), : id(id),
name(name) name(name)
{ {
#ifdef ENABLE_REMOTE_WIDGETS
if (isPrivateKey) { if (isPrivateKey) {
privateKey = QCA::PrivateKey::fromPEM(pemKey); privateKey = QCA::PrivateKey::fromPEM(pemKey);
publicKey = privateKey.toPublicKey(); publicKey = privateKey.toPublicKey();
} else { } else {
publicKey = QCA::PublicKey::fromPEM(pemKey); publicKey = QCA::PublicKey::fromPEM(pemKey);
} }
#endif
} }
~CredentialsPrivate() ~CredentialsPrivate()
@ -51,8 +58,11 @@ public:
QString id; QString id;
QString name; QString name;
#ifdef ENABLE_REMOTE_WIDGETS
QCA::PublicKey publicKey; QCA::PublicKey publicKey;
QCA::PrivateKey privateKey; QCA::PrivateKey privateKey;
#endif
}; };
Credentials::Credentials(const QString &id, const QString &name, Credentials::Credentials(const QString &id, const QString &name,
@ -85,12 +95,16 @@ Credentials &Credentials::operator=(const Credentials &other)
Credentials Credentials::createCredentials(const QString &name) Credentials Credentials::createCredentials(const QString &name)
{ {
#ifdef ENABLE_REMOTE_WIDGETS
QCA::KeyGenerator generator; QCA::KeyGenerator generator;
QCA::PrivateKey key = generator.createRSA(2048); QCA::PrivateKey key = generator.createRSA(2048);
QString pemKey(key.toPublicKey().toPEM()); QString pemKey(key.toPublicKey().toPEM());
//TODO: is using a md5 hash for the id a good idea?
QString id = QCA::Hash("sha1").hashToString(pemKey.toAscii()); QString id = QCA::Hash("sha1").hashToString(pemKey.toAscii());
return Credentials(id, name, key.toPEM(), true); return Credentials(id, name, key.toPEM(), true);
#else
kDebug() << "libplasma is compiled without support for remote widgets. Creating an empty identity.";
return Credentials();
#endif
} }
TrustLevel Credentials::trustLevel() const TrustLevel Credentials::trustLevel() const
@ -111,12 +125,17 @@ TrustLevel Credentials::trustLevel() const
bool Credentials::isValid() const bool Credentials::isValid() const
{ {
#ifdef ENABLE_REMOTE_WIDGETS
if (d->publicKey.isNull()) { if (d->publicKey.isNull()) {
return false; return false;
} else { } else {
QString id = QCA::Hash("sha1").hashToString(d->publicKey.toPEM().toAscii()); QString id = QCA::Hash("sha1").hashToString(d->publicKey.toPEM().toAscii());
return (id == d->id); return (id == d->id);
} }
#else
kDebug() << "libplasma is compiled without support for remote widgets. Key invalid.";
return false;
#endif
} }
QString Credentials::name() const QString Credentials::name() const
@ -131,6 +150,7 @@ QString Credentials::id() const
bool Credentials::isValidSignature(const QByteArray &signature, const QByteArray &payload) bool Credentials::isValidSignature(const QByteArray &signature, const QByteArray &payload)
{ {
#ifdef ENABLE_REMOTE_WIDGETS
if (d->publicKey.canVerify()) { if (d->publicKey.canVerify()) {
if (!isValid()) { if (!isValid()) {
kDebug() << "Key is null?"; kDebug() << "Key is null?";
@ -143,15 +163,23 @@ bool Credentials::isValidSignature(const QByteArray &signature, const QByteArray
kDebug() << "Can't verify?"; kDebug() << "Can't verify?";
return false; return false;
} }
#else
return false;
#endif
} }
bool Credentials::canSign() const bool Credentials::canSign() const
{ {
#ifdef ENABLE_REMOTE_WIDGETS
return d->privateKey.canSign(); return d->privateKey.canSign();
#else
return false;
#endif
} }
QByteArray Credentials::signMessage(const QByteArray &message) QByteArray Credentials::signMessage(const QByteArray &message)
{ {
#ifdef ENABLE_REMOTE_WIDGETS
if(!QCA::isSupported("pkey") || if(!QCA::isSupported("pkey") ||
!QCA::PKey::supportedIOTypes().contains(QCA::PKey::RSA)) { !QCA::PKey::supportedIOTypes().contains(QCA::PKey::RSA)) {
kDebug() << "RSA not supported"; kDebug() << "RSA not supported";
@ -163,21 +191,27 @@ QByteArray Credentials::signMessage(const QByteArray &message)
QByteArray signature = d->privateKey.signature(); QByteArray signature = d->privateKey.signature();
return signature; return signature;
} else { } else {
kDebug() << "can't sign?";
return QByteArray(); return QByteArray();
} }
#else
return QByteArray();
#endif
} }
Credentials Credentials::toPublicCredentials() const Credentials Credentials::toPublicCredentials() const
{ {
kDebug(); #ifdef ENABLE_REMOTE_WIDGETS
Credentials result(*this); Credentials result(*this);
result.d->privateKey = QCA::PrivateKey(); result.d->privateKey = QCA::PrivateKey();
return result; return result;
#else
return Credentials();
#endif
} }
QDataStream &operator<<(QDataStream &out, const Credentials &myObj) QDataStream &operator<<(QDataStream &out, const Credentials &myObj)
{ {
#ifdef ENABLE_REMOTE_WIDGETS
QString privateKeyPem; QString privateKeyPem;
QString publicKeyPem; QString publicKeyPem;
@ -189,12 +223,14 @@ QDataStream &operator<<(QDataStream &out, const Credentials &myObj)
} }
out << 1 << myObj.d->id << myObj.d->name << privateKeyPem << publicKeyPem; out << 1 << myObj.d->id << myObj.d->name << privateKeyPem << publicKeyPem;
#endif
return out; return out;
} }
QDataStream &operator>>(QDataStream &in, Credentials &myObj) QDataStream &operator>>(QDataStream &in, Credentials &myObj)
{ {
#ifdef ENABLE_REMOTE_WIDGETS
QString privateKeyString; QString privateKeyString;
QString publicKeyString; QString publicKeyString;
uint version; uint version;
@ -213,6 +249,7 @@ QDataStream &operator>>(QDataStream &in, Credentials &myObj)
if (conversionResult != QCA::ConvertGood) { if (conversionResult != QCA::ConvertGood) {
kDebug() << "Unsuccessfull conversion of key?"; kDebug() << "Unsuccessfull conversion of key?";
} }
#endif
return in; return in;
} }

View File

@ -23,6 +23,8 @@
#include "private/service_p.h" #include "private/service_p.h"
#include "private/serviceprovider_p.h" #include "private/serviceprovider_p.h"
#include "config.h"
#include <QFile> #include <QFile>
#include <QTimer> #include <QTimer>
@ -120,6 +122,7 @@ void ServicePrivate::jobFinished(KJob *job)
void ServicePrivate::publish(AnnouncementMethods methods, const QString &name, PackageMetadata metadata) void ServicePrivate::publish(AnnouncementMethods methods, const QString &name, PackageMetadata metadata)
{ {
#ifdef ENABLE_REMOTE_WIDGETS
if (!serviceProvider) { if (!serviceProvider) {
AuthorizationManager::self()->d->prepareForServicePublication(); AuthorizationManager::self()->d->prepareForServicePublication();
@ -145,6 +148,9 @@ void ServicePrivate::jobFinished(KJob *job)
} else { } else {
kDebug() << "already published!"; kDebug() << "already published!";
} }
#else
kWarning() << "libplasma is compiled without support for remote widgets. not publishing.";
#endif
} }
void ServicePrivate::unpublish() void ServicePrivate::unpublish()