1 /* 2 This file is part of Akregator. 3 4 SPDX-FileCopyrightText: 2006 Frank Osterfeld <osterfeld@kde.org> 5 6 SPDX-License-Identifier: GPL-2.0-or-later WITH Qt-Commercial-exception-1.0 7 */ 8 9 #include "articleformatter.h" 10 #include "akregatorconfig.h" 11 #include "article.h" 12 #include "feed.h" 13 #include "folder.h" 14 #include "treenode.h" 15 #include "treenodevisitor.h" 16 #include "utils.h" 17 18 #include <KLocalizedString> 19 20 #include <KFormat> 21 22 using namespace Syndication; 23 using namespace Akregator; 24 ArticleFormatter()25ArticleFormatter::ArticleFormatter() 26 { 27 } 28 29 ArticleFormatter::~ArticleFormatter() = default; 30 formatEnclosure(const Enclosure & enclosure)31QString ArticleFormatter::formatEnclosure(const Enclosure &enclosure) 32 { 33 if (enclosure.isNull()) { 34 return QString(); 35 } 36 37 const QString title = !enclosure.title().isEmpty() ? enclosure.title() : enclosure.url(); 38 const uint length = enclosure.length(); 39 const QString type = enclosure.type(); 40 QString inf; 41 if (!type.isEmpty() && length > 0) { 42 inf = i18n("(%1, %2)", type, KFormat().formatByteSize(length)); 43 } else if (!type.isNull()) { 44 inf = type; 45 } else if (length > 0) { 46 inf = KFormat().formatByteSize(length); 47 } 48 const QString str = QStringLiteral("<a href=\"%1\">%2</a> %3").arg(enclosure.url(), title, inf); 49 return str; 50 } 51