From 3da6b4fe8f711bf760e88a78ef7b2a11cb3fe5dd Mon Sep 17 00:00:00 2001
From: Kai Koehne <kai.koehne@nokia.com>
Date: Wed, 29 Jun 2011 15:56:45 +0200
Subject: [PATCH] QtQuickApp: Enable booster for Meego/Harmattan

Change-Id: I41db2c3dedf1f86bc38619d566f15622800dcb65
---
 share/qtcreator/templates/qtquickapp/app.pro       |    3 +
 share/qtcreator/templates/qtquickapp/main.cpp      |   24 +++++++-
 .../qmlapplicationviewer/qmlapplicationviewer.cpp  |   59 +++++++++++++++-----
 .../qmlapplicationviewer/qmlapplicationviewer.h    |    1 +
 4 files changed, 68 insertions(+), 19 deletions(-)

diff --git a/share/qtcreator/templates/qtquickapp/app.pro b/share/qtcreator/templates/qtquickapp/app.pro
index e8d1976..92f10c7 100644
--- a/share/qtcreator/templates/qtquickapp/app.pro
+++ b/share/qtcreator/templates/qtquickapp/app.pro
@@ -28,6 +28,9 @@ symbian:TARGET.CAPABILITY += NetworkServices
 # CONFIG += mobility
 # MOBILITY +=
 
+# Speed up launching on Meego/Harmattan when using applauncherd daemon
+CONFIG += qdeclarative-boostable
+
 # Add dependency to symbian components
 # QTQUICKCOMPONENTS #
 # CONFIG += qtquickcomponents
diff --git a/share/qtcreator/templates/qtquickapp/main.cpp b/share/qtcreator/templates/qtquickapp/main.cpp
index dfb208a..abd9a79 100644
--- a/share/qtcreator/templates/qtquickapp/main.cpp
+++ b/share/qtcreator/templates/qtquickapp/main.cpp
@@ -1,15 +1,31 @@
-#include <QtGui/QApplication>
 #include "qmlapplicationviewer.h"
+#include <QtGui/QApplication>
+
+#ifdef MEEGO_EDITION_HARMATTAN
+#include <MDeclarativeCache>
+#endif
 
-int main(int argc, char *argv[])
+Q_DECL_EXPORT int main(int argc, char *argv[])
 {
+#ifdef MEEGO_EDITION_HARMATTAN
+    QApplication *app = MDeclarativeCache::qApplication(argc, argv);
+    QDeclarativeView *view = MDeclarativeCache::qDeclarativeView();
+    QmlApplicationViewer viewer(view, "app");
+#else
     QApplication app(argc, argv);
-
     QmlApplicationViewer viewer;
+#endif
+
     viewer.addImportPath(QLatin1String("modules")); // ADDIMPORTPATH
     viewer.setOrientation(QmlApplicationViewer::ScreenOrientationAuto); // ORIENTATION
     viewer.setMainQmlFile(QLatin1String("qml/app/main.qml")); // MAINQML
     viewer.showExpanded();
 
-    return app.exec();
+#ifdef MEEGO_EDITION_HARMATTAN
+    app->exec();
+    delete view;
+    delete app;
+#else
+    app.exec();
+#endif
 }
diff --git a/share/qtcreator/templates/qtquickapp/qmlapplicationviewer/qmlapplicationviewer.cpp b/share/qtcreator/templates/qtquickapp/qmlapplicationviewer/qmlapplicationviewer.cpp
index f1a6b80..80cc5ea 100644
--- a/share/qtcreator/templates/qtquickapp/qmlapplicationviewer/qmlapplicationviewer.cpp
+++ b/share/qtcreator/templates/qtquickapp/qmlapplicationviewer/qmlapplicationviewer.cpp
@@ -43,9 +43,13 @@ static QmlJsDebuggingEnabler enableDebuggingHelper;
 
 class QmlApplicationViewerPrivate
 {
+    QmlApplicationViewerPrivate(QDeclarativeView *view_) : view(view_) {}
+
     QString mainQmlFile;
+    QString applicationName;
+    QDeclarativeView *view;
     friend class QmlApplicationViewer;
-    static QString adjustPath(const QString &path);
+    QString adjustPath(const QString &path);
 };
 
 QString QmlApplicationViewerPrivate::adjustPath(const QString &path)
