From dda95bf106079fdfd12a690de0ce79a88279505f Mon Sep 17 00:00:00 2001 From: Mark Tiefenbruck Date: Mon, 6 Oct 2008 18:16:26 -0700 Subject: allow relative path for background images in style files --- ChangeLog | 3 +++ src/FbTk/Image.cc | 36 +++++++++++++++++++----------------- src/FbTk/Image.hh | 2 ++ src/RootTheme.cc | 6 ++++-- 4 files changed, 28 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index ad55595..fe11533 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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 diff --git a/src/FbTk/Image.cc b/src/FbTk/Image.cc index 639bafd..020f9c6 100644 --- a/src/FbTk/Image.cc +++ b/src/FbTk/Image.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; +} - return pm; +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 ""; } bool Image::registerType(const string &type, ImageBase &base) { diff --git a/src/FbTk/Image.hh b/src/FbTk/Image.hh index c27e452..acb5879 100644 --- a/src/FbTk/Image.hh +++ b/src/FbTk/Image.hh @@ -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 ImageMap; typedef std::list StringList; diff --git a/src/RootTheme.cc b/src/RootTheme.cc index a40732e..049eb27 100644 --- a/src/RootTheme.cc +++ b/src/RootTheme.cc @@ -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; -- cgit v0.11.2