findDefaultApplication

Find default application for given MIME type.

const(DesktopFile)
findDefaultApplication
(
ListRange
CacheRange
)
if (
isForwardRange!ListRange &&
is(ElementType!ListRange : const(MimeAppsListFile))
&&
isForwardRange!CacheRange
&&
is(ElementType!CacheRange : const(MimeInfoCacheFile))
)

Parameters

mimeType string

MIME type or uri scheme handler in question.

mimeAppsListFiles ListRange

Range of MimeAppsListFile objects to use in searching.

mimeInfoCacheFiles CacheRange

Range of MimeInfoCacheFile objects to use in searching.

desktopFileProvider IDesktopFileProvider

Desktop file provider instance. Must be non-null.

Return Value

Type: const(DesktopFile)

Found desktopfile.file.DesktopFile or null if not found. Note: You may consider calling this function on parent MIME types (recursively until application is found) if it fails for the original mimeType. Retrieving parent MIME types is out of the scope of this library. MIME library is available for that purpose. Check the Open example.

Examples

auto desktopProvider = new DesktopFileProvider(["test/applications"]);
auto mimeAppsList = new MimeAppsListFile("test/applications/mimeapps.list");
auto mimeInfoCache = new MimeInfoCacheFile("test/applications/mimeinfo.cache");
assert(findDefaultApplication("text/plain", [null, mimeAppsList], [null, mimeInfoCache], desktopProvider).displayName() == "Geany");
assert(findDefaultApplication("image/png", [mimeAppsList], [mimeInfoCache], desktopProvider).displayName() == "Gwenview");
assert(findDefaultApplication("application/pdf", [mimeAppsList], [mimeInfoCache], desktopProvider).displayName() == "Okular");
assert(findDefaultApplication("application/nonexistent", [mimeAppsList], [mimeInfoCache], desktopProvider) is null);
assert(findDefaultApplication("application/x-data", [mimeAppsList], [mimeInfoCache], desktopProvider) is null);

See Also

Meta