6065bb7c1c043ee1b088bce75ee8ed7f0f39090e
[ubi] / qml / ubi / AccountPage.qml
1 import QtQuick 1.0 // to target S60 5th Edition or Maemo 5
2 import "components"
3 import "UIConstants.js" as Const
4 import "u1.js" as U1
5 import "bytesconv.js" as Conv
6
7 Page {
8     id: root
9     title: qsTr("Account")
10
11     property variant secrets
12     property alias taskMenu: taskMenu
13
14     Component.onCompleted: init()
15
16     function init()
17     {
18         secrets = {
19             token: Utils.token(),
20             secret: Utils.tokenSecret(),
21             consumer_key : Utils.customerKey(),
22             consumer_secret: Utils.customerSecret()
23         };
24         mask.state = "busy";
25         U1.getAccount(secrets,root);
26     }
27
28     function onResp(secrets,account)
29     {
30         //console.log("onResp");
31         mask.state = "idle";
32
33         //uid.text = account.id;
34         username.text = account.username;
35         //nick.text = account.nickname;
36         email.text = account.email;
37         storage.text = Conv.bytesToSize(account.total_storage);
38
39         U1.getRootNode(secrets,root);
40     }
41
42     function onRespRootNode(resp)
43     {
44         //console.log("onResp");
45         mask.state = "idle";
46         var ubytes = Conv.bytesToSize(resp.used_bytes);
47         var uprec = Math.round((resp.used_bytes/resp.max_bytes)*100);
48         used.text = ubytes+" ("+uprec+"%)";
49     }
50
51     function onErr(status)
52     {
53         //console.log("onErr");
54         mask.state = "idle";
55         if(status==401) {
56             tip.show(qsTr("Ubuntu One authorization has failed. Try once again or check login settings."));
57         } else if(status==0) {
58             tip.show(qsTr("Unable to connect. Check internet connection."));
59         } else {
60             tip.show(qsTr("Unknown error: ")+status);
61         }
62         pageStack.pop();
63     }
64
65     Flickable {
66         width: root.width
67         height: root.height
68
69         contentHeight: content.height+Const.TOP_BAR_HEIGHT+Const.SYSTEM_BAR_HEIGHT+Const.TEXT_MARGIN
70         y: Const.TOP_BAR_HEIGHT
71
72         Column {
73             id: content
74             spacing: Const.DEFAULT_MARGIN
75             x: Const.TEXT_MARGIN
76
77             /*Text {
78                 font.pixelSize: 30
79                 color: "white"
80                 text: "Id:"
81             }
82             Text {
83                 id: uid
84                 font.pixelSize: 30
85                 color: "black"
86                 wrapMode: Text.Wrap
87                 width: root.width - 6*Const.DEFAULT_MARGIN
88             }*/
89             Text {
90                 font.pixelSize: 30
91                 color: "white"
92                 text: qsTr("User name:")
93             }
94             Text {
95                 id: username
96                 font.pixelSize: 30
97                 color: "black"
98                 wrapMode: Text.Wrap
99                 width: root.width - 6*Const.DEFAULT_MARGIN
100             }
101             Line {
102                 width: root.width-2*Const.TEXT_MARGIN
103             }
104             /*Text {
105                 font.pixelSize: 30
106                 color: "white"
107                 text: qsTr("Nickname:")
108             }
109             Text {
110                 id: nick
111                 font.pixelSize: 30
112                 color: "black"
113                 wrapMode: Text.Wrap
114                 width: root.width - 6*Const.DEFAULT_MARGIN
115             }*/
116             Text {
117                 font.pixelSize: 30
118                 color: "white"
119                 text: qsTr("Email:")
120             }
121             Text {
122                 id: email
123                 font.pixelSize: 30
124                 color: "black"
125                 wrapMode: Text.Wrap
126                 width: root.width - 6*Const.DEFAULT_MARGIN
127             }
128             Line {
129                 width: root.width-2*Const.TEXT_MARGIN
130             }
131             Text {
132                 font.pixelSize: 30
133                 color: "white"
134                 text: qsTr("Total storage:")
135             }
136             Text {
137                 id: storage
138                 font.pixelSize: 30
139                 color: "black"
140                 wrapMode: Text.Wrap
141                 width: root.width - 6*Const.DEFAULT_MARGIN
142             }
143             Line {
144                 width: root.width-2*Const.TEXT_MARGIN
145             }
146             Text {
147                 font.pixelSize: 30
148                 color: "white"
149                 text: qsTr("Used:")
150             }
151             Text {
152                 id: used
153                 font.pixelSize: 30
154                 color: "black"
155                 wrapMode: Text.Wrap
156                 width: root.width - 6*Const.DEFAULT_MARGIN
157             }
158             Spacer{}
159         }
160     }
161
162     TaskMenu {
163         z: 200
164         id: taskMenu
165         menuHeight: menuFixed.height+4*Const.DEFAULT_MARGIN
166
167         menuDynamic: _menuDyn
168         Flow {
169             y: root.height-taskMenu.menuHeight-Const.SYSTEM_BAR_HEIGHT+1*Const.DEFAULT_MARGIN
170             id: _menuDyn
171         }
172     }
173 }