From 5e58a60578e95be0663a3ad3b40ee26422adf7ad Mon Sep 17 00:00:00 2001 From: Jan Grulich Date: Mon, 19 Jun 2017 07:46:20 +0200 Subject: [PATCH] Add missing getters/setters for most of the properties in AS::Component Also implement missing classes like AS::Launchable, AS:Translation or AS:ContentRating. --- qt/CMakeLists.txt | 6 + qt/bundle.cpp | 10 ++ qt/bundle.h | 5 + qt/category.cpp | 10 ++ qt/category.h | 5 + qt/chelpers.h | 23 ++++ qt/component.cpp | 264 +++++++++++++++++++++++++++++++++++++++++++ qt/component.h | 83 +++++++++++++- qt/contentrating.cpp | 139 +++++++++++++++++++++++ qt/contentrating.h | 82 ++++++++++++++ qt/icon.cpp | 9 ++ qt/icon.h | 5 + qt/image.cpp | 10 ++ qt/image.h | 5 + qt/launchable.cpp | 130 +++++++++++++++++++++ qt/launchable.h | 74 ++++++++++++ qt/provided.cpp | 10 ++ qt/provided.h | 5 + qt/release.cpp | 10 ++ qt/release.h | 5 + qt/screenshot.cpp | 10 ++ qt/screenshot.h | 5 + qt/suggested.cpp | 10 ++ qt/suggested.h | 5 + qt/translation.cpp | 133 ++++++++++++++++++++++ qt/translation.h | 76 +++++++++++++ 26 files changed, 1127 insertions(+), 2 deletions(-) create mode 100644 qt/contentrating.cpp create mode 100644 qt/contentrating.h create mode 100644 qt/launchable.cpp create mode 100644 qt/launchable.h create mode 100644 qt/translation.cpp create mode 100644 qt/translation.h diff --git a/qt/CMakeLists.txt b/qt/CMakeLists.txt index 5c3ef7d9..7dbbc91d 100644 --- a/qt/CMakeLists.txt +++ b/qt/CMakeLists.txt @@ -32,6 +32,9 @@ set(APPSTREAMQT_SRC release.cpp bundle.cpp suggested.cpp + contentrating.cpp + launchable.cpp + translation.cpp ) set(APPSTREAMQT_PUBLIC_HEADERS @@ -45,6 +48,9 @@ set(APPSTREAMQT_PUBLIC_HEADERS release.h bundle.h suggested.h + contentrating.h + launchable.h + translation.h ) include_directories(${CMAKE_CURRENT_SOURCE_DIR} diff --git a/qt/bundle.cpp b/qt/bundle.cpp index 5cf8d034..1f36677a 100644 --- a/qt/bundle.cpp +++ b/qt/bundle.cpp @@ -60,6 +60,11 @@ class AppStream::BundleData : public QSharedData { return rd.m_bundle == m_bundle; } + AsBundle *bundle() const + { + return m_bundle; + } + AsBundle* m_bundle; }; @@ -88,6 +93,11 @@ bool Bundle::operator==(const Bundle &other) const return false; } +_AsBundle * AppStream::Bundle::asBundle() const +{ + return d->bundle(); +} + Bundle::Kind Bundle::kind() const { return Bundle::Kind(as_bundle_get_kind(d->m_bundle)); diff --git a/qt/bundle.h b/qt/bundle.h index 0f1b37ed..35d5163d 100644 --- a/qt/bundle.h +++ b/qt/bundle.h @@ -40,6 +40,11 @@ class APPSTREAMQT_EXPORT Bundle { Bundle& operator=(const Bundle& bundle); bool operator==(const Bundle& r) const; + /** + * \returns the internally stored AsBundle + */ + _AsBundle *asBundle() const; + enum Kind { KindUnknown, KindPackage, diff --git a/qt/category.cpp b/qt/category.cpp index 009c41d7..05497bba 100644 --- a/qt/category.cpp +++ b/qt/category.cpp @@ -42,6 +42,11 @@ class AppStream::CategoryData : public QSharedData { return rd.m_category == m_category; } + AsCategory *category() const + { + return m_category; + } + AsCategory* m_category; }; @@ -66,6 +71,11 @@ bool Category::operator==(const Category &other) const return false; } +_AsCategory * AppStream::Category::asCategory() const +{ + return d->category(); +} + QString Category::id() const { return valueWrap(as_category_get_id(d->m_category)); diff --git a/qt/category.h b/qt/category.h index 31f04d09..7f0abe2f 100644 --- a/qt/category.h +++ b/qt/category.h @@ -41,6 +41,11 @@ class APPSTREAMQT_EXPORT Category { Category& operator=(const Category& category); bool operator==(const Category& r) const; + /** + * \returns the internally stored AsCategory + */ + _AsCategory *asCategory() const; + QString id() const; QString name() const; QString summary() const; diff --git a/qt/chelpers.h b/qt/chelpers.h index 17646d88..cbf42b55 100644 --- a/qt/chelpers.h +++ b/qt/chelpers.h @@ -52,6 +52,29 @@ inline QStringList valueWrap(GPtrArray *array) return res; } +inline QStringList valueWrap(GList *list) +{ + GList *l; + QStringList res; + res.reserve(g_list_length(list)); + for (l = list; l != NULL; l = l->next) { + auto strval = (const gchar*) l->data; + res.append (QString::fromUtf8(strval)); + } + return res; +} + +inline char ** stringListToCharArray(const QStringList& list) +{ + char **array = (char**) g_malloc(sizeof(char*) * list.size()); + for (int i = 0; i < list.size(); ++i) { + const QByteArray string = list[i].toLocal8Bit(); + array[i] = (char*) g_malloc(sizeof(char) * (string.size() + 1)); + strcpy(array[i], string.constData()); + } + return array; +} + } #endif // APPSTREAMQT_CHELPERS_H diff --git a/qt/component.cpp b/qt/component.cpp index eea22ac5..8e515645 100644 --- a/qt/component.cpp +++ b/qt/component.cpp @@ -31,6 +31,9 @@ #include "release.h" #include "bundle.h" #include "suggested.h" +#include "contentrating.h" +#include "launchable.h" +#include "translation.h" using namespace AppStream; @@ -151,6 +154,31 @@ Component::~Component() g_object_unref(m_cpt); } +_AsComponent * AppStream::Component::asComponent() const +{ + return m_cpt; +} + +uint AppStream::Component::valueFlags() const +{ + return (uint) as_component_get_value_flags(m_cpt); +} + +void AppStream::Component::setValueFlags(uint flags) +{ + as_component_set_value_flags(m_cpt, (AsValueFlags) flags); +} + +QString AppStream::Component::activeLocale() const +{ + return valueWrap(as_component_get_active_locale(m_cpt)); +} + +void AppStream::Component::setActiveLocale(const QString& locale) +{ + as_component_set_active_locale(m_cpt, qPrintable(locale)); +} + Component::Kind Component::kind() const { return static_cast(as_component_get_kind (m_cpt)); @@ -161,6 +189,16 @@ void Component::setKind(Component::Kind kind) as_component_set_kind(m_cpt, static_cast(kind)); } +QString AppStream::Component::origin() const +{ + return valueWrap(as_component_get_origin(m_cpt)); +} + +void AppStream::Component::setOrigin(const QString& origin) +{ + as_component_set_origin(m_cpt, qPrintable(origin)); +} + QString Component::id() const { return valueWrap(as_component_get_id(m_cpt)); @@ -186,6 +224,23 @@ QStringList Component::packageNames() const return valueWrap(as_component_get_pkgnames(m_cpt)); } +void AppStream::Component::setPackageNames(const QStringList& list) +{ + char **packageList = stringListToCharArray(list); + as_component_set_pkgnames(m_cpt, packageList); + g_strfreev(packageList); +} + +QString AppStream::Component::sourcePackageName() const +{ + return valueWrap(as_component_get_source_pkgname(m_cpt)); +} + +void AppStream::Component::setSourcePackageName(const QString& sourcePkg) +{ + as_component_set_source_pkgname(m_cpt, qPrintable(sourcePkg)); +} + QString Component::name() const { return valueWrap(as_component_get_name(m_cpt)); @@ -216,6 +271,29 @@ void Component::setDescription(const QString& description, const QString& lang) as_component_set_description(m_cpt, qPrintable(description), lang.isEmpty()? NULL : qPrintable(lang)); } +AppStream::Launchable AppStream::Component::launchable(AppStream::Launchable::Kind kind) const +{ + auto launch = as_component_get_launchable(m_cpt, (AsLaunchableKind) kind); + if (launch == NULL) + return Launchable(); + return Launchable(launch); +} + +void AppStream::Component::addLaunchable(const AppStream::Launchable& launchable) +{ + as_component_add_launchable(m_cpt, launchable.asLaunchable()); +} + +QString AppStream::Component::metadataLicense() const +{ + return valueWrap(as_component_get_metadata_license(m_cpt)); +} + +void AppStream::Component::setMetadataLicense(const QString& license) +{ + as_component_set_metadata_license(m_cpt, qPrintable(license)); +} + QString Component::projectLicense() const { return valueWrap(as_component_get_project_license(m_cpt)); @@ -251,6 +329,11 @@ QStringList Component::compulsoryForDesktops() const return valueWrap(as_component_get_compulsory_for_desktops(m_cpt)); } +void AppStream::Component::setCompulsoryForDesktop(const QString& desktop) +{ + as_component_set_compulsory_for_desktop(m_cpt, qPrintable(desktop)); +} + bool Component::isCompulsoryForDesktop(const QString& desktop) const { return as_component_is_compulsory_for_desktop(m_cpt, qPrintable(desktop)); @@ -261,6 +344,11 @@ QStringList Component::categories() const return valueWrap(as_component_get_categories(m_cpt)); } +void AppStream::Component::addCategory(const QString& category) +{ + as_component_add_category(m_cpt, qPrintable(category)); +} + bool Component::hasCategory(const QString& category) const { return as_component_has_category(m_cpt, qPrintable(category)); @@ -271,6 +359,11 @@ QStringList Component::extends() const return valueWrap(as_component_get_extends(m_cpt)); } +void AppStream::Component::addExtends(const QString& extend) +{ + as_component_add_extends(m_cpt, qPrintable(extend)); +} + QList Component::addons() const { QList res; @@ -284,6 +377,44 @@ QList Component::addons() const return res; } +void AppStream::Component::addAddon(const AppStream::Component& addon) +{ + as_component_add_addon(m_cpt, addon.asComponent()); +} + +QStringList AppStream::Component::languages() const +{ + return valueWrap(as_component_get_languages(m_cpt)); +} + +int AppStream::Component::language(const QString& locale) const +{ + return as_component_get_language(m_cpt, qPrintable(locale)); +} + +void AppStream::Component::addLanguage(const QString& locale, int percentage) +{ + as_component_add_language(m_cpt, qPrintable(locale), percentage); +} + +QList AppStream::Component::translations() const +{ + QList res; + + auto translations = as_component_get_translations(m_cpt); + res.reserve(translations->len); + for (uint i = 0; i < translations->len; i++) { + auto translation = AS_TRANSLATION (g_ptr_array_index (translations, i)); + res.append(Translation(translation)); + } + return res; +} + +void AppStream::Component::addTranslation(const AppStream::Translation& translation) +{ + as_component_add_translation(m_cpt, translation.asTranslation()); +} + QUrl Component::url(Component::UrlKind kind) const { auto url = as_component_get_url(m_cpt, static_cast(kind)); @@ -292,6 +423,11 @@ QUrl Component::url(Component::UrlKind kind) const return QUrl(url); } +void AppStream::Component::addUrl(AppStream::Component::UrlKind kind, const QString& url) +{ + as_component_add_url(m_cpt, (AsUrlKind) kind, qPrintable(url)); +} + QList Component::icons() const { QList res; @@ -313,6 +449,11 @@ Icon Component::icon(const QSize& size) const return Icon(res); } +void AppStream::Component::addIcon(const AppStream::Icon& icon) +{ + as_component_add_icon(m_cpt, icon.asIcon()); +} + QList Component::provided() const { QList res; @@ -334,6 +475,11 @@ AppStream::Provided Component::provided(Provided::Kind kind) const return Provided(prov); } +void AppStream::Component::addProvided(const AppStream::Provided& provided) +{ + as_component_add_provided(m_cpt, provided.asProvided()); +} + QList Component::screenshots() const { QList res; @@ -347,6 +493,11 @@ QList Component::screenshots() const return res; } +void AppStream::Component::addScreenshot(const AppStream::Screenshot& screenshot) +{ + as_component_add_screenshot(m_cpt, screenshot.asScreenshot()); +} + QList Component::releases() const { QList res; @@ -360,6 +511,16 @@ QList Component::releases() const return res; } +void AppStream::Component::addRelease(const AppStream::Release& release) +{ + as_component_add_release(m_cpt, release.asRelease()); +} + +bool AppStream::Component::hasBundle() const +{ + return as_component_has_bundle(m_cpt); +} + QList Component::bundles() const { QList res; @@ -381,6 +542,11 @@ Bundle Component::bundle(Bundle::Kind kind) const return Bundle(bundle); } +void AppStream::Component::addBundle(const AppStream::Bundle& bundle) const +{ + as_component_add_bundle(m_cpt, bundle.asBundle()); +} + QList AppStream::Component::suggested() const { QList res; @@ -394,11 +560,109 @@ QList AppStream::Component::suggested() const return res; } +void AppStream::Component::addSuggested(const AppStream::Suggested& suggested) +{ + as_component_add_suggested(m_cpt, suggested.suggested()); +} + +QStringList AppStream::Component::searchTokens() const +{ + return valueWrap(as_component_get_search_tokens(m_cpt)); +} + +uint AppStream::Component::searchMatches(const QString& term) const +{ + return as_component_search_matches(m_cpt, qPrintable(term)); +} + +uint AppStream::Component::searchMatchesAll(const QStringList& terms) const +{ + char **termList = stringListToCharArray(terms); + const uint searchMatches = as_component_search_matches_all(m_cpt, termList); + g_strfreev(termList); + return searchMatches; +} + +AppStream::Component::MergeKind AppStream::Component::mergeKind() const +{ + return static_cast(as_component_get_merge_kind(m_cpt)); +} + +void AppStream::Component::setMergeKind(AppStream::Component::MergeKind kind) +{ + as_component_set_merge_kind(m_cpt, (AsMergeKind) kind); +} + +QHash AppStream::Component::custom() const +{ + QHash result; + GHashTableIter iter; + gpointer key, value; + + auto custom = as_component_get_custom(m_cpt); + g_hash_table_iter_init(&iter, custom); + while (g_hash_table_iter_next(&iter, &key, &value)) { + result.insert(valueWrap(static_cast(key)), valueWrap(static_cast(value))); + } + return result; +} + +QString AppStream::Component::customValue(const QString& key) +{ + return valueWrap(as_component_get_custom_value(m_cpt, qPrintable(key))); +} + +bool AppStream::Component::insertCustomValue(const QString& key, const QString& value) +{ + return as_component_insert_custom_value(m_cpt, qPrintable(key), qPrintable(value)); +} + +QList AppStream::Component::contentRatings() const +{ + QList res; + + auto ratings = as_component_get_content_ratings(m_cpt); + res.reserve(ratings->len); + for (uint i = 0; i < ratings->len; i++) { + auto rating = AS_CONTENT_RATING (g_ptr_array_index (ratings, i)); + res.append(ContentRating(rating)); + } + return res; +} + +AppStream::ContentRating AppStream::Component::contentRating(const QString& kind) const +{ + auto rating = as_component_get_content_rating(m_cpt, qPrintable(kind)); + if (rating == NULL) + return ContentRating(); + return ContentRating(rating); +} + +void AppStream::Component::addContentRating(const AppStream::ContentRating& contentRating) +{ + as_component_add_content_rating(m_cpt, contentRating.asContentRating()); +} + +bool AppStream::Component::isMemberOfCategory(const AppStream::Category& category) const +{ + return as_component_is_member_of_category(m_cpt, category.asCategory()); +} + +bool AppStream::Component::isIgnored() const +{ + return as_component_is_ignored(m_cpt); +} + bool Component::isValid() const { return as_component_is_valid(m_cpt); } +QString AppStream::Component::toString() const +{ + return valueWrap(as_component_to_string(m_cpt)); +} + QString Component::desktopId() const { auto de_launchable = as_component_get_launchable (m_cpt, AS_LAUNCHABLE_KIND_DESKTOP_ID); diff --git a/qt/component.h b/qt/component.h index 3adbab32..3509f7ff 100644 --- a/qt/component.h +++ b/qt/component.h @@ -28,6 +28,10 @@ #include "appstreamqt_export.h" #include "provided.h" #include "bundle.h" +#include "category.h" +#include "contentrating.h" +#include "launchable.h" +#include "translation.h" struct _AsComponent; namespace AppStream { @@ -62,6 +66,13 @@ Q_GADGET }; Q_ENUM(Kind) + enum MergeKind { + MergeKindNone, + MergeKindReplace, + MergeKindAppend + }; + Q_ENUM(MergeKind) + enum UrlKind { UrlKindUnknown, UrlKindHomepage, @@ -73,6 +84,13 @@ Q_GADGET }; Q_ENUM(UrlKind) + enum ValueFlags { + FlagNone = 0, + FlagDuplicateCheck = 1 << 0, + FlagNoTranslationFallback = 1 << 1 + }; + Q_ENUM(ValueFlags) + static Kind stringToKind(const QString& kindString); static QString kindToString(Kind kind); @@ -84,9 +102,20 @@ Q_GADGET Component(const Component& other); ~Component(); + _AsComponent *asComponent() const; + + uint valueFlags() const; + void setValueFlags(uint flags); + + QString activeLocale() const; + void setActiveLocale(const QString& locale); + Kind kind () const; void setKind (Component::Kind kind); + QString origin() const; + void setOrigin(const QString& origin); + QString id() const; void setId(const QString& id); @@ -94,6 +123,10 @@ Q_GADGET void setDataId(const QString& cdid); QStringList packageNames() const; + void setPackageNames(const QStringList& list); + + QString sourcePackageName() const; + void setSourcePackageName(const QString& sourcePkg); QString name() const; void setName(const QString& name, const QString& lang = {}); @@ -104,6 +137,12 @@ Q_GADGET QString description() const; void setDescription(const QString& description, const QString& lang = {}); + AppStream::Launchable launchable(AppStream::Launchable::Kind kind) const; + void addLaunchable(const AppStream::Launchable& launchable); + + QString metadataLicense() const; + void setMetadataLicense(const QString& license); + QString projectLicense() const; void setProjectLicense(const QString& license); @@ -114,19 +153,33 @@ Q_GADGET void setDeveloperName(const QString& developerName, const QString& lang = {}); QStringList compulsoryForDesktops() const; + void setCompulsoryForDesktop(const QString& desktop); bool isCompulsoryForDesktop(const QString& desktop) const; QStringList categories() const; + void addCategory(const QString& category); bool hasCategory(const QString& category) const; QStringList extends() const; void setExtends(const QStringList& extends); + void addExtends(const QString& extend); + QList addons() const; + void addAddon(const AppStream::Component& addon); + + QStringList languages() const; + int language(const QString& locale) const; + void addLanguage(const QString& locale, int percentage); + + QList translations() const; + void addTranslation(const AppStream::Translation& translation); QUrl url(UrlKind kind) const; + void addUrl(UrlKind kind, const QString& url); QList icons() const; AppStream::Icon icon(const QSize& size) const; + void addIcon(const AppStream::Icon& icon); /** * \return the full list of provided entries for all kinds. @@ -138,20 +191,46 @@ Q_GADGET * \return provided items for this \param kind */ AppStream::Provided provided(Provided::Kind kind) const; + void addProvided(const AppStream::Provided& provided); QList screenshots() const; + void addScreenshot(const AppStream::Screenshot& screenshot); QList releases() const; + void addRelease(const AppStream::Release& release); + bool hasBundle() const; QList bundles() const; AppStream::Bundle bundle(Bundle::Kind kind) const; + void addBundle(const AppStream::Bundle& bundle) const; QList suggested() const; + void addSuggested(const AppStream::Suggested& suggested); + + QStringList searchTokens() const; + uint searchMatches(const QString& term) const; + uint searchMatchesAll(const QStringList& terms) const; + MergeKind mergeKind() const; + void setMergeKind(MergeKind kind); + + QHash custom() const; + QString customValue(const QString& key); + bool insertCustomValue(const QString& key, const QString& value); + + QList contentRatings() const; + AppStream::ContentRating contentRating(const QString& kind) const; + void addContentRating(const AppStream::ContentRating& contentRating); + + bool isMemberOfCategory(const AppStream::Category& category) const; + + bool isIgnored() const; bool isValid() const; - // DEPRECATED - Q_DECL_DEPRECATED QString desktopId() const; + QString toString() const; + + // DEPRECATED + Q_DECL_DEPRECATED QString desktopId() const; private: _AsComponent *m_cpt; diff --git a/qt/contentrating.cpp b/qt/contentrating.cpp new file mode 100644 index 00000000..1e2dcb72 --- /dev/null +++ b/qt/contentrating.cpp @@ -0,0 +1,139 @@ +/* + * Copyright (C) 2017 Jan Grulich + * Copyright (C) 2016 Matthias Klumpp + * + * Licensed under the GNU Lesser General Public License Version 2.1 + * + * 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, see . + */ + +#include "appstream.h" +#include "contentrating.h" + +#include +#include "chelpers.h" + +using namespace AppStream; + +class AppStream::ContentRatingData : public QSharedData { +public: + ContentRatingData() + { + m_contentRating = as_content_rating_new(); + } + + ContentRatingData(AsContentRating* cat) : m_contentRating(cat) + { + g_object_ref(m_contentRating); + } + + ~ContentRatingData() + { + g_object_unref(m_contentRating); + } + + bool operator==(const ContentRatingData& rd) const + { + return rd.m_contentRating == m_contentRating; + } + + AsContentRating *contentRating() const + { + return m_contentRating; + } + + AsContentRating* m_contentRating; +}; + +typedef QHash RatingMap; +Q_GLOBAL_STATIC_WITH_ARGS(RatingMap, ratingMap, ( { + { ContentRating::RatingValueUnknown, QLatin1String("unknown") }, + { ContentRating::RatingValueNone, QLatin1String("none") }, + { ContentRating::RatingValueMild, QLatin1String("mild") }, + { ContentRating::RatingValueModerate, QLatin1String("moderate") }, + { ContentRating::RatingValueIntense, QLatin1String("intense") } + } +)); + +AppStream::ContentRating::RatingValue AppStream::ContentRating::stringToRatingValue(const QString& ratingValue) +{ + return ratingMap->key(ratingValue, AppStream::ContentRating::RatingValueUnknown); +} + +QString AppStream::ContentRating::ratingValueToString(AppStream::ContentRating::RatingValue ratingValue) +{ + return ratingMap->value(ratingValue); +} + +ContentRating::ContentRating() + : d(new ContentRatingData) +{} + +ContentRating::ContentRating(_AsContentRating* contentRating) + : d(new ContentRatingData(contentRating)) +{} + +ContentRating::ContentRating(const ContentRating &contentRating) = default; + +ContentRating::~ContentRating() = default; + +ContentRating& ContentRating::operator=(const ContentRating &contentRating) = default; + +bool ContentRating::operator==(const ContentRating &other) const +{ + if(this->d == other.d) { + return true; + } + if(this->d && other.d) { + return *(this->d) == *other.d; + } + return false; +} + +_AsContentRating * AppStream::ContentRating::asContentRating() const +{ + return d->contentRating(); +} + +QString AppStream::ContentRating::kind() const +{ + return valueWrap(as_content_rating_get_kind(d->m_contentRating)); +} + +void AppStream::ContentRating::setKind(const QString& kind) +{ + as_content_rating_set_kind(d->m_contentRating, qPrintable(kind)); +} + +uint AppStream::ContentRating::minimumAge() const +{ + return as_content_rating_get_minimum_age(d->m_contentRating); +} + +AppStream::ContentRating::RatingValue AppStream::ContentRating::value(const QString& id) const +{ + return static_cast(as_content_rating_get_value(d->m_contentRating, qPrintable(id))); +} + +void AppStream::ContentRating::setValue(const QString& id, AppStream::ContentRating::RatingValue ratingValue) +{ + as_content_rating_set_value(d->m_contentRating, qPrintable(id), (AsContentRatingValue) ratingValue); +} + +QDebug operator<<(QDebug s, const AppStream::ContentRating& contentRating) +{ + s.nospace() << "AppStream::ContentRating(" << contentRating.kind() << contentRating.minimumAge() << ")"; + return s.space(); +} + diff --git a/qt/contentrating.h b/qt/contentrating.h new file mode 100644 index 00000000..7e0a6f7a --- /dev/null +++ b/qt/contentrating.h @@ -0,0 +1,82 @@ + +/* + * Copyright (C) 2017 Jan Grulich + * Copyright (C) 2016 Matthias Klumpp + * + * Licensed under the GNU Lesser General Public License Version 2.1 + * + * 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, see . + */ + +#ifndef APPSTREAMQT_CONTENT_RATING_H +#define APPSTREAMQT_CONTENT_RATING_H + +#include +#include +#include +#include "appstreamqt_export.h" + +struct _AsContentRating; + +namespace AppStream { + +class ContentRatingData; + +class APPSTREAMQT_EXPORT ContentRating { + Q_GADGET + + public: + enum RatingValue { + RatingValueUnknown, + RatingValueNone, + RatingValueMild, + RatingValueModerate, + RatingValueIntense + }; + Q_ENUM(RatingValue) + + ContentRating(); + ContentRating(_AsContentRating* category); + ContentRating(const ContentRating& category); + ~ContentRating(); + + static RatingValue stringToRatingValue(const QString& ratingValue); + static QString ratingValueToString(RatingValue ratingValue); + + ContentRating& operator=(const ContentRating& category); + bool operator==(const ContentRating& r) const; + + /** + * \returns the internally stored AsContentRating + */ + _AsContentRating *asContentRating() const; + + QString kind() const; + void setKind(const QString& kind); + + uint minimumAge() const; + + RatingValue value(const QString& id) const; + void setValue(const QString& id, RatingValue ratingValue); + + private: + QSharedDataPointer d; +}; +} + +APPSTREAMQT_EXPORT QDebug operator<<(QDebug s, const AppStream::ContentRating& category); + +#endif // APPSTREAMQT_CONTENT_RATING_H + + diff --git a/qt/icon.cpp b/qt/icon.cpp index 005d3679..c5a1aeb4 100644 --- a/qt/icon.cpp +++ b/qt/icon.cpp @@ -51,6 +51,10 @@ class AppStream::IconData : public QSharedData { return rd.m_icon == m_icon; } + AsIcon *icon() const { + return m_icon; + } + AsIcon *m_icon; }; @@ -75,6 +79,11 @@ Icon& Icon::operator=(const Icon& other) return *this; } +AsIcon * AppStream::Icon::asIcon() const +{ + return d->icon(); +} + Icon::Kind Icon::kind() const { return Icon::Kind(as_icon_get_kind(d->m_icon)); diff --git a/qt/icon.h b/qt/icon.h index 37e5cacc..cbcf1d6b 100644 --- a/qt/icon.h +++ b/qt/icon.h @@ -54,6 +54,11 @@ class APPSTREAMQT_EXPORT Icon { Icon& operator=(const Icon& other); + /** + * \returns the internally stored AsIcon + */ + _AsIcon *asIcon() const; + /** * \return the kind of icon */ diff --git a/qt/image.cpp b/qt/image.cpp index 9f9f82a6..765c4f2f 100644 --- a/qt/image.cpp +++ b/qt/image.cpp @@ -50,6 +50,11 @@ class AppStream::ImageData : public QSharedData { return rd.m_img == m_img; } + AsImage *image() const + { + return m_img; + } + AsImage *m_img; }; @@ -74,6 +79,11 @@ Image& Image::operator=(const Image& other) return *this; } +_AsImage * AppStream::Image::asImage() const +{ + return d->image(); +} + Image::Kind Image::kind() const { return Image::Kind(as_image_get_kind(d->m_img)); diff --git a/qt/image.h b/qt/image.h index 7038f92b..d8e457fe 100644 --- a/qt/image.h +++ b/qt/image.h @@ -59,6 +59,11 @@ class APPSTREAMQT_EXPORT Image { Image& operator=(const Image& other); + /** + * \returns the internally stored AsImage + */ + _AsImage *asImage() const; + /** * \return the kind of image */ diff --git a/qt/launchable.cpp b/qt/launchable.cpp new file mode 100644 index 00000000..94b489a3 --- /dev/null +++ b/qt/launchable.cpp @@ -0,0 +1,130 @@ +/* + * Copyright (C) 2017 Jan Grulich + * Copyright (C) 2016 Matthias Klumpp + * + * Licensed under the GNU Lesser General Public License Version 2.1 + * + * 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, see . + */ + +#include "appstream.h" +#include "launchable.h" + +#include +#include "chelpers.h" + +using namespace AppStream; + +class AppStream::LaunchableData : public QSharedData { +public: + LaunchableData() + { + m_launchable = as_launchable_new(); + } + + LaunchableData(AsLaunchable* cat) : m_launchable(cat) + { + g_object_ref(m_launchable); + } + + ~LaunchableData() + { + g_object_unref(m_launchable); + } + + bool operator==(const LaunchableData& rd) const + { + return rd.m_launchable == m_launchable; + } + + AsLaunchable *launchable() const + { + return m_launchable; + } + + AsLaunchable* m_launchable; +}; + + +AppStream::Launchable::Kind AppStream::Launchable::stringToKind(const QString& kindString) +{ + if (kindString == QLatin1String("desktop-id")) { + return AppStream::Launchable::KindDesktopId; + } + return AppStream::Launchable::KindUnknown; +} + +QString AppStream::Launchable::kindToString(AppStream::Launchable::Kind kind) +{ + if (kind == AppStream::Launchable::KindDesktopId) { + return QLatin1String("desktop-id"); + } + return QLatin1String("unknown"); +} + +Launchable::Launchable() + : d(new LaunchableData) +{} + +Launchable::Launchable(_AsLaunchable* launchable) + : d(new LaunchableData(launchable)) +{} + +Launchable::Launchable(const Launchable &launchable) = default; + +Launchable::~Launchable() = default; + +Launchable& Launchable::operator=(const Launchable &launchable) = default; + +bool Launchable::operator==(const Launchable &other) const +{ + if(this->d == other.d) { + return true; + } + if(this->d && other.d) { + return *(this->d) == *other.d; + } + return false; +} + +_AsLaunchable * AppStream::Launchable::asLaunchable() const +{ + return d->launchable(); +} + +AppStream::Launchable::Kind AppStream::Launchable::kind() const +{ + return static_cast(as_launchable_get_kind(d->m_launchable)); +} + +void AppStream::Launchable::setKind(AppStream::Launchable::Kind kind) +{ + as_launchable_set_kind(d->m_launchable, (AsLaunchableKind) kind); +} + +QStringList AppStream::Launchable::entries() const +{ + return valueWrap(as_launchable_get_entries(d->m_launchable)); +} + +void AppStream::Launchable::addEntry(const QString& entry) +{ + as_launchable_add_entry(d->m_launchable, qPrintable(entry)); +} + +QDebug operator<<(QDebug s, const AppStream::Launchable& launchable) +{ + s.nospace() << "AppStream::Launchable(" << launchable.entries() << ")"; + return s.space(); +} diff --git a/qt/launchable.h b/qt/launchable.h new file mode 100644 index 00000000..8f65b134 --- /dev/null +++ b/qt/launchable.h @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2017 Jan Grulich + * Copyright (C) 2016 Matthias Klumpp + * + * Licensed under the GNU Lesser General Public License Version 2.1 + * + * 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, see . + */ + +#ifndef APPSTREAMQT_LAUNCHABLE_H +#define APPSTREAMQT_LAUNCHABLE_H + +#include +#include +#include +#include "appstreamqt_export.h" + +struct _AsLaunchable; + +namespace AppStream { + +class LaunchableData; + +class APPSTREAMQT_EXPORT Launchable { + Q_GADGET + public: + enum Kind { + KindUnknown, + KindDesktopId + }; + Q_ENUM(Kind) + + Launchable(); + Launchable(_AsLaunchable* category); + Launchable(const Launchable& category); + ~Launchable(); + + static Kind stringToKind(const QString& kindString); + static QString kindToString(Kind kind); + + Launchable& operator=(const Launchable& category); + bool operator==(const Launchable& r) const; + + /** + * \returns the internally stored AsLaunchable + */ + _AsLaunchable *asLaunchable() const; + + Kind kind() const; + void setKind(Kind kind); + + QStringList entries() const; + void addEntry(const QString& entry); + + private: + QSharedDataPointer d; +}; +} + +APPSTREAMQT_EXPORT QDebug operator<<(QDebug s, const AppStream::Launchable& category); + +#endif // APPSTREAMQT_LAUNCHABLE_H + diff --git a/qt/provided.cpp b/qt/provided.cpp index c59c29da..4f9f2b77 100644 --- a/qt/provided.cpp +++ b/qt/provided.cpp @@ -53,6 +53,11 @@ class AppStream::ProvidedData : public QSharedData { return rd.m_prov == m_prov; } + AsProvided *provided() const + { + return m_prov; + } + AsProvided *m_prov; }; @@ -98,6 +103,11 @@ bool Provided::operator==(const Provided& other) const return false; } +_AsProvided * AppStream::Provided::asProvided() const +{ + return d->provided(); +} + Provided::Kind Provided::kind() const { return Provided::Kind(as_provided_get_kind(d->m_prov)); diff --git a/qt/provided.h b/qt/provided.h index 761b7ec9..1e3ba317 100644 --- a/qt/provided.h +++ b/qt/provided.h @@ -42,6 +42,11 @@ class APPSTREAMQT_EXPORT Provided { Provided& operator=(const Provided& other); bool operator==(const Provided& other) const; + /** + * \returns the internally stored AsProvided + */ + _AsProvided *asProvided() const; + enum Kind { KindUnknown, KindLibrary, diff --git a/qt/release.cpp b/qt/release.cpp index ea899840..d050d7f7 100644 --- a/qt/release.cpp +++ b/qt/release.cpp @@ -44,6 +44,11 @@ class AppStream::ReleaseData : public QSharedData { return rd.m_release == m_release; } + AsRelease *release() const + { + return m_release; + } + AsRelease* m_release; }; @@ -68,6 +73,11 @@ bool Release::operator==(const Release &other) const return false; } +_AsRelease * AppStream::Release::asRelease() const +{ + return d->release(); +} + QString Release::version() const { return QString::fromUtf8(as_release_get_version(d->m_release)); diff --git a/qt/release.h b/qt/release.h index 15d6f28b..737efe40 100644 --- a/qt/release.h +++ b/qt/release.h @@ -52,6 +52,11 @@ class APPSTREAMQT_EXPORT Release { Release& operator=(const Release& release); bool operator==(const Release& r) const; + /** + * \returns the internally stored AsRelease + */ + _AsRelease *asRelease() const; + enum SizeKind { SizeUnknown, SizeDownload, diff --git a/qt/screenshot.cpp b/qt/screenshot.cpp index 5141762d..3ddbbf1e 100644 --- a/qt/screenshot.cpp +++ b/qt/screenshot.cpp @@ -51,6 +51,11 @@ class AppStream::ScreenshotData : public QSharedData { return rd.m_scr == m_scr; } + AsScreenshot *screenshot() const + { + return m_scr; + } + AsScreenshot *m_scr; }; @@ -75,6 +80,11 @@ Screenshot& Screenshot::operator=(const Screenshot& other) return *this; } +_AsScreenshot * AppStream::Screenshot::asScreenshot() const +{ + return d->screenshot(); +} + bool Screenshot::isDefault() const { return as_screenshot_get_kind(d->m_scr) == AS_SCREENSHOT_KIND_DEFAULT; diff --git a/qt/screenshot.h b/qt/screenshot.h index a10e6938..b13b58a3 100644 --- a/qt/screenshot.h +++ b/qt/screenshot.h @@ -47,6 +47,11 @@ class APPSTREAMQT_EXPORT Screenshot { ~Screenshot(); Screenshot& operator=(const Screenshot& other); + /** + * \returns the internally stored AsScreenshot + */ + _AsScreenshot *asScreenshot() const; + /** * \return true if it is the default screenshot * A \ref Component should in general only have one default diff --git a/qt/suggested.cpp b/qt/suggested.cpp index 5a1499fd..a3dd847f 100644 --- a/qt/suggested.cpp +++ b/qt/suggested.cpp @@ -51,6 +51,11 @@ class AppStream::SuggestedData : public QSharedData { return rd.m_suggested == m_suggested; } + AsSuggested *suggested() const + { + return m_suggested; + } + AsSuggested *m_suggested; }; @@ -75,6 +80,11 @@ Suggested& Suggested::operator=(const Suggested& other) return *this; } +_AsSuggested * AppStream::Suggested::suggested() const +{ + return d->suggested(); +} + Suggested::Kind Suggested::kind() const { return Suggested::Kind(as_suggested_get_kind(d->m_suggested)); diff --git a/qt/suggested.h b/qt/suggested.h index d29fab63..253594af 100644 --- a/qt/suggested.h +++ b/qt/suggested.h @@ -53,6 +53,11 @@ class APPSTREAMQT_EXPORT Suggested { Suggested& operator=(const Suggested& other); + /** + * \returns the internally stored AsSuggested + */ + _AsSuggested *suggested() const; + /** * \return the kind of suggestion */ diff --git a/qt/translation.cpp b/qt/translation.cpp new file mode 100644 index 00000000..276919da --- /dev/null +++ b/qt/translation.cpp @@ -0,0 +1,133 @@ +/* + * Copyright (C) 2017 Jan Grulich + * Copyright (C) 2016 Matthias Klumpp + * + * Licensed under the GNU Lesser General Public License Version 2.1 + * + * 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, see . + */ + +#include "appstream.h" +#include "translation.h" + +#include +#include "chelpers.h" + +using namespace AppStream; + +class AppStream::TranslationData : public QSharedData { +public: + TranslationData() + { + m_translation = as_translation_new(); + } + + TranslationData(AsTranslation* cat) : m_translation(cat) + { + g_object_ref(m_translation); + } + + ~TranslationData() + { + g_object_unref(m_translation); + } + + bool operator==(const TranslationData& rd) const + { + return rd.m_translation == m_translation; + } + + AsTranslation *translation() const + { + return m_translation; + } + + AsTranslation* m_translation; +}; + +AppStream::Translation::Kind AppStream::Translation::stringToKind(const QString& kindString) +{ + if (kindString == QLatin1String("gettext")) { + return AppStream::Translation::KindGettext; + } else if (kindString == QLatin1String("qt")) { + return AppStream::Translation::KindQt; + } + return AppStream::Translation::KindUnknown; +} + +QString AppStream::Translation::kindToString(AppStream::Translation::Kind kind) +{ + if (kind == AppStream::Translation::KindGettext) { + return QLatin1String("gettext"); + } else if (kind == AppStream::Translation::KindQt) { + return QLatin1String("qt"); + } + return QLatin1String("unknown"); +} + +Translation::Translation() + : d(new TranslationData) +{} + +Translation::Translation(_AsTranslation* translation) + : d(new TranslationData(translation)) +{} + +Translation::Translation(const Translation &translation) = default; + +Translation::~Translation() = default; + +Translation& Translation::operator=(const Translation &translation) = default; + +bool Translation::operator==(const Translation &other) const +{ + if(this->d == other.d) { + return true; + } + if(this->d && other.d) { + return *(this->d) == *other.d; + } + return false; +} + +_AsTranslation * AppStream::Translation::asTranslation() const +{ + return d->translation(); +} + +AppStream::Translation::Kind AppStream::Translation::kind() const +{ + return static_cast(as_translation_get_kind(d->m_translation)); +} + +void AppStream::Translation::setKind(AppStream::Translation::Kind kind) +{ + as_translation_set_kind(d->m_translation, (AsTranslationKind) kind); +} + +QString AppStream::Translation::id() const +{ + return valueWrap(as_translation_get_id(d->m_translation)); +} + +void AppStream::Translation::setId(const QString& id) +{ + as_translation_set_id(d->m_translation, qPrintable(id)); +} + +QDebug operator<<(QDebug s, const AppStream::Translation& translation) +{ + s.nospace() << "AppStream::Translation(" << translation.id() << ")"; + return s.space(); +} diff --git a/qt/translation.h b/qt/translation.h new file mode 100644 index 00000000..2f352a1a --- /dev/null +++ b/qt/translation.h @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2017 Jan Grulich + * Copyright (C) 2016 Matthias Klumpp + * + * Licensed under the GNU Lesser General Public License Version 2.1 + * + * 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, see . + */ + +#ifndef APPSTREAMQT_TRANSLATION_H +#define APPSTREAMQT_TRANSLATION_H + +#include +#include +#include +#include "appstreamqt_export.h" + +struct _AsTranslation; + +namespace AppStream { + +class TranslationData; + +class APPSTREAMQT_EXPORT Translation { + Q_GADGET + public: + enum Kind { + KindUnknown, + KindGettext, + KindQt + }; + Q_ENUM(Kind) + + Translation(); + Translation(_AsTranslation* category); + Translation(const Translation& category); + ~Translation(); + + static Kind stringToKind(const QString& kindString); + static QString kindToString(Kind kind); + + Translation& operator=(const Translation& category); + bool operator==(const Translation& r) const; + + /** + * \returns the internally stored AsTranslation + */ + _AsTranslation *asTranslation() const; + + Kind kind() const; + void setKind(Kind kind); + + QString id() const; + void setId(const QString& id); + + private: + QSharedDataPointer d; +}; +} + +APPSTREAMQT_EXPORT QDebug operator<<(QDebug s, const AppStream::Translation& category); + +#endif // APPSTREAMQT_TRANSLATION_H + +