Syndication

enclosurerss2impl.cpp
1 /*
2  This file is part of the syndication library
3  SPDX-FileCopyrightText: 2006 Frank Osterfeld <[email protected]>
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 
14 namespace Syndication
15 {
16 EnclosureRSS2Impl::EnclosureRSS2Impl(const Syndication::RSS2::Item &item, const Syndication::RSS2::Enclosure &enc)
17  : m_item(item)
18  , m_enclosure(enc)
19 {
20 }
21 
23 {
24  return m_enclosure.isNull();
25 }
26 
28 {
29  return m_enclosure.url();
30 }
31 
33 {
34  // RSS2 enclosures have no title
35  return QString();
36 }
37 
39 {
40  return m_enclosure.type();
41 }
42 
44 {
45  return m_enclosure.length();
46 }
47 
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
const T & at(int i) const const
Describes a media object that is "attached" to the item.
int count(const T &value) const const
void append(const T &value)
bool isEmpty() const const
QStringList split(const QString &sep, QString::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
uint length() const override
returns the length of the linked file in bytes
QString title() const override
title of the enclosure.
QString url() const override
The URL of the linked resource (required).
uint duration() const override
for audio/video files, the duration of the file in seconds
bool isNull() const override
returns whether this enclosure is a null object.
QString type() const override
mimetype of the enclosure.
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Dec 6 2021 22:54:25 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.