Struct DesktopFile.DesktopReadOptions

Options to manage desktop file reading

struct DesktopReadOptions ;

Constructors

NameDescription
this Setting parameters in any order, leaving not mentioned ones in default state.

Fields

NameTypeDescription
actionGroupPolicy DesktopFile.ActionGroupPolicySet policy about desktop action groups. By default they are all preserved. Note that all groups still need to be preserved if desktop file must be rewritten.
baseOptions IniLikeFile.ReadOptionsBase IniLikeFile.ReadOptions.
extensionGroupPolicy DesktopFile.ExtensionGroupPolicySet policy about extension groups. By default they are all preserved. Set it to skip if you're not willing to support any extensions in your applications. Note that all groups still need to be preserved if desktop file must be rewritten.
unknownGroupPolicy DesktopFile.UnknownGroupPolicySet policy about unknown groups. By default they are skipped without errors. Note that all groups still need to be preserved if desktop file must be rewritten.

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"]));