feat: add method SendToDesktop/RemoveFromDesktop, Property isOnDesktop
Signed-off-by: ComixHe <heyuming@deepin.org>
This commit is contained in:
parent
40babe8aae
commit
ca24d2d908
@ -92,5 +92,16 @@
|
|||||||
`env` option will not take effect at all."
|
`env` option will not take effect at all."
|
||||||
/>
|
/>
|
||||||
</method>
|
</method>
|
||||||
|
|
||||||
|
<property name="isOnDesktop" type="b" access="read"/>
|
||||||
|
|
||||||
|
<method name="SendToDesktop">
|
||||||
|
<arg type="b" name="success" direction="out"/>
|
||||||
|
</method>
|
||||||
|
|
||||||
|
<method name="RemoveFromDesktop">
|
||||||
|
<arg type="b" name="success" direction="out"/>
|
||||||
|
</method>
|
||||||
|
|
||||||
</interface>
|
</interface>
|
||||||
</node>
|
</node>
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
|
#include <QStandardPaths>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <new>
|
#include <new>
|
||||||
|
|
||||||
@ -186,6 +187,71 @@ QDBusObjectPath ApplicationService::Launch(const QString &action, const QStringL
|
|||||||
std::move(res));
|
std::move(res));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ApplicationService::SendToDesktop() const noexcept
|
||||||
|
{
|
||||||
|
if (isOnDesktop()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto dir = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
|
||||||
|
if (dir.isEmpty()) {
|
||||||
|
qDebug() << "no desktop directory found.";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto desktopFile = QDir{dir}.filePath(m_desktopSource.desktopId() + ".desktop");
|
||||||
|
auto success = m_desktopSource.sourceFileRef().link(desktopFile);
|
||||||
|
if (!success) {
|
||||||
|
qDebug() << "create link failed:" << m_desktopSource.sourceFileRef().errorString() << "path:" << desktopFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ApplicationService::RemoveFromDesktop() const noexcept
|
||||||
|
{
|
||||||
|
if (!isOnDesktop()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto dir = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
|
||||||
|
if (dir.isEmpty()) {
|
||||||
|
qDebug() << "no desktop directory found.";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
QFile desktopFile{QDir{dir}.filePath(m_desktopSource.desktopId() + ".desktop")};
|
||||||
|
auto success = desktopFile.remove();
|
||||||
|
|
||||||
|
if (!success) {
|
||||||
|
qDebug() << "remove desktop file failed:" << desktopFile.errorString();
|
||||||
|
}
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ApplicationService::isOnDesktop() const noexcept
|
||||||
|
{
|
||||||
|
auto dir = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
|
||||||
|
|
||||||
|
if (dir.isEmpty()) {
|
||||||
|
qDebug() << "no desktop directory found.";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
QFileInfo info{QDir{dir}.filePath(m_desktopSource.desktopId() + ".desktop")};
|
||||||
|
|
||||||
|
if (!info.exists()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!info.isSymbolicLink()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return info.symLinkTarget() == m_desktopSource.sourcePath();
|
||||||
|
}
|
||||||
|
|
||||||
QStringList ApplicationService::actions() const noexcept
|
QStringList ApplicationService::actions() const noexcept
|
||||||
{
|
{
|
||||||
auto val = findEntryValue(DesktopFileEntryKey, "Actions", EntryValueType::String);
|
auto val = findEntryValue(DesktopFileEntryKey, "Actions", EntryValueType::String);
|
||||||
|
@ -69,6 +69,9 @@ public:
|
|||||||
Q_PROPERTY(qulonglong installedTime READ installedTime)
|
Q_PROPERTY(qulonglong installedTime READ installedTime)
|
||||||
[[nodiscard]] qulonglong installedTime() const noexcept;
|
[[nodiscard]] qulonglong installedTime() const noexcept;
|
||||||
|
|
||||||
|
Q_PROPERTY(bool isOnDesktop READ isOnDesktop)
|
||||||
|
[[nodiscard]] bool isOnDesktop() const noexcept;
|
||||||
|
|
||||||
[[nodiscard]] QDBusObjectPath findInstance(const QString &instanceId) const;
|
[[nodiscard]] QDBusObjectPath findInstance(const QString &instanceId) const;
|
||||||
|
|
||||||
[[nodiscard]] const QString &getLauncher() const noexcept { return m_launcher; }
|
[[nodiscard]] const QString &getLauncher() const noexcept { return m_launcher; }
|
||||||
@ -89,6 +92,8 @@ public:
|
|||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
QDBusObjectPath Launch(const QString &action, const QStringList &fields, const QVariantMap &options);
|
QDBusObjectPath Launch(const QString &action, const QStringList &fields, const QVariantMap &options);
|
||||||
[[nodiscard]] ObjectMap GetManagedObjects() const;
|
[[nodiscard]] ObjectMap GetManagedObjects() const;
|
||||||
|
[[nodiscard]] bool SendToDesktop() const noexcept;
|
||||||
|
[[nodiscard]] bool RemoveFromDesktop() const noexcept;
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void InterfacesAdded(const QDBusObjectPath &object_path, const ObjectInterfaceMap &interfaces);
|
void InterfacesAdded(const QDBusObjectPath &object_path, const ObjectInterfaceMap &interfaces);
|
||||||
|
Loading…
Reference in New Issue
Block a user