]> git.sur5r.net Git - minitube/commitdiff
Fixed time formatting bug with videos longer than 1 hour
authorFlavio Tordini <flavio.tordini@gmail.com>
Sat, 19 Dec 2009 15:19:06 +0000 (16:19 +0100)
committerFlavio Tordini <flavio.tordini@gmail.com>
Sat, 19 Dec 2009 15:19:06 +0000 (16:19 +0100)
src/MainWindow.cpp
src/MainWindow.h

index beedc2bd11eee05631b851d48d2b4b684b942764..9d05596609d939fe68bf7e9981734c2cfc29d3fc 100755 (executable)
@@ -657,15 +657,13 @@ void MainWindow::tick(qint64 time) {
         currentTime->clear();
         return;
     }
-    QTime displayTime(0, (time / 60000) % 60, (time / 1000) % 60);
-    currentTime->setText(displayTime.toString("mm:ss"));
-    
-    // remaining time tooltip
-    int remainingTimeInt = mediaObject->remainingTime();
-    QTime remainingTime(0, (remainingTimeInt / 60000) % 60, (remainingTimeInt / 1000) % 60);
-    currentTime->setStatusTip(tr("Remaining time: %1").arg(remainingTime.toString("mm:ss")));
-    
-    // qDebug() << "currentTime" << time << displayTime.toString("mm:ss");
+
+    currentTime->setText(formatTime(time));
+
+    // remaining time
+    const qint64 remainingTime = mediaObject->remainingTime();
+    currentTime->setStatusTip(tr("Remaining time: %1").arg(formatTime(remainingTime)));
+
 }
 
 void MainWindow::totalTimeChanged(qint64 time) {
@@ -673,9 +671,19 @@ void MainWindow::totalTimeChanged(qint64 time) {
         totalTime->clear();
         return;
     }
-    QTime displayTime(0, (time / 60000) % 60, (time / 1000) % 60);
-    totalTime->setText(displayTime.toString("/ mm:ss"));
-    // qDebug() << "totalTime" << time << displayTime.toString("mm:ss");
+    totalTime->setText("/ " + formatTime(time));
+}
+
+QString MainWindow::formatTime(qint64 time) {
+    QTime displayTime;
+    displayTime = displayTime.addMSecs(time);
+    QString timeString;
+    // 60 * 60 * 1000 = 3600000
+    if (time > 3600000)
+        timeString = displayTime.toString("h:mm:ss");
+    else
+        timeString = displayTime.toString("m:ss");
+    return timeString;
 }
 
 void MainWindow::volumeUp() {
index 6ffc83ff7c21245cbf8d8230c7aee4d8264b162e..7d3f23d460bf6df9584072c9c6ce955e2a6c4fed 100755 (executable)
@@ -86,6 +86,7 @@ private:
     void showWidget(QWidget*);
     QPixmap createHDPixmap(bool enabled);
     QIcon createHDIcon();
+    static QString formatTime(qint64 time);
 
     // view mechanism
     QPointer<FaderWidget> faderWidget;