Added support for .webp, .svg and unanimated .gif files to the slideshow screensaver when using a custom image directory

Also changed the default slideshow custom image directory from slideshow/custom_images to screensavers/custom_slideshow and improved the menu entry for setting the custom directory. Changed the setting ScreensaverSlideshowImageDir to blank by default
This commit is contained in:
Leon Styhre 2023-12-16 21:03:41 +01:00
parent e851f1205f
commit 9283ab71fa
3 changed files with 61 additions and 22 deletions

View file

@ -464,8 +464,14 @@ void Screensaver::generateVideoList()
void Screensaver::generateCustomImageList()
{
std::string imageDir = Utils::FileSystem::expandHomePath(
Settings::getInstance()->getString("ScreensaverSlideshowImageDir"));
std::string imageDir {Utils::FileSystem::expandHomePath(
Settings::getInstance()->getString("ScreensaverSlideshowImageDir"))};
if (imageDir.empty())
imageDir = Utils::FileSystem::getAppDataDirectory()
.append("screensavers")
.append("custom_slideshow")
.string();
// This makes it possible to set the custom image directory relative to the ES-DE binary
// directory or the ROM directory.
@ -473,19 +479,23 @@ void Screensaver::generateCustomImageList()
imageDir = Utils::String::replace(imageDir, "%ROMPATH%", FileData::getROMDirectory());
if (imageDir != "" && Utils::FileSystem::isDirectory(imageDir)) {
std::string imageFilter {".jpg, .JPG, .png, .PNG"};
Utils::FileSystem::StringList dirContent = Utils::FileSystem::getDirContent(
imageDir, Settings::getInstance()->getBool("ScreensaverSlideshowRecurse"));
const std::vector<std::string> extList {".jpg", ".JPG", ".png", ".PNG", ".gif",
".GIF", ".webp", ".WEBP", ".svg", ".SVG"};
Utils::FileSystem::StringList dirContent {Utils::FileSystem::getDirContent(
imageDir, Settings::getInstance()->getBool("ScreensaverSlideshowRecurse"))};
for (auto it = dirContent.begin(); it != dirContent.end(); ++it) {
if (Utils::FileSystem::isRegularFile(*it)) {
if (imageFilter.find(Utils::FileSystem::getExtension(*it)) != std::string::npos)
if (std::find(extList.cbegin(), extList.cend(),
Utils::FileSystem::getExtension(*it)) != extList.cend())
mImageCustomFiles.push_back(*it);
}
}
}
else {
LOG(LogWarning) << "Custom screensaver image directory '" << imageDir << "' does not exist";
LOG(LogWarning) << "Custom screensaver image directory \"" << imageDir
<< "\" does not exist";
}
mCustomFilesInventory.insert(mCustomFilesInventory.begin(), mImageCustomFiles.begin(),

View file

@ -15,6 +15,8 @@
#include "components/SliderComponent.h"
#include "components/SwitchComponent.h"
#include "guis/GuiMsgBox.h"
#include "guis/GuiTextEditKeyboardPopup.h"
#include "guis/GuiTextEditPopup.h"
GuiScreensaverOptions::GuiScreensaverOptions(const std::string& title)
: GuiSettings {title}
@ -196,20 +198,48 @@ void GuiScreensaverOptions::openSlideshowScreensaverOptions()
});
// Custom image directory.
ComponentListRow rowCustomImageDir;
auto screensaverSlideshowImageDir = std::make_shared<TextComponent>(
"", Font::get(FONT_SIZE_SMALL), mMenuColorPrimary, ALIGN_RIGHT);
s->addEditableTextComponent(
"CUSTOM IMAGE DIRECTORY", screensaverSlideshowImageDir,
Settings::getInstance()->getString("ScreensaverSlideshowImageDir"),
Settings::getInstance()->getDefaultString("ScreensaverSlideshowImageDir"));
s->addSaveFunc([screensaverSlideshowImageDir, s] {
if (screensaverSlideshowImageDir->getValue() !=
Settings::getInstance()->getString("ScreensaverSlideshowImageDir")) {
Settings::getInstance()->setString("ScreensaverSlideshowImageDir",
screensaverSlideshowImageDir->getValue());
s->setNeedsSaving();
}
});
"CUSTOM IMAGE DIRECTORY", Font::get(FONT_SIZE_MEDIUM), mMenuColorPrimary);
auto bracketCustomImageDir = std::make_shared<ImageComponent>();
bracketCustomImageDir->setResize(
glm::vec2 {0.0f, Font::get(FONT_SIZE_MEDIUM)->getLetterHeight()});
bracketCustomImageDir->setImage(":/graphics/arrow.svg");
bracketCustomImageDir->setColorShift(mMenuColorPrimary);
rowCustomImageDir.addElement(screensaverSlideshowImageDir, true);
rowCustomImageDir.addElement(bracketCustomImageDir, false);
const std::string titleCustomImageDir {"CUSTOM IMAGE DIRECTORY"};
const std::string defaultImageDirStaticText {"Default directory:"};
const std::string defaultImageDirText {Utils::FileSystem::getAppDataDirectory()
.append("screensavers")
.append("custom_slideshow")
.string()};
const std::string initValueMediaDir {
Settings::getInstance()->getString("ScreensaverSlideshowImageDir")};
const bool multiLineMediaDir {false};
auto updateValMediaDir = [this, s](const std::string& newVal) {
Settings::getInstance()->setString("ScreensaverSlideshowImageDir", newVal);
s->setNeedsSaving();
};
rowCustomImageDir.makeAcceptInputHandler(
[this, s, titleCustomImageDir, defaultImageDirStaticText, defaultImageDirText,
initValueMediaDir, updateValMediaDir, multiLineMediaDir] {
if (Settings::getInstance()->getBool("VirtualKeyboard")) {
mWindow->pushGui(new GuiTextEditKeyboardPopup(
getHelpStyle(), s->getMenu().getPosition().y, titleCustomImageDir,
Settings::getInstance()->getString("ScreensaverSlideshowImageDir"),
updateValMediaDir, multiLineMediaDir, "SAVE", "SAVE CHANGES?",
defaultImageDirStaticText, defaultImageDirText, "load default directory"));
}
else {
mWindow->pushGui(new GuiTextEditPopup(
getHelpStyle(), titleCustomImageDir,
Settings::getInstance()->getString("ScreensaverSlideshowImageDir"),
updateValMediaDir, multiLineMediaDir, "SAVE", "SAVE CHANGES?",
defaultImageDirStaticText, defaultImageDirText, "load default directory"));
}
});
s->addRow(rowCustomImageDir);
s->setSize(mSize);
mWindow->pushGui(s);

View file

@ -202,8 +202,7 @@ void Settings::setDefaults()
mBoolMap["ScreensaverSlideshowScanlines"] = {false, false};
mBoolMap["ScreensaverSlideshowCustomImages"] = {false, false};
mBoolMap["ScreensaverSlideshowRecurse"] = {false, false};
mStringMap["ScreensaverSlideshowImageDir"] = {"~/.emulationstation/slideshow/custom_images",
"~/.emulationstation/slideshow/custom_images"};
mStringMap["ScreensaverSlideshowImageDir"] = {"", ""};
// UI settings -> screensaver settings -> video screensaver settings.
mIntMap["ScreensaverSwapVideoTimeout"] = {0, 0};