755df06343c85f645a917c761706a5208cb85c69
[ubi] / qml / ubi / InitPage.qml
1 import QtQuick 1.0 // to target S60 5th Edition or Maemo 5
2 import "UIConstants.js" as Const
3 import "u1.js" as U1
4 import "components"
5
6 Rectangle {
7     id: root
8
9     color: Const.DEFAULT_BACKGROUND_COLOR
10     state: "opened"
11
12     function hide() {
13         root.state = "closed";
14     }
15
16     Component.onCompleted: init()
17
18     function init() {
19         if(Utils.isAuthorized()) {
20             //title = "Hi, "+Utils.name();
21             login();
22         } else {
23             pageStack.initialPage = "LoginPage.qml";
24             hide();
25         }
26     }
27
28     function login() {
29         var secrets = {
30             token: Utils.token(),
31             secret: Utils.tokenSecret(),
32             consumer_key : Utils.customerKey(),
33             consumer_secret: Utils.customerSecret()
34         };
35         U1.getRootNode(secrets,root);
36     }
37
38     function onRespRootNode(resp) {
39         hide();
40     }
41
42     function onErr(status) {
43         hide()
44         if(status==401) {
45             tip.show(qsTr("Authorization failed!"));
46         } else if(status==0) {
47             tip.show(qsTr("Unable to connect!"));
48         } else {
49             tip.show(qsTr("Error: ")+status);
50         }
51     }
52
53     Image {
54         id: pic
55         source: "images/ubi100.png"
56         width: 104; height: 70
57         anchors.horizontalCenter: parent.horizontalCenter
58         y: (root.height-height)/3
59     }
60
61     Text {
62         id: loading
63         anchors.top: pic.bottom
64         anchors.margins: Const.TEXT_MARGIN
65         anchors.horizontalCenter: parent.horizontalCenter
66         font.pixelSize: 25
67         color: "white"
68         text: "Loading..."
69     }
70
71     Image {
72         id: icon
73         width: 64
74         height: 64
75         anchors.top: loading.bottom
76         anchors.margins: 2*Const.TEXT_MARGIN
77         source: "images/progress.png"
78         sourceSize.width: width
79         sourceSize.height: height
80         anchors.horizontalCenter: parent.horizontalCenter
81         Component.onCompleted: animationIcon.start()
82
83         NumberAnimation {
84             id: animationIcon
85             target: icon
86             properties: "rotation"
87             from: 0
88             to: 360
89             duration: 500
90             loops: Animation.Infinite
91         }
92     }
93
94     Text {
95         anchors.bottom: root.bottom
96         anchors.bottomMargin: Const.TEXT_MARGIN
97         anchors.horizontalCenter: parent.horizontalCenter
98         font.pixelSize: 18
99         color: "white"
100         text: "ver. 0.9.2-2"
101     }
102
103     MouseArea {
104         anchors.fill: parent
105     }
106
107     states: [
108         State {
109             name: "opened"
110             //PropertyChanges { target: root; opacity: 1 }
111             PropertyChanges { target: root; y: 0}
112         },
113         State {
114             name: "closed"
115             //PropertyChanges { target: root; opacity: 0 }
116             PropertyChanges { target: root; y: root.height }
117         }
118     ]
119
120     transitions: Transition {
121         //NumberAnimation { properties: "opacity"; easing.type: Easing.InOutQuad }
122         NumberAnimation { properties: "y"; easing.type: Easing.InOutQuad }
123     }
124
125 }