Implement strict mode for qmldir modules
[profile/ivi/qtdeclarative.git] / src / qml / qml / qqmlimport_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtQml module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QQMLIMPORT_P_H
43 #define QQMLIMPORT_P_H
44
45 #include <QtCore/qurl.h>
46 #include <QtCore/qcoreapplication.h>
47 #include <QtCore/qset.h>
48 #include <QtCore/qstringlist.h>
49 #include <private/qqmldirparser_p.h>
50 #include <private/qqmlscript_p.h>
51 #include <private/qqmlmetatype_p.h>
52
53 //
54 //  W A R N I N G
55 //  -------------
56 //
57 // This file is not part of the Qt API.  It exists purely as an
58 // implementation detail.  This header file may change from version to
59 // version without notice, or even be removed.
60 //
61 // We mean it.
62 //
63
64 QT_BEGIN_NAMESPACE
65
66 class QQmlTypeNameCache;
67 class QQmlEngine;
68 class QDir;
69 class QQmlImportNamespace;
70 class QQmlImportsPrivate;
71 class QQmlImportDatabase;
72 class QQmlTypeLoader;
73
74 class Q_QML_PRIVATE_EXPORT QQmlImports
75 {
76 public:
77     enum ImportVersion { FullyVersioned, PartiallyVersioned, Unversioned };
78
79     QQmlImports(QQmlTypeLoader *);
80     QQmlImports(const QQmlImports &);
81     ~QQmlImports();
82     QQmlImports &operator=(const QQmlImports &);
83
84     void setBaseUrl(const QUrl &url, const QString &urlString = QString());
85     QUrl baseUrl() const;
86
87     bool resolveType(const QHashedStringRef &type,
88                      QQmlType** type_return, QString* url_return,
89                      int *version_major, int *version_minor,
90                      QQmlImportNamespace** ns_return,
91                      QList<QQmlError> *errors = 0) const;
92     bool resolveType(QQmlImportNamespace*,
93                      const QHashedStringRef& type,
94                      QQmlType** type_return, QString* url_return,
95                      int *version_major, int *version_minor) const;
96
97     bool addImplicitImport(QQmlImportDatabase *importDb, QList<QQmlError> *errors);
98
99     bool addFileImport(QQmlImportDatabase *,
100                        const QString& uri, const QString& prefix, int vmaj, int vmin, bool incomplete,
101                        QList<QQmlError> *errors);
102
103     bool addLibraryImport(QQmlImportDatabase *importDb,
104                           const QString &uri, const QString &prefix, int vmaj, int vmin,
105                           const QString &qmldirIdentifier, const QString &qmldirUrl, bool incomplete, QList<QQmlError> *errors);
106
107     bool updateQmldirContent(QQmlImportDatabase *importDb,
108                              const QString &uri, const QString &prefix,
109                              const QString &qmldirIdentifier, const QString &qmldirUrl, QList<QQmlError> *errors);
110
111     bool locateQmldir(QQmlImportDatabase *,
112                       const QString &uri, int vmaj, int vmin,
113                       QString *qmldirFilePath, QString *url);
114
115     void populateCache(QQmlTypeNameCache *cache, QQmlEngine *) const;
116
117     struct ScriptReference
118     {
119         QString nameSpace;
120         QString qualifier;
121         QUrl location;
122     };
123
124     QList<ScriptReference> resolvedScripts() const;
125
126     static QString completeQmldirPath(const QString &uri, const QString &base, int vmaj, int vmin,
127                                       QQmlImports::ImportVersion version);
128
129     static bool isLocal(const QString &url);
130     static bool isLocal(const QUrl &url);
131
132 private:
133     friend class QQmlImportDatabase;
134     QQmlImportsPrivate *d;
135 };
136
137 class QQmlImportDatabase
138 {
139     Q_DECLARE_TR_FUNCTIONS(QQmlImportDatabase)
140 public:
141     enum PathType { Local, Remote, LocalOrRemote };
142
143     QQmlImportDatabase(QQmlEngine *);
144     ~QQmlImportDatabase();
145
146     bool importPlugin(const QString &filePath, const QString &uri, const QString &importNamespace, QList<QQmlError> *errors);
147
148     QStringList importPathList(PathType type = LocalOrRemote) const;
149     void setImportPathList(const QStringList &paths);
150     void addImportPath(const QString& dir);
151
152     QStringList pluginPathList() const;
153     void setPluginPathList(const QStringList &paths);
154     void addPluginPath(const QString& path);
155
156 private:
157     friend class QQmlImportsPrivate;
158     QString resolvePlugin(QQmlTypeLoader *typeLoader,
159                           const QString &qmldirPath, const QString &qmldirPluginPath,
160                           const QString &baseName, const QStringList &suffixes,
161                           const QString &prefix = QString());
162     QString resolvePlugin(QQmlTypeLoader *typeLoader,
163                           const QString &qmldirPath, const QString &qmldirPluginPath,
164                           const QString &baseName);
165
166     struct QmldirCache {
167         int versionMajor;
168         int versionMinor;
169         QString qmldirFilePath;
170         QString qmldirPathUrl;
171         QmldirCache *next;
172     };
173     // Maps from an import to a linked list of qmldir info.
174     // Used in QQmlImportsPrivate::locateQmldir()
175     QStringHash<QmldirCache *> qmldirCache;
176
177     // XXX thread
178     QStringList filePluginPath;
179     QStringList fileImportPath;
180
181     QSet<QString> qmlDirFilesForWhichPluginsHaveBeenLoaded;
182     QSet<QString> initializedPlugins;
183     QQmlEngine *engine;
184 };
185
186 QT_END_NAMESPACE
187
188 #endif // QQMLIMPORT_P_H
189