DtkCore
DTK Core module
|
处理desktop文件的接口 更多...
#include <ddesktopentry.h>
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 } |
desktop文件的解析状态 更多... | |
Public 成员函数 | |
DDesktopEntry (const QString &filePath) noexcept | |
DDesktopEntry构造函数 | |
bool | save () const |
将数据回写到desktop文件。 | |
Status | status () const |
Get data parse status | |
QStringList | keys (const QString §ion="Desktop Entry") const |
根据 section 返回全部键值 | |
QStringList | allGroups (bool sorted=false) const |
获取desktop中所有组的列表。如果 sorted 设置为true, 则返回结果将保持读取desktop文件时的顺序不变。 | |
bool | contains (const QString &key, const QString §ion="Desktop Entry") const |
检查desktop文件是否有给定的 section 包含给定的 key | |
QString | name () const |
返回“Desktop Entry”部分下的“Name”键的本地化字符串值。这等价于调用localizedValue("Name")。 | |
QString | genericName () const |
返回"Desktop Entry"部分下的"GenericName"键的本地化字符串值。它等价于调用localizedValue("GenericName")。如果是“GenericName”不存在。则不会回退到“Name”。 | |
QString | ddeDisplayName () const |
为DDE应用程序专门显示名称 | |
QString | comment () const |
返回“Desktop Entry”部分下的“Comment”键的本地化字符串值。这等价于调用localizedValue("Comment")。 | |
QString | rawValue (const QString &key, const QString §ion="Desktop Entry", const QString &defaultValue=QString()) const |
返回 section 中与给定 key 关联的原始字符串值。如果desktop不包含具有该键的项, 则函数返回一个构造好的 defaultValue 。 | |
QString | stringValue (const QString &key, const QString §ion="Desktop Entry", const QString &defaultValue=QString()) const |
返回 section 与给定 key 关联的未转义字符串值。如果desktop不包含键值为0的项, 则函数返回一个构造好的 defaultValue 。 | |
QString | localizedValue (const QString &key, const QString &localeKey="default", const QString §ion="Desktop Entry", const QString &defaultValue=QString()) const |
返回与 section 中给定的 key 和 localeKey 相关联的本地化字符串值。 | |
QString | localizedValue (const QString &key, const QLocale &locale, const QString §ion="Desktop Entry", const QString &defaultValue=QString()) const |
返回与给定的 key 和 section 中的区域设置相关联的本地化字符串值。 | |
QStringList | stringListValue (const QString &key, const QString §ion="Desktop Entry") const |
返回给定 section 中与给定 key 关联的字符串的列表。如果destkop不包含为该键的项,则函数返回一个空字符串列表。 | |
bool | setRawValue (const QString &value, const QString &key, const QString §ion="Desktop Entry") |
设置给定 section 中与给定 key 关联的原始字符串值。 | |
bool | setStringValue (const QString &value, const QString &key, const QString §ion="Desktop Entry") |
设置给定 section 中与给定 key 关联的字符串 | |
bool | setLocalizedValue (const QString &value, const QString &localeKey, const QString &key, const QString §ion="Desktop Entry") |
设置给定的 key 和 section 中的区域设置相关联的本地化字符串值。 | |
bool | removeEntry (const QString &key, const QString §ion="Desktop Entry") |
删除desktop中 section 与 key 对应的值 | |
静态 Public 成员函数 | |
static QString & | escape (QString &str) |
支持转义序列\s 、\n 、\t 、\r 和\\ 表示值 | |
static QString & | escapeExec (QString &str) |
必须将参数括在双引号之间,并对双引号字符进行转义。 | |
static QString & | unescape (QString &str, bool unescapeSemicolons=false) |
对于类型为string和localestring的值,支持转义序列\s 、\n 、\t 、\r 和\\ ,分别表示ASCII空格、换行符、制表符、回车符和反斜杠。 | |
static QString & | unescapeExec (QString &str) |
必须将参数括在双引号之间,并对双引号字符进行转义, | |
Protected 成员函数 | |
bool | setStatus (const Status &status) |
设置desktop文件解析状态 | |
处理desktop文件的接口
DDesktopEntry提供了处理XDG desktop读写的方法的接口,这个Class类似于QSettings。
有关该规范本身的更多详细信息,请参阅: https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html
项目目录结构在同一目录下
结果如下图
QStringList Dtk::Core::DDesktopEntry::allGroups | ( | bool | sorted = false | ) | const |
获取desktop中所有组的列表。如果 sorted
设置为true, 则返回结果将保持读取desktop文件时的顺序不变。
QString Dtk::Core::DDesktopEntry::comment | ( | ) | const |
返回“Desktop Entry”部分下的“Comment”键的本地化字符串值。这等价于调用localizedValue("Comment")。
bool Dtk::Core::DDesktopEntry::contains | ( | const QString & | key, |
const QString & | section = "Desktop Entry" |
||
) | const |
检查desktop文件是否有给定的 section
包含给定的 key
section
包含 key
返回true; 否则返回false。 QString Dtk::Core::DDesktopEntry::ddeDisplayName | ( | ) | const |
为DDE应用程序专门显示名称
这将检查“X-Deepin-Vendor”,并将返回本地化的字符串值“GenericName” "X-Deepin-Vendor"是"deepin",否则它将返回"Name"的本地化字符串值。
|
static |
支持转义序列\s
、\n
、\t
、\r
和\\
表示值
string和localestring类型的值支持转义序列\s
、\n
、\t
、\r
和\\
,分别表示ASCII空格、换行符、制表符、回车和反斜杠。
|
static |
必须将参数括在双引号之间,并对双引号字符进行转义。
原字符 | 转义后 |
---|---|
` | "`" |
$ | "$" |
\ | "\" |
在它前面加上一个额外的反斜杠字符。实现必须在扩展字段代码之前和之前撤销引用,将参数传递给可执行程序。
QString Dtk::Core::DDesktopEntry::genericName | ( | ) | const |
返回"Desktop Entry"部分下的"GenericName"键的本地化字符串值。它等价于调用localizedValue("GenericName")。如果是“GenericName”不存在。则不会回退到“Name”。
QStringList Dtk::Core::DDesktopEntry::keys | ( | const QString & | section = "Desktop Entry" | ) | const |
根据 section
返回全部键值
QString Dtk::Core::DDesktopEntry::localizedValue | ( | const QString & | key, |
const QLocale & | locale, | ||
const QString & | section = "Desktop Entry" , |
||
const QString & | defaultValue = QString() |
||
) | const |
返回与给定的 key
和 section
中的区域设置相关联的本地化字符串值。
如果找不到给定的 localeKey
,它将回退到"C",如果仍然找不到,将回退 key
没有localeKey
部分。 如果destkop不包含 key
值为0的项,则函数返回一个构造好的 defaultValue
。
section
中 与给定的 key
和 locale
设置相关联的本地化字符串值。 QString Dtk::Core::DDesktopEntry::localizedValue | ( | const QString & | key, |
const QString & | localeKey = "default" , |
||
const QString & | section = "Desktop Entry" , |
||
const QString & | defaultValue = QString() |
||
) | const |
返回与 section
中给定的 key
和 localeKey
相关联的本地化字符串值。
如果找不到给定的 localeKey
,它将回退到"C",如果仍然找不到,将回退 key
没有localeKey
部分。。 如果destkop不包含 key
值为0的项,则函数返回一个构造好的 defaultValue
。
section
中与给定的 key
和 localeKey
关联的本地化字符串值。 QString Dtk::Core::DDesktopEntry::name | ( | ) | const |
返回“Desktop Entry”部分下的“Name”键的本地化字符串值。这等价于调用localizedValue("Name")。
QString Dtk::Core::DDesktopEntry::rawValue | ( | const QString & | key, |
const QString & | section = "Desktop Entry" , |
||
const QString & | defaultValue = QString() |
||
) | const |
返回 section
中与给定 key
关联的原始字符串值。如果desktop不包含具有该键的项, 则函数返回一个构造好的 defaultValue
。
section
中与给定 key
相关联的原始字符串值。 bool Dtk::Core::DDesktopEntry::save | ( | ) | const |
将数据回写到desktop文件。
Status Dtk::Core::DDesktopEntry::status | ( | ) | const |
Get data parse status
QStringList Dtk::Core::DDesktopEntry::stringListValue | ( | const QString & | key, |
const QString & | section = "Desktop Entry" |
||
) | const |
返回给定 section
中与给定 key
关联的字符串的列表。如果destkop不包含为该键的项,则函数返回一个空字符串列表。
section
中与给定 key
关联的字符串的列表。 QString Dtk::Core::DDesktopEntry::stringValue | ( | const QString & | key, |
const QString & | section = "Desktop Entry" , |
||
const QString & | defaultValue = QString() |
||
) | const |
返回 section
与给定 key
关联的未转义字符串值。如果desktop不包含键值为0的项, 则函数返回一个构造好的 defaultValue
。
section
中与给定 key
相关联的未转义字符串值。
|
static |
对于类型为string和localestring的值,支持转义序列\s
、\n
、\t
、\r
和\\
,分别表示ASCII空格、换行符、制表符、回车符和反斜杠。
有些键可以有多个值。这种情况下,key
的值被指定为复数形式: 例如,字符串。多个值应该用分号分隔,key
的值可以选择以分号结尾。空字符串必须以分号结尾。 这些值中的分号需要使用\;
转义。
有关该规范本身的更多详细信息,请参阅: https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#value-types
|
static |
必须将参数括在双引号之间,并对双引号字符进行转义,
原字符 | 转义后 |
---|---|
` | "`" |
$ | "$" |
\ | "\" |
在它前面加上一个额外的反斜杠字符。实现必须在扩展字段代码之前和之前撤销引用,将参数传递给可执行程序。
保留字符:
功能 | 字符 |
---|---|
space | " " |
tab | |
newline | |
double quote | |
single quote | "'" |
backslash character | "\" |
greater-than sign | ">" |
less-than sign | "<" |
tilde | "~" |
vertical bar | | |
ampersand | "&" |
semicolon | ";" |
dollar sign | "$" |
asterisk | "*" |
question mark | "?" |
hash mark | "#" |
parenthesis | "(" 和 ")" |
backtick character | "`" |