File: release-list.cpp

package info (click to toggle)
appstream 1.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 18,448 kB
  • sloc: ansic: 51,878; xml: 10,459; cpp: 4,721; python: 538; sh: 264; makefile: 24
file content (152 lines) | stat: -rw-r--r-- 3,332 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
 * Copyright (C) 2019-2024 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 "release-list.h"

#include <QSharedData>
#include <QDebug>

using namespace AppStream;

class AppStream::ReleaseListData : public QSharedData
{
public:
    ReleaseListData()
    {
        m_rels = as_release_list_new();
    }

    ReleaseListData(AsReleaseList *rels)
        : m_rels(rels)
    {
        g_object_ref(m_rels);
    }

    ~ReleaseListData()
    {
        g_object_unref(m_rels);
    }

    bool operator==(const ReleaseListData &rd) const
    {
        return rd.m_rels == m_rels;
    }

    AsReleaseList *ReleaseList() const
    {
        return m_rels;
    }

    AsReleaseList *m_rels;
};

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

ReleaseList::ReleaseList()
    : d(new ReleaseListData())
{
}

ReleaseList::ReleaseList(_AsReleaseList *rels)
    : d(new ReleaseListData(rels))
{
}

ReleaseList::~ReleaseList() { }

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

_AsReleaseList *AppStream::ReleaseList::cPtr() const
{
    return d->ReleaseList();
}

QList<Release> ReleaseList::entries() const
{
    QList<Release> res;
    res.reserve(as_release_list_len(d->m_rels));
    for (uint i = 0; i < as_release_list_len(d->m_rels); i++) {
        Release release(as_release_list_index(d->m_rels, i));
        res.append(release);
    }

    return res;
}

uint ReleaseList::size() const
{
    return as_release_list_get_size(d->m_rels);
}

bool ReleaseList::isEmpty() const
{
    return as_release_list_is_empty(d->m_rels);
}

void ReleaseList::clear()
{
    as_release_list_clear(d->m_rels);
}

std::optional<Release> ReleaseList::indexSafe(uint index) const
{
    std::optional<Release> result;
    AsRelease *release = as_release_list_index_safe(d->m_rels, index);
    if (release != nullptr)
        result = Release(release);
    return result;
}

void ReleaseList::add(Release &release)
{
    as_release_list_add(d->m_rels, release.cPtr());
}

void ReleaseList::sort()
{
    as_release_list_sort(d->m_rels);
}

ReleaseList::Kind ReleaseList::kind() const
{
    return static_cast<ReleaseList::Kind>(as_release_list_get_kind(d->m_rels));
}

void ReleaseList::setKind(Kind kind)
{
    as_release_list_set_kind(d->m_rels, static_cast<AsReleaseListKind>(kind));
}

QString ReleaseList::url() const
{
    return QString::fromUtf8(as_release_list_get_url(d->m_rels));
}

void ReleaseList::setUrl(const QString &url)
{
    as_release_list_set_url(d->m_rels, qPrintable(url));
}