summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2012-02-06 23:15:13 +0100
committerThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2012-02-06 23:16:10 +0100
commit762bd357756e35b0a25cc6a66a890dfedb1f6596 (patch)
treeaaeb26a1b3cb527b0f2f860defbce4f74e08059a /src
parent367b2e8b01c42c34c7782c4410db359c2b3ca060 (diff)
downloadMana-762bd357756e35b0a25cc6a66a890dfedb1f6596.tar.gz
Mana-762bd357756e35b0a25cc6a66a890dfedb1f6596.tar.bz2
Mana-762bd357756e35b0a25cc6a66a890dfedb1f6596.tar.xz
Mana-762bd357756e35b0a25cc6a66a890dfedb1f6596.zip
Some cleanups in the initialization of wallpaper paths
The 'paths' configuration in client-data now overrides any configuration in 'branding', so that it will apply after the updates for a certain server have been downloaded. Also, some isDirectory checks have been removed. When the configuration is wrong, it's probably better to see that there is a problem. Reviewed-by: Yohann Ferreira
Diffstat (limited to 'src')
-rw-r--r--src/gui/widgets/desktop.cpp2
-rw-r--r--src/gui/widgets/desktop.h2
-rw-r--r--src/resources/wallpaper.cpp57
3 files changed, 33 insertions, 28 deletions
diff --git a/src/gui/widgets/desktop.cpp b/src/gui/widgets/desktop.cpp
index d0e2a498..bf833898 100644
--- a/src/gui/widgets/desktop.cpp
+++ b/src/gui/widgets/desktop.cpp
@@ -67,7 +67,7 @@ void Desktop::reloadWallpaper()
setBestFittingWallpaper();
}
-void Desktop::widgetResized(const gcn::Event &event)
+void Desktop::widgetResized(const gcn::Event &)
{
setBestFittingWallpaper();
}
diff --git a/src/gui/widgets/desktop.h b/src/gui/widgets/desktop.h
index 593c8ab0..8ecb7e03 100644
--- a/src/gui/widgets/desktop.h
+++ b/src/gui/widgets/desktop.h
@@ -54,7 +54,7 @@ class Desktop : public Container, gcn::WidgetListener
*/
void reloadWallpaper();
- void widgetResized(const gcn::Event &event);
+ void widgetResized(const gcn::Event &);
void draw(gcn::Graphics *graphics);
diff --git a/src/resources/wallpaper.cpp b/src/resources/wallpaper.cpp
index 727ccced..f48f954f 100644
--- a/src/resources/wallpaper.cpp
+++ b/src/resources/wallpaper.cpp
@@ -41,68 +41,73 @@ struct WallpaperData
int height;
};
+inline std::ostream& operator <<(std::ostream &os, const WallpaperData &d)
+{
+ os << d.filename << "[" << d.width << "x" << d.height << "]";
+ return os;
+}
+
static std::vector<WallpaperData> 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()
+static void initWallpaperPaths()
{
- ResourceManager *resman = ResourceManager::getInstance();
-
// Init the path
- wallpaperPath = branding.getStringValue("wallpapersPath");
+ wallpaperPath = paths.getStringValue("wallpapers");
- if (wallpaperPath.empty() || !resman->isDirectory(wallpaperPath))
- wallpaperPath = paths.getStringValue("wallpapers");
+ if (wallpaperPath.empty())
+ {
+ wallpaperPath = branding.getStringValue("wallpapersPath");
- if (wallpaperPath.empty() || !resman->isDirectory(wallpaperPath))
- wallpaperPath = "graphics/images/";
+ if (wallpaperPath.empty())
+ wallpaperPath = "graphics/images/";
+ }
// Init the default file
- wallpaperFile = branding.getStringValue("wallpaperFile");
+ wallpaperFile = paths.getStringValue("wallpaperFile");
- if (!wallpaperFile.empty() && !resman->isDirectory(wallpaperFile))
- return;
- else
- wallpaperFile = paths.getStringValue("wallpaperFile");
+ if (wallpaperFile.empty())
+ {
+ wallpaperFile = branding.getStringValue("wallpaperFile");
- if (wallpaperFile.empty() || resman->isDirectory(wallpaperFile))
- wallpaperFile = "login_wallpaper.png";
+ if (wallpaperFile.empty())
+ wallpaperFile = "login_wallpaper.png";
+ }
}
-bool wallpaperCompare(WallpaperData a, WallpaperData b)
+bool wallpaperCompare(const WallpaperData &a, const WallpaperData &b)
{
int aa = a.width * a.height;
int ab = b.width * b.height;
return (aa > ab || (aa == ab && a.width > b.width));
}
-#include <iostream>
+
void Wallpaper::loadWallpapers()
{
wallpaperData.clear();
- initDefaultWallpaperPaths();
+ initWallpaperPaths();
- char **imgs = PHYSFS_enumerateFiles(wallpaperPath.c_str());
+ char **fileNames = PHYSFS_enumerateFiles(wallpaperPath.c_str());
- for (char **i = imgs; *i != NULL; i++)
+ for (char **fileName = fileNames; *fileName; fileName++)
{
int width;
int height;
// If the backup file is found, we tell it.
- if (strncmp (*i, wallpaperFile.c_str(), strlen(*i)) == 0)
+ if (strncmp(*fileName, wallpaperFile.c_str(), strlen(*fileName)) == 0)
haveBackup = true;
// If the image format is terminated by: "_<width>x<height>.png"
// It is taken as a potential wallpaper.
// First, get the base filename of the image:
- std::string filename = *i;
+ std::string filename = *fileName;
filename = filename.substr(0, filename.rfind("_"));
// Check that the base filename doesn't have any '%' markers.
@@ -111,11 +116,11 @@ void Wallpaper::loadWallpapers()
// Then, append the width and height search mask.
filename.append("_%dx%d.png");
- if (sscanf(*i, filename.c_str(), &width, &height) == 2)
+ if (sscanf(*fileName, filename.c_str(), &width, &height) == 2)
{
WallpaperData wp;
wp.filename = wallpaperPath;
- wp.filename.append(*i);
+ wp.filename.append(*fileName);
wp.width = width;
wp.height = height;
wallpaperData.push_back(wp);
@@ -123,7 +128,7 @@ void Wallpaper::loadWallpapers()
}
}
- PHYSFS_freeList(imgs);
+ PHYSFS_freeList(fileNames);
std::sort(wallpaperData.begin(), wallpaperData.end(), wallpaperCompare);
}