summaryrefslogtreecommitdiff
path: root/src/FbTk
diff options
context:
space:
mode:
authorMark Tiefenbruck <mark@fluxbox.org>2008-10-07 01:16:26 (GMT)
committerMark Tiefenbruck <mark@fluxbox.org>2008-10-07 01:16:26 (GMT)
commitdda95bf106079fdfd12a690de0ce79a88279505f (patch)
treebdf8d56789f56c094e775a32fd3b26e9b36fa64b /src/FbTk
parentc033c201c4254c11804713dc427d22940da05438 (diff)
downloadfluxbox_lack-dda95bf106079fdfd12a690de0ce79a88279505f.zip
fluxbox_lack-dda95bf106079fdfd12a690de0ce79a88279505f.tar.bz2
allow relative path for background images in style files
Diffstat (limited to 'src/FbTk')
-rw-r--r--src/FbTk/Image.cc36
-rw-r--r--src/FbTk/Image.hh2
2 files changed, 21 insertions, 17 deletions
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 @@
21 21
22#include "Image.hh" 22#include "Image.hh"
23#include "StringUtil.hh" 23#include "StringUtil.hh"
24#include "FileUtil.hh"
24 25
25#ifdef HAVE_CONFIG_H 26#ifdef HAVE_CONFIG_H
26#include "config.h" 27#include "config.h"
@@ -94,25 +95,26 @@ PixmapWithMask *Image::load(const string &filename, int screen_num) {
94 if (s_image_map.find(extension) == s_image_map.end()) 95 if (s_image_map.find(extension) == s_image_map.end())
95 return false; 96 return false;
96 97
97 // load file 98 string path = locateFile(filename);
98 PixmapWithMask *pm = s_image_map[extension]->load(filename, screen_num); 99 if (!path.empty())
99 // failed?, try different search paths 100 return s_image_map[extension]->load(path, screen_num);
100 if (pm == 0 && s_search_paths.size()) {
101 // first we need to get basename of current filename
102 string base_filename = StringUtil::basename(filename);
103 string path = "";
104 // append each search path and try to load
105 StringList::iterator it = s_search_paths.begin();
106 StringList::iterator it_end = s_search_paths.end();
107 for (; it != it_end && pm == 0; ++it) {
108 // append search path and try load it
109 path = StringUtil::expandFilename(*it);
110 pm = s_image_map[extension]->load(path + "/" + base_filename, screen_num);
111 }
112 101
113 } 102 return 0;
103}
114 104
115 return pm; 105string Image::locateFile(const string &filename) {
106 string path = StringUtil::expandFilename(filename);
107 if (FileUtil::isRegularFile(path.c_str()))
108 return path;
109 string base = StringUtil::basename(filename);
110 StringList::iterator it = s_search_paths.begin();
111 StringList::iterator it_end = s_search_paths.end();
112 for (; it != it_end; ++it) {
113 path = StringUtil::expandFilename(*it) + "/" + base;
114 if (FileUtil::isRegularFile(path.c_str()))
115 return path;
116 }
117 return "";
116} 118}
117 119
118bool Image::registerType(const string &type, ImageBase &base) { 120bool 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:
55 static void removeSearchPath(const std::string &search_path); 55 static void removeSearchPath(const std::string &search_path);
56 /// adds a path to search images from 56 /// adds a path to search images from
57 static void removeAllSearchPaths(); 57 static void removeAllSearchPaths();
58 /// locates an image in the search path
59 static std::string locateFile(const std::string &filename);
58private: 60private:
59 typedef std::map<std::string, ImageBase *> ImageMap; 61 typedef std::map<std::string, ImageBase *> ImageMap;
60 typedef std::list<std::string> StringList; 62 typedef std::list<std::string> StringList;