feat: add categories for application service
Signed-off-by: ComixHe <heyuming@deepin.org>
This commit is contained in:
parent
0896f845a6
commit
8ab6adc290
@ -6,6 +6,8 @@
|
|||||||
value="This interface is designed to provide a dbus interface of desktop file. Missing fields will be added later."
|
value="This interface is designed to provide a dbus interface of desktop file. Missing fields will be added later."
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<property name="Categories" type="as" access="read"/>
|
||||||
|
|
||||||
<property name="Actions" type="as" access="read">
|
<property name="Actions" type="as" access="read">
|
||||||
<annotation
|
<annotation
|
||||||
name="org.freedesktop.DBus.Description"
|
name="org.freedesktop.DBus.Description"
|
||||||
|
@ -202,27 +202,27 @@ QDBusObjectPath ApplicationService::Launch(const QString &action, const QStringL
|
|||||||
|
|
||||||
QStringList ApplicationService::actions() const noexcept
|
QStringList ApplicationService::actions() const noexcept
|
||||||
{
|
{
|
||||||
if (m_entry.isNull()) {
|
auto val = findEntryValue(DesktopFileEntryKey, "Actions", EntryValueType::String);
|
||||||
qWarning() << "desktop entry is empty, source file:" << m_desktopSource.sourcePath();
|
|
||||||
|
if (val.isNull()) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto &actions = m_entry->value(DesktopFileEntryKey, "Actions");
|
auto actionList = val.toString().split(";", Qt::SkipEmptyParts);
|
||||||
if (!actions) {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ok{false};
|
|
||||||
const auto &str = actions->toString(ok);
|
|
||||||
if (!ok) {
|
|
||||||
qWarning() << "Actions convert to String failed.";
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
auto actionList = str.split(";", Qt::SkipEmptyParts);
|
|
||||||
return actionList;
|
return actionList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QStringList ApplicationService::categories() const noexcept
|
||||||
|
{
|
||||||
|
auto val = findEntryValue(DesktopFileEntryKey, "Categories", EntryValueType::String);
|
||||||
|
|
||||||
|
if (val.isNull()) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
return val.toString().split(';', Qt::SkipEmptyParts);
|
||||||
|
}
|
||||||
|
|
||||||
PropMap ApplicationService::actionName() const noexcept
|
PropMap ApplicationService::actionName() const noexcept
|
||||||
{
|
{
|
||||||
PropMap ret;
|
PropMap ret;
|
||||||
@ -477,3 +477,47 @@ LaunchTask ApplicationService::unescapeExec(const QString &str, const QStringLis
|
|||||||
|
|
||||||
return task;
|
return task;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QVariant ApplicationService::findEntryValue(const QString &group,
|
||||||
|
const QString &valueKey,
|
||||||
|
EntryValueType type,
|
||||||
|
const QLocale &locale) const noexcept
|
||||||
|
{
|
||||||
|
QVariant ret;
|
||||||
|
auto tmp = m_entry->value(group, valueKey);
|
||||||
|
if (!tmp.has_value()) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto val = std::move(tmp).value();
|
||||||
|
bool ok{false};
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case EntryValueType::String: {
|
||||||
|
auto valStr = val.toString(ok);
|
||||||
|
if (ok) {
|
||||||
|
ret = QVariant::fromValue(valStr);
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
case EntryValueType::LocaleString: {
|
||||||
|
auto valStr = val.toLocaleString(locale, ok);
|
||||||
|
if (ok) {
|
||||||
|
ret = QVariant::fromValue(valStr);
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
case EntryValueType::Boolean: {
|
||||||
|
auto valBool = val.toBoolean(ok);
|
||||||
|
if (ok) {
|
||||||
|
ret = QVariant::fromValue(valBool);
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
case EntryValueType::IconString: {
|
||||||
|
auto valStr = val.toIconString(ok);
|
||||||
|
if (ok) {
|
||||||
|
ret = QVariant::fromValue(valStr);
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
@ -32,6 +32,9 @@ public:
|
|||||||
ApplicationService &operator=(const ApplicationService &) = delete;
|
ApplicationService &operator=(const ApplicationService &) = delete;
|
||||||
ApplicationService &operator=(ApplicationService &&) = delete;
|
ApplicationService &operator=(ApplicationService &&) = delete;
|
||||||
|
|
||||||
|
Q_PROPERTY(QStringList Categories READ categories)
|
||||||
|
[[nodiscard]] QStringList categories() const noexcept;
|
||||||
|
|
||||||
Q_PROPERTY(QStringList Actions READ actions)
|
Q_PROPERTY(QStringList Actions READ actions)
|
||||||
[[nodiscard]] QStringList actions() const noexcept;
|
[[nodiscard]] QStringList actions() const noexcept;
|
||||||
|
|
||||||
@ -96,6 +99,10 @@ private:
|
|||||||
QMap<QDBusObjectPath, QSharedPointer<InstanceService>> m_Instances;
|
QMap<QDBusObjectPath, QSharedPointer<InstanceService>> m_Instances;
|
||||||
static QString userNameLookup(uid_t uid);
|
static QString userNameLookup(uid_t uid);
|
||||||
[[nodiscard]] LaunchTask unescapeExec(const QString &str, const QStringList &fields);
|
[[nodiscard]] LaunchTask unescapeExec(const QString &str, const QStringList &fields);
|
||||||
|
[[nodiscard]] QVariant findEntryValue(const QString &group,
|
||||||
|
const QString &valueKey,
|
||||||
|
EntryValueType type,
|
||||||
|
const QLocale &locale = getUserLocale()) const noexcept;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -29,6 +29,8 @@ enum class DesktopErrorCode {
|
|||||||
|
|
||||||
enum class EntryContext { Unknown, EntryOuter, Entry, Done };
|
enum class EntryContext { Unknown, EntryOuter, Entry, Done };
|
||||||
|
|
||||||
|
enum class EntryValueType { String, LocaleString, Boolean, IconString };
|
||||||
|
|
||||||
struct DesktopFileGuard;
|
struct DesktopFileGuard;
|
||||||
|
|
||||||
struct DesktopFile
|
struct DesktopFile
|
||||||
|
Loading…
Reference in New Issue
Block a user