Add mute button with dynamic icon to MPRIS volume control
ClosedPublic

Authored by blaws on Nov 17 2018, 5:53 PM.

Details

Summary

The icon changes depending on the slider value and clicking it
will switch the volume between 0 and 100

Diff Detail

Repository
R224 KDE Connect
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
blaws created this revision.Nov 17 2018, 5:53 PM
Restricted Application added a project: KDE Connect. · View Herald TranscriptNov 17 2018, 5:53 PM
Restricted Application added a subscriber: kdeconnect. · View Herald Transcript
blaws requested review of this revision.Nov 17 2018, 5:53 PM

When I have my volume at e.g. 70%, mute and unmute again it will be 100%. I would rather expect it to be 70% again

blaws added a comment.Nov 18 2018, 8:24 PM

Yeah, I thought about that but in the end I decides not to as mpris has no real way to mute (unlike plasma-pa, which when you click mute just keeps volume same but mutes output). Should I just save the last set volume somewhere and dim slider instead of changing position

Should I just save the last set volume somewhere and dim slider instead of changing position

Sounds good

blaws updated this revision to Diff 45828.Nov 19 2018, 5:32 PM

When muting keep volume slider to what it was before muting but grey it out.

albertvaka added inline comments.
app/qml/mpris.qml
147

This is gonna be more readable in two lines.

blaws updated this revision to Diff 45832.Nov 19 2018, 7:44 PM

Split volume setting onto two lines

blaws marked an inline comment as done.Nov 20 2018, 6:25 AM
broulik added inline comments.
app/qml/mpris.qml
141

I think you could just set these as bindings rather than programmatically doing it onClicked

blaws added inline comments.Nov 20 2018, 7:31 AM
app/qml/mpris.qml
141

How would I do that?

broulik added inline comments.Nov 20 2018, 8:07 AM
app/qml/mpris.qml
37

You could also add a if (volume == 0) { return "audio-volume-muted" } and save the muted check below :)

141
Button {
    ...
    icon.name: muted ? "audio-volume-muted" : soundState(root.pluginInterface.volume)
    ...
}

as well as

Slider {
    ...
    enabled: !muted
    ...
}

and then just keep

onClicked: {
    muted = !muted
    root.pluginInterface.volume = muted ? 0 : volumeUnmuted
}
blaws added inline comments.Nov 20 2018, 6:03 PM
app/qml/mpris.qml
37

Nope, as 0 doesn't always mean muted

141

The setting icon name as property in button also fails, maybe qml doesnt check as isnt direct variable

blaws updated this revision to Diff 45907.Nov 20 2018, 6:22 PM

Use property bindings for volumeslider enabled

blaws marked an inline comment as done.Nov 20 2018, 7:09 PM

Works good except for one thing: When I change the volume in the player itself the slider isn't updated. This worked before this patch.

apol added a subscriber: apol.Nov 26 2018, 8:42 PM
apol added inline comments.
app/qml/mpris.qml
155

If you want the property to update instead of just setting the value, use Qt.binding().
http://doc.qt.io/qt-5/qtqml-syntax-propertybinding.html

It could also make sense to use visualPosition.

blaws added inline comments.Nov 26 2018, 8:50 PM
app/qml/mpris.qml
155

Tried that, doesn't work

apol added inline comments.Nov 27 2018, 12:20 AM
app/qml/mpris.qml
155

Both?
Check dbusinterfaces.cpp:128 and make sure the signal is being emitted?

blaws updated this revision to Diff 46336.Nov 27 2018, 7:08 PM

Change shown volume when changed from mpris player

nicolasfella added inline comments.Nov 27 2018, 8:12 PM
app/qml/mpris.qml
55

How about naming it toggleMute()?

blaws updated this revision to Diff 46353.Nov 27 2018, 8:35 PM

rename muted function

blaws marked an inline comment as done.Nov 27 2018, 8:36 PM
nicolasfella accepted this revision.Nov 27 2018, 8:41 PM

Cool. Thanks for the work!

This revision is now accepted and ready to land.Nov 27 2018, 8:41 PM
This revision was automatically updated to reflect the committed changes.