Syndication

enclosurerss2impl.cpp
1/*
2 This file is part of the syndication library
3 SPDX-FileCopyrightText: 2006 Frank Osterfeld <osterfeld@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#include "enclosurerss2impl.h"
9#include <constants.h>
10
11#include <QString>
12#include <QStringList>
13
14namespace Syndication
15{
16EnclosureRSS2Impl::EnclosureRSS2Impl(const Syndication::RSS2::Item &item, const Syndication::RSS2::Enclosure &enc)
17 : m_item(item)
18 , m_enclosure(enc)
19{
20}
21
22bool EnclosureRSS2Impl::isNull() const
23{
24 return m_enclosure.isNull();
25}
26
27QString EnclosureRSS2Impl::url() const
28{
29 return m_enclosure.url();
30}
31
32QString EnclosureRSS2Impl::title() const
33{
34 // RSS2 enclosures have no title
35 return QString();
36}
37
38QString EnclosureRSS2Impl::type() const
39{
40 return m_enclosure.type();
41}
42
43uint EnclosureRSS2Impl::length() const
44{
45 return m_enclosure.length();
46}
47
48uint EnclosureRSS2Impl::duration() const
49{
50 QString durStr = m_item.extractElementTextNS(itunesNamespace(), QStringLiteral("duration"));
51
52 if (durStr.isEmpty()) {
53 return 0;
54 }
55
56 const QStringList strTokens = durStr.split(QLatin1Char(':'));
57 QList<int> intTokens;
58
59 const int count = strTokens.count();
60 bool ok;
61
62 for (int i = 0; i < count; ++i) {
63 int intVal = strTokens.at(i).toInt(&ok);
64 if (ok) {
65 intTokens.append(intVal >= 0 ? intVal : 0); // do not accept negative values
66 } else {
67 return 0;
68 }
69 }
70
71 if (count == 3) {
72 return intTokens.at(0) * 3600 + intTokens.at(1) * 60 + intTokens.at(2);
73 } else if (count == 2) {
74 return intTokens.at(0) * 60 + intTokens.at(1);
75 } else if (count == 1) {
76 return intTokens.at(0);
77 }
78
79 return 0;
80}
81
82} // namespace Syndication
Describes a media object that is "attached" to the item.
void append(QList< T > &&value)
const_reference at(qsizetype i) const const
qsizetype count() const const
bool isEmpty() const const
qsizetype length() const const
QStringList split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:14:15 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.