@@ -56,13 +60,20 @@ 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;
+    if (!applicationName.isEmpty()) {
+        pathInInstallDir = QLatin1String("/opt/") + applicationName
+                + QLatin1Char('/') + path;
+    } else {
+        pathInInstallDir = QCoreApplication::applicationDirPath()
+                + QLatin1String("/../") + path;
+    }
+
+    if (QFileInfo(pathInInstallDir).exists()) {
         return pathInInstallDir;
     }
+
 #endif
 #endif
     return path;
@@ -70,17 +81,35 @@ QString QmlApplicationViewerPrivate::adjustPath(const QString &path)
 
 QmlApplicationViewer::QmlApplicationViewer(QWidget *parent) :
     QDeclarativeView(parent),
-    m_d(new QmlApplicationViewerPrivate)
+    m_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(m_d->view->engine());
+#endif
+#if !defined(NO_QMLOBSERVER)
+    new QmlJSDebugger::QDeclarativeViewObserver(m_d->view, m_d->view);
+#endif
+#endif
+}
+
+QmlApplicationViewer::QmlApplicationViewer(QDeclarativeView *view, const QString &applicationName)
+    : QDeclarativeView(0),
+      m_d(new QmlApplicationViewerPrivate(view))
+{
+    m_d->applicationName = applicationName;
+    connect(view->engine(), SIGNAL(quit()), 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(m_d->view->engine());
 #endif
 #if !defined(NO_QMLOBSERVER)
-    new QmlJSDebugger::QDeclarativeViewObserver(this, this);
+    new QmlJSDebugger::QDeclarativeViewObserver(m_d->view, m_d->view);
 #endif
 #endif
 }
@@ -92,13 +121,13 @@ QmlApplicationViewer::~QmlApplicationViewer()
 
 void QmlApplicationViewer::setMainQmlFile(const QString &file)
 {
-    m_d->mainQmlFile = QmlApplicationViewerPrivate::adjustPath(file);
-    setSource(QUrl::fromLocalFile(m_d->mainQmlFile));
+    m_d->mainQmlFile = m_d->adjustPath(file);
+    m_d->view->setSource(QUrl::fromLocalFile(m_d->mainQmlFile));
 }
 
 void QmlApplicationViewer::addImportPath(const QString &path)
 {
-    engine()->addImportPath(QmlApplicationViewerPrivate::adjustPath(path));
+    m_d->view->engine()->addImportPath(m_d->adjustPath(path));
 }
 
 void QmlApplicationViewer::setOrientation(ScreenOrientation orientation)
@@ -147,10 +176,10 @@ void QmlApplicationViewer::setOrientation(ScreenOrientation orientation)
 void QmlApplicationViewer::showExpanded()
 {
 #if defined(Q_OS_SYMBIAN) || defined(MEEGO_EDITION_HARMATTAN)
-    showFullScreen();
+    m_d->view->showFullScreen();
 #elif defined(Q_WS_MAEMO_5)
-    showMaximized();
+    m_d->view->showMaximized();
 #else
-    show();
+    m_d->view->show();
 #endif
 }
diff --git a/share/qtcreator/templates/qtquickapp/qmlapplicationviewer/qmlapplicationviewer.h b/share/qtcreator/templates/qtquickapp/qmlapplicationviewer/qmlapplicationviewer.h
index f4d7f40..90b4bd4 100644
--- a/share/qtcreator/templates/qtquickapp/qmlapplicationviewer/qmlapplicationviewer.h
+++ b/share/qtcreator/templates/qtquickapp/qmlapplicationviewer/qmlapplicationviewer.h
@@ -24,6 +24,7 @@ public:
     };
 
     explicit QmlApplicationViewer(QWidget *parent = 0);
+    explicit QmlApplicationViewer(QDeclarativeView *view, const QString &applicationName);
     virtual ~QmlApplicationViewer();
 
     void setMainQmlFile(const QString &file);
-- 
1.7.4.msysgit.0

