115 lines
2.5 KiB
C++
115 lines
2.5 KiB
C++
#ifndef ALPM_DATABASE_H
|
|
#define ALPM_DATABASE_H
|
|
|
|
#include "./repository.h"
|
|
|
|
#include <QJsonArray>
|
|
#include <QMutex>
|
|
#include <QFuture>
|
|
|
|
#include <memory>
|
|
|
|
QT_FORWARD_DECLARE_CLASS(QNetworkRequest)
|
|
|
|
namespace RepoIndex {
|
|
|
|
class AlpmPackage;
|
|
class AlpmDatabase;
|
|
class LoadPackage;
|
|
|
|
enum class DatabaseError
|
|
{
|
|
NoError,
|
|
NotFound,
|
|
NoAccess,
|
|
UnableToOpenArchive,
|
|
UnableToOpenDescFile,
|
|
UnableToEnterDirectory
|
|
};
|
|
|
|
class AlpmPackageLoader : public PackageLoader
|
|
{
|
|
public:
|
|
AlpmPackageLoader(AlpmDatabase *db, PackageOrigin origin);
|
|
AlpmDatabase *database() const;
|
|
DatabaseError error() const;
|
|
|
|
private:
|
|
AlpmDatabase *const m_db;
|
|
DatabaseError m_error;
|
|
QList<QPair<QString, QList<QByteArray> > > m_descriptions;
|
|
ChronoUtilities::DateTime m_descriptionsLastModified;
|
|
};
|
|
|
|
/*!
|
|
* \brief Returns the associated database.
|
|
*/
|
|
inline AlpmDatabase *AlpmPackageLoader::database() const
|
|
{
|
|
return m_db;
|
|
}
|
|
|
|
/*!
|
|
* \brief Returns the error status.
|
|
*/
|
|
inline DatabaseError AlpmPackageLoader::error() const
|
|
{
|
|
return m_error;
|
|
}
|
|
|
|
class AlpmDatabase : public Repository
|
|
{
|
|
Q_OBJECT
|
|
|
|
friend class AlpmPackageLoader;
|
|
public:
|
|
explicit AlpmDatabase(const QString &name, const QString &dbPath, RepositoryUsage usage, SignatureLevel sigLevel, uint32 index = invalidIndex, QObject *parent = nullptr);
|
|
AlpmPackageLoader *internalInit();
|
|
|
|
RepositoryType type() const;
|
|
PackageDetailAvailability requestsRequired(PackageDetail packageDetail) const;
|
|
|
|
// database meta data
|
|
const QString &databasePath() const;
|
|
void setDatabasePath(const QString &dbPath);
|
|
|
|
// updating/refreshing
|
|
bool downloadDatabase(const QString &targetDir, bool filesDatabase = true);
|
|
void refresh(const QString &targetDir);
|
|
|
|
protected:
|
|
std::unique_ptr<Package> emptyPackage();
|
|
|
|
private slots:
|
|
void databaseDownloadFinished();
|
|
|
|
private:
|
|
DatabaseError loadDescriptions(QList<QPair<QString, QList<QByteArray> > > &descriptions, ChronoUtilities::DateTime *lastModified = nullptr);
|
|
QNetworkRequest regularDatabaseRequest();
|
|
QNetworkRequest filesDatabaseRequest();
|
|
|
|
QString m_dbPath;
|
|
QString m_downloadTargetDir;
|
|
};
|
|
|
|
/*!
|
|
* \brief Returns the path of the database directory/file.
|
|
*/
|
|
inline const QString &AlpmDatabase::databasePath() const
|
|
{
|
|
return m_dbPath;
|
|
}
|
|
|
|
/*!
|
|
* \brief Sets the path of the database directory/file.
|
|
* \remarks Does not invoke reinitialization using the new path.
|
|
*/
|
|
inline void AlpmDatabase::setDatabasePath(const QString &dbPath)
|
|
{
|
|
m_dbPath = dbPath;
|
|
}
|
|
|
|
} // namespace Alpm
|
|
|
|
#endif // ALPM_DATABASE_H
|