DesktopFile.id - multiple declarations
Function DesktopFile.id
See Desktop File ID
string id() nothrow @safe const;
Returns
Desktop file ID or empty string if file does not have an ID.
Note
This function retrieves applications paths each time it's called and therefore can impact performance. To avoid this issue use overload with argument.
See Also
Example
import desktopfile .paths;
string contents = "[Desktop Entry]\nType=Directory";
auto df = new DesktopFile(iniLikeStringReader(contents), "/home/user/data/applications/test/example.desktop");
auto dataHomeGuard = EnvGuard("XDG_DATA_HOME", "/home/user/data");
assert(df .id() == "test-example.desktop");
}
Function DesktopFile.id
See Desktop File ID
string id(Range)
(
Range appPaths
) const nothrow
if (isInputRange!Range && is(ElementType!Range : string));
Parameters
Name | Description |
---|---|
appPaths | range of base application paths to check if this file belongs to one of them. |
Returns
Desktop file ID or empty string if file does not have an ID.
See Also
Example
string contents =
`[Desktop Entry]
Name=Program
Type=Directory`;
string[] appPaths;
string filePath, nestedFilePath, wrongFilePath;
version(Windows) {
appPaths = [`C:\ProgramData\KDE\share\applications`, `C:\Users\username\.kde\share\applications`];
filePath = `C:\ProgramData\KDE\share\applications\example.desktop`;
nestedFilePath = `C:\ProgramData\KDE\share\applications\kde\example.desktop`;
wrongFilePath = `C:\ProgramData\desktop\example.desktop`;
} else {
appPaths = ["/usr/share/applications", "/usr/local/share/applications"];
filePath = "/usr/share/applications/example.desktop";
nestedFilePath = "/usr/share/applications/kde/example.desktop";
wrongFilePath = "/etc/desktop/example.desktop";
}
auto df = new DesktopFile(iniLikeStringReader(contents), nestedFilePath);
assert(df .id(appPaths) == "kde-example.desktop");
df = new DesktopFile(iniLikeStringReader(contents), filePath);
assert(df .id(appPaths) == "example.desktop");
df = new DesktopFile(iniLikeStringReader(contents), wrongFilePath);
assert(df .id(appPaths) .empty);
df = new DesktopFile(iniLikeStringReader(contents));
assert(df .id(appPaths) .empty);