From 34b9e01ac468cf1346de04d37cd113b1c9064e5c Mon Sep 17 00:00:00 2001 From: Rob Scheepmaker Date: Wed, 9 Sep 2009 13:40:16 +0000 Subject: [PATCH] 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 --- CMakeLists.txt | 9 ++++--- applet.cpp | 6 +++++ config.h.in | 2 ++ remote/accessappletjob.cpp | 9 +++++++ remote/accessmanager.cpp | 6 +++++ remote/authorizationmanager.cpp | 3 --- remote/credentials.cpp | 45 ++++++++++++++++++++++++++++++--- service.cpp | 6 +++++ 8 files changed, 75 insertions(+), 11 deletions(-) create mode 100644 config.h.in diff --git a/CMakeLists.txt b/CMakeLists.txt index e6b3276ba..7b1bd991f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,10 +15,11 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${KDE4_INCLUDES} ) -find_package(QCA2 REQUIRED) - - -include_directories(${QCA2_INCLUDE_DIR}) +if(QCA2_FOUND) + include_directories(${QCA2_INCLUDE_DIR}) + set(ENABLE_REMOTE_WIDGETS TRUE) +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) # libGL needs dlopen() and friends from the dl library diff --git a/applet.cpp b/applet.cpp index b0cb1e104..a91a5a089 100644 --- a/applet.cpp +++ b/applet.cpp @@ -100,6 +100,8 @@ #include "private/toolbox_p.h" #include "ui_publish.h" +#include "config.h" + namespace Plasma { @@ -1649,7 +1651,9 @@ void Applet::showConfigurationInterface() } d->addGlobalShortcutsPage(dialog); +#ifdef ENABLE_REMOTE_WIDGETS d->addPublishPage(dialog); +#endif dialog->show(); } else if (d->script) { d->script->showConfigurationInterface(); @@ -1708,7 +1712,9 @@ KConfigDialog *AppletPrivate::generateGenericConfigDialog() dialog->setAttribute(Qt::WA_DeleteOnClose, true); q->createConfigurationInterface(dialog); addGlobalShortcutsPage(dialog); +#ifdef ENABLE_REMOTE_WIDGETS addPublishPage(dialog); +#endif //TODO: Apply button does not correctly work for now, so do not show it dialog->showButton(KDialog::Apply, false); QObject::connect(dialog, SIGNAL(applyClicked()), q, SLOT(configDialogFinished())); diff --git a/config.h.in b/config.h.in new file mode 100644 index 000000000..577a8cd5c --- /dev/null +++ b/config.h.in @@ -0,0 +1,2 @@ +#cmakedefine ENABLE_REMOTE_WIDGETS + diff --git a/remote/accessappletjob.cpp b/remote/accessappletjob.cpp index 1ee099195..bfed78fb2 100644 --- a/remote/accessappletjob.cpp +++ b/remote/accessappletjob.cpp @@ -23,6 +23,8 @@ #include "servicejob.h" #include "applet.h" +#include "config.h" + #include #include #include @@ -147,10 +149,17 @@ Applet *AccessAppletJob::applet() const void AccessAppletJob::start() { +#ifdef ENABLE_REMOTE_WIDGETS kDebug() << "fetching a plasmoid from location = " << d->location.prettyUrl(); Service *service = Service::access(d->location); connect(service, SIGNAL(serviceReady(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 diff --git a/remote/accessmanager.cpp b/remote/accessmanager.cpp index 6492eb282..640cf71ea 100644 --- a/remote/accessmanager.cpp +++ b/remote/accessmanager.cpp @@ -25,6 +25,8 @@ #include "serviceaccessjob.h" #include "private/authorizationmanager_p.h" +#include "config.h" + #include #include @@ -96,11 +98,15 @@ AccessManagerPrivate::AccessManagerPrivate(AccessManager *manager) : q(manager), browser(new DNSSD::ServiceBrowser("_plasma._tcp")) { +#ifdef ENABLE_REMOTE_WIDGETS q->connect(browser, SIGNAL(serviceAdded(DNSSD::RemoteService::Ptr)), q, SLOT(slotAddService(DNSSD::RemoteService::Ptr))); q->connect(browser, SIGNAL(serviceRemoved(DNSSD::RemoteService::Ptr)), q, SLOT(slotRemoveService(DNSSD::RemoteService::Ptr))); browser->startBrowse(); +#else + kWarning() << "libplasma is compiled without support for remote widgets. not monitoring remote widgets on the network"; +#endif } AccessManagerPrivate::~AccessManagerPrivate() diff --git a/remote/authorizationmanager.cpp b/remote/authorizationmanager.cpp index fa30c06bd..1c5f61212 100644 --- a/remote/authorizationmanager.cpp +++ b/remote/authorizationmanager.cpp @@ -162,9 +162,6 @@ void AuthorizationManagerPrivate::prepareForServiceAccess() void AuthorizationManagerPrivate::prepareForServicePublication() { 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); } } diff --git a/remote/credentials.cpp b/remote/credentials.cpp index fc167c40c..b2ad6550d 100644 --- a/remote/credentials.cpp +++ b/remote/credentials.cpp @@ -17,11 +17,16 @@ #include "credentials.h" +#include "authorizationmanager.h" +#include "config.h" + #include + +#ifdef ENABLE_REMOTE_WIDGETS #include +#endif #include -#include "authorizationmanager.h" #include namespace Plasma { @@ -37,12 +42,14 @@ public: : id(id), name(name) { + #ifdef ENABLE_REMOTE_WIDGETS if (isPrivateKey) { privateKey = QCA::PrivateKey::fromPEM(pemKey); publicKey = privateKey.toPublicKey(); } else { publicKey = QCA::PublicKey::fromPEM(pemKey); } + #endif } ~CredentialsPrivate() @@ -51,8 +58,11 @@ public: QString id; QString name; + +#ifdef ENABLE_REMOTE_WIDGETS QCA::PublicKey publicKey; QCA::PrivateKey privateKey; +#endif }; Credentials::Credentials(const QString &id, const QString &name, @@ -85,12 +95,16 @@ Credentials &Credentials::operator=(const Credentials &other) Credentials Credentials::createCredentials(const QString &name) { +#ifdef ENABLE_REMOTE_WIDGETS QCA::KeyGenerator generator; QCA::PrivateKey key = generator.createRSA(2048); 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()); 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 @@ -111,12 +125,17 @@ TrustLevel Credentials::trustLevel() const bool Credentials::isValid() const { +#ifdef ENABLE_REMOTE_WIDGETS if (d->publicKey.isNull()) { return false; } else { QString id = QCA::Hash("sha1").hashToString(d->publicKey.toPEM().toAscii()); return (id == d->id); } +#else + kDebug() << "libplasma is compiled without support for remote widgets. Key invalid."; + return false; +#endif } QString Credentials::name() const @@ -131,6 +150,7 @@ QString Credentials::id() const bool Credentials::isValidSignature(const QByteArray &signature, const QByteArray &payload) { +#ifdef ENABLE_REMOTE_WIDGETS if (d->publicKey.canVerify()) { if (!isValid()) { kDebug() << "Key is null?"; @@ -143,15 +163,23 @@ bool Credentials::isValidSignature(const QByteArray &signature, const QByteArray kDebug() << "Can't verify?"; return false; } +#else + return false; +#endif } bool Credentials::canSign() const { +#ifdef ENABLE_REMOTE_WIDGETS return d->privateKey.canSign(); +#else + return false; +#endif } QByteArray Credentials::signMessage(const QByteArray &message) { +#ifdef ENABLE_REMOTE_WIDGETS if(!QCA::isSupported("pkey") || !QCA::PKey::supportedIOTypes().contains(QCA::PKey::RSA)) { kDebug() << "RSA not supported"; @@ -163,21 +191,27 @@ QByteArray Credentials::signMessage(const QByteArray &message) QByteArray signature = d->privateKey.signature(); return signature; } else { - kDebug() << "can't sign?"; return QByteArray(); } +#else + return QByteArray(); +#endif } Credentials Credentials::toPublicCredentials() const { - kDebug(); +#ifdef ENABLE_REMOTE_WIDGETS Credentials result(*this); result.d->privateKey = QCA::PrivateKey(); return result; +#else + return Credentials(); +#endif } QDataStream &operator<<(QDataStream &out, const Credentials &myObj) { +#ifdef ENABLE_REMOTE_WIDGETS QString privateKeyPem; QString publicKeyPem; @@ -189,12 +223,14 @@ QDataStream &operator<<(QDataStream &out, const Credentials &myObj) } out << 1 << myObj.d->id << myObj.d->name << privateKeyPem << publicKeyPem; +#endif return out; } QDataStream &operator>>(QDataStream &in, Credentials &myObj) { +#ifdef ENABLE_REMOTE_WIDGETS QString privateKeyString; QString publicKeyString; uint version; @@ -213,6 +249,7 @@ QDataStream &operator>>(QDataStream &in, Credentials &myObj) if (conversionResult != QCA::ConvertGood) { kDebug() << "Unsuccessfull conversion of key?"; } +#endif return in; } diff --git a/service.cpp b/service.cpp index eeaab7a20..831d2f6ac 100644 --- a/service.cpp +++ b/service.cpp @@ -23,6 +23,8 @@ #include "private/service_p.h" #include "private/serviceprovider_p.h" +#include "config.h" + #include #include @@ -120,6 +122,7 @@ void ServicePrivate::jobFinished(KJob *job) void ServicePrivate::publish(AnnouncementMethods methods, const QString &name, PackageMetadata metadata) { + #ifdef ENABLE_REMOTE_WIDGETS if (!serviceProvider) { AuthorizationManager::self()->d->prepareForServicePublication(); @@ -145,6 +148,9 @@ void ServicePrivate::jobFinished(KJob *job) } else { kDebug() << "already published!"; } + #else + kWarning() << "libplasma is compiled without support for remote widgets. not publishing."; + #endif } void ServicePrivate::unpublish()