From c7b13e477befe0a29cf63bd2f1537449bf0bcb1a Mon Sep 17 00:00:00 2001 From: "Aaron J. Seigo" Date: Tue, 17 Jul 2007 22:26:18 +0000 Subject: [PATCH] don't crash when we are asked to create something bogus svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=689221 --- applet.cpp | 32 ++++++++++++++++++++++++++------ applet.h | 4 ++-- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/applet.cpp b/applet.cpp index a0e3a0bc3..741e089a1 100644 --- a/applet.cpp +++ b/applet.cpp @@ -50,7 +50,7 @@ class Applet::Private : appletId( uniqueID ), globalConfig( 0 ), appletConfig( 0 ), - appletDescription(new KPluginInfo(appletDescription)), + appletDescription(appletDescription ? new KPluginInfo(appletDescription) : 0), background(0), failureText(0), immutable(false), @@ -128,13 +128,17 @@ Applet::~Applet() void Applet::init() { + if (!d->appletDescription) { + setFailedToLaunch(true); + } + setImmutable(globalConfig().isImmutable() || config().isImmutable()); } KConfigGroup Applet::config() const { - if ( !d->appletConfig ) { + if (!d->appletConfig) { QString file = KStandardDirs::locateLocal( "appdata", "applets/" + instanceName() + "rc", true ); @@ -183,11 +187,19 @@ void Applet::constraintsUpdated() QString Applet::name() const { + if (!d->appletDescription) { + return i18n("Unknown Applet"); + } + return d->appletDescription->name(); } QString Applet::category() const { + if (!d->appletDescription) { + return i18n("Misc"); + } + return d->appletDescription->property("X-KDE-PluginInfo-Category").toString(); } @@ -341,11 +353,19 @@ Location Applet::location() const QString Applet::globalName() const { + if (!d->appletDescription) { + return QString(); + } + return d->appletDescription->service()->library(); } QString Applet::instanceName() const { + if (!d->appletDescription) { + return QString(); + } + return d->appletDescription->service()->library() + QString::number( d->appletId ); } @@ -421,14 +441,14 @@ KPluginInfo::List Applet::knownApplets(const QString &category, constraint.append(" and "); } - if (category == "NONE") { - constraint.append("(not exist [X-KDE-PluginInfo-Category] or [X-KDE-PluginInfo-Category] == '')"); - } else { - constraint.append("'").append(category).append("' in [X-KDE-PluginInfo-Category]"); + constraint.append("[X-KDE-PluginInfo-Category] == '").append(category).append("'"); + if (category == "Misc") { + constraint.append(" or (not exist [X-KDE-PluginInfo-Category] or [X-KDE-PluginInfo-Category] == '')"); } } KService::List offers = KServiceTypeTrader::self()->query("Plasma/Applet", constraint); + //kDebug() << "Applet::knownApplets constraint was '" << constraint << "' which got us " << offers.count() << " matches" << endl; return KPluginInfo::fromServices(offers); } diff --git a/applet.h b/applet.h index 33f1cd66a..b5cd4de98 100644 --- a/applet.h +++ b/applet.h @@ -159,8 +159,8 @@ class PLASMA_EXPORT Applet : public QObject, public Widget * * @param category Only applets matchin this category will be returned. * Useful in conjunction with knownCategories. - * If NONE is passed in, then applets without a - * Categories= entry are returned. + * If "Misc" is passed in, then applets without a + * Categories= entry are also returned. * If an empty string is passed in, all applets are * returned. * @param parentApp the application to filter applets on. Uses the