/* * SPDX-FileCopyrightText: 2012 Aleix Pol Gonzalez * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL */ #pragma once #include "PackageKitResource.h" #include #include #include #include #include #include #include #include #include #include #include #include class AppPackageKitResource; class PackageKitUpdater; class OdrsReviewsBackend; class PKResultsStream; class PKResolveTransaction; /** This is either a package name or an appstream id */ struct PackageOrAppId { QString id; bool isPackageName; }; PackageOrAppId makePackageId(const QString &id); PackageOrAppId makeAppId(const QString &id); class Delay : public QObject { Q_OBJECT public: Delay(); void add(const QString &pkgid) { if (!m_delay.isActive()) { m_delay.start(); } m_pkgids << pkgid; } void add(const QSet &pkgids) { if (!m_delay.isActive()) { m_delay.start(); } m_pkgids += pkgids; } Q_SIGNALS: void perform(const QSet &pkgids); private: QTimer m_delay; QSet m_pkgids; }; class DISCOVERCOMMON_EXPORT PackageKitBackend : public AbstractResourcesBackend { Q_OBJECT public: explicit PackageKitBackend(QObject *parent = nullptr); ~PackageKitBackend() override; AbstractBackendUpdater *backendUpdater() const override; AbstractReviewsBackend *reviewsBackend() const override; QSet resourcesByPackageName(const QString &name) const; ResultsStream *search(const AbstractResourcesBackend::Filters &search) override; PKResultsStream *findResourceByPackageName(const QUrl &search); int updatesCount() const override; bool hasSecurityUpdates() const override; Transaction *installApplication(AbstractResource *app) override; Transaction *installApplication(AbstractResource *app, const AddonList &addons) override; Transaction *removeApplication(AbstractResource *app) override; bool isValid() const override { return !QFile::exists(QStringLiteral("/run/ostree-booted")); } QSet upgradeablePackages() const; bool isFetching() const override; bool isPackageNameUpgradeable(const PackageKitResource *res) const; QSet upgradeablePackageId(const PackageKitResource *res) const; QVector extendedBy(const QString &id) const; PKResolveTransaction *resolvePackages(const QStringList &packageNames); void fetchDetails(const QString &pkgid); void fetchDetails(const QSet &pkgid); void checkForUpdates() override; QString displayName() const override; bool hasApplications() const override { return true; } static QString locateService(const QString &filename); AppStream::ComponentBox componentsById(const QString &id) const; void fetchUpdates(); int fetchingUpdatesProgress() const override; uint fetchingUpdatesProgressWeight() const override; InlineMessage *explainDysfunction() const override; void addPackageArch(PackageKit::Transaction::Info info, const QString &packageId, const QString &summary); void addPackageNotArch(PackageKit::Transaction::Info info, const QString &packageId, const QString &summary); void clear() { m_updatesPackageId.clear(); } Delay &updateDetails() { return m_updateDetails; } template T resourcesByPackageNames(const W &names) const; QStringList globalHints() { return m_globalHints; } void aboutTo(AboutToAction action) override; bool needsRebootForPowerOffAction() const override { return true; } public Q_SLOTS: void reloadPackageList(); void transactionError(PackageKit::Transaction::Error, const QString &message); private Q_SLOTS: void getPackagesFinished(); void addPackage(PackageKit::Transaction::Info info, const QString &packageId, const QString &summary, bool arch); void packageDetails(const PackageKit::Details &details); void addPackageToUpdate(PackageKit::Transaction::Info, const QString &pkgid, const QString &summary); void getUpdatesFinished(PackageKit::Transaction::Exit, uint); void loadAllPackages(); Q_SIGNALS: void loadedAppStream(); void available(); private: friend class PackageKitResource; template T resourcesByAppNames(const W &names) const; template T resourcesByComponents(const AppStream::ComponentBox &names) const; QVector resultsByComponents(const AppStream::ComponentBox &names) const; PKResultsStream *deferredResultStream(const QString &streamName, std::function callback); void checkDaemonRunning(); void acquireFetching(bool f); void includePackagesToAdd(); void performDetailsFetch(const QSet &pkgids); AppPackageKitResource *addComponent(const AppStream::Component &component) const; void updateProxy(); void foundNewMajorVersion(const AppStream::Release &release); QScopedPointer m_appdata; bool m_appdataLoaded = false; PackageKitUpdater *m_updater; QPointer m_refresher; int m_isFetching; QSet m_updatesPackageId; bool m_hasSecurityUpdates = false; mutable QHash m_packagesToAdd; QSet m_packagesToDelete; bool m_appstreamInitialized = false; mutable struct { QHash packages; QHash packageToApp; } m_packages; Delay m_details; Delay m_updateDetails; QSharedPointer m_reviews; QThreadPool m_threadPool; QPointer m_resolveTransaction; QStringList m_globalHints; bool m_allPackagesLoaded = false; DiscoverAction *m_reportToDistroAction; };