repoindex/lib/alpm/aurpackage.cpp

62 lines
2.2 KiB
C++

#include "./aurpackage.h"
#include "../network/userrepository.h"
#include <QJsonObject>
using namespace CppUtilities;
namespace RepoIndex {
/*!
* \brief The AurPackage class holds information about AUR packages. It allows to convert the information
* to JSON objects used by the network classes and the web interface.
*/
/*!
* \brief Creates a new instance from the specified "AurJson value".
*/
AurPackage::AurPackage(const QJsonObject &aurJsonObject, UserRepository *repository) :
Package(QString(), repository)
{
m_origin = PackageOrigin::Aur;
putJson(aurJsonObject);
}
/*!
* \brief Creates a new instance where only the name is known.
*/
AurPackage::AurPackage(const QString &name, UserRepository *repository) :
Package(name, repository)
{}
/*!
* \brief Creates a new, empty instance.
* \remarks The only purpose of this c'tor is to use it with restoreFromCacheStream().
*/
AurPackage::AurPackage(UserRepository *repository) :
Package(QString(), repository)
{}
void AurPackage::putJson(const QJsonObject &aurJsonObject)
{
m_name = aurJsonObject.value(QStringLiteral("Name")).toString();
m_hasGeneralInfo = true;
m_id = aurJsonObject.value(QStringLiteral("ID")).toInt(-1);
m_categoryId = aurJsonObject.value(QStringLiteral("CategoryID")).toInt(-1);
m_version = aurJsonObject.value(QStringLiteral("Version")).toString();
m_description = aurJsonObject.value(QStringLiteral("Description")).toString();
m_upstreamUrl = aurJsonObject.value(QStringLiteral("URL")).toString();
m_votes = aurJsonObject.value(QStringLiteral("NumVotes")).toInt(0);
m_outOfDate = DateTime::fromTimeStamp(aurJsonObject.value(QStringLiteral("OutOfDate")).toInt());
m_maintainer = aurJsonObject.value(QStringLiteral("Maintainer")).toString();
m_firstSubmitted = DateTime::fromTimeStamp(aurJsonObject.value(QStringLiteral("FirstSubmitted")).toInt());
m_lastModified = DateTime::fromTimeStamp(aurJsonObject.value(QStringLiteral("LastModified")).toInt());
m_licenses.clear();
m_licenses << aurJsonObject.value(QStringLiteral("License")).toString();
m_tarUrl = aurJsonObject.value(QStringLiteral("URLPath")).toString();
}
} // namespace PackageManagement