repoindex/alpm/alpmdatabase.h

125 lines
2.6 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"
#include "list.h"
#include <QJsonArray>
#include <QMutex>
#include <QFuture>
#include <memory>
2015-09-04 14:37:01 +02:00
namespace RepoIndex {
2015-09-04 14:37:01 +02:00
class AlpmPackage;
class AlpmDatabase;
class PackageLoader
2015-09-04 14:37:01 +02:00
{
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, QObject *parent = nullptr);
PackageLoader *init();
// explicit AlpmDatabase(const QString &dataBaseFile, QObject *parent = nullptr);
2015-09-04 14:37:01 +02:00
RepositoryType type() const;
PackageDetailAvailability requestsRequired(PackageDetail packageDetail) const;
2015-09-04 14:37:01 +02:00
// operators
bool operator ==(const AlpmDatabase &other) const;
bool operator !=(const AlpmDatabase &other) const;
2015-09-04 14:37:01 +02:00
// 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();
2015-09-04 14:37:01 +02:00
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
2015-09-04 14:37:01 +02:00
{
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
2015-09-04 14:37:01 +02:00
{
return m_ptr != other.m_ptr;
}
/*!
* \brief Returns the pointer to the underlying database struct.
*/
inline alpm_db_t *AlpmDatabase::ptr()
2015-09-04 14:37:01 +02:00
{
return m_ptr;
}
/*!
* \brief Returns the path of the data base file.
*/
inline const QString &AlpmDatabase::dataBaseFile() const
2015-09-04 14:37:01 +02:00
{
return m_dbFile;
}
/*!
* \brief Returns the servers of the database.
*/
inline StringList AlpmDatabase::servers() const
2015-09-04 14:37:01 +02:00
{
return alpm_db_get_servers(m_ptr);
}
/*!
* \brief Sets the servers of the database.
*/
inline bool AlpmDatabase::setServers(StringList servers)
2015-09-04 14:37:01 +02:00
{
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
2015-09-04 14:37:01 +02:00
{
return alpm_db_search(m_ptr, terms.begin().ptr());
}
} // namespace Alpm
#endif // ALPM_DATABASE_H