summaryrefslogtreecommitdiffstats
path: root/src/declarative
diff options
context:
space:
mode:
Diffstat (limited to 'src/declarative')
-rw-r--r--src/declarative/declarative.pro3
-rw-r--r--src/declarative/qml/qmlengine.cpp119
-rw-r--r--src/declarative/qml/qmlengine_p.h36
-rw-r--r--src/declarative/qml/qmlsqldatabase.cpp12
-rw-r--r--src/declarative/qml/qmlworkerscript.cpp5
-rw-r--r--src/declarative/qml/qmlxmlhttprequest.cpp47
6 files changed, 141 insertions, 81 deletions
diff --git a/src/declarative/declarative.pro b/src/declarative/declarative.pro
index 0669d13..9cb45f6 100644
--- a/src/declarative/declarative.pro
+++ b/src/declarative/declarative.pro
@@ -16,6 +16,9 @@ exists("qml_enable_gcov") {
include(../qbase.pri)
+#INCLUDEPATH -= $$QMAKE_INCDIR_QT/$$TARGET
+#DESTDIR=.
+
#modules
include(3rdparty/3rdparty.pri)
include(util/util.pri)
diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp
index 3e7ac8e..8258bcb 100644
--- a/src/declarative/qml/qmlengine.cpp
+++ b/src/declarative/qml/qmlengine.cpp
@@ -115,60 +115,99 @@ struct StaticQtMetaObject : public QObject
QmlEnginePrivate::QmlEnginePrivate(QmlEngine *e)
: rootContext(0), currentExpression(0),
isDebugging(false), contextClass(0), sharedContext(0), sharedScope(0), objectClass(0), valueTypeClass(0), globalClass(0),
- nodeListClass(0), namedNodeMapClass(0), sqlQueryClass(0), cleanup(0), erroredBindings(0),
+ cleanup(0), erroredBindings(0),
inProgressCreations(0), scriptEngine(this), workerScriptEngine(0), componentAttacheds(0),
rootComponent(0), networkAccessManager(0), typeManager(e), uniqueId(1)
{
+ globalClass = new QmlGlobalScriptClass(&scriptEngine);
+}
+
+QUrl QmlScriptEngine::resolvedUrl(QScriptContext *context, const QUrl& url)
+{
+ if (p) {
+ QmlContext *ctxt = QmlEnginePrivate::get(this)->getContext(context);
+ Q_ASSERT(ctxt);
+ return ctxt->resolvedUrl(url);
+ }
+ return baseUrl.resolved(url);
+}
+
+QmlScriptEngine::QmlScriptEngine(QmlEnginePrivate *priv)
+ : p(priv),
+ sqlQueryClass(0),
+ namedNodeMapClass(0),
+ nodeListClass(0)
+{
// Note that all documentation for stuff put on the global object goes in
// doc/src/declarative/globalobject.qdoc
+
+ bool mainthread = priv != 0;
+
QScriptValue qtObject =
- scriptEngine.newQMetaObject(StaticQtMetaObject::get());
- scriptEngine.globalObject().setProperty(QLatin1String("Qt"), qtObject);
+ newQMetaObject(StaticQtMetaObject::get());
+ globalObject().setProperty(QLatin1String("Qt"), qtObject);
offlineStoragePath = QDesktopServices::storageLocation(QDesktopServices::DataLocation)
+ QDir::separator() + QLatin1String("QML")
+ QDir::separator() + QLatin1String("OfflineStorage");
- qt_add_qmlxmlhttprequest(&scriptEngine);
- qt_add_qmlsqldatabase(&scriptEngine);
+ qt_add_qmlxmlhttprequest(this);
+ qt_add_qmlsqldatabase(this);
//types
- qtObject.setProperty(QLatin1String("rgba"), scriptEngine.newFunction(QmlEnginePrivate::rgba, 4));
- qtObject.setProperty(QLatin1String("hsla"), scriptEngine.newFunction(QmlEnginePrivate::hsla, 4));
- qtObject.setProperty(QLatin1String("rect"), scriptEngine.newFunction(QmlEnginePrivate::rect, 4));
- qtObject.setProperty(QLatin1String("point"), scriptEngine.newFunction(QmlEnginePrivate::point, 2));
- qtObject.setProperty(QLatin1String("size"), scriptEngine.newFunction(QmlEnginePrivate::size, 2));
- qtObject.setProperty(QLatin1String("vector3d"), scriptEngine.newFunction(QmlEnginePrivate::vector, 3));
-
- //color helpers
- qtObject.setProperty(QLatin1String("lighter"), scriptEngine.newFunction(QmlEnginePrivate::lighter, 1));
- qtObject.setProperty(QLatin1String("darker"), scriptEngine.newFunction(QmlEnginePrivate::darker, 1));
- qtObject.setProperty(QLatin1String("tint"), scriptEngine.newFunction(QmlEnginePrivate::tint, 2));
+ qtObject.setProperty(QLatin1String("rgba"), newFunction(QmlEnginePrivate::rgba, 4));
+ qtObject.setProperty(QLatin1String("hsla"), newFunction(QmlEnginePrivate::hsla, 4));
+ qtObject.setProperty(QLatin1String("rect"), newFunction(QmlEnginePrivate::rect, 4));
+ qtObject.setProperty(QLatin1String("point"), newFunction(QmlEnginePrivate::point, 2));
+ qtObject.setProperty(QLatin1String("size"), newFunction(QmlEnginePrivate::size, 2));
+ qtObject.setProperty(QLatin1String("vector3d"), newFunction(QmlEnginePrivate::vector, 3));
+
+ if (mainthread) {
+ //color helpers
+ qtObject.setProperty(QLatin1String("lighter"), newFunction(QmlEnginePrivate::lighter, 1));
+ qtObject.setProperty(QLatin1String("darker"), newFunction(QmlEnginePrivate::darker, 1));
+ qtObject.setProperty(QLatin1String("tint"), newFunction(QmlEnginePrivate::tint, 2));
+ }
//misc methods
- qtObject.setProperty(QLatin1String("closestAngle"), scriptEngine.newFunction(QmlEnginePrivate::closestAngle, 2));
- qtObject.setProperty(QLatin1String("playSound"), scriptEngine.newFunction(QmlEnginePrivate::playSound, 1));
- qtObject.setProperty(QLatin1String("openUrlExternally"),scriptEngine.newFunction(desktopOpenUrl, 1));
- qtObject.setProperty(QLatin1String("md5"),scriptEngine.newFunction(md5, 1));
- qtObject.setProperty(QLatin1String("btoa"),scriptEngine.newFunction(btoa, 1));
- qtObject.setProperty(QLatin1String("atob"),scriptEngine.newFunction(atob, 1));
- qtObject.setProperty(QLatin1String("quit"), scriptEngine.newFunction(QmlEnginePrivate::quit, 0));
+ qtObject.setProperty(QLatin1String("closestAngle"), newFunction(QmlEnginePrivate::closestAngle, 2));
+ qtObject.setProperty(QLatin1String("playSound"), newFunction(QmlEnginePrivate::playSound, 1));
+ qtObject.setProperty(QLatin1String("openUrlExternally"),newFunction(QmlEnginePrivate::desktopOpenUrl, 1));
+ qtObject.setProperty(QLatin1String("md5"),newFunction(QmlEnginePrivate::md5, 1));
+ qtObject.setProperty(QLatin1String("btoa"),newFunction(QmlEnginePrivate::btoa, 1));
+ qtObject.setProperty(QLatin1String("atob"),newFunction(QmlEnginePrivate::atob, 1));
+ qtObject.setProperty(QLatin1String("quit"), newFunction(QmlEnginePrivate::quit, 0));
+ qtObject.setProperty(QLatin1String("resolvedUrl"),newFunction(QmlScriptEngine::resolvedUrl, 1));
//firebug/webkit compat
- QScriptValue consoleObject = scriptEngine.newObject();
- consoleObject.setProperty(QLatin1String("log"),scriptEngine.newFunction(consoleLog, 1));
- consoleObject.setProperty(QLatin1String("debug"),scriptEngine.newFunction(consoleLog, 1));
- scriptEngine.globalObject().setProperty(QLatin1String("console"), consoleObject);
-
- scriptEngine.globalObject().setProperty(QLatin1String("createQmlObject"),
- scriptEngine.newFunction(QmlEnginePrivate::createQmlObject, 1));
- scriptEngine.globalObject().setProperty(QLatin1String("createComponent"),
- scriptEngine.newFunction(QmlEnginePrivate::createComponent, 1));
+ QScriptValue consoleObject = newObject();
+ consoleObject.setProperty(QLatin1String("log"),newFunction(QmlEnginePrivate::consoleLog, 1));
+ consoleObject.setProperty(QLatin1String("debug"),newFunction(QmlEnginePrivate::consoleLog, 1));
+ globalObject().setProperty(QLatin1String("console"), consoleObject);
+
+ if (mainthread) {
+ globalObject().setProperty(QLatin1String("createQmlObject"),
+ newFunction(QmlEnginePrivate::createQmlObject, 1));
+ globalObject().setProperty(QLatin1String("createComponent"),
+ newFunction(QmlEnginePrivate::createComponent, 1));
+ }
// translation functions need to be installed
// before the global script class is constructed (QTBUG-6437)
- scriptEngine.installTranslatorFunctions();
+ installTranslatorFunctions();
+}
- globalClass = new QmlGlobalScriptClass(&scriptEngine);
+QmlScriptEngine::~QmlScriptEngine()
+{
+ delete sqlQueryClass;
+ delete nodeListClass;
+ delete namedNodeMapClass;
+}
+
+QScriptValue QmlScriptEngine::resolvedUrl(QScriptContext *ctxt, QScriptEngine *engine)
+{
+ QString arg = ctxt->argument(0).toString();
+ QUrl r = QmlScriptEngine::get(engine)->resolvedUrl(ctxt,QUrl(arg));
+ return QScriptValue(r.toString());
}
QmlEnginePrivate::~QmlEnginePrivate()
@@ -194,12 +233,6 @@ QmlEnginePrivate::~QmlEnginePrivate()
typeNameClass = 0;
delete listClass;
listClass = 0;
- delete nodeListClass;
- nodeListClass = 0;
- delete namedNodeMapClass;
- namedNodeMapClass = 0;
- delete sqlQueryClass;
- sqlQueryClass = 0;
for(int ii = 0; ii < bindValues.count(); ++ii)
clear(bindValues[ii]);
@@ -877,7 +910,7 @@ QScriptValue QmlEnginePrivate::consoleLog(QScriptContext *ctxt, QScriptEngine *e
// does just ignore the format letter, which makes it pointless.
}
- qDebug(msg.constData());
+ qDebug("%s",msg.constData());
return e->newVariant(QVariant(true));
}
@@ -1347,13 +1380,13 @@ void QmlEngine::addImportPath(const QString& path)
void QmlEngine::setOfflineStoragePath(const QString& dir)
{
Q_D(QmlEngine);
- d->offlineStoragePath = dir;
+ d->scriptEngine.offlineStoragePath = dir;
}
QString QmlEngine::offlineStoragePath() const
{
Q_D(const QmlEngine);
- return d->offlineStoragePath;
+ return d->scriptEngine.offlineStoragePath;
}
diff --git a/src/declarative/qml/qmlengine_p.h b/src/declarative/qml/qmlengine_p.h
index 68dcb2d..1d83d0f 100644
--- a/src/declarative/qml/qmlengine_p.h
+++ b/src/declarative/qml/qmlengine_p.h
@@ -104,6 +104,31 @@ class QmlCleanup;
class QmlBindingData;
class QmlWorkerScriptEngine;
+class QmlScriptEngine : public QScriptEngine
+{
+public:
+ QmlScriptEngine(QmlEnginePrivate *priv);
+
+ ~QmlScriptEngine();
+
+ QUrl resolvedUrl(QScriptContext *context, const QUrl& url); // resolved against p's context, or baseUrl if no p
+ static QScriptValue resolvedUrl(QScriptContext *ctxt, QScriptEngine *engine);
+
+ static QmlScriptEngine *get(QScriptEngine* e) { return static_cast<QmlScriptEngine*>(e); }
+
+ QmlEnginePrivate *p;
+
+ // User by SQL API
+ QScriptClass *sqlQueryClass;
+ QString offlineStoragePath;
+
+ // Used by DOM Core 3 API
+ QScriptClass *namedNodeMapClass;
+ QScriptClass *nodeListClass;
+
+ QUrl baseUrl;
+};
+
class QmlEnginePrivate : public QObjectPrivate
{
Q_DECLARE_PUBLIC(QmlEngine)
@@ -137,11 +162,6 @@ public:
QmlListScriptClass *listClass;
// Global script class
QScriptClass *globalClass;
- // Used by DOM Core 3 API
- QScriptClass *nodeListClass;
- QScriptClass *namedNodeMapClass;
- // Used by SQL database API
- QScriptClass *sqlQueryClass;
// Registered cleanup handlers
QmlCleanup *cleanup;
@@ -150,12 +170,6 @@ public:
QmlBindingData *erroredBindings;
int inProgressCreations;
- struct QmlScriptEngine : public QScriptEngine
- {
- QmlScriptEngine(QmlEnginePrivate *priv)
- : p(priv) {}
- QmlEnginePrivate *p;
- };
QmlScriptEngine scriptEngine;
QmlWorkerScriptEngine *getWorkerScriptEngine();
diff --git a/src/declarative/qml/qmlsqldatabase.cpp b/src/declarative/qml/qmlsqldatabase.cpp
index 2efe988..6ddd5e5 100644
--- a/src/declarative/qml/qmlsqldatabase.cpp
+++ b/src/declarative/qml/qmlsqldatabase.cpp
@@ -173,7 +173,8 @@ static const char* sqlerror[] = {
static QString databaseFile(const QString& connectionName, QScriptEngine *engine)
{
- QString basename = QmlEnginePrivate::get(engine)->offlineStoragePath
+ QmlScriptEngine *qmlengine = static_cast<QmlScriptEngine*>(engine);
+ QString basename = qmlengine->offlineStoragePath
+ QDir::separator() + QLatin1String("Databases") + QDir::separator();
basename += connectionName;
return basename;
@@ -198,6 +199,7 @@ static QScriptValue qmlsqldatabase_item(QScriptContext *context, QScriptEngine *
static QScriptValue qmlsqldatabase_executeSql_outsidetransaction(QScriptContext *context, QScriptEngine * /*engine*/)
{
+ qDebug() << QmlEngine::tr("executeSql called outside transaction()"); // XXX pending bug QTBUG-6507
THROW_SQL(DATABASE_ERR,QmlEngine::tr("executeSql called outside transaction()"));
}
@@ -224,9 +226,10 @@ static QScriptValue qmlsqldatabase_executeSql(QScriptContext *context, QScriptEn
}
if (query.exec()) {
result = engine->newObject();
- if (!QmlEnginePrivate::get(engine)->sqlQueryClass)
- QmlEnginePrivate::get(engine)->sqlQueryClass= new QmlSqlQueryScriptClass(engine);
- QScriptValue rows = engine->newObject(QmlEnginePrivate::get(engine)->sqlQueryClass);
+ QmlScriptEngine *qmlengine = static_cast<QmlScriptEngine*>(engine);
+ if (!qmlengine->sqlQueryClass)
+ qmlengine->sqlQueryClass = new QmlSqlQueryScriptClass(engine);
+ QScriptValue rows = engine->newObject(qmlengine->sqlQueryClass);
rows.setData(engine->newVariant(qVariantFromValue(query)));
rows.setProperty(QLatin1String("item"), engine->newFunction(qmlsqldatabase_item,1), QScriptValue::SkipInEnumeration);
result.setProperty(QLatin1String("rows"),rows);
@@ -406,6 +409,7 @@ void qt_add_qmlsqldatabase(QScriptEngine *engine)
{
QScriptValue openDatabase = engine->newFunction(qmlsqldatabase_open_sync, 4);
engine->globalObject().setProperty(QLatin1String("openDatabaseSync"), openDatabase);
+qDebug() << "qt_add_qmlsqldatabase" << engine;
QScriptValue sqlExceptionPrototype = engine->newObject();
for (int i=0; sqlerror[i]; ++i)
diff --git a/src/declarative/qml/qmlworkerscript.cpp b/src/declarative/qml/qmlworkerscript.cpp
index 2e1f16b..5c281bb 100644
--- a/src/declarative/qml/qmlworkerscript.cpp
+++ b/src/declarative/qml/qmlworkerscript.cpp
@@ -101,9 +101,9 @@ class QmlWorkerScriptEnginePrivate : public QObject
public:
QmlWorkerScriptEnginePrivate();
- struct ScriptEngine : public QScriptEngine
+ struct ScriptEngine : public QmlScriptEngine
{
- ScriptEngine(QmlWorkerScriptEnginePrivate *parent) : p(parent) {}
+ ScriptEngine(QmlWorkerScriptEnginePrivate *parent) : QmlScriptEngine(0), p(parent) {}
QmlWorkerScriptEnginePrivate *p;
};
ScriptEngine *workerEngine;
@@ -259,6 +259,7 @@ void QmlWorkerScriptEnginePrivate::processLoad(int id, const QUrl &url)
QScriptContext *ctxt = workerEngine->pushContext();
ctxt->setActivationObject(activation);
+ workerEngine->baseUrl = url;
workerEngine->evaluate(script);
workerEngine->popContext();
diff --git a/src/declarative/qml/qmlxmlhttprequest.cpp b/src/declarative/qml/qmlxmlhttprequest.cpp
index a5d6cd7..5f0fe9ce 100644
--- a/src/declarative/qml/qmlxmlhttprequest.cpp
+++ b/src/declarative/qml/qmlxmlhttprequest.cpp
@@ -754,10 +754,10 @@ QScriptValue NamedNodeMap::create(QScriptEngine *engine, NodeImpl *data, QList<N
instance.setData(engine->newVariant(qVariantFromValue(map)));
- if (!QmlEnginePrivate::get(engine)->namedNodeMapClass)
- QmlEnginePrivate::get(engine)->namedNodeMapClass= new NamedNodeMapClass(engine);
+ if (!QmlScriptEngine::get(engine)->namedNodeMapClass)
+ QmlScriptEngine::get(engine)->namedNodeMapClass= new NamedNodeMapClass(engine);
- instance.setScriptClass(QmlEnginePrivate::get(engine)->namedNodeMapClass);
+ instance.setScriptClass(QmlScriptEngine::get(engine)->namedNodeMapClass);
return instance;
}
@@ -811,10 +811,10 @@ QScriptValue NodeList::create(QScriptEngine *engine, NodeImpl *data)
instance.setData(engine->newVariant(qVariantFromValue(list)));
- if (!QmlEnginePrivate::get(engine)->nodeListClass)
- QmlEnginePrivate::get(engine)->nodeListClass= new NodeListClass(engine);
+ if (!QmlScriptEngine::get(engine)->nodeListClass)
+ QmlScriptEngine::get(engine)->nodeListClass= new NodeListClass(engine);
- instance.setScriptClass(QmlEnginePrivate::get(engine)->nodeListClass);
+ instance.setScriptClass(QmlScriptEngine::get(engine)->nodeListClass);
return instance;
}
@@ -939,7 +939,7 @@ public:
Opened = 1, HeadersReceived = 2,
Loading = 3, Done = 4 };
- QmlXMLHttpRequest(QmlEngine *engine);
+ QmlXMLHttpRequest();
virtual ~QmlXMLHttpRequest();
QScriptValue callback() const;
@@ -965,8 +965,6 @@ private slots:
void finished();
private:
- QmlEngine *m_engine;
-
State m_state;
bool m_errorFlag;
bool m_sendFlag;
@@ -987,13 +985,22 @@ private:
QNetworkRequest m_request;
QNetworkReply *m_network;
void destroyNetwork();
+
+ QNetworkAccessManager *m_nam;
+ QNetworkAccessManager *networkAccessManager()
+ {
+ if (!m_nam) {
+ m_nam = new QNetworkAccessManager;
+ // XXX proxy, etc...
+ }
+ return m_nam;
+ }
};
-QmlXMLHttpRequest::QmlXMLHttpRequest(QmlEngine *engine)
-: m_engine(engine), m_state(Unsent), m_errorFlag(false), m_sendFlag(false),
- m_network(0)
+QmlXMLHttpRequest::QmlXMLHttpRequest()
+: m_state(Unsent), m_errorFlag(false), m_sendFlag(false),
+ m_network(0), m_nam(0)
{
- Q_ASSERT(m_engine);
}
QmlXMLHttpRequest::~QmlXMLHttpRequest()
@@ -1138,13 +1145,13 @@ void QmlXMLHttpRequest::send(const QByteArray &data)
}
if (m_method == QLatin1String("GET"))
- m_network = m_engine->networkAccessManager()->get(request);
+ m_network = networkAccessManager()->get(request);
else if (m_method == QLatin1String("HEAD"))
- m_network = m_engine->networkAccessManager()->head(request);
+ m_network = networkAccessManager()->head(request);
else if(m_method == QLatin1String("POST"))
- m_network = m_engine->networkAccessManager()->post(request, data);
+ m_network = networkAccessManager()->post(request, data);
else if(m_method == QLatin1String("PUT"))
- m_network = m_engine->networkAccessManager()->put(request, data);
+ m_network = networkAccessManager()->put(request, data);
QObject::connect(m_network, SIGNAL(downloadProgress(qint64,qint64)),
this, SLOT(downloadProgress(qint64)));
@@ -1291,9 +1298,7 @@ static QScriptValue qmlxmlhttprequest_open(QScriptContext *context, QScriptEngin
QUrl url(context->argument(1).toString());
if (url.isRelative()) {
- QmlContext *ctxt = QmlEnginePrivate::get(engine)->getContext(context);
- Q_ASSERT(ctxt);
- url = ctxt->resolvedUrl(url);
+ url = QmlScriptEngine::get(engine)->resolvedUrl(context,url);
}
// Argument 2 - async (optional)
@@ -1527,7 +1532,7 @@ static QScriptValue qmlxmlhttprequest_onreadystatechange(QScriptContext *context
static QScriptValue qmlxmlhttprequest_new(QScriptContext *context, QScriptEngine *engine)
{
if (context->isCalledAsConstructor()) {
- context->thisObject().setData(engine->newQObject(new QmlXMLHttpRequest(QmlEnginePrivate::getEngine(engine)), QScriptEngine::ScriptOwnership));
+ context->thisObject().setData(engine->newQObject(new QmlXMLHttpRequest(), QScriptEngine::ScriptOwnership));
}
return engine->undefinedValue();
}