From 05c577bd3d0b6c8f532ad90ec23ca9c85db43c9c Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Thu, 22 Jul 2021 21:19:35 +0200 Subject: [PATCH] Filter out non-image files from the launcher collection (closes #1693) --- .../ext/launcher/src/launcherwindow.cpp | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/apps/OpenSpace/ext/launcher/src/launcherwindow.cpp b/apps/OpenSpace/ext/launcher/src/launcherwindow.cpp index a7ebe492c3..460313f531 100644 --- a/apps/OpenSpace/ext/launcher/src/launcherwindow.cpp +++ b/apps/OpenSpace/ext/launcher/src/launcherwindow.cpp @@ -312,8 +312,24 @@ void LauncherWindow::setBackgroundImage(const std::string& syncPath) { std::mt19937 g(rd()); std::shuffle(files.begin(), files.end(), g); // We know there has to be at least one folder, so it's fine to just pick the first - std::string image = files.front(); - _backgroundImage->setPixmap(QPixmap(QString::fromStdString(image))); + while (!files.empty()) { + std::string p = files.front(); + if (std::filesystem::path(p).extension() == ".png") { + // If the top path starts with the png extension, we have found our candidate + break; + } + else { + // There shouldn't be any non-png images in here, but you never know. So we + // just remove non-image files here + files.erase(files.begin()); + } + } + + // There better be at least one file left, but just in in case + if (!files.empty()) { + std::string image = files.front(); + _backgroundImage->setPixmap(QPixmap(QString::fromStdString(image))); + } } void LauncherWindow::populateProfilesList(std::string preset) {