44a000a95e5a630416f35d174484eabb5b45ff10
[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         //username.text = "Molly";
36
37         //nick.text = account.nickname;
38
39         email.text = account.email;
40         //email.text = "molly@ponny.eu";
41         storage.text = Conv.bytesToSize(account.total_storage);
42
43         U1.getRootNode(secrets,root);
44     }
45
46     function onRespRootNode(resp)
47     {
48         //console.log("onResp");
49         mask.state = "idle";
50         var ubytes = Conv.bytesToSize(resp.used_bytes);
51         var uprec = Math.round((resp.used_bytes/resp.max_bytes)*100);
52         used.text = ubytes+" ("+uprec+"%)";
53     }
54
55     function onErr(status)
56     {
57         //console.log("onErr");
58         mask.state = "idle";
59         if(status==401) {
60             tip.show(qsTr("Ubuntu One authorization has failed. Try once again or check login settings."));
61         } else if(status==0) {
62             tip.show(qsTr("Unable to connect. Check internet connection."));
63         } else {
64             tip.show(qsTr("Unknown error: ")+status);
65         }
66         pageStack.pop();
67     }
68
69     Flickable {
70         width: root.width
71         height: root.height
72
73         contentHeight: content.height+Const.TOP_BAR_HEIGHT+Const.SYSTEM_BAR_HEIGHT+Const.TEXT_MARGIN
74         y: Const.TOP_BAR_HEIGHT
75
76         Column {
77             id: content
78             spacing: Const.DEFAULT_MARGIN
79             x: Const.TEXT_MARGIN
80
81             /*Text {
82                 font.pixelSize: 30
83                 color: "white"
84                 text: "Id:"
85             }
86             Text {
87                 id: uid
88                 font.pixelSize: 30
89                 color: "black"
90                 wrapMode: Text.Wrap
91                 width: root.width - 6*Const.DEFAULT_MARGIN
92             }*/
93             Text {
94                 font.pixelSize: 30
95                 color: "white"
96                 text: qsTr("User name:")
97             }
98             Text {
99                 id: username
100                 font.pixelSize: 30
101                 color: "black"
102                 wrapMode: Text.Wrap
103                 width: root.width - 6*Const.DEFAULT_MARGIN
104             }
105             Line {
106                 width: root.width-2*Const.TEXT_MARGIN
107             }
108             /*Text {
109                 font.pixelSize: 30
110                 color: "white"
111                 text: qsTr("Nickname:")
112             }
113             Text {
114                 id: nick
115                 font.pixelSize: 30
116                 color: "black"
117                 wrapMode: Text.Wrap
118                 width: root.width - 6*Const.DEFAULT_MARGIN
119             }*/
120             Text {
121                 font.pixelSize: 30
122                 color: "white"
123                 text: qsTr("Email:")
124             }
125             Text {
126                 id: email
127                 font.pixelSize: 30
128                 color: "black"
129                 wrapMode: Text.Wrap
130                 width: root.width - 6*Const.DEFAULT_MARGIN
131             }
132             Line {
133                 width: root.width-2*Const.TEXT_MARGIN
134             }
135             Text {
136                 font.pixelSize: 30
137                 color: "white"
138                 text: qsTr("Total storage:")
139             }
140             Text {
141                 id: storage
142                 font.pixelSize: 30
143                 color: "black"
144                 wrapMode: Text.Wrap
145                 width: root.width - 6*Const.DEFAULT_MARGIN
146             }
147             Line {
148                 width: root.width-2*Const.TEXT_MARGIN
149             }
150             Text {
151                 font.pixelSize: 30
152                 color: "white"
153                 text: qsTr("Used:")
154             }
155             Text {
156                 id: used
157                 font.pixelSize: 30
158                 color: "black"
159                 wrapMode: Text.Wrap
160                 width: root.width - 6*Const.DEFAULT_MARGIN
161             }
162             Spacer{}
163         }
164     }
165
166     TaskMenu {
167         z: 200
168         id: taskMenu
169         menuHeight: menuFixed.height+4*Const.DEFAULT_MARGIN
170
171         menuDynamic: _menuDyn
172         Flow {
173             y: root.height-taskMenu.menuHeight-Const.SYSTEM_BAR_HEIGHT+1*Const.DEFAULT_MARGIN
174             id: _menuDyn
175         }
176     }
177 }