Icon Applet: Disable plasmoid if it is defunct

Otherwise clicking it would show an "invalid URL" error and
trying to open the properties dialog would trigger an assert.

This can normally not happen but you can get here with e.g. plasmoidviewer

BUG: 455433
wilder-5.26
Kai Uwe Broulik 4 years ago
parent e8daedab8f
commit 2b8dc98749
  1. 11
      applets/icon/iconapplet.cpp
  2. 3
      applets/icon/iconapplet.h
  3. 11
      applets/icon/package/contents/ui/main.qml

@ -265,7 +265,7 @@ void IconApplet::populateFromDesktopFile(const QString &path)
m_openWithActions.clear(); m_openWithActions.clear();
m_jumpListActions.clear(); m_jumpListActions.clear();
m_localPath = path; setLocalPath(path);
setBusy(false); setBusy(false);
} }
@ -311,6 +311,11 @@ QString IconApplet::genericName() const
return m_genericName; return m_genericName;
} }
bool IconApplet::isValid() const
{
return !m_localPath.isEmpty();
}
QList<QAction *> IconApplet::contextualActions() QList<QAction *> IconApplet::contextualActions()
{ {
QList<QAction *> actions; QList<QAction *> actions;
@ -569,8 +574,12 @@ QString IconApplet::localPath() const
void IconApplet::setLocalPath(const QString &localPath) void IconApplet::setLocalPath(const QString &localPath)
{ {
const bool oldValid = isValid();
m_localPath = localPath; m_localPath = localPath;
config().writeEntry(QStringLiteral("localPath"), localPath); config().writeEntry(QStringLiteral("localPath"), localPath);
if (oldValid != isValid()) {
Q_EMIT isValidChanged();
}
} }
K_PLUGIN_CLASS(IconApplet) K_PLUGIN_CLASS(IconApplet)

@ -30,6 +30,7 @@ class IconApplet : public Plasma::Applet
Q_PROPERTY(QString name READ name NOTIFY nameChanged) Q_PROPERTY(QString name READ name NOTIFY nameChanged)
Q_PROPERTY(QString iconName READ iconName NOTIFY iconNameChanged) Q_PROPERTY(QString iconName READ iconName NOTIFY iconNameChanged)
Q_PROPERTY(QString genericName READ genericName NOTIFY genericNameChanged) Q_PROPERTY(QString genericName READ genericName NOTIFY genericNameChanged)
Q_PROPERTY(bool valid READ isValid NOTIFY isValidChanged)
public: public:
explicit IconApplet(QObject *parent, const KPluginMetaData &data, const QVariantList &args); explicit IconApplet(QObject *parent, const KPluginMetaData &data, const QVariantList &args);
@ -44,6 +45,7 @@ public:
QString name() const; QString name() const;
QString iconName() const; QString iconName() const;
QString genericName() const; QString genericName() const;
bool isValid() const;
QList<QAction *> contextualActions() override; QList<QAction *> contextualActions() override;
@ -59,6 +61,7 @@ Q_SIGNALS:
void nameChanged(const QString &name); void nameChanged(const QString &name);
void iconNameChanged(const QString &iconName); void iconNameChanged(const QString &iconName);
void genericNameChanged(const QString &genericName); void genericNameChanged(const QString &genericName);
void isValidChanged();
void jumpListActionsChanged(const QVariantList &jumpListActions); void jumpListActionsChanged(const QVariantList &jumpListActions);
private: private:

@ -50,6 +50,7 @@ MouseArea {
Layout.maximumHeight: inPanel ? PlasmaCore.Units.iconSizeHints.panel : -1 Layout.maximumHeight: inPanel ? PlasmaCore.Units.iconSizeHints.panel : -1
hoverEnabled: true hoverEnabled: true
enabled: Plasmoid.nativeInterface.valid
onClicked: Plasmoid.nativeInterface.run() onClicked: Plasmoid.nativeInterface.run()
@ -66,10 +67,9 @@ MouseArea {
function updateActions() { function updateActions() {
Plasmoid.clearActions() Plasmoid.clearActions()
Plasmoid.removeAction("configure"); Plasmoid.removeAction("configure");
if (Plasmoid.immutability !== PlasmaCore.Types.SystemImmutable) { if (Plasmoid.nativeInterface.valid && Plasmoid.immutability !== PlasmaCore.Types.SystemImmutable) {
Plasmoid.setAction("configure", i18n("Properties"), "document-properties"); Plasmoid.setAction("configure", i18n("Properties"), "document-properties");
} }
} }
@ -85,6 +85,13 @@ MouseArea {
} }
} }
Connections {
target: Plasmoid.nativeInterface
function onValidChanged() {
updateActions();
}
}
DragDrop.DropArea { DragDrop.DropArea {
id: dropArea id: dropArea
anchors.fill: parent anchors.fill: parent

Loading…
Cancel
Save