-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvlc-control.qml
217 lines (180 loc) · 4.94 KB
/
vlc-control.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
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
import QtQuick 2.4
import Ubuntu.Components 1.2
import U1db 1.0 as U1db
import "view"
import "view/control"
/*!
\brief MainView with a Label and Button elements.
*/
MainView {
// objectName for functional testing purposes (autopilot-qt5)
objectName: "com.ubuntu.developer.jdorleans.vlc-control"
// Note! applicationName needs to match the "name" field of the click manifest
applicationName: "com.ubuntu.developer.jdorleans.vlc-control"
/*
This property enables the application to change orientation
when the device is rotated. The default is false.
*/
//automaticOrientation: true
// Removes the old toolbar and enables new features of the new header.
//useDeprecatedToolbar: false
id: main
width: units.gu(46)
height: units.gu(78)
backgroundColor: "#333"
property string protocol: "http"
property string host: "192.168.0.1" // default ip
property int port: 8080
property string password: ""
property string baseUrl: ""
property string requestUrl: ""
property string statusUrl: ""
property var currentState: null
property string cmdPlay: "pl_play"
property string cmdPause: "pl_pause"
property string cmdStop: "pl_stop"
property string cmdNext: "pl_next"
property string cmdPrev: "pl_previous"
property string cmdDelete: "pl_delete&id="
property string cmdEmpty: "pl_empty"
property string cmdSeek: "seek&val="
property string cmdVolume: "volume&val="
property string cmdPlayInput: "in_play&input="
Component.onCompleted: {
loadConnectionData();
createBaseUrl();
updateTimer.running = true;
connection.connect(host, port);
}
onHostChanged: createBaseUrl();
onPortChanged: createBaseUrl();
U1db.Database {
id: db;
path: "vlc-control.u1db"
}
U1db.Document {
id: dbConnection
database: db
docId: "connection"
create: true
}
Timer {
id: updateTimer
interval: 1000
repeat: true
onTriggered: updateStatus()
}
// NetworkFinder { id: networkFinder }
Tabs {
Tab {
title: i18n.tr("Control")
anchors.fill: parent
page: Control { id: control }
}
Tab {
title: i18n.tr("Playlist")
anchors.fill: parent
page: Playlist { id: playlist }
}
Tab {
title: i18n.tr("Browser")
anchors.fill: parent
page: Browser { id: browser }
}
Tab {
title: i18n.tr("Connection")
anchors.fill: parent
page: Connection { id: connection }
}
Tab {
title: i18n.tr("About")
anchors.fill: parent
page: About { id: about }
}
}
function loadConnectionData()
{
if (dbConnection.contents)
{
if (dbConnection.contents.host) {
host = dbConnection.contents.host;
}
if (dbConnection.contents.port) {
port = dbConnection.contents.port;
}
if (dbConnection.contents.password) {
password = dbConnection.contents.password;
}
}
}
function createBaseUrl() {
baseUrl = protocol +"://"+ host +":"+ port +"/";
createRequestUrl();
return baseUrl;
}
function createRequestUrl() {
requestUrl = baseUrl +"requests/";
createStatusUrl();
return requestUrl;
}
function createStatusUrl() {
statusUrl = requestUrl +"status.json";
updateStatus();
return statusUrl;
}
function request(url)
{
//console.log("Main - Request: "+ url);
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) {
currentState = JSON.parse(xhr.responseText);
}
}
xhr.open("GET", url, true, '', password);
xhr.send();
}
function execute(command) {
updateTimer.stop();
request(statusUrl +"?command="+ command);
updateTimer.restart();
}
function updateStatus() {
request(statusUrl);
}
function play(id)
{
if (id) {
execute(cmdPlay +"&id="+ id);
} else {
execute(cmdPlay);
}
}
function pause() {
execute(cmdPause);
}
function stop() {
execute(cmdStop);
}
function next() {
execute(cmdNext);
}
function previous() {
execute(cmdPrev);
}
function remove(id) {
execute(cmdDelete+id);
}
function empty() {
execute(cmdEmpty);
}
function seek(val) {
execute(cmdSeek+val);
}
function volume(val) {
execute(cmdVolume+val);
}
function playInput(url) {
execute(cmdPlayInput + url);
}
}