MainPage.qml 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /**
  2. * Copyright (c) 2012 Nokia Corporation.
  3. */
  4. import QtQuick 1.1
  5. import com.nokia.symbian 1.1
  6. import SocialConnect 1.0
  7. import QtWebKit 1.0
  8. Page {
  9. id: mainPage
  10. ToolBarLayout {
  11. id: toolBarLayout
  12. ToolButton {
  13. flat: true
  14. iconSource: "toolbar-back"
  15. onClicked: {
  16. facebookConnection.removeCredentials();
  17. Qt.quit();
  18. }
  19. }
  20. }
  21. tools: toolBarLayout
  22. Component.onCompleted: {
  23. // Try restoring credentials. If access token not found or
  24. // it has been expired, authenticate.
  25. facebookConnection.restoreCredentials()
  26. if (!facebookConnection.authenticated) {
  27. facebookConnection.authenticate();
  28. }
  29. }
  30. FacebookConnection {
  31. id: facebookConnection
  32. webInterface: webInterface
  33. permissions: ["publish_stream", "read_stream", "friends_status"]
  34. clientId: "399096860123557" // Replace with your own application id.
  35. onNameChanged: helloText.text += "\nWelcome " + name +
  36. "! This is a FacebookConnection example program.";
  37. property string lastId: ""
  38. onAuthenticateCompleted: {
  39. if (success) {
  40. facebookConnection.storeCredentials();
  41. }
  42. webView.destroy(); // Destroy WebView after authentication.
  43. container.opacity = 1;
  44. }
  45. onDeauthenticateCompleted: Qt.quit();
  46. // Show busy indicator when sending requests to the network.
  47. onTransmittingChanged: {
  48. busyIndicator.visible = transmitting;
  49. }
  50. onRetrieveMessagesCompleted: {
  51. lastId = messages[messages.length - 1].time;
  52. for (var i = 0; i < messages.length; i++) {
  53. if (messages[i].text !== "") {
  54. // Convert Unix timestamp to human readable time.
  55. var time = new Date(messages[i].time * 1000);
  56. var timeStr = time.getMonth() + "/" +
  57. time.getDate() + "/" +
  58. time.getFullYear() + " " +
  59. time.getHours() + ":" +
  60. time.getMinutes() + "." +
  61. time.getSeconds();
  62. listModel.append({"message" : messages[i].text, "time" : timeStr});
  63. }
  64. }
  65. pageStack.push("qrc:/MessagesList.qml", {model: listModel});
  66. }
  67. }
  68. WebView {
  69. id: webView
  70. anchors.fill: parent
  71. preferredHeight: height
  72. preferredWidth: width
  73. onUrlChanged: webInterface.url = url;
  74. }
  75. WebInterface {
  76. id: webInterface
  77. onUrlChanged: webView.url = url;
  78. }
  79. Column {
  80. id: container
  81. width: parent.width
  82. spacing: 20
  83. opacity: 0
  84. Label {
  85. id: helloText
  86. wrapMode: Text.WordWrap
  87. width: parent.width
  88. z: 2
  89. }
  90. Button {
  91. width: parent.width
  92. text: "Post a test message"
  93. onClicked: facebookConnection.postMessage({"text" : "Hello!"});
  94. z: 2
  95. }
  96. Button {
  97. width: parent.width
  98. text: "Retrieve messages"
  99. onClicked: {
  100. facebookConnection.retrieveMessages("", facebookConnection.lastId, 20);
  101. }
  102. z: 2
  103. }
  104. ListModel {
  105. id: listModel
  106. }
  107. Behavior on opacity { NumberAnimation { duration: 300 } }
  108. }
  109. BusyIndicator {
  110. id: busyIndicator
  111. width: 100
  112. height: 100
  113. anchors.centerIn: parent
  114. running: visible ? true : false;
  115. visible: false
  116. Behavior on opacity { NumberAnimation { duration: 300 } }
  117. }
  118. }