Compare commits

..

5 Commits

10 changed files with 334 additions and 63 deletions

View File

@ -23,7 +23,6 @@ These features are not available, some of them are TBD and others are not planne
- Limited system integration:
- No [SMTC](https://learn.microsoft.com/en-us/uwp/api/windows.media.systemmediatransportcontrols) support under Windows for now
- No [MPRIS](https://www.freedesktop.org/wiki/Specifications/mpris-spec/) support under Linux desktop for now
- No "playback progress on taskbar icon" and "taskbar thumbnail buttons" support whatever on Windows or Linux desktop for now
- Limited lyrics (`.lrc`) loading support:
- Currently no `.tlrc` (for translated lyrics) or `.rlrc` (for romanized lyrics) support.
- Multi-line lyrics and duplicated timestamps are not supported

View File

@ -12,82 +12,113 @@
<context>
<name>MainWindow</name>
<message>
<location filename="../mainwindow.cpp" line="93"/>
<location filename="../mainwindow.cpp" line="125"/>
<source>Mono</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="95"/>
<location filename="../mainwindow.cpp" line="127"/>
<source>Stereo</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="97"/>
<location filename="../mainwindow.cpp" line="129"/>
<source>%1 Channels</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="241"/>
<location filename="../mainwindow.cpp" line="298"/>
<source>Select songs to play</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="243"/>
<location filename="../mainwindow.cpp" line="300"/>
<source>Audio Files</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="576"/>
<location filename="../mainwindow.cpp" line="685"/>
<source>Select image as background skin</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="578"/>
<location filename="../mainwindow.cpp" line="687"/>
<source>Image files (*.jpg *.jpeg *.png *.gif)</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="764"/>
<source>Based on the following free software libraries:</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mainwindow.ui" line="23"/>
<location filename="../mainwindow.cpp" line="762"/>
<location filename="../lrcbar.cpp" line="89"/>
<source>Pineapple Music</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mainwindow.ui" line="313"/>
<location filename="../mainwindow.ui" line="327"/>
<source>No song loaded...</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mainwindow.ui" line="325"/>
<location filename="../mainwindow.ui" line="339"/>
<source>Drag and drop file to load</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mainwindow.ui" line="338"/>
<location filename="../mainwindow.ui" line="352"/>
<source>Lrc</source>
<comment>Lyrics</comment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="103"/>
<location filename="../mainwindow.ui" line="711"/>
<location filename="../mainwindow.ui" line="714"/>
<location filename="../mainwindow.cpp" line="759"/>
<source>About</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mainwindow.ui" line="728"/>
<source>Open</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="135"/>
<source>Sample Rate: %1 Hz</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="108"/>
<location filename="../mainwindow.cpp" line="140"/>
<source>Bitrate: %1 Kbps</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="113"/>
<location filename="../mainwindow.cpp" line="145"/>
<source>Channel Count: %1</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PlaybackProgressIndicator</name>
<message>
<location filename="../playbackprogressindicator.cpp" line="85"/>
<source>Time</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../playbackprogressindicator.cpp" line="85"/>
<source>Chapter Name</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>main</name>
<message>
<location filename="../main.cpp" line="28"/>
<location filename="../main.cpp" line="27"/>
<source>File list.</source>
<translation type="unfinished"></translation>
</message>

View File

@ -12,82 +12,113 @@
<context>
<name>MainWindow</name>
<message>
<location filename="../mainwindow.cpp" line="93"/>
<location filename="../mainwindow.cpp" line="125"/>
<source>Mono</source>
<translation></translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="95"/>
<location filename="../mainwindow.cpp" line="127"/>
<source>Stereo</source>
<translation></translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="97"/>
<location filename="../mainwindow.cpp" line="129"/>
<source>%1 Channels</source>
<translation>%1 </translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="241"/>
<location filename="../mainwindow.cpp" line="298"/>
<source>Select songs to play</source>
<translation></translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="243"/>
<location filename="../mainwindow.cpp" line="300"/>
<source>Audio Files</source>
<translation></translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="576"/>
<location filename="../mainwindow.cpp" line="685"/>
<source>Select image as background skin</source>
<translation></translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="578"/>
<location filename="../mainwindow.cpp" line="687"/>
<source>Image files (*.jpg *.jpeg *.png *.gif)</source>
<translation> (*.jpg *.jpeg *.png *.gif)</translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="764"/>
<source>Based on the following free software libraries:</source>
<translation></translation>
</message>
<message>
<location filename="../mainwindow.ui" line="23"/>
<location filename="../mainwindow.cpp" line="762"/>
<location filename="../lrcbar.cpp" line="89"/>
<source>Pineapple Music</source>
<translation></translation>
</message>
<message>
<location filename="../mainwindow.ui" line="313"/>
<location filename="../mainwindow.ui" line="327"/>
<source>No song loaded...</source>
<translation>...</translation>
</message>
<message>
<location filename="../mainwindow.ui" line="325"/>
<location filename="../mainwindow.ui" line="339"/>
<source>Drag and drop file to load</source>
<translation></translation>
</message>
<message>
<location filename="../mainwindow.ui" line="338"/>
<location filename="../mainwindow.ui" line="352"/>
<source>Lrc</source>
<comment>Lyrics</comment>
<translation></translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="103"/>
<location filename="../mainwindow.ui" line="711"/>
<location filename="../mainwindow.ui" line="714"/>
<location filename="../mainwindow.cpp" line="759"/>
<source>About</source>
<translation></translation>
</message>
<message>
<location filename="../mainwindow.ui" line="728"/>
<source>Open</source>
<translation></translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="135"/>
<source>Sample Rate: %1 Hz</source>
<translation>: %1 Hz</translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="108"/>
<location filename="../mainwindow.cpp" line="140"/>
<source>Bitrate: %1 Kbps</source>
<translation>: %1 Kbps</translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="113"/>
<location filename="../mainwindow.cpp" line="145"/>
<source>Channel Count: %1</source>
<translation>: %1</translation>
</message>
</context>
<context>
<name>PlaybackProgressIndicator</name>
<message>
<location filename="../playbackprogressindicator.cpp" line="85"/>
<source>Time</source>
<translation></translation>
</message>
<message>
<location filename="../playbackprogressindicator.cpp" line="85"/>
<source>Chapter Name</source>
<translation></translation>
</message>
</context>
<context>
<name>main</name>
<message>
<location filename="../main.cpp" line="28"/>
<location filename="../main.cpp" line="27"/>
<source>File list.</source>
<translation></translation>
</message>

View File

@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2024 Gary Wang <git@blumia.net>
// SPDX-FileCopyrightText: 2025 Gary Wang <opensource@blumia.net>
//
// SPDX-License-Identifier: MIT
@ -27,6 +27,7 @@
#include <QListView>
#include <QCollator>
#include <QMimeData>
#include <QMenu>
#include <QWindow>
#include <QStandardPaths>
#include <QMediaDevices>
@ -60,6 +61,10 @@ MainWindow::MainWindow(QWidget *parent)
m_mediaPlayer->setLoops(QMediaPlayer::Infinite);
ui->playlistView->setModel(m_playlistManager->model());
ui->chapterNameBtn->setVisible(false);
ui->chapterlistView->setModel(ui->playbackProgressIndicator->chapterModel());
ui->chapterlistView->setRootIsDecorated(false);
ui->actionHelp->setShortcut(QKeySequence::HelpContents);
addAction(ui->actionHelp);
ui->actionOpen->setShortcut(QKeySequence::Open);
@ -260,6 +265,15 @@ void MainWindow::dropEvent(QDropEvent *e)
return;
}
if (fileName.endsWith(".m3u") || fileName.endsWith(".m3u8")) {
const QModelIndex & modelIndex = m_playlistManager->loadM3U8Playlist(urls.constFirst());
if (modelIndex.isValid()) {
loadByModelIndex(modelIndex);
play();
}
return;
}
const QModelIndex & modelIndex = m_playlistManager->loadPlaylist(urls);
if (modelIndex.isValid()) {
loadByModelIndex(modelIndex);
@ -267,6 +281,16 @@ void MainWindow::dropEvent(QDropEvent *e)
}
}
void MainWindow::contextMenuEvent(QContextMenuEvent *event)
{
QMenu * menu = new QMenu;
menu->addAction(ui->actionHelp);
menu->exec(mapToGlobal(event->pos()));
menu->deleteLater();
return QMainWindow::contextMenuEvent(event);
}
void MainWindow::loadFile()
{
QStringList musicFolders(QStandardPaths::standardLocations(QStandardPaths::MusicLocation));
@ -281,9 +305,8 @@ void MainWindow::loadFile()
urlList.append(QUrl::fromLocalFile(fileName));
}
m_playlistManager->loadPlaylist(urlList);
const QUrl & firstUrl = urlList.first();
loadFile(firstUrl);
const QModelIndex & modelIndex = m_playlistManager->loadPlaylist(urlList);
loadByModelIndex(modelIndex);
}
void MainWindow::loadFile(const QUrl &url)
@ -349,16 +372,6 @@ void MainWindow::on_playBtn_clicked()
}
}
QString MainWindow::ms2str(qint64 ms)
{
QTime duaTime(QTime::fromMSecsSinceStartOfDay(ms));
if (duaTime.hour() > 0) {
return duaTime.toString("h:mm:ss");
} else {
return duaTime.toString("m:ss");
}
}
QList<QUrl> MainWindow::strlst2urllst(QStringList strlst)
{
QList<QUrl> urlList;
@ -501,12 +514,28 @@ void MainWindow::initConnections()
});
connect(m_mediaPlayer, &QMediaPlayer::positionChanged, this, [=](qint64 pos) {
ui->nowTimeLabel->setText(ms2str(pos));
ui->nowTimeLabel->setText(PlaybackProgressIndicator::formatTime(pos));
if (m_mediaPlayer->duration() != 0) {
ui->playbackProgressIndicator->setPosition(pos);
m_taskbarManager->setProgressValue(pos);
}
m_lrcbar->playbackPositionChanged(pos, m_mediaPlayer->duration());
static QString lastChapterName;
if (ui->playbackProgressIndicator->chapterModel()->rowCount() > 0) {
QString currentChapterName = ui->playbackProgressIndicator->currentChapterName();
if (currentChapterName != lastChapterName) {
ui->chapterNameBtn->setText(currentChapterName);
lastChapterName = currentChapterName;
}
ui->chapterNameBtn->setVisible(true);
} else {
if (!lastChapterName.isEmpty()) {
ui->chapterNameBtn->setText("");
lastChapterName.clear();
}
ui->chapterNameBtn->setVisible(false);
}
});
connect(m_audioOutput, &QAudioOutput::mutedChanged, this, [=](bool muted) {
@ -520,7 +549,7 @@ void MainWindow::initConnections()
connect(m_mediaPlayer, &QMediaPlayer::durationChanged, this, [=](qint64 dua) {
ui->playbackProgressIndicator->setDuration(dua);
m_taskbarManager->setProgressMaximum(dua);
ui->totalTimeLabel->setText(ms2str(dua));
ui->totalTimeLabel->setText(PlaybackProgressIndicator::formatTime(dua));
});
connect(m_mediaPlayer, &QMediaPlayer::playbackStateChanged, this, [=](QMediaPlayer::PlaybackState newState) {
@ -668,7 +697,16 @@ void MainWindow::on_setSkinBtn_clicked()
void MainWindow::on_playListBtn_clicked()
{
setFixedSize(size().height() < 200 ? fullSize : miniSize);
if (size().height() < 200) {
setFixedSize(fullSize);
ui->pluginStackedWidget->setCurrentWidget(ui->playlistViewPage);
} else {
if (ui->pluginStackedWidget->currentWidget() == ui->playlistViewPage) {
setFixedSize(miniSize);
} else {
ui->pluginStackedWidget->setCurrentWidget(ui->playlistViewPage);
}
}
}
void MainWindow::on_playlistView_activated(const QModelIndex &index)
@ -687,6 +725,33 @@ void MainWindow::on_lrcBtn_clicked()
}
}
void MainWindow::on_chapterlistView_activated(const QModelIndex &index)
{
if (!index.isValid()) return;
QModelIndex timeColumnIndex = index.sibling(index.row(), 0);
QStandardItem* timeItem = ui->playbackProgressIndicator->chapterModel()->itemFromIndex(timeColumnIndex);
if (!timeItem) return;
qint64 chapterStartTime = timeItem->data(PlaybackProgressIndicator::StartTimeMsRole).toLongLong();
m_mediaPlayer->setPosition(chapterStartTime);
}
void MainWindow::on_chapterNameBtn_clicked()
{
if (size().height() < 200) {
setFixedSize(fullSize);
}
ui->pluginStackedWidget->setCurrentWidget(ui->chaptersViewPage);
if (ui->playbackProgressIndicator->chapterModel()->rowCount() > 0) {
const QModelIndex & curChapterItem = ui->playbackProgressIndicator->currentChapterItem();
if (curChapterItem.isValid()) {
ui->chapterlistView->setCurrentIndex(curChapterItem);
ui->chapterlistView->scrollTo(curChapterItem, QAbstractItemView::EnsureVisible);
}
}
}
void MainWindow::on_actionOpen_triggered()
{
loadFile();
@ -734,4 +799,3 @@ QGraphicsDropShadowEffect *MainWindow::createLabelShadowEffect()
effect->setOffset(1, 1);
return effect;
}

View File

@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2024 Gary Wang <git@blumia.net>
// SPDX-FileCopyrightText: 2025 Gary Wang <opensource@blumia.net>
//
// SPDX-License-Identifier: MIT
@ -55,6 +55,7 @@ protected:
void mouseReleaseEvent(QMouseEvent *event) override;
void dragEnterEvent(QDragEnterEvent *e) override;
void dropEvent(QDropEvent *e) override;
void contextMenuEvent(QContextMenuEvent *event) override;
void loadFile();
void loadFile(const QUrl &url);
@ -79,6 +80,8 @@ private slots:
void on_playListBtn_clicked();
void on_playlistView_activated(const QModelIndex &index);
void on_lrcBtn_clicked();
void on_chapterlistView_activated(const QModelIndex &index);
void on_chapterNameBtn_clicked();
void on_actionOpen_triggered();
void on_actionHelp_triggered();

View File

@ -109,6 +109,18 @@ QLabel#coverLabel {
QListView {
color: white;
background: rgba(0, 0, 0, 50);
}
/****** TreeView ******/
QTreeView {
color: white;
background: rgba(0, 0, 0, 50);
}
QHeaderView {
color: white;
background-color: rgba(200, 200, 200, 50);
}</string>
</property>
<property name="locale">
@ -217,7 +229,7 @@ QListView {
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
@ -295,7 +307,7 @@ QListView {
<item>
<layout class="QVBoxLayout" name="playerPanelLayout">
<property name="sizeConstraint">
<enum>QLayout::SizeConstraint::SetDefaultConstraint</enum>
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<property name="rightMargin">
<number>10</number>
@ -358,13 +370,26 @@ QListView {
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="chapterNameBtn">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="totalTimeLabel">
<property name="text">
<string notr="true">0:00</string>
</property>
<property name="alignment">
<set>Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter</set>
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
@ -599,7 +624,7 @@ QListView {
<number>100</number>
</property>
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
@ -626,7 +651,10 @@ QListView {
<height>0</height>
</size>
</property>
<widget class="QWidget" name="pluginStackedWidgetPage1">
<property name="currentIndex">
<number>1</number>
</property>
<widget class="QWidget" name="playlistViewPage">
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="spacing">
<number>0</number>
@ -648,22 +676,48 @@ QListView {
</item>
</layout>
</widget>
<widget class="QWidget" name="chaptersViewPage">
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="leftMargin">
<number>4</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>4</number>
</property>
<property name="bottomMargin">
<number>4</number>
</property>
<item>
<widget class="QTreeView" name="chapterlistView">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<action name="actionHelp">
<property name="icon">
<iconset theme="system-help"/>
</property>
<property name="text">
<string>Help</string>
<string>About</string>
</property>
<property name="toolTip">
<string>Help</string>
<string>About</string>
</property>
<property name="shortcut">
<string>F1</string>
<string notr="true">F1</string>
</property>
<property name="menuRole">
<enum>QAction::MenuRole::NoRole</enum>
<enum>QAction::AboutRole</enum>
</property>
</action>
<action name="actionOpen">
@ -674,10 +728,10 @@ QListView {
<string>Open</string>
</property>
<property name="shortcut">
<string>Ctrl+O</string>
<string notr="true">Ctrl+O</string>
</property>
<property name="menuRole">
<enum>QAction::MenuRole::NoRole</enum>
<enum>QAction::NoRole</enum>
</property>
</action>
</widget>

View File

@ -25,6 +25,37 @@ PlaybackProgressIndicator::PlaybackProgressIndicator(QWidget *parent) :
{
}
QModelIndex PlaybackProgressIndicator::currentChapterItem() const
{
int currentChapterIndex = -1;
for (int i = 0; i < m_chapterModel.rowCount(); i++) {
QStandardItem* timeItem = m_chapterModel.item(i, 0);
qint64 chapterStartTime = timeItem->data(PlaybackProgressIndicator::StartTimeMsRole).toLongLong();
if (m_position >= chapterStartTime) {
currentChapterIndex = i;
} else {
break;
}
}
if (currentChapterIndex >= 0) {
return m_chapterModel.index(currentChapterIndex, 0);
}
return {};
}
QString PlaybackProgressIndicator::currentChapterName() const
{
const QModelIndex timeIndex(currentChapterItem());
if (timeIndex.isValid()) {
return m_chapterModel.item(timeIndex.row(), 1)->text();
}
return {};
}
void PlaybackProgressIndicator::setPosition(qint64 pos)
{
m_position = pos;
@ -37,14 +68,34 @@ void PlaybackProgressIndicator::setDuration(qint64 dur)
emit durationChanged(m_duration);
}
QString PlaybackProgressIndicator::formatTime(qint64 milliseconds)
{
QTime duaTime(QTime::fromMSecsSinceStartOfDay(milliseconds));
if (duaTime.hour() > 0) {
return duaTime.toString("h:mm:ss");
} else {
return duaTime.toString("m:ss");
}
}
void PlaybackProgressIndicator::setChapters(QList<std::pair<qint64, QString> > chapters)
{
qDebug() << chapters;
m_chapterModel.clear();
m_chapterModel.setHorizontalHeaderLabels(QStringList() << tr("Time") << tr("Chapter Name"));
for (const std::pair<qint64, QString> & chapter : chapters) {
QList<QStandardItem*> row;
QStandardItem * timeItem = new QStandardItem(formatTime(chapter.first));
timeItem->setData(chapter.first, StartTimeMsRole);
row.append(timeItem);
QStandardItem * chapterItem = new QStandardItem(chapter.second);
chapterItem->setData(chapter.first, StartTimeMsRole);
m_chapterModel.appendRow(chapterItem);
row.append(chapterItem);
m_chapterModel.appendRow(row);
}
update();
}

View File

@ -24,10 +24,15 @@ public:
explicit PlaybackProgressIndicator(QWidget *parent = nullptr);
~PlaybackProgressIndicator() = default;
QStandardItemModel* chapterModel() { return &m_chapterModel; }
QModelIndex currentChapterItem() const;
QString currentChapterName() const;
void setPosition(qint64 pos);
void setDuration(qint64 dur);
void setChapters(QList<std::pair<qint64, QString>> chapters);
static QString formatTime(qint64 milliseconds);
static QList<std::pair<qint64, QString>> tryLoadChapters(const QString & filePath);
static QList<std::pair<qint64, QString>> tryLoadSidecarChapterFile(const QString & filePath);
static QList<std::pair<qint64, QString>> tryLoadChaptersFromMetadata(const QString & filePath);

View File

@ -186,6 +186,26 @@ QModelIndex PlaylistManager::loadPlaylist(const QUrl &url)
return idx;
}
QModelIndex PlaylistManager::loadM3U8Playlist(const QUrl &url)
{
QFile file(url.toLocalFile());
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
QList<QUrl> urls;
while (!file.atEnd()) {
QString line = file.readLine();
if (line.startsWith('#')) {
continue;
}
QFileInfo fileInfo(file);
QUrl item = QUrl::fromUserInput(line, fileInfo.absolutePath());
urls.append(item);
}
return loadPlaylist(urls);
} else {
return {};
}
}
int PlaylistManager::totalCount() const
{
return m_model.rowCount();
@ -196,7 +216,7 @@ QModelIndex PlaylistManager::previousIndex() const
int count = totalCount();
if (count == 0) return {};
return m_model.index(m_currentIndex - 1 < 0 ? count - 1 : m_currentIndex - 1);
return m_model.index(isFirstIndex() ? count - 1 : m_currentIndex - 1);
}
QModelIndex PlaylistManager::nextIndex() const
@ -204,7 +224,7 @@ QModelIndex PlaylistManager::nextIndex() const
int count = totalCount();
if (count == 0) return {};
return m_model.index(m_currentIndex + 1 == count ? 0 : m_currentIndex + 1);
return m_model.index(isLastIndex() ? 0 : m_currentIndex + 1);
}
QModelIndex PlaylistManager::curIndex() const
@ -212,6 +232,16 @@ QModelIndex PlaylistManager::curIndex() const
return m_model.index(m_currentIndex);
}
bool PlaylistManager::isFirstIndex() const
{
return m_currentIndex == 0;
}
bool PlaylistManager::isLastIndex() const
{
return m_currentIndex + 1 == totalCount();
}
void PlaylistManager::setCurrentIndex(const QModelIndex &index)
{
if (index.isValid() && index.row() >= 0 && index.row() < totalCount()) {

View File

@ -61,11 +61,14 @@ public:
void setPlaylist(const QList<QUrl> & url);
Q_INVOKABLE QModelIndex loadPlaylist(const QList<QUrl> & urls);
Q_INVOKABLE QModelIndex loadPlaylist(const QUrl & url);
Q_INVOKABLE QModelIndex loadM3U8Playlist(const QUrl & url);
int totalCount() const;
QModelIndex previousIndex() const;
QModelIndex nextIndex() const;
QModelIndex curIndex() const;
bool isFirstIndex() const;
bool isLastIndex() const;
void setCurrentIndex(const QModelIndex & index);
QUrl urlByIndex(const QModelIndex & index);
QString localFileByIndex(const QModelIndex & index);