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 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
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/qdeclarativeerror.h>
59 #include <QtDeclarative/qdeclarativeengine.h>
60 #include <private/qdeclarativescriptparser_p.h>
61 #include <private/qdeclarativedirparser_p.h>
62 #include <private/qdeclarativeimport_p.h>
66 class QDeclarativeScriptData;
67 class QDeclarativeQmldirData;
68 class QDeclarativeTypeLoader;
69 class QDeclarativeCompiledData;
70 class QDeclarativeComponentPrivate;
71 class QDeclarativeTypeData;
72 class QDeclarativeDataLoader;
74 class Q_AUTOTEST_EXPORT QDeclarativeDataBlob : public QDeclarativeRefCount
78 Null, // Prior to QDeclarativeDataLoader::load()
79 Loading, // Prior to data being received and dataReceived() being called
80 WaitingForDependencies, // While there are outstanding addDependency()s
91 QDeclarativeDataBlob(const QUrl &, Type);
92 virtual ~QDeclarativeDataBlob();
96 Status status() const;
98 bool isLoading() const;
99 bool isWaiting() const;
100 bool isComplete() const;
101 bool isError() const;
102 bool isCompleteOrError() const;
104 qreal progress() const;
107 QUrl finalUrl() const;
109 QList<QDeclarativeError> errors() const;
111 void setError(const QDeclarativeError &);
112 void setError(const QList<QDeclarativeError> &errors);
114 void addDependency(QDeclarativeDataBlob *);
117 virtual void dataReceived(const QByteArray &) = 0;
120 virtual void networkError(QNetworkReply::NetworkError);
122 virtual void dependencyError(QDeclarativeDataBlob *);
123 virtual void dependencyComplete(QDeclarativeDataBlob *);
124 virtual void allDependenciesDone();
126 virtual void downloadProgressChanged(qreal);
129 friend class QDeclarativeDataLoader;
131 void cancelAllWaitingFor();
132 void notifyAllWaitingOnMe();
133 void notifyComplete(QDeclarativeDataBlob *);
142 // List of QDeclarativeDataBlob's that are waiting for me to complete.
143 QList<QDeclarativeDataBlob *> m_waitingOnMe;
145 // List of QDeclarativeDataBlob's that I am waiting for to complete.
146 QList<QDeclarativeDataBlob *> m_waitingFor;
148 // Manager that is currently fetching data for me
149 QDeclarativeDataLoader *m_manager;
150 int m_redirectCount:30;
154 QList<QDeclarativeError> m_errors;
157 class Q_AUTOTEST_EXPORT QDeclarativeDataLoader : public QObject
161 QDeclarativeDataLoader(QDeclarativeEngine *);
162 ~QDeclarativeDataLoader();
164 void load(QDeclarativeDataBlob *);
165 void loadWithStaticData(QDeclarativeDataBlob *, const QByteArray &);
167 QDeclarativeEngine *engine() const;
170 void networkReplyFinished();
171 void networkReplyProgress(qint64,qint64);
174 void setData(QDeclarativeDataBlob *, const QByteArray &);
176 QDeclarativeEngine *m_engine;
177 typedef QHash<QNetworkReply *, QDeclarativeDataBlob *> NetworkReplies;
178 NetworkReplies m_networkReplies;
182 class Q_AUTOTEST_EXPORT QDeclarativeTypeLoader : public QDeclarativeDataLoader
186 QDeclarativeTypeLoader(QDeclarativeEngine *);
187 ~QDeclarativeTypeLoader();
193 Q_DECLARE_FLAGS(Options, Option)
195 QDeclarativeTypeData *get(const QUrl &url);
196 QDeclarativeTypeData *get(const QByteArray &, const QUrl &url, Options = None);
199 QDeclarativeScriptData *getScript(const QUrl &);
200 QDeclarativeQmldirData *getQmldir(const QUrl &);
202 typedef QHash<QUrl, QDeclarativeTypeData *> TypeCache;
203 typedef QHash<QUrl, QDeclarativeScriptData *> ScriptCache;
204 typedef QHash<QUrl, QDeclarativeQmldirData *> QmldirCache;
206 TypeCache m_typeCache;
207 ScriptCache m_scriptCache;
208 QmldirCache m_qmldirCache;
211 Q_DECLARE_OPERATORS_FOR_FLAGS(QDeclarativeTypeLoader::Options)
213 class Q_AUTOTEST_EXPORT QDeclarativeTypeData : public QDeclarativeDataBlob
218 TypeReference() : type(0), majorVersion(0), minorVersion(0), typeData(0) {}
220 QDeclarativeParser::Location location;
221 QDeclarativeType *type;
224 QDeclarativeTypeData *typeData;
227 struct ScriptReference
229 ScriptReference() : script(0) {}
231 QDeclarativeParser::Location location;
233 QDeclarativeScriptData *script;
236 QDeclarativeTypeData(const QUrl &, QDeclarativeTypeLoader::Options, QDeclarativeTypeLoader *);
237 ~QDeclarativeTypeData();
239 QDeclarativeTypeLoader *typeLoader() const;
241 const QDeclarativeImports &imports() const;
242 const QDeclarativeScriptParser &parser() const;
244 const QList<TypeReference> &resolvedTypes() const;
245 const QList<ScriptReference> &resolvedScripts() const;
247 QDeclarativeCompiledData *compiledData() const;
249 // Used by QDeclarativeComponent to get notifications
250 struct TypeDataCallback {
251 ~TypeDataCallback() {}
252 virtual void typeDataProgress(QDeclarativeTypeData *, qreal) {}
253 virtual void typeDataReady(QDeclarativeTypeData *) {}
255 void registerCallback(TypeDataCallback *);
256 void unregisterCallback(TypeDataCallback *);
260 virtual void dataReceived(const QByteArray &);
261 virtual void allDependenciesDone();
262 virtual void downloadProgressChanged(qreal);
268 QDeclarativeTypeLoader::Options m_options;
270 QDeclarativeQmldirData *qmldirForUrl(const QUrl &);
272 QDeclarativeScriptParser scriptParser;
273 QDeclarativeImports m_imports;
275 QList<ScriptReference> m_scripts;
276 QList<QDeclarativeQmldirData *> m_qmldirs;
278 QList<TypeReference> m_types;
279 bool m_typesResolved:1;
281 QDeclarativeCompiledData *m_compiledData;
283 QList<TypeDataCallback *> m_callbacks;
285 QDeclarativeTypeLoader *m_typeLoader;
288 class Q_AUTOTEST_EXPORT QDeclarativeScriptData : public QDeclarativeDataBlob
291 QDeclarativeScriptData(const QUrl &);
293 QDeclarativeParser::Object::ScriptBlock::Pragmas pragmas() const;
294 QString scriptSource() const;
297 virtual void dataReceived(const QByteArray &);
300 QDeclarativeParser::Object::ScriptBlock::Pragmas m_pragmas;
304 class Q_AUTOTEST_EXPORT QDeclarativeQmldirData : public QDeclarativeDataBlob
307 QDeclarativeQmldirData(const QUrl &);
309 const QDeclarativeDirComponents &dirComponents() const;
312 virtual void dataReceived(const QByteArray &);
315 QDeclarativeDirComponents m_components;
321 #endif // QDECLARATIVETYPELOADER_P_H