Warning, file /office/calligra/libs/flake/KoEventActionRegistry.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* This file is part of the KDE project 0002 Copyright (C) 2008 Thorsten Zachmann <zachmann@kde.org> 0003 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Library General Public 0006 License as published by the Free Software Foundation; either 0007 version 2 of the License, or (at your option) any later version. 0008 0009 This library is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 Library General Public License for more details. 0013 0014 You should have received a copy of the GNU Library General Public License 0015 along with this library; see the file COPYING.LIB. If not, write to 0016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 * Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #include "KoEventActionRegistry.h" 0021 0022 #include <QHash> 0023 #include <QGlobalStatic> 0024 0025 #include <FlakeDebug.h> 0026 0027 #include <KoXmlReader.h> 0028 #include <KoXmlNS.h> 0029 #include "KoEventActionFactoryBase.h" 0030 #include "KoEventAction.h" 0031 #include <KoPluginLoader.h> 0032 0033 0034 class KoEventActionRegistry::Singleton 0035 { 0036 public: 0037 Singleton() 0038 : initDone(false) {} 0039 0040 KoEventActionRegistry q; 0041 bool initDone; 0042 }; 0043 0044 Q_GLOBAL_STATIC(KoEventActionRegistry::Singleton, singleton) 0045 0046 class Q_DECL_HIDDEN KoEventActionRegistry::Private 0047 { 0048 public: 0049 QHash<QString, KoEventActionFactoryBase*> presentationEventActionFactories; 0050 QHash<QString, KoEventActionFactoryBase*> presentationEventActions; 0051 QHash<QString, KoEventActionFactoryBase*> scriptEventActionFactories; 0052 }; 0053 0054 KoEventActionRegistry * KoEventActionRegistry::instance() 0055 { 0056 KoEventActionRegistry * registry = &(singleton->q); 0057 if (! singleton->initDone) { 0058 singleton->initDone = true; 0059 registry->init(); 0060 } 0061 return registry; 0062 } 0063 0064 KoEventActionRegistry::KoEventActionRegistry() 0065 : d(new Private()) 0066 { 0067 } 0068 0069 KoEventActionRegistry::~KoEventActionRegistry() 0070 { 0071 delete d; 0072 } 0073 0074 void KoEventActionRegistry::addPresentationEventAction(KoEventActionFactoryBase * factory) 0075 { 0076 const QString & action = factory->action(); 0077 if (! action.isEmpty()) { 0078 d->presentationEventActionFactories.insert(factory->id(), factory); 0079 d->presentationEventActions.insert(action, factory); 0080 } 0081 } 0082 0083 void KoEventActionRegistry::addScriptEventAction(KoEventActionFactoryBase * factory) 0084 { 0085 d->scriptEventActionFactories.insert(factory->id(), factory); 0086 } 0087 0088 QList<KoEventActionFactoryBase *> KoEventActionRegistry::presentationEventActions() 0089 { 0090 return d->presentationEventActionFactories.values(); 0091 } 0092 0093 QList<KoEventActionFactoryBase *> KoEventActionRegistry::scriptEventActions() 0094 { 0095 return d->scriptEventActionFactories.values(); 0096 } 0097 0098 void KoEventActionRegistry::init() 0099 { 0100 KoPluginLoader::PluginsConfig config; 0101 config.whiteList = "PresentationEventActionPlugins"; 0102 config.blacklist = "PresentationEventActionPluginsDisabled"; 0103 config.group = "calligra"; 0104 KoPluginLoader::load(QStringLiteral("calligra/presentationeventactions"), config); 0105 0106 config.whiteList = "ScriptEventActionPlugins"; 0107 config.blacklist = "ScriptEventActionPluginsDisabled"; 0108 KoPluginLoader::load(QStringLiteral("calligra/scripteventactions"), config); 0109 } 0110 0111 QSet<KoEventAction*> KoEventActionRegistry::createEventActionsFromOdf(const KoXmlElement & e, KoShapeLoadingContext & context) const 0112 { 0113 QSet<KoEventAction *> eventActions; 0114 0115 if (e.namespaceURI() == KoXmlNS::office && e.tagName() == "event-listeners") { 0116 KoXmlElement element; 0117 forEachElement(element, e) { 0118 if (element.tagName() == "event-listener") { 0119 if (element.namespaceURI() == KoXmlNS::presentation) { 0120 QString action(element.attributeNS(KoXmlNS::presentation, "action", QString())); 0121 QHash<QString, KoEventActionFactoryBase *>::const_iterator it(d->presentationEventActions.find(action)); 0122 0123 if (it != d->presentationEventActions.constEnd()) { 0124 KoEventAction * eventAction = it.value()->createEventAction(); 0125 if (eventAction) { 0126 if (eventAction->loadOdf(element, context)) { 0127 eventActions.insert(eventAction); 0128 } else { 0129 delete eventAction; 0130 } 0131 } 0132 } else { 0133 warnFlake << "presentation:event-listerer action = " << action << "not supported"; 0134 } 0135 } else if (element.namespaceURI() == KoXmlNS::script) { 0136 // TODO 0137 } else { 0138 warnFlake << "element" << e.namespaceURI() << e.tagName() << "not supported"; 0139 } 0140 } else { 0141 warnFlake << "element" << e.namespaceURI() << e.tagName() << "not supported"; 0142 } 0143 } 0144 } else { 0145 warnFlake << "office:event-listeners not found got:" << e.namespaceURI() << e.tagName(); 0146 } 0147 0148 return eventActions; 0149 } 0150