[Backend] Move more code to backend.
This commit is contained in:
parent
d4e0115c8f
commit
f32ead3e1d
|
@ -329,6 +329,17 @@ MpvPlayerBackend::on_mpv_events()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
MpvPlayerBackend::updateDurationStringText()
|
||||||
|
{
|
||||||
|
findChild<QObject*>("timeLabel")
|
||||||
|
->setProperty("text",
|
||||||
|
QString("%1 / %2 (%3x)")
|
||||||
|
.arg(createTimestamp(getProperty("time-pos")).toString(),
|
||||||
|
createTimestamp(getProperty("duration")).toString(),
|
||||||
|
getProperty("speed").toString()));
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
MpvPlayerBackend::handle_mpv_event(mpv_event* event)
|
MpvPlayerBackend::handle_mpv_event(mpv_event* event)
|
||||||
{
|
{
|
||||||
|
@ -338,15 +349,13 @@ MpvPlayerBackend::handle_mpv_event(mpv_event* event)
|
||||||
if (strcmp(prop->name, "time-pos") == 0) {
|
if (strcmp(prop->name, "time-pos") == 0) {
|
||||||
if (prop->format == MPV_FORMAT_DOUBLE) {
|
if (prop->format == MPV_FORMAT_DOUBLE) {
|
||||||
double time = *(double*)prop->data;
|
double time = *(double*)prop->data;
|
||||||
QMetaObject::invokeMethod(
|
updateDurationStringText();
|
||||||
this, "setProgressBarValue", Q_ARG(QVariant, time));
|
findChild<QObject*>("progressBar")->setProperty("value", time);
|
||||||
}
|
}
|
||||||
} else if (strcmp(prop->name, "duration") == 0) {
|
} else if (strcmp(prop->name, "duration") == 0) {
|
||||||
if (prop->format == MPV_FORMAT_DOUBLE) {
|
if (prop->format == MPV_FORMAT_DOUBLE) {
|
||||||
double time = *(double*)prop->data;
|
double time = *(double*)prop->data;
|
||||||
Q_ARG(QVariant, "txt1"),
|
findChild<QObject*>("progressBar")->setProperty("to", time);
|
||||||
QMetaObject::invokeMethod(
|
|
||||||
this, "setProgressBarEnd", Q_ARG(QVariant, time));
|
|
||||||
}
|
}
|
||||||
} 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) {
|
||||||
|
@ -363,13 +372,12 @@ MpvPlayerBackend::handle_mpv_event(mpv_event* event)
|
||||||
} 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;
|
||||||
QMetaObject::invokeMethod(this, "setTitle", Q_ARG(QVariant, title));
|
findChild<QObject*>("titleLabel")->setProperty("text", title);
|
||||||
}
|
}
|
||||||
} else if (strcmp(prop->name, "sub-text") == 0) {
|
} else if (strcmp(prop->name, "sub-text") == 0) {
|
||||||
if (prop->format == MPV_FORMAT_STRING) {
|
if (prop->format == MPV_FORMAT_STRING) {
|
||||||
char* subs = *(char**)prop->data;
|
char* subs = *(char**)prop->data;
|
||||||
QMetaObject::invokeMethod(
|
findChild<QObject*>("nativeSubs")->setProperty("text", subs);
|
||||||
this, "setSubtitles", Q_ARG(QVariant, subs));
|
|
||||||
}
|
}
|
||||||
} else if (strcmp(prop->name, "demuxer-cache-duration") == 0) {
|
} else if (strcmp(prop->name, "demuxer-cache-duration") == 0) {
|
||||||
if (prop->format == MPV_FORMAT_DOUBLE) {
|
if (prop->format == MPV_FORMAT_DOUBLE) {
|
||||||
|
|
|
@ -37,6 +37,7 @@ public slots:
|
||||||
void prevPlaylistItem();
|
void prevPlaylistItem();
|
||||||
void nextPlaylistItem();
|
void nextPlaylistItem();
|
||||||
void toggleOnTop();
|
void toggleOnTop();
|
||||||
|
void updateDurationStringText();
|
||||||
QVariant getTracks() const;
|
QVariant getTracks() const;
|
||||||
|
|
||||||
QVariant getTrack(const QString& track);
|
QVariant getTrack(const QString& track);
|
||||||
|
|
|
@ -168,18 +168,6 @@ ApplicationWindow {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function setProgressBarEnd(val) {
|
|
||||||
progressBar.to = val
|
|
||||||
}
|
|
||||||
|
|
||||||
function setProgressBarValue(val) {
|
|
||||||
progressBar.value = val
|
|
||||||
timeLabel.text = player.createTimestamp(
|
|
||||||
val) + " / " + player.createTimestamp(
|
|
||||||
progressBar.to) + " (" + parseFloat(
|
|
||||||
player.getProperty("speed").toFixed(2)) + "x)"
|
|
||||||
}
|
|
||||||
|
|
||||||
function skipToNinth(val) {
|
function skipToNinth(val) {
|
||||||
var skipto = 0
|
var skipto = 0
|
||||||
if (val != 0) {
|
if (val != 0) {
|
||||||
|
@ -226,14 +214,6 @@ ApplicationWindow {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function setTitle(title) {
|
|
||||||
titleLabel.text = title
|
|
||||||
}
|
|
||||||
|
|
||||||
function setSubtitles(subs) {
|
|
||||||
nativeSubs.text = subs
|
|
||||||
}
|
|
||||||
|
|
||||||
function isAnyMenuOpen() {
|
function isAnyMenuOpen() {
|
||||||
return settingsMenu.visible || fileMenuBarItem.opened
|
return settingsMenu.visible || fileMenuBarItem.opened
|
||||||
|| playbackMenuBarItem.opened || viewMenuBarItem.opened
|
|| playbackMenuBarItem.opened || viewMenuBarItem.opened
|
||||||
|
@ -864,6 +844,7 @@ ApplicationWindow {
|
||||||
|
|
||||||
Text {
|
Text {
|
||||||
id: titleLabel
|
id: titleLabel
|
||||||
|
objectName: "titleLabel"
|
||||||
text: translate.getTranslation("TITLE", i18n.language)
|
text: translate.getTranslation("TITLE", i18n.language)
|
||||||
color: "white"
|
color: "white"
|
||||||
width: parent.width
|
width: parent.width
|
||||||
|
@ -926,6 +907,7 @@ ApplicationWindow {
|
||||||
|
|
||||||
Label {
|
Label {
|
||||||
id: nativeSubs
|
id: nativeSubs
|
||||||
|
objectName: "nativeSubs"
|
||||||
onWidthChanged: {
|
onWidthChanged: {
|
||||||
|
|
||||||
if (width > parent.width - 10)
|
if (width > parent.width - 10)
|
||||||
|
@ -990,6 +972,7 @@ ApplicationWindow {
|
||||||
|
|
||||||
Slider {
|
Slider {
|
||||||
id: progressBar
|
id: progressBar
|
||||||
|
objectName: "progressBar"
|
||||||
to: 1
|
to: 1
|
||||||
value: 0.0
|
value: 0.0
|
||||||
anchors.bottom: parent.top
|
anchors.bottom: parent.top
|
||||||
|
@ -1206,6 +1189,7 @@ ApplicationWindow {
|
||||||
|
|
||||||
Text {
|
Text {
|
||||||
id: timeLabel
|
id: timeLabel
|
||||||
|
objectName: "timeLabel"
|
||||||
text: "0:00 / 0:00"
|
text: "0:00 / 0:00"
|
||||||
color: "white"
|
color: "white"
|
||||||
anchors.left: volumeBar.right
|
anchors.left: volumeBar.right
|
||||||
|
|
Loading…
Reference in a new issue