Commit 555e011a authored by Graham Littlewood's avatar Graham Littlewood
Browse files

Add directory-based file adding

parent 09ee9676
......@@ -48,6 +48,8 @@ public:
QRandomGenerator mRandomGenerator;
QMimeDatabase mMimeDb;
ElisaUtils::PlayListEnqueueTriggerPlay mTriggerPlay = ElisaUtils::DoNotTriggerPlay;
int mCurrentPlayListPosition = -1;
......@@ -844,4 +846,27 @@ void MediaPlayListProxyModel::setPersistentState(const QVariantMap &persistentSt
Q_EMIT persistentStateChanged();
}
void MediaPlayListProxyModel::enqueueDirectory(const QUrl &fileName, ElisaUtils::PlayListEntryType databaseIdType,
ElisaUtils::PlayListEnqueueMode enqueueMode,
ElisaUtils::PlayListEnqueueTriggerPlay triggerPlay, int depth)
{
if (!fileName.isLocalFile()) return;
QDir dirInfo = QDir(fileName.toLocalFile());
auto files = dirInfo.entryInfoList(QDir::NoDotAndDotDot | QDir::Readable | QDir::Files | QDir::Dirs, QDir::Name);
auto newFiles = ElisaUtils::EntryDataList();
for (auto file : files)
{
auto fileUrl = QUrl::fromLocalFile(file.filePath());
if (file.isFile() && d->mMimeDb.mimeTypeForUrl(fileUrl).name().startsWith(QLatin1String("audio/")))
{
newFiles.append({ElisaUtils::EntryData{{},{},fileUrl}});
}
else if (file.isDir() && depth > 1)
{
enqueueDirectory(fileUrl, databaseIdType, ElisaUtils::AppendPlayList, triggerPlay, depth-1);
}
}
if (newFiles.size() != 0) enqueue(newFiles, databaseIdType, enqueueMode, triggerPlay);
}
#include "moc_mediaplaylistproxymodel.cpp"
......@@ -24,6 +24,8 @@
#include <QAbstractProxyModel>
#include <QMediaPlayer>
#include <QDir>
#include <QMimeDatabase>
#include <memory>
......@@ -176,6 +178,11 @@ public Q_SLOTS:
void setPersistentState(const QVariantMap &persistentState);
void enqueueDirectory(const QUrl &fileName,
ElisaUtils::PlayListEntryType databaseIdType,
ElisaUtils::PlayListEnqueueMode enqueueMode,
ElisaUtils::PlayListEnqueueTriggerPlay triggerPlay, int depth);
Q_SIGNALS:
void previousTrackChanged(const QPersistentModelIndex &previousTrack);
......
......@@ -151,12 +151,14 @@ FocusScope {
entryType: ElisaUtils.FileName
imageUrl: model.imageUrl
showDetailsButton: !model.isDirectory && !model.isPlaylist
showEnqueueButton: !model.isDirectory && !model.isPlaylist
showPlayButton: !model.isDirectory
showEnqueueButton: !model.isPlaylist
showPlayButton: true
onEnqueue: elisa.mediaPlayListProxyModel.enqueue(url, ElisaUtils.FileName, ElisaUtils.AppendPlayList, ElisaUtils.DoNotTriggerPlay)
onEnqueue: isDirectory? elisa.mediaPlayListProxyModel.enqueueDirectory(url, ElisaUtils.FileName, ElisaUtils.AppendPlayList, ElisaUtils.DoNotTriggerPlay, 5) : elisa.mediaPlayListProxyModel.enqueue(url, ElisaUtils.FileName, ElisaUtils.AppendPlayList, ElisaUtils.DoNotTriggerPlay)
onReplaceAndPlay: {
if (model.isPlaylist) {
if (model.isDirectory) {
elisa.mediaPlayListProxyModel.enqueueDirectory(url, ElisaUtils.FileName, ElisaUtils.ReplacePlayList, ElisaUtils.TriggerPlay, 5)
} else if (model.isPlaylist) {
elisa.mediaPlayListProxyModel.loadPlaylist(url)
} else {
elisa.mediaPlayListProxyModel.enqueue(url, ElisaUtils.FileName, ElisaUtils.ReplacePlayList, ElisaUtils.TriggerPlay)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment