KConfig 5.109.0
Public Member Functions | Static Public Member Functions | List of all members
KDesktopFile

KDE Desktop File Management. More...

#include <KDesktopFile>

Public Member Functions

 KDesktopFile (const QString &fileName)
 Constructs a KDesktopFile object.
 
 KDesktopFile (QStandardPaths::StandardLocation resourceType, const QString &fileName)
 Constructs a KDesktopFile object.
 
 ~KDesktopFile () override
 Destructs the KDesktopFile object.
 
KConfigGroup actionGroup (const QString &group)
 Sets the desktop action group.
 
const KConfigGroup actionGroup (const QString &group) const
 
KDesktopFilecopyTo (const QString &file) const
 Copies all entries from this config object to a new KDesktopFile object that will save itself to file.
 
KConfigGroup desktopGroup () const
 Returns the main config group (named "Desktop Entry") in a .desktop file.
 
QString fileName () const
 Returns the name of the .desktop file that was used to construct this KDesktopFile.
 
bool hasActionGroup (const QString &group) const
 Returns true if the action group exists, false otherwise.
 
bool hasApplicationType () const
 Checks whether there is an entry "Type=Application".
 
bool hasDeviceType () const
 Checks whether there is an entry "Type=FSDevice".
 
bool hasLinkType () const
 Checks whether there is a "Type=Link" entry.
 
bool noDisplay () const
 Whether the entry should be suppressed in menus.
 
QStringList readActions () const
 Returns a list of the "Actions=" entries.
 
QString readComment () const
 Returns the value of the "Comment=" entry.
 
QString readDocPath () const
 Returns the value of the "X-DocPath=" Or "DocPath=" entry.
 
QString readGenericName () const
 Returns the value of the "GenericName=" entry.
 
QString readIcon () const
 Returns the value of the "Icon=" entry.
 
QStringList readMimeTypes () const
 Returns a list of the "MimeType=" entries.
 
QString readName () const
 Returns the value of the "Name=" entry.
 
QString readPath () const
 Returns the value of the "Path=" entry.
 
QString readType () const
 Returns the value of the "Type=" entry.
 
QString readUrl () const
 Returns the value of the "URL=" entry.
 
bool tryExec () const
 Checks whether the TryExec field contains a binary which is found on the local system.
 
- Public Member Functions inherited from KConfig
 KConfig (const QString &file, const QString &backend, QStandardPaths::StandardLocation type=QStandardPaths::GenericConfigLocation)
 
 KConfig (const QString &file=QString(), OpenFlags mode=FullConfig, QStandardPaths::StandardLocation type=QStandardPaths::GenericConfigLocation)
 Creates a KConfig object to manipulate a configuration file for the current application.
 
void checkUpdate (const QString &id, const QString &updateFile)
 Ensures that the configuration file contains a certain update.
 
KConfigcopyTo (const QString &file, KConfig *config=nullptr) const
 Copies all entries from this config object to a new config object that will save itself to file.
 
QMap< QString, QString > entryMap (const QString &aGroup=QString()) const
 Returns a map (tree) of entries in a particular group.
 
QStringList groupList () const override
 
bool isDirty () const
 Returns true if sync has any changes to write out.
 
QStandardPaths::StandardLocation locationType () const
 Returns the standard location enum passed to the constructor.
 
void markAsClean () override
 
QString name () const
 Returns the filename used to store the configuration.
 
OpenFlags openFlags () const
 
void reparseConfiguration ()
 Updates the state of this object to match the persistent storage.
 
bool sync () override
 
AccessMode accessMode () const override
 
bool isConfigWritable (bool warnUser)
 Whether the configuration can be written to.
 
void addConfigSources (const QStringList &sources)
 extra config files
 
QStringList additionalConfigSources () const
 Returns a list of the additional configuration sources used in this object.
 
QString locale () const
 locales
 
bool setLocale (const QString &aLocale)
 Sets the locale to aLocale.
 
void setReadDefaults (bool b)
 defaults
 
bool readDefaults () const
 
bool isImmutable () const override
 
void setForceGlobal (bool force)
 global
 
bool forceGlobal () const
 Returns whether all entries are being written to kdeglobals.
 
- Public Member Functions inherited from KConfigBase
virtual ~KConfigBase ()
 Destructs the KConfigBase object.
 
virtual AccessMode accessMode () const =0
 Returns the access mode of the app-config object.
 
void deleteGroup (const char *group, WriteConfigFlags flags=Normal)
 Overload for deleteGroup(const QString&, WriteConfigFlags)
 
