findLargestIcon

Find icon of the largest size. It uses icon theme cache wherever possible. This is similar to findLargestThemedIcon, but returns file path only and allows to search for non-themed icons.

  1. string findLargestIcon(string iconName, IconThemes iconThemes, BaseDirs searchIconDirs, Exts extensions, Flag!"allowNonThemed" allowNonThemed)
    string
    findLargestIcon
    (
    alias subdirFilter = (a => true)
    IconThemes
    BaseDirs
    Exts
    )
    (
    string iconName
    ,
    IconThemes iconThemes
    ,,,
    Flag!"allowNonThemed" allowNonThemed = Yes.allowNonThemed
    )
  2. string findLargestIcon(string iconName, IconThemes iconThemes, BaseDirs searchIconDirs, Exts extensions, Flag!"allowFallbackIcon" allowFallback)
  3. 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.

allowNonThemed Flag!"allowNonThemed"

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!(subdir => subdir.context == "Places")("folder", iconThemes, baseDirs);
assert(found == buildPath("test", "Tango", "128x128/places", "folder.png"));

found = findLargestIcon!(subdir => subdir.context == "Actions")("folder", iconThemes, baseDirs);
assert(found.empty);

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 non-themed
found = findLargestIcon("pidgin", iconThemes, baseDirs);
assert(found == buildPath("test", "pidgin.png"));

//don't lookup non-themed
found = findLargestIcon("pidgin", iconThemes, baseDirs, defaultIconExtensions, No.allowNonThemed);
assert(found.empty);

See Also

findLargestThemedIcon, icontheme.paths.baseIconDirs, lookupIcon, findNonThemedIcon

Meta