~ubuntu-branches/ubuntu/precise/koffice/precise

« back to all changes in this revision

Viewing changes to libs/kotext/KoVariableRegistry.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2010-10-27 17:52:57 UTC
  • mfrom: (0.12.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20101027175257-s04zqqk5bs8ckm9o
Tags: 1:2.2.83-0ubuntu1
* Merge with Debian git remaining changes:
 - Add build-deps on librcps-dev, opengtl-dev, libqtgtl-dev, freetds-dev,
   create-resources, libspnav-dev
 - Remove needless build-dep on libwv2-dev
 - koffice-libs recommends create-resources
 - krita recommends pstoedit
 - Keep our patches
* New upstream release 2.3 beta 3
  - Remove debian/patches fixed by upstream
  - Update install files

Show diffs side-by-side

added added

removed removed

Lines of Context:
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>
4
 
 *
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.
9
 
 *
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.
14
 
 *
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.
19
 
 */
20
 
 
21
 
#include "KoVariableRegistry.h"
22
 
#include "KoVariableFactory.h"
23
 
#include "KoVariable.h"
24
 
#include "InsertVariableAction_p.h"
25
 
 
26
 
#include <KoXmlReader.h>
27
 
#include <KoCanvasBase.h>
28
 
#include <KoPluginLoader.h>
29
 
#include <kglobal.h>
30
 
#include <kdebug.h>
31
 
 
32
 
class KoVariableRegistry::Singleton
33
 
{
34
 
public:
35
 
    Singleton()
36
 
            : initDone(false) {}
37
 
    ~Singleton() {}
38
 
 
39
 
    KoVariableRegistry q;
40
 
    bool initDone;
41
 
};
42
 
 
43
 
K_GLOBAL_STATIC(KoVariableRegistry::Singleton, singleton)
44
 
 
45
 
class KoVariableRegistry::Private
46
 
{
47
 
public:
48
 
    QHash<QPair<QString, QString>, KoVariableFactory *> factories;
49
 
};
50
 
 
51
 
KoVariableRegistry::KoVariableRegistry()
52
 
        : d(new Private())
53
 
{
54
 
}
55
 
 
56
 
KoVariableRegistry::~KoVariableRegistry()
57
 
{
58
 
    delete(d);
59
 
}
60
 
 
61
 
void KoVariableRegistry::init()
62
 
{
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);
69
 
 
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";
77
 
        } else {
78
 
            foreach(const QString & elementName, factory->odfElementNames()) {
79
 
                d->factories.insert(QPair<QString, QString>(nameSpace, elementName), factory);
80
 
 
81
 
                kDebug(32500) << "Inserting variable factory" << factory->id() << " for"
82
 
                << nameSpace << ":" << elementName;
83
 
            }
84
 
        }
85
 
    }
86
 
 
87
 
}
88
 
 
89
 
KoVariableRegistry *KoVariableRegistry::instance()
90
 
{
91
 
    KoVariableRegistry *registry = &(singleton->q);
92
 
    if (! singleton->initDone) {
93
 
        singleton->initDone = true;
94
 
        registry->init();
95
 
    }
96
 
    return registry;
97
 
}
98
 
 
99
 
KoVariable *KoVariableRegistry::createFromOdf(const KoXmlElement & e, KoShapeLoadingContext & context) const
100
 
{
101
 
    kDebug(32500) << "Going to check for" << e.namespaceURI() << ":" << e.tagName();
102
 
 
103
 
    KoVariable *variable = 0;
104
 
 
105
 
    KoVariableFactory *factory = d->factories.value(QPair<QString, QString>(e.namespaceURI(), e.tagName()));
106
 
 
107
 
    if (factory) {
108
 
        variable = factory->createVariable();
109
 
        if (variable) {
110
 
            variable->loadOdf(e, context);
111
 
        }
112
 
    }
113
 
 
114
 
    return variable;
115
 
}
116
 
 
117
 
QList<QAction*> KoVariableRegistry::createInsertVariableActions(KoCanvasBase *host) const
118
 
{
119
 
    QList<QAction*> answer;
120
 
    foreach(KoVariableFactory *factory, values()) {
121
 
        foreach(const KoVariableTemplate & templ, factory->templates()) {
122
 
            answer.append(new InsertVariableAction(host, factory, templ));
123
 
        }
124
 
    }
125
 
    return answer;
126
 
}
127