[SCM] ktp-common-internals packaging branch, master, updated. debian/15.12.1-2-1839-gf0635e9
Maximiliano Curia
maxy at moszumanska.debian.org
Mon May 9 09:06:51 UTC 2016
Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-common-internals.git;a=commitdiff;h=f2ca523
The following commit has been merged in the master branch:
commit f2ca5230a91d5e308cbfabc4464d2639ac200b60
Author: Dan Vrátil <dvratil at redhat.com>
Date: Wed May 15 15:08:21 2013 +0200
Allow dynamic loading and unloading of text filters
The code now also allows running filters before the default
escape filter.
CCBUG: 316887
BUG: 305997
FIXED-IN: 0.7.0
---
KTp/message-filter-config-manager.cpp | 19 ++++++
KTp/message-filter-config-manager.h | 2 +
KTp/message-processor-private.h | 53 +++++++++++++++
KTp/message-processor.cpp | 119 ++++++++++++++++++++--------------
KTp/message-processor.h | 1 +
5 files changed, 146 insertions(+), 48 deletions(-)
diff --git a/KTp/message-filter-config-manager.cpp b/KTp/message-filter-config-manager.cpp
index 70c4f81..9c78654 100644
--- a/KTp/message-filter-config-manager.cpp
+++ b/KTp/message-filter-config-manager.cpp
@@ -17,6 +17,7 @@
*/
#include "message-filter-config-manager.h"
+#include "message-processor-private.h"
#include "version.h"
#include <QMutex>
@@ -112,3 +113,21 @@ KSharedConfig::Ptr MessageFilterConfigManager::sharedConfig() const
{
return KSharedConfig::openConfig(QLatin1String("ktelepathyrc"));
}
+
+void MessageFilterConfigManager::reloadConfig()
+{
+ PluginSet::ConstIterator iter = d->all.constBegin();
+ for ( ; iter != d->all.constEnd(); ++iter) {
+ KPluginInfo pluginInfo = *iter;
+
+ const bool wasEnabled = d->enabled.contains(pluginInfo);
+
+ if (!wasEnabled && pluginInfo.isPluginEnabled()) {
+ d->enabled.insert(pluginInfo);
+ MessageProcessor::instance()->d->loadFilter(pluginInfo);
+ } else if (wasEnabled && !pluginInfo.isPluginEnabled()) {
+ d->enabled.remove(pluginInfo);
+ MessageProcessor::instance()->d->unloadFilter(pluginInfo);
+ }
+ }
+}
diff --git a/KTp/message-filter-config-manager.h b/KTp/message-filter-config-manager.h
index fa7bc06..2f02944 100644
--- a/KTp/message-filter-config-manager.h
+++ b/KTp/message-filter-config-manager.h
@@ -37,6 +37,8 @@ class KTP_EXPORT MessageFilterConfigManager
KConfigGroup configGroup() const;
KSharedConfig::Ptr sharedConfig() const;
+ void reloadConfig();
+
protected:
MessageFilterConfigManager();
~MessageFilterConfigManager();
diff --git a/KTp/message-processor-private.h b/KTp/message-processor-private.h
new file mode 100644
index 0000000..c8e3daf
--- /dev/null
+++ b/KTp/message-processor-private.h
@@ -0,0 +1,53 @@
+/*
+ Copyright (C) 2013 Daniel Vrátil <dvratil at redhat.com>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#include "message-processor.h"
+
+using namespace KTp;
+
+class FilterPlugin
+{
+ public:
+ explicit FilterPlugin(const KPluginInfo &pluginInfo, KTp::AbstractMessageFilter *instance);
+ explicit FilterPlugin(const QString &name, int weight, KTp::AbstractMessageFilter *instance);
+
+ bool operator<(const FilterPlugin &other) const;
+ bool operator==(const FilterPlugin &other) const;
+
+ QString name;
+ int weight;
+ KTp::AbstractMessageFilter* instance;
+};
+
+class MessageProcessor::Private
+{
+ public:
+ Private(MessageProcessor *parent):
+ q(parent)
+ { }
+
+ void loadFilters();
+
+ void loadFilter(const KPluginInfo &pluginInfo);
+ void unloadFilter(const KPluginInfo &pluginInfo);
+
+ QList<FilterPlugin> filters;
+
+ private:
+ MessageProcessor *q;
+};
diff --git a/KTp/message-processor.cpp b/KTp/message-processor.cpp
index db41ecf..ea2699d 100644
--- a/KTp/message-processor.cpp
+++ b/KTp/message-processor.cpp
@@ -18,6 +18,7 @@
#include "message-processor.h"
+#include "message-processor-private.h"
#include "message-filters-private.h"
#include "message-filter-config-manager.h"
@@ -32,34 +33,70 @@
using namespace KTp;
-class MessageProcessor::Private
+FilterPlugin::FilterPlugin(const KPluginInfo &pluginInfo, KTp::AbstractMessageFilter *instance_):
+ name(pluginInfo.pluginName()),
+ instance(instance_)
{
- public:
- Private(MessageProcessor *parent):
- q(parent)
- { }
+ bool ok;
+ weight = pluginInfo.service()->property(QLatin1String("X-KDE-PluginInfo-Weight"), QVariant::Int).toInt(&ok);
+ if (!ok) {
+ weight = 100;
+ }
+}
- void loadFilters();
+FilterPlugin::FilterPlugin(const QString &name_, int weight_, KTp::AbstractMessageFilter *instance_):
+ name(name_),
+ weight(weight_),
+ instance(instance_)
+{
+}
- QList<KTp::AbstractMessageFilter*> filters;
+bool FilterPlugin::operator<(const FilterPlugin &other) const
+{
+ return weight < other.weight;
+}
- private:
- MessageProcessor *q;
-};
+bool FilterPlugin::operator==(const FilterPlugin &other) const
+{
+ return instance == other.instance &&
+ name == other.name &&
+ weight == other.weight;
+}
-bool pluginWeightLessThan(const KPluginInfo &p1, const KPluginInfo &p2)
+void MessageProcessor::Private::loadFilter(const KPluginInfo &pluginInfo)
{
- bool ok;
- int weight1 = p1.service()->property(QLatin1String("X-KDE-PluginInfo-Weight"), QVariant::Int).toInt(&ok);
- if (!ok) {
- weight1 = 100;
- }
- int weight2 = p2.service()->property(QLatin1String("X-KDE-PluginInfo-Weight"), QVariant::Int).toInt(&ok);
- if (!ok) {
- weight2 = 100;
+ KService::Ptr service = pluginInfo.service();
+
+ KPluginFactory *factory = KPluginLoader(service->library()).factory();
+ if (factory) {
+ kDebug() << "loaded factory :" << factory;
+ AbstractMessageFilter *filter = factory->create<AbstractMessageFilter>(q);
+
+ if (filter) {
+ kDebug() << "loaded message filter : " << filter;
+ filters << FilterPlugin(pluginInfo, filter);
+ }
+ } else {
+ kError() << "error loading plugin :" << service->library();
}
- return weight1 < weight2;
+ // Re-sort filters by weight
+ qSort(filters);
+}
+
+void MessageProcessor::Private::unloadFilter(const KPluginInfo &pluginInfo)
+{
+ QList<FilterPlugin>::Iterator iter = filters.begin();
+ for ( ; iter != filters.end(); ++iter) {
+ const FilterPlugin &plugin = *iter;
+
+ if (plugin.name == pluginInfo.pluginName()) {
+ kDebug() << "unloading message filter : " << plugin.instance;
+ plugin.instance->deleteLater();
+ filters.erase(iter);
+ return;
+ }
+ }
}
void MessageProcessor::Private::loadFilters()
@@ -68,27 +105,11 @@ void MessageProcessor::Private::loadFilters()
KPluginInfo::List plugins = MessageFilterConfigManager::self()->enabledPlugins();
- qSort(plugins.begin(), plugins.end(), pluginWeightLessThan);
-
Q_FOREACH (const KPluginInfo &plugin, plugins) {
- KService::Ptr service = plugin.service();
-
- KPluginFactory *factory = KPluginLoader(service->library()).factory();
- if(factory) {
- kDebug() << "loaded factory :" << factory;
- AbstractMessageFilter *filter = factory->create<AbstractMessageFilter>(q);
-
- if(filter) {
- kDebug() << "loaded message filter : " << filter;
- filters.append(filter);
- }
- } else {
- kError() << "error loading plugin :" << service->library();
- }
+ loadFilter(plugin);
}
}
-
KTp::MessageProcessor* MessageProcessor::instance()
{
kDebug();
@@ -108,8 +129,10 @@ KTp::MessageProcessor* MessageProcessor::instance()
MessageProcessor::MessageProcessor():
d(new MessageProcessor::Private(this))
{
- d->filters.append(new MessageEscapeFilter(this));
- d->filters.append(new MessageUrlFilter(this));
+ // Default weight is 100. Make sure these two plugins are always above those
+ // which don't have weight specified and in this exact order.
+ d->filters << FilterPlugin(QLatin1String("__messageEscapeFilter"), 98, new MessageEscapeFilter(this));
+ d->filters << FilterPlugin(QLatin1String("__messageUrlFilter"), 99, new MessageUrlFilter(this));
d->loadFilters();
}
@@ -124,14 +147,14 @@ QString MessageProcessor::header()
{
QStringList scripts;
QStringList stylesheets;
- Q_FOREACH (AbstractMessageFilter *filter, d->filters) {
- Q_FOREACH (const QString &script, filter->requiredScripts()) {
+ Q_FOREACH (const FilterPlugin &plugin, d->filters) {
+ Q_FOREACH (const QString &script, plugin.instance->requiredScripts()) {
// Avoid duplicates
if (!scripts.contains(script)) {
scripts << script;
}
}
- Q_FOREACH (const QString &stylesheet, filter->requiredStylesheets()) {
+ Q_FOREACH (const QString &stylesheet, plugin.instance->requiredStylesheets()) {
// Avoid duplicates
if (!stylesheets.contains(stylesheet)) {
stylesheets << stylesheet;
@@ -177,9 +200,9 @@ KTp::Message KTp::MessageProcessor::processIncomingMessage(const Tpl::TextEventP
KTp::Message MessageProcessor::processIncomingMessage(KTp::Message message, const KTp::MessageContext &context)
{
- Q_FOREACH (AbstractMessageFilter *filter, d->filters) {
- kDebug() << "running filter :" << filter->metaObject()->className();
- filter->filterMessage(message, context);
+ Q_FOREACH (const FilterPlugin &plugin, d->filters) {
+ kDebug() << "running filter :" << plugin.instance->metaObject()->className();
+ plugin.instance->filterMessage(message, context);
}
return message;
}
@@ -189,9 +212,9 @@ KTp::OutgoingMessage MessageProcessor::processOutgoingMessage(const QString &mes
KTp::MessageContext context(account, channel);
KTp::OutgoingMessage message(messageText);
- Q_FOREACH (AbstractMessageFilter *filter, d->filters) {
- kDebug() << "running outgoing filter : " << filter->metaObject()->className();
- filter->filterOutgoingMessage(message, context);
+ Q_FOREACH (const FilterPlugin &plugin, d->filters) {
+ kDebug() << "running outgoing filter : " << plugin.instance->metaObject()->className();
+ plugin.instance->filterOutgoingMessage(message, context);
}
return message;
diff --git a/KTp/message-processor.h b/KTp/message-processor.h
index acbcd20..42f8be6 100644
--- a/KTp/message-processor.h
+++ b/KTp/message-processor.h
@@ -70,6 +70,7 @@ class KTP_EXPORT MessageProcessor : public QObject
class Private;
Private * const d;
+ friend class MessageFilterConfigManager;
};
}
--
ktp-common-internals packaging
More information about the pkg-kde-commits
mailing list