91 lines
2.5 KiB
C++
91 lines
2.5 KiB
C++
#include "alpmdatabase.h"
|
|
#include "group.h"
|
|
#include "upgradelookup.h"
|
|
#include "alpmpackage.h"
|
|
#include "utilities.h"
|
|
|
|
#include <c++utilities/misc/memory.h>
|
|
|
|
#include <QList>
|
|
#include <QJsonObject>
|
|
|
|
using namespace std;
|
|
|
|
namespace PackageManagement {
|
|
|
|
using namespace Utilities;
|
|
|
|
/*!
|
|
* \brief The AlpmDataBase class wraps an ALPM data base struct and holds additional meta information.
|
|
*
|
|
* All packages returned by the AlpmDataBase class are AlpmPackage instances.
|
|
*/
|
|
|
|
/*!
|
|
* \brief Creates a new instance wrapping the specified database struct.
|
|
*/
|
|
PackageManagement::AlpmDataBase::AlpmDataBase(alpm_db_t *dataBase, const QString &dbPath, QObject *parent) :
|
|
Repository(QString::fromLocal8Bit(alpm_db_get_name(dataBase)), parent),
|
|
m_ptr(dataBase),
|
|
m_dbFile(QStringLiteral("%1/sync/%2").arg(dbPath, m_name))
|
|
{
|
|
if(alpm_db_get_usage(dataBase, &m_usage)) {
|
|
m_usage = static_cast<decltype(m_usage)>(ALPM_DB_USAGE_ALL);
|
|
}
|
|
if(m_name.compare(QLatin1String("local"), Qt::CaseInsensitive) == 0) {
|
|
m_description = QStringLiteral("The local database");
|
|
} else {
|
|
if((m_usage & ALPM_DB_USAGE_SYNC) || (m_usage & ALPM_DB_USAGE_INSTALL) || (m_usage & ALPM_DB_USAGE_UPGRADE)) {
|
|
m_description = QStringLiteral("Sync database »%1«").arg(m_name);
|
|
} else {
|
|
m_description = QStringLiteral("Database »%1«").arg(m_name);
|
|
}
|
|
}
|
|
for(auto *nativePkg : PackageList(alpm_db_get_pkgcache(m_ptr))) {
|
|
auto pkg = make_unique<AlpmPackage>(nativePkg, this);
|
|
QString pkgName = pkg->name();
|
|
for(const auto &grpName : pkg->groups()) {
|
|
m_groups[grpName] << pkg.get();
|
|
}
|
|
m_packages.emplace(pkgName, move(pkg));
|
|
}
|
|
for(const char *str : servers()) {
|
|
m_serverUrls << qstr(str);
|
|
}
|
|
m_sigLevel = alpm_db_get_siglevel(m_ptr);
|
|
}
|
|
|
|
//AlpmDataBase::AlpmDataBase(const QString &dataBaseFile, QObject *parent) :
|
|
// PackageSource(parent),
|
|
// m_ptr(nullptr)
|
|
//{}
|
|
|
|
RepositoryType AlpmDataBase::type() const
|
|
{
|
|
return RepositoryType::AlpmDataBase;
|
|
}
|
|
|
|
bool AlpmDataBase::isSourceOnly() const
|
|
{
|
|
return false;
|
|
}
|
|
|
|
/*!
|
|
* \brief Adds the specified server URLs.
|
|
*/
|
|
bool AlpmDataBase::addServerUrls(const QStringList &urls)
|
|
{
|
|
bool res = true;
|
|
for(const auto &url : urls) {
|
|
if(alpm_db_add_server(m_ptr, url.toLocal8Bit().data()) != 0) {
|
|
res = false;
|
|
} else {
|
|
m_serverUrls << url;
|
|
}
|
|
}
|
|
return res;
|
|
}
|
|
|
|
} // namespace Alpm
|
|
|