20
20
#include "message-processor.h"
21
21
#include "filters.h"
22
#include "plugin-config-manager.h"
28
#include <KServiceTypeTrader>
29
#include <KPluginFactory>
23
31
MessageProcessor* MessageProcessor::s_instance = 0;
25
AbstractMessageFilter::AbstractMessageFilter(QObject* parent)
30
AbstractMessageFilter::~AbstractMessageFilter()
34
33
MessageProcessor* MessageProcessor::instance()
36
37
static QMutex mutex;
41
s_instance = new MessageProcessor;
40
s_instance = new MessageProcessor;
49
48
MessageProcessor::MessageProcessor()
51
m_filters << new EscapeFilter(this) << new UrlFilter(this) << new EmoticonFilter(this);
50
m_filters.append(new EscapeFilter(this));
51
m_filters.append(new UrlFilter(this));
59
Message MessageProcessor::processIncomingMessage(const Tp::ReceivedMessage &receivedMessage)
61
Message message(receivedMessage);
62
Q_FOREACH(AbstractMessageFilter *filter, MessageProcessor::m_filters) {
63
filter->filterMessage(message);
68
Message MessageProcessor::processOutgoingMessage(const Tp::Message &sentMessage)
70
Message message(sentMessage);
71
Q_FOREACH(AbstractMessageFilter *filter, MessageProcessor::m_filters) {
72
filter->filterMessage(message);
61
Message MessageProcessor::processIncomingMessage(Message receivedMessage)
63
Q_FOREACH(AbstractMessageFilter *filter, MessageProcessor::m_filters) {
64
kDebug() << "running filter :" << filter->metaObject()->className();
65
filter->filterMessage(receivedMessage);
67
return receivedMessage;
70
Message MessageProcessor::processOutgoingMessage(Message sentMessage)
72
Q_FOREACH(AbstractMessageFilter *filter, MessageProcessor::m_filters) {
73
filter->filterMessage(sentMessage);
78
void MessageProcessor::loadFilters() {
79
kDebug() << "Starting loading filters...";
81
Q_FOREACH (const KPluginInfo &plugin, PluginConfigManager::self()->enabledPlugins()) {
82
KService::Ptr service = plugin.service();
84
KPluginFactory *factory = KPluginLoader(service->library()).factory();
86
kDebug() << "loaded factory :" << factory;
87
AbstractMessageFilter *filter = factory->create<AbstractMessageFilter>(this);
90
kDebug() << "loaded message filter : " << filter;
91
m_filters.append(filter);
94
kError() << "error loading plugin :" << service->library();