Class MimeAppsListFile

Class represenation of single mimeapps.list file containing information about MIME type associations and default applications.

class MimeAppsListFile
  : IniLikeFile ;

Constructors

NameDescription
this Read mimeapps.list file.
this Read MIME type associations from IniLikeReader, e.g. acquired from iniLikeFileReader or iniLikeStringReader.

Methods

NameDescription
addAssociation Add desktopId as association for mimeType. Delete it from removed associations if listed.
addedAssociations Access "Added Associations" group of explicitly added associations.
defaultApplications Access "Desktop Applications" group of default associations.
ensureAddedAssociations Create empty "Added Associations" group if it does not exist.
ensureDefaultApplications Create empty "Default Applications" group if it does not exist.
ensureRemovedAssociations Create empty "Removed Associations" group if it does not exist.
removeAssociation Explicitly remove desktopId association for mimeType. Delete it from added associations and default applications.
removedAssociations Access "Removed Associations" group of explicitily removed associations.
setAddedAssocations Set list of desktop ids as assocations for mimeType. This overwrites existing assocations.
setDefaultApplication Set desktopId as default application for mimeType. Set it as first element in the list of added associations. Delete it from removed associations if listed.
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).
removeGroup Remove group by name. Do nothing if group with such name does not exist.
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
GroupNode Wrapper for internal ListMap node.
ReadOptions Behavior of ini-like file reading.
WriteOptions Behavior of ini-like file saving.

Enums

NameDescription
DuplicateGroupPolicy Behavior on group with duplicate name in the file.
DuplicateKeyPolicy Behavior on duplicate key in the group.

Example

string content =
`[Added Associations]
text/plain=geany.desktop;kde4-kwrite.desktop;
image/png=kde4-gwenview.desktop;gthumb.desktop;

[Removed Associations]
text/plain=libreoffice-writer.desktop;

[Default Applications]
text/plain=kde4-kate.desktop
x-scheme-handler/http=chromium.desktop;iceweasel.desktop;


[Unknown group]
Key=Value`;
auto mimeAppsList = new MimeAppsListFile(iniLikeStringReader(content));
assert(mimeAppsList.addedAssociations() !is null);
assert(mimeAppsList.removedAssociations() !is null);
assert(mimeAppsList.defaultApplications() !is null);
assert(mimeAppsList.group("Unknown group") is null);

assert(mimeAppsList.addedAssociations().appsForMimeType("text/plain").equal(["geany.desktop", "kde4-kwrite.desktop"]));
assert(mimeAppsList.removedAssociations().appsForMimeType("text/plain").equal(["libreoffice-writer.desktop"]));
assert(mimeAppsList.defaultApplications().appsForMimeType("x-scheme-handler/http").equal(["chromium.desktop", "iceweasel.desktop"]));

content =
`[Default Applications]
text/plain=geany.desktop
notmimetype=value
`;
assertThrown!IniLikeReadException(new MimeAppsListFile(iniLikeStringReader(content)));
assertNotThrown(mimeAppsList = new MimeAppsListFile(iniLikeStringReader(content), null, IniLikeFile.ReadOptions(IniLikeGroup.InvalidKeyPolicy.save)));
assert(mimeAppsList.defaultApplications().escapedValue("notmimetype") == "value");