IconThemeFile

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

Constructors

this
this(string fileName, IconThemeReadOptions options)

Reads icon theme from file.

this
this(IniLikeReader reader, IconThemeReadOptions options, string fileName)
this(IniLikeReader reader, string fileName, IconThemeReadOptions options)

Reads icon theme file from range of IniLikeReader, e.g. acquired from iniLikeFileReader or iniLikeStringReader.

this
this()

Constructs IconThemeFile with empty "Icon Theme" group.

Alias This

iconTheme

This alias allows to call functions related to "Icon Theme" group without need to call iconTheme explicitly.

Members

Enums

ExtensionGroupPolicy
enum ExtensionGroupPolicy

Policy about reading extension groups (those start with 'X-').

UnknownGroupPolicy
enum UnknownGroupPolicy

Policy about reading groups with names which meaning is unknown, i.e. it's not extension nor relative directory path.

Functions

bySubdir
auto bySubdir()

Iterating over subdirectories of icon theme.

cache
IconThemeCache cache(IconThemeCache setCache)

Set cache object.

cache
inout(IconThemeCache) cache()

The object of loaded cache.

cachePath
string cachePath()

Path of icon theme cache file.

createGroupByName
IniLikeGroup createGroupByName(string groupName)
Undocumented in source. Be warned that the author may not have intended to support it.
iconTheme
inout(IconThemeGroup) iconTheme()

Icon Theme group in underlying file.

internalName
string internalName()

The name of the subdirectory index.theme was loaded from.

removeGroup
bool removeGroup(string groupName)

Removes group by name. This function will not remove "Icon Theme" group.

tryLoadCache
auto tryLoadCache(Flag!"allowOutdated" allowOutdated)

Try to load icon cache. Loaded icon cache will be used on icon lookup.

unloadCache
void unloadCache()

Unset loaded cache.

Static functions

isDirectoryName
bool isDirectoryName(string groupName)
Undocumented in source. Be warned that the author may not have intended to support it.
joinValues
string joinValues(Range values)

Join range of multiple values into a string using comma as separator. If range is empty, then the empty string is returned.

splitValues
auto splitValues(string values)

Some keys can have multiple values, separated by comma. This function helps to parse such kind of strings into the range.

Structs

IconThemeReadOptions
struct IconThemeReadOptions

Options to manage icon theme file reading

Inherited Members

From IniLikeFile

DuplicateKeyPolicy
enum DuplicateKeyPolicy

Behavior on duplicate key in the group.

DuplicateGroupPolicy
enum DuplicateGroupPolicy

Behavior on group with duplicate name in the file.

ReadOptions
struct ReadOptions

Behavior of ini-like file reading.

WriteOptions
struct WriteOptions

Behavior of ini-like file saving.

GroupNode
struct GroupNode

Wrapper for internal ListMap node.

insertGroup
auto insertGroup(IniLikeGroup group)

Insert group into IniLikeFile object and use its name as key. Prerequisites: group must be non-null. It also should not be held by some other IniLikeFile object.

putGroup
auto putGroup(IniLikeGroup group)

Append group to group list without associating group name with it. Can be used to add groups with duplicated names. Prerequisites: group must be non-null. It also should not be held by some other IniLikeFile object.

onLeadingComment
void onLeadingComment(string comment)

Add comment before groups. This function is called only in constructor and can be reimplemented in derived classes.

onCommentInGroup
void onCommentInGroup(string comment, IniLikeGroup currentGroup, string groupName)

Add comment for group. This function is called only in constructor and can be reimplemented in derived classes.

onKeyValue
void onKeyValue(string key, string value, IniLikeGroup currentGroup, string groupName)

Add key/value pair for group. This function is called only in constructor and can be reimplemented in derived classes.

onGroup
IniLikeGroup onGroup(string groupName)

Create IniLikeGroup by groupName during file parsing.

createGroupByName
IniLikeGroup createGroupByName(string groupName)

Reimplement in derive class.

createEmptyGroup
createEmptyGroup(string groupName)

Can be used in derived classes to create instance of IniLikeGroup.

group
inout(IniLikeGroup) group(string groupName)

Get group by name.

getNode
auto getNode(string groupName)

Get GroupNode by groupName.

addGenericGroup
IniLikeGroup addGenericGroup(string groupName)

Create new group using groupName.

removeGroup
bool removeGroup(string groupName)

Remove group by name. Do nothing if group with such name does not exist.

byGroup
auto byGroup()

Range of groups in order how they were defined in file.

byNode
auto byNode()

Iterate over GroupNodes.

saveToFile
void saveToFile(string fileName, WriteOptions options)

Save object to the file using .ini-like format.

saveToString
string saveToString(WriteOptions options)

Save object to string using .ini like format.

save
void save(OutRange sink, WriteOptions options)

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. Note: Output strings don't have trailing newline character.

