CFrameBuffer: outsource code for icon path detecting

Unified handling and makes it possible to use in other objects.
This commit is contained in:
2016-03-17 10:25:26 +01:00
parent 95885c4f6e
commit 97343d1190
2 changed files with 15 additions and 8 deletions

View File

@@ -1013,6 +1013,18 @@ void CFrameBuffer::setIconBasePath(const std::string & iconPath)
iconBasePath = iconPath; iconBasePath = iconPath;
} }
std::string CFrameBuffer::getIconPath(std::string icon_name, std::string file_type)
{
std::string path, filetype;
filetype = "." + file_type;
path = std::string(ICONSDIR_VAR) + "/" + icon_name + filetype;
if (access(path.c_str(), F_OK))
path = iconBasePath + "/" + icon_name + filetype;
if (icon_name.find("/", 0) != std::string::npos)
path = icon_name;
return path;
}
void CFrameBuffer::getIconSize(const char * const filename, int* width, int *height) void CFrameBuffer::getIconSize(const char * const filename, int* width, int *height)
{ {
*width = 0; *width = 0;
@@ -1110,11 +1122,7 @@ bool CFrameBuffer::paintIcon(const std::string & filename, const int x, const in
/* we cache and check original name */ /* we cache and check original name */
it = icon_cache.find(filename); it = icon_cache.find(filename);
if(it == icon_cache.end()) { if(it == icon_cache.end()) {
std::string newname = std::string(ICONSDIR_VAR) + "/" + filename + ".png"; std::string newname = getIconPath(filename);
if (access(newname.c_str(), F_OK))
newname = iconBasePath + "/" + filename + ".png";
if (filename.find("/", 0) != std::string::npos)
newname = filename;
//printf("CFrameBuffer::paintIcon: check for %s\n", newname.c_str());fflush(stdout); //printf("CFrameBuffer::paintIcon: check for %s\n", newname.c_str());fflush(stdout);
data = g_PicViewer->getIcon(newname, &width, &height); data = g_PicViewer->getIcon(newname, &width, &height);
@@ -1133,9 +1141,7 @@ bool CFrameBuffer::paintIcon(const std::string & filename, const int x, const in
goto _display; goto _display;
} }
newname = std::string(ICONSDIR_VAR) + "/" + filename + ".raw"; newname = getIconPath(filename, "raw");
if (access(newname.c_str(), F_OK))
newname = iconBasePath + "/" + filename + ".raw";
int lfd = open(newname.c_str(), O_RDONLY); int lfd = open(newname.c_str(), O_RDONLY);

View File

@@ -226,6 +226,7 @@ class CFrameBuffer : public sigc::trackable
void setIconBasePath(const std::string & iconPath); void setIconBasePath(const std::string & iconPath);
std::string getIconBasePath(){return iconBasePath;}; std::string getIconBasePath(){return iconBasePath;};
std::string getIconPath(std::string icon_name, std::string file_type = "png");
void getIconSize(const char * const filename, int* width, int *height); void getIconSize(const char * const filename, int* width, int *height);
/* h is the height of the target "window", if != 0 the icon gets centered in that window */ /* h is the height of the target "window", if != 0 the icon gets centered in that window */