diff options
Diffstat (limited to 'playlist/playlist.cpp')
-rw-r--r-- | playlist/playlist.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/playlist/playlist.cpp b/playlist/playlist.cpp new file mode 100644 index 0000000..778fae1 --- /dev/null +++ b/playlist/playlist.cpp @@ -0,0 +1,36 @@ +/* ============================================================ + * SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2023 aqua <aqua@iserlohn-fortress.net> + * ============================================================ */ + +#include "playlist.hpp" +#include "playlistmodel.hpp" +#include <QDir> +#include <QFileInfo> + +Playlist::Playlist(QObject *parent) : QObject{parent}, m_model(new PlaylistModel(this)) {} + +void Playlist::appendUrl(const QUrl &url) +{ + const QFileInfo info(url.toLocalFile()); + if (!info.exists()) return; // if file doesn't exist, return + + if (info.isFile()) { + emit mediaAboutToBeInserted(m_urls.count(), m_urls.count() + 1); + m_urls.append(url.toLocalFile()); + emit mediaInserted(); + } + else if (info.isFile()) { + QDir dir(info.absoluteFilePath()); + const auto list = dir.entryInfoList(QDir::Files); + emit mediaAboutToBeInserted(m_urls.count(), m_urls.count() + list.count()); + for (const auto &i : list) { m_urls.append(i.absoluteFilePath()); } + emit mediaInserted(); + } +} + +QUrl Playlist::operator[](const int index) const +{ + if (index < m_urls.count()) return m_urls.at(index); + return {}; +} |