[Backend] Improved createTimestamp readability and also cache duration string.
This commit is contained in:
parent
b27f2e6b27
commit
4f65900e7e
|
@ -433,22 +433,6 @@ DirectMpvPlayerBackend::playerCommand(const Enums::Commands& cmd,
|
|||
return QVariant("NoOutput");
|
||||
}
|
||||
|
||||
QVariant
|
||||
DirectMpvPlayerBackend::createTimestamp(const QVariant& seconds) const
|
||||
{
|
||||
int d = seconds.toInt();
|
||||
double h = floor(d / 3600);
|
||||
double m = floor(d % 3600 / 60);
|
||||
double s = floor(d % 3600 % 60);
|
||||
|
||||
QString hour = h > 0 ? QString::number(h) + ":" : "";
|
||||
QString minute = h < 1 ? QString::number(m) + ":"
|
||||
: (m < 10 ? "0" + QString::number(m) + ":"
|
||||
: QString::number(m) + ":");
|
||||
QString second = s < 10 ? "0" + QString::number(s) : QString::number(s);
|
||||
return hour + minute + second;
|
||||
}
|
||||
|
||||
void
|
||||
DirectMpvPlayerBackend::handleWindowChanged(QQuickWindow* win)
|
||||
{
|
||||
|
@ -496,8 +480,8 @@ DirectMpvPlayerBackend::updateDurationString()
|
|||
{
|
||||
emit durationStringChanged(
|
||||
QString("%1 / %2 (%3x)")
|
||||
.arg(createTimestamp(getProperty("time-pos")).toString(),
|
||||
createTimestamp(getProperty("duration")).toString(),
|
||||
.arg(Utils::createTimestamp(getProperty("time-pos").toInt()),
|
||||
totalDurationString,
|
||||
getProperty("speed").toString()));
|
||||
}
|
||||
|
||||
|
@ -521,6 +505,7 @@ DirectMpvPlayerBackend::handle_mpv_event(mpv_event* event)
|
|||
} else if (strcmp(prop->name, "duration") == 0) {
|
||||
if (prop->format == MPV_FORMAT_DOUBLE) {
|
||||
double time = *(double*)prop->data;
|
||||
totalDurationString = Utils::createTimestamp(time);
|
||||
emit durationChanged(time);
|
||||
}
|
||||
} else if (strcmp(prop->name, "mute") == 0 ||
|
||||
|
|
|
@ -42,6 +42,7 @@ class DirectMpvPlayerBackend
|
|||
mpv_opengl_cb_context* mpv_gl;
|
||||
MpvRenderer* renderer;
|
||||
bool onTop = false;
|
||||
QString totalDurationString;
|
||||
|
||||
public:
|
||||
static void on_update(void* ctx);
|
||||
|
@ -60,9 +61,7 @@ public slots:
|
|||
void setProperty(const QString& name, const QVariant& value);
|
||||
void setOption(const QString& name, const QVariant& value);
|
||||
QVariant getProperty(const QString& name) const;
|
||||
// Misc
|
||||
QVariant createTimestamp(const QVariant& seconds) const;
|
||||
//
|
||||
|
||||
void sync();
|
||||
void swapped();
|
||||
void cleanup();
|
||||
|
|
|
@ -423,22 +423,6 @@ MpvPlayerBackend::playerCommand(const Enums::Commands& cmd,
|
|||
return QVariant("NoOutput");
|
||||
}
|
||||
|
||||
QVariant
|
||||
MpvPlayerBackend::createTimestamp(const QVariant& seconds) const
|
||||
{
|
||||
int d = seconds.toInt();
|
||||
double h = floor(d / 3600);
|
||||
double m = floor(d % 3600 / 60);
|
||||
double s = floor(d % 3600 % 60);
|
||||
|
||||
QString hour = h > 0 ? QString::number(h) + ":" : "";
|
||||
QString minute = h < 1 ? QString::number(m) + ":"
|
||||
: (m < 10 ? "0" + QString::number(m) + ":"
|
||||
: QString::number(m) + ":");
|
||||
QString second = s < 10 ? "0" + QString::number(s) : QString::number(s);
|
||||
return hour + minute + second;
|
||||
}
|
||||
|
||||
void
|
||||
MpvPlayerBackend::toggleOnTop()
|
||||
{
|
||||
|
@ -463,8 +447,8 @@ MpvPlayerBackend::updateDurationString()
|
|||
{
|
||||
emit durationStringChanged(
|
||||
QString("%1 / %2 (%3x)")
|
||||
.arg(createTimestamp(getProperty("time-pos")).toString(),
|
||||
createTimestamp(getProperty("duration")).toString(),
|
||||
.arg(Utils::createTimestamp(getProperty("time-pos").toInt()),
|
||||
totalDurationString,
|
||||
getProperty("speed").toString()));
|
||||
}
|
||||
|
||||
|
@ -488,6 +472,7 @@ MpvPlayerBackend::handle_mpv_event(mpv_event* event)
|
|||
} else if (strcmp(prop->name, "duration") == 0) {
|
||||
if (prop->format == MPV_FORMAT_DOUBLE) {
|
||||
double time = *(double*)prop->data;
|
||||
totalDurationString = Utils::createTimestamp(time);
|
||||
emit durationChanged(time);
|
||||
}
|
||||
} else if (strcmp(prop->name, "mute") == 0 ||
|
||||
|
|
|
@ -25,6 +25,7 @@ class MpvPlayerBackend
|
|||
mpv_handle* mpv;
|
||||
mpv_render_context* mpv_gl;
|
||||
bool onTop = false;
|
||||
QString totalDurationString;
|
||||
|
||||
friend class MpvRenderer;
|
||||
|
||||
|
@ -46,8 +47,6 @@ public slots:
|
|||
void setProperty(const QString& name, const QVariant& value);
|
||||
void setOption(const QString& name, const QVariant& value);
|
||||
QVariant getProperty(const QString& name) const;
|
||||
// Misc
|
||||
QVariant createTimestamp(const QVariant& seconds) const;
|
||||
|
||||
signals:
|
||||
void onUpdate();
|
||||
|
|
|
@ -189,19 +189,15 @@ ApplicationWindow {
|
|||
player.playerCommand(Enums.Commands.SeekAbsolute, skipto)
|
||||
}
|
||||
|
||||
function isAnyMenuOpen() {
|
||||
return menuBar.anythingOpen()
|
||||
}
|
||||
|
||||
function hideControls(force) {
|
||||
if (!isAnyMenuOpen() || force) {
|
||||
if (!menuBar.anythingOpen() || force) {
|
||||
controlsShowing = false
|
||||
mouseAreaPlayer.cursorShape = Qt.BlankCursor
|
||||
}
|
||||
}
|
||||
|
||||
function showControls() {
|
||||
if (!controlsBar.controls.visible) {
|
||||
if (!controlsShowing) {
|
||||
controlsShowing = true
|
||||
mouseAreaPlayer.cursorShape = Qt.ArrowCursor
|
||||
}
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
#include <QGuiApplication>
|
||||
#include <QProcessEnvironment>
|
||||
#include <QQmlApplicationEngine>
|
||||
#include <QString>
|
||||
#include <QVariant>
|
||||
#include <QtCore>
|
||||
|
||||
#ifdef __linux__
|
||||
|
@ -39,6 +41,20 @@ updateAppImage()
|
|||
qApp->exit();
|
||||
}
|
||||
|
||||
QString
|
||||
createTimestamp(int seconds)
|
||||
{
|
||||
int h = floor(seconds / 3600);
|
||||
int m = floor(seconds % 3600 / 60);
|
||||
int s = floor(seconds % 3600 % 60);
|
||||
|
||||
if (h > 0) {
|
||||
return QString::asprintf("%02d:%02d:%02d", h, m, s);
|
||||
} else {
|
||||
return QString::asprintf("%02d:%02d", m, s);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __linux__
|
||||
void
|
||||
SetDPMS(bool on)
|
||||
|
|
|
@ -10,5 +10,7 @@ void
|
|||
AlwaysOnTop(WId wid, bool on);
|
||||
void
|
||||
updateAppImage();
|
||||
QString
|
||||
createTimestamp(int seconds);
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue