Commit 4e0005a9 authored by Laurent Montel's avatar Laurent Montel 😁

Don't create all grantlee engine when not necessary

parent 1860e669
......@@ -77,8 +77,7 @@ ArticleViewerWidget::ArticleViewerWidget(const QString &grantleeDirectory, KActi
m_node(0),
m_viewMode(NormalView),
m_articleViewerWidgetNg(new Akregator::ArticleViewerWebEngineWidgetNg(ac, this)),
m_normalViewFormatter(new DefaultNormalViewFormatter(grantleeDirectory, m_imageDir, m_articleViewerWidgetNg->articleViewerNg())),
m_combinedViewFormatter(new DefaultCombinedViewFormatter(grantleeDirectory, m_imageDir, m_articleViewerWidgetNg->articleViewerNg()))
m_grantleeDirectory(grantleeDirectory)
{
QGridLayout *layout = new QGridLayout(this);
layout->setMargin(0);
......@@ -92,6 +91,22 @@ ArticleViewerWidget::~ArticleViewerWidget()
{
}
QSharedPointer<ArticleFormatter> ArticleViewerWidget::normalViewFormatter()
{
if (!m_normalViewFormatter.data()) {
m_normalViewFormatter = QSharedPointer<ArticleFormatter>(new DefaultNormalViewFormatter(m_grantleeDirectory, m_imageDir, m_articleViewerWidgetNg->articleViewerNg()));
}
return m_normalViewFormatter;
}
QSharedPointer<ArticleFormatter> ArticleViewerWidget::combinedViewFormatter()
{
if (!m_combinedViewFormatter.data()) {
m_combinedViewFormatter = QSharedPointer<ArticleFormatter>(new DefaultCombinedViewFormatter(m_grantleeDirectory, m_imageDir, m_articleViewerWidgetNg->articleViewerNg()));
}
return m_combinedViewFormatter;
}
void ArticleViewerWidget::slotZoomChangeInFrame(qreal value)
{
m_articleViewerWidgetNg->articleViewerNg()->setZoomFactor(value);
......@@ -171,7 +186,7 @@ void ArticleViewerWidget::slotShowSummary(TreeNode *node)
m_node = node;
}
const QString summary = m_normalViewFormatter->formatSummary(node);
const QString summary = normalViewFormatter()->formatSummary(node);
m_link.clear();
renderContent(summary);
......@@ -193,7 +208,7 @@ void ArticleViewerWidget::showArticle(const Akregator::Article &article)
if (article.feed()->loadLinkedWebsite()) {
openUrl(article.link());
} else {
renderContent(m_normalViewFormatter->formatArticles(QVector<Akregator::Article>() << article, ArticleFormatter::ShowIcon));
renderContent(normalViewFormatter()->formatArticles(QVector<Akregator::Article>() << article, ArticleFormatter::ShowIcon));
}
setArticleActionsEnabled(true);
......@@ -252,7 +267,7 @@ void ArticleViewerWidget::slotUpdateCombinedView()
articles << i;
++num;
}
text = m_combinedViewFormatter->formatArticles(articles, ArticleFormatter::NoIcon);
text = combinedViewFormatter()->formatArticles(articles, ArticleFormatter::NoIcon);
qCDebug(AKREGATOR_LOG) << "Combined view rendering: (" << num << " articles):" << "generating HTML:" << spent.elapsed() << "ms";
renderContent(text);
......@@ -365,7 +380,7 @@ void ArticleViewerWidget::updateAfterConfigChanged()
switch (m_viewMode) {
case NormalView:
if (!m_article.isNull()) {
renderContent(m_normalViewFormatter->formatArticles(QVector<Akregator::Article>() << m_article, ArticleFormatter::ShowIcon));
renderContent(normalViewFormatter()->formatArticles(QVector<Akregator::Article>() << m_article, ArticleFormatter::ShowIcon));
}
break;
case CombinedView:
......
......@@ -128,7 +128,8 @@ protected Q_SLOTS:
// from ArticleViewer
private:
QSharedPointer<ArticleFormatter> combinedViewFormatter();
QSharedPointer<ArticleFormatter> normalViewFormatter();
void keyPressEvent(QKeyEvent *e) Q_DECL_OVERRIDE;
/** renders @c body. Use this method whereever possible.
......@@ -162,6 +163,7 @@ private:
Akregator::ArticleViewerWebEngineWidgetNg *m_articleViewerWidgetNg;
QSharedPointer<ArticleFormatter> m_normalViewFormatter;
QSharedPointer<ArticleFormatter> m_combinedViewFormatter;
QString m_grantleeDirectory;
};
} // namespace Akregator
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment