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 APPLICATIONMANAGER1SERVICE_H
|
|
|
|
#define APPLICATIONMANAGER1SERVICE_H
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QDBusObjectPath>
|
|
|
|
#include <QDBusUnixFileDescriptor>
|
2023-07-17 14:49:35 +08:00
|
|
|
#include <QSharedPointer>
|
2023-07-24 14:12:59 +08:00
|
|
|
#include <QScopedPointer>
|
|
|
|
#include <memory>
|
2023-07-17 14:49:35 +08:00
|
|
|
#include <QMap>
|
2023-09-13 11:47:04 +08:00
|
|
|
#include "applicationmanagerstorage.h"
|
2023-08-07 14:25:22 +08:00
|
|
|
#include "dbus/jobmanager1service.h"
|
2023-09-20 18:29:42 +08:00
|
|
|
#include "dbus/mimemanager1service.h"
|
2023-08-21 16:02:26 +08:00
|
|
|
#include "desktopentry.h"
|
2023-07-24 14:12:59 +08:00
|
|
|
#include "identifier.h"
|
2023-07-10 10:18:33 +08:00
|
|
|
|
2023-08-21 16:02:26 +08:00
|
|
|
class ApplicationService;
|
|
|
|
|
2023-10-16 14:39:20 +08:00
|
|
|
class ApplicationManager1Service final : public QObject, public QDBusContext
|
2023-07-10 10:18:33 +08:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2023-09-13 11:47:04 +08:00
|
|
|
explicit ApplicationManager1Service(std::unique_ptr<Identifier> ptr,
|
|
|
|
std::weak_ptr<ApplicationManager1Storage> storage) noexcept;
|
2023-07-17 14:49:35 +08:00
|
|
|
~ApplicationManager1Service() override;
|
|
|
|
ApplicationManager1Service(const ApplicationManager1Service &) = delete;
|
|
|
|
ApplicationManager1Service(ApplicationManager1Service &&) = delete;
|
|
|
|
ApplicationManager1Service &operator=(const ApplicationManager1Service &) = delete;
|
2023-07-21 14:47:40 +08:00
|
|
|
ApplicationManager1Service &operator=(ApplicationManager1Service &&) = delete;
|
2023-07-10 10:18:33 +08:00
|
|
|
|
2023-09-08 10:58:41 +08:00
|
|
|
Q_PROPERTY(QList<QDBusObjectPath> List READ list NOTIFY listChanged)
|
2023-08-10 14:32:09 +08:00
|
|
|
[[nodiscard]] QList<QDBusObjectPath> list() const;
|
2023-08-16 17:44:56 +08:00
|
|
|
|
2023-09-14 13:38:44 +08:00
|
|
|
void initService(QDBusConnection &connection) noexcept;
|
2023-08-20 18:25:59 +08:00
|
|
|
bool addApplication(DesktopFile desktopFileSource) noexcept;
|
|
|
|
void removeOneApplication(const QDBusObjectPath &application) noexcept;
|
|
|
|
void removeAllApplication() noexcept;
|
2023-09-20 18:29:42 +08:00
|
|
|
[[nodiscard]] QMap<QDBusObjectPath, QSharedPointer<ApplicationService>>
|
|
|
|
findApplicationsByIds(const QStringList &appIds) const noexcept;
|
2023-09-13 16:52:53 +08:00
|
|
|
void updateApplication(const QSharedPointer<ApplicationService> &destApp, DesktopFile desktopFile) noexcept;
|
2023-08-11 17:46:46 +08:00
|
|
|
|
2023-10-07 15:15:08 +08:00
|
|
|
[[nodiscard]] JobManager1Service &jobManager() noexcept { return *m_jobManager; }
|
|
|
|
[[nodiscard]] const JobManager1Service &jobManager() const noexcept { return *m_jobManager; }
|
|
|
|
[[nodiscard]] const QStringList &applicationHooks() const noexcept { return m_hookElements; }
|
2023-09-20 18:29:42 +08:00
|
|
|
[[nodiscard]] MimeManager1Service &mimeManager() noexcept { return *m_mimeManager; }
|
|
|
|
[[nodiscard]] const MimeManager1Service &mimeManager() const noexcept { return *m_mimeManager; }
|
2023-07-24 14:12:59 +08:00
|
|
|
|
2023-07-10 10:18:33 +08:00
|
|
|
public Q_SLOTS:
|
2023-09-14 17:16:10 +08:00
|
|
|
QString Identify(const QDBusUnixFileDescriptor &pidfd,
|
|
|
|
QDBusObjectPath &instance,
|
|
|
|
ObjectInterfaceMap &application_instance_info) const noexcept;
|
2023-09-06 12:06:34 +08:00
|
|
|
void ReloadApplications();
|
2023-10-16 14:39:20 +08:00
|
|
|
QString addUserApplication(const QVariantMap &desktop_file, const QString &name) noexcept;
|
2023-08-18 10:01:52 +08:00
|
|
|
[[nodiscard]] ObjectMap GetManagedObjects() const;
|
|
|
|
|
|
|
|
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 listChanged();
|
2023-07-17 14:49:35 +08:00
|
|
|
|
|
|
|
private:
|
2023-07-24 14:12:59 +08:00
|
|
|
std::unique_ptr<Identifier> m_identifier;
|
2023-09-13 11:47:04 +08:00
|
|
|
std::weak_ptr<ApplicationManager1Storage> m_storage;
|
2023-09-20 18:29:42 +08:00
|
|
|
QScopedPointer<MimeManager1Service> m_mimeManager{nullptr};
|
2023-07-24 14:12:59 +08:00
|
|
|
QScopedPointer<JobManager1Service> m_jobManager{nullptr};
|
2023-10-07 15:15:08 +08:00
|
|
|
QStringList m_hookElements;
|
2023-07-21 14:47:40 +08:00
|
|
|
QMap<QDBusObjectPath, QSharedPointer<ApplicationService>> m_applicationList;
|
2023-08-28 17:57:21 +08:00
|
|
|
|
2023-09-20 18:29:42 +08:00
|
|
|
void scanMimeInfos() noexcept;
|
2023-08-28 17:57:21 +08:00
|
|
|
void scanApplications() noexcept;
|
|
|
|
void scanInstances() noexcept;
|
2023-09-04 18:39:09 +08:00
|
|
|
void scanAutoStart() noexcept;
|
2023-10-07 15:15:08 +08:00
|
|
|
void loadHooks() noexcept;
|
2023-08-28 17:57:21 +08:00
|
|
|
void addInstanceToApplication(const QString &unitName, const QDBusObjectPath &systemdUnitPath);
|
|
|
|
void removeInstanceFromApplication(const QString &unitName, const QDBusObjectPath &systemdUnitPath);
|
2023-07-10 10:18:33 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|