main_qt4.qml 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. import QtQuick 1.1
  2. import com.nokia.meego 1.0
  3. import QtWebKit 1.0
  4. import "cordova_wrapper.js" as CordovaWrapper
  5. PageStackWindow {
  6. id: appWindow
  7. initialPage: mainPage
  8. showToolBar: false
  9. Page {
  10. id: mainPage
  11. Flickable {
  12. id: webFlickable
  13. anchors.fill: parent
  14. contentHeight: webView.height
  15. contentWidth: webView.width
  16. boundsBehavior: "StopAtBounds"
  17. clip: true
  18. WebView {
  19. id: webView
  20. preferredWidth: mainPage.width
  21. preferredHeight: mainPage.height
  22. url: cordova.mainUrl
  23. settings.javascriptEnabled: true
  24. settings.offlineWebApplicationCacheEnabled : true
  25. settings.pluginsEnabled : true
  26. settings.localStorageDatabaseEnabled: true
  27. settings.offlineStorageDatabaseEnabled: true
  28. settings.localContentCanAccessRemoteUrls: true
  29. javaScriptWindowObjects: [QtObject{
  30. WebView.windowObjectName: "qmlWrapper"
  31. function callPluginFunction(pluginName, functionName, parameters) {
  32. parameters = eval("("+parameters+")")
  33. CordovaWrapper.execMethodOld(pluginName, functionName, parameters)
  34. }
  35. function callConfirm(message){
  36. comfirmText.text = message;
  37. myConfirm.open();
  38. }
  39. }]
  40. onUrlChanged: { console.log("url changing..")}
  41. onLoadFinished: {
  42. cordova.loadFinished(true)
  43. }
  44. onLoadFailed: cordova.loadFinished(false)
  45. onAlert: {
  46. alertText.text = message
  47. myalert.open()
  48. }
  49. Connections {
  50. target: cordova
  51. onJavaScriptExecNeeded: {
  52. console.log("onJavaScriptExecNeeded: " + js)
  53. webView.evaluateJavaScript(js)
  54. }
  55. onPluginWantsToBeAdded: {
  56. console.log("onPluginWantsToBeAdded: " + pluginName)
  57. CordovaWrapper.addPlugin(pluginName, pluginObject)
  58. }
  59. }
  60. Dialog {
  61. id: myalert
  62. content:Item {
  63. height: 50
  64. width: parent.width
  65. Text {
  66. id: alertText
  67. font.pixelSize: 22
  68. anchors.centerIn: parent
  69. color: "white"
  70. text: "Hello"
  71. }
  72. }
  73. buttons: ButtonRow {
  74. style: ButtonStyle { }
  75. anchors.horizontalCenter: parent.horizontalCenter
  76. Button {text: "OK"; onClicked: myalert.accept()}
  77. }
  78. }
  79. Dialog {
  80. id: myConfirm
  81. property string js: "Notification.Callback"
  82. content:Item {
  83. height: 50
  84. width: parent.width
  85. Text {
  86. id: comfirmText
  87. font.pixelSize: 22
  88. anchors.centerIn: parent
  89. color: "white"
  90. text: "confirm"
  91. }
  92. }
  93. buttons: ButtonRow {
  94. style: ButtonStyle { }
  95. anchors.horizontalCenter: parent.horizontalCenter
  96. Button {text: "OK"; onClicked:myConfirm.accept()}
  97. Button {text: "Cancel"; onClicked:myConfirm.reject()}
  98. }
  99. onAccepted: cordova.execJS(js + "(1)")
  100. onRejected: cordova.execJS(js + "(2)")
  101. }
  102. }
  103. }
  104. }
  105. }