File indexing completed on 2024-11-24 04:54:59

0001 /*
0002  *   SPDX-FileCopyrightText: 2012 Aleix Pol Gonzalez <aleixpol@blue-systems.com>
0003  *
0004  *   SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005  */
0006 
0007 #pragma once
0008 
0009 #include <KService>
0010 #include <PackageKit/Details>
0011 #include <PackageKit/Transaction>
0012 #include <resources/AbstractResource.h>
0013 
0014 class PackageKitBackend;
0015 
0016 class PackageKitResource : public AbstractResource
0017 {
0018     Q_OBJECT
0019 
0020 public:
0021     explicit PackageKitResource(QString packageName, QString summary, PackageKitBackend *parent);
0022     QString packageName() const override;
0023     QString name() const override;
0024     QString comment() override;
0025     QString longDescription() override;
0026     QUrl homepage() override;
0027     QVariant icon() const override;
0028     QStringList categories() override;
0029     QJsonArray licenses() override;
0030     QString origin() const override;
0031     QString section() override;
0032     AbstractResource::Type type() const override;
0033     quint64 size() override;
0034     void fetchChangelog() override;
0035     void fetchUpdateDetails() override;
0036 
0037     QList<PackageState> addonsInformation() override;
0038     State state() override;
0039 
0040     QString installedVersion() const override;
0041     QString availableVersion() const override;
0042     QString author() const override
0043     {
0044         return {};
0045     }
0046     virtual QStringList allPackageNames() const;
0047     QString installedPackageId() const;
0048     QString availablePackageId() const;
0049 
0050     void clearPackageIds()
0051     {
0052         m_packages.clear();
0053     }
0054 
0055     PackageKitBackend *backend() const;
0056 
0057     static QString joinPackages(const QStringList &pkgids, const QString &_sep, const QString &shadowPackageName);
0058 
0059     /**
0060      * Critical packages are those that might render an installation unusable if removed
0061      */
0062     virtual bool isCritical() const;
0063 
0064     void invokeApplication() const override
0065     {
0066     }
0067     bool canExecute() const override
0068     {
0069         return false;
0070     }
0071 
0072     QString sizeDescription() override;
0073     void setDependenciesCount(int count);
0074 
0075     QString sourceIcon() const override;
0076 
0077     QDate releaseDate() const override
0078     {
0079         return {};
0080     }
0081 
0082     QStringList topObjects() const override;
0083 
0084     virtual QString changelog() const
0085     {
0086         return m_changelog;
0087     }
0088 
0089     bool extendsItself() const;
0090 
0091     void runService(KService::Ptr service) const;
0092     bool containsPackageId(const QString &pkgid) const;
0093 
0094 Q_SIGNALS:
0095     void dependenciesFound(const QJsonArray &dependencies);
0096 
0097 public Q_SLOTS:
0098     void addPackageId(PackageKit::Transaction::Info info, const QString &packageId, bool arch);
0099     void setDetails(const PackageKit::Details &details);
0100 
0101     void updateDetail(const QString &packageID,
0102                       const QStringList &updates,
0103                       const QStringList &obsoletes,
0104                       const QStringList &vendorUrls,
0105                       const QStringList &bugzillaUrls,
0106                       const QStringList &cveUrls,
0107                       PackageKit::Transaction::Restart restart,
0108                       const QString &updateText,
0109                       const QString &changelog,
0110                       PackageKit::Transaction::UpdateState state,
0111                       const QDateTime &issued,
0112                       const QDateTime &updated);
0113 
0114     void failedFetchingDetails(PackageKit::Transaction::Error, const QString &msg);
0115 
0116 protected:
0117     PackageKit::Details m_details;
0118 
0119 private:
0120     void fetchDependencies();
0121     /** fetches details individually, it's better if done in batch, like for updates */
0122     virtual void fetchDetails();
0123 
0124     struct Ids {
0125         QVector<QString> archPkgIds;
0126         QVector<QString> nonarchPkgIds;
0127 
0128         QString first() const
0129         {
0130             return !archPkgIds.isEmpty() ? archPkgIds.first() : nonarchPkgIds.first();
0131         }
0132 
0133         bool isEmpty() const
0134         {
0135             return archPkgIds.isEmpty() && nonarchPkgIds.isEmpty();
0136         }
0137     };
0138     QMap<PackageKit::Transaction::Info, Ids> m_packages;
0139     const QString m_summary;
0140     const QString m_name;
0141     QString m_changelog;
0142     int m_dependenciesCount = -1;
0143     static const QStringList s_topObjects;
0144 };