diff --git a/qt/CMakeLists.txt b/qt/CMakeLists.txt index 717eaa83..98672a54 100644 --- a/qt/CMakeLists.txt +++ b/qt/CMakeLists.txt @@ -27,6 +27,7 @@ set(APPSTREAMQT_SRC image.cpp provides.cpp screenshot.cpp + release.cpp ) set(APPSTREAMQT_PUBLIC_HEADERS @@ -35,6 +36,7 @@ set(APPSTREAMQT_PUBLIC_HEADERS image.h provides.h screenshot.h + release.h ) include_directories(${CMAKE_CURRENT_SOURCE_DIR} diff --git a/qt/component.cpp b/qt/component.cpp index 2c593aab..911a2299 100644 --- a/qt/component.cpp +++ b/qt/component.cpp @@ -19,6 +19,7 @@ #include "component.h" #include "screenshot.h" +#include "release.h" #include #include #include @@ -53,6 +54,7 @@ class Appstream::ComponentData : public QSharedData { QList m_screenshots; QMultiHash m_provides; QHash m_bundles; + QList m_releases; bool operator==(const ComponentData& other) const { if(m_categories != other.m_categories) { return false; @@ -108,6 +110,9 @@ class Appstream::ComponentData : public QSharedData { if(m_bundles != other.m_bundles) { return false; } + if(m_releases != other.m_releases) { + return false; + } // we don't check for m_extensions, since this is auto-generated and not a specific property of a component. @@ -423,6 +428,16 @@ void Component::setProvides(const QList& provides) { } } +QList Appstream::Component::releases() const +{ + return d->m_releases; +} + +void Appstream::Component::setReleases(const QList& releases) +{ + d->m_releases = releases; +} + bool Component::isValid() const { return !d->m_id.isEmpty() && diff --git a/qt/component.h b/qt/component.h index c98e7398..a115b2e9 100644 --- a/qt/component.h +++ b/qt/component.h @@ -29,10 +29,10 @@ #include "appstreamqt_export.h" #include "provides.h" - namespace Appstream { class Screenshot; +class Release; class ComponentData; @@ -168,6 +168,8 @@ class APPSTREAMQT_EXPORT Component { QHash bundles() const; QString bundle(BundleKind kind) const; + void setReleases(const QList &releases); + QList releases() const; /** * \returns whether the component is fully initialized diff --git a/qt/database.cpp b/qt/database.cpp index 452c84b3..25fe2e1e 100644 --- a/qt/database.cpp +++ b/qt/database.cpp @@ -34,6 +34,7 @@ #include "image.h" #include "screenshot.h" +#include "release.h" Q_LOGGING_CATEGORY(APPSTREAMQT_DB, "appstreamqt.database") @@ -112,7 +113,6 @@ QStringList value(GPtrArray *array) { Component convertAsComponent(AsComponent *cpt) { Component component; - std::string str; // kind QString kindString = value (as_component_kind_to_string (as_component_get_kind (cpt))); @@ -275,7 +275,13 @@ Component convertAsComponent(AsComponent *cpt) { component.setDeveloperName(developerName); // Releases - // TODO + QList releases; + auto releaseArray = as_component_get_releases(cpt); + for (uint i = 0; i < releaseArray->len; i++) { + auto release = AS_RELEASE (g_ptr_array_index (releaseArray, i)); + releases += Release(release); + } + component.setReleases(releases); return component; } diff --git a/qt/release.cpp b/qt/release.cpp new file mode 100644 index 00000000..3d46e1f9 --- /dev/null +++ b/qt/release.cpp @@ -0,0 +1,136 @@ +/* + * Copyright (C) 2016 Aleix Pol Gonzalez + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include "appstream.h" + +#include "release.h" + +#include +#include +#include + +using namespace Appstream; + +class Appstream::ReleaseData : public QSharedData { +public: + ReleaseData(AsRelease* rel) : m_release(rel) + { + g_object_ref(m_release); + } + + ~ReleaseData() + { + g_object_unref(m_release); + } + + bool operator==(const ReleaseData& rd) const + { + return rd.m_release == m_release; + } + + AsRelease* m_release; +}; + +Release::Release(_AsRelease* release) + : d(new ReleaseData(release)) +{} + +Release::Release(const Release &release) = default; + +Release::~Release() = default; + +Release& Release::operator=(const Release &release) = default; + +bool Release::operator==(const Release &other) const +{ + if(this->d == other.d) { + return true; + } + if(this->d && other.d) { + return *(this->d) == *other.d; + } + return false; +} + +QString Release::version() const +{ + return QString::fromUtf8(as_release_get_version(d->m_release)); +} + +QDateTime Release::timestamp() const +{ + return QDateTime::fromTime_t(as_release_get_timestamp(d->m_release)); +} + +QString Release::description() const +{ + return QString::fromUtf8(as_release_get_description(d->m_release)); +} + +QString Release::activeLocale() const +{ + return QString::fromUtf8(as_release_get_active_locale(d->m_release)); +} + +QList Release::locations() const +{ + auto urls = as_release_get_locations(d->m_release); + QList ret; + ret.reserve(urls->len); + for(uint i = 0; ilen; ++i) { + auto strval = (const gchar*) g_ptr_array_index (urls, i); + ret << QUrl(QString::fromUtf8(strval)); + } + return ret; +} + +Checksum Release::checksum() const +{ + { + auto cs = as_release_get_checksum(d->m_release, AS_CHECKSUM_KIND_SHA256); + if (cs) + return Checksum { Checksum::Sha256Checksum, QByteArray(cs) }; + } + + { + auto cs = as_release_get_checksum(d->m_release, AS_CHECKSUM_KIND_SHA1); + if (cs) + return Checksum { Checksum::Sha1Checksum, QByteArray(cs) }; + } + return Checksum { Checksum::NoneChecksum, "" }; +} + +QHash Release::sizes() const +{ + return { + { InstalledSize, as_release_get_size(d->m_release, AS_SIZE_KIND_INSTALLED) }, + { DownloadSize, as_release_get_size(d->m_release, AS_SIZE_KIND_DOWNLOAD) } + }; +} + +Release::UrgencyKind Release::urgency() const +{ + return Release::UrgencyKind(as_release_get_urgency(d->m_release)); +} + +QDebug operator<<(QDebug s, const Appstream::Release& release) +{ + s.nospace() << "Appstream::Release(" << release.version() << ": " << release.description() << ")"; + return s.space(); +} diff --git a/qt/release.h b/qt/release.h new file mode 100644 index 00000000..5113374a --- /dev/null +++ b/qt/release.h @@ -0,0 +1,97 @@ +/* + * Copyright (C) 2016 Aleix Pol Gonzalez + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef APPSTREAMQT_RELEASE_H +#define APPSTREAMQT_RELEASE_H + +#include +#include +#include +#include +#include "appstreamqt_export.h" + +struct _AsRelease; + +namespace Appstream { + +class ReleaseData; + +struct Checksum { + enum ChecksumKind { + NoneChecksum, + Sha256Checksum, + Sha1Checksum, + LastChecksum + }; + const ChecksumKind kind; + const QByteArray data; +}; + +class APPSTREAMQT_EXPORT Release { + Q_GADGET + public: + Release(_AsRelease* release); + Release(const Release& release); + ~Release(); + + Release& operator=(const Release& release); + bool operator==(const Release& r) const; + + enum SizeKind { + UnknownSize, + DownloadSize, + InstalledSize, + LastSize + }; + Q_ENUM(SizeKind) + + enum UrgencyKind { + UnknownUrgency, + LowUrgency, + MediumUrgency, + HighUrgency, + CriticalUrgency, + LastUrgency + }; + Q_ENUM(UrgencyKind) + + QString version() const; + + QDateTime timestamp() const; + + QString description() const; + + QString activeLocale() const; + + QList locations() const; + + Checksum checksum() const; + + QHash sizes() const; + + UrgencyKind urgency() const; + + private: + QSharedDataPointer d; +}; +} + +APPSTREAMQT_EXPORT QDebug operator<<(QDebug s, const Appstream::Release& release); + +#endif // APPSTREAMQT_RELEASE_H