fileName
string fileName()

File path where the object was loaded from.

leadingComments
auto leadingComments()

Leading comments.

appendLeadingComment
string appendLeadingComment(string line)

Add leading comment. This will be appended to the list of leadingComments. Note: # will be prepended automatically if line is not empty and does not have # at the start. The last new line character will be removed if present. Others will be replaced with whitespaces.

prependLeadingComment
string prependLeadingComment(string line)

Prepend leading comment (e.g. for setting shebang line).

clearLeadingComments
void clearLeadingComments()

Remove all coments met before groups.

moveGroupToFront
void moveGroupToFront(GroupNode toMove)

Move the group to make it the first.

moveGroupToBack
void moveGroupToBack(GroupNode toMove)

Move the group to make it the last.

moveGroupBefore
void moveGroupBefore(GroupNode other, GroupNode toMove)

Move group before other.

moveGroupAfter
void moveGroupAfter(GroupNode other, GroupNode toMove)

Move group after other.

readOptions
ReadOptions readOptions()
Undocumented in source. Be warned that the author may not have intended to support it.

Examples

1     string contents =
2 `# First comment
3 [Icon Theme]
4 Name=Hicolor
5 Name[ru]=Стандартная тема
6 Comment=Fallback icon theme
7 Comment[ru]=Резервная тема
8 Hidden=true
9 Directories=16x16/actions,32x32/animations,scalable/emblems
10 Example=folder
11 Inherits=gnome,hicolor
12 
13 [16x16/actions]
14 Size=16
15 Context=Actions
16 Type=Threshold
17 
18 [32x32/animations]
19 Size=32
20 Context=Animations
21 Type=Fixed
22 
23 [scalable/emblems]
24 Context=Emblems
25 Size=64
26 MinSize=8
27 MaxSize=512
28 Type=Scalable
29 
30 # Will be saved.
31 [X-NoName]
32 Key=Value`;
33 
34     string path = buildPath(".", "test", "Tango", "index.theme");
35 
36     auto iconTheme = new IconThemeFile(iniLikeStringReader(contents), path);
37     assert(equal(iconTheme.leadingComments(), ["# First comment"]));
38     assert(iconTheme.displayName() == "Hicolor");
39     assert(iconTheme.localizedDisplayName("ru") == "Стандартная тема");
40     assert(iconTheme.comment() == "Fallback icon theme");
41     assert(iconTheme.localizedComment("ru") == "Резервная тема");
42     assert(iconTheme.hidden());
43     assert(equal(iconTheme.directories(), ["16x16/actions", "32x32/animations", "scalable/emblems"]));
44     assert(equal(iconTheme.inherits(), ["gnome", "hicolor"]));
45     assert(iconTheme.internalName() == "Tango");
46     assert(iconTheme.example() == "folder");
47     assert(iconTheme.group("X-NoName") !is null);
48 
49     iconTheme.removeGroup("Icon Theme");
50     assert(iconTheme.group("Icon Theme") !is null);
51 
52     assert(iconTheme.cachePath() == buildPath(".", "test", "Tango", "icon-theme.cache"));
53 
54     assert(equal(iconTheme.bySubdir().map!(subdir => tuple(subdir.name(), subdir.size(), subdir.minSize(), subdir.maxSize(), subdir.context(), subdir.type() )),
55                  [tuple("16x16/actions", 16, 16, 16, "Actions", IconSubDir.Type.Threshold),
56                  tuple("32x32/animations", 32, 32, 32, "Animations", IconSubDir.Type.Fixed),
57                  tuple("scalable/emblems", 64, 8, 512, "Emblems", IconSubDir.Type.Scalable)]));
58 
59     version(iconthemeFileTest)
60     {
61         string cachePath = iconTheme.cachePath();
62         assert(cachePath.exists);
63 
64         auto cache = new IconThemeCache(cachePath);
65 
66         assert(iconTheme.cache is null);
67         iconTheme.cache = cache;
68         assert(iconTheme.cache is cache);
69         iconTheme.unloadCache();
70         assert(iconTheme.cache is null);
71 
72         assert(iconTheme.tryLoadCache(Flag!"allowOutdated".yes));
73     }
74 
75     iconTheme.removeGroup("scalable/emblems");
76     assert(iconTheme.group("scalable/emblems") is null);
77 
78     auto itf = new IconThemeFile();
79     itf.displayName = "Oxygen";
80     itf.comment = "Oxygen theme";
81     itf.hidden = true;
82     itf.directories = ["actions", "places"];
83     itf.inherits = ["locolor", "hicolor"];
84     assert(itf.displayName() == "Oxygen");
85     assert(itf.comment() == "Oxygen theme");
86     assert(itf.hidden());
87     assert(equal(itf.directories(), ["actions", "places"]));
88     assert(equal(itf.inherits(), ["locolor", "hicolor"]));

Meta