Update internal printer enabled/paused state if it changes externally
ClosedPublic

Authored by marten on Nov 7 2019, 8:46 AM.

Details

Summary

This means the internal enabled/disabled state of the printer, as tracked by isPaused in plasmoid/package/contents/ui/PrinterItem.qml and used to control the state of the play/pause button and the opacity of the printer name. If the printer state is changed by some external action, e.g. CUPS detecting a printer problem or the cupsenable/cupsdisable commands being used, the applet does not notice the change and still retains the previous state.

This change watches for state changes from the PrinterModel and updates the internal state (and therefore the GUI) appropriately. It could be more selective, but I've tried to guard against spurious property changes (so hopefully signals and redrawing) by only changing the isPaused property if necessary.

Test Plan

Run the unmodified print manager, observe that a working printer shows the name in black and the hover button shows the "pause" icon. Use the cupsdisable command to disable the printer, note that the UI does not change.

Run the modified print manager, observe that if a printer is disabled using the cupsdisable command then the printer name turns grey and the hover button shows the "play" icon. Enable the printer using the cupsenable command and observe that the printer name returns to black and the hover button shows "pause" again.

Diff Detail

Repository
R363 Print Manager
Lint
Lint Skipped
Unit
Unit Tests Skipped
marten created this revision.Nov 7 2019, 8:46 AM
Restricted Application added a subscriber: kde-utils-devel. · View Herald TranscriptNov 7 2019, 8:46 AM
marten requested review of this revision.Nov 7 2019, 8:46 AM
broulik added inline comments.Nov 7 2019, 10:42 AM
plasmoid/package/contents/ui/PrinterItem.qml
259

Can you see if assigning a binding here works instead?

isPaused = Qt.binding(function() {
    return printerState === 5;
});

Ideally, this was done entirely declaratively, i.e. assign the property

isPaused: printerState === 5

but I don't know the code enough to tell why it was done imperatively originally

marten updated this revision to Diff 69389.Nov 7 2019, 1:38 PM

Yes, that seems to work (and simplifies the code a bit).

marten marked an inline comment as done.Nov 7 2019, 1:38 PM
marten updated this revision to Diff 69390.Nov 7 2019, 1:48 PM

Actually everything appears to still work if isPaused is handled entirely declaratively.

Ping - anyone able to review?

This revision was not accepted when it landed; it landed in state Needs Review.Feb 8 2020, 2:36 PM
This revision was automatically updated to reflect the committed changes.