testapp.qml 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
  4. ** All rights reserved.
  5. ** Contact: Nokia Corporation (qt-info@nokia.com)
  6. **
  7. ** This file is part of the QtDeclarative module of the Qt Toolkit.
  8. **
  9. ** $QT_BEGIN_LICENSE:LGPL$
  10. ** GNU Lesser General Public License Usage
  11. ** This file may be used under the terms of the GNU Lesser General Public
  12. ** License version 2.1 as published by the Free Software Foundation and
  13. ** appearing in the file LICENSE.LGPL included in the packaging of this
  14. ** file. Please review the following information to ensure the GNU Lesser
  15. ** General Public License version 2.1 requirements will be met:
  16. ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
  17. **
  18. ** In addition, as a special exception, Nokia gives you certain additional
  19. ** rights. These rights are described in the Nokia Qt LGPL Exception
  20. ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
  21. **
  22. ** GNU General Public License Usage
  23. ** Alternatively, this file may be used under the terms of the GNU General
  24. ** Public License version 3.0 as published by the Free Software Foundation
  25. ** and appearing in the file LICENSE.GPL included in the packaging of this
  26. ** file. Please review the following information to ensure the GNU General
  27. ** Public License version 3.0 requirements will be met:
  28. ** http://www.gnu.org/copyleft/gpl.html.
  29. **
  30. ** Other Usage
  31. ** Alternatively, this file may be used in accordance with the terms and
  32. ** conditions contained in a signed written agreement between you and Nokia.
  33. **
  34. **
  35. **
  36. **
  37. **
  38. ** $QT_END_LICENSE$
  39. **
  40. ****************************************************************************/
  41. import QtQuick 1.1
  42. import QtWebKit 1.0
  43. import SocialConnect 1.0
  44. Item {
  45. id: screen; width: 300; height: 480
  46. property variant retrievedMessages: []
  47. state: "deauthenticated"
  48. Component.onCompleted: {
  49. facebookConnection.restoreCredentials();
  50. if (!facebookConnection.authenticated) {
  51. facebookConnection.authenticate();
  52. }
  53. else {
  54. proceed();
  55. }
  56. }
  57. function proceed() {
  58. state = "authenticated";
  59. }
  60. FacebookConnection {
  61. id: facebookConnection
  62. webInterface: webInterface
  63. permissions: ["publish_stream", "read_stream", "friends_status"]
  64. clientId: "399096860123557"
  65. onNameChanged: textArea.text += "\nWelcome " + name + "!";
  66. onAuthenticateCompleted: {
  67. facebookConnection.storeCredentials();
  68. proceed();
  69. }
  70. onDeauthenticateCompleted: Qt.quit();
  71. onRetrieveMessagesCompleted: {
  72. retrievedMessages = messages;
  73. console.debug("lngth:" + messages.length);
  74. for (var i = 0; i < messages.length; i++) {
  75. textArea.text += "\n" + messages[i]["text"];
  76. }
  77. }
  78. onRetrieveMessageCountCompleted: {
  79. textArea.text += "\nMsg count:" + count;
  80. }
  81. onPostMessageCompleted: {
  82. if (success) {
  83. textArea.text += "\nMessage posted";
  84. }
  85. else {
  86. textArea.text += "\nMessage posting failed";
  87. }
  88. }
  89. }
  90. WebInterface {
  91. id: webInterface
  92. onUrlChanged: webView.url = url;
  93. }
  94. WebView {
  95. id: webView
  96. anchors.fill: parent
  97. preferredHeight: height
  98. preferredWidth: width
  99. onUrlChanged: webInterface.url = url;
  100. Behavior on opacity { NumberAnimation { duration: 300 } }
  101. }
  102. Rectangle {
  103. id: background
  104. anchors.fill: parent; color: "#343434";
  105. opacity: 0
  106. Flickable {
  107. z: 2
  108. height: parent.height
  109. width: parent.width
  110. anchors.top: buttonRow2.bottom
  111. anchors.bottom: parent.bottom
  112. contentHeight: textArea.height
  113. Text {
  114. anchors.fill: parent
  115. id: textArea
  116. color: "white"
  117. }
  118. }
  119. Behavior on opacity { NumberAnimation { duration: 300 } }
  120. Image {
  121. source: "images/stripes.png";
  122. fillMode: Image.Tile;
  123. anchors.fill: parent;
  124. opacity: 0.3
  125. }
  126. MouseArea {
  127. anchors.fill: parent
  128. onClicked: screen.focus = false;
  129. }
  130. Item {
  131. id: views
  132. x: 2; width: parent.width - 4
  133. y:60
  134. height: parent.height - 100
  135. }
  136. Row {
  137. z: 3
  138. id: buttonRow
  139. anchors.top: parent.top
  140. Button {
  141. id: button1
  142. width: 100; height: 32
  143. focus:true
  144. text: "Post image"
  145. onClicked: {
  146. facebookConnection.postMessage({"text" : "Hello from socialexample!",
  147. "url" : "file:///socialconnectexample80.png"});
  148. }
  149. }
  150. Button {
  151. id: button2
  152. width: 100; height: 32
  153. text: "Post msg"
  154. onClicked: {
  155. facebookConnection.postMessage({"text" : "Hello from socialexample!"});
  156. }
  157. }
  158. Button {
  159. id: button3
  160. width: 100; height: 32
  161. text: "Retrieve msgs"
  162. onClicked: {
  163. facebookConnection.retrieveMessages("", "", 10);
  164. }
  165. }
  166. }
  167. Row {
  168. z: 3
  169. id: buttonRow2
  170. anchors.top: buttonRow.bottom
  171. Button {
  172. id: button4
  173. width: 100; height: 32
  174. focus:true
  175. text: "Retr. msg cnt"
  176. onClicked: {
  177. facebookConnection.retrieveMessageCount();
  178. }
  179. }
  180. Button {
  181. id: button5
  182. width: 100; height: 32
  183. focus:true
  184. text: "Deauthenticate"
  185. onClicked: {
  186. facebookConnection.deauthenticate();
  187. }
  188. }
  189. // Button {
  190. // id: button6
  191. // width: 100; height: 32
  192. // text: "Retrieve 5 more"
  193. // onClicked: {
  194. // facebookConnection.retrieveMessages("", "", 10);
  195. // }
  196. // }
  197. }
  198. }
  199. states: [
  200. State {
  201. name: "authenticated"
  202. PropertyChanges { target: webView; opacity: 0 }
  203. PropertyChanges { target: background; opacity: 1 }
  204. },
  205. State {
  206. name: "deauthenticated"
  207. PropertyChanges { target: webView; opacity: 1 }
  208. PropertyChanges { target: background; opacity: 0 }
  209. }
  210. ]
  211. }