KNewStuff

downloadlinkinfo.cpp
1/*
2 SPDX-FileCopyrightText: 2016 Dan Leinir Turthra Jensen <admin@leinir.dk>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6
7#include "downloadlinkinfo.h"
8#include <KFormat>
9#include <QMimeDatabase>
10
11class DownloadLinkInfoPrivate : public QSharedData
12{
13public:
14 QString name;
15 QString priceAmount;
16 QString distributionType;
17 QString descriptionLink;
18 int id = 0;
19 bool isDownloadtypeLink = true;
20 quint64 size = 0;
21 QString mimeType;
22 QString icon;
23};
24
25DownloadLinkInfo::DownloadLinkInfo(const KNSCore::Entry::DownloadLinkInformation &data)
26 : d(new DownloadLinkInfoPrivate)
27{
28 d->name = data.name;
29 d->priceAmount = data.priceAmount;
30 d->distributionType = data.distributionType;
31 d->descriptionLink = data.descriptionLink;
32 d->id = data.id;
33 d->isDownloadtypeLink = data.isDownloadtypeLink;
34 d->size = data.size;
36 for (QString string : data.tags) {
37 if (string.startsWith(QStringLiteral("data##mimetype="))) {
38 d->mimeType = string.split(QStringLiteral("=")).last();
39 }
40 }
41 d->icon = db.mimeTypeForName(d->mimeType).iconName();
42 if (d->icon.isEmpty()) {
43 d->icon = db.mimeTypeForName(d->mimeType).genericIconName();
44 }
45 if (d->icon.isEmpty()) {
46 d->icon = QStringLiteral("download");
47 }
48}
49
50DownloadLinkInfo::DownloadLinkInfo(const DownloadLinkInfo &) = default;
51DownloadLinkInfo &DownloadLinkInfo::operator=(const DownloadLinkInfo &) = default;
52DownloadLinkInfo::~DownloadLinkInfo() = default;
53
54QString DownloadLinkInfo::name() const
55{
56 return d->name;
57}
58
59QString DownloadLinkInfo::priceAmount() const
60{
61 return d->priceAmount;
62}
63
64QString DownloadLinkInfo::distributionType() const
65{
66 return d->distributionType;
67}
68
69QString DownloadLinkInfo::descriptionLink() const
70{
71 return d->descriptionLink;
72}
73
74int DownloadLinkInfo::id() const
75{
76 return d->id;
77}
78
79bool DownloadLinkInfo::isDownloadtypeLink() const
80{
81 return d->isDownloadtypeLink;
82}
83
84quint64 DownloadLinkInfo::size() const
85{
86 return d->size;
87}
88
89QString DownloadLinkInfo::formattedSize() const
90{
91 static const KFormat formatter;
92 if (d->size == 0) {
93 return QString();
94 }
95 return formatter.formatByteSize(d->size * 1000);
96}
97
98QString DownloadLinkInfo::icon() const
99{
100 return d->icon;
101}
102
103#include "moc_downloadlinkinfo.cpp"
One downloadable item as contained within one content item.
QString formatByteSize(double size, int precision=1, KFormat::BinaryUnitDialect dialect=KFormat::DefaultBinaryDialect, KFormat::BinarySizeUnits units=KFormat::DefaultBinaryUnits) const
QMimeType mimeTypeForName(const QString &nameOrAlias) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:07:37 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.