Private naughty.getIcon() -> public awful.util.geticonpath()

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Majic 2011-11-01 18:42:37 -07:00 committed by Uli Schlachter
parent bb3fc70fb3
commit 3636b884d3
2 changed files with 19 additions and 15 deletions

View File

@ -174,6 +174,24 @@ function getdir(d)
end
end
--- Search for an icon and return the full path.
-- It searches for the icon path under the directories given w/the right ext
-- @param iconname The name of the icon to search for.
-- @param exts Table of image extensions allowed, otherwise { 'png', gif' }
-- @param dirs Table of dirs to search, otherwise { '/usr/share/pixmaps/' }
function geticonpath(iconname, exts, dirs)
exts = exts or { 'png', 'gif' }
dirs = dirs or { '/usr/share/pixmaps/' }
for _, d in pairs(dirs) do
for _, e in pairs(exts) do
local icon = d .. iconname .. '.' .. e
if file_readable(icon) then
return icon
end
end
end
end
--- Check if file exists and is readable.
-- @param filename The file path
-- @return True if file exists and readable.

View File

@ -243,20 +243,6 @@ local function getById(id)
end
end
-- Search for an icon in specified directories with a specified format
-- @param icon Name of the icon
-- @return full path of the icon, or nil of no icon was found
local function getIcon(name)
for d, dir in pairs(config.icon_dirs) do
for f, format in pairs(config.icon_formats) do
local icon = dir .. name .. "." .. format
if util.file_readable(icon) then
return icon
end
end
end
end
--- Create notification. args is a dictionary of (optional) arguments.
-- @param text Text of the notification. Default: ''
-- @param title Title of the notification. Default: nil
@ -397,7 +383,7 @@ function notify(args)
if icon then
-- try to guess icon if the provided one is non-existent/readable
if type(icon) == "string" and not util.file_readable(icon) then
icon = getIcon(icon)
icon = util.geticonpath(icon, config.icon_formats, config.icon_dirs)
end
-- if we have an icon, use it