1
0
Fork 0

[Backend] Improved createTimestamp readability and also cache duration string.

This commit is contained in:
NamedKitten 2018-11-19 05:07:22 +00:00
parent b27f2e6b27
commit 4f65900e7e
7 changed files with 29 additions and 47 deletions

View file

@ -433,22 +433,6 @@ DirectMpvPlayerBackend::playerCommand(const Enums::Commands& cmd,
return QVariant("NoOutput"); 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 void
DirectMpvPlayerBackend::handleWindowChanged(QQuickWindow* win) DirectMpvPlayerBackend::handleWindowChanged(QQuickWindow* win)
{ {
@ -496,8 +480,8 @@ DirectMpvPlayerBackend::updateDurationString()
{ {
emit durationStringChanged( emit durationStringChanged(
QString("%1 / %2 (%3x)") QString("%1 / %2 (%3x)")
.arg(createTimestamp(getProperty("time-pos")).toString(), .arg(Utils::createTimestamp(getProperty("time-pos").toInt()),
createTimestamp(getProperty("duration")).toString(), totalDurationString,
getProperty("speed").toString())); getProperty("speed").toString()));
} }
@ -521,6 +505,7 @@ DirectMpvPlayerBackend::handle_mpv_event(mpv_event* event)
} 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;
totalDurationString = Utils::createTimestamp(time);
emit durationChanged(time); emit durationChanged(time);
} }
} else if (strcmp(prop->name, "mute") == 0 || } else if (strcmp(prop->name, "mute") == 0 ||

View file

@ -42,6 +42,7 @@ class DirectMpvPlayerBackend
mpv_opengl_cb_context* mpv_gl; mpv_opengl_cb_context* mpv_gl;
MpvRenderer* renderer; MpvRenderer* renderer;
bool onTop = false; bool onTop = false;
QString totalDurationString;
public: public:
static void on_update(void* ctx); static void on_update(void* ctx);
@ -60,9 +61,7 @@ public slots:
void setProperty(const QString& name, const QVariant& value); void setProperty(const QString& name, const QVariant& value);
void setOption(const QString& name, const QVariant& value); void setOption(const QString& name, const QVariant& value);
QVariant getProperty(const QString& name) const; QVariant getProperty(const QString& name) const;
// Misc
QVariant createTimestamp(const QVariant& seconds) const;
//
void sync(); void sync();
void swapped(); void swapped();
void cleanup(); void cleanup();

View file

@ -423,22 +423,6 @@ MpvPlayerBackend::playerCommand(const Enums::Commands& cmd,
return QVariant("NoOutput"); 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 void
MpvPlayerBackend::toggleOnTop() MpvPlayerBackend::toggleOnTop()
{ {
@ -463,8 +447,8 @@ MpvPlayerBackend::updateDurationString()
{ {
emit durationStringChanged( emit durationStringChanged(
QString("%1 / %2 (%3x)") QString("%1 / %2 (%3x)")
.arg(createTimestamp(getProperty("time-pos")).toString(), .arg(Utils::createTimestamp(getProperty("time-pos").toInt()),
createTimestamp(getProperty("duration")).toString(), totalDurationString,
getProperty("speed").toString())); getProperty("speed").toString()));
} }
@ -488,6 +472,7 @@ MpvPlayerBackend::handle_mpv_event(mpv_event* event)
} 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;
totalDurationString = Utils::createTimestamp(time);
emit durationChanged(time); emit durationChanged(time);
} }
} else if (strcmp(prop->name, "mute") == 0 || } else if (strcmp(prop->name, "mute") == 0 ||

View file

@ -25,6 +25,7 @@ class MpvPlayerBackend
mpv_handle* mpv; mpv_handle* mpv;
mpv_render_context* mpv_gl; mpv_render_context* mpv_gl;
bool onTop = false; bool onTop = false;
QString totalDurationString;
friend class MpvRenderer; friend class MpvRenderer;
@ -46,8 +47,6 @@ public slots:
void setProperty(const QString& name, const QVariant& value); void setProperty(const QString& name, const QVariant& value);
void setOption(const QString& name, const QVariant& value); void setOption(const QString& name, const QVariant& value);
QVariant getProperty(const QString& name) const; QVariant getProperty(const QString& name) const;
// Misc
QVariant createTimestamp(const QVariant& seconds) const;
signals: signals:
void onUpdate(); void onUpdate();

View file

@ -189,19 +189,15 @@ ApplicationWindow {
player.playerCommand(Enums.Commands.SeekAbsolute, skipto) player.playerCommand(Enums.Commands.SeekAbsolute, skipto)
} }
function isAnyMenuOpen() {
return menuBar.anythingOpen()
}
function hideControls(force) { function hideControls(force) {
if (!isAnyMenuOpen() || force) { if (!menuBar.anythingOpen() || force) {
controlsShowing = false controlsShowing = false
mouseAreaPlayer.cursorShape = Qt.BlankCursor mouseAreaPlayer.cursorShape = Qt.BlankCursor
} }
} }
function showControls() { function showControls() {
if (!controlsBar.controls.visible) { if (!controlsShowing) {
controlsShowing = true controlsShowing = true
mouseAreaPlayer.cursorShape = Qt.ArrowCursor mouseAreaPlayer.cursorShape = Qt.ArrowCursor
} }

View file

@ -5,6 +5,8 @@
#include <QGuiApplication> #include <QGuiApplication>
#include <QProcessEnvironment> #include <QProcessEnvironment>
#include <QQmlApplicationEngine> #include <QQmlApplicationEngine>
#include <QString>
#include <QVariant>
#include <QtCore> #include <QtCore>
#ifdef __linux__ #ifdef __linux__
@ -39,6 +41,20 @@ updateAppImage()
qApp->exit(); 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__ #ifdef __linux__
void void
SetDPMS(bool on) SetDPMS(bool on)

View file

@ -10,5 +10,7 @@ void
AlwaysOnTop(WId wid, bool on); AlwaysOnTop(WId wid, bool on);
void void
updateAppImage(); updateAppImage();
QString
createTimestamp(int seconds);
} }
#endif #endif