KDesktopFile Class

Header: #include <KDesktopFile>
CMake: find_package(KF6 REQUIRED COMPONENTS Config)
target_link_libraries(mytarget PRIVATE KF6::ConfigCore)
Inherits: KConfig

Public Functions

KDesktopFile(const QString &fileName)
KDesktopFile(QStandardPaths::StandardLocation resourceType, const QString &fileName)
virtual ~KDesktopFile() override
KConfigGroup actionGroup(const QString &group)
KConfigGroup actionGroup(const QString &group) const
(since 6.0) QList<KDesktopFileAction> actions() const
KDesktopFile *copyTo(const QString &file) const
KConfigGroup desktopGroup() const
QString fileName() const
bool hasActionGroup(const QString &group) const
bool hasApplicationType() const
bool hasDeviceType() const
bool hasLinkType() const
bool noDisplay() const
QStringList readActions() const
QString readComment() const
QString readDocPath() const
QString readGenericName() const
QString readIcon() const
QStringList readMimeTypes() const
QString readName() const
QString readPath() const
QString readType() const
QString readUrl() const
bool tryExec() const

Static Public Members

bool isAuthorizedDesktopFile(const QString &path)
bool isDesktopFile(const QString &path)
QString locateLocal(const QString &path)

Detailed Description

This class implements KDE's support for the freedesktop.org Desktop Entry Spec.

See also KConfigBase, KConfig, and KDesktopFileAction.

Member Function Documentation

[explicit] KDesktopFile::KDesktopFile(const QString &fileName)

Constructs a KDesktopFile object with the given fileName in its standard location QStandardPaths::ApplicationsLocation.

See also QStandardPaths::ApplicationsLocation.

[explicit] KDesktopFile::KDesktopFile(QStandardPaths::StandardLocation resourceType, const QString &fileName)

Constructs a KDesktopFile object in resourceType with the given fileName.

The resourceType allows to change where to search for the desktop file if fileName is not absolute. For instance, you might want to specify GenericConfigLocation.

See also QStandardPaths::StandardLocation.

[override virtual noexcept] KDesktopFile::~KDesktopFile()

Destructs the KDesktopFile object.

Writes back any changed configuration entries.

KConfigGroup KDesktopFile::actionGroup(const QString &group)

Sets a new desktop action group.

KConfigGroup KDesktopFile::actionGroup(const QString &group) const

Sets a new desktop action group.

[since 6.0] QList<KDesktopFileAction> KDesktopFile::actions() const

Returns the desktop file's actions.

This function was introduced in 6.0.

KDesktopFile *KDesktopFile::copyTo(const QString &file) const

Copies all entries from this config object to a new KDesktopFile object that will save itself to file.

Actual saving to file happens when the returned object is destructed or when sync() is called upon it.

KConfigGroup KDesktopFile::desktopGroup() const

Returns the main config group (named "Desktop Entry") in a .desktop file.

QString KDesktopFile::fileName() const

Returns the name of the .desktop file that was used to construct this KDesktopFile.

bool KDesktopFile::hasActionGroup(const QString &group) const

Returns whether the given action group exists.

bool KDesktopFile::hasApplicationType() const

Returns whether there is an entry "Type=Application".

bool KDesktopFile::hasDeviceType() const

Returns whether there is an entry "Type=FSDevice".

bool KDesktopFile::hasLinkType() const

Returns whether there is a "Type=Link" entry.

The link points to the "URL=" entry.

[static] bool KDesktopFile::isAuthorizedDesktopFile(const QString &path)

Returns whether the user is authorized to run desktop file at the given path.

By default users are authorized to run all desktop files but the Kiosk framework can be used to activate certain restrictions.

Note that desktop files that are not in a standard location (as specified by XDG_DATA_DIRS) must have their executable bit set to be authorized regardless of Kiosk settings to prevent users from inadvertently running trojan desktop files.

See also KAuthorized and Kiosk - Simple configuration management for large deployment.

[static] bool KDesktopFile::isDesktopFile(const QString &path)

Returns whether the file in the given path is a desktop file.

The check is performed looking at the file extension (the file is not opened). Currently, the only valid extension is ".desktop".

[static] QString KDesktopFile::locateLocal(const QString &path)

Returns the appropriate location to use to write changes to the desktop file based on the given path.

If the path is non-writable (such as /usr/share/applications), this function returns the appropriate equivalent.

If the appropriate location cannot be determined, the writable location will be in QStandardPaths::GenericDataLocation.

For example:

PathWritable Location
/etc/xdg/autostart/myapp.desktop~/.config/autostart/myapp.desktop
/usr/share/applications/myapp.desktop~/.local/share/applications/myapp.desktop
~/Documents/myapp.desktop~/.local/share/myapp.desktop
myapp.desktop~/.local/share/myapp.desktop

bool KDesktopFile::noDisplay() const

Returns whether the entry should be suppressed in menus.

This handles the "NoDisplay=" key.

QStringList KDesktopFile::readActions() const

Returns a list of the "Actions=" entries.

QString KDesktopFile::readComment() const

Returns the value of the "Comment=" entry, or QString() if not specified.

QString KDesktopFile::readDocPath() const

Returns the value of the "X-DocPath=" Or "DocPath=" entry.

QString KDesktopFile::readGenericName() const

Returns the value of the "GenericName=" entry, or QString() if not specified.

QString KDesktopFile::readIcon() const

Returns the value of the "Icon=" entry, or QString() if not specified.

QStringList KDesktopFile::readMimeTypes() const

Returns a list of the "MimeType=" entries.

QString KDesktopFile::readName() const

Returns the value of the "Name=" entry, or QString() if not specified.

QString KDesktopFile::readPath() const

Returns the value of the "Path=" entry, or QString() if not specified.

QString KDesktopFile::readType() const

Returns the value of the "Type=" entry, or QString() if not specified.

QString KDesktopFile::readUrl() const

Returns the value of the "URL=" entry, or QString() if not specified.

bool KDesktopFile::tryExec() const

Returns whether the "TryExec=" field contains a binary that is found on the local system.