blob: 778fae1e05f0be2fe5e19e932672d5d0a0e49363 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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 {};
}
|