File indexing completed on 2024-05-12 05:12:54
0001 /* 0002 SPDX-FileCopyrightText: 2016-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "defaultnormalviewformatter.h" 0008 #include "akregatorconfig.h" 0009 #include "article.h" 0010 #include "feed.h" 0011 #include "folder.h" 0012 #include "grantleeviewformatter.h" 0013 #include "treenode.h" 0014 #include "treenodevisitor.h" 0015 0016 #include <QPaintDevice> 0017 #include <QString> 0018 0019 using namespace Syndication; 0020 0021 using namespace Akregator; 0022 0023 class DefaultNormalViewFormatter::SummaryVisitor : public TreeNodeVisitor 0024 { 0025 public: 0026 SummaryVisitor(DefaultNormalViewFormatter *p) 0027 : parent(p) 0028 { 0029 } 0030 0031 ~SummaryVisitor() override = default; 0032 0033 bool visitFeed(Feed *node) override 0034 { 0035 text = parent->mGrantleeViewFormatter->formatFeed(node); 0036 return true; 0037 } 0038 0039 bool visitFolder(Folder *node) override 0040 { 0041 text = parent->mGrantleeViewFormatter->formatFolder(node); 0042 return true; 0043 } 0044 0045 QString formatSummary(TreeNode *node) 0046 { 0047 text.clear(); 0048 visit(node); 0049 return text; 0050 } 0051 0052 QString text; 0053 0054 private: 0055 DefaultNormalViewFormatter *const parent; 0056 }; 0057 0058 DefaultNormalViewFormatter::DefaultNormalViewFormatter(const QString &grantleeDirectory, QPaintDevice *device) 0059 : ArticleFormatter() 0060 , m_summaryVisitor(new SummaryVisitor(this)) 0061 { 0062 m_DefaultThemePath = QStandardPaths::locate(QStandardPaths::GenericDataLocation, 0063 QStringLiteral("akregator/grantleetheme/%1/").arg(grantleeDirectory), 0064 QStandardPaths::LocateDirectory); 0065 mGrantleeViewFormatter = new GrantleeViewFormatter(QStringLiteral("normalview.html"), m_DefaultThemePath, device->logicalDpiY()); 0066 } 0067 0068 DefaultNormalViewFormatter::~DefaultNormalViewFormatter() 0069 { 0070 delete mGrantleeViewFormatter; 0071 delete m_summaryVisitor; 0072 } 0073 0074 QString DefaultNormalViewFormatter::formatSummary(TreeNode *node) const 0075 { 0076 return m_summaryVisitor->formatSummary(node); 0077 } 0078 0079 QString DefaultNormalViewFormatter::formatArticles(const QList<Article> &articles, IconOption icon) const 0080 { 0081 if (articles.count() != 1) { 0082 return {}; 0083 } 0084 return mGrantleeViewFormatter->formatArticles(articles, icon); 0085 }