b5901b8cc02d87a20f18eedb1cc38bcabcc78542
[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
13     Component.onCompleted: init()
14
15     function init()
16     {
17         secrets = {
18             token: Utils.token(),
19             secret: Utils.tokenSecret(),
20             consumer_key : Utils.customerKey(),
21             consumer_secret: Utils.customerSecret()
22         };
23         mask.state = "busy";
24         U1.getAccount(secrets,root);
25     }
26
27     function onResp(secrets,account)
28     {
29         //console.log("onResp");
30         mask.state = "idle";
31
32         //uid.text = account.id;
33         username.text = account.username;
34         //nick.text = account.nickname;
35         email.text = account.email;
36         storage.text = Conv.bytesToSize(account.total_storage);
37
38         U1.getRootNode(secrets,root);
39     }
40
41     function onRespRootNode(resp)
42     {
43         //console.log("onResp");
44         mask.state = "idle";
45         var ubytes = Conv.bytesToSize(resp.used_bytes);
46         var uprec = Math.round((resp.used_bytes/resp.max_bytes)*100);
47         used.text = ubytes+" ("+uprec+"%)";
48     }
49
50     function onErr(status)
51     {
52         //console.log("onErr");
53         mask.state = "idle";
54         if(status==401) {
55             tip.show(qsTr("Authorization failed!"));
56         } else if(status==0) {
57             tip.show(qsTr("Unable to connect!"));
58         } else {
59             tip.show(qsTr("Error: ")+status);
60         }
61         pageStack.pop();
62     }
63
64     Flickable {
65         width: root.width
66         height: root.height
67         contentHeight: content.height+Const.SYSTEM_BAR_HEIGHT+Const.TEXT_MARGIN
68         y: Const.SYSTEM_BAR_HEIGHT+Const.TEXT_MARGIN
69
70         Column {
71             id: content
72             spacing: Const.DEFAULT_MARGIN
73             x: Const.TEXT_MARGIN
74
75             /*Text {
76                 font.pixelSize: 30
77                 color: "white"
78                 text: "Id:"
79             }
80             Text {
81                 id: uid
82                 font.pixelSize: 30
83                 color: "black"
84                 wrapMode: Text.Wrap
85                 width: root.width - 6*Const.DEFAULT_MARGIN
86             }*/
87             Text {
88                 font.pixelSize: 30
89                 color: "white"
90                 text: qsTr("User name:")
91             }
92             Text {
93                 id: username
94                 font.pixelSize: 30
95                 color: "black"
96                 wrapMode: Text.Wrap
97                 width: root.width - 6*Const.DEFAULT_MARGIN
98             }
99             Line {
100                 width: root.width-2*Const.TEXT_MARGIN
101             }
102             /*Text {
103                 font.pixelSize: 30
104                 color: "white"
105                 text: qsTr("Nickname:")
106             }
107             Text {
108                 id: nick
109                 font.pixelSize: 30
110                 color: "black"
111                 wrapMode: Text.Wrap
112                 width: root.width - 6*Const.DEFAULT_MARGIN
113             }*/
114             Text {
115                 font.pixelSize: 30
116                 color: "white"
117                 text: qsTr("Email:")
118             }
119             Text {
120                 id: email
121                 font.pixelSize: 30
122                 color: "black"
123                 wrapMode: Text.Wrap
124                 width: root.width - 6*Const.DEFAULT_MARGIN
125             }
126             Line {
127                 width: root.width-2*Const.TEXT_MARGIN
128             }
129             Text {
130                 font.pixelSize: 30
131                 color: "white"
132                 text: qsTr("Total storage:")
133             }
134             Text {
135                 id: storage
136                 font.pixelSize: 30
137                 color: "black"
138                 wrapMode: Text.Wrap
139                 width: root.width - 6*Const.DEFAULT_MARGIN
140             }
141             Line {
142                 width: root.width-2*Const.TEXT_MARGIN
143             }
144             Text {
145                 font.pixelSize: 30
146                 color: "white"
147                 text: qsTr("Used:")
148             }
149             Text {
150                 id: used
151                 font.pixelSize: 30
152                 color: "black"
153                 wrapMode: Text.Wrap
154                 width: root.width - 6*Const.DEFAULT_MARGIN
155             }
156             Spacer{}
157         }
158     }
159 }