repoindex/alpm/database.h

220 lines
4.8 KiB
C++

#ifndef ALPM_DATABASE_H
#define ALPM_DATABASE_H
#include "list.h"
#include "package.h"
#include <alpm.h>
#include <QJsonArray>
#include <QList>
#include <map>
namespace PackageManagement {
class UpdateLookupResults
{
public:
UpdateLookupResults();
/*!
* \brief Indicates that there are no upgrade sources available.
*/
bool noSources;
/*!
* \brief Packages providing a software upgrade (new version).
*/
QList<AlpmPackage> newVersions;
/*!
* \brief Package upgrades only (new release).
*/
QList<AlpmPackage> newReleases;
/*!
* \brief Downgrades (older version in sync db).
*/
QList<AlpmPackage> downgrades;
/*!
* \brief Orphaned packages (could not be found in any of the sync dbs).
*/
QList<AlpmPackage> orphaned;
QStringList warnings;
QStringList errors;
};
/*!
* \brief Constructs new update lookup results.
*/
inline UpdateLookupResults::UpdateLookupResults() :
noSources(false)
{}
class AlpmDataBase
{
public:
AlpmDataBase(alpm_db_t *dataBase = nullptr);
// operators
operator bool() const;
bool operator ==(const AlpmDataBase &other) const;
bool operator !=(const AlpmDataBase &other) const;
// database properties
alpm_db_t *ptr() const;
const char *name() const;
alpm_siglevel_t sigLevel() const;
alpm_db_usage_t usage() const;
StringList servers() const;
const QJsonArray &serverUrls() const;
bool setServers(StringList servers);
alpm_pkg_t *package(const char *name) const;
const std::map<QString, AlpmPackage> &packages() const;
QStringList packageNames() const;
const QJsonArray &packageNameJsonArray() const;
alpm_group_t *group(const char *name) const;
GroupList groups() const;
QJsonObject groupInfo() const;
PackageList search(StringList terms) const;
// upgrade lookup
const QStringList &upgradeSources() const;
QStringList &upgradeSources();
void checkForUpgrades(const QList<const AlpmDataBase *> &syncDbs, UpdateLookupResults &results) const;
private:
alpm_db_t *m_ptr;
QStringList m_updateSources;
mutable QJsonArray m_serverUrls;
mutable std::map<QString, AlpmPackage> m_packages;
mutable QJsonArray m_packageNamesJsonArray;
mutable QJsonArray m_groupInfo;
};
/*!
* \brief Creates a new instance wrapping the specified database struct.
*/
inline AlpmDataBase::AlpmDataBase(alpm_db_t *dataBase) :
m_ptr(dataBase)
{}
/*!
* \brief Checks whether the specified ALPM database is equal to 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() const
{
return m_ptr;
}
/*!
* \brief Returns the name of the database.
*/
inline const char *AlpmDataBase::name() const
{
return alpm_db_get_name(m_ptr);
}
/*!
* \brief Returns the signature level of the database.
*/
inline alpm_siglevel_t AlpmDataBase::sigLevel() const
{
return alpm_db_get_siglevel(m_ptr);
}
/*!
* \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 Returns the package with the specified \a name.
*/
inline alpm_pkg_t *AlpmDataBase::package(const char *name) const
{
return alpm_db_get_pkg(m_ptr, name);
}
/*!
* \brief Returns the groups.
*/
inline alpm_group_t *AlpmDataBase::group(const char *name) const
{
return alpm_db_get_group(m_ptr, name);
}
/*!
* \brief Returns the groups.
*/
inline GroupList AlpmDataBase::groups() const
{
return alpm_db_get_groupcache(m_ptr);
}
/*!
* \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());
}
/*!
* \brief Returns a list of databases which are used (by default) to upgrade this database.
*/
inline const QStringList &AlpmDataBase::upgradeSources() const
{
return m_updateSources;
}
/*!
* \brief Returns a list of databases which are used (by default) to upgrade this database.
*/
inline QStringList &AlpmDataBase::upgradeSources()
{
return m_updateSources;
}
/*!
* \brief Returns whether the database instance is valid or null.
*/
inline PackageManagement::AlpmDataBase::operator bool() const
{
return m_ptr != nullptr;
}
} // namespace Alpm
#endif // ALPM_DATABASE_H