Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce AppStream::Suggested in the Qt frontend #93

Merged
merged 1 commit into from Nov 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -31,6 +31,7 @@ set(APPSTREAMQT_SRC
provided.cpp
release.cpp
bundle.cpp
suggested.cpp
)

set(APPSTREAMQT_PUBLIC_HEADERS
@@ -43,6 +44,7 @@ set(APPSTREAMQT_PUBLIC_HEADERS
provided.h
release.h
bundle.h
suggested.h
)

include_directories(${CMAKE_CURRENT_SOURCE_DIR}
@@ -30,6 +30,7 @@
#include "screenshot.h"
#include "release.h"
#include "bundle.h"
#include "suggested.h"

using namespace AppStream;

@@ -385,6 +386,19 @@ Bundle Component::bundle(Bundle::Kind kind) const
return Bundle(bundle);
}

QList<AppStream::Suggested> AppStream::Component::suggested() const
{
QList<Suggested> res;

auto suggestions = as_component_get_suggested(m_cpt);
res.reserve(suggestions->len);
for (uint i = 0; i < suggestions->len; i++) {
auto suggestion = AS_SUGGESTED (g_ptr_array_index (suggestions, i));
res.append(Suggested(suggestion));
}
return res;
}

bool Component::isValid() const
{
return as_component_is_valid(m_cpt);
@@ -35,6 +35,7 @@ namespace AppStream {
class Icon;
class Screenshot;
class Release;
class Suggested;

class ComponentData;

@@ -147,6 +148,8 @@ Q_GADGET
QList<AppStream::Bundle> bundles() const;
AppStream::Bundle bundle(Bundle::Kind kind) const;

QList<AppStream::Suggested> suggested() const;

bool isValid() const;

private:
@@ -0,0 +1,101 @@
/*
* Copyright (C) 2016 Aleix Pol Gonzalez <aleixpol@kde.org>
*
* 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 "suggested.h"

#include <QSharedData>
#include <QSize>
#include <QUrl>
#include <QDebug>
#include "chelpers.h"

using namespace AppStream;

class AppStream::SuggestedData : public QSharedData {
public:
SuggestedData()
{
m_suggested = as_suggested_new();
}

SuggestedData(AsSuggested *suggested)
: m_suggested(suggested)
{
g_object_ref(m_suggested);
}

~SuggestedData()
{
g_object_unref(m_suggested);
}

bool operator==(const SuggestedData& rd) const
{
return rd.m_suggested == m_suggested;
}

AsSuggested *m_suggested;
};

Suggested::Suggested(const Suggested& other)
: d(other.d)
{}

Suggested::Suggested()
: d(new SuggestedData)
{}

Suggested::Suggested(_AsSuggested *suggested)
: d(new SuggestedData(suggested))
{}

Suggested::~Suggested()
{}

Suggested& Suggested::operator=(const Suggested& other)
{
this->d = other.d;
return *this;
}

Suggested::Kind Suggested::kind() const
{
return Suggested::Kind(as_suggested_get_kind(d->m_suggested));
}

void Suggested::setKind(Suggested::Kind kind)
{
as_suggested_set_kind(d->m_suggested, (AsSuggestedKind) kind);
}

const QStringList AppStream::Suggested::ids() const
{
return valueWrap(as_suggested_get_ids(d->m_suggested));
}

void AppStream::Suggested::addSuggested(const QString& id)
{
as_suggested_add_id(d->m_suggested, qPrintable(id));
}

QDebug operator<<(QDebug s, const AppStream::Suggested& image) {
Copy link
Owner

@ximion ximion Nov 26, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: Image? (also, bracked should come after a newline for functions)

s.nospace() << "AppStream::Suggested(" << image.ids() << ")";
return s.space();
}
@@ -0,0 +1,75 @@
/*
* Copyright (C) 2016 Aleix Pol Gonzalez <aleixpol@kde.org>
*
* 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_SUGGESTED_H
#define APPSTREAMQT_SUGGESTED_H

#include <QSharedDataPointer>
#include <QObject>
#include "appstreamqt_export.h"

class QUrl;
class QString;
struct _AsSuggested;
namespace AppStream {

class SuggestedData;

/**
* This class provides a list of other component-ids suggested by a software component, as well
* as an origin of the suggestion (manually suggested by the upstream project, or
* automatically determined by heuristics)..
*/
class APPSTREAMQT_EXPORT Suggested {
Q_GADGET
public:
enum Kind {
KindUnknown,
KindUpstream,
KindHeuristic
};
Q_ENUM(Kind)

Suggested();
Suggested(_AsSuggested *suggested);
Suggested(const Suggested& other);
~Suggested();

Suggested& operator=(const Suggested& other);

/**
* \return the kind of suggestion
*/
Kind kind() const;
void setKind(Kind kind);

/**
* \return the local or remote url for this suggested
*/
const QStringList ids() const;
void addSuggested(const QString &id);

private:
QSharedDataPointer<SuggestedData> d;
};
}

APPSTREAMQT_EXPORT QDebug operator<<(QDebug s, const AppStream::Suggested& suggested);

#endif // APPSTREAMQT_SUGGESTED_H