From 4f3a52cec240fd69d5a91aae3fd6bc0262fb46dc Mon Sep 17 00:00:00 2001 From: Aaron Seigo Date: Wed, 7 Nov 2012 02:14:18 +0100 Subject: [PATCH] support setting a custom name from applets (e.g. a timezone for a clock ;) --- applet.cpp | 9 +++++++++ applet.h | 10 ++++++++-- private/applet_p.h | 1 + 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/applet.cpp b/applet.cpp index 323ec0d88..58118c8af 100644 --- a/applet.cpp +++ b/applet.cpp @@ -487,6 +487,10 @@ bool Applet::isBusy() const QString Applet::name() const { + if (!d->customName.isEmpty()) { + return d->customName; + } + if (d->isContainment) { const Containment *c = qobject_cast(this); if (c && c->d->isPanelContainment()) { @@ -503,6 +507,11 @@ QString Applet::name() const return d->appletDescription.name(); } +void Applet::setName(const QString &name) const +{ + d->customName = name; +} + QFont Applet::font() const { return QApplication::font(); diff --git a/applet.h b/applet.h index 1c1661e97..bc4e04416 100644 --- a/applet.h +++ b/applet.h @@ -74,7 +74,7 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget { Q_OBJECT Q_PROPERTY(bool hasConfigurationInterface READ hasConfigurationInterface) - Q_PROPERTY(QString name READ name) + Q_PROPERTY(QString name READ name WRITE setName) Q_PROPERTY(QString pluginName READ pluginName) Q_PROPERTY(QString category READ category) Q_PROPERTY(ImmutabilityType immutability READ immutability WRITE setImmutability) @@ -354,12 +354,18 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget /** * Returns the user-visible name for the applet, as specified in the - * .desktop file. + * .desktop file. Can be changed with @see setName * * @return the user-visible name for the applet. **/ QString name() const; + /** + * Sets a custom name for this instance of the applet. E.g. a clock might + * use the timezone as its name rather than the .desktop file + */ + void setName(const QString &name) const; + /** * @return the font currently set for this widget **/ diff --git a/private/applet_p.h b/private/applet_p.h index 4266bef68..2faebe2d6 100644 --- a/private/applet_p.h +++ b/private/applet_p.h @@ -148,6 +148,7 @@ public: // applet info we keep around in case its needed KPluginInfo appletDescription; QVariantList args; + QString name; // bookkeeping QSet registeredAsDragHandle;