New GUI
[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     //property alias taskMenu: taskMenu
12
13     function getToken() {
14         mask.state = "busy";
15         U1.getToken(user.text,pass.text,root)
16     }
17
18     function onResp(secrets,account) {
19         mask.state = "idle";
20         Utils.setCustomerKey(secrets.consumer_key);
21         Utils.setCustomerSecret(secrets.consumer_secret);
22         Utils.setToken(secrets.token);
23         Utils.setTokenSecret(secrets.secret);
24         Utils.setName(account.username);
25
26         tip.show(qsTr("Logged in!"));
27         //pageStack.initialPage = "StartPage.qml";
28         pageStack.initialPage = "FilesPage.qml";
29         pageStack.currentPage.init();
30     }
31
32     function onErr(status) {
33         mask.state = "idle";
34         //console.log("onErr");
35         if(status==401) {
36             tip.show(qsTr("Ubuntu One authorization has failed. Try once again or check login settings."));
37         } else if(status==0) {
38             tip.show(qsTr("Unable to connect. Check internet connection."));
39         } else {
40             tip.show(qsTr("Unknown error: ")+status);
41         }
42     }
43
44     Flickable {
45         width: root.width
46         height: root.height
47
48         contentHeight: content.height+Const.TOP_BAR_HEIGHT+Const.SYSTEM_BAR_HEIGHT+Const.TEXT_MARGIN
49         y: Const.TOP_BAR_HEIGHT
50
51         Column {
52             id: content
53             spacing: Const.DEFAULT_MARGIN
54             x: Const.TEXT_MARGIN
55
56             Text {
57                 font.pixelSize: 30
58                 color: "white"
59                 text: qsTr("Ubuntu One sign in:")
60             }
61
62             Spacer {}
63
64             TextField {
65                 id: user
66                 placeholderText: qsTr("User ID")
67                 width: 400
68             }
69
70             TextField {
71                 id: pass
72                 width: 400
73                 placeholderText: qsTr("Password")
74                 echoMode: TextInput.Password
75             }
76
77             Spacer {}
78
79             Button {
80                 label: qsTr("Save")
81                 onButtonClicked: root.getToken()
82             }
83         }
84     }
85
86     /*TaskMenu {
87         z: 200
88         id: taskMenu
89         menuHeight: menuFixed.height+4*Const.DEFAULT_MARGIN
90
91         menuDynamic: _menuDyn
92         Flow {
93             y: root.height-taskMenu.menuHeight-Const.SYSTEM_BAR_HEIGHT+1*Const.DEFAULT_MARGIN
94             id: _menuDyn
95         }
96     }*/
97 }