File indexing completed on 2024-07-07 03:55:24

0001 /*
0002     This file is part of the syndication library
0003     SPDX-FileCopyrightText: 2005 Frank Osterfeld <osterfeld@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #include "image.h"
0009 
0010 #include <QString>
0011 
0012 namespace Syndication
0013 {
0014 namespace RSS2
0015 {
0016 Image::Image()
0017     : ElementWrapper()
0018 {
0019 }
0020 
0021 Image::Image(const QDomElement &element)
0022     : ElementWrapper(element)
0023 {
0024 }
0025 
0026 QString Image::url() const
0027 {
0028     return extractElementTextNS(QString(), QStringLiteral("url"));
0029 }
0030 
0031 QString Image::title() const
0032 {
0033     return extractElementTextNS(QString(), QStringLiteral("title"));
0034 }
0035 
0036 QString Image::link() const
0037 {
0038     return extractElementTextNS(QString(), QStringLiteral("link"));
0039 }
0040 
0041 uint Image::width() const
0042 {
0043     QString text;
0044     bool ok;
0045     uint c;
0046 
0047     text = extractElementTextNS(QString(), QStringLiteral("width"));
0048     c = text.toUInt(&ok);
0049     return ok ? c : 88; // set to default if not parsable
0050 }
0051 
0052 uint Image::height() const
0053 {
0054     QString text;
0055     bool ok;
0056     uint c;
0057 
0058     text = extractElementTextNS(QString(), QStringLiteral("height"));
0059     c = text.toUInt(&ok);
0060     return ok ? c : 31; // set to default if not parsable
0061 }
0062 
0063 QString Image::description() const
0064 {
0065     return extractElementTextNS(QString(), QStringLiteral("description"));
0066 }
0067 
0068 QString Image::debugInfo() const
0069 {
0070     QString info = QLatin1String("### Image: ###################\n");
0071     if (!title().isNull()) {
0072         info += QLatin1String("title: #") + title() + QLatin1String("#\n");
0073     }
0074     if (!link().isNull()) {
0075         info += QLatin1String("link: #") + link() + QLatin1String("#\n");
0076     }
0077     if (!description().isNull()) {
0078         info += QLatin1String("description: #") + description() + QLatin1String("#\n");
0079     }
0080     if (!url().isNull()) {
0081         info += QLatin1String("url: #") + url() + QLatin1String("#\n");
0082     }
0083     info += QLatin1String("width: #") + QString::number(width()) + QLatin1String("#\n");
0084     info += QLatin1String("height: #") + QString::number(height()) + QLatin1String("#\n");
0085     info += QLatin1String("### Image end ################\n");
0086     return info;
0087 }
0088 
0089 } // namespace RSS2
0090 } // namespace Syndication