diff options
author | Mark Tiefenbruck <mark@fluxbox.org> | 2008-10-07 01:16:26 (GMT) |
---|---|---|
committer | Mark Tiefenbruck <mark@fluxbox.org> | 2008-10-07 01:16:26 (GMT) |
commit | dda95bf106079fdfd12a690de0ce79a88279505f (patch) | |
tree | bdf8d56789f56c094e775a32fd3b26e9b36fa64b /src/FbTk/Image.cc | |
parent | c033c201c4254c11804713dc427d22940da05438 (diff) | |
download | fluxbox-dda95bf106079fdfd12a690de0ce79a88279505f.zip fluxbox-dda95bf106079fdfd12a690de0ce79a88279505f.tar.bz2 |
allow relative path for background images in style files
Diffstat (limited to 'src/FbTk/Image.cc')
-rw-r--r-- | src/FbTk/Image.cc | 36 |
1 files changed, 19 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; | 105 | string 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 | ||
118 | bool Image::registerType(const string &type, ImageBase &base) { | 120 | bool Image::registerType(const string &type, ImageBase &base) { |