QtQuickApp: Tweak template to enable Meego booster

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>
This commit is contained in:
Kai Koehne
2011-08-17 12:27:24 +02:00
committed by Eike Ziller
parent 4848be6fe8
commit d687d11240
6 changed files with 89 additions and 31 deletions

View File

@@ -28,7 +28,11 @@ symbian:TARGET.CAPABILITY += NetworkServices
# CONFIG += mobility # CONFIG += mobility
# 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 # # QTQUICKCOMPONENTS #
# CONFIG += qtquickcomponents # CONFIG += qtquickcomponents

View File

@@ -1,15 +1,15 @@
#include <QtGui/QApplication> #include <QtGui/QApplication>
#include "qmlapplicationviewer.h" #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.addImportPath(QLatin1String("modules")); // ADDIMPORTPATH viewer->setOrientation(QmlApplicationViewer::ScreenOrientationAuto); // ORIENTATION
viewer.setOrientation(QmlApplicationViewer::ScreenOrientationAuto); // ORIENTATION viewer->setMainQmlFile(QLatin1String("qml/app/main.qml")); // MAINQML
viewer.setMainQmlFile(QLatin1String("qml/app/main.qml")); // MAINQML viewer->showExpanded();
viewer.showExpanded();
return app.exec(); return app->exec();
} }

View File

@@ -9,15 +9,19 @@
#include "qmlapplicationviewer.h" #include "qmlapplicationviewer.h"
#include <QtCore/QCoreApplication>
#include <QtCore/QDir> #include <QtCore/QDir>
#include <QtCore/QFileInfo> #include <QtCore/QFileInfo>
#include <QtDeclarative/QDeclarativeComponent> #include <QtDeclarative/QDeclarativeComponent>
#include <QtDeclarative/QDeclarativeEngine> #include <QtDeclarative/QDeclarativeEngine>
#include <QtDeclarative/QDeclarativeContext> #include <QtDeclarative/QDeclarativeContext>
#include <QtGui/QApplication>
#include <qplatformdefs.h> // MEEGO_EDITION_HARMATTAN #include <qplatformdefs.h> // MEEGO_EDITION_HARMATTAN
#ifdef HARMATTAN_BOOSTER
#include <MDeclarativeCache>
#endif
#if defined(QMLJSDEBUGGER) && QT_VERSION < 0x040800 #if defined(QMLJSDEBUGGER) && QT_VERSION < 0x040800
#include <qt_private/qdeclarativedebughelper_p.h> #include <qt_private/qdeclarativedebughelper_p.h>
@@ -45,9 +49,12 @@ static QmlJsDebuggingEnabler enableDebuggingHelper;
class QmlApplicationViewerPrivate class QmlApplicationViewerPrivate
{ {
QmlApplicationViewerPrivate(QDeclarativeView *view_) : view(view_) {}
QString mainQmlFile; QString mainQmlFile;
QDeclarativeView *view;
friend class QmlApplicationViewer; friend class QmlApplicationViewer;
static QString adjustPath(const QString &path); QString adjustPath(const QString &path);
}; };
QString QmlApplicationViewerPrivate::adjustPath(const QString &path) QString QmlApplicationViewerPrivate::adjustPath(const QString &path)
@@ -58,49 +65,78 @@ QString QmlApplicationViewerPrivate::adjustPath(const QString &path)
return QCoreApplication::applicationDirPath() return QCoreApplication::applicationDirPath()
+ QLatin1String("/../Resources/") + path; + QLatin1String("/../Resources/") + path;
#else #else
const QString pathInInstallDir = QCoreApplication::applicationDirPath() QString pathInInstallDir;
+ QLatin1String("/../") + path; #ifdef HARMATTAN_BOOSTER
if (pathInInstallDir.contains(QLatin1String("opt")) QString applicationDirPath = MDeclarativeCache::applicationDirPath();
&& pathInInstallDir.contains(QLatin1String("bin")) #else
&& QFileInfo(pathInInstallDir).exists()) { QString applicationDirPath = QCoreApplication::applicationDirPath();
#endif
pathInInstallDir = QString::fromAscii("%1/../%2").arg(applicationDirPath, path);
if (QFileInfo(pathInInstallDir).exists())
return pathInInstallDir; return pathInInstallDir;
}
#endif #endif
#endif #endif
return path; return path;
} }
QmlApplicationViewer::QmlApplicationViewer(QWidget *parent) : QmlApplicationViewer::QmlApplicationViewer(QWidget *parent)
QDeclarativeView(parent), : QDeclarativeView(parent)
m_d(new QmlApplicationViewerPrivate) , d(new QmlApplicationViewerPrivate(this))
{ {
connect(engine(), SIGNAL(quit()), SLOT(close())); connect(engine(), SIGNAL(quit()), SLOT(close()));
setResizeMode(QDeclarativeView::SizeRootObjectToView); setResizeMode(QDeclarativeView::SizeRootObjectToView);
// Qt versions prior to 4.8.0 don't have QML/JS debugging services built in // Qt versions prior to 4.8.0 don't have QML/JS debugging services built in
#if defined(QMLJSDEBUGGER) && QT_VERSION < 0x040800 #if defined(QMLJSDEBUGGER) && QT_VERSION < 0x040800
#if !defined(NO_JSDEBUGGER) #if !defined(NO_JSDEBUGGER)
new QmlJSDebugger::JSDebuggerAgent(engine()); new QmlJSDebugger::JSDebuggerAgent(d->view->engine());
#endif #endif
#if !defined(NO_QMLOBSERVER) #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
#endif #endif
} }
QmlApplicationViewer::~QmlApplicationViewer() 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) void QmlApplicationViewer::setMainQmlFile(const QString &file)
{ {
m_d->mainQmlFile = QmlApplicationViewerPrivate::adjustPath(file); d->mainQmlFile = d->adjustPath(file);
setSource(QUrl::fromLocalFile(m_d->mainQmlFile)); d->view->setSource(QUrl::fromLocalFile(d->mainQmlFile));
} }
void QmlApplicationViewer::addImportPath(const QString &path) void QmlApplicationViewer::addImportPath(const QString &path)
{ {
engine()->addImportPath(QmlApplicationViewerPrivate::adjustPath(path)); d->view->engine()->addImportPath(d->adjustPath(path));
} }
void QmlApplicationViewer::setOrientation(ScreenOrientation orientation) void QmlApplicationViewer::setOrientation(ScreenOrientation orientation)
@@ -149,10 +185,19 @@ void QmlApplicationViewer::setOrientation(ScreenOrientation orientation)
void QmlApplicationViewer::showExpanded() void QmlApplicationViewer::showExpanded()
{ {
#if defined(Q_OS_SYMBIAN) || defined(MEEGO_EDITION_HARMATTAN) || defined(Q_WS_SIMULATOR) #if defined(Q_OS_SYMBIAN) || defined(MEEGO_EDITION_HARMATTAN) || defined(Q_WS_SIMULATOR)
showFullScreen(); d->view->showFullScreen();
#elif defined(Q_WS_MAEMO_5) #elif defined(Q_WS_MAEMO_5)
showMaximized(); d->view->showMaximized();
#else #else
show(); d->view->show();
#endif
}
QApplication *createApplication(int &argc, char **argv)
{
#ifdef HARMATTAN_BOOSTER
return MDeclarativeCache::qApplication(argc, argv);
#else
return new QApplication(argc, argv);
#endif #endif
} }

