Function MimeAppsListFile.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.

void setDefaultApplication (
  string mimeType,
  string desktopId
) @trusted;

Note

This only changes the object, but not file itself.

Example

MimeAppsListFile appsList = new MimeAppsListFile();
appsList.setDefaultApplication("text/plain", "geany.desktop");
assert(appsList.defaultApplications() !is null);
assert(appsList.addedAssociations() !is null);
assert(appsList.defaultApplications().appsForMimeType("text/plain").equal(["geany.desktop"]));
assert(appsList.addedAssociations().appsForMimeType("text/plain").equal(["geany.desktop"]));

appsList.setDefaultApplication("image/png", null);
assert(!appsList.defaultApplications().contains("image/png"));

string contents =
`[Default Applications]
text/plain=kde4-kate.desktop`;

appsList = new MimeAppsListFile(iniLikeStringReader(contents));
appsList.setDefaultApplication("text/plain", "geany.desktop");
assert(appsList.defaultApplications().appsForMimeType("text/plain").equal(["geany.desktop"]));
assert(appsList.addedAssociations().appsForMimeType("text/plain").equal(["geany.desktop"]));

contents =
`[Default Applications]
text/plain=kde4-kate.desktop
[Added Associations]
text/plain=kde4-kate.desktop;emacs.desktop;`;

appsList = new MimeAppsListFile(iniLikeStringReader(contents));
appsList.setDefaultApplication("text/plain", "geany.desktop");
assert(appsList.defaultApplications().appsForMimeType("text/plain").equal(["geany.desktop"]));
assert(appsList.addedAssociations().appsForMimeType("text/plain").equal(["geany.desktop", "kde4-kate.desktop", "emacs.desktop"]));

contents =
`[Default Applications]
text/plain=emacs.desktop
[Added Associations]
text/plain=emacs.desktop;kde4-kate.desktop;geany.desktop;`;

appsList = new MimeAppsListFile(iniLikeStringReader(contents));
appsList.setDefaultApplication("text/plain", "geany.desktop");
assert(appsList.defaultApplications().appsForMimeType("text/plain").equal(["geany.desktop"]));
assert(appsList.addedAssociations().appsForMimeType("text/plain").equal(["geany.desktop", "emacs.desktop", "kde4-kate.desktop"]));

contents =
`[Default Applications]
text/plain=emacs.desktop
[Added Associations]
text/plain=emacs.desktop;kde4-kate.desktop;
[Removed Associations]
text/plain=kde4-okular.desktop;geany.desktop`;

appsList = new MimeAppsListFile(iniLikeStringReader(contents));
appsList.setDefaultApplication("text/plain", "geany.desktop");
assert(appsList.removedAssociations() !is null);
assert(appsList.defaultApplications().appsForMimeType("text/plain").equal(["geany.desktop"]));
assert(appsList.addedAssociations().appsForMimeType("text/plain").equal(["geany.desktop", "emacs.desktop", "kde4-kate.desktop"]));
assert(appsList.removedAssociations().appsForMimeType("text/plain").equal(["kde4-okular.desktop"]));