main.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. QDir qmlPath(QCoreApplication::applicationDirPath());
  24. qmlPath.cdUp();
  25. QString listModelFilePath = qmlPath.filePath("qml/VideoStreamer/VideoListModel.qml");
  26. QScopedPointer<QDeclarativeComponent> dataModelComponent(
  27. new QDeclarativeComponent(viewer->engine(), listModelFilePath));
  28. QScopedPointer<QObject> dataModel(dataModelComponent->create());
  29. viewer->rootContext()->setContextProperty("xmlDataModel", dataModel.data());
  30. QScopedPointer<PlayerLauncher> playerLauncher(new PlayerLauncher);
  31. viewer->rootContext()->setContextProperty("playerLauncher", playerLauncher.data());
  32. #if defined(Q_OS_SYMBIAN)
  33. // Context property for listening the HW Volume key events in QML
  34. QScopedPointer<VolumeKeys> volumeKeys(new VolumeKeys(0));
  35. viewer->rootContext()->setContextProperty("volumeKeys", volumeKeys.data());
  36. // Set this attribute in order to avoid drawing the system
  37. // background unnecessarily.
  38. viewer->setAttribute(Qt::WA_NoSystemBackground);
  39. // Workaround for an issue with Symbian: "X.Y.Z" -> X.Y.Z
  40. static const QString VERSION_NUMBER(QString("%1").arg(VER).mid(1, QString(VER).length()-2));
  41. #else
  42. static const QString VERSION_NUMBER(QString("%1").arg(VER)); // X.Y.Z by itself
  43. #endif
  44. // Set the application version number as a context property (for the AboutView
  45. // to show) and set the quick loading Splash QML file.
  46. app->setApplicationVersion(VERSION_NUMBER);
  47. viewer->rootContext()->setContextProperty(QString("cp_versionNumber"), VERSION_NUMBER);
  48. viewer->setMainQmlFile(QLatin1String("qml/VideoStreamer/Splash.qml"));
  49. // Then trigger loading the *real* main.qml file, which can take longer to load.
  50. QScopedPointer<LoadHelper> loadHelper(
  51. LoadHelper::create(static_cast<QmlApplicationViewer*>(viewer.data())));
  52. QTimer::singleShot(1, loadHelper.data(), SLOT(loadMainQML()));
  53. // Show the QML app & execute the main loop.
  54. viewer->showExpanded();
  55. return app->exec();
  56. }