Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import QtQuick 1.1
- import org.nemomobile.accounts 1.0
- import org.nemomobile.signon 1.0
- Page {
- id: root
- property AccountManager _acm: AccountManager {}
- property IdentityManager _idm: IdentityManager {}
- property QtObject _identity
- property QtObject _account
- // the following 3 things would be populated from the UI.
- property string userName: "username"
- property string secret: "password"
- property string caption: "caption"
- Rectangle {
- anchors.fill: parent
- color: "lightsteelblue"
- opacity: 0.5
- }
- Text {
- id: alist
- anchors.top: parent.top
- anchors.left: parent.left
- anchors.right: parent.right
- height: (parent.height / 4) * 3
- text: "\n\n\nProvider Names:\n" + _acm.providerNames + "\n\nService Names:\n" + _acm.serviceNames + "\n\nAccount Identifiers:\n" + _acm.accountIdentifiers;
- color: "white"
- font.pixelSize: 20
- }
- MouseArea {
- anchors.top: alist.bottom
- anchors.bottom: parent.bottom
- anchors.left: parent.left
- anchors.right: parent.right
- Text { anchors.fill: parent; text: "click to add identity and account" }
- onClicked: root.addIdentityAndAccount()
- }
- function addIdentityAndAccount() {
- console.log("Creating and storing identity...")
- _identity = _idm.createIdentity()
- _identity.statusChanged.connect(handleIdentityStatusChange)
- }
- function handleIdentityStatusChange() {
- if (_identity.status === Identity.Initialized) {
- // the identity is ready to be modified.
- _identity.userName = root.userName
- _identity.secret = root.secret
- _identity.caption = root.caption
- _identity.sync() // store to db
- } else if (_identity.status === Identity.Synced) {
- // success. Create the account, store the credentials.
- console.log("Successfully created identity. Creating and storing account...")
- _account = _acm.createAccount("google-example")
- _account.statusChanged.connect(handleAccountStatusChange)
- _account.displayName = "example account"
- _account.enabled = true
- _account.enableAccountWithService("google-talk")
- _account.identityIdentifier = _identity.identifier
- _account.sync() // store to db
- } else if (_identity.status === Identity.Invalid || _identity.status === Identity.SyncError) {
- // Identity was removed or error occurred; display error and exit
- console.log("Error storing identity: " + _identity.error + ": " + _identity.errorMessage)
- }
- }
- function handleAccountStatusChange() {
- if (_account.status === Account.Synced) {
- // Finished syncing, display success message
- console.log("Successfully created account: " + _account.displayName + " with credentials id: " + _account.identityIdentifier)
- // Ensure that we can retrieve the identity successfully.
- _identity = _idm.identity(_account.identityIdentifier)
- _identity.statusChanged.connect(handleAccountIdentity);
- } else if (_account.status === Account.Invalid || _account.status === Account.SyncError) {
- // Account was removed or error occured; display error and exit
- console.log("Error storing account: " + _account.error + ": " + _account.errorMessage)
- }
- }
- function handleAccountIdentity() {
- if (_identity.status == Identity.Initialized) {
- console.log("Retrieved account identity: identity caption: " + _identity.caption)
- } else {
- console.log("Error: could not retrieve account identity: " + _identity.errorMessage)
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement