main.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * Copyright 2011 Wolfgang Koller - http://www.gofg.at/
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include <QApplication>
  17. #include "src/cordova.h"
  18. #if QT_VERSION < 0x050000
  19. # include <QDeclarativeView>
  20. # include <QDeclarativeContext>
  21. # include <QDeclarativeEngine>
  22. #else
  23. # include <QDeviceInfo>
  24. # include <QQuickView>
  25. # include <QQmlContext>
  26. # include <QQmlEngine>
  27. #endif
  28. #include <qplatformdefs.h>
  29. #ifdef MEEGO_EDITION_HARMATTAN
  30. # include <MDeclarativeCache>
  31. #endif
  32. #ifdef MEEGO_EDITION_HARMATTAN
  33. Q_DECL_EXPORT int main(int argc, char *argv[])
  34. #else
  35. int main(int argc, char *argv[])
  36. #endif
  37. {
  38. #ifdef MEEGO_EDITION_HARMATTAN
  39. QScopedPointer<QApplication> app(MDeclarativeCache::qApplication(argc, argv));
  40. #else
  41. QScopedPointer<QApplication> app(new QApplication(argc, argv));
  42. #endif
  43. if(argc == 3) {
  44. Cordova::instance()->setApp(argv[1], argv[2]);
  45. }
  46. #if QT_VERSION < 0x050000
  47. //#if defined(Q_OS_SYMBIAN)
  48. //Workaround for symbian: without this HTMl5 localStorage is not persistent, and HTML5 client side database
  49. // does not work (javascript execution stops due to error)
  50. // Reason is probably that on symbian default path for storage is set incorrectly.
  51. QWebSettings::globalSettings()->enablePersistentStorage(Cordova::instance()->workingDir());
  52. //#endif
  53. # ifdef MEEGO_EDITION_HARMATTAN
  54. QScopedPointer<QDeclarativeView> view(MDeclarativeCache::qDeclarativeView());
  55. # else
  56. QScopedPointer<QDeclarativeView> view(new QDeclarativeView());
  57. # endif
  58. Cordova::instance()->setTopLevelEventsReceiver(view.data());
  59. view->setResizeMode(QDeclarativeView::SizeRootObjectToView);
  60. view->rootContext()->setContextProperty("cordova", Cordova::instance());
  61. # ifdef MEEGO_EDITION_HARMATTAN
  62. view->setSource(QUrl(QString("%1/qml/main_qt4.qml").arg(Cordova::instance()->workingDir())));
  63. view->showFullScreen();
  64. # else
  65. view->setSource(QUrl(QString("%1/qml/main.qml").arg(Cordova::instance()->workingDir())));
  66. # if defined(Q_OS_SYMBIAN) || defined(QT_SIMULATOR)
  67. view->showFullScreen();
  68. # else
  69. view->show();
  70. # endif
  71. # endif
  72. #else // QT_VERSION >= 0x050000
  73. //HACK: we don't have any solution to check for harmattan in qt5
  74. // so we use check for LINUX OS and for "dfl61" substring in kernel version
  75. // (at least pr1.1 and pr1.2 contains it)
  76. QDeviceInfo info;
  77. bool isHarmattan = info.version(QDeviceInfo::Firmware).contains("dfl61");
  78. #ifndef Q_OS_LINUX
  79. isHarmattan = false;
  80. #endif
  81. //TODO: look later at boostable possibility for this here
  82. QScopedPointer<QQuickView> view(new QQuickView());;
  83. Cordova::instance()->setTopLevelEventsReceiver(view.data());
  84. view->setResizeMode(QQuickView::SizeRootObjectToView);
  85. view->rootContext()->setContextProperty("cordova", Cordova::instance());
  86. if (isHarmattan) {
  87. view->setSource(QUrl(QString("%1/qml/main_harmattan_qt5.qml").arg(Cordova::instance()->workingDir())));
  88. view->showFullScreen();
  89. } else {
  90. view->setSource(QUrl(QString("%1/qml/main_qt5.qml").arg(Cordova::instance()->workingDir())));
  91. view->show();
  92. }
  93. #endif
  94. return app->exec();
  95. }