]> git.sesse.net Git - pkanalytics/commitdiff
Factor out timestamp formatting.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 30 Apr 2023 11:20:37 +0000 (13:20 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 30 Apr 2023 11:20:37 +0000 (13:20 +0200)
stats.cpp

index 7bce2a26dba3b893c42bc2fa4a248a30fabdadaf..1edee1161b2d022de75aa9f690a5aab6f54ede2e 100644 (file)
--- a/stats.cpp
+++ b/stats.cpp
@@ -4,10 +4,25 @@
 #include <QGridLayout>
 #include <QVideoWidget>
 #include <QShortcut>
-#include <iostream>
+#include <string>
+#include <sqlite3.h>
 #include "mainwindow.h"
 #include "ui_mainwindow.h"
 
+std::string format_timestamp(uint64_t pos)
+{
+       int ms = pos % 1000;
+       pos /= 1000;
+       int sec = pos % 60;
+       pos /= 60;
+       int min = pos % 60;
+       int hour = pos / 60;
+
+       char buf[256];
+       snprintf(buf, sizeof(buf), "%d:%02d:%02d.%03d", hour, min, sec, ms);
+       return buf;
+}
+
 MainWindow::MainWindow()
 {
        player = new QMediaPlayer;
@@ -19,16 +34,7 @@ MainWindow::MainWindow()
        ui->setupUi(this);
 
        connect(player, &QMediaPlayer::positionChanged, [ui, this](uint64_t pos) {
-               int ms = pos % 1000;
-               pos /= 1000;
-               int sec = pos % 60;
-               pos /= 60;
-               int min = pos % 60;
-               int hour = pos / 60;
-
-               char buf[256];
-               snprintf(buf, sizeof(buf), "%d:%02d:%02d.%03d", hour, min, sec, ms);
-               ui->timestamp->setText(buf);
+               ui->timestamp->setText(QString::fromUtf8(format_timestamp(pos)));
                if (buffered_seek) {
                        player->setPosition(*buffered_seek);
                        buffered_seek.reset();