From 3f48c41090de4fd222bc8feb1556e9e4cd0c872d Mon Sep 17 00:00:00 2001 From: Stefan Seyfried Date: Sat, 22 Oct 2016 11:46:34 +0200 Subject: [PATCH] framebuffer_ng: implement getIconPath this implements upstream commit 97343d11 in framebuffer_ng --- src/driver/framebuffer_ng.cpp | 24 ++++++++++++++---------- src/driver/framebuffer_ng.h | 1 + 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/driver/framebuffer_ng.cpp b/src/driver/framebuffer_ng.cpp index 946f79aa4..283f6066c 100644 --- a/src/driver/framebuffer_ng.cpp +++ b/src/driver/framebuffer_ng.cpp @@ -719,6 +719,18 @@ void CFrameBuffer::setIconBasePath(const std::string & iconPath) iconBasePath += "/"; } +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) { *width = 0; @@ -816,13 +828,7 @@ bool CFrameBuffer::paintIcon(const std::string & filename, const int x, const in /* we cache and check original name */ it = icon_cache.find(filename); if(it == icon_cache.end()) { - std::string newname = filename; - /* if it is not an absolute path, search in configured paths */ - if (filename.find("/", 0) == std::string::npos) { - newname = ICONSDIR_VAR + filename + ".png"; - if (access(newname.c_str(), F_OK)) - newname = iconBasePath + filename + ".png"; - } + std::string newname = getIconPath(filename); //printf("CFrameBuffer::paintIcon: check for %s\n", newname.c_str());fflush(stdout); data = g_PicViewer->getIcon(newname, &width, &height); @@ -841,9 +847,7 @@ bool CFrameBuffer::paintIcon(const std::string & filename, const int x, const in goto _display; } - newname = ICONSDIR_VAR + filename + ".raw"; - if (access(newname.c_str(), F_OK)) - newname = iconBasePath + filename + ".raw"; + newname = getIconPath(filename, "raw"); lfd = open(newname.c_str(), O_RDONLY); diff --git a/src/driver/framebuffer_ng.h b/src/driver/framebuffer_ng.h index 736db44e9..7599c1f76 100644 --- a/src/driver/framebuffer_ng.h +++ b/src/driver/framebuffer_ng.h @@ -218,6 +218,7 @@ class CFrameBuffer : public sigc::trackable void setIconBasePath(const std::string & iconPath); 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); /* h is the height of the target "window", if != 0 the icon gets centered in that window */