289 lines
6.9 KiB
C++
289 lines
6.9 KiB
C++
#ifndef PACKAGEMANAGEMENT_PACKAGESOURCE_H
|
|
#define PACKAGEMANAGEMENT_PACKAGESOURCE_H
|
|
|
|
#include "package.h"
|
|
#include "group.h"
|
|
|
|
#include <QObject>
|
|
|
|
#include <memory>
|
|
#include <functional>
|
|
|
|
QT_FORWARD_DECLARE_CLASS(QNetworkReply)
|
|
|
|
namespace PackageManagement {
|
|
|
|
class UpgradeLookupResults;
|
|
|
|
class Reply : public QObject
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
Reply(QNetworkReply *networkReply);
|
|
const QString &error() const;
|
|
|
|
signals:
|
|
void resultsAvailable();
|
|
|
|
private slots:
|
|
virtual void processData() = 0;
|
|
|
|
protected:
|
|
QNetworkReply *m_networkReply;
|
|
QString m_error;
|
|
};
|
|
|
|
inline const QString &Reply::error() const
|
|
{
|
|
return m_error;
|
|
}
|
|
|
|
class PackageReply : public Reply
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
PackageReply(QNetworkReply *networkReply, std::map<QString, std::unique_ptr<Package> > &packages);
|
|
const std::map<QString, std::unique_ptr<Package> > &packages() const;
|
|
|
|
protected:
|
|
std::map<QString, std::unique_ptr<Package> > &m_packages;
|
|
};
|
|
|
|
inline PackageReply::PackageReply(QNetworkReply *networkReply, std::map<QString, std::unique_ptr<Package> > &packages) :
|
|
Reply(networkReply),
|
|
m_packages(packages)
|
|
{}
|
|
|
|
inline const std::map<QString, std::unique_ptr<Package> > &PackageReply::packages() const
|
|
{
|
|
return m_packages;
|
|
}
|
|
|
|
class SuggestionsReply : public Reply
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
SuggestionsReply(QNetworkReply *networkReply);
|
|
const QJsonArray &suggestions() const;
|
|
|
|
protected:
|
|
QJsonArray m_suggestions;
|
|
};
|
|
|
|
inline SuggestionsReply::SuggestionsReply(QNetworkReply *networkReply) :
|
|
Reply(networkReply)
|
|
{}
|
|
|
|
inline const QJsonArray &SuggestionsReply::suggestions() const
|
|
{
|
|
return m_suggestions;
|
|
}
|
|
|
|
enum class RepositoryType
|
|
{
|
|
AlpmDataBase, /*! The repository is an AlpmDataBase instance. */
|
|
UserRepository, /*! The repository is a UserRepository instance. */
|
|
Other /*! The repository type is unknown. */
|
|
};
|
|
|
|
class Repository : public QObject
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
~Repository();
|
|
|
|
virtual RepositoryType type() const = 0;
|
|
|
|
// general meta data
|
|
const QString &name() const;
|
|
const QString &description() const;
|
|
const std::map<QString, std::unique_ptr<Package> > &packages() const;
|
|
std::map<QString, std::unique_ptr<Package> > &packages();
|
|
const QStringList packageNames() const;
|
|
alpm_db_usage_t usage() const;
|
|
virtual bool isSourceOnly() const;
|
|
const std::map<QString, QList<Package *> > &groups() const;
|
|
const QStringList &serverUrls() const;
|
|
alpm_siglevel_t sigLevel() const;
|
|
|
|
// gathering data
|
|
virtual bool requestsRequired() const;
|
|
virtual SuggestionsReply *requestSuggestions(const QString &phrase) const;
|
|
virtual PackageReply *requestPackageInfo(const QStringList &packageNames, bool forceUpdate = false) const;
|
|
virtual PackageReply *requestFullPackageInfo(const QString &package, bool forceUpdate = false) const;
|
|
|
|
// package search
|
|
const Package *packageByName(const QString &name) const;
|
|
Package *packageByName(const QString &name);
|
|
const Package *packageProviding(const Dependency &dependency) const;
|
|
QList<const Package *> packagesProviding(const Dependency &dependency) const;
|
|
QList<Package *> packageByFilter(std::function<bool (const Package *)> pred);
|
|
|
|
// upgrade lookup
|
|
const QList<const Repository *> &upgradeSources() const;
|
|
QList<const Repository *> &upgradeSources();
|
|
QJsonArray upgradeSourcesJsonArray() const;
|
|
void checkForUpgrades(UpgradeLookupResults &results) const;
|
|
void checkForUpgrades(UpgradeLookupResults &results, const QList<const Repository *> &upgradeSources) const;
|
|
|
|
// build system
|
|
const QString &sourcesDirectory() const;
|
|
void setSourcesDirectory(const QString &dir);
|
|
const QString &packagesDirectory() const;
|
|
void setPackagesDirectory(const QString &dir);
|
|
|
|
// JSON serialization
|
|
QJsonArray packageNamesJsonArray() const;
|
|
QJsonObject basicInfo() const;
|
|
QJsonObject groupInfo() const;
|
|
|
|
protected:
|
|
explicit Repository(const QString &name, QObject *parent = nullptr);
|
|
|
|
QString m_name;
|
|
QString m_description;
|
|
std::map<QString, std::unique_ptr<Package> > m_packages;
|
|
alpm_db_usage_t m_usage;
|
|
std::map<QString, QList<Package *> > m_groups;
|
|
QStringList m_serverUrls;
|
|
alpm_siglevel_t m_sigLevel;
|
|
QList<const Repository *> m_upgradeSources;
|
|
QString m_srcDir;
|
|
QString m_pkgDir;
|
|
};
|
|
|
|
/*!
|
|
* \brief Returns the name.
|
|
*/
|
|
inline const QString &Repository::name() const
|
|
{
|
|
return m_name;
|
|
}
|
|
|
|
/*!
|
|
* \brief Returns the description.
|
|
*/
|
|
inline const QString &Repository::description() const
|
|
{
|
|
return m_description;
|
|
}
|
|
|
|
/*!
|
|
* \brief Returns the packages.
|
|
*/
|
|
inline const std::map<QString, std::unique_ptr<Package> > &Repository::packages() const
|
|
{
|
|
return m_packages;
|
|
}
|
|
|
|
/*!
|
|
* \brief Returns the packages.
|
|
*/
|
|
inline std::map<QString, std::unique_ptr<Package> > &Repository::packages()
|
|
{
|
|
return m_packages;
|
|
}
|
|
|
|
/*!
|
|
* \brief Returns the package with the specified \a name or nullptr if the package can not be found.
|
|
* \remarks Ownership remains by this instance.
|
|
*/
|
|
inline const Package *Repository::packageByName(const QString &name) const
|
|
{
|
|
try {
|
|
return m_packages.at(name).get();
|
|
} catch(const std::out_of_range &) {
|
|
return nullptr;
|
|
}
|
|
}
|
|
|
|
/*!
|
|
* \brief Returns the package with the specified \a name or nullptr if the package can not be found.
|
|
* \remarks Ownership remains by this instance.
|
|
*/
|
|
inline Package *Repository::packageByName(const QString &name)
|
|
{
|
|
try {
|
|
return m_packages.at(name).get();
|
|
} catch(const std::out_of_range &) {
|
|
return nullptr;
|
|
}
|
|
}
|
|
|
|
inline alpm_db_usage_t Repository::usage() const
|
|
{
|
|
return m_usage;
|
|
}
|
|
|
|
inline const std::map<QString, QList<Package *> > &Repository::groups() const
|
|
{
|
|
return m_groups;
|
|
}
|
|
|
|
/*!
|
|
* \brief Returns the server URLs.
|
|
*/
|
|
inline const QStringList &Repository::serverUrls() const
|
|
{
|
|
return m_serverUrls;
|
|
}
|
|
|
|
/*!
|
|
* \brief Returns the signature level of the database.
|
|
*/
|
|
inline alpm_siglevel_t Repository::sigLevel() const
|
|
{
|
|
return m_sigLevel;
|
|
}
|
|
|
|
inline const QList<const Repository *> &Repository::upgradeSources() const
|
|
{
|
|
return m_upgradeSources;
|
|
}
|
|
|
|
inline QList<const Repository *> &Repository::upgradeSources()
|
|
{
|
|
return m_upgradeSources;
|
|
}
|
|
|
|
inline void Repository::checkForUpgrades(UpgradeLookupResults &results) const
|
|
{
|
|
checkForUpgrades(results, upgradeSources());
|
|
}
|
|
|
|
/*!
|
|
* \brief Returns the path of the local sources directory.
|
|
*/
|
|
inline const QString &Repository::sourcesDirectory() const
|
|
{
|
|
return m_srcDir;
|
|
}
|
|
|
|
/*!
|
|
* \brief Sets the path of the local sources directory.
|
|
*/
|
|
inline void Repository::setSourcesDirectory(const QString &dir)
|
|
{
|
|
m_srcDir = dir;
|
|
}
|
|
|
|
/*!
|
|
* \brief Returns the path of the local packages directory.
|
|
*/
|
|
inline const QString &Repository::packagesDirectory() const
|
|
{
|
|
return m_pkgDir;
|
|
}
|
|
|
|
/*!
|
|
* \brief Sets the path of the local packages directory.
|
|
*/
|
|
inline void Repository::setPackagesDirectory(const QString &dir)
|
|
{
|
|
m_pkgDir = dir;
|
|
}
|
|
|
|
} // namespace PackageManagement
|
|
|
|
#endif // PACKAGEMANAGEMENT_PACKAGESOURCE_H
|