DesktopFile.id

  1. string id()
  2. string id(Range appPaths)
    class DesktopFile
    string
    id
    const nothrow
    (
    Range
    )
    (
    Range appPaths
    )
    if (
    isInputRange!Range &&
    is(ElementType!Range : string)
    )

Parameters

appPaths
Type: Range

range of base application paths to check if this file belongs to one of them.

Return Value

Type: string

Desktop file ID or empty string if file does not have an ID.

Examples

1         string contents =
2 `[Desktop Entry]
3 Name=Program
4 Type=Directory`;
5 
6         string[] appPaths;
7         string filePath, nestedFilePath, wrongFilePath;
8 
9         version(Windows) {
10             appPaths = [`C:\ProgramData\KDE\share\applications`, `C:\Users\username\.kde\share\applications`];
11             filePath = `C:\ProgramData\KDE\share\applications\example.desktop`;
12             nestedFilePath = `C:\ProgramData\KDE\share\applications\kde\example.desktop`;
13             wrongFilePath = `C:\ProgramData\desktop\example.desktop`;
14         } else {
15             appPaths = ["/usr/share/applications", "/usr/local/share/applications"];
16             filePath = "/usr/share/applications/example.desktop";
17             nestedFilePath = "/usr/share/applications/kde/example.desktop";
18             wrongFilePath = "/etc/desktop/example.desktop";
19         }
20 
21         auto df = new DesktopFile(iniLikeStringReader(contents), nestedFilePath);
22         assert(df.id(appPaths) == "kde-example.desktop");
23 
24         df = new DesktopFile(iniLikeStringReader(contents), filePath);
25         assert(df.id(appPaths) == "example.desktop");
26 
27         df = new DesktopFile(iniLikeStringReader(contents), wrongFilePath);
28         assert(df.id(appPaths).empty);
29 
30         df = new DesktopFile(iniLikeStringReader(contents));
31         assert(df.id(appPaths).empty);
32 

See Also

desktopfile.paths.applicationsPaths, desktopfile.utils.desktopId

Meta