allow relative path for background images in style files
This commit is contained in:
parent
c033c201c4
commit
dda95bf106
4 changed files with 28 additions and 19 deletions
|
@ -1,5 +1,8 @@
|
|||
(Format: Year/Month/Day)
|
||||
Changes for 1.1.2
|
||||
*08/10/07:
|
||||
* Allow relative paths for background images in style files (Mark)
|
||||
RootTheme.cc FbTk/Image.cc/hh
|
||||
*08/10/05:
|
||||
* Remove menu modes (Mark)
|
||||
Screen.cc/hh ScreenResources.cc FbTk/MenuTheme.cc/hh FbTk/Menu.cc
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
#include "Image.hh"
|
||||
#include "StringUtil.hh"
|
||||
#include "FileUtil.hh"
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
|
@ -94,25 +95,26 @@ PixmapWithMask *Image::load(const string &filename, int screen_num) {
|
|||
if (s_image_map.find(extension) == s_image_map.end())
|
||||
return false;
|
||||
|
||||
// load file
|
||||
PixmapWithMask *pm = s_image_map[extension]->load(filename, screen_num);
|
||||
// failed?, try different search paths
|
||||
if (pm == 0 && s_search_paths.size()) {
|
||||
// first we need to get basename of current filename
|
||||
string base_filename = StringUtil::basename(filename);
|
||||
string path = "";
|
||||
// append each search path and try to load
|
||||
StringList::iterator it = s_search_paths.begin();
|
||||
StringList::iterator it_end = s_search_paths.end();
|
||||
for (; it != it_end && pm == 0; ++it) {
|
||||
// append search path and try load it
|
||||
path = StringUtil::expandFilename(*it);
|
||||
pm = s_image_map[extension]->load(path + "/" + base_filename, screen_num);
|
||||
}
|
||||
string path = locateFile(filename);
|
||||
if (!path.empty())
|
||||
return s_image_map[extension]->load(path, screen_num);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
string Image::locateFile(const string &filename) {
|
||||
string path = StringUtil::expandFilename(filename);
|
||||
if (FileUtil::isRegularFile(path.c_str()))
|
||||
return path;
|
||||
string base = StringUtil::basename(filename);
|
||||
StringList::iterator it = s_search_paths.begin();
|
||||
StringList::iterator it_end = s_search_paths.end();
|
||||
for (; it != it_end; ++it) {
|
||||
path = StringUtil::expandFilename(*it) + "/" + base;
|
||||
if (FileUtil::isRegularFile(path.c_str()))
|
||||
return path;
|
||||
}
|
||||
|
||||
return pm;
|
||||
return "";
|
||||
}
|
||||
|
||||
bool Image::registerType(const string &type, ImageBase &base) {
|
||||
|
|
|
@ -55,6 +55,8 @@ public:
|
|||
static void removeSearchPath(const std::string &search_path);
|
||||
/// adds a path to search images from
|
||||
static void removeAllSearchPaths();
|
||||
/// locates an image in the search path
|
||||
static std::string locateFile(const std::string &filename);
|
||||
private:
|
||||
typedef std::map<std::string, ImageBase *> ImageMap;
|
||||
typedef std::list<std::string> StringList;
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
|
||||
#include "FbTk/App.hh"
|
||||
#include "FbTk/Font.hh"
|
||||
#include "FbTk/Image.hh"
|
||||
#include "FbTk/ImageControl.hh"
|
||||
#include "FbTk/Resource.hh"
|
||||
#include "FbTk/FileUtil.hh"
|
||||
|
@ -197,6 +198,7 @@ void RootTheme::reconfigTheme() {
|
|||
// if background argument is a file then
|
||||
// parse image options and call image setting
|
||||
// command specified in the resources
|
||||
std::string img_path = FbTk::Image::locateFile(filename);
|
||||
filename = FbTk::StringUtil::expandFilename(filename);
|
||||
std::string cmd = realProgramName("fbsetbg") + (m_first ? " -z " : " -Z ");
|
||||
|
||||
|
@ -204,7 +206,7 @@ void RootTheme::reconfigTheme() {
|
|||
if (strstr(m_background->options().c_str(), "none") != 0) {
|
||||
if (!m_first)
|
||||
return;
|
||||
} else if (FbTk::FileUtil::isRegularFile(filename.c_str())) {
|
||||
} else if (!img_path.empty()) {
|
||||
// parse options
|
||||
if (strstr(m_background->options().c_str(), "tiled") != 0)
|
||||
cmd += "-t ";
|
||||
|
@ -215,7 +217,7 @@ void RootTheme::reconfigTheme() {
|
|||
else
|
||||
cmd += "-f ";
|
||||
|
||||
cmd += filename;
|
||||
cmd += img_path;
|
||||
} else if (FbTk::FileUtil::isDirectory(filename.c_str()) &&
|
||||
strstr(m_background->options().c_str(), "random") != 0) {
|
||||
cmd += "-r " + filename;
|
||||
|
|
Loading…
Reference in a new issue