File indexing completed on 2024-05-12 05:12:54

0001 /*
0002     This file is part of Akregator.
0003 
0004     SPDX-FileCopyrightText: 2006 Frank Osterfeld <osterfeld@kde.org>
0005 
0006     SPDX-License-Identifier: GPL-2.0-or-later WITH Qt-Commercial-exception-1.0
0007 */
0008 
0009 #include "articleformatter.h"
0010 #include "akregatorconfig.h"
0011 #include "article.h"
0012 #include "utils.h"
0013 
0014 #include <KLocalizedString>
0015 
0016 #include <KIO/Global>
0017 
0018 using namespace Syndication;
0019 using namespace Akregator;
0020 
0021 ArticleFormatter::ArticleFormatter() = default;
0022 
0023 ArticleFormatter::~ArticleFormatter() = default;
0024 
0025 QString ArticleFormatter::formatEnclosure(const Enclosure &enclosure)
0026 {
0027     if (enclosure.isNull()) {
0028         return {};
0029     }
0030 
0031     const QString title = !enclosure.title().isEmpty() ? enclosure.title() : enclosure.url();
0032     const uint length = enclosure.length();
0033     const QString type = enclosure.type();
0034     QString inf;
0035     if (!type.isEmpty() && length > 0) {
0036         inf = i18n("(%1, %2)", type, KIO::convertSize(length));
0037     } else if (!type.isNull()) {
0038         inf = type;
0039     } else if (length > 0) {
0040         inf = KIO::convertSize(length);
0041     }
0042     const QString str = QStringLiteral("<a href=\"%1\">%2</a> %3").arg(enclosure.url(), title, inf);
0043     return str;
0044 }