void deleteGroup (const QByteArray &group, WriteConfigFlags flags=Normal)
 Overload for deleteGroup(const QString&, WriteConfigFlags)
 
void deleteGroup (const QString &group, WriteConfigFlags flags=Normal)
 Delete group.
 
KConfigGroup group (const char *group)
 Overload for group(const QString&)
 
const KConfigGroup group (const char *group) const
 Const overload for group(const QString&)
 
KConfigGroup group (const QByteArray &group)
 Overload for group(const QString&)
 
const KConfigGroup group (const QByteArray &group) const
 Const overload for group(const QString&)
 
KConfigGroup group (const QString &group)
 Returns an object for the named subgroup.
 
const KConfigGroup group (const QString &group) const
 Const overload for group(const QString&)
 
virtual QStringList groupList () const =0
 Returns a list of groups that are known about.
 
bool hasGroup (const char *group) const
 Overload for hasGroup(const QString&) const.
 
bool hasGroup (const QByteArray &group) const
 Overload for hasGroup(const QString&) const.
 
bool hasGroup (const QString &group) const
 Returns true if the specified group is known about.
 
bool isGroupImmutable (const char *group) const
 Overload for isGroupImmutable(const QString&) const.
 
bool isGroupImmutable (const QByteArray &group) const
 Overload for isGroupImmutable(const QString&) const.
 
bool isGroupImmutable (const QString &group) const
 Can changes be made to the entries in group?
 
virtual bool isImmutable () const =0
 Checks whether this configuration object can be modified.
 
virtual void markAsClean ()=0
 Reset the dirty flags of all entries in the entry map, so the values will not be written to disk on a later call to sync().
 
virtual bool sync ()=0
 Syncs the configuration object that this group belongs to.
 

Static Public Member Functions

static bool isAuthorizedDesktopFile (const QString &path)
 Checks whether the user is authorized to run this desktop file.
 
static bool isDesktopFile (const QString &path)
 Checks whether this is really a desktop file.
 
static QString locateLocal (const QString &path)
 Returns the location where changes for the .desktop file path should be written to.
 
- Static Public Member Functions inherited from KConfig
static QString mainConfigName ()
 Get the name of application config file.
 
static void setMainConfigName (const QString &str)
 Sets the name of the application config file.
 

Additional Inherited Members

- Public Types inherited from KConfig
enum  OpenFlag {
  IncludeGlobals = 0x01 , CascadeConfig = 0x02 , SimpleConfig = 0x00 , NoCascade = IncludeGlobals ,
  NoGlobals = CascadeConfig , FullConfig = IncludeGlobals | CascadeConfig
}
 Determines how the system-wide and user's global settings will affect the reading of the configuration. More...
 
typedef QFlags< OpenFlagOpenFlags
 Stores a combination of #OpenFlag values.
 
- Public Types inherited from KConfigBase
enum  AccessMode { NoAccess , ReadOnly , ReadWrite }
 Possible return values for accessMode(). More...
 
enum  WriteConfigFlag {
  Persistent = 0x01 , Global = 0x02 , Localized = 0x04 , Notify = 0x08 | Persistent ,
  Normal = Persistent
}
 Flags to control write entry. More...
 
typedef QFlags< WriteConfigFlagWriteConfigFlags
 Stores a combination of #WriteConfigFlag values.
 
- Protected Member Functions inherited from KConfig
 __attribute__ ((visibility("hidden"))) explicit KConfig(KConfigPrivate &d)
 
void deleteGroupImpl (const QByteArray &group, WriteConfigFlags flags=Normal) override
 
const KConfigGroup groupImpl (const QByteArray &b) const override
 
KConfigGroup groupImpl (const QByteArray &b) override
 
bool hasGroupImpl (const QByteArray &group) const override
 
bool isGroupImmutableImpl (const QByteArray &aGroup) const override
 
void virtual_hook (int id, void *data) override
 Virtual hook, used to add new "virtual" functions while maintaining binary compatibility.
 
virtual void deleteGroupImpl (const QByteArray &group, WriteConfigFlags flags=Normal)=0
 
virtual const KConfigGroup groupImpl (const QByteArray &group) const =0
 
virtual KConfigGroup groupImpl (const QByteArray &group)=0
 
virtual bool hasGroupImpl (const QByteArray &group) const =0
 
virtual bool isGroupImmutableImpl (const QByteArray &group) const =0
 
virtual void virtual_hook (int id, void *data)
 Virtual hook, used to add new "virtual" functions while maintaining binary compatibility.
 
- Protected Attributes inherited from KConfig
KConfigPrivate *const d_ptr
 

