DesktopFile.id

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

Parameters

appPaths 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

        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), DesktopFile.ReadOptions.noOptions, nestedFilePath);
        assert(df.id(appPaths) == "kde-example.desktop");
        
        df = new DesktopFile(iniLikeStringReader(contents), DesktopFile.ReadOptions.noOptions, filePath);
        assert(df.id(appPaths) == "example.desktop");
        
        df = new DesktopFile(iniLikeStringReader(contents), DesktopFile.ReadOptions.noOptions, wrongFilePath);
        assert(df.id(appPaths).empty);
        
        df = new DesktopFile(iniLikeStringReader(contents), DesktopFile.ReadOptions.noOptions);
        assert(df.id(appPaths).empty);
    

See Also

applicationsPaths

Meta