forked from scakemyer/quasar
-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathxbmcgui.go
340 lines (289 loc) · 8.41 KB
/
xbmcgui.go
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
package xbmc
import (
"time"
)
// DialogProgress ...
type DialogProgress struct {
Host *XBMCHost
hWnd string
}
// DialogProgressBG ...
type DialogProgressBG struct {
Host *XBMCHost
hWnd string
}
// OverlayStatus ...
type OverlayStatus struct {
Host *XBMCHost
hWnd string
}
// DialogInsert ...
func (h *XBMCHost) DialogInsert() map[string]string {
var retVal map[string]string
h.executeJSONRPCEx("DialogInsert", &retVal, nil)
return retVal
}
// NewDialogProgress ...
func (h *XBMCHost) NewDialogProgress(title, line1, line2, line3 string) *DialogProgress {
retVal := ""
h.executeJSONRPCEx("DialogProgress_Create", &retVal, Args{title, line1, line2, line3})
if len(retVal) <= 0 {
return nil
}
return &DialogProgress{
Host: h,
hWnd: retVal,
}
}
// Update ...
func (dp *DialogProgress) Update(percent int, line1, line2, line3 string) {
retVal := -1
dp.Host.executeJSONRPCEx("DialogProgress_Update", &retVal, Args{dp.hWnd, percent, dp.Host.TranslateText(line1), dp.Host.TranslateText(line2), dp.Host.TranslateText(line3)})
}
// IsCanceled ...
func (dp *DialogProgress) IsCanceled() bool {
retVal := 0
dp.Host.executeJSONRPCEx("DialogProgress_IsCanceled", &retVal, Args{dp.hWnd})
return retVal != 0
}
// Close ...
func (dp *DialogProgress) Close() {
retVal := -1
dp.Host.executeJSONRPCEx("DialogProgress_Close", &retVal, Args{dp.hWnd})
}
// DialogProgressBGCleanup ...
func (h *XBMCHost) DialogProgressBGCleanup() {
retVal := -1
h.executeJSONRPCEx("DialogProgressBG_Cleanup", &retVal, Args{})
}
// NewDialogProgressBG ...
func (h *XBMCHost) NewDialogProgressBG(title, message string, translations ...string) *DialogProgressBG {
retVal := ""
h.executeJSONRPCEx("DialogProgressBG_Create", &retVal, Args{title, message, translations})
if len(retVal) <= 0 {
return nil
}
return &DialogProgressBG{
Host: h,
hWnd: retVal,
}
}
// Update ...
func (dp *DialogProgressBG) Update(percent int, heading string, message string) {
retVal := -1
dp.Host.executeJSONRPCEx("DialogProgressBG_Update", &retVal, Args{dp.hWnd, percent, dp.Host.TranslateText(heading), dp.Host.TranslateText(message)})
}
// IsFinished ...
func (dp *DialogProgressBG) IsFinished() bool {
retVal := 0
dp.Host.executeJSONRPCEx("DialogProgressBG_IsFinished", &retVal, Args{dp.hWnd})
return retVal != 0
}
// Close ...
func (dp *DialogProgressBG) Close() {
retVal := -1
dp.Host.executeJSONRPCEx("DialogProgressBG_Close", &retVal, Args{dp.hWnd})
}
// NewOverlayStatus ...
func (h *XBMCHost) NewOverlayStatus() *OverlayStatus {
retVal := ""
h.executeJSONRPCEx("OverlayStatus_Create", &retVal, Args{})
if len(retVal) <= 0 {
return nil
}
return &OverlayStatus{
Host: h,
hWnd: retVal,
}
}
// Update ...
func (ov *OverlayStatus) Update(percent int, line1, line2, line3 string) {
if ov == nil {
return
}
retVal := -1
ov.Host.executeJSONRPCEx("OverlayStatus_Update", &retVal, Args{ov.hWnd, percent, ov.Host.TranslateText(line1), ov.Host.TranslateText(line2), ov.Host.TranslateText(line3)})
}
// Show ...
func (ov *OverlayStatus) Show() {
if ov == nil {
return
}
retVal := -1
ov.Host.executeJSONRPCEx("OverlayStatus_Show", &retVal, Args{ov.hWnd})
}
// Hide ...
func (ov *OverlayStatus) Hide() {
if ov == nil {
return
}
retVal := -1
ov.Host.executeJSONRPCEx("OverlayStatus_Hide", &retVal, Args{ov.hWnd})
}
// Close ...
func (ov *OverlayStatus) Close() {
if ov == nil {
return
}
retVal := -1
ov.Host.executeJSONRPCEx("OverlayStatus_Close", &retVal, Args{ov.hWnd})
}
// Notify ...
func (h *XBMCHost) Notify(header string, message string, image string) {
var retVal string
h.executeJSONRPCEx("Notify", &retVal, Args{header, message, image})
}
// InfoLabels ...
func (h *XBMCHost) InfoLabels(labels ...string) map[string]string {
var retVal map[string]string
h.executeJSONRPC("XBMC.GetInfoLabels", &retVal, Args{labels})
return retVal
}
// InfoLabel ...
func (h *XBMCHost) InfoLabel(label string) string {
labels := h.InfoLabels(label)
return labels[label]
}
// GetWindowProperty ...
func (h *XBMCHost) GetWindowProperty(key string) string {
var retVal string
h.executeJSONRPCEx("GetWindowProperty", &retVal, Args{key})
return retVal
}
// SetWindowProperty ...
func (h *XBMCHost) SetWindowProperty(key string, value string) {
var retVal string
h.executeJSONRPCEx("SetWindowProperty", &retVal, Args{key, value})
}
// Keyboard ...
func (h *XBMCHost) Keyboard(args ...interface{}) string {
var retVal string
h.executeJSONRPCEx("Keyboard", &retVal, args)
return retVal
}
// Dialog ...
func (h *XBMCHost) Dialog(title string, message string) bool {
retVal := 0
h.executeJSONRPCEx("Dialog", &retVal, Args{title, message})
return retVal != 0
}
// DialogBrowseSingle ...
func (h *XBMCHost) DialogBrowseSingle(browseType int, title string, shares string, mask string, useThumbs bool, treatAsFolder bool, defaultt string) string {
retVal := ""
h.executeJSONRPCEx("Dialog_Browse_Single", &retVal, Args{browseType, title, shares, mask, useThumbs, treatAsFolder, defaultt})
return retVal
}
// DialogConfirmNonTimed is a regular Yes/No dialog, without time limitation applied.
func (h *XBMCHost) DialogConfirmNonTimed(title string, message string) bool {
retVal := 0
h.executeJSONRPCEx("Dialog_Confirm", &retVal, Args{title, message})
return retVal != 0
}
// DialogConfirm ...
func (h *XBMCHost) DialogConfirm(title string, message string) bool {
return h.dialogConfirmRunner(title, message, false)
}
// DialogConfirmFocused ...
func (h *XBMCHost) DialogConfirmFocused(title string, message string) bool {
return h.dialogConfirmRunner(title, message, true)
}
func (h *XBMCHost) dialogConfirmRunner(title, message string, focused bool) bool {
c1 := make(chan bool, 1)
go func() {
// Emulating left click to make "OK predefined"
if focused {
go func() {
time.Sleep(time.Millisecond * 200)
retVal := 0
h.executeJSONRPC("Input.Left", &retVal, nil)
}()
}
retVal := 0
h.executeJSONRPCEx("Dialog_Confirm_With_Timeout", &retVal, Args{title, message, focused, DialogAutoclose})
c1 <- retVal != 0
}()
select {
case res := <-c1:
return res
case <-time.After(time.Duration(DialogAutoclose) * time.Second):
h.CloseAllConfirmDialogs()
return focused
}
}
// DialogText ...
func (h *XBMCHost) DialogText(title string, text string) bool {
retVal := 0
h.executeJSONRPCEx("Dialog_Text", &retVal, Args{title, text})
return retVal != 0
}
// ListDialog ...
func (h *XBMCHost) ListDialog(title string, items ...string) int {
retVal := -1
h.executeJSONRPCEx("Dialog_Select", &retVal, Args{title, items})
return retVal
}
// ListDialogWithOptions adds autoclose and preselect to a dialog
func (h *XBMCHost) ListDialogWithOptions(autoclose, preselect int, title string, items ...string) int {
retVal := -1
h.executeJSONRPCEx("Dialog_Select_With_Options", &retVal, Args{title, items, autoclose, preselect})
return retVal
}
// ListDialogLarge ...
func (h *XBMCHost) ListDialogLarge(title string, subject string, items ...string) int {
retVal := -1
h.executeJSONRPCEx("Dialog_Select_Large", &retVal, Args{title, subject, items})
return retVal
}
// PlayerGetPlayingFile ...
func (h *XBMCHost) PlayerGetPlayingFile() string {
retVal := ""
h.executeJSONRPCEx("Player_GetPlayingFile", &retVal, nil)
return retVal
}
// PlayerIsPlaying ...
func (h *XBMCHost) PlayerIsPlaying() bool {
retVal := 0
h.executeJSONRPCEx("Player_IsPlaying", &retVal, nil)
return retVal != 0
}
// PlayerSeek ...
func (h *XBMCHost) PlayerSeek(position float64) (ret string) {
if position <= 0 {
return
}
h.executeJSONRPCEx("Player_Seek", &ret, Args{position})
return
}
// PlayerIsPaused ...
func (h *XBMCHost) PlayerIsPaused() bool {
retVal := 0
h.executeJSONRPCEx("Player_IsPaused", &retVal, nil)
return retVal != 0
}
// PlayerGetSubtitles ...
func (h *XBMCHost) PlayerGetSubtitles() (ret []string) {
h.executeJSONRPCEx("Player_GetSubtitles", &ret, nil)
return
}
// PlayerSetSubtitles ...
func (h *XBMCHost) PlayerSetSubtitles(urls []string) {
h.executeJSONRPCEx("Player_SetSubtitles", nil, Args{urls})
}
// GetWatchTimes ...
func (h *XBMCHost) GetWatchTimes() map[string]string {
var retVal map[string]string
h.executeJSONRPCEx("Player_WatchTimes", &retVal, nil)
return retVal
}
// CloseAllDialogs ...
func (h *XBMCHost) CloseAllDialogs() bool {
retVal := 0
h.executeJSONRPCEx("Dialog_CloseAll", &retVal, nil)
return retVal != 0
}
// CloseAllConfirmDialogs ...
func (h *XBMCHost) CloseAllConfirmDialogs() bool {
retVal := 0
h.executeJSONRPCEx("Dialog_CloseAllConfirms", &retVal, nil)
return retVal != 0
}