-
Notifications
You must be signed in to change notification settings - Fork 1
/
JsonSearch.qml
105 lines (88 loc) · 2.65 KB
/
JsonSearch.qml
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
import QtQuick 2.7
Rectangle {
height: 400
width: 600
ListView {
id: listview
anchors.fill: parent
model: model
delegate: Column {
id: delegate
width: delegate.ListView.view.width
spacing: 2
Text {
width: parent.width
font.bold: true
font.pixelSize: 18
wrapMode: Text.WordWrap
text: title;
}
Text {
text: "id: " + id;
}
Text {
text: "link: " + link;
}
Text {
text: "author: " + author;
}
Text {
text: "comments: " + comments;
}
Text {
text: "size: " + size;
}
Text {
text: "seeders: " + seeders;
}
Text {
text: "leechers: " + leechers;
}
Text {
text: "complete: " + complete;
}
}
}
ListModel {
id: model
}
function getData(request) {
var xmlhttp = new XMLHttpRequest();
request = getRequest(request);
var url = "https://toloka.to/api.php?search=" + request;
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState == XMLHttpRequest.DONE && xmlhttp.status == 200) {
updateModel(xmlhttp.responseText);
}
}
xmlhttp.open("GET", url, true);
xmlhttp.send();
}
function getRequest(request) {
var splittedRequest = request.split(" ");
var result = "";
result += splittedRequest[0];
for (var i = 1; i < splittedRequest.length; i++){
result += "+";
result += splittedRequest[i];
}
return result;
}
function updateModel(response) {
model.clear();
var arr = JSON.parse(response);
for(var i = 0; i < arr.length; i++) {
listview.model.append( {
id: arr[i].id,
link: arr[i].link,
title: arr[i].title,
author: arr[i].author,
comments: arr[i].comments,
size: arr[i].size,
seeders: arr[i].seeders,
leechers: arr[i].leechers,
complete: arr[i].complete
} );
}
}
}