1
/* This file is part of the KDE project
2
* Copyright (C) 2006-2007 Thomas Zander <zander@kde.org>
3
* Copyright (C) 2008 Thorsten Zachmann <zachmann@kde.org>
5
* This library is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU Library General Public
7
* License as published by the Free Software Foundation; either
8
* version 2 of the License, or (at your option) any later version.
10
* This library is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* Library General Public License for more details.
15
* You should have received a copy of the GNU Library General Public License
16
* along with this library; see the file COPYING.LIB. If not, write to
17
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
* Boston, MA 02110-1301, USA.
21
#include "KoVariableRegistry.h"
22
#include "KoVariableFactory.h"
23
#include "KoVariable.h"
24
#include "InsertVariableAction_p.h"
26
#include <KoXmlReader.h>
27
#include <KoCanvasBase.h>
28
#include <KoPluginLoader.h>
32
class KoVariableRegistry::Singleton
43
K_GLOBAL_STATIC(KoVariableRegistry::Singleton, singleton)
45
class KoVariableRegistry::Private
48
QHash<QPair<QString, QString>, KoVariableFactory *> factories;
51
KoVariableRegistry::KoVariableRegistry()
56
KoVariableRegistry::~KoVariableRegistry()
61
void KoVariableRegistry::init()
63
KoPluginLoader::PluginsConfig config;
64
config.whiteList = "TextVariablePlugins";
65
config.blacklist = "TextVariablePluginsDisabled";
66
config.group = "koffice";
67
KoPluginLoader::instance()->load(QString::fromLatin1("KOffice/Text-Variable"),
68
QString::fromLatin1("[X-KoText-MinVersion] <= 0"), config);
70
QList<KoVariableFactory*> factories = values();
71
kDebug(32500) << "factories count" << factories.size();
72
foreach(KoVariableFactory *factory, factories) {
73
kDebug(32500) << factory->id();
74
QString nameSpace = factory->odfNameSpace();
75
if (nameSpace.isEmpty() || factory->odfElementNames().isEmpty()) {
76
kDebug(32500) << "Variable factory" << factory->id() << " does not have odfNameSpace defined, ignoring";
78
foreach(const QString & elementName, factory->odfElementNames()) {
79
d->factories.insert(QPair<QString, QString>(nameSpace, elementName), factory);
81
kDebug(32500) << "Inserting variable factory" << factory->id() << " for"
82
<< nameSpace << ":" << elementName;
89
KoVariableRegistry *KoVariableRegistry::instance()
91
KoVariableRegistry *registry = &(singleton->q);
92
if (! singleton->initDone) {
93
singleton->initDone = true;
99
KoVariable *KoVariableRegistry::createFromOdf(const KoXmlElement & e, KoShapeLoadingContext & context) const
101
kDebug(32500) << "Going to check for" << e.namespaceURI() << ":" << e.tagName();
103
KoVariable *variable = 0;
105
KoVariableFactory *factory = d->factories.value(QPair<QString, QString>(e.namespaceURI(), e.tagName()));
108
variable = factory->createVariable();
110
variable->loadOdf(e, context);
117
QList<QAction*> KoVariableRegistry::createInsertVariableActions(KoCanvasBase *host) const
119
QList<QAction*> answer;
120
foreach(KoVariableFactory *factory, values()) {
121
foreach(const KoVariableTemplate & templ, factory->templates()) {
122
answer.append(new InsertVariableAction(host, factory, templ));