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 <QtScript/qscriptvalue.h>
59 #include <QtScript/qscriptprogram.h>
60 #include <QtDeclarative/qdeclarativeerror.h>
61 #include <QtDeclarative/qdeclarativeengine.h>
62 #include <private/qdeclarativecleanup_p.h>
63 #include <private/qdeclarativescriptparser_p.h>
64 #include <private/qdeclarativedirparser_p.h>
65 #include <private/qdeclarativeimport_p.h>
69 class QDeclarativeScriptData;
70 class QDeclarativeScriptBlob;
71 class QDeclarativeQmldirData;
72 class QDeclarativeTypeLoader;
73 class QDeclarativeCompiledData;
74 class QDeclarativeComponentPrivate;
75 class QDeclarativeTypeData;
76 class QDeclarativeDataLoader;
78 class Q_AUTOTEST_EXPORT QDeclarativeDataBlob : public QDeclarativeRefCount
82 Null, // Prior to QDeclarativeDataLoader::load()
83 Loading, // Prior to data being received and dataReceived() being called
84 WaitingForDependencies, // While there are outstanding addDependency()s
95 QDeclarativeDataBlob(const QUrl &, Type);
96 virtual ~QDeclarativeDataBlob();
100 Status status() const;
102 bool isLoading() const;
103 bool isWaiting() const;
104 bool isComplete() const;
105 bool isError() const;
106 bool isCompleteOrError() const;
108 qreal progress() const;
111 QUrl finalUrl() const;
113 QList<QDeclarativeError> errors() const;
115 void setError(const QDeclarativeError &);
116 void setError(const QList<QDeclarativeError> &errors);
118 void addDependency(QDeclarativeDataBlob *);
121 virtual void dataReceived(const QByteArray &) = 0;
124 virtual void networkError(QNetworkReply::NetworkError);
126 virtual void dependencyError(QDeclarativeDataBlob *);
127 virtual void dependencyComplete(QDeclarativeDataBlob *);
128 virtual void allDependenciesDone();
130 virtual void downloadProgressChanged(qreal);
133 friend class QDeclarativeDataLoader;
135 void cancelAllWaitingFor();
136 void notifyAllWaitingOnMe();
137 void notifyComplete(QDeclarativeDataBlob *);
146 // List of QDeclarativeDataBlob's that are waiting for me to complete.
147 QList<QDeclarativeDataBlob *> m_waitingOnMe;
149 // List of QDeclarativeDataBlob's that I am waiting for to complete.
150 QList<QDeclarativeDataBlob *> m_waitingFor;
152 // Manager that is currently fetching data for me
153 QDeclarativeDataLoader *m_manager;
154 int m_redirectCount:30;
158 QList<QDeclarativeError> m_errors;
161 class Q_AUTOTEST_EXPORT QDeclarativeDataLoader : public QObject
165 QDeclarativeDataLoader(QDeclarativeEngine *);
166 ~QDeclarativeDataLoader();
168 void load(QDeclarativeDataBlob *);
169 void loadWithStaticData(QDeclarativeDataBlob *, const QByteArray &);
171 QDeclarativeEngine *engine() const;
174 void networkReplyFinished();
175 void networkReplyProgress(qint64,qint64);
178 void setData(QDeclarativeDataBlob *, const QByteArray &);
180 QDeclarativeEngine *m_engine;
181 typedef QHash<QNetworkReply *, QDeclarativeDataBlob *> NetworkReplies;
182 NetworkReplies m_networkReplies;
185 class Q_AUTOTEST_EXPORT QDeclarativeTypeLoader : public QDeclarativeDataLoader
189 QDeclarativeTypeLoader(QDeclarativeEngine *);
190 ~QDeclarativeTypeLoader();
196 Q_DECLARE_FLAGS(Options, Option)
198 QDeclarativeTypeData *get(const QUrl &url);
199 QDeclarativeTypeData *get(const QByteArray &, const QUrl &url, Options = None);
202 QDeclarativeScriptBlob *getScript(const QUrl &);
203 QDeclarativeQmldirData *getQmldir(const QUrl &);
205 typedef QHash<QUrl, QDeclarativeTypeData *> TypeCache;
206 typedef QHash<QUrl, QDeclarativeScriptBlob *> ScriptCache;
207 typedef QHash<QUrl, QDeclarativeQmldirData *> QmldirCache;
209 TypeCache m_typeCache;
210 ScriptCache m_scriptCache;
211 QmldirCache m_qmldirCache;
214 Q_DECLARE_OPERATORS_FOR_FLAGS(QDeclarativeTypeLoader::Options)
216 class Q_AUTOTEST_EXPORT QDeclarativeTypeData : public QDeclarativeDataBlob
221 TypeReference() : type(0), majorVersion(0), minorVersion(0), typeData(0) {}
223 QDeclarativeParser::Location location;
224 QDeclarativeType *type;
227 QDeclarativeTypeData *typeData;
230 struct ScriptReference
232 ScriptReference() : script(0) {}
234 QDeclarativeParser::Location location;
236 QDeclarativeScriptBlob *script;
239 QDeclarativeTypeData(const QUrl &, QDeclarativeTypeLoader::Options, QDeclarativeTypeLoader *);
240 ~QDeclarativeTypeData();
242 QDeclarativeTypeLoader *typeLoader() const;
244 const QDeclarativeImports &imports() const;
245 const QDeclarativeScriptParser &parser() const;
247 const QList<TypeReference> &resolvedTypes() const;
248 const QList<ScriptReference> &resolvedScripts() const;
250 QDeclarativeCompiledData *compiledData() const;
252 // Used by QDeclarativeComponent to get notifications
253 struct TypeDataCallback {
254 ~TypeDataCallback() {}
255 virtual void typeDataProgress(QDeclarativeTypeData *, qreal) {}
256 virtual void typeDataReady(QDeclarativeTypeData *) {}
258 void registerCallback(TypeDataCallback *);
259 void unregisterCallback(TypeDataCallback *);
263 virtual void dataReceived(const QByteArray &);
264 virtual void allDependenciesDone();
265 virtual void downloadProgressChanged(qreal);
271 QDeclarativeTypeLoader::Options m_options;
273 QDeclarativeQmldirData *qmldirForUrl(const QUrl &);
275 QDeclarativeScriptParser scriptParser;
276 QDeclarativeImports m_imports;
278 QList<ScriptReference> m_scripts;
279 QList<QDeclarativeQmldirData *> m_qmldirs;
281 QList<TypeReference> m_types;
282 bool m_typesResolved:1;
284 QDeclarativeCompiledData *m_compiledData;
286 QList<TypeDataCallback *> m_callbacks;
288 QDeclarativeTypeLoader *m_typeLoader;
291 class Q_AUTOTEST_EXPORT QDeclarativeScriptData : public QDeclarativeRefCount, public QDeclarativeCleanup
294 QDeclarativeScriptData(QDeclarativeEngine *);
295 ~QDeclarativeScriptData();
298 QDeclarativeTypeNameCache *importCache;
299 QList<QDeclarativeScriptBlob *> scripts;
300 QDeclarativeParser::Object::ScriptBlock::Pragmas pragmas;
303 virtual void clear(); // From QDeclarativeCleanup
306 friend class QDeclarativeVME;
307 friend class QDeclarativeScriptBlob;
310 QScriptProgram m_program;
311 QScriptValue m_value;
314 class Q_AUTOTEST_EXPORT QDeclarativeScriptBlob : public QDeclarativeDataBlob
317 QDeclarativeScriptBlob(const QUrl &, QDeclarativeTypeLoader *);
318 ~QDeclarativeScriptBlob();
320 struct ScriptReference
322 ScriptReference() : script(0) {}
324 QDeclarativeParser::Location location;
326 QDeclarativeScriptBlob *script;
329 QDeclarativeParser::Object::ScriptBlock::Pragmas pragmas() const;
330 QString scriptSource() const;
332 QDeclarativeTypeLoader *typeLoader() const;
333 const QDeclarativeImports &imports() const;
335 QDeclarativeScriptData *scriptData() const;
338 virtual void dataReceived(const QByteArray &);
342 QDeclarativeParser::Object::ScriptBlock::Pragmas m_pragmas;
345 QDeclarativeImports m_imports;
346 QList<ScriptReference> m_scripts;
347 QDeclarativeScriptData *m_scriptData;
349 QDeclarativeTypeLoader *m_typeLoader;
352 class Q_AUTOTEST_EXPORT QDeclarativeQmldirData : public QDeclarativeDataBlob
355 QDeclarativeQmldirData(const QUrl &);
357 const QDeclarativeDirComponents &dirComponents() const;
360 virtual void dataReceived(const QByteArray &);
363 QDeclarativeDirComponents m_components;
369 #endif // QDECLARATIVETYPELOADER_P_H