main.cpp 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /**
  2. * Copyright (c) 2012 Nokia Corporation.
  3. */
  4. #include <QtCore/QString>
  5. #include <QtCore/QTimer>
  6. #include <QtCore/QDir>
  7. #include <QtGui/QApplication>
  8. #include <QtDeclarative/QDeclarativeContext>
  9. #include <QtDeclarative/QDeclarativeComponent>
  10. #include <QtDeclarative/QDeclarativeEngine>
  11. #include "qmlapplicationviewer.h"
  12. #include "loadhelper.h"
  13. #include "playerlauncher.h"
  14. #if defined(Q_OS_SYMBIAN)
  15. #include "volumekeys.h"
  16. #endif
  17. Q_DECL_EXPORT int main(int argc, char *argv[])
  18. {
  19. QScopedPointer<QApplication> app(createApplication(argc, argv));
  20. QScopedPointer<QmlApplicationViewer> viewer(QmlApplicationViewer::create());
  21. // Data model is created immediately to allow data fetching
  22. // during splash screen is shown.
  23. QScopedPointer<QDeclarativeComponent> dataModelComponent(
  24. new QDeclarativeComponent(
  25. viewer->engine(),
  26. QUrl::fromLocalFile("qml/VideoStreamer/VideoListModel.qml")) );
  27. QScopedPointer<QObject> dataModel(dataModelComponent->create());
  28. viewer->rootContext()->setContextProperty("xmlDataModel", dataModel.data());
  29. QScopedPointer<PlayerLauncher> playerLauncher(new PlayerLauncher);
  30. viewer->rootContext()->setContextProperty("playerLauncher", playerLauncher.data());
  31. #if defined(Q_OS_SYMBIAN)
  32. // Context property for listening the HW Volume key events in QML
  33. QScopedPointer<VolumeKeys> volumeKeys(new VolumeKeys(0));
  34. viewer->rootContext()->setContextProperty("volumeKeys", volumeKeys.data());
  35. // Set this attribute in order to avoid drawing the system
  36. // background unnecessarily.
  37. viewer->setAttribute(Qt::WA_NoSystemBackground);
  38. // Workaround for an issue with Symbian: "X.Y.Z" -> X.Y.Z
  39. static const QString VERSION_NUMBER(QString("%1").arg(VER).mid(1, QString(VER).length()-2));
  40. #else
  41. static const QString VERSION_NUMBER(QString("%1").arg(VER)); // X.Y.Z by itself
  42. #endif
  43. // Set the application version number as a context property (for the AboutView
  44. // to show) and set the quick loading Splash QML file.
  45. app->setApplicationVersion(VERSION_NUMBER);
  46. viewer->rootContext()->setContextProperty(QString("cp_versionNumber"), VERSION_NUMBER);
  47. viewer->setMainQmlFile(QLatin1String("qml/VideoStreamer/Splash.qml"));
  48. #if defined(IAA)
  49. viewer->rootContext()->setContextProperty(QString("cp_IAADefined"), true);
  50. #else
  51. viewer->rootContext()->setContextProperty(QString("cp_IAADefined"), false);
  52. #endif
  53. // Then trigger loading the *real* main.qml file, which can take longer to load.
  54. QScopedPointer<LoadHelper> loadHelper(
  55. LoadHelper::create(static_cast<QmlApplicationViewer*>(viewer.data())));
  56. QTimer::singleShot(1, loadHelper.data(), SLOT(loadMainQML()));
  57. // Show the QML app & execute the main loop.
  58. viewer->showExpanded();
  59. return app->exec();
  60. }