StandardPaths QML Type

Provides methods for accessing standard paths. More...

Import Statement: import ArcGIS.AppFramework 1.0
Inherits:

AppFrameworkObject

Methods

  • FileFolder defaultFolder(standardlocation type)
  • string displayName(standardlocation type)
  • string locate(standardlocation type, string fileName)
  • string locate(standardlocation type, string fileName, locateoptions options)
  • QStringList locateAll(standardlocation type, string fileName)
  • QStringList locateAll(standardlocation type, string fileName, locateoptions options)
  • QStringList standardLocations(standardlocation type)
  • FileFolder writableFolder(standardlocation type)
  • string writableLocation(standardlocation type)

Detailed Description

The StandardPaths component contains functions to query standard locations on the local filesystem. This is often used for aiding common tasks, such as user-specific directories or system-wide configuration directories.

This code sample, primarily demonstrating AudioRecorder in the Multimedia plugin, also includes a typical usage of StandardPaths. The 'Location' button opens a file dialog to the current standard location for music files, allowing you to define a new one.

App {
    id: app

    width: 500
    height: 100

        RowLayout {
        Layout.fillWidth: true

        Button {
            text: "Record"
            enabled: audioRecorder.available
            onClicked: audioRecorder.record();
        }

        Button {
            text: audioRecorder.state == AudioRecorder.PausedState ? "Unpause" : "Pause"
            enabled: audioRecorder.state == AudioRecorder.RecordingState

            onClicked: {
                if (audioRecorder.state == AudioRecorder.PausedState) {
                    audioRecorder.record();
                } else {
                    audioRecorder.pause();
                }
            }
        }

        Button {
            text: "Stop"
            enabled: audioRecorder.state == AudioRecorder.RecordingState || audioRecorder.state == AudioRecorder.PausedState
            onClicked: audioRecorder.stop();
        }

        Button {
            text: "Location"
            enabled: audioRecorder.state == AudioRecorder.StoppedState
            onClicked: outputDialog.open();
        }

        Button {
            text: "Play"
            enabled: audioRecorder.state == AudioRecorder.StoppedState && audioRecorder.actualLocation > "" && audioRecorder.duration > 0

            onClicked: {
                audio.source = audioRecorder.actualLocation;
                audio.play();
            }
        }
    }

    AudioRecorder {
        id: audioRecorder

        onStatusChanged: {
            console.log("audioRecorder status:", status);
        }

        onErrorChanged: {
            console.log("audioRecorder error:", error, "errorString:", errorString);
        }
    }

    FileDialog {
        id: outputDialog

        title: qsTr("Output Location")
        selectExisting: false
        selectMultiple: false
        nameFilters: [ "All files (*)" ]
        folder: AppFramework.resolvedPathUrl(AppFramework.standardPaths.standardLocations(StandardPaths.MusicLocation)[0])

        onAccepted: {
            audioRecorder.outputLocation = fileUrl;
        }
    }
}

Enumerations

StandardLocation enumeration

This enum describes the locations that are associated with various types of files.

NameValue
StandardPaths.DesktopLocation0
StandardPaths.DocumentsLocation1
StandardPaths.FontsLocation2
StandardPaths.ApplicationsLocation3
StandardPaths.MusicLocation4
StandardPaths.MoviesLocation5
StandardPaths.PicturesLocation6
StandardPaths.TempLocation7
StandardPaths.HomeLocation8
StandardPaths.DataLocation9
StandardPaths.AppLocalDataLocation9
StandardPaths.CacheLocation10
StandardPaths.GenericDataLocation11
StandardPaths.RuntimeLocation12
StandardPaths.ConfigLocation13
StandardPaths.DownloadLocation14
StandardPaths.GenericCacheLocation15
StandardPaths.GenericConfigLocation16
StandardPaths.AppDataLocation17
StandardPaths.AppStudioExternalDataLocation256
StandardPaths.AppStudioHomeLocation257
StandardPaths.AppStudioPicturesLocation258

LocateOption enumeration

This enum describes the different flags that can be used for controlling the behavior of locate and locateAll.

NameValue
StandardPaths.LocateFile0
StandardPaths.LocateDirectory1

LocateOptions flags

The LocateOptions flag contains LocateOption enums.

Method Documentation

FileFolder defaultFolder(standardlocation type)

Returns a single location where files of this type belong, as a FileFolder object. This is ideal for when you want to define a location without requiring user input.

The following code sample demonstrates how to use defaultFolder(), and the result it would produce on a Windows machine.

// Get the default AppDataLocation:
var path = AppFramework.standardPaths.defaultFolder(StandardPaths.AppDataLocation).path;
// Returns: "C:/Users/USERNAME/AppData/Roaming/Esri/APPNAME"

The type parameter

The type of file to create a subfolder for, i.e. 'pictures' or 'fonts'.


string displayName(standardlocation type)

Returns a localized display name for the given location type. Returns an empty string if no relevant location can be found.

The type parameter

The type of file to display the location name for, i.e. 'pictures' or 'fonts'.


string locate(standardlocation type, string fileName)

Tries to find a file or directory with the given filename, in the standard locations for the defined type.

The type parameter

The type of file to locate the directory for, i.e. 'pictures' or 'fonts'.

The fileName parameter

The name of the file or directory to search for.


string locate(standardlocation type, string fileName, locateoptions options)

Tries to find a file or directory with the given file name, in the standard locations for the defined type.

The type parameter

The type of file to locate the directory for, i.e. 'pictures' or 'fonts'.

The fileName parameter

The name of the file or directory to search for.

The options parameter

0 to return only files, 1 to return only directories.


QStringList locateAll(standardlocation type, string fileName)

Tries to find all files or directories with the given filename in the standard locations for the defined file type.

The type parameter

The type of file to locate the directory for, i.e. 'pictures' or 'fonts'.

The fileName parameter

Name of the file or directory to locate.


QStringList locateAll(standardlocation type, string fileName, locateoptions options)

Attempts to find all files or directories of the given filename, in the standard locations for the defined type. The options flag specifies whether to look for files or directories.

The type parameter

The type of file to locate the directory for, i.e. 'pictures' or 'fonts'.

The fileName parameter

Name of the file or directory to locate.

The options parameter

0 to return only files, 1 to return only directories.


QStringList standardLocations(standardlocation type)

Returns all directories where files of the defined type belong as an array of strings.

The following code sample demonstrates how to use standardLocations(), and the result it would produce on a Windows machine.

// Get an array of AppDataLocation(s):
var pathArray = AppFramework.standardPaths.standardLocations(StandardPaths.AppDataLocation);
// Returns:
// {
//   "0":"C:/Users/USERNAME/AppData/Roaming/Esri/APPNAME",
//   "1":"C:/ProgramData/Esri/APPNAME",
//   "2":"C:/Users/USERNAME/Applications/ArcGIS/AppStudio/bin",
//   "3":"C:/Users/USERNAME/Applications/ArcGIS/AppStudio/bin/data"
// }

The type parameter

The type of file to return the default directory for, i.e. 'pictures' or 'fonts'.


FileFolder writableFolder(standardlocation type)

If the writable location for the given type is not empty, creates a subfolder within the directory. If the location is empty, this function does nothing.

The type parameter

The type of file to create a subfolder for, i.e. 'pictures' or 'fonts'.


string writableLocation(standardlocation type)

Returns the directory where files of the defined type should be written to. Returns an empty string if the location cannot be determined.

The type parameter

The type of file to return the default directory for, i.e. 'pictures' or 'fonts'.


Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.