[PlasmaComponents Menu] Don't crash on null action
ClosedPublic

Authored by broulik on Jul 10 2017, 1:19 PM.

Details

Summary

You can assign a QAction as "action", this way you can just pass it e.g. plasmoid.action("configure").
However, when assigning a null action as can happen with kiosk restrictions, it would crash as it assigns m_action the nullptr but never checks for that.
This patch ensures we always have a QAction, creating a new empty one, if neccessary.
Also deletes our own action if an external one is assigned

Test Plan

Created a menu and applied plasma/plasmashell/unlockedDesktop=false and opened it, no longer crashes:

PlasmaComponents.ContextMenu {
    id: contextMenu

    PlasmaComponents.MenuItem {
        action: plasmoid.action("configure")
    }
}

Manual test has a new button to test this.

Diff Detail

Repository
R242 Plasma Framework (Library)
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
broulik created this revision.Jul 10 2017, 1:19 PM
Restricted Application added projects: Plasma, Frameworks. · View Herald TranscriptJul 10 2017, 1:19 PM
Restricted Application added subscribers: Frameworks, plasma-devel. · View Herald Transcript
davidedmundson added inline comments.
src/declarativeimports/plasmacomponents/qmenuitem.cpp
29

Another approach I've seen done before is:

if (action->parent() == this) we delete it, else it's the client's problem.

IMHO cleaner, but up to you.

58

you need a setVisible(true);

otherwise setAction(null); setAction(something) will still be hidden.

anthonyfieroni added inline comments.
src/declarativeimports/plasmacomponents/qmenuitem.cpp
59

Why delete it?

if (!a) {
    setVisible(false);
    return;
}
// m_action stays last one, but disconnected. And we want to have last one "inactive"?
broulik updated this revision to Diff 16452.Jul 10 2017, 1:48 PM
broulik edited the summary of this revision. (Show Details)
  • For simplicitly just always delete the current action if it's ours before proceeding. Then either use the one passed in or create a new one. As a (neat) side-effect, explicitly assigning null to an action will also clear the menu item
davidedmundson requested changes to this revision.Jul 10 2017, 11:37 PM

You've not addressed my setVisible comment.

This revision now requires changes to proceed.Jul 10 2017, 11:37 PM
broulik updated this revision to Diff 16491.Jul 11 2017, 8:47 AM
broulik edited edge metadata.

When assigning an action, match the item's visibility and enabled

davidedmundson accepted this revision.Jul 11 2017, 9:33 AM
This revision is now accepted and ready to land.Jul 11 2017, 9:33 AM
This revision was automatically updated to reflect the committed changes.