Update WWW
[ubi] / qml / ubi / LoginPage.qml
1 import QtQuick 1.0 // to target S60 5th Edition or Maemo 5
2 import "components"
3 import "u1.js" as U1
4 import "UIConstants.js" as Const
5
6 Page {
7     id: root
8     title: qsTr("Login")
9     orientation: "auto"
10
11     function getToken() {
12         mask.state = "busy";
13         U1.getToken(user.text,pass.text,root)
14     }
15
16     function onResp(secrets,account) {
17         mask.state = "idle";
18         Utils.setCustomerKey(secrets.consumer_key);
19         Utils.setCustomerSecret(secrets.consumer_secret);
20         Utils.setToken(secrets.token);
21         Utils.setTokenSecret(secrets.secret);
22         Utils.setName(account.username);
23
24         tip.show(qsTr("Logged in!"));
25         pageStack.initialPage = "StartPage.qml";
26     }
27
28     function onErr(status) {
29         mask.state = "idle";
30         //console.log("onErr");
31         if(status==401) {
32             tip.show(qsTr("Authorization failed!"));
33         } else if(status==0) {
34             tip.show(qsTr("Unable to connect!"));
35         } else {
36             tip.show(qsTr("Error: ")+status);
37         }
38     }
39
40     Flickable {
41         width: root.width
42         height: root.height
43         contentHeight: content.height+Const.SYSTEM_BAR_HEIGHT+Const.TEXT_MARGIN
44         y: Const.SYSTEM_BAR_HEIGHT+2*Const.TEXT_MARGIN
45
46         Column {
47             id: content
48             spacing: Const.DEFAULT_MARGIN
49             x: Const.TEXT_MARGIN
50
51             Text {
52                 font.pixelSize: 30
53                 color: "white"
54                 text: qsTr("Ubuntu One sign in:")
55             }
56
57             Spacer {}
58
59             TextField {
60                 id: user
61                 placeholderText: qsTr("User ID")
62                 width: 400
63             }
64
65             TextField {
66                 id: pass
67                 width: 400
68                 placeholderText: qsTr("Password")
69                 echoMode: TextInput.Password
70             }
71
72             Spacer {}
73
74             Button {
75                 label: qsTr("Save")
76                 onButtonClicked: root.getToken()
77             }
78         }
79     }
80 }