Detailed Description

KDE Desktop File Management.

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

Author
Pietro Iglio iglio.nosp@m.@kde.nosp@m..org
See also
KConfigBase KConfig
Desktop Entry Spec

Constructor & Destructor Documentation

◆ KDesktopFile() [1/2]

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

Constructs a KDesktopFile object.

See QStandardPaths for more information on resources.

Parameters
resourceTypeAllows you to change what sort of resource to search for if fileName is not absolute. For instance, you might want to specify GenericConfigLocation.
fileNameThe name or path of the desktop file. If it is not absolute, it will be located using the resource type resType.

◆ KDesktopFile() [2/2]

KDesktopFile::KDesktopFile ( const QString &  fileName)
explicit

Constructs a KDesktopFile object.

See QStandardPaths for more information on resources.

Parameters
fileNameThe name or path of the desktop file. If it is not absolute, it will be located using the resource type ApplicationsLocation

◆ ~KDesktopFile()

KDesktopFile::~KDesktopFile ( )
override

Destructs the KDesktopFile object.

Writes back any changed configuration entries.

Member Function Documentation

◆ actionGroup()

KConfigGroup KDesktopFile::actionGroup ( const QString &  group)

Sets the desktop action group.

Parameters
groupthe new action group

◆ copyTo()

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.

Parameters
filethe new KDesktopFile object it will save itself to.

◆ desktopGroup()

KConfigGroup KDesktopFile::desktopGroup ( ) const

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

◆ fileName()

QString KDesktopFile::fileName ( ) const

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

◆ hasActionGroup()

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

Returns true if the action group exists, false otherwise.

Parameters
groupthe action group to test
Returns
true if the action group exists

◆ hasApplicationType()

bool KDesktopFile::hasApplicationType ( ) const

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

Returns
true if there is a "Type=Application" entry

◆ hasDeviceType()

bool KDesktopFile::hasDeviceType ( ) const

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

Returns
true if there is a "Type=FSDevice" entry

◆ hasLinkType()

bool KDesktopFile::hasLinkType ( ) const

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

The link points to the "URL=" entry.

Returns
true if there is a "Type=Link" entry

◆ isAuthorizedDesktopFile()

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

Checks whether the user is authorized to run this desktop file.

By default users are authorized to run all desktop files but the KIOSK framework can be used to activate certain restrictions. See README.kiosk for more information.

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.

Parameters
paththe file to check
Returns
true if the user is authorized to run the file

◆ isDesktopFile()

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

Checks whether this is really a desktop file.

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

Parameters
paththe path of the file to check
Returns
true if the file appears to be a desktop file.

◆ locateLocal()

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

Returns the location where changes for the .desktop file path should be written to.

◆ noDisplay()

bool KDesktopFile::noDisplay ( ) const

Whether the entry should be suppressed in menus.

This handles the NoDisplay key, but also OnlyShowIn / NotShowIn.

Returns
true to suppress this service
Since
4.1

◆ readActions()

QStringList KDesktopFile::readActions ( ) const

Returns a list of the "Actions=" entries.

Returns
the list of actions

◆ readComment()

QString KDesktopFile::readComment ( ) const

Returns the value of the "Comment=" entry.

Returns
the comment or QString() if not specified

◆ readDocPath()

QString KDesktopFile::readDocPath ( ) const

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

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

◆ readGenericName()

QString KDesktopFile::readGenericName ( ) const

Returns the value of the "GenericName=" entry.

Returns
the generic name or QString() if not specified

◆ readIcon()

QString KDesktopFile::readIcon ( ) const

Returns the value of the "Icon=" entry.

Returns
the icon or QString() if not specified

◆ readMimeTypes()

QStringList KDesktopFile::readMimeTypes ( ) const

Returns a list of the "MimeType=" entries.

Returns
the list of mime types
Since
5.15

◆ readName()

QString KDesktopFile::readName ( ) const

Returns the value of the "Name=" entry.

Returns
the name or QString() if not specified

◆ readPath()

QString KDesktopFile::readPath ( ) const

Returns the value of the "Path=" entry.

Returns
the path or QString() if not specified

◆ readType()

QString KDesktopFile::readType ( ) const

Returns the value of the "Type=" entry.

Returns
the type or QString() if not specified

◆ readUrl()

QString KDesktopFile::readUrl ( ) const

Returns the value of the "URL=" entry.

Returns
the URL or QString() if not specified

◆ tryExec()

bool KDesktopFile::tryExec ( ) const

Checks whether the TryExec field contains a binary which is found on the local system.

Returns
true if TryExec contains an existing binary