repoindex/alpm/alpmdatabase.h

114 lines
2.4 KiB
C
Raw Normal View History

2015-09-04 14:37:01 +02:00
#ifndef ALPM_DATABASE_H
#define ALPM_DATABASE_H
#include "./repository.h"
2015-09-04 14:37:01 +02:00
#include <QJsonArray>
#include <QMutex>
#include <QFuture>
#include <memory>
2015-09-04 14:37:01 +02:00
QT_FORWARD_DECLARE_CLASS(QNetworkRequest)
namespace RepoIndex {
2015-09-04 14:37:01 +02:00
class AlpmPackage;
class AlpmDatabase;
2016-02-14 23:48:43 +01:00
class LoadPackage;
2016-02-25 22:53:33 +01:00
enum class DatabaseError
{
NoError,
NotFound,
NoAccess,
UnableToOpenArchive,
UnableToOpenDescFile,
UnableToEnterDirectory
};
2016-01-18 20:34:29 +01:00
class AlpmPackageLoader : public PackageLoader
2015-09-04 14:37:01 +02:00
{
public:
2016-02-14 23:48:43 +01:00
AlpmPackageLoader(AlpmDatabase *db, PackageOrigin origin);
2016-02-25 22:53:33 +01:00
AlpmDatabase *database() const;
DatabaseError error() const;
private:
2016-02-25 22:53:33 +01:00
AlpmDatabase *const m_db;
DatabaseError m_error;
2016-02-14 23:48:43 +01:00
QList<QPair<QString, QList<QByteArray> > > m_descriptions;
};
2016-02-25 22:53:33 +01:00
/*!
* \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
{
2016-02-25 22:53:33 +01:00
Q_OBJECT
2016-02-14 23:48:43 +01:00
friend class AlpmPackageLoader;
public:
2016-02-14 23:48:43 +01:00
explicit AlpmDatabase(const QString &name, const QString &dbPath, RepositoryUsage usage, SignatureLevel sigLevel, uint32 index = invalidIndex, QObject *parent = nullptr);
2016-02-25 22:53:33 +01:00
AlpmPackageLoader *internalInit();
2015-09-04 14:37:01 +02:00
RepositoryType type() const;
PackageDetailAvailability requestsRequired(PackageDetail packageDetail) const;
2015-09-04 14:37:01 +02:00
// database meta data
2016-02-14 23:48:43 +01:00
const QString &databasePath() const;
void setDatabasePath(const QString &dbPath);
2015-09-04 14:37:01 +02:00
// updating/refreshing
void downloadDatabase(const QString &targetDir, bool filesDatabase = true);
void refresh(const QString &targetDir);
2016-02-12 01:05:08 +01:00
protected:
std::unique_ptr<Package> emptyPackage();
private slots:
void databaseDownloadFinished();
2015-09-04 14:37:01 +02:00
private:
2016-02-25 22:53:33 +01:00
DatabaseError loadDescriptions(QList<QPair<QString, QList<QByteArray> > > &descriptions);
QNetworkRequest regularDatabaseRequest();
QNetworkRequest filesDatabaseRequest();
2015-09-04 14:37:01 +02:00
2016-02-14 23:48:43 +01:00
QString m_dbPath;
QString m_downloadTargetDir;
2016-02-14 23:48:43 +01:00
};
2015-09-04 14:37:01 +02:00
/*!
2016-02-14 23:48:43 +01:00
* \brief Returns the path of the database directory/file.
2015-09-04 14:37:01 +02:00
*/
2016-02-14 23:48:43 +01:00
inline const QString &AlpmDatabase::databasePath() const
2015-09-04 14:37:01 +02:00
{
2016-02-14 23:48:43 +01:00
return m_dbPath;
2015-09-04 14:37:01 +02:00
}
/*!
2016-02-14 23:48:43 +01:00
* \brief Sets the path of the database directory/file.
* \remarks Does not invoke reinitialization using the new path.
2015-09-04 14:37:01 +02:00
*/
2016-02-14 23:48:43 +01:00
inline void AlpmDatabase::setDatabasePath(const QString &dbPath)
2015-09-04 14:37:01 +02:00
{
2016-02-14 23:48:43 +01:00
m_dbPath = dbPath;
2015-09-04 14:37:01 +02:00
}
} // namespace Alpm
#endif // ALPM_DATABASE_H