platform

Wrappers for what differs per system and Qt does not cover, and the pure parsers they are built on.

Detailed description

Function documentation

desktopFileForId

QString desktopFileForId(const QStringList &applicationFolders, const QString &desktopId)

Returns the file that desktopId names in applicationFolders, the first folder first, or an empty string.

desktopFileId

QString desktopFileId(const QString &applicationFolder, const QString &filePath)

Returns the desktop file id of filePath, which is below applicationFolder.

The id is the path below the folder with each `/` made a `-`: `applications/kde/foo.desktop` is `kde-foo.desktop` (Desktop Entry Specification, "Desktop File ID").

execCommands

QList<QStringList> execCommands(const platform::DesktopEntry &entry, const QStringList &paths, const QString &locale = QString(), QString *error = nullptr)

Returns the argument lists that open paths with entry.

One list, from expandExec(), when the program takes many files. With `%f` or `%u`, which take one, one list for each path: the specification says the launcher "should probably spawn and execute multiple copies of a program". An empty result, with error set when given, when the entry is refused. locale is passed on to expandExec().

execTakesManyFiles

bool execTakesManyFiles(const platform::DesktopEntry &entry)

Returns true when the `Exec` key of entry takes many files in one start: it has `%F` or `%U`, or no file field code at all.

expandExec

QStringList expandExec(const platform::DesktopEntry &entry, const QStringList &paths, const QString &locale = QString(), QString *error = nullptr)

Returns the argument list that starts entry with paths: the program first, then its arguments.

The rules are those of exec-variables.html. The quoting of `Exec` is undone first, then each field code is expanded once:

  • `%f`: the first of paths. `%u`: the same as a URL.
  • `%F`: each of paths as an argument of its own. `%U`: the same as URLs.
  • `%i`: `–icon` and the `Icon` key, or nothing when there is no icon.
  • `%c`: the name of the entry for locale.
  • `%k`: the file of the entry.
  • `%%`: a percent sign.
  • The deprecated codes `%d %D %n %N %v %m` are removed.

A path is one argument, whatever it holds: no shell sees it. An argument that was only field codes, and expands to nothing, is dropped.

Returns an empty list, with error set when given, when the entry has no `Exec` key, when a quote does not close, when a field code is not in the specification, when `%F`, `%U` or `%i` is not an argument of its own, or when there are two file field codes: the specification says such a line "must not be processed".

With `%f` or `%u`, only the first path is used. execCommands() starts one program for each path in that case.

resolveMimeHandlers

QList<platform::MimeHandler> resolveMimeHandlers(const platform::MimeHandlerQuery &query)

Returns the programs that open query's type, the default first.

The rules are the XDG MIME Applications Specification's (https://specifications.freedesktop.org/mime-apps/latest/):

  • The lists are read in the order of MimeAppsList::lookupOrder().
  • The programs of the type are its added associations, then the desktop files whose `MimeType=` names it, less its removed associations, folder by folder (associations.html). An added and a removed association in one file: the added one counts, because the algorithm adds before it blacklists. A removal in a more important file than an addition wins.
  • Then the programs of each ancestor type, the closest first: "an association from a mimetype that is more specific will be listed before an association with a lower priority".
  • The default is the first id of a `[Default Applications]` line that is installed and associated with its type (default.html). It goes first. When no list names one, the first program is the default.
  • An entry with `Hidden=true`, or with a `TryExec` program that is not found, is not installed. A desktop file hides the files of the same id in less important folders.

query names the folders and gives the type's ancestors. Nothing here reads the environment, so a test passes fixture folders.

Classes

Class What it is
DesktopEntry A desktop entry: the `.desktop` file that names a program, its icon and the file types it opens to a Linux desktop
KeyFile A file of the XDG key-file format that keeps every line it does not change
MimeAppsList One `mimeapps.list` file: the defaults and the associations of file types with programs, read and written line by line

Namespaces

Namespace What it is
associations File associations of the desktop
crash Sentinel and its link to an application (diagnostic-reports §DGK-4)
diagnostics Diagnostics of a running process, such as the stack of another thread
filesystem File stamps and folder watches, as the platform reports them
hardware Of the machine: processors, caches, memory, drives and the network link
shell Other programs that open a file: the system's list, a start of one of them, and the system's own chooser (construct-viewer §VWO-2)
spawn Start of child processes and the job trees that hold them
system What the system says of this machine and process: processor, control group memory and thread times
terminal Of the standard error stream, and the color conventions of the environment
In this section