Struct DesktopFile.DesktopReadOptions
Options to manage desktop file reading
struct DesktopReadOptions
;
Constructors
Name | Description |
this
|
Setting parameters in any order, leaving not mentioned ones in default state.
|
Example
string contents =
`[Desktop Entry]
Key=Value
Actions=Action1;
[Desktop Action Action1]
Name=Action1 Name
Key=Value`;
alias DesktopFile.DesktopReadOptions DesktopReadOptions;
auto df = new DesktopFile(iniLikeStringReader(contents), DesktopReadOptions(ActionGroupPolicy.skip));
assert(df.action("Action1") is null);
contents =
`[Desktop Entry]
Key=Value
Actions=Action1;
[X-SomeGroup]
Key=Value`;
df = new DesktopFile(iniLikeStringReader(contents));
assert(df.group("X-SomeGroup") !is null);
df = new DesktopFile(iniLikeStringReader(contents), DesktopReadOptions(ExtensionGroupPolicy.skip));
assert(df.group("X-SomeGroup") is null);
contents =
`[Desktop Entry]
Valid=Key
$=Invalid`;
auto thrown = collectException!IniLikeReadException(new DesktopFile(iniLikeStringReader(contents)));
assert(thrown !is null);
assert(thrown.entryException !is null);
assert(thrown.entryException.key == "$");
assert(thrown.entryException.value == "Invalid");
assertNotThrown(new DesktopFile(iniLikeStringReader(contents), DesktopReadOptions(IniLikeGroup.InvalidKeyPolicy.skip)));
df = new DesktopFile(iniLikeStringReader(contents), DesktopReadOptions(IniLikeGroup.InvalidKeyPolicy.save));
assert(df.desktopEntry.escapedValue("$") == "Invalid");
contents =
`[Desktop Entry]
Name=Name
[Unknown]
Key=Value`;
assertThrown(new DesktopFile(iniLikeStringReader(contents), DesktopReadOptions(UnknownGroupPolicy.throwError)));
assertNotThrown(df = new DesktopFile(iniLikeStringReader(contents), DesktopReadOptions(UnknownGroupPolicy.preserve)));
assert(df.group("Unknown") !is null);
df = new DesktopFile(iniLikeStringReader(contents), DesktopReadOptions(UnknownGroupPolicy.skip));
assert(df.group("Unknown") is null);
contents =
`[Desktop Entry]
Name=One
[Desktop Entry]
Name=Two`;
df = new DesktopFile(iniLikeStringReader(contents), DesktopReadOptions(DuplicateGroupPolicy.preserve));
assert(df.displayName() == "One");
assert(df.byGroup().map!(g => g.escapedValue("Name")).equal(["One", "Two"]));