Syndication

rss2/image.cpp
1/*
2 This file is part of the syndication library
3 SPDX-FileCopyrightText: 2005 Frank Osterfeld <osterfeld@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#include "image.h"
9
10#include <QString>
11
12namespace Syndication
13{
14namespace RSS2
15{
20
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
41uint Image::width() const
42{
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
52uint Image::height() const
53{
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
A wrapper for XML elements.
QString text() const
Returns the wrapped element's text or an empty string.
bool isNull() const
returns whether the wrapped element is a null element
QString extractElementTextNS(const QString &namespaceURI, const QString &localName) const
extracts the text from a child element, respecting namespaces.
QString description() const
optional text that can be included in the TITLE attribute of the link formed around the image in HTML...
QString link() const
The URL of the site, when the channel is rendered, the image should be a link to the site.
QString title() const
Describes the image, can be used in the ALT attribute of the HTML <img> tag when the channel is rende...
QString debugInfo() const
Returns a description of the object for debugging purposes.
uint width() const
The width of the image.
Image()
Default constructor, creates a null object, for which isNull() is true.
QString url() const
the URL of a GIF, JPEG or PNG image
uint height() const
The height of the image.
QString number(double n, char format, int precision)
uint toUInt(bool *ok, int base) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:03:18 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.