View File

@@ -26,6 +26,8 @@ public:
explicit QmlApplicationViewer(QWidget *parent = 0); explicit QmlApplicationViewer(QWidget *parent = 0);
virtual ~QmlApplicationViewer(); virtual ~QmlApplicationViewer();
static QmlApplicationViewer *create();
void setMainQmlFile(const QString &file); void setMainQmlFile(const QString &file);
void addImportPath(const QString &path); void addImportPath(const QString &path);
@@ -35,7 +37,10 @@ public:
void showExpanded(); void showExpanded();
private: private:
class QmlApplicationViewerPrivate *m_d; explicit QmlApplicationViewer(QDeclarativeView *view, QWidget *parent);
class QmlApplicationViewerPrivate *d;
}; };
QApplication *createApplication(int &argc, char **argv);
#endif // QMLAPPLICATIONVIEWER_H #endif // QMLAPPLICATIONVIEWER_H

View File

@@ -16,3 +16,7 @@ INCLUDEPATH += $$PWD
} else { } else {
DEFINES -= QMLJSDEBUGGER DEFINES -= QMLJSDEBUGGER
} }
contains(CONFIG,qdeclarative-boostable):contains(MEEGO_EDITION,harmattan) {
DEFINES += HARMATTAN_BOOSTER
}

View File

@@ -460,7 +460,7 @@ QString QtQuickApp::componentSetDir(ComponentSet componentSet) const
} }
} }
const int QtQuickApp::StubVersion = 15; const int QtQuickApp::StubVersion = 16;
} // namespace Internal } // namespace Internal
} // namespace Qt4ProjectManager } // namespace Qt4ProjectManager