1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #ifndef QDECLARATIVETYPELOADER_P_H
43 #define QDECLARATIVETYPELOADER_P_H
49 // This file is not part of the Qt API. It exists purely as an
50 // implementation detail. This header file may change from version to
51 // version without notice, or even be removed.
56 #include <QtCore/qobject.h>
57 #include <QtNetwork/qnetworkreply.h>
58 #include <QtDeclarative/qjsvalue.h>
59 #include <QtDeclarative/qdeclarativeerror.h>
60 #include <QtDeclarative/qdeclarativeengine.h>
61 #include <private/qdeclarativecleanup_p.h>
62 #include <private/qdeclarativescriptparser_p.h>
63 #include <private/qdeclarativedirparser_p.h>
64 #include <private/qdeclarativeimport_p.h>
66 #include <private/qv8_p.h>
70 class QDeclarativeScriptData;
71 class QDeclarativeScriptBlob;
72 class QDeclarativeQmldirData;
73 class QDeclarativeTypeLoader;
74 class QDeclarativeCompiledData;
75 class QDeclarativeComponentPrivate;
76 class QDeclarativeTypeData;
77 class QDeclarativeDataLoader;
79 class Q_AUTOTEST_EXPORT QDeclarativeDataBlob : public QDeclarativeRefCount
83 Null, // Prior to QDeclarativeDataLoader::load()
84 Loading, // Prior to data being received and dataReceived() being called
85 WaitingForDependencies, // While there are outstanding addDependency()s
96 QDeclarativeDataBlob(const QUrl &, Type);
97 virtual ~QDeclarativeDataBlob();
101 Status status() const;
103 bool isLoading() const;
104 bool isWaiting() const;
105 bool isComplete() const;
106 bool isError() const;
107 bool isCompleteOrError() const;
109 qreal progress() const;
112 QUrl finalUrl() const;
114 QList<QDeclarativeError> errors() const;
116 void setError(const QDeclarativeError &);
117 void setError(const QList<QDeclarativeError> &errors);
119 void addDependency(QDeclarativeDataBlob *);
122 virtual void dataReceived(const QByteArray &) = 0;
125 virtual void networkError(QNetworkReply::NetworkError);
127 virtual void dependencyError(QDeclarativeDataBlob *);
128 virtual void dependencyComplete(QDeclarativeDataBlob *);
129 virtual void allDependenciesDone();
131 virtual void downloadProgressChanged(qreal);
134 friend class QDeclarativeDataLoader;
136 void cancelAllWaitingFor();
137 void notifyAllWaitingOnMe();
138 void notifyComplete(QDeclarativeDataBlob *);
147 // List of QDeclarativeDataBlob's that are waiting for me to complete.
148 QList<QDeclarativeDataBlob *> m_waitingOnMe;
150 // List of QDeclarativeDataBlob's that I am waiting for to complete.
151 QList<QDeclarativeDataBlob *> m_waitingFor;
153 // Manager that is currently fetching data for me
154 QDeclarativeDataLoader *m_manager;
155 int m_redirectCount:30;
159 QList<QDeclarativeError> m_errors;
162 class Q_AUTOTEST_EXPORT QDeclarativeDataLoader : public QObject
166 QDeclarativeDataLoader(QDeclarativeEngine *);
167 ~QDeclarativeDataLoader();
169 void load(QDeclarativeDataBlob *);
170 void loadWithStaticData(QDeclarativeDataBlob *, const QByteArray &);
172 QDeclarativeEngine *engine() const;
175 void networkReplyFinished();
176 void networkReplyProgress(qint64,qint64);
179 void setData(QDeclarativeDataBlob *, const QByteArray &);
181 QDeclarativeEngine *m_engine;
182 typedef QHash<QNetworkReply *, QDeclarativeDataBlob *> NetworkReplies;
183 NetworkReplies m_networkReplies;
186 class Q_AUTOTEST_EXPORT QDeclarativeTypeLoader : public QDeclarativeDataLoader
190 QDeclarativeTypeLoader(QDeclarativeEngine *);
191 ~QDeclarativeTypeLoader();
197 Q_DECLARE_FLAGS(Options, Option)
199 QDeclarativeTypeData *get(const QUrl &url);
200 QDeclarativeTypeData *get(const QByteArray &, const QUrl &url, Options = None);
203 QDeclarativeScriptBlob *getScript(const QUrl &);
204 QDeclarativeQmldirData *getQmldir(const QUrl &);
206 typedef QHash<QUrl, QDeclarativeTypeData *> TypeCache;
207 typedef QHash<QUrl, QDeclarativeScriptBlob *> ScriptCache;
208 typedef QHash<QUrl, QDeclarativeQmldirData *> QmldirCache;
210 TypeCache m_typeCache;
211 ScriptCache m_scriptCache;
212 QmldirCache m_qmldirCache;
215 Q_DECLARE_OPERATORS_FOR_FLAGS(QDeclarativeTypeLoader::Options)
217 class Q_AUTOTEST_EXPORT QDeclarativeTypeData : public QDeclarativeDataBlob
222 TypeReference() : type(0), majorVersion(0), minorVersion(0), typeData(0) {}
224 QDeclarativeParser::Location location;
225 QDeclarativeType *type;
228 QDeclarativeTypeData *typeData;
231 struct ScriptReference
233 ScriptReference() : script(0) {}
235 QDeclarativeParser::Location location;
237 QDeclarativeScriptBlob *script;
240 QDeclarativeTypeData(const QUrl &, QDeclarativeTypeLoader::Options, QDeclarativeTypeLoader *);
241 ~QDeclarativeTypeData();
243 QDeclarativeTypeLoader *typeLoader() const;
245 const QDeclarativeImports &imports() const;
246 const QDeclarativeScriptParser &parser() const;
248 const QList<TypeReference> &resolvedTypes() const;
249 const QList<ScriptReference> &resolvedScripts() const;
251 QDeclarativeCompiledData *compiledData() const;
253 // Used by QDeclarativeComponent to get notifications
254 struct TypeDataCallback {
255 ~TypeDataCallback() {}
256 virtual void typeDataProgress(QDeclarativeTypeData *, qreal) {}
257 virtual void typeDataReady(QDeclarativeTypeData *) {}
259 void registerCallback(TypeDataCallback *);
260 void unregisterCallback(TypeDataCallback *);
264 virtual void dataReceived(const QByteArray &);
265 virtual void allDependenciesDone();
266 virtual void downloadProgressChanged(qreal);
272 QDeclarativeTypeLoader::Options m_options;
274 QDeclarativeQmldirData *qmldirForUrl(const QUrl &);
276 QDeclarativeScriptParser scriptParser;
277 QDeclarativeImports m_imports;
279 QList<ScriptReference> m_scripts;
280 QList<QDeclarativeQmldirData *> m_qmldirs;
282 QList<TypeReference> m_types;
283 bool m_typesResolved:1;
285 QDeclarativeCompiledData *m_compiledData;
287 QList<TypeDataCallback *> m_callbacks;
289 QDeclarativeTypeLoader *m_typeLoader;
292 class Q_AUTOTEST_EXPORT QDeclarativeScriptData : public QDeclarativeRefCount, public QDeclarativeCleanup
295 QDeclarativeScriptData(QDeclarativeEngine *);
296 ~QDeclarativeScriptData();
299 QDeclarativeTypeNameCache *importCache;
300 QList<QDeclarativeScriptBlob *> scripts;
301 QDeclarativeParser::Object::ScriptBlock::Pragmas pragmas;
304 virtual void clear(); // From QDeclarativeCleanup
307 friend class QDeclarativeVME;
308 friend class QDeclarativeScriptBlob;
311 v8::Persistent<v8::Script> m_program;
312 v8::Persistent<v8::Object> m_value;
313 // QScriptProgram m_program;
314 // QScriptValue m_value;
317 class Q_AUTOTEST_EXPORT QDeclarativeScriptBlob : public QDeclarativeDataBlob
320 QDeclarativeScriptBlob(const QUrl &, QDeclarativeTypeLoader *);
321 ~QDeclarativeScriptBlob();
323 struct ScriptReference
325 ScriptReference() : script(0) {}
327 QDeclarativeParser::Location location;
329 QDeclarativeScriptBlob *script;
332 QDeclarativeParser::Object::ScriptBlock::Pragmas pragmas() const;
333 QString scriptSource() const;
335 QDeclarativeTypeLoader *typeLoader() const;
336 const QDeclarativeImports &imports() const;
338 QDeclarativeScriptData *scriptData() const;
341 virtual void dataReceived(const QByteArray &);
345 QDeclarativeParser::Object::ScriptBlock::Pragmas m_pragmas;
348 QDeclarativeImports m_imports;
349 QList<ScriptReference> m_scripts;
350 QDeclarativeScriptData *m_scriptData;
352 QDeclarativeTypeLoader *m_typeLoader;
355 class Q_AUTOTEST_EXPORT QDeclarativeQmldirData : public QDeclarativeDataBlob
358 QDeclarativeQmldirData(const QUrl &);
360 const QDeclarativeDirComponents &dirComponents() const;
363 virtual void dataReceived(const QByteArray &);
366 QDeclarativeDirComponents m_components;
372 #endif // QDECLARATIVETYPELOADER_P_H