1
0
Fork 0

[Backend] Move even more things to backend.

This commit is contained in:
Kitteh 2018-11-08 12:46:43 +00:00
parent f32ead3e1d
commit 02750f65db
3 changed files with 57 additions and 54 deletions

View file

@ -130,7 +130,7 @@ MpvPlayerBackend::MpvPlayerBackend(QQuickItem* parent)
mpv_observe_property(mpv, 0, "track-list", MPV_FORMAT_NODE); mpv_observe_property(mpv, 0, "track-list", MPV_FORMAT_NODE);
mpv_observe_property(mpv, 0, "playlist-pos", MPV_FORMAT_DOUBLE); mpv_observe_property(mpv, 0, "playlist-pos", MPV_FORMAT_DOUBLE);
mpv_observe_property(mpv, 0, "volume", MPV_FORMAT_DOUBLE); mpv_observe_property(mpv, 0, "volume", MPV_FORMAT_DOUBLE);
mpv_observe_property(mpv, 0, "muted", MPV_FORMAT_DOUBLE); mpv_observe_property(mpv, 0, "muted", MPV_FORMAT_NONE);
mpv_observe_property(mpv, 0, "duration", MPV_FORMAT_DOUBLE); mpv_observe_property(mpv, 0, "duration", MPV_FORMAT_DOUBLE);
mpv_observe_property(mpv, 0, "media-title", MPV_FORMAT_STRING); mpv_observe_property(mpv, 0, "media-title", MPV_FORMAT_STRING);
mpv_observe_property(mpv, 0, "sub-text", MPV_FORMAT_STRING); mpv_observe_property(mpv, 0, "sub-text", MPV_FORMAT_STRING);
@ -321,7 +321,6 @@ MpvPlayerBackend::on_mpv_events()
{ {
while (mpv) { while (mpv) {
mpv_event* event = mpv_wait_event(mpv, 0); mpv_event* event = mpv_wait_event(mpv, 0);
if (event->event_id == MPV_EVENT_NONE) { if (event->event_id == MPV_EVENT_NONE) {
break; break;
} }
@ -340,6 +339,45 @@ MpvPlayerBackend::updateDurationStringText()
getProperty("speed").toString())); getProperty("speed").toString()));
} }
void
MpvPlayerBackend::updatePrev(const QVariant& val)
{
if (val.toDouble() != 0) {
findChild<QObject*>("playlistPrevButton")->setProperty("visible", true);
} else {
findChild<QObject*>("playlistPrevButton")->setProperty("visible", false);
}
}
void
MpvPlayerBackend::updateVolume(const QVariant& val)
{
if (getProperty("mute").toBool() || (val.toDouble() == 0)) {
findChild<QObject*>("volumeButton")
->setProperty("iconSource", "qrc:/player/icons/volume-mute.svg");
} else {
if (val.toDouble() < 25) {
findChild<QObject*>("volumeButton")
->setProperty("iconSource", "qrc:/player/icons/volume-down.svg");
} else {
findChild<QObject*>("volumeButton")
->setProperty("iconSource", "qrc:/player/icons/volume-up.svg");
}
}
}
void
MpvPlayerBackend::updatePlayPause(const QVariant& val)
{
if (val.toBool()) {
findChild<QObject*>("playPauseButton")
->setProperty("iconSource", "qrc:/player/icons/play.svg");
} else {
findChild<QObject*>("playPauseButton")
->setProperty("iconSource", "qrc:/player/icons/pause.svg");
}
}
void void
MpvPlayerBackend::handle_mpv_event(mpv_event* event) MpvPlayerBackend::handle_mpv_event(mpv_event* event)
{ {
@ -360,15 +398,10 @@ MpvPlayerBackend::handle_mpv_event(mpv_event* event)
} else if (strcmp(prop->name, "volume") == 0) { } else if (strcmp(prop->name, "volume") == 0) {
if (prop->format == MPV_FORMAT_DOUBLE) { if (prop->format == MPV_FORMAT_DOUBLE) {
double volume = *(double*)prop->data; double volume = *(double*)prop->data;
QMetaObject::invokeMethod( updateVolume(QVariant(volume));
this, "updateVolume", Q_ARG(QVariant, volume));
} }
} else if (strcmp(prop->name, "muted") == 0) { } else if (strcmp(prop->name, "muted") == 0) {
if (prop->format == MPV_FORMAT_DOUBLE) { updateVolume(getProperty("volume"));
double muted = *(double*)prop->data;
QMetaObject::invokeMethod(
this, "updateMuted", Q_ARG(QVariant, muted));
}
} else if (strcmp(prop->name, "media-title") == 0) { } else if (strcmp(prop->name, "media-title") == 0) {
if (prop->format == MPV_FORMAT_STRING) { if (prop->format == MPV_FORMAT_STRING) {
char* title = *(char**)prop->data; char* title = *(char**)prop->data;
@ -388,17 +421,17 @@ MpvPlayerBackend::handle_mpv_event(mpv_event* event)
} else if (strcmp(prop->name, "playlist-pos") == 0) { } else if (strcmp(prop->name, "playlist-pos") == 0) {
if (prop->format == MPV_FORMAT_DOUBLE) { if (prop->format == MPV_FORMAT_DOUBLE) {
double pos = *(double*)prop->data; double pos = *(double*)prop->data;
QMetaObject::invokeMethod(this, "updatePrev", Q_ARG(QVariant, pos)); updatePrev(QVariant(pos));
} }
} else if (strcmp(prop->name, "pause") == 0) { } else if (strcmp(prop->name, "pause") == 0) {
QMetaObject::invokeMethod(this, "updatePlayPause"); updatePlayPause(getProperty("pause"));
} else if (strcmp(prop->name, "tracks-menu") == 0) { } else if (strcmp(prop->name, "tracks-menu") == 0) {
QMetaObject::invokeMethod(this, "tracksUpdate"); QMetaObject::invokeMethod(this, "tracksUpdate");
} }
break; break;
} }
case MPV_EVENT_SHUTDOWN: { case MPV_EVENT_SHUTDOWN: {
exit(0); qApp->exit();
break; break;
} }
default: { default: {

View file

@ -39,6 +39,9 @@ public slots:
void toggleOnTop(); void toggleOnTop();
void updateDurationStringText(); void updateDurationStringText();
QVariant getTracks() const; QVariant getTracks() const;
void updatePrev(const QVariant& val);
void updateVolume(const QVariant& val);
void updatePlayPause(const QVariant& val);
QVariant getTrack(const QString& track); QVariant getTrack(const QString& track);
void setTrack(const QVariant& track, const QVariant& id); void setTrack(const QVariant& track, const QVariant& id);

View file

@ -176,44 +176,6 @@ ApplicationWindow {
player.command(["seek", skipto, "absolute"]) player.command(["seek", skipto, "absolute"])
} }
function updatePrev(val) {
if (val != 0) {
playlistPrevButton.visible = true
playlistPrevButton.width = playPauseButton.width
} else {
playlistPrevButton.visible = false
playlistPrevButton.width = 0
}
}
function updateVolume(volume) {
var muted = player.getProperty("mute")
if (muted || volume === 0) {
volumeButton.icon.source = "qrc:/player/icons/volume-mute.svg"
} else {
if (volume < 25) {
volumeButton.icon.source = "qrc:/player/icons/volume-down.svg"
} else {
volumeButton.icon.source = "qrc:/player/icons/volume-up.svg"
}
}
}
function updateMuted(muted) {
if (muted) {
volumeButton.icon.source = "qrc:/player/icons/volume-mute.svg"
}
}
function updatePlayPause() {
var paused = player.getProperty("pause")
if (paused) {
playPauseButton.icon.source = "qrc:/player/icons/play.svg"
} else {
playPauseButton.icon.source = "qrc:/player/icons/pause.svg"
}
}
function isAnyMenuOpen() { function isAnyMenuOpen() {
return settingsMenu.visible || fileMenuBarItem.opened return settingsMenu.visible || fileMenuBarItem.opened
|| playbackMenuBarItem.opened || viewMenuBarItem.opened || playbackMenuBarItem.opened || viewMenuBarItem.opened
@ -1072,6 +1034,7 @@ ApplicationWindow {
Button { Button {
id: playlistPrevButton id: playlistPrevButton
objectName: "playlistPrevButton"
//icon.name: "prev" //icon.name: "prev"
icon.source: "icons/prev.svg" icon.source: "icons/prev.svg"
icon.color: "white" icon.color: "white"
@ -1079,7 +1042,7 @@ ApplicationWindow {
anchors.top: parent.top anchors.top: parent.top
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
visible: false visible: false
width: 0 width: visible ? playPauseButton.width : 0
onClicked: { onClicked: {
player.prevPlaylistItem() player.prevPlaylistItem()
} }
@ -1091,7 +1054,9 @@ ApplicationWindow {
Button { Button {
id: playPauseButton id: playPauseButton
//icon.name: "pause" //icon.name: "pause"
icon.source: "icons/pause.svg" objectName: "playPauseButton"
property string iconSource: "icons/pause.svg"
icon.source: iconSource
icon.color: "white" icon.color: "white"
display: AbstractButton.IconOnly display: AbstractButton.IconOnly
anchors.top: parent.top anchors.top: parent.top
@ -1124,8 +1089,9 @@ ApplicationWindow {
Button { Button {
id: volumeButton id: volumeButton
//icon.name: "volume-up" objectName: "volumeButton"
icon.source: "icons/volume-up.svg" property string iconSource: "icons/volume-up.svg"
icon.source: iconSource
icon.color: "white" icon.color: "white"
display: AbstractButton.IconOnly display: AbstractButton.IconOnly
anchors.top: parent.top anchors.top: parent.top
@ -1133,6 +1099,7 @@ ApplicationWindow {
anchors.left: playlistNextButton.right anchors.left: playlistNextButton.right
onClicked: { onClicked: {
player.toggleMute() player.toggleMute()
player.updateVolume(player.getProperty("volume"))
} }
background: Rectangle { background: Rectangle {
color: "transparent" color: "transparent"