264 changes: 264 additions & 0 deletions qt/component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<Component::Kind>(as_component_get_kind (m_cpt));
Expand All @@ -161,6 +189,16 @@ void Component::setKind(Component::Kind kind)
as_component_set_kind(m_cpt, static_cast<AsComponentKind>(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));
Expand All @@ -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));
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand All @@ -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));
Expand All @@ -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<AppStream::Component> Component::addons() const
{
QList<AppStream::Component> res;
Expand All @@ -284,6 +377,44 @@ QList<AppStream::Component> 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::Translation> AppStream::Component::translations() const
{
QList<Translation> 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<AsUrlKind>(kind));
Expand All @@ -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<Icon> Component::icons() const
{
QList<Icon> res;
Expand All @@ -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<Provided> Component::provided() const
{
QList<Provided> res;
Expand All @@ -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<Screenshot> Component::screenshots() const
{
QList<Screenshot> res;
Expand All @@ -347,6 +493,11 @@ QList<Screenshot> Component::screenshots() const
return res;
}

void AppStream::Component::addScreenshot(const AppStream::Screenshot& screenshot)
{
as_component_add_screenshot(m_cpt, screenshot.asScreenshot());
}

QList<Release> Component::releases() const
{
QList<Release> res;
Expand All @@ -360,6 +511,16 @@ QList<Release> 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<Bundle> Component::bundles() const
{
QList<Bundle> res;
Expand All @@ -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::Suggested> AppStream::Component::suggested() const
{
QList<Suggested> res;
Expand All @@ -394,11 +560,109 @@ QList<AppStream::Suggested> 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<Component::MergeKind>(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<QString, QString> AppStream::Component::custom() const
{
QHash<QString, QString> 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<char*>(key)), valueWrap(static_cast<char*>(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::ContentRating> AppStream::Component::contentRatings() const
{
QList<ContentRating> 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);
Expand Down
83 changes: 81 additions & 2 deletions qt/component.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -62,6 +66,13 @@ Q_GADGET
};
Q_ENUM(Kind)

enum MergeKind {
MergeKindNone,
MergeKindReplace,
MergeKindAppend
};
Q_ENUM(MergeKind)

enum UrlKind {
UrlKindUnknown,
UrlKindHomepage,
Expand All @@ -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);

Expand All @@ -84,16 +102,31 @@ 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);

QString dataId() const;
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 = {});
Expand All @@ -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);

Expand All @@ -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<AppStream::Component> 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<AppStream::Translation> translations() const;
void addTranslation(const AppStream::Translation& translation);

QUrl url(UrlKind kind) const;
void addUrl(UrlKind kind, const QString& url);

QList<AppStream::Icon> 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.
Expand All @@ -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<AppStream::Screenshot> screenshots() const;
void addScreenshot(const AppStream::Screenshot& screenshot);

QList<AppStream::Release> releases() const;
void addRelease(const AppStream::Release& release);

bool hasBundle() const;
QList<AppStream::Bundle> bundles() const;
AppStream::Bundle bundle(Bundle::Kind kind) const;
void addBundle(const AppStream::Bundle& bundle) const;

QList<AppStream::Suggested> 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<QString,QString> custom() const;
QString customValue(const QString& key);
bool insertCustomValue(const QString& key, const QString& value);

QList<AppStream::ContentRating> 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;
Expand Down
139 changes: 139 additions & 0 deletions qt/contentrating.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/*
* Copyright (C) 2017 Jan Grulich <jgrulich@redhat.com>
* Copyright (C) 2016 Matthias Klumpp <matthias@tenstral.net>
*
* 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 <http://www.gnu.org/licenses/>.
*/

#include "appstream.h"
#include "contentrating.h"

#include <QDebug>
#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<ContentRating::RatingValue, QString> 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<AppStream::ContentRating::RatingValue>(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();
}

82 changes: 82 additions & 0 deletions qt/contentrating.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@

/*
* Copyright (C) 2017 Jan Grulich <jgrulich@redhat.com>
* Copyright (C) 2016 Matthias Klumpp <matthias@tenstral.net>
*
* 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 <http://www.gnu.org/licenses/>.
*/

#ifndef APPSTREAMQT_CONTENT_RATING_H
#define APPSTREAMQT_CONTENT_RATING_H

#include <QSharedDataPointer>
#include <QString>
#include <QObject>
#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<ContentRatingData> d;
};
}

APPSTREAMQT_EXPORT QDebug operator<<(QDebug s, const AppStream::ContentRating& category);

#endif // APPSTREAMQT_CONTENT_RATING_H


9 changes: 9 additions & 0 deletions qt/icon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ class AppStream::IconData : public QSharedData {
return rd.m_icon == m_icon;
}

AsIcon *icon() const {
return m_icon;
}

AsIcon *m_icon;
};

Expand All @@ -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));
Expand Down
5 changes: 5 additions & 0 deletions qt/icon.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
10 changes: 10 additions & 0 deletions qt/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ class AppStream::ImageData : public QSharedData {
return rd.m_img == m_img;
}

