findLargestIcon

Find icon of the largest size. It uses icon theme cache wherever possible.

  1. string findLargestIcon(string iconName, IconThemes iconThemes, BaseDirs searchIconDirs, Exts extensions, Flag!"allowFallbackIcon" allowFallback)
    string
    findLargestIcon
    (
    alias subdirFilter = (a => true)
    IconThemes
    BaseDirs
    Exts
    )
    (
    string iconName
    ,
    IconThemes iconThemes
    ,,,
    Flag!"allowFallbackIcon" allowFallback = Yes.allowFallbackIcon
    )
  2. string findLargestIcon(string iconName, IconThemes iconThemes, BaseDirs searchIconDirs)

Parameters

iconName string

Name of icon to search as defined by Icon Theme Specification (i.e. without path and extension parts).

iconThemes IconThemes
searchIconDirs BaseDirs

Base icon directories.

extensions Exts

Allowed file extensions.

allowFallback Flag!"allowFallbackIcon"

Allow searching for non-themed fallback if could not find icon in themes.

Return Value

Type: string

Icon file path or empty string if not found. Note: If icon of some size was found in the icon theme, this algorithm does not check following themes, even if they contain icons with larger size. Therefore the icon found in the most preferred theme always has presedence over icons from other themes.

Examples

auto baseDirs = ["test"];
auto iconThemes = [openIconTheme("Tango", baseDirs), openIconTheme("hicolor", baseDirs)];

string found;

found = findLargestIcon("folder", iconThemes, baseDirs);
assert(found == buildPath("test", "Tango", "128x128/places", "folder.png"));

found = findLargestIcon("desktop", iconThemes, baseDirs);
assert(found == buildPath("test", "Tango", "32x32/places", "desktop.png"));

found = findLargestIcon("desktop", iconThemes, baseDirs, [".svg", ".png"]);
assert(found == buildPath("test", "Tango", "scalable/places", "desktop.svg"));

//lookup with fallback
found = findLargestIcon("pidgin", iconThemes, baseDirs);
assert(found == buildPath("test", "pidgin.png"));

//lookup without fallback
found = findLargestIcon("pidgin", iconThemes, baseDirs, defaultIconExtensions, No.allowFallbackIcon);
assert(found.empty);

See Also

icontheme.paths.baseIconDirs, lookupIcon, findFallbackIcon

Meta