OSDN Git Service

QtQuickApp: Tweak template to enable Meego booster
authorKai Koehne <kai.koehne@nokia.com>
Wed, 17 Aug 2011 10:27:24 +0000 (12:27 +0200)
committerEike Ziller <eike.ziller@nokia.com>
Thu, 1 Sep 2011 11:15:12 +0000 (13:15 +0200)
Add support for the meego booster. This requires
 - Telling qmake to link to right libraries
 - Exporting main method
 - using QApplication, QDeclarativeView objects from cache
 - avoiding QCoreApplication::applicationDirPath()

To keep compatibility, QmlApplicationViewer is still derived from QDeclarativeView.
However, if the app booster is used it merely acts as a proxy to the view from the
cache.

Change-Id: I83e285d9ca3c2cfd86d1711e1fb93c72589ba14d
Reviewed-on: http://codereview.qt.nokia.com/3730
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Alessandro Portale <alessandro.portale@nokia.com>
Reviewed-by: Christian Kandeler <christian.kandeler@nokia.com>
share/qtcreator/templates/qtquickapp/app.pro
share/qtcreator/templates/qtquickapp/main.cpp
share/qtcreator/templates/qtquickapp/qmlapplicationviewer/qmlapplicationviewer.cpp
share/qtcreator/templates/qtquickapp/qmlapplicationviewer/qmlapplicationviewer.h
share/qtcreator/templates/qtquickapp/qmlapplicationviewer/qmlapplicationviewer.pri
src/plugins/qt4projectmanager/wizards/qtquickapp.cpp

index e8d1976..fcbcc0b 100644 (file)
@@ -28,7 +28,11 @@ symbian:TARGET.CAPABILITY += NetworkServices
 # CONFIG += mobility
 # MOBILITY +=
 
-# Add dependency to symbian components
+# Speed up launching on MeeGo/Harmattan when using applauncherd daemon
+# HARMATTAN_BOOSTABLE #
+# CONFIG += qdeclarative-boostable
+
+# Add dependency to Symbian components
 # QTQUICKCOMPONENTS #
 # CONFIG += qtquickcomponents
 
index dfb208a..82347f6 100644 (file)
@@ -1,15 +1,15 @@
 #include <QtGui/QApplication>
 #include "qmlapplicationviewer.h"
 
-int main(int argc, char *argv[])
+Q_DECL_EXPORT int main(int argc, char *argv[])
 {
-    QApplication app(argc, argv);
+    QScopedPointer<QApplication> app(createApplication(argc, argv));
+    QScopedPointer<QmlApplicationViewer> viewer(QmlApplicationViewer::create());
 
-    QmlApplicationViewer viewer;
-    viewer.addImportPath(QLatin1String("modules")); // ADDIMPORTPATH
-    viewer.setOrientation(QmlApplicationViewer::ScreenOrientationAuto); // ORIENTATION
-    viewer.setMainQmlFile(QLatin1String("qml/app/main.qml")); // MAINQML
-    viewer.showExpanded();
+    viewer->addImportPath(QLatin1String("modules")); // ADDIMPORTPATH
+    viewer->setOrientation(QmlApplicationViewer::ScreenOrientationAuto); // ORIENTATION
+    viewer->setMainQmlFile(QLatin1String("qml/app/main.qml")); // MAINQML
+    viewer->showExpanded();
 
-    return app.exec();
+    return app->exec();
 }
index d8500a2..c7ccf08 100644 (file)
@@ -9,15 +9,19 @@
 
 #include "qmlapplicationviewer.h"
 
-#include <QtCore/QCoreApplication>
 #include <QtCore/QDir>
 #include <QtCore/QFileInfo>
 #include <QtDeclarative/QDeclarativeComponent>
 #include <QtDeclarative/QDeclarativeEngine>
 #include <QtDeclarative/QDeclarativeContext>
+#include <QtGui/QApplication>
 
 #include <qplatformdefs.h> // MEEGO_EDITION_HARMATTAN
 
+#ifdef HARMATTAN_BOOSTER
+#include <MDeclarativeCache>
+#endif
+
 #if defined(QMLJSDEBUGGER) && QT_VERSION < 0x040800
 
 #include <qt_private/qdeclarativedebughelper_p.h>
@@ -45,9 +49,12 @@ static QmlJsDebuggingEnabler enableDebuggingHelper;
 
 class QmlApplicationViewerPrivate
 {
+    QmlApplicationViewerPrivate(QDeclarativeView *view_) : view(view_) {}
+
     QString mainQmlFile;
+    QDeclarativeView *view;
     friend class QmlApplicationViewer;
-    static QString adjustPath(const QString &path);
+    QString adjustPath(const QString &path);
 };
 
 QString QmlApplicationViewerPrivate::adjustPath(const QString &path)
@@ -58,49 +65,78 @@ QString QmlApplicationViewerPrivate::adjustPath(const QString &path)
         return QCoreApplication::applicationDirPath()
                 + QLatin1String("/../Resources/") + path;
 #else
-    const QString pathInInstallDir = QCoreApplication::applicationDirPath()
-        + QLatin1String("/../") + path;
-    if (pathInInstallDir.contains(QLatin1String("opt"))
-            && pathInInstallDir.contains(QLatin1String("bin"))
-            && QFileInfo(pathInInstallDir).exists()) {
+    QString pathInInstallDir;
+#ifdef HARMATTAN_BOOSTER
+    QString applicationDirPath = MDeclarativeCache::applicationDirPath();
+#else
+    QString applicationDirPath = QCoreApplication::applicationDirPath();
+#endif
+    pathInInstallDir = QString::fromAscii("%1/../%2").arg(applicationDirPath, path);
+
+    if (QFileInfo(pathInInstallDir).exists())
         return pathInInstallDir;
-    }
 #endif
 #endif
     return path;
 }
 
