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

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

@ -50,6 +50,7 @@ MouseArea {
Layout.maximumHeight: inPanel ? PlasmaCore.Units.iconSizeHints.panel : -1
hoverEnabled: true
enabled: Plasmoid.nativeInterface.valid
onClicked: Plasmoid.nativeInterface.run()
@ -66,10 +67,9 @@ MouseArea {
function updateActions() {
Plasmoid.clearActions()
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");
}
}
@ -85,6 +85,13 @@ MouseArea {
}
}
Connections {
target: Plasmoid.nativeInterface
function onValidChanged() {
updateActions();
}
}
DragDrop.DropArea {
id: dropArea
anchors.fill: parent

Loading…
Cancel
Save