#ifndef PACKAGEMANAGEMENT_UPDATELOOKUP_H #define PACKAGEMANAGEMENT_UPDATELOOKUP_H #include "./package.h" #include #include #include #include namespace RepoIndex { class Manager; class UpgradeLookup; class UpgradeLookupProcess; class PackageReply; class UpgradeResult { public: UpgradeResult(const Package *package, const QString ¤tVersion); const Package *package; QString currentVersion; QJsonObject toJson() const; }; /*! * \brief Constructs a new upgrade result. */ inline UpgradeResult::UpgradeResult(const Package *package, const QString &previousVersion) : package(package), currentVersion(previousVersion) {} class UpgradeLookupResults { public: UpgradeLookupResults(); /*! * \brief Indicates that there are no upgrade sources available. */ bool noSources; /*! * \brief Packages providing a software upgrade (new version). */ QList newVersions; /*! * \brief Package upgrades only (new release). */ QList newReleases; /*! * \brief Downgrades (older version in sync db). */ QList downgrades; /*! * \brief Orphaned packages (could not be found in any of the sync dbs). */ QSet orphaned; /*! * \brief Warnings occured when checking for updates. */ QStringList warnings; /*! * \brief Errors occured when checking for updates. */ QStringList errors; }; /*! * \brief Constructs new update lookup results. */ inline UpgradeLookupResults::UpgradeLookupResults() : noSources(false) {} class UpgradeLookupProcess : public QObject { Q_OBJECT public: explicit UpgradeLookupProcess(UpgradeLookup *upgradeLookup, Repository *upgradeSource); const UpgradeLookupResults &results() const; Q_SIGNALS: void finished(); private Q_SLOTS: void requestSources(); void sourceReady(); void checkUpgrades(); private: bool ensureNotBusy(); const Repository *m_toCheck; Repository *m_upgradeSource; PackageReply *m_reply; QFutureWatcher *m_watcher; UpgradeLookupResults m_results; }; class UpgradeLookup : public QObject { Q_OBJECT friend class UpgradeLookupProcess; public: const Repository *toCheck() const; private Q_SLOTS: virtual void processFinished() = 0; protected: explicit UpgradeLookup(QObject *parent = nullptr); Repository *m_toCheck; unsigned int m_remainingProcesses; bool m_firstFinished; QSet m_orphanedPackages; }; /*! * \brief Returns the repository to be checked (if available; otherwise nullptr). */ inline const Repository *UpgradeLookup::toCheck() const { return m_toCheck; } class UpgradeLookupJson : public UpgradeLookup { Q_OBJECT public: explicit UpgradeLookupJson(Manager &manager, const QJsonObject &request, QObject *parent = nullptr); const QJsonArray &errors() const; QJsonArray results() const; bool finished() const; Q_SIGNALS: void resultsAvailable(const QJsonValue &what, const QJsonValue &id, const QJsonValue &value); private Q_SLOTS: virtual void processFinished(); private: const QJsonObject m_request; QJsonArray m_warningsArray; QJsonArray m_errorsArray; QJsonArray m_softwareUpgradesArray; QJsonArray m_packageOnlyUpgradesArray; QJsonArray m_downgradesArray; QJsonArray m_orphanedPackagesArray; }; inline const QJsonArray &UpgradeLookupJson::errors() const { return m_errorsArray; } inline QJsonArray UpgradeLookupJson::results() const { return QJsonArray(); // results are currently only returned by emitting resultsAvailable() } inline bool UpgradeLookupJson::finished() const { return !m_remainingProcesses && m_errorsArray.isEmpty(); } class UpgradeLookupCli : public UpgradeLookup { Q_OBJECT friend class UpgradeLookupProcess; public: explicit UpgradeLookupCli(Manager &manager, const std::string &repo, QObject *parent = nullptr); bool hasErrors() const; const Repository *toCheck() const; private Q_SLOTS: void processFinished(); private: void printResults(); QStringList m_warningsArray; QStringList m_errorsArray; QStringList m_softwareUpgradesArray; QStringList m_packageOnlyUpgradesArray; QStringList m_downgradesArray; QStringList m_orphanedPackagesArray; }; inline bool UpgradeLookupCli::hasErrors() const { return !m_errorsArray.isEmpty(); } } // namespace PackageManagement #endif // PACKAGEMANAGEMENT_UPDATELOOKUP_H