Skip to content

Improve usability of "Run custom script" KCM controls

Jakob Petsovits requested to merge work/jpetso/kcm-custom-script-usability into master

This discussion on KDE Discuss pointed out a few flaws in the phrasing and general design of the "Run custom scripts" cluster of controls in the PowerDevil KCM. Ideally I'd like to move the whole thing out into a different page, or perhaps just migrate these scripts to a Notification + attached command script if that's an acceptable loss in discoverability. But any redesign is a whole bunch more work, and there are straightforward improvements that we can make to the current set of controls.

Original commit message(s)

kcmodule: Hide profile load/unload fields if battery profiles are absent

Profile load/unload events only make sense in the context of switching between power state profiles, which can't happen unless battery profiles are supported on the given system.

For a system with only "AC Power", let's not show the corresponding profile load/unload custom script fields in the KCM. This only leaves the idle timeout custom script, which in this case we may as well show unconditionally and take out the "Choose run conditions" button.

In the C++ backend, the code for querying Solid for batteries gets moved to the KCM constructor so that kcm.supportsBatteryProfiles is correct at QML component construction time already.

kcmodule: Include profile name in profile load/unload script labels

Now, instead of 'When entering this power state', the label reads e.g. 'When entering "On AC Power"'. Hopefully easier to understand.

This requires a little refactoring in main.qml to set the new profileLabel property on the respective ProfileConfig item.

kcmodule: Focus custom command field once it appears

Use a FocusScope as root element for the RunScriptEdit component, and set initial focus within it to the commandText field. Forcing focus after the corresponding checkbox is toggled on will then work correctly.

Unfortunately, the containing Flickable does not scroll down to a newly visible command field. That's a different issue though.

Test plan

Click the "Choose run conditions" button, see the new labels, make sure that labels in the menu and in the subsequently appearing form controls match up. Notice the focus.

For testing the "Hide profile load/unload fields" commits as a laptop user, I changed PowerKCM.cpp to comment out the line setSupportsBatteryProfiles(true);, then rebuild. That will display the KCM as a desktop PC user without power supply battery would see it. (At least in regards to tabs and custom scripts.)

Bugs fixed

None in the PowerDevil KCM category for System Settings, at least. Why don't I get on that instead!

Merge request reports