WWW update
[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 = "FilesPage.qml";
26         pageStack.currentPage.init();
27     }
28
29     function onErr(status) {
30         mask.state = "idle";
31         if(status==401) {
32             tip.show(qsTr("Ubuntu One authorization has failed. Try once again or check login settings."));
33         } else if(status==0) {
34             tip.show(qsTr("Unable to connect. Check internet connection."));
35         } else {
36             tip.show(qsTr("Unknown error: ")+status);
37         }
38     }
39
40     Flickable {
41         width: root.width
42         height: root.height
43
44         contentHeight: content.height+Const.TOP_BAR_HEIGHT+Const.SYSTEM_BAR_HEIGHT+Const.TEXT_MARGIN
45
46         Column {
47             id: content
48             spacing: Const.DEFAULT_MARGIN
49             x: Const.TEXT_MARGIN
50             width: root.width-2*Const.TEXT_MARGIN
51
52             Spacer {}
53
54             Text {
55                 font.pixelSize: 30
56                 color: "white"
57                 text: qsTr("Ubuntu One sign in:")
58             }
59
60             Spacer {}
61
62             TextField {
63                 id: user
64                 placeholderText: qsTr("User ID")
65                 anchors.left: parent.left
66                 anchors.right: parent.right
67             }
68
69             TextField {
70                 id: pass
71                 placeholderText: qsTr("Password")
72                 echoMode: TextInput.Password
73                 anchors.left: parent.left
74                 anchors.right: parent.right
75             }
76
77             Spacer {}
78
79             Button {
80                 label: qsTr("Save")
81                 onButtonClicked: {
82                     root.getToken();
83                     user.closeSoftwareInputPanel();
84                     pass.closeSoftwareInputPanel();
85                 }
86                 anchors.left: parent.left
87             }
88         }
89     }
90
91 }