Class IconThemeFile

Class representation of index.theme file containing an icon theme description.

class IconThemeFile
  : IniLikeFile ;

Constructors

NameDescription
this Reads icon theme from file.
this Reads icon theme file from range of IniLikeReader, e.g. acquired from iniLikeFileReader or iniLikeStringReader.
this Constructs IconThemeFile with empty "Icon Theme" group.

Methods

NameDescription
bySubdir Iterating over subdirectories of icon theme.
cache Set cache object.
cache The object of loaded cache.
cachePath Path of icon theme cache file.
iconTheme Icon Theme group in underlying file.
internalName The name of the subdirectory index.theme was loaded from.
joinValues Join range of multiple values into a string using comma as separator. If range is empty, then the empty string is returned.
removeGroup Removes group by name. This function will not remove "Icon Theme" group.
splitValues Some keys can have multiple values, separated by comma. This function helps to parse such kind of strings into the range.
tryLoadCache Try to load icon cache. Loaded icon cache will be used on icon lookup.
unloadCache Unset loaded cache.
addGenericGroup Create new group using groupName.
appendLeadingComment Add leading comment. This will be appended to the list of leadingComments.
byGroup Range of groups in order how they were defined in file.
byNode Iterate over GroupNodes.
clearLeadingComments Remove all coments met before groups.
escapedValue Shortcut to IniLikeGroup.escapedValue of given group. Returns null if the group does not exist.
escapedValue ditto, localized version
fileName File path where the object was loaded from.
getNode Get GroupNode by groupName.
group Get group by name.
leadingComments Leading comments.
moveGroupAfter Move group after other.
moveGroupBefore Move group before other.
moveGroupToBack Move the group to make it the last.
moveGroupToFront Move the group to make it the first.
prependLeadingComment Prepend leading comment (e.g. for setting shebang line).
save Use Output range or delegate to retrieve strings line by line. Those strings can be written to the file or be showed in text area.
saveToFile Save object to the file using .ini-like format.
saveToString Save object to string using .ini like format.
unescapedValue Shortcut to IniLikeGroup.unescapedValue of given group. Returns null if the group does not exist.
createEmptyGroup Can be used in derived classes to create instance of IniLikeGroup.
createGroupByName Reimplement in derive class.
insertGroup Insert group into IniLikeFile object and use its name as key.
onCommentInGroup Add comment for group. This function is called only in constructor and can be reimplemented in derived classes.
onGroup Create IniLikeGroup by groupName during file parsing.
onKeyValue Add key/value pair for group. This function is called only in constructor and can be reimplemented in derived classes.
onLeadingComment Add comment before groups. This function is called only in constructor and can be reimplemented in derived classes.
putGroup Append group to group list without associating group name with it. Can be used to add groups with duplicated names.

Inner structs

NameDescription
IconThemeReadOptions Options to manage icon theme file reading
GroupNode Wrapper for internal ListMap node.
ReadOptions Behavior of ini-like file reading.
WriteOptions Behavior of ini-like file saving.

Enums

NameDescription
ExtensionGroupPolicy Policy about reading extension groups (those start with 'X-').
UnknownGroupPolicy Policy about reading groups with names which meaning is unknown, i.e. it's not extension nor relative directory path.
DuplicateGroupPolicy Behavior on group with duplicate name in the file.
DuplicateKeyPolicy Behavior on duplicate key in the group.

Example

string contents =
`# First comment
[Icon Theme]
Name=Hicolor
Name[ru]=Стандартная тема
Comment=Fallback icon theme
Comment[ru]=Резервная тема
Hidden=true
Directories=16x16/actions,32x32/animations,scalable/emblems
Example=folder
Inherits=gnome,hicolor

[16x16/actions]
Size=16
Context=Actions
Type=Threshold

[32x32/animations]
Size=32
Context=Animations
Type=Fixed

[scalable/emblems]
Context=Emblems
Size=64
MinSize=8
MaxSize=512
Type=Scalable

# Will be saved.
[X-NoName]
Key=Value`;

string path = buildPath(".", "test", "Tango", "index.theme");

auto iconTheme = new IconThemeFile(iniLikeStringReader(contents), path);
assert(equal(iconTheme.leadingComments(), ["# First comment"]));
assert(iconTheme.displayName() == "Hicolor");
assert(iconTheme.localizedDisplayName("ru") == "Стандартная тема");
assert(iconTheme.comment() == "Fallback icon theme");
assert(iconTheme.localizedComment("ru") == "Резервная тема");
assert(iconTheme.hidden());
assert(equal(iconTheme.directories(), ["16x16/actions", "32x32/animations", "scalable/emblems"]));
assert(equal(iconTheme.inherits(), ["gnome", "hicolor"]));
assert(iconTheme.internalName() == "Tango");
assert(iconTheme.example() == "folder");
assert(iconTheme.group("X-NoName") !is null);

iconTheme.removeGroup("Icon Theme");
assert(iconTheme.group("Icon Theme") !is null);

assert(iconTheme.cachePath() == buildPath(".", "test", "Tango", "icon-theme.cache"));

assert(equal(iconTheme.bySubdir().map!(subdir => tuple(subdir.name(), subdir.size(), subdir.minSize(), subdir.maxSize(), subdir.context(), subdir.type() )),
             [tuple("16x16/actions", 16, 16, 16, "Actions", IconSubDir.Type.Threshold),
             tuple("32x32/animations", 32, 32, 32, "Animations", IconSubDir.Type.Fixed),
             tuple("scalable/emblems", 64, 8, 512, "Emblems", IconSubDir.Type.Scalable)]));

version(iconthemeFileTest)
{
    string cachePath = iconTheme.cachePath();
    assert(cachePath.exists);

    auto cache = new IconThemeCache(cachePath);

    assert(iconTheme.cache is null);
    iconTheme.cache = cache;
    assert(iconTheme.cache is cache);
    iconTheme.unloadCache();
    assert(iconTheme.cache is null);

    assert(iconTheme.tryLoadCache(Flag!"allowOutdated".yes));
}

iconTheme.removeGroup("scalable/emblems");
assert(iconTheme.group("scalable/emblems") is null);

auto itf = new IconThemeFile();
itf.displayName = "Oxygen";
itf.comment = "Oxygen theme";
itf.hidden = true;
itf.directories = ["actions", "places"];
itf.inherits = ["locolor", "hicolor"];
assert(itf.displayName() == "Oxygen");
assert(itf.comment() == "Oxygen theme");
assert(itf.hidden());
assert(equal(itf.directories(), ["actions", "places"]));
assert(equal(itf.inherits(), ["locolor", "hicolor"]));