forked from rh-lab-q/confla-android
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathData.qml
More file actions
186 lines (143 loc) · 6.24 KB
/
Data.qml
File metadata and controls
186 lines (143 loc) · 6.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
import QtQuick.LocalStorage 2.0 as Sql
import QtQuick 2.0
Item {
property string dbName: "confla"
property string dbVersion: "1.0"
property string dbDisplayName: "confla"
property int dbEstimatedSize: 10000;
property variant conferences;
property variant data;
property int lastUpdate: 0
property string status: "idle"
// property variant secondPage
function configSet(key, value) {
console.log("configSet(" +key + "," + value + ")")
var db = Sql.LocalStorage.openDatabaseSync(dbName, dbVersion, dbDisplayName, dbEstimatedSize);
db.transaction(
function(tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS Keys(key TEXT PRIMARY KEY, value TEXT)');
var rs = tx.executeSql('SELECT * FROM Keys WHERE key==?', [ key ]);
if (rs.rows.length === 0){
tx.executeSql('INSERT INTO Keys VALUES(?, ?)', [ key, value ]);
} else {
tx.executeSql('UPDATE Keys SET value=? WHERE key==?', [value, key]);
}
})
}
function configGet(key, default_value) {
var db = Sql.LocalStorage.openDatabaseSync(dbName, dbVersion, dbDisplayName, dbEstimatedSize);
var result = "";
db.transaction(
function(tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS Keys(key TEXT PRIMARY KEY, value TEXT)');
var rs = tx.executeSql('SELECT * FROM Keys WHERE key=?', [ key ]);
if (rs.rows.length === 1 && rs.rows.item(0).value.length > 0){
result = rs.rows.item(0).value
console.log("configGet(" +key + ", " + result + ", "+ default_value +")")
}
else {
result = default_value;
console.log("configGet(" +key + ", " + default_value +") (default)")
}
}
)
return result;
}
function init_data() {
read_cache();
check_updates();
}
function read_cache() {
conferences = JSON.parse(configGet("conferences", "{}"));
updateUI();
}
function check_updates() {
var url = "http://python-conflab.rhcloud.com/export/conference_list/?lang="+Qt.locale().name;
// var url = "http://pcmlich.fit.vutbr.cz/tmp/if.json"
// var url = "http://localhost:8000/export/conference_list/?lang="+Qt.locale().name;
var http = new XMLHttpRequest()
http.open("GET", url, true)
http.onreadystatechange = function(){
if (http.readyState == 4) {
if (http.status == 200) {
conferences = JSON.parse(http.responseText);
configSet("conferences", http.responseText)
updateUI();
}
}
}
http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
//http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");
// http.send(params)
http.send()
}
function init_conference(conf_data) {
data = JSON.parse(configGet(conf_data['url_id']+"/cache",'{}'));
updateUIConference(conf_data);
var cache_checksum = configGet(conf_data['url_id']+"/checksum", 'INVALID_CHECKSUM');
if (conf_data['checksum'] !== cache_checksum) {
console.error("init_conference " + conf_data['checksum'] + " -> " + cache_checksum)
download_conference(conf_data);
}
}
function download_conference(conf_data) {
var url = conf_data['url_json'] + "?json&lang="+Qt.locale().name;
var http = new XMLHttpRequest()
http.open("GET", url, true)
status = "updating"
http.onreadystatechange = function(){
if (http.readyState == 4) {
if (http.status == 200) {
if (conferenceDetailPage.url_id === conf_data['url_id'] ) { // update UI only when showing same page
data = JSON.parse(http.responseText);
status = "idle"
updateUIConference(conf_data);
}
configSet(conf_data['url_id']+"/cache", http.responseText)
if (data.checksum !== undefined) {
configSet(conf_data['url_id']+"/checksum", data.checksum)
}
} else { // offline or error while downloading
console.log("error downloading ")
status = "offline"
}
}
}
http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
//http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");
// http.send(params)
http.send()
}
function getFavorites(url_id) {
return JSON.parse(configGet(url_id+"/favorites", "[]"));
}
function setFavorites(url_id, _fav) {
configSet(url_id+"/favorites", JSON.stringify(_fav));
}
function updateUIConference(conf_data) {
conferenceDetailPage.name = conf_data['name'];
conferenceDetailPage.url_id = (conf_data['url_id'] !== undefined) ? conf_data['url_id'] : '';
conferenceDetailPage.feedback_url = (conf_data['url_feedback'] !== undefined) ? conf_data['url_feedback'] : '';
conferenceDetailPage.reload(data);
schedulePage.reloadFavorites(getFavorites(conf_data['url_id']));
schedulePage.reload(data)
mapPage.reload(data);
}
function updateUI() {
conferenceListPage.reload(conferences)
// coverPage.reload(data)
// coverPage.coundownTarget = data.days[0]
// secondPage.load(data.events);
}
function getSpeakerDetail(name) {
var usersArray = data.users
for (var i = 0; i < usersArray.length; i++) {
var user = usersArray[i];
if (user.name === name) {
return user;
}
}
}
}