feat(playlist): compact rows with clean titles and durations
This commit is contained in:
1 parent
b34a01a92f
commit
76ba7b0be0
9 files changed
+370
-55
No files matched your search
@@ -4,7 +4,9 @@
|
||||
#include "playlistmodel.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QProcess>
|
||||
#include <QSignalSpy>
|
||||
#include <QStandardPaths>
|
||||
#include <QTemporaryDir>
|
||||
#include <QTest>
|
||||
|
||||
@@ -98,6 +100,31 @@ private Q_SLOTS:
|
||||
QCOMPARE(model.playingIndex(), -1);
|
||||
QCOMPARE(model.count(), 1);
|
||||
}
|
||||
|
||||
void titleAndDurationRoles()
|
||||
{
|
||||
const QString ffmpeg = QStandardPaths::findExecutable(u"ffmpeg"_s);
|
||||
if (ffmpeg.isEmpty()) {
|
||||
QSKIP("ffmpeg is needed to make a sample file");
|
||||
}
|
||||
QTemporaryDir dir;
|
||||
const QString path = dir.filePath(u"Show.S01E02.The.Tone.1080p.WEB.mka"_s);
|
||||
QProcess process;
|
||||
process.start(ffmpeg, {u"-v"_s, u"error"_s, u"-f"_s, u"lavfi"_s, u"-i"_s, u"sine=duration=2"_s, path});
|
||||
QVERIFY(process.waitForFinished());
|
||||
QCOMPARE(process.exitCode(), 0);
|
||||
|
||||
PlaylistModel model;
|
||||
QSignalSpy changed(&model, &QAbstractItemModel::dataChanged);
|
||||
model.append({QUrl::fromLocalFile(path), QUrl(u"https://example.com/a"_s)});
|
||||
QCOMPARE(model.data(model.index(0), PlaylistModel::TitleRole).toString(), u"S01E02 · The Tone"_s);
|
||||
QCOMPARE(model.data(model.index(1), PlaylistModel::TitleRole).toString(), u"https://example.com/a"_s);
|
||||
QCOMPARE(model.data(model.index(1), PlaylistModel::DurationRole).toDouble(), -1.0);
|
||||
|
||||
QTRY_COMPARE(changed.count(), 1);
|
||||
QCOMPARE(changed.first().at(2).value<QList<int>>(), QList<int>{PlaylistModel::DurationRole});
|
||||
QVERIFY(qAbs(model.data(model.index(0), PlaylistModel::DurationRole).toDouble() - 2) < 0.1);
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_GUILESS_MAIN(PlaylistModelTest)
|
||||
|
||||
Reference in new issue
Block a user