Syndication

rss2/image.cpp
1 /*
2  This file is part of the syndication library
3  SPDX-FileCopyrightText: 2005 Frank Osterfeld <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7 
8 #include "image.h"
9 
10 #include <QString>
11 
12 namespace Syndication
13 {
14 namespace RSS2
15 {
17  : ElementWrapper()
18 {
19 }
20 
21 Image::Image(const QDomElement &element)
22  : ElementWrapper(element)
23 {
24 }
25 
27 {
28  return extractElementTextNS(QString(), QStringLiteral("url"));
29 }
30 
32 {
33  return extractElementTextNS(QString(), QStringLiteral("title"));
34 }
35 
37 {
38  return extractElementTextNS(QString(), QStringLiteral("link"));
39 }
40 
41 uint Image::width() const
42 {
43  QString text;
44  bool ok;
45  uint c;
46 
47  text = extractElementTextNS(QString(), QStringLiteral("width"));
48  c = text.toUInt(&ok);
49  return ok ? c : 88; // set to default if not parsable
50 }
51 
52 uint Image::height() const
53 {
54  QString text;
55  bool ok;
56  uint c;
57 
58  text = extractElementTextNS(QString(), QStringLiteral("height"));
59  c = text.toUInt(&ok);
60  return ok ? c : 31; // set to default if not parsable
61 }
62 
64 {
65  return extractElementTextNS(QString(), QStringLiteral("description"));
66 }
67 
69 {
70  QString info = QLatin1String("### Image: ###################\n");
71  if (!title().isNull()) {
72  info += QLatin1String("title: #") + title() + QLatin1String("#\n");
73  }
74  if (!link().isNull()) {
75  info += QLatin1String("link: #") + link() + QLatin1String("#\n");
76  }
77  if (!description().isNull()) {
78  info += QLatin1String("description: #") + description() + QLatin1String("#\n");
79  }
80  if (!url().isNull()) {
81  info += QLatin1String("url: #") + url() + QLatin1String("#\n");
82  }
83  info += QLatin1String("width: #") + QString::number(width()) + QLatin1String("#\n");
84  info += QLatin1String("height: #") + QString::number(height()) + QLatin1String("#\n");
85  info += QLatin1String("### Image end ################\n");
86  return info;
87 }
88 
89 } // namespace RSS2
90 } // namespace Syndication
QString number(int n, int base)
QString url() const
the URL of a GIF, JPEG or PNG image
Definition: rss2/image.cpp:26
Image()
Default constructor, creates a null object, for which isNull() is true.
Definition: rss2/image.cpp:16
uint height() const
The height of the image.
Definition: rss2/image.cpp:52
QString debugInfo() const
Returns a description of the object for debugging purposes.
Definition: rss2/image.cpp:68
uint width() const
The width of the image.
Definition: rss2/image.cpp:41
uint toUInt(bool *ok, int base) const const
QString title() const
Describes the image, can be used in the ALT attribute of the HTML <img> tag when the channel is rende...
Definition: rss2/image.cpp:31
QString link() const
The URL of the site, when the channel is rendered, the image should be a link to the site.
Definition: rss2/image.cpp:36
QString description() const
optional text that can be included in the TITLE attribute of the link formed around the image in HTML...
Definition: rss2/image.cpp:63
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Thu Nov 30 2023 03:51:26 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.