Skip to content

Commit

Permalink
Read system projectm presets from subdirs
Browse files Browse the repository at this point in the history
Fix clementine-player#7151

Note that this requires C++17 patches from clementine-player#7272 because I don't want to
bother backporting the fix to syntax available in C++11
  • Loading branch information
DarthGandalf committed Nov 10, 2023
1 parent 5968648 commit fb3d5ad
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
20 changes: 12 additions & 8 deletions src/visualisations/projectmpresetmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,26 @@
#endif

#include <QDir>
#include <QDirIterator>
#include <QtDebug>
#include <set>

ProjectMPresetModel::ProjectMPresetModel(ProjectMVisualisation* vis,
QObject* parent)
: QAbstractItemModel(parent), vis_(vis) {
// Find presets
QDir preset_dir(vis_->preset_url());
QStringList presets(
preset_dir.entryList(QStringList() << "*.milk"
<< "*.prjm",
QDirIterator it(vis_->preset_url(),
QStringList() << "*.milk" << "*.prjm",
QDir::Files | QDir::NoDotAndDotDot | QDir::Readable,
QDir::Name | QDir::IgnoreCase));
QDirIterator::Subdirectories);
std::set<std::pair<QString, QString>> files;
while (it.hasNext()) {
it.next();
files.insert({it.filePath(), it.fileName()});
}

for (const QString& filename : presets) {
all_presets_ << Preset(preset_dir.absoluteFilePath(filename), filename,
false);
for (const auto& [filePath, fileName] : files) {
all_presets_ << Preset(filePath, fileName, false);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/visualisations/projectmvisualisation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void ProjectMVisualisation::InitProjectM() {
if (!QFile::exists(path)) continue;

// Don't use empty directories
if (QDir(path).entryList(QDir::Files | QDir::NoDotAndDotDot).isEmpty())
if (QDir(path).entryList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot).isEmpty())
continue;

preset_path = path;
Expand Down

0 comments on commit fb3d5ad

Please sign in to comment.