Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit d223e4fa authored by Volker Krause's avatar Volker Krause

Simplify MessagePartRendererFactory

It's not a base class for anything, so don't pretend to be one.
parent b565cb36
......@@ -165,14 +165,12 @@ set(libmessageviewer_messagepartthemes_default_SRCS
messagepartthemes/default/htmlblock.cpp
messagepartthemes/default/messagepartrenderermanager.cpp
messagepartthemes/default/partrendered.cpp
messagepartthemes/default/rendererpluginfactorysingleton.cpp
messagepartthemes/default/plugins/attachmentmessagepartrenderer.cpp
messagepartthemes/default/plugins/messagepartrenderer.cpp
messagepartthemes/default/plugins/textmessagepartrenderer.cpp
messagepartthemes/default/plugins/plugins.cpp
messagepartthemes/default/plugins/quotehtml.cpp
messagepartthemes/default/messagepartrenderbase.cpp
messagepartthemes/default/messagepartrendererfactorybase.cpp
messagepartthemes/default/messagepartrendererfactory.cpp
)
set(libmessageviewer_SRCS
......
......@@ -23,10 +23,9 @@
#include "messageviewer_debug.h"
#include "rendererpluginfactorysingleton.h"
#include "converthtmltoplaintext.h"
#include "messagepartrendererbase.h"
#include "messagepartrendererfactorybase.h"
#include "messagepartrendererfactory.h"
#include "htmlblock.h"
#include "partrendered.h"
......@@ -366,7 +365,7 @@ public:
MimeTreeParser::HtmlWriter *mBaseWriter = nullptr;
};
DefaultRendererPrivate::DefaultRendererPrivate(const Interface::MessagePart::Ptr &msgPart, CSSHelperBase *cssHelper, const MessagePartRendererFactoryBase *rendererFactory)
DefaultRendererPrivate::DefaultRendererPrivate(const Interface::MessagePart::Ptr &msgPart, CSSHelperBase *cssHelper, const MessagePartRendererFactory *rendererFactory)
: mMsgPart(msgPart)
, mOldWriter(msgPart->htmlWriter())
, mCSSHelper(cssHelper)
......@@ -1084,8 +1083,7 @@ QString DefaultRendererPrivate::renderFactory(const Interface::MessagePart::Ptr
}
DefaultRenderer::DefaultRenderer(const MimeTreeParser::Interface::MessagePart::Ptr &msgPart, CSSHelperBase *cssHelper)
: d(new MimeTreeParser::DefaultRendererPrivate(msgPart, cssHelper,
rendererPluginFactoryInstance()))
: d(new MimeTreeParser::DefaultRendererPrivate(msgPart, cssHelper, MessagePartRendererFactory::instance()))
{
}
......
......@@ -30,7 +30,7 @@ class CacheHtmlWriter;
class PartRendered;
namespace MessageViewer {
class MessagePartRendererFactoryBase;
class MessagePartRendererFactory;
class CSSHelperBase;
}
......@@ -38,7 +38,7 @@ namespace MimeTreeParser {
class DefaultRendererPrivate
{
public:
DefaultRendererPrivate(const Interface::MessagePart::Ptr &msgPart, CSSHelperBase *cssHelper, const MessagePartRendererFactoryBase *rendererFactory);
DefaultRendererPrivate(const Interface::MessagePart::Ptr &msgPart, CSSHelperBase *cssHelper, const MessagePartRendererFactory *rendererFactory);
~DefaultRendererPrivate();
QString alignText();
......@@ -66,7 +66,7 @@ public:
HtmlWriter *mOldWriter = nullptr;
CSSHelperBase *mCSSHelper = nullptr;
const MessageViewer::MessagePartRendererFactoryBase *mRendererFactory = nullptr;
const MessageViewer::MessagePartRendererFactory *mRendererFactory = nullptr;
};
}
#endif
......@@ -28,34 +28,39 @@
your version.
*/
#include "messagepartrendererfactorybase.h"
#include "messagepartrendererfactorybase_p.h"
#include "messagepartrendererfactory.h"
#include "messagepartrendererfactory_p.h"
#include "messagepartrendererbase.h"
#include "messageviewer_debug.h"
#include "plugins/attachmentmessagepartrenderer.h"
#include "plugins/messagepartrenderer.h"
#include "plugins/textmessagepartrenderer.h"
using namespace MessageViewer;
MessagePartRendererFactoryBasePrivate::MessagePartRendererFactoryBasePrivate(
MessagePartRendererFactoryBase *factory)
: q(factory)
void MessagePartRendererFactoryPrivate::setup()
{
if (mAll.isEmpty()) {
initalize_builtin_renderers();
loadPlugins();
}
}
MessagePartRendererFactoryBasePrivate::~MessagePartRendererFactoryBasePrivate()
void MessagePartRendererFactoryPrivate::loadPlugins()
{
qCDebug(MESSAGEVIEWER_LOG) << "plugin loading is not enabled in libmimetreeparser";
}
void MessagePartRendererFactoryBasePrivate::setup()
void MessagePartRendererFactoryPrivate::initalize_builtin_renderers()
{
if (mAll.isEmpty()) {
initalize_builtin_renderers();
q->loadPlugins();
}
insert(QStringLiteral("MimeTreeParser::MessagePart"), new MessagePartRenderer());
insert(QStringLiteral("MimeTreeParser::TextMessagePart"), new TextMessagePartRenderer());
insert(QStringLiteral("MimeTreeParser::AttachmentMessagePart"), new AttachmentMessagePartRenderer());
}
void MessagePartRendererFactoryBasePrivate::insert(const QString &type, MessagePartRendererBase *formatter)
void MessagePartRendererFactoryPrivate::insert(const QString &type, MessagePartRendererBase *formatter)
{
if (type.isEmpty() || !formatter) {
return;
......@@ -64,30 +69,25 @@ void MessagePartRendererFactoryBasePrivate::insert(const QString &type, MessageP
mAll[type].insert(mAll[type].begin(), formatter);
}
MessagePartRendererFactoryBase::MessagePartRendererFactoryBase()
: d(std::unique_ptr<MessagePartRendererFactoryBasePrivate>(
new MessagePartRendererFactoryBasePrivate(this)))
MessagePartRendererFactory::MessagePartRendererFactory()
: d(new MessagePartRendererFactoryPrivate)
{
}
MessagePartRendererFactoryBase::~MessagePartRendererFactoryBase()
MessagePartRendererFactory::~MessagePartRendererFactory()
{
}
void MessagePartRendererFactoryBase::insert(const QString &type, MessagePartRendererBase *formatter)
MessagePartRendererFactory* MessagePartRendererFactory::instance()
{
d->insert(type, formatter);
static std::unique_ptr<MessagePartRendererFactory> singeltonRendererFactory(new MessagePartRendererFactory);
return singeltonRendererFactory.get();
}
std::vector<MessagePartRendererBase *> MessagePartRendererFactoryBase::typeRegistry(
std::vector<MessagePartRendererBase *> MessagePartRendererFactory::typeRegistry(
const QString &type) const
{
d->setup();
Q_ASSERT(!d->mAll.isEmpty());
return d->mAll.value(type);
}
void MessagePartRendererFactoryBase::loadPlugins()
{
qCDebug(MESSAGEVIEWER_LOG) << "plugin loading is not enabled in libmimetreeparser";
}
......@@ -28,38 +28,35 @@
your version.
*/
#ifndef __MIMETREEPARSER_MESSAGEPARTRENDERERBASEFACTORY_H__
#define __MIMETREEPARSER_MESSAGEPARTRENDERERBASEFACTORY_H__
#ifndef MESSAGEVIEWER_MESSAGEPARTRENDERERFACTORY_H
#define MESSAGEVIEWER_MESSAGEPARTRENDERERFACTORY_H
#include "messageviewer_export.h"
#include <memory>
#include <map>
#include <qglobal.h>
#include <QString>
#include <QSharedPointer>
#include <memory>
#include <vector>
class QString;
class MessagePartRendererBase;
namespace MessageViewer {
class MessagePartRendererFactoryBasePrivate;
class MessagePartRendererFactoryPrivate;
class MESSAGEVIEWER_EXPORT MessagePartRendererFactoryBase
class MESSAGEVIEWER_EXPORT MessagePartRendererFactory
{
public:
MessagePartRendererFactoryBase();
virtual ~MessagePartRendererFactoryBase();
MessagePartRendererFactory();
~MessagePartRendererFactory();
std::vector<MessagePartRendererBase *> typeRegistry(const QString &type) const;
static MessagePartRendererFactory* instance();
protected:
void insert(const QString &type, MessagePartRendererBase *formatter);
virtual void loadPlugins();
std::vector<MessagePartRendererBase *> typeRegistry(const QString &type) const;
private:
Q_DISABLE_COPY(MessagePartRendererFactoryBase)
std::unique_ptr<MessagePartRendererFactoryBasePrivate> d;
friend class MessagePartRendererFactoryBasePrivate;
Q_DISABLE_COPY(MessagePartRendererFactory)
std::unique_ptr<MessagePartRendererFactoryPrivate> d;
};
}
......
......@@ -30,28 +30,22 @@
#ifndef __MESSAGEVIEWER_MESSAGEPARTRENDERERBASEFACTORY_P_H__
#define __MESSAGEVIEWER_MESSAGEPARTRENDERERBASEFACTORY_P_H__
#include <map>
#include <QMap>
class MessagePartRendererBase;
namespace MessageViewer {
class MessagePartRendererFactoryBase;
typedef QMap<QString, std::vector<MessagePartRendererBase *> > TypeRegistry;
class MessagePartRendererFactoryBasePrivate
class MessagePartRendererFactoryPrivate
{
public:
MessagePartRendererFactoryBasePrivate(MessagePartRendererFactoryBase *factory);
~MessagePartRendererFactoryBasePrivate();
void setup();
void loadPlugins();
void initalize_builtin_renderers(); //defined in pugins/plugins.cpp
void insert(const QString &type, MessagePartRendererBase *formatter);
MessagePartRendererFactoryBase *q;
TypeRegistry mAll;
};
}
......
/*
Copyright (c) 2016 Sandro Knauß <sknauss@kde.org>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#include "attachmentmessagepartrenderer.h"
#include "messagepartrenderer.h"
#include "textmessagepartrenderer.h"
#include "../messagepartrendererfactorybase_p.h"
using namespace MessageViewer;
void MessagePartRendererFactoryBasePrivate::initalize_builtin_renderers()
{
insert(QStringLiteral("MimeTreeParser::MessagePart"), new MessagePartRenderer());
insert(QStringLiteral("MimeTreeParser::TextMessagePart"), new TextMessagePartRenderer());
insert(QStringLiteral(
"MimeTreeParser::AttachmentMessagePart"), new AttachmentMessagePartRenderer());
}
/*
Copyright (c) 2016 Sandro Knauß <sknauss@kde.org>
KMail is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
KMail is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
In addition, as a special exception, the copyright holders give
permission to link the code of this program with any edition of
the Qt library by Trolltech AS, Norway (or with modified versions
of Qt that use the same license as Qt), and distribute linked
combinations including the two. You must obey the GNU General
Public License in all respects for all of the code used other than
Qt. If you modify this file, you may extend this exception to
your version of the file, but you are not obligated to do so. If
you do not wish to do so, delete this exception statement from
your version.
*/
#include "rendererpluginfactorysingleton.h"
#include "messagepartrendererfactorybase.h"
#include <QSharedPointer>
using namespace MessageViewer;
static QSharedPointer<MessagePartRendererFactoryBase> singeltonRendererFactory;
const MessagePartRendererFactoryBase *rendererPluginFactoryInstance()
{
if (!singeltonRendererFactory) {
singeltonRendererFactory = QSharedPointer<MessagePartRendererFactoryBase>(
new MessagePartRendererFactoryBase());
}
return singeltonRendererFactory.data();
}
/*
Copyright (c) 2017 Sandro Knauß <sknauss@kde.org>
KMail is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
KMail is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
In addition, as a special exception, the copyright holders give
permission to link the code of this program with any edition of
the Qt library by Trolltech AS, Norway (or with modified versions
of Qt that use the same license as Qt), and distribute linked
combinations including the two. You must obey the GNU General
Public License in all respects for all of the code used other than
Qt. If you modify this file, you may extend this exception to
your version of the file, but you are not obligated to do so. If
you do not wish to do so, delete this exception statement from
your version.
*/
#ifndef __MESSAGEVIEWER_DEFAULTRRENDERER_RENDERERRPLUGINFACTORYSIGNLETON_P_H__
#define __MESSAGEVIEWER_DEFAULTRRENDERER_RENDERERRPLUGINFACTORYSIGNLETON_P_H__
namespace MessageViewer {
class MessagePartRendererFactoryBase;
}
const MessageViewer::MessagePartRendererFactoryBase *rendererPluginFactoryInstance();
#endif
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