-QmlApplicationViewer::QmlApplicationViewer(QWidget *parent) :
-    QDeclarativeView(parent),
-    m_d(new QmlApplicationViewerPrivate)
+QmlApplicationViewer::QmlApplicationViewer(QWidget *parent)
+    : QDeclarativeView(parent)
+    , d(new QmlApplicationViewerPrivate(this))
 {
     connect(engine(), SIGNAL(quit()), SLOT(close()));
     setResizeMode(QDeclarativeView::SizeRootObjectToView);
     // Qt versions prior to 4.8.0 don't have QML/JS debugging services built in
 #if defined(QMLJSDEBUGGER) && QT_VERSION < 0x040800
 #if !defined(NO_JSDEBUGGER)
-    new QmlJSDebugger::JSDebuggerAgent(engine());
+    new QmlJSDebugger::JSDebuggerAgent(d->view->engine());
 #endif
 #if !defined(NO_QMLOBSERVER)
-    new QmlJSDebugger::QDeclarativeViewObserver(this, this);
+    new QmlJSDebugger::QDeclarativeViewObserver(d->view, d->view);
+#endif
+#endif
+}
+
+QmlApplicationViewer::QmlApplicationViewer(QDeclarativeView *view, QWidget *parent)
+    : QDeclarativeView(parent)
+    , d(new QmlApplicationViewerPrivate(view))
+{
+    connect(view->engine(), SIGNAL(quit()), view, SLOT(close()));
+    view->setResizeMode(QDeclarativeView::SizeRootObjectToView);
+    // Qt versions prior to 4.8.0 don't have QML/JS debugging services built in
+#if defined(QMLJSDEBUGGER) && QT_VERSION < 0x040800
+#if !defined(NO_JSDEBUGGER)
+    new QmlJSDebugger::JSDebuggerAgent(d->view->engine());
+#endif
+#if !defined(NO_QMLOBSERVER)
+    new QmlJSDebugger::QDeclarativeViewObserver(d->view, d->view);
 #endif
 #endif
 }
 
 QmlApplicationViewer::~QmlApplicationViewer()
 {
-    delete m_d;
+    delete d;
+}
+
+QmlApplicationViewer *QmlApplicationViewer::create()
+{
+#ifdef HARMATTAN_BOOSTER
+    return new QmlApplicationViewer(MDeclarativeCache::qDeclarativeView(), 0);
+#else
+    return new QmlApplicationViewer();
+#endif
 }
 
 void QmlApplicationViewer::setMainQmlFile(const QString &file)
 {
-    m_d->mainQmlFile = QmlApplicationViewerPrivate::adjustPath(file);
-    setSource(QUrl::fromLocalFile(m_d->mainQmlFile));
+    d->mainQmlFile = d->adjustPath(file);
+    d->view->setSource(QUrl::fromLocalFile(d->mainQmlFile));
 }
 
 void QmlApplicationViewer::addImportPath(const QString &path)
 {
-    engine()->addImportPath(QmlApplicationViewerPrivate::adjustPath(path));
+    d->view->engine()->addImportPath(d->adjustPath(path));
 }
 
 void QmlApplicationViewer::setOrientation(ScreenOrientation orientation)
@@ -149,10 +185,19 @@ void QmlApplicationViewer::setOrientation(ScreenOrientation orientation)
 void QmlApplicationViewer::showExpanded()
 {
 #if defined(Q_OS_SYMBIAN) || defined(MEEGO_EDITION_HARMATTAN) || defined(Q_WS_SIMULATOR)
-    showFullScreen();
+    d->view->showFullScreen();
 #elif defined(Q_WS_MAEMO_5)
-    showMaximized();
+    d->view->showMaximized();
+#else
+    d->view->show();
+#endif
+}
+
+QApplication *createApplication(int &argc, char **argv)
+{
+#ifdef HARMATTAN_BOOSTER
+    return MDeclarativeCache::qApplication(argc, argv);
 #else
-    show();
+    return new QApplication(argc, argv);
 #endif
 }
index f4d7f40..d6cb43e 100644 (file)
@@ -26,6 +26,8 @@ public:
     explicit QmlApplicationViewer(QWidget *parent = 0);
     virtual ~QmlApplicationViewer();
 
+    static QmlApplicationViewer *create();
+
     void setMainQmlFile(const QString &file);
     void addImportPath(const QString &path);
 
@@ -35,7 +37,10 @@ public:
     void showExpanded();
 
 private:
-    class QmlApplicationViewerPrivate *m_d;
+    explicit QmlApplicationViewer(QDeclarativeView *view, QWidget *parent);
+    class QmlApplicationViewerPrivate *d;
 };
 
+QApplication *createApplication(int &argc, char **argv);
+
 #endif // QMLAPPLICATIONVIEWER_H
index 6704a74..a32c88d 100644 (file)
@@ -16,3 +16,7 @@ INCLUDEPATH += $$PWD
 } else {
     DEFINES -= QMLJSDEBUGGER
 }
+
+contains(CONFIG,qdeclarative-boostable):contains(MEEGO_EDITION,harmattan) {
+    DEFINES += HARMATTAN_BOOSTER
+}
index 859d2da..72446e5 100644 (file)
@@ -460,7 +460,7 @@ QString QtQuickApp::componentSetDir(ComponentSet componentSet) const
     }
 }
 
-const int QtQuickApp::StubVersion = 15;
+const int QtQuickApp::StubVersion = 16;
 
 } // namespace Internal
 } // namespace Qt4ProjectManager