Commit 74c59bea authored by Matthieu Gallien's avatar Matthieu Gallien 🎵
Browse files

fix most issues when enqueing stuff in files browser

parent e4d5a486
......@@ -791,7 +791,8 @@ void MediaPlayListProxyModel::enqueueDirectory(const QUrl &fileName, ElisaUtils:
auto fileUrl = QUrl::fromLocalFile(file.filePath());
if (file.isFile() && d->mMimeDb.mimeTypeForUrl(fileUrl).name().startsWith(QLatin1String("audio/")))
{
newFiles.append({DataTypes::EntryData{{},{},fileUrl}});
newFiles.push_back({{{DataTypes::ElementTypeRole, ElisaUtils::Track},
{DataTypes::ResourceRole, fileUrl}},{}, {}});
}
else if (file.isDir() && depth > 1)
{
......
......@@ -76,7 +76,7 @@ bool FileBrowserProxyModel::filterAcceptsRow(int source_row, const QModelIndex &
return result;
}
void FileBrowserProxyModel::enqueueToPlayList()
void FileBrowserProxyModel::genericEnqueueToPlayList(ElisaUtils::PlayListEnqueueMode enqueueMode, ElisaUtils::PlayListEnqueueTriggerPlay triggerPlay)
{
QtConcurrent::run(&mThreadPool, [=] () {
QReadLocker locker(&mDataLock);
......@@ -84,30 +84,24 @@ void FileBrowserProxyModel::enqueueToPlayList()
for (int rowIndex = 0, maxRowCount = rowCount(); rowIndex < maxRowCount; ++rowIndex) {
auto currentIndex = index(rowIndex, 0);
if (!data(currentIndex, FileBrowserModel::IsDirectoryRole).toBool()) {
allTrackUrls.push_back({{}, {}, data(currentIndex, FileBrowserModel::FileUrlRole).toUrl()});
allTrackUrls.push_back({{{DataTypes::ElementTypeRole, ElisaUtils::Track},
{DataTypes::ResourceRole, data(currentIndex, FileBrowserModel::FileUrlRole).toUrl()}}, {}, {}});
}
}
Q_EMIT filesToEnqueue(allTrackUrls,
ElisaUtils::AppendPlayList,
ElisaUtils::DoNotTriggerPlay);
Q_EMIT entriesToEnqueue(allTrackUrls, enqueueMode, triggerPlay);
});
}
void FileBrowserProxyModel::enqueueToPlayList()
{
genericEnqueueToPlayList(ElisaUtils::AppendPlayList,
ElisaUtils::DoNotTriggerPlay);
}
void FileBrowserProxyModel::replaceAndPlayOfPlayList()
{
QtConcurrent::run(&mThreadPool, [=] () {
QReadLocker locker(&mDataLock);
auto allTrackUrls = DataTypes::EntryDataList{};
for (int rowIndex = 0, maxRowCount = rowCount(); rowIndex < maxRowCount; ++rowIndex) {
auto currentIndex = index(rowIndex, 0);
if (!data(currentIndex, FileBrowserModel::IsDirectoryRole).toBool()) {
allTrackUrls.push_back({{}, {}, data(currentIndex, FileBrowserModel::FileUrlRole).toUrl()});
}
}
Q_EMIT filesToEnqueue(allTrackUrls,
ElisaUtils::ReplacePlayList,
genericEnqueueToPlayList(ElisaUtils::ReplacePlayList,
ElisaUtils::TriggerPlay);
});
}
QString FileBrowserProxyModel::parentFolder() const
......@@ -130,7 +124,7 @@ QString FileBrowserProxyModel::parentFolder() const
void FileBrowserProxyModel::disconnectPlayList()
{
if (mPlayList) {
disconnect(this, &FileBrowserProxyModel::filesToEnqueue,
disconnect(this, &FileBrowserProxyModel::entriesToEnqueue,
mPlayList, static_cast<void(MediaPlayListProxyModel::*)(const DataTypes::EntryDataList&, ElisaUtils::PlayListEnqueueMode, ElisaUtils::PlayListEnqueueTriggerPlay)>(&MediaPlayListProxyModel::enqueue));
}
}
......@@ -138,7 +132,7 @@ void FileBrowserProxyModel::disconnectPlayList()
void FileBrowserProxyModel::connectPlayList()
{
if (mPlayList) {
connect(this, &FileBrowserProxyModel::filesToEnqueue,
connect(this, &FileBrowserProxyModel::entriesToEnqueue,
mPlayList, static_cast<void(MediaPlayListProxyModel::*)(const DataTypes::EntryDataList&, ElisaUtils::PlayListEnqueueMode, ElisaUtils::PlayListEnqueueTriggerPlay)>(&MediaPlayListProxyModel::enqueue));
}
}
......
......@@ -82,9 +82,9 @@ public Q_SLOTS:
Q_SIGNALS:
void filesToEnqueue(const DataTypes::EntryDataList &newFiles,
ElisaUtils::PlayListEnqueueMode enqueueMode,
ElisaUtils::PlayListEnqueueTriggerPlay triggerPlay);
void entriesToEnqueue(const DataTypes::EntryDataList &newEntries,
ElisaUtils::PlayListEnqueueMode enqueueMode,
ElisaUtils::PlayListEnqueueTriggerPlay triggerPlay);
void urlChanged();
......@@ -102,6 +102,9 @@ protected:
private:
void genericEnqueueToPlayList(ElisaUtils::PlayListEnqueueMode enqueueMode,
ElisaUtils::PlayListEnqueueTriggerPlay triggerPlay);
QString parentFolder() const;
void disconnectPlayList();
......
......@@ -143,14 +143,22 @@ FocusScope {
showEnqueueButton: !model.isPlaylist
showPlayButton: true
onEnqueue: isDirectory ? elisa.mediaPlayListProxyModel.enqueueDirectory(url, ElisaUtils.FileName, ElisaUtils.AppendPlayList, ElisaUtils.DoNotTriggerPlay, 10) : elisa.mediaPlayListProxyModel.enqueue(url, ElisaUtils.AppendPlayList, ElisaUtils.DoNotTriggerPlay)
onEnqueue: {
if (model.isDirectory) {
elisa.mediaPlayListProxyModel.enqueueDirectory(model.fileUrl, ElisaUtils.FileName, ElisaUtils.AppendPlayList, ElisaUtils.DoNotTriggerPlay, 10)
} else if (model.isPlaylist) {
elisa.mediaPlayListProxyModel.loadPlayList(model.fileUrl)
} else {
elisa.mediaPlayListProxyModel.enqueue(model.fileUrl, ElisaUtils.AppendPlayList, ElisaUtils.DoNotTriggerPlay)
}
}
onReplaceAndPlay: {
if (model.isDirectory) {
elisa.mediaPlayListProxyModel.enqueueDirectory(url, ElisaUtils.FileName, ElisaUtils.ReplacePlayList, ElisaUtils.TriggerPlay, 10)
elisa.mediaPlayListProxyModel.enqueueDirectory(model.fileUrl, ElisaUtils.FileName, ElisaUtils.ReplacePlayList, ElisaUtils.TriggerPlay, 10)
} else if (model.isPlaylist) {
elisa.mediaPlayListProxyModel.loadPlaylist(url)
elisa.mediaPlayListProxyModel.loadPlayList(model.fileUrl)
} else {
elisa.mediaPlayListProxyModel.enqueue(url, ElisaUtils.ReplacePlayList, ElisaUtils.TriggerPlay)
elisa.mediaPlayListProxyModel.enqueue(model.fileUrl, ElisaUtils.ReplacePlayList, ElisaUtils.TriggerPlay)
}
}
onSelected: {
......
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