jf-roku/components/config/SetServerScreen.brs

96 lines
3.0 KiB
Plaintext
Raw Normal View History

2021-07-09 10:12:19 +00:00
sub init()
m.top.setFocus(true)
m.top.optionsAvailable = false
m.spinner = m.top.findNode("spinner")
m.serverPicker = m.top.findNode("serverPicker")
2021-07-09 10:21:24 +00:00
m.serverUrlTextbox = m.top.findNode("serverUrlTextbox")
2021-07-09 10:12:19 +00:00
m.serverUrlContainer = m.top.findNode("serverUrlContainer")
m.serverUrlOutline = m.top.findNode("serverUrlOutline")
m.submit = m.top.findNode("submit")
m.serverPicker.setFocus(true)
ScanForServers()
end sub
function onKeyEvent(key as string, press as boolean) as boolean
print "onKeyEvent", key, press
if not press then return true
handled = true
2021-07-09 19:16:43 +00:00
if key = "OK" and m.serverPicker.hasFocus()
2021-07-09 10:21:24 +00:00
m.top.serverUrl = m.serverPicker.content.getChild(m.serverPicker.itemFocused).baseUrl
m.submit.setFocus(true)
'if the user pressed the down key and we are already at the last child of server picker, then change focus to the url textbox
else if key = "down" and m.serverPicker.hasFocus() and m.serverPicker.itemFocused = m.serverPicker.content.getChildCount() - 1
2021-07-09 10:12:19 +00:00
m.serverUrlContainer.setFocus(true)
'user navigating up to the server picker from the input box
2021-07-09 10:12:19 +00:00
else if key = "up" and m.serverUrlContainer.hasFocus()
m.serverPicker.animateToItem = m.serverPicker.content.getChildCount() - 1
2021-07-09 10:12:19 +00:00
m.serverPicker.setFocus(true)
else if key = "OK" and m.serverUrlContainer.hasFocus()
ShowKeyboard()
'focus the serverUrl input from submit button
else if key = "up" and m.submit.hasFocus()
m.serverUrlContainer.setFocus(true)
'focus the submit button from serverUrl
else if key = "down" and m.serverUrlContainer.hasFocus()
m.submit.setFocus(true)
else
handled = false
end if
'show/hide input box outline
m.serverUrlOutline.visible = m.serverUrlContainer.isInFocusChain()
return handled
end function
2021-07-09 19:16:43 +00:00
sub ScanForServers()
2021-07-09 10:12:19 +00:00
m.ssdpScanner = CreateObject("roSGNode", "SSDPTask")
'run the task
m.ssdpScanner.observeField("content", "ScanForServersComplete")
m.ssdpScanner.control = "RUN"
2021-07-09 19:16:43 +00:00
end sub
2021-07-09 10:12:19 +00:00
sub ScanForServersComplete(event)
servers = event.getData()
items = CreateObject("roSGNode", "ContentNode")
for each server in servers
server.subtype = "ContentNode"
2021-07-09 10:21:24 +00:00
'add new fields for every server property onto the ContentNode (rather than making a dedicated component just to hold data...)
2021-07-09 10:12:19 +00:00
items.update([server], true)
end for
m.serverPicker.content = items
m.spinner.visible = false
end sub
2021-07-09 19:16:43 +00:00
sub ShowKeyboard()
2021-07-09 10:12:19 +00:00
dialog = createObject("roSGNode", "KeyboardDialog")
dialog.title = "Enter the server name or ip address"
dialog.buttons = [tr("OK"), tr("Cancel")]
2021-07-09 10:21:24 +00:00
dialog.text = m.serverUrlTextbox.text
2021-07-09 10:12:19 +00:00
m.top.getscene().dialog = dialog
m.dialog = dialog
dialog.observeField("buttonSelected", "onDialogButton")
2021-07-09 19:16:43 +00:00
end sub
2021-07-09 10:12:19 +00:00
function onDialogButton()
d = m.dialog
button_text = d.buttons[d.buttonSelected]
if button_text = tr("OK")
2021-07-09 10:21:24 +00:00
m.serverUrlTextbox.text = d.text
2021-07-09 10:12:19 +00:00
m.dialog.close = true
return true
else if button_text = tr("Cancel")
m.dialog.close = true
return true
2021-07-09 19:16:43 +00:00
else
return false
2021-07-09 10:12:19 +00:00
end if
end function