DtkCore
DTK Core module
Dtk::Core::DDesktopEntry类 参考

Handling desktop entry files. 更多...

Public 类型

enum  EntryType {
  Unknown = 0 , Application , Link , Directory ,
  ServiceType , Service , FSDevice
}
 
enum  ValueType {
  Unparsed = 0 , String , Strings , Boolean ,
  Numeric , NotExisted = 99
}
 
enum  Status { NoError = 0 , AccessError , FormatError }
 

Public 成员函数

 DDesktopEntry (const QString &filePath) noexcept
 
bool save () const
 Write back data to the desktop entry file. 更多...
 
Status status () const
 Get data parse status 更多...
 
QStringList keys (const QString &section="Desktop Entry") const
 Get a list of all section keys inside the given section. 更多...
 
QStringList allGroups (bool sorted=false) const
 Get a list of all section groups inside the desktop entry. 更多...
 
bool contains (const QString &key, const QString &section="Desktop Entry") const
 Check if the desktop entry file have the given section contains the given key 更多...
 
QString name () const
 Returns the localized string value of the "Name" key under "Desktop Entry" section. 更多...
 
QString genericName () const
 Returns the localized string value of the "GenericName" key under "Desktop Entry" section. 更多...
 
QString ddeDisplayName () const
 Display name specially for DDE applications. 更多...
 
QString comment () const
 Returns the localized string value of the "Comment" key under "Desktop Entry" section. 更多...
 
QString rawValue (const QString &key, const QString &section="Desktop Entry", const QString &defaultValue=QString()) const
 Returns the raw string value associated with the given key in section. 更多...
 
QString stringValue (const QString &key, const QString &section="Desktop Entry", const QString &defaultValue=QString()) const
 Returns the unescaped string value associated with the given key in section. 更多...
 
QString localizedValue (const QString &key, const QString &localeKey="default", const QString &section="Desktop Entry", const QString &defaultValue=QString()) const
 Returns the localized string value associated with the given key and localeKey in section. 更多...
 
QString localizedValue (const QString &key, const QLocale &locale, const QString &section="Desktop Entry", const QString &defaultValue=QString()) const
 Returns the localized string value associated with the given key and locale in section. 更多...
 
QStringList stringListValue (const QString &key, const QString &section="Desktop Entry") const
 Returns a list of strings associated with the given key in the given section. 更多...
 
bool setRawValue (const QString &value, const QString &key, const QString &section="Desktop Entry")
 
bool setStringValue (const QString &value, const QString &key, const QString &section="Desktop Entry")
 
bool setLocalizedValue (const QString &value, const QString &localeKey, const QString &key, const QString &section="Desktop Entry")
 
bool removeEntry (const QString &key, const QString &section="Desktop Entry")
 

静态 Public 成员函数

static QString & escape (QString &str)
 
static QString & escapeExec (QString &str)
 
static QString & unescape (QString &str, bool unescapeSemicolons=false)
 
static QString & unescapeExec (QString &str)
 

Protected 成员函数

bool setStatus (const Status &status)
 

详细描述

Handling desktop entry files.

\inmodule dtkcore

DDesktopEntry provide method for handling XDG desktop entry read and write. The interface of this class is similar to QSettings.

For more details about the spec itself, please refer to: https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html

成员枚举类型说明

◆ EntryType

枚举值
Unknown 

Unknown desktop file type. Maybe is invalid.

Application 

The file describes application.

Link 

The file describes URL.

Directory 

The file describes directory settings.

ServiceType 

KDE specific type. mentioned in the spec, so listed here too.

Service 

KDE specific type. mentioned in the spec, so listed here too.

FSDevice 

KDE specific type. mentioned in the spec, so listed here too.

◆ Status

枚举值
NoError 

No error occurred.

AccessError 

An access error occurred (e.g. trying to write to a read-only file).

FormatError 

A format error occurred (e.g. loading a malformed desktop entry file).

成员函数说明

◆ allGroups()

QStringList Dtk::Core::DDesktopEntry::allGroups ( bool  sorted = false) const

Get a list of all section groups inside the desktop entry.

If sorted is set to true, the returned result will keep the order as-is when reading the entry file.

返回
all available section groups.

◆ comment()

QString Dtk::Core::DDesktopEntry::comment ( ) const

Returns the localized string value of the "Comment" key under "Desktop Entry" section.

It's equivalent to calling localizedValue("Comment").

返回
Returns the localized string value of the "Comment" key under "Desktop Entry" section.
参见
localizedValue()

