aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/FbTk/Image.cc36
-rw-r--r--src/FbTk/Image.hh2
-rw-r--r--src/RootTheme.cc6
3 files changed, 25 insertions, 19 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;
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 @@
28 28
29#include "FbTk/App.hh" 29#include "FbTk/App.hh"
30#include "FbTk/Font.hh" 30#include "FbTk/Font.hh"
31#include "FbTk/Image.hh"
31#include "FbTk/ImageControl.hh" 32#include "FbTk/ImageControl.hh"
32#include "FbTk/Resource.hh" 33#include "FbTk/Resource.hh"
33#include "FbTk/FileUtil.hh" 34#include "FbTk/FileUtil.hh"
@@ -197,6 +198,7 @@ void RootTheme::reconfigTheme() {
197 // if background argument is a file then 198 // if background argument is a file then
198 // parse image options and call image setting 199 // parse image options and call image setting
199 // command specified in the resources 200 // command specified in the resources
201 std::string img_path = FbTk::Image::locateFile(filename);
200 filename = FbTk::StringUtil::expandFilename(filename); 202 filename = FbTk::StringUtil::expandFilename(filename);
201 std::string cmd = realProgramName("fbsetbg") + (m_first ? " -z " : " -Z "); 203 std::string cmd = realProgramName("fbsetbg") + (m_first ? " -z " : " -Z ");
202 204
@@ -204,7 +206,7 @@ void RootTheme::reconfigTheme() {
204 if (strstr(m_background->options().c_str(), "none") != 0) { 206 if (strstr(m_background->options().c_str(), "none") != 0) {
205 if (!m_first) 207 if (!m_first)
206 return; 208 return;
207 } else if (FbTk::FileUtil::isRegularFile(filename.c_str())) { 209 } else if (!img_path.empty()) {
208 // parse options 210 // parse options
209 if (strstr(m_background->options().c_str(), "tiled") != 0) 211 if (strstr(m_background->options().c_str(), "tiled") != 0)
210 cmd += "-t "; 212 cmd += "-t ";
@@ -215,7 +217,7 @@ void RootTheme::reconfigTheme() {
215 else 217 else
216 cmd += "-f "; 218 cmd += "-f ";
217 219
218 cmd += filename; 220 cmd += img_path;
219 } else if (FbTk::FileUtil::isDirectory(filename.c_str()) && 221 } else if (FbTk::FileUtil::isDirectory(filename.c_str()) &&
220 strstr(m_background->options().c_str(), "random") != 0) { 222 strstr(m_background->options().c_str(), "random") != 0) {
221 cmd += "-r " + filename; 223 cmd += "-r " + filename;