126 lines
2.6 KiB
C++
126 lines
2.6 KiB
C++
#ifndef ALPM_DATABASE_H
|
|
#define ALPM_DATABASE_H
|
|
|
|
#include "./repository.h"
|
|
#include "./list.h"
|
|
|
|
#include <QJsonArray>
|
|
#include <QMutex>
|
|
#include <QFuture>
|
|
|
|
#include <memory>
|
|
|
|
namespace RepoIndex {
|
|
|
|
class AlpmPackage;
|
|
class AlpmDatabase;
|
|
|
|
class PackageLoader
|
|
{
|
|
public:
|
|
PackageLoader(AlpmDatabase *db);
|
|
QFuture<void> &future();
|
|
|
|
private:
|
|
QMutex m_mutex;
|
|
QList<alpm_pkg_t *> m_packages;
|
|
QFuture<void> m_future;
|
|
};
|
|
|
|
inline QFuture<void> &PackageLoader::future()
|
|
{
|
|
return m_future;
|
|
}
|
|
|
|
class AlpmDatabase : public Repository
|
|
{
|
|
friend class EmplacePackage;
|
|
|
|
public:
|
|
explicit AlpmDatabase(alpm_db_t *dataBase, const QString &dbPath, uint32 index = invalidIndex, QObject *parent = nullptr);
|
|
PackageLoader *init();
|
|
// explicit AlpmDatabase(const QString &dataBaseFile, QObject *parent = nullptr);
|
|
|
|
RepositoryType type() const;
|
|
PackageDetailAvailability requestsRequired(PackageDetail packageDetail) const;
|
|
|
|
// operators
|
|
bool operator ==(const AlpmDatabase &other) const;
|
|
bool operator !=(const AlpmDatabase &other) const;
|
|
|
|
// database meta data
|
|
alpm_db_t *ptr();
|
|
const QString &dataBaseFile() const;
|
|
StringList servers() const;
|
|
bool setServers(StringList servers);
|
|
bool addServerUrls(const QStringList &urls);
|
|
PackageList search(StringList terms) const;
|
|
|
|
signals:
|
|
void initiated();
|
|
|
|
private:
|
|
alpm_db_t *m_ptr;
|
|
QString m_dbFile;
|
|
};
|
|
|
|
/*!
|
|
* \brief Checks whether the specified ALPM database is equal the current instance.
|
|
*/
|
|
inline bool AlpmDatabase::operator ==(const AlpmDatabase &other) const
|
|
{
|
|
return m_ptr == other.m_ptr;
|
|
}
|
|
|
|
/*!
|
|
* \brief Checks whether the specified ALPM database is not equal to the current instance.
|
|
*/
|
|
inline bool AlpmDatabase::operator !=(const AlpmDatabase &other) const
|
|
{
|
|
return m_ptr != other.m_ptr;
|
|
}
|
|
|
|
/*!
|
|
* \brief Returns the pointer to the underlying database struct.
|
|
*/
|
|
inline alpm_db_t *AlpmDatabase::ptr()
|
|
{
|
|
return m_ptr;
|
|
}
|
|
|
|
/*!
|
|
* \brief Returns the path of the data base file.
|
|
*/
|
|
inline const QString &AlpmDatabase::dataBaseFile() const
|
|
{
|
|
return m_dbFile;
|
|
}
|
|
|
|
/*!
|
|
* \brief Returns the servers of the database.
|
|
*/
|
|
inline StringList AlpmDatabase::servers() const
|
|
{
|
|
return alpm_db_get_servers(m_ptr);
|
|
}
|
|
|
|
/*!
|
|
* \brief Sets the servers of the database.
|
|
*/
|
|
inline bool AlpmDatabase::setServers(StringList servers)
|
|
{
|
|
return alpm_db_set_servers(m_ptr, servers.begin().ptr()) == 0;
|
|
}
|
|
|
|
/*!
|
|
* \brief Performs a search using the build-in ALPM function.
|
|
*/
|
|
inline PackageList AlpmDatabase::search(StringList terms) const
|
|
{
|
|
return alpm_db_search(m_ptr, terms.begin().ptr());
|
|
}
|
|
|
|
} // namespace Alpm
|
|
|
|
#endif // ALPM_DATABASE_H
|