Commit 8527f46b authored by Matthieu Gallien's avatar Matthieu Gallien

fix enqueue of directories via the delegate buttons

parent 50cae23c
......@@ -138,5 +138,14 @@ void AbstractMediaProxyModel::replaceAndPlayOfPlayList(QModelIndex rootIndex)
genericEnqueueToPlayList(rootIndex, ElisaUtils::ReplacePlayList, ElisaUtils::TriggerPlay);
}
void AbstractMediaProxyModel::enqueue(const DataTypes::MusicDataType &newEntry, const QString &newEntryTitle, ElisaUtils::PlayListEnqueueMode enqueueMode, ElisaUtils::PlayListEnqueueTriggerPlay triggerPlay)
{
auto allData = DataTypes::EntryDataList{};
allData.push_back(DataTypes::EntryData{newEntry, newEntryTitle, {}});
Q_EMIT entriesToEnqueue(allData, enqueueMode, triggerPlay);
}
#include "moc_abstractmediaproxymodel.cpp"
......@@ -69,6 +69,11 @@ public Q_SLOTS:
void replaceAndPlayOfPlayList(QModelIndex rootIndex);
void enqueue(const DataTypes::MusicDataType &newEntry,
const QString &newEntryTitle,
ElisaUtils::PlayListEnqueueMode enqueueMode,
ElisaUtils::PlayListEnqueueTriggerPlay triggerPlay);
Q_SIGNALS:
void filterTextChanged(const QString &filterText);
......
......@@ -60,47 +60,7 @@ void FileBrowserProxyModel::genericEnqueueToPlayList(QModelIndex rootIndex,
auto currentIndex = index(rowIndex, 0, rootIndex);
const auto rootUrl = data(currentIndex, DataTypes::FilePathRole).toUrl();
auto *job = KIO::listRecursive(rootUrl, {KIO::HideProgressInfo});
connect(job, &KJob::result,
this, [](KJob*) {
});
connect(job, &KIO::ListJob::entries,
this, [rootUrl, this, &enqueueMode, &triggerPlay, &firstTime](KIO::Job *job, const KIO::UDSEntryList &list) {
Q_UNUSED(job)
auto allData = DataTypes::EntryDataList{};
for (const auto &oneEntry : list) {
if (oneEntry.isDir()) {
continue;
}
auto returnedPath = oneEntry.stringValue(KIO::UDSEntry::UDS_NAME);
auto fullPath = QStringLiteral("%0/%1").arg(rootUrl.toString(), returnedPath);
auto fullPathUrl = QUrl{fullPath};
auto mimeType = mMimeDatabase.mimeTypeForUrl(fullPathUrl);
if (!mimeType.name().startsWith(QLatin1String("audio/"))) {
continue;
}
allData.push_back(DataTypes::EntryData{{{DataTypes::ElementTypeRole, ElisaUtils::FileName}}, fullPath, fullPathUrl});
}
if (!firstTime) {
enqueueMode = ElisaUtils::PlayListEnqueueMode::AppendPlayList;
triggerPlay = ElisaUtils::PlayListEnqueueTriggerPlay::DoNotTriggerPlay;
}
if (!allData.isEmpty()) {
Q_EMIT entriesToEnqueue(allData, enqueueMode, triggerPlay);
firstTime = false;
}
});
recursiveEnqueue(rootUrl, enqueueMode, triggerPlay, firstTime);
}
}
......@@ -111,6 +71,18 @@ void FileBrowserProxyModel::enqueueToPlayList(QModelIndex rootIndex)
ElisaUtils::DoNotTriggerPlay);
}
void FileBrowserProxyModel::enqueue(const DataTypes::MusicDataType &newEntry,
const QString &newEntryTitle,
ElisaUtils::PlayListEnqueueMode enqueueMode,
ElisaUtils::PlayListEnqueueTriggerPlay triggerPlay)
{
Q_UNUSED(newEntryTitle)
bool firstTime = true;
recursiveEnqueue(newEntry[DataTypes::FilePathRole].toUrl(), enqueueMode, triggerPlay, firstTime);
}
void FileBrowserProxyModel::replaceAndPlayOfPlayList(QModelIndex rootIndex)
{
genericEnqueueToPlayList(rootIndex,
......@@ -134,6 +106,54 @@ void FileBrowserProxyModel::connectPlayList()
}
}
void FileBrowserProxyModel::recursiveEnqueue(const QUrl &rootUrl,
ElisaUtils::PlayListEnqueueMode enqueueMode,
ElisaUtils::PlayListEnqueueTriggerPlay triggerPlay,
bool &firstTime)
{
auto *job = KIO::listRecursive(rootUrl, {KIO::HideProgressInfo});
connect(job, &KJob::result,
this, [](KJob*) {
});
connect(job, &KIO::ListJob::entries,
this, [rootUrl, this, &enqueueMode, &triggerPlay, &firstTime](KIO::Job *job, const KIO::UDSEntryList &list) {
Q_UNUSED(job)
auto allData = DataTypes::EntryDataList{};
for (const auto &oneEntry : list) {
if (oneEntry.isDir()) {
continue;
}
auto returnedPath = oneEntry.stringValue(KIO::UDSEntry::UDS_NAME);
auto fullPath = QStringLiteral("%0/%1").arg(rootUrl.toString(), returnedPath);
auto fullPathUrl = QUrl{fullPath};
auto mimeType = mMimeDatabase.mimeTypeForUrl(fullPathUrl);
if (!mimeType.name().startsWith(QLatin1String("audio/"))) {
continue;
}
allData.push_back(DataTypes::EntryData{{{DataTypes::ElementTypeRole, ElisaUtils::FileName}}, fullPath, fullPathUrl});
}
if (!firstTime) {
enqueueMode = ElisaUtils::PlayListEnqueueMode::AppendPlayList;
triggerPlay = ElisaUtils::PlayListEnqueueTriggerPlay::DoNotTriggerPlay;
}
if (!allData.isEmpty()) {
Q_EMIT entriesToEnqueue(allData, enqueueMode, triggerPlay);
firstTime = false;
}
});
}
void FileBrowserProxyModel::setSourceModel(QAbstractItemModel *sourceModel)
{
KDirSortFilterProxyModel::setSourceModel(sourceModel);
......
......@@ -64,6 +64,11 @@ public Q_SLOTS:
void replaceAndPlayOfPlayList(QModelIndex rootIndex);
void enqueue(const DataTypes::MusicDataType &newEntry,
const QString &newEntryTitle,
ElisaUtils::PlayListEnqueueMode enqueueMode,
ElisaUtils::PlayListEnqueueTriggerPlay triggerPlay);
void setFilterText(const QString &filterText);
void setFilterRating(int filterRating);
......@@ -98,6 +103,10 @@ private:
void connectPlayList();
void recursiveEnqueue(const QUrl &rootUrl,
ElisaUtils::PlayListEnqueueMode enqueueMode,
ElisaUtils::PlayListEnqueueTriggerPlay triggerPlay, bool &firstTime);
QString mFilterText;
QRegularExpression mFilterExpression;
......
......@@ -73,13 +73,13 @@ FocusScope {
anchors.fill: parent
onEnqueue: elisa.mediaPlayListProxyModel.enqueue(fullData, name,
ElisaUtils.AppendPlayList,
ElisaUtils.DoNotTriggerPlay)
onEnqueue: proxyModel.enqueue(fullData, name,
ElisaUtils.AppendPlayList,
ElisaUtils.DoNotTriggerPlay)
onReplaceAndPlay: elisa.mediaPlayListProxyModel.enqueue(fullData, name,
ElisaUtils.ReplacePlayList,
ElisaUtils.TriggerPlay)
onReplaceAndPlay: proxyModel.enqueue(fullData, name,
ElisaUtils.ReplacePlayList,
ElisaUtils.TriggerPlay)
onOpen: viewManager.openChildView(fullData)
......
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