2023-07-10 10:18:33 +08:00
|
|
|
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
|
|
|
|
|
|
#ifndef APPLICATIONSERVICE_H
|
|
|
|
#define APPLICATIONSERVICE_H
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QDBusObjectPath>
|
2023-07-17 14:49:35 +08:00
|
|
|
#include <QMap>
|
|
|
|
#include <QString>
|
|
|
|
#include <QDBusUnixFileDescriptor>
|
|
|
|
#include <QSharedPointer>
|
2023-07-24 14:12:59 +08:00
|
|
|
#include <QUuid>
|
|
|
|
#include <QTextStream>
|
2023-08-23 17:20:47 +08:00
|
|
|
#include <QDBusContext>
|
2023-07-24 14:12:59 +08:00
|
|
|
#include <QFile>
|
2023-08-16 17:44:56 +08:00
|
|
|
#include <memory>
|
2023-08-20 18:25:59 +08:00
|
|
|
#include <utility>
|
2023-09-13 11:47:04 +08:00
|
|
|
#include "applicationmanagerstorage.h"
|
2023-10-07 15:15:08 +08:00
|
|
|
#include "dbus/applicationmanager1service.h"
|
2023-08-07 14:25:22 +08:00
|
|
|
#include "dbus/instanceservice.h"
|
2023-07-17 14:49:35 +08:00
|
|
|
#include "global.h"
|
2023-07-24 14:12:59 +08:00
|
|
|
#include "desktopentry.h"
|
2023-08-07 14:25:22 +08:00
|
|
|
#include "dbus/jobmanager1service.h"
|
2023-09-20 18:29:42 +08:00
|
|
|
#include "applicationmanager1service.h"
|
2023-07-10 10:18:33 +08:00
|
|
|
|
2023-09-07 15:55:25 +08:00
|
|
|
QString getDeepinWineScaleFactor(const QString &appId) noexcept;
|
2023-10-08 17:18:06 +08:00
|
|
|
double getScaleFactor() noexcept;
|
2023-09-07 15:55:25 +08:00
|
|
|
|
2023-08-23 17:20:47 +08:00
|
|
|
class ApplicationService : public QObject, public QDBusContext
|
2023-07-10 10:18:33 +08:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2023-07-17 14:49:35 +08:00
|
|
|
~ApplicationService() override;
|
2023-07-21 14:47:40 +08:00
|
|
|
ApplicationService(const ApplicationService &) = delete;
|
2023-07-17 14:49:35 +08:00
|
|
|
ApplicationService(ApplicationService &&) = delete;
|
2023-07-21 14:47:40 +08:00
|
|
|
ApplicationService &operator=(const ApplicationService &) = delete;
|
2023-07-17 14:49:35 +08:00
|
|
|
ApplicationService &operator=(ApplicationService &&) = delete;
|
|
|
|
|
2023-09-15 13:49:34 +08:00
|
|
|
Q_PROPERTY(QStringList Categories READ categories NOTIFY categoriesChanged)
|
2023-08-30 15:21:20 +08:00
|
|
|
[[nodiscard]] QStringList categories() const noexcept;
|
|
|
|
|
2023-09-15 13:49:34 +08:00
|
|
|
Q_PROPERTY(QStringList Actions READ actions NOTIFY actionsChanged)
|
2023-08-10 14:32:09 +08:00
|
|
|
[[nodiscard]] QStringList actions() const noexcept;
|
2023-07-17 14:49:35 +08:00
|
|
|
|
2023-09-15 13:49:34 +08:00
|
|
|
Q_PROPERTY(PropMap ActionName READ actionName NOTIFY actionNameChanged)
|
2023-08-25 10:47:17 +08:00
|
|
|
[[nodiscard]] PropMap actionName() const noexcept;
|
|
|
|
|
2023-07-24 14:12:59 +08:00
|
|
|
Q_PROPERTY(QString ID READ id CONSTANT)
|
2023-08-10 14:32:09 +08:00
|
|
|
[[nodiscard]] QString id() const noexcept;
|
2023-07-17 14:49:35 +08:00
|
|
|
|
2023-09-27 16:19:12 +08:00
|
|
|
Q_PROPERTY(PropMap Name READ name NOTIFY nameChanged)
|
|
|
|
[[nodiscard]] PropMap name() const noexcept;
|
|
|
|
|
|
|
|
Q_PROPERTY(PropMap GenericName READ genericName NOTIFY genericNameChanged)
|
|
|
|
[[nodiscard]] PropMap genericName() const noexcept;
|
2023-08-25 10:47:17 +08:00
|
|
|
|
2023-09-15 13:49:34 +08:00
|
|
|
Q_PROPERTY(PropMap Icons READ icons NOTIFY iconsChanged)
|
2023-08-29 13:28:25 +08:00
|
|
|
[[nodiscard]] PropMap icons() const noexcept;
|
2023-08-25 10:47:17 +08:00
|
|
|
|
2023-09-15 13:49:34 +08:00
|
|
|
Q_PROPERTY(qulonglong LastLaunchedTime READ lastLaunchedTime NOTIFY lastLaunchedTimeChanged)
|
2023-08-23 17:20:47 +08:00
|
|
|
[[nodiscard]] qulonglong lastLaunchedTime() const noexcept;
|
|
|
|
|
2023-10-08 17:18:06 +08:00
|
|
|
Q_PROPERTY(double ScaleFactor READ scaleFactor WRITE setScaleFactor NOTIFY scaleFactorChanged)
|
|
|
|
[[nodiscard]] double scaleFactor() const noexcept;
|
|
|
|
void setScaleFactor(double value) noexcept;
|
|
|
|
|
|
|
|
Q_PROPERTY(bool Terminal READ terminal NOTIFY terminalChanged)
|
|
|
|
[[nodiscard]] bool terminal() const noexcept;
|
|
|
|
|
2023-09-06 13:22:01 +08:00
|
|
|
// FIXME:
|
|
|
|
// This property should implement with fuse guarded $XDG_CONFIG_HOME/autostart/.
|
|
|
|
// Current implementation has some problems,
|
2023-09-08 10:58:41 +08:00
|
|
|
Q_PROPERTY(bool AutoStart READ isAutoStart WRITE setAutoStart NOTIFY autostartChanged)
|
2023-08-10 14:32:09 +08:00
|
|
|
[[nodiscard]] bool isAutoStart() const noexcept;
|
2023-07-17 14:49:35 +08:00
|
|
|
void setAutoStart(bool autostart) noexcept;
|
|
|
|
|
2023-09-20 18:29:42 +08:00
|
|
|
Q_PROPERTY(QStringList MimeTypes READ mimeTypes WRITE setMimeTypes)
|
|
|
|
[[nodiscard]] QStringList mimeTypes() const noexcept;
|
|
|
|
void setMimeTypes(const QStringList &value) noexcept;
|
|
|
|
|
2023-09-15 13:49:34 +08:00
|
|
|
Q_PROPERTY(QList<QDBusObjectPath> Instances READ instances NOTIFY instanceChanged)
|
2023-08-10 14:32:09 +08:00
|
|
|
[[nodiscard]] QList<QDBusObjectPath> instances() const noexcept;
|
2023-07-17 14:49:35 +08:00
|
|
|
|
2023-09-15 13:49:34 +08:00
|
|
|
Q_PROPERTY(bool X_Flatpak READ x_Flatpak NOTIFY x_FlatpakChanged)
|
2023-08-31 16:40:29 +08:00
|
|
|
[[nodiscard]] bool x_Flatpak() const noexcept;
|
|
|
|
|
2023-09-15 13:49:34 +08:00
|
|
|
Q_PROPERTY(bool X_linglong READ x_linglong NOTIFY x_linglongChanged)
|
2023-08-31 16:40:29 +08:00
|
|
|
[[nodiscard]] bool x_linglong() const noexcept;
|
|
|
|
|
2023-09-15 13:49:34 +08:00
|
|
|
Q_PROPERTY(qulonglong installedTime READ installedTime NOTIFY installedTimeChanged)
|
2023-08-31 16:40:29 +08:00
|
|
|
[[nodiscard]] qulonglong installedTime() const noexcept;
|
|
|
|
|
2023-09-15 13:49:34 +08:00
|
|
|
Q_PROPERTY(bool isOnDesktop READ isOnDesktop NOTIFY isOnDesktopChanged)
|
2023-09-01 15:48:29 +08:00
|
|
|
[[nodiscard]] bool isOnDesktop() const noexcept;
|
|
|
|
|
2023-09-15 13:49:34 +08:00
|
|
|
Q_PROPERTY(bool NoDisplay READ noDisplay NOTIFY noDisplayChanged)
|
2023-09-07 12:01:08 +08:00
|
|
|
[[nodiscard]] bool noDisplay() const noexcept;
|
|
|
|
|
2023-08-10 14:32:09 +08:00
|
|
|
[[nodiscard]] QDBusObjectPath findInstance(const QString &instanceId) const;
|
2023-07-24 14:12:59 +08:00
|
|
|
|
2023-08-10 14:32:09 +08:00
|
|
|
[[nodiscard]] const QString &getLauncher() const noexcept { return m_launcher; }
|
2023-07-24 14:12:59 +08:00
|
|
|
void setLauncher(const QString &launcher) noexcept { m_launcher = launcher; }
|
|
|
|
|
2023-09-13 16:52:53 +08:00
|
|
|
bool addOneInstance(const QString &instanceId,
|
|
|
|
const QString &application,
|
|
|
|
const QString &systemdUnitPath,
|
|
|
|
const QString &launcher);
|
2023-08-20 18:25:59 +08:00
|
|
|
void recoverInstances(const QList<QDBusObjectPath> &instanceList) noexcept;
|
|
|
|
void removeOneInstance(const QDBusObjectPath &instance) noexcept;
|
|
|
|
void removeAllInstance() noexcept;
|
|
|
|
[[nodiscard]] const QDBusObjectPath &applicationPath() const noexcept { return m_applicationPath; }
|
2023-08-21 16:02:26 +08:00
|
|
|
[[nodiscard]] DesktopFile &desktopFileSource() noexcept { return m_desktopSource; }
|
2023-08-20 18:25:59 +08:00
|
|
|
[[nodiscard]] const QMap<QDBusObjectPath, QSharedPointer<InstanceService>> &applicationInstances() const noexcept
|
|
|
|
{
|
|
|
|
return m_Instances;
|
|
|
|
}
|
|
|
|
void resetEntry(DesktopEntry *newEntry) noexcept;
|
2023-09-14 17:16:10 +08:00
|
|
|
void detachAllInstance() noexcept;
|
2023-07-10 10:18:33 +08:00
|
|
|
|
2023-10-08 17:18:06 +08:00
|
|
|
private Q_SLOTS:
|
|
|
|
void onGlobalScaleFactorChanged() noexcept;
|
|
|
|
|
2023-07-10 10:18:33 +08:00
|
|
|
public Q_SLOTS:
|
2023-08-20 18:25:59 +08:00
|
|
|
QDBusObjectPath Launch(const QString &action, const QStringList &fields, const QVariantMap &options);
|
2023-08-18 10:01:52 +08:00
|
|
|
[[nodiscard]] ObjectMap GetManagedObjects() const;
|
2023-09-01 15:48:29 +08:00
|
|
|
[[nodiscard]] bool SendToDesktop() const noexcept;
|
|
|
|
[[nodiscard]] bool RemoveFromDesktop() const noexcept;
|
2023-08-18 10:01:52 +08:00
|
|
|
|
|
|
|
Q_SIGNALS:
|
2023-08-25 10:47:17 +08:00
|
|
|
void InterfacesAdded(const QDBusObjectPath &object_path, const ObjectInterfaceMap &interfaces);
|
2023-08-18 10:01:52 +08:00
|
|
|
void InterfacesRemoved(const QDBusObjectPath &object_path, const QStringList &interfaces);
|
2023-09-08 10:58:41 +08:00
|
|
|
void autostartChanged();
|
2023-09-15 13:49:34 +08:00
|
|
|
void noDisplayChanged();
|
|
|
|
void isOnDesktopChanged();
|
|
|
|
void installedTimeChanged();
|
|
|
|
void x_FlatpakChanged();
|
|
|
|
void x_linglongChanged();
|
|
|
|
void instanceChanged();
|
|
|
|
void lastLaunchedTimeChanged();
|
|
|
|
void iconsChanged();
|
2023-09-27 16:19:12 +08:00
|
|
|
void nameChanged();
|
|
|
|
void genericNameChanged();
|
2023-09-15 13:49:34 +08:00
|
|
|
void actionNameChanged();
|
|
|
|
void actionsChanged();
|
|
|
|
void categoriesChanged();
|
2023-09-20 18:29:42 +08:00
|
|
|
void MimeTypesChanged();
|
2023-10-08 17:18:06 +08:00
|
|
|
void terminalChanged();
|
|
|
|
void scaleFactorChanged();
|
2023-07-17 14:49:35 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
friend class ApplicationManager1Service;
|
2023-09-13 11:47:04 +08:00
|
|
|
explicit ApplicationService(DesktopFile source,
|
|
|
|
ApplicationManager1Service *parent,
|
|
|
|
std::weak_ptr<ApplicationManager1Storage> storage);
|
|
|
|
static QSharedPointer<ApplicationService> createApplicationService(
|
|
|
|
DesktopFile source, ApplicationManager1Service *parent, std::weak_ptr<ApplicationManager1Storage> storage) noexcept;
|
2023-10-08 17:18:06 +08:00
|
|
|
bool m_customScale{false};
|
2023-09-13 11:47:04 +08:00
|
|
|
qint64 m_lastLaunch{0};
|
2023-10-08 17:18:06 +08:00
|
|
|
double m_scaleFactor;
|
2023-09-13 11:47:04 +08:00
|
|
|
std::weak_ptr<ApplicationManager1Storage> m_storage;
|
2023-07-17 14:49:35 +08:00
|
|
|
QDBusObjectPath m_applicationPath;
|
2023-08-07 14:25:22 +08:00
|
|
|
QString m_launcher{getApplicationLauncherBinary()};
|
2023-08-20 18:25:59 +08:00
|
|
|
DesktopFile m_desktopSource;
|
2023-07-24 14:12:59 +08:00
|
|
|
QSharedPointer<DesktopEntry> m_entry{nullptr};
|
2023-07-21 14:47:40 +08:00
|
|
|
QMap<QDBusObjectPath, QSharedPointer<InstanceService>> m_Instances;
|
2023-07-24 14:12:59 +08:00
|
|
|
[[nodiscard]] LaunchTask unescapeExec(const QString &str, const QStringList &fields);
|
2023-08-30 15:21:20 +08:00
|
|
|
[[nodiscard]] QVariant findEntryValue(const QString &group,
|
|
|
|
const QString &valueKey,
|
|
|
|
EntryValueType type,
|
|
|
|
const QLocale &locale = getUserLocale()) const noexcept;
|
2023-09-14 17:16:10 +08:00
|
|
|
void updateAfterLaunch(bool isLaunch) noexcept;
|
2023-09-05 11:49:28 +08:00
|
|
|
static bool shouldBeShown(const std::unique_ptr<DesktopEntry> &entry) noexcept;
|
2023-09-15 14:44:27 +08:00
|
|
|
[[nodiscard]] bool autostartCheck(const QString &linkPath) const noexcept;
|
2023-10-07 15:15:08 +08:00
|
|
|
[[nodiscard]] ApplicationManager1Service *parent() { return dynamic_cast<ApplicationManager1Service *>(QObject::parent()); }
|
|
|
|
[[nodiscard]] const ApplicationManager1Service *parent() const
|
|
|
|
{
|
|
|
|
return dynamic_cast<ApplicationManager1Service *>(QObject::parent());
|
|
|
|
}
|
2023-07-10 10:18:33 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|