rework framebuffer getIconPath

This commit is contained in:
TangoCash
2021-10-28 19:32:23 +02:00
committed by Thilo Graf
parent 7de08f0f31
commit 19f81835fd
2 changed files with 38 additions and 17 deletions

View File

@@ -706,27 +706,48 @@ void CFrameBuffer::setIconBasePath(const std::string & iconPath)
std::string CFrameBuffer::getIconPath(std::string icon_name, std::string file_type) std::string CFrameBuffer::getIconPath(std::string icon_name, std::string file_type)
{ {
std::string path, filetype = ""; // why search when we have an absolut path ?
if (!file_type.empty()) if (icon_name.find("/", 0) != std::string::npos)
filetype = "." + file_type; return icon_name;
std::string dir[] = { THEMESDIR_VAR "/" + g_settings.theme_name + "/icons", std::vector<std::string> filetypes = { ".svg", ".png", ".jpg" };
THEMESDIR "/" + g_settings.theme_name + "/icons", std::string path = icon_name;
ICONSDIR_VAR,
iconBasePath std::string::size_type pos = icon_name.find_last_of(".");
if (pos != std::string::npos && file_type.empty())
if (std::find(filetypes.begin(), filetypes.end(), icon_name.substr(pos)) != filetypes.end())
{
icon_name = path.substr(0,pos);
file_type = path.substr(pos+1);
}
if (!file_type.empty())
{
filetypes.clear();
filetypes.push_back("." + file_type);
}
std::vector<std::string> dir =
{
THEMESDIR_VAR "/" + g_settings.theme_name + "/icons",
THEMESDIR "/" + g_settings.theme_name + "/icons",
ICONSDIR_VAR,
iconBasePath
}; };
for(int i=0; i<4 ; i++){ for(unsigned int t=0; t<filetypes.size(); t++)
path = std::string(dir[i]) + "/" + icon_name + filetype; {
if (access(path.c_str(), F_OK) == 0){ for(unsigned int i=0; i<dir.size(); i++)
return path; {
path = std::string(dir[i]) + "/" + icon_name + filetypes[t];
if (access(path.c_str(), F_OK) == 0)
{
return path;
}
} }
} }
if (icon_name.find("/", 0) != std::string::npos) // nothing found, return empty string
path = icon_name; return "";
return path;
} }
void CFrameBuffer::getIconSize(const char * const filename, int* width, int *height) void CFrameBuffer::getIconSize(const char * const filename, int* width, int *height)
@@ -1572,7 +1593,7 @@ void CFrameBuffer::Clear()
bool CFrameBuffer::showFrame(const std::string & filename, int fallback_mode) bool CFrameBuffer::showFrame(const std::string & filename, int fallback_mode)
{ {
std::string picture = getIconPath(filename, ""); std::string picture = getIconPath(filename);
bool ret = false; bool ret = false;
if (access(picture.c_str(), F_OK) == 0 && !(fallback_mode & SHOW_FRAME_FALLBACK_MODE_IMAGE_UNSCALED)) if (access(picture.c_str(), F_OK) == 0 && !(fallback_mode & SHOW_FRAME_FALLBACK_MODE_IMAGE_UNSCALED))

View File

@@ -233,7 +233,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"); std::string getIconPath(std::string icon_name, std::string file_type = "");
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 */