From fab4818c92317de0886929b2db33f5337dfa2041 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Mon, 23 Sep 2013 16:44:31 +0200 Subject: [PATCH] allow plasmoids to change icon changing icon will change the icon of the default compact representation --- src/plasma/applet.cpp | 9 +++++---- src/plasma/applet.h | 8 +++++++- src/plasma/private/applet_p.cpp | 1 + src/plasma/private/applet_p.h | 1 + .../qml/plasmoid/appletinterface.cpp | 20 ++++++++++++++----- .../qml/plasmoid/appletinterface.h | 5 +++-- 6 files changed, 32 insertions(+), 12 deletions(-) diff --git a/src/plasma/applet.cpp b/src/plasma/applet.cpp index 49a9635bf..377204eee 100644 --- a/src/plasma/applet.cpp +++ b/src/plasma/applet.cpp @@ -332,11 +332,12 @@ void Applet::setTitle(const QString &title) const QString Applet::icon() const { - if (!d->appletDescription.isValid()) { - return QString(); - } + return d->icon; +} - return d->appletDescription.icon(); +void Applet::setIcon(const QString &icon) +{ + d->icon = icon; } KPluginInfo Applet::pluginInfo() const diff --git a/src/plasma/applet.h b/src/plasma/applet.h index 8cdf99a6f..c91cb6e3b 100644 --- a/src/plasma/applet.h +++ b/src/plasma/applet.h @@ -282,10 +282,16 @@ class PLASMA_EXPORT Applet : public QObject static Applet *loadPlasmoid(const QString &path, uint appletId = 0); /** - * Returns the icon related to this applet + * @returns The icon name related to this applet + * By default is the one in the plasmoid desktop file **/ QString icon() const; + /** + * Sets an icon name for this applet + * @param icon Freedesktop compatible icon name + */ + void setIcon(const QString &icon); //ACTIONS diff --git a/src/plasma/private/applet_p.cpp b/src/plasma/private/applet_p.cpp index ff0fe718f..8c448727f 100644 --- a/src/plasma/private/applet_p.cpp +++ b/src/plasma/private/applet_p.cpp @@ -52,6 +52,7 @@ AppletPrivate::AppletPrivate(KService::Ptr service, const KPluginInfo *info, int q(applet), immutability(Types::Mutable), appletDescription(info ? *info : KPluginInfo(service)), + icon(appletDescription.isValid() ? appletDescription.icon() : QString()), mainConfig(0), pendingConstraints(Types::NoConstraint), script(0), diff --git a/src/plasma/private/applet_p.h b/src/plasma/private/applet_p.h index 859acc8cd..65ec9aa06 100644 --- a/src/plasma/private/applet_p.h +++ b/src/plasma/private/applet_p.h @@ -87,6 +87,7 @@ public: // applet info we keep around in case its needed KPluginInfo appletDescription; QString customTitle; + QString icon; // bookkeeping KConfigGroup *mainConfig; diff --git a/src/scriptengines/qml/plasmoid/appletinterface.cpp b/src/scriptengines/qml/plasmoid/appletinterface.cpp index 92b97fd84..60f4d19a1 100644 --- a/src/scriptengines/qml/plasmoid/appletinterface.cpp +++ b/src/scriptengines/qml/plasmoid/appletinterface.cpp @@ -221,21 +221,31 @@ QObject* AppletInterface::configuration() const return m_configuration; } +uint AppletInterface::id() const +{ + return applet()->id(); +} + QString AppletInterface::icon() const { return applet()->icon(); } +void AppletInterface::setIcon(const QString &icon) +{ + if (applet()->icon() == icon) { + return; + } + + applet()->setIcon(icon); + emit iconChanged(); +} + QString AppletInterface::title() const { return applet()->title(); } -uint AppletInterface::id() const -{ - return applet()->id(); -} - void AppletInterface::setTitle(const QString &title) { if (applet()->title() == title) { diff --git a/src/scriptengines/qml/plasmoid/appletinterface.h b/src/scriptengines/qml/plasmoid/appletinterface.h index a394ac6ad..06ad7d9ba 100644 --- a/src/scriptengines/qml/plasmoid/appletinterface.h +++ b/src/scriptengines/qml/plasmoid/appletinterface.h @@ -64,11 +64,10 @@ class AppletInterface : public QQuickItem */ Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged) - //TODO: writable icon /** * Icon to represent the plasmoid */ - Q_PROPERTY(QString icon READ icon CONSTANT) + Q_PROPERTY(QString icon READ icon WRITE setIcon NOTIFY iconChanged) /** * Applet id: is unique in the whole Plasma session and will never change across restarts @@ -235,6 +234,7 @@ public: //PROPERTY ACCESSORS------------------------------------------------------------------- QString icon() const; + void setIcon(const QString &icon); QString title() const; void setTitle(const QString &title); @@ -294,6 +294,7 @@ Q_SIGNALS: void configNeedsSaving(); //PROPERTY change notifiers-------------- + void iconChanged(); void titleChanged(); void formFactorChanged(); void locationChanged();