◆ contains()

bool Dtk::Core::DDesktopEntry::contains ( const QString &  key,
const QString &  section = "Desktop Entry" 
) const

Check if the desktop entry file have the given section contains the given key

返回
true if the desktop entry contains the key in section; otherwise returns false.

◆ ddeDisplayName()

QString Dtk::Core::DDesktopEntry::ddeDisplayName ( ) const

Display name specially for DDE applications.

This will check "X-Deepin-Vendor" and will return the localized string value of "GenericName" if "X-Deepin-Vendor" is "deepin", or it will return the localized string value of "Name".

返回
Returns the display name specially for DDE applications.
参见
localizedValue(), name(), genericName()

◆ genericName()

QString Dtk::Core::DDesktopEntry::genericName ( ) const

Returns the localized string value of the "GenericName" key under "Desktop Entry" section.

It's equivalent to calling localizedValue("GenericName"). It will NOT fallback to "Name" if "GenericName" is not existed.

返回
Returns the localized string value of the "GenericName" key under "Desktop Entry" section.
参见
localizedValue(), name(), ddeDisplayName()

◆ keys()

QStringList Dtk::Core::DDesktopEntry::keys ( const QString &  section = "Desktop Entry") const

Get a list of all section keys inside the given section.

返回
all available section keys.

◆ localizedValue() [1/2]

QString Dtk::Core::DDesktopEntry::localizedValue ( const QString &  key,
const QLocale &  locale,
const QString &  section = "Desktop Entry",
const QString &  defaultValue = QString() 
) const

Returns the localized string value associated with the given key and locale in section.

If the given locale can't be found, it will fallback to "C", if still cannot found, will fallback to the key without a locale key.

If the entry contains no item with the key, the function returns a default-constructed value.

返回
Returns the localized string value associated with the given key and locale in section.
参见
rawValue() stringValue() stringListValue()

◆ localizedValue() [2/2]

QString Dtk::Core::DDesktopEntry::localizedValue ( const QString &  key,
const QString &  localeKey = "default",
const QString &  section = "Desktop Entry",
const QString &  defaultValue = QString() 
) const

Returns the localized string value associated with the given key and localeKey in section.

If the given localeKey can't be found, it will fallback to "C", if still cannot found, will fallback to the key without localeKey.

If the entry contains no item with the key, the function returns a constructed defaultValue.

返回
Returns the localized string value associated with the given key and localeKey in section.
参见
rawValue() stringValue() stringListValue()

◆ name()

QString Dtk::Core::DDesktopEntry::name ( ) const

Returns the localized string value of the "Name" key under "Desktop Entry" section.

It's equivalent to calling localizedValue("Name").

返回
Returns the localized string value of the "Name" key under "Desktop Entry" section.
参见
localizedValue(), genericName(), ddeDisplayName()

◆ rawValue()

QString Dtk::Core::DDesktopEntry::rawValue ( const QString &  key,
const QString &  section = "Desktop Entry",
const QString &  defaultValue = QString() 
) const

Returns the raw string value associated with the given key in section.

If the entry contains no item with the key, the function returns a constructed defaultValue.

返回
Returns the raw string value associated with the given key in section.
参见
stringValue() localizedValue() stringListValue()

◆ save()

bool Dtk::Core::DDesktopEntry::save ( ) const

Write back data to the desktop entry file.

返回
true if write success; otherwise returns false.

◆ status()

DDesktopEntry::Status Dtk::Core::DDesktopEntry::status ( ) const

Get data parse status

返回
Returns a status code indicating the first error that was met by DDesktopEntry, or QSettings::NoError if no error occurred.

Be aware that DDesktopEntry delays performing some operations.

◆ stringListValue()

QStringList Dtk::Core::DDesktopEntry::stringListValue ( const QString &  key,
const QString &  section = "Desktop Entry" 
) const

Returns a list of strings associated with the given key in the given section.

If the entry contains no item with the key, the function returns a empty string list.

返回
Returns a list of strings associated with the given key in the given section.
参见
rawValue() stringValue() localizedValue()

◆ stringValue()

QString Dtk::Core::DDesktopEntry::stringValue ( const QString &  key,
const QString &  section = "Desktop Entry",
const QString &  defaultValue = QString() 
) const

Returns the unescaped string value associated with the given key in section.

If the entry contains no item with the key, the function returns a constructed defaultValue.

返回
Returns the unescaped string value associated with the given key in section.
参见
rawValue() localizedValue() stringListValue()

该类的文档由以下文件生成: