Advertisement
Guest User

Untitled

a guest
Dec 6th, 2012
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.81 KB | None | 0 0
  1. import QtQuick 1.1
  2. import org.nemomobile.accounts 1.0
  3. import org.nemomobile.signon 1.0
  4.  
  5. Page {
  6. id: root
  7.  
  8. property AccountManager _acm: AccountManager {}
  9. property IdentityManager _idm: IdentityManager {}
  10. property QtObject _identity
  11. property QtObject _account
  12.  
  13. // the following 3 things would be populated from the UI.
  14. property string userName: "username"
  15. property string secret: "password"
  16. property string caption: "caption"
  17.  
  18. Rectangle {
  19. anchors.fill: parent
  20. color: "lightsteelblue"
  21. opacity: 0.5
  22. }
  23.  
  24. Text {
  25. id: alist
  26. anchors.top: parent.top
  27. anchors.left: parent.left
  28. anchors.right: parent.right
  29. height: (parent.height / 4) * 3
  30. text: "\n\n\nProvider Names:\n" + _acm.providerNames + "\n\nService Names:\n" + _acm.serviceNames + "\n\nAccount Identifiers:\n" + _acm.accountIdentifiers;
  31. color: "white"
  32. font.pixelSize: 20
  33. }
  34.  
  35. MouseArea {
  36. anchors.top: alist.bottom
  37. anchors.bottom: parent.bottom
  38. anchors.left: parent.left
  39. anchors.right: parent.right
  40. Text { anchors.fill: parent; text: "click to add identity and account" }
  41. onClicked: root.addIdentityAndAccount()
  42. }
  43.  
  44. function addIdentityAndAccount() {
  45. console.log("Creating and storing identity...")
  46. _identity = _idm.createIdentity()
  47. _identity.statusChanged.connect(handleIdentityStatusChange)
  48. }
  49.  
  50. function handleIdentityStatusChange() {
  51. if (_identity.status === Identity.Initialized) {
  52. // the identity is ready to be modified.
  53. _identity.userName = root.userName
  54. _identity.secret = root.secret
  55. _identity.caption = root.caption
  56. _identity.sync() // store to db
  57. } else if (_identity.status === Identity.Synced) {
  58. // success. Create the account, store the credentials.
  59. console.log("Successfully created identity. Creating and storing account...")
  60. _account = _acm.createAccount("google-example")
  61. _account.statusChanged.connect(handleAccountStatusChange)
  62. _account.displayName = "example account"
  63. _account.enabled = true
  64. _account.enableAccountWithService("google-talk")
  65. _account.identityIdentifier = _identity.identifier
  66. _account.sync() // store to db
  67. } else if (_identity.status === Identity.Invalid || _identity.status === Identity.SyncError) {
  68. // Identity was removed or error occurred; display error and exit
  69. console.log("Error storing identity: " + _identity.error + ": " + _identity.errorMessage)
  70. }
  71. }
  72.  
  73. function handleAccountStatusChange() {
  74. if (_account.status === Account.Synced) {
  75. // Finished syncing, display success message
  76. console.log("Successfully created account: " + _account.displayName + " with credentials id: " + _account.identityIdentifier)
  77. // Ensure that we can retrieve the identity successfully.
  78. _identity = _idm.identity(_account.identityIdentifier)
  79. _identity.statusChanged.connect(handleAccountIdentity);
  80. } else if (_account.status === Account.Invalid || _account.status === Account.SyncError) {
  81. // Account was removed or error occured; display error and exit
  82. console.log("Error storing account: " + _account.error + ": " + _account.errorMessage)
  83. }
  84. }
  85.  
  86. function handleAccountIdentity() {
  87. if (_identity.status == Identity.Initialized) {
  88. console.log("Retrieved account identity: identity caption: " + _identity.caption)
  89. } else {
  90. console.log("Error: could not retrieve account identity: " + _identity.errorMessage)
  91. }
  92. }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement