File: content.cpp

package info (click to toggle)
attica 0.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 644 kB
  • sloc: cpp: 5,227; makefile: 3
file content (325 lines) | stat: -rw-r--r-- 8,175 bytes parent folder | download
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
/*
    This file is part of KDE.

    Copyright (c) 2008 Cornelius Schumacher <schumacher@kde.org>

    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) version 3, or any
    later version accepted by the membership of KDE e.V. (or its
    successor approved by the membership of KDE e.V.), which shall
    act as a proxy defined in Section 6 of version 3 of the license.

    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 "content.h"

#include <QtCore/QDateTime>

using namespace Attica;

class Content::Private : public QSharedData {
    public:
        QString m_id;
        QString m_name;
        int m_downloads;
        int m_numberOfComments;
        int m_rating;
        QDateTime m_created;
        QDateTime m_updated;
        QList<Icon> m_icons;
        QList<QUrl> m_videos;

        QMap<QString,QString> m_extendedAttributes;

        Private()
            : m_downloads(0),
              m_rating(0),
              m_numberOfComments(0)
        {
        }
};


Content::Content()
  : d(new Private)
{
}

Content::Content(const Attica::Content& other)
    : d(other.d)
{
}

Content& Content::operator=(const Attica::Content & other)
{
    d = other.d;
    return *this;
}

Content::~Content()
{
}


void Content::setId( const QString &u )
{
  d->m_id = u;
}

QString Content::id() const
{
  return d->m_id;
}

void Content::setName( const QString &name )
{
  d->m_name = name;
}

QString Content::name() const
{
  return d->m_name;
}

void Content::setRating( int v )
{
  d->m_rating = v;
}

int Content::rating() const
{
  return d->m_rating;
}

void Content::setDownloads( int v )
{
  d->m_downloads = v;
}

int Content::downloads() const
{
  return d->m_downloads;
}

void Content::setNumberOfComments(int v)
{
  d->m_numberOfComments = v;
}

int Content::numberOfComments() const
{
  return d->m_numberOfComments;
}

void Content::setCreated( const QDateTime &date )
{
  d->m_created = date;
}

QDateTime Content::created() const
{
  return d->m_created;
}

void Content::setUpdated( const QDateTime &date )
{
  d->m_updated = date;
}

QDateTime Content::updated() const
{
  return d->m_updated;
}

void Content::addAttribute( const QString &key, const QString &value )
{
  d->m_extendedAttributes.insert( key, value );
}

QString Content::attribute( const QString &key ) const
{
  return d->m_extendedAttributes.value( key );
}

QMap<QString,QString> Content::attributes() const
{
  return d->m_extendedAttributes;
}

bool Content::isValid() const
{
  return !(d->m_id.isEmpty());
}

QString Content::summary() const
{
    return attribute(QLatin1String( "summary" ));
}

QString Content::description() const
{
    return attribute(QLatin1String( "description" ));
}

QUrl Content::detailpage() const
{
    return attribute(QLatin1String( "detailpage" ));
}

QString Attica::Content::changelog() const
{
    return attribute(QLatin1String( "changelog" ));

}

QString Attica::Content::depend() const
{
    return attribute(QLatin1String( "depend" ));
}

QList<Attica::DownloadDescription> Attica::Content::downloadUrlDescriptions() const
{
    QList<Attica::DownloadDescription> descriptions;
    QMap<QString,QString>::const_iterator iter = d->m_extendedAttributes.constBegin();
    while (iter != d->m_extendedAttributes.constEnd()) {
        QString key = iter.key();
        if (key.startsWith(QLatin1String("downloadname"))) {
            bool ok;
            // remove "downloadlink", get the rest as number
            int num = key.right(key.size() - 12).toInt(&ok);
            if (ok) {
                // check if the download actually has a name
                if (!iter.value().isEmpty()) {
                    descriptions.append(downloadUrlDescription(num));
                }
            }
        }
        ++iter;
    }
    return descriptions;
}

Attica::DownloadDescription Attica::Content::downloadUrlDescription(int number) const
{
    QString num(QString::number(number));
    DownloadDescription desc;

    Attica::DownloadDescription::Type downloadType = Attica::DownloadDescription::LinkDownload;
    if (attribute(QLatin1String( "downloadway" ) + num) == QLatin1String( "0" )) {
        downloadType = Attica::DownloadDescription::FileDownload;
    } else if (attribute(QLatin1String( "downloadway" ) + num) == QLatin1String( "1" )) {
        downloadType = Attica::DownloadDescription::LinkDownload;
    } else if (attribute(QLatin1String( "downloadway" ) + num) == QLatin1String( "2" )) {
        downloadType = Attica::DownloadDescription::PackageDownload;
    }
    desc.setType(downloadType);
    desc.setId(number);
    desc.setName(attribute(QLatin1String( "downloadname" ) + num));
    desc.setDistributionType(attribute(QLatin1String( "downloadtype" ) + num));
    desc.setHasPrice(attribute(QLatin1String( "downloadbuy" ) + num) == QLatin1String( "1" ));
    desc.setLink(attribute(QLatin1String( "downloadlink" ) + num));
    desc.setPriceReason(attribute(QLatin1String( "downloadreason" ) + num));
    desc.setPriceAmount(attribute(QLatin1String( "downloadprice" ) + num));
    desc.setSize(attribute(QLatin1String( "downloadsize" ) + num).toUInt());
    desc.setGpgFingerprint(attribute(QLatin1String( "downloadgpgfingerprint" )) + num);
    desc.setGpgSignature(attribute(QLatin1String( "downloadgpgsignature" )) + num);
    desc.setPackageName(attribute(QLatin1String( "downloadpackagename" )) + num);
    desc.setRepository(attribute(QLatin1String( "downloadrepository" )) + num);
    return desc;
}

QList<HomePageEntry> Attica::Content::homePageEntries()
{
    QList<Attica::HomePageEntry> homepages;
    QMap<QString,QString>::const_iterator iter = d->m_extendedAttributes.constBegin();
    while (iter != d->m_extendedAttributes.constEnd()) {
        QString key = iter.key();
        if (key.startsWith(QLatin1String("homepagetype"))) {
            bool ok;
            // remove "homepage", get the rest as number
            int num = key.right(key.size() - 12).toInt(&ok);
            if (ok) {
                // check if the homepage actually has a valid type
                if (!iter.value().isEmpty()) {
                    homepages.append(homePageEntry(num));
                }
            }
        }
        ++iter;
    }

    return homepages;
}

Attica::HomePageEntry Attica::Content::homePageEntry(int number) const
{
    QString num(QString::number(number));
    HomePageEntry homepage;

    if (number == 1 && attribute(QLatin1String( "homepage1" )).isEmpty()) {
        num.clear();
    }
    homepage.setType(attribute(QLatin1String( "homepagetype" ) + num));
    homepage.setUrl(attribute(QLatin1String( "homepage" ) + num));
    return homepage;
}

QString Attica::Content::version() const
{
    return attribute(QLatin1String( "version" ));
}

QString Attica::Content::author() const
{
    return attribute(QLatin1String( "personid" ));
}

QString Attica::Content::license() const
{
    return attribute(QLatin1String( "licensetype" ));
}

QString Attica::Content::licenseName() const
{
    return attribute(QLatin1String( "license" ));
}

QString Attica::Content::previewPicture(const QString& number) const
{
    return attribute(QLatin1String( "previewpic" ) + number);
}

QString Attica::Content::smallPreviewPicture(const QString& number) const
{
    return attribute(QLatin1String( "smallpreviewpic" ) + number);
}

QList<Icon> Attica::Content::icons()
{
    return d->m_icons;
}

void Attica::Content::setIcons(QList<Icon> icons)
{
    d->m_icons = icons;
}

QList<QUrl> Attica::Content::videos()
{
    return d->m_videos;
}

void Attica::Content::setVideos(QList<QUrl> videos)
{
    d->m_videos = videos;
}