From abde0f51b3062c158fb52e9dfff23d21d3be03d1 Mon Sep 17 00:00:00 2001 From: Yohann Ferreira Date: Sun, 11 Jul 2010 20:05:44 +0200 Subject: Made the different hard-coded paths and files be now taken from the data/paths.xml configuration file. Also added default gui theme path in branding and default wallpaper path and file searched respectively in the branding and paths.xml files. Hard-coded values are still used as fallbacks. Resolves: Manasource Mantis #148. Reviewed-by: jaxad0127. --- src/resources/wallpaper.cpp | 46 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 7 deletions(-) (limited to 'src/resources/wallpaper.cpp') diff --git a/src/resources/wallpaper.cpp b/src/resources/wallpaper.cpp index f57f429d..22bbda9c 100644 --- a/src/resources/wallpaper.cpp +++ b/src/resources/wallpaper.cpp @@ -21,9 +21,11 @@ #include "resources/wallpaper.h" +#include "resources/resourcemanager.h" #include "log.h" #include "utils/stringutils.h" +#include "configuration.h" #include @@ -32,9 +34,6 @@ #include #include -#define WALLPAPER_FOLDER "graphics/images/" -#define WALLPAPER_BASE "login_wallpaper.png" - struct WallpaperData { std::string filename; @@ -45,6 +44,37 @@ struct WallpaperData static std::vector wallpaperData; static bool haveBackup; // Is the backup (no size given) version available? +static std::string wallpaperPath; +static std::string wallpaperFile; + +// Search for the wallpaper path values sequentially.. +static void initDefaultWallpaperPaths() +{ + ResourceManager *resman = ResourceManager::getInstance(); + + // Init the path + wallpaperPath = branding.getValue("wallpapersPath", ""); + + if (!wallpaperPath.empty() && resman->isDirectory(wallpaperPath)) + return; + else + wallpaperPath = paths.getValue("wallpapers", ""); + + if (wallpaperPath.empty() || !resman->isDirectory(wallpaperPath)) + wallpaperPath = "graphics/images/"; + + // Init the default file + wallpaperFile = branding.getValue("wallpaperFile", ""); + + if (!wallpaperFile.empty() && resman->isDirectory(wallpaperFile)) + return; + else + wallpaperFile = paths.getValue("wallpaperFile", ""); + + if (wallpaperFile.empty() || !resman->isDirectory(wallpaperFile)) + wallpaperFile = "login_wallpaper.png"; +} + bool wallpaperCompare(WallpaperData a, WallpaperData b) { int aa = a.width * a.height; @@ -57,7 +87,9 @@ void Wallpaper::loadWallpapers() { wallpaperData.clear(); - char **imgs = PHYSFS_enumerateFiles(WALLPAPER_FOLDER); + initDefaultWallpaperPaths(); + + char **imgs = PHYSFS_enumerateFiles(wallpaperPath.c_str()); for (char **i = imgs; *i != NULL; i++) { @@ -65,7 +97,7 @@ void Wallpaper::loadWallpapers() int height; // If the backup file is found, we tell it. - if (strncmp (*i, WALLPAPER_BASE, strlen(*i)) == 0) + if (strncmp (*i, wallpaperFile.c_str(), strlen(*i)) == 0) haveBackup = true; // If the image format is terminated by: "_x.png" @@ -86,7 +118,7 @@ void Wallpaper::loadWallpapers() if (sscanf(*i, filename.c_str(), &width, &height) == 2) { WallpaperData wp; - wp.filename = WALLPAPER_FOLDER; + wp.filename = wallpaperPath; wp.filename.append(*i); wp.width = width; wp.height = height; @@ -132,7 +164,7 @@ std::string Wallpaper::getWallpaper(int width, int height) // Return the backup file if everything else failed... if (haveBackup) - return std::string(WALLPAPER_FOLDER WALLPAPER_BASE); + return std::string(wallpaperPath + wallpaperFile); // Return an empty string if everything else failed return std::string(); -- cgit v1.2.3-70-g09d2