AsImage *image() const
{
return m_img;
}

AsImage *m_img;
};

Expand All @@ -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));
Expand Down
5 changes: 5 additions & 0 deletions qt/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
130 changes: 130 additions & 0 deletions qt/launchable.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
/*
* Copyright (C) 2017 Jan Grulich <jgrulich@redhat.com>
* Copyright (C) 2016 Matthias Klumpp <matthias@tenstral.net>
*
* 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 <http://www.gnu.org/licenses/>.
*/

#include "appstream.h"
#include "launchable.h"

#include <QDebug>
#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<AppStream::Launchable::Kind>(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();
}
74 changes: 74 additions & 0 deletions qt/launchable.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright (C) 2017 Jan Grulich <jgrulich@redhat.com>
* Copyright (C) 2016 Matthias Klumpp <matthias@tenstral.net>
*
* 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 <http://www.gnu.org/licenses/>.
*/

#ifndef APPSTREAMQT_LAUNCHABLE_H
#define APPSTREAMQT_LAUNCHABLE_H

#include <QSharedDataPointer>
#include <QString>
#include <QObject>
#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<LaunchableData> d;
};
}

APPSTREAMQT_EXPORT QDebug operator<<(QDebug s, const AppStream::Launchable& category);

#endif // APPSTREAMQT_LAUNCHABLE_H

10 changes: 10 additions & 0 deletions qt/provided.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ class AppStream::ProvidedData : public QSharedData {
return rd.m_prov == m_prov;
}

AsProvided *provided() const
{
return m_prov;
}

AsProvided *m_prov;
};

Expand Down Expand Up @@ -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));
Expand Down
5 changes: 5 additions & 0 deletions qt/provided.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions qt/release.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ class AppStream::ReleaseData : public QSharedData {
return rd.m_release == m_release;
}

AsRelease *release() const
{
return m_release;
}

AsRelease* m_release;
};

Expand All @@ -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));
Expand Down
5 changes: 5 additions & 0 deletions qt/release.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions qt/screenshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ class AppStream::ScreenshotData : public QSharedData {
return rd.m_scr == m_scr;
}

AsScreenshot *screenshot() const
{
return m_scr;
}

AsScreenshot *m_scr;
};

Expand All @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions qt/screenshot.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions qt/suggested.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ class AppStream::SuggestedData : public QSharedData {
return rd.m_suggested == m_suggested;
}

AsSuggested *suggested() const
{
return m_suggested;
}

AsSuggested *m_suggested;
};

Expand All @@ -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));
Expand Down
5 changes: 5 additions & 0 deletions qt/suggested.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
133 changes: 133 additions & 0 deletions qt/translation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/*
* Copyright (C) 2017 Jan Grulich <jgrulich@redhat.com>
* Copyright (C) 2016 Matthias Klumpp <matthias@tenstral.net>
*
* 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 <http://www.gnu.org/licenses/>.
*/

#include "appstream.h"
#include "translation.h"

#include <QDebug>
#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<AppStream::Translation::Kind>(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();
}
76 changes: 76 additions & 0 deletions qt/translation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright (C) 2017 Jan Grulich <jgrulich@redhat.com>
* Copyright (C) 2016 Matthias Klumpp <matthias@tenstral.net>
*
* 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 <http://www.gnu.org/licenses/>.
*/

#ifndef APPSTREAMQT_TRANSLATION_H
#define APPSTREAMQT_TRANSLATION_H

#include <QSharedDataPointer>
#include <QString>
#include <QObject>
#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<TranslationData> d;
};
}

APPSTREAMQT_EXPORT QDebug operator<<(QDebug s, const AppStream::Translation& category);

#endif // APPSTREAMQT_TRANSLATION_H