192 lines
4.7 KiB
Plaintext
Raw Normal View History

2019-01-29 22:19:27 -06:00
sub Main()
keepalive = CreateObject("roSGScreen")
keepalive.show()
2019-03-04 22:59:31 -06:00
' First thing to do is validate the ability to use the API
start_login:
if get_setting("server") = invalid then
print "Get server details"
ShowServerSelect()
end if
2019-01-29 22:19:27 -06:00
if get_setting("active_user") = invalid then
print "Get user login"
ShowSigninSelect()
end if
2019-03-02 16:03:11 -06:00
2019-03-04 22:59:31 -06:00
' Confirm the configured server and user work
m.user = AboutMe()
if m.user.id <> get_setting("active_user")
print "Login failed, restart flow"
goto start_login
2019-03-04 22:59:31 -06:00
end if
2019-03-04 22:59:31 -06:00
ShowLibrarySelect()
2019-01-29 22:19:27 -06:00
end sub
2019-02-10 14:47:24 -06:00
sub ShowServerSelect()
port = CreateObject("roMessagePort")
screen = CreateObject("roSGScreen")
screen.setMessagePort(port)
scene = screen.CreateScene("ConfigScene")
screen.show()
scene.findNode("prompt").text = "Connect to Serviette"
config = scene.findNode("configOptions")
items = [
{"field": "server", "label": "Host", "type": "string"},
{"field": "port", "label": "Port", "type": "string"}
]
config.callfunc("setData", items)
button = scene.findNode("submit")
button.observeField("buttonSelected", port)
server_hostname = config.content.getChild(0)
server_port = config.content.getChild(1)
while(true)
msg = wait(0, port)
if type(msg) = "roSGScreenEvent" and msg.isScreenClosed()
return
else if type(msg) = "roSGNodeEvent"
node = msg.getNode()
if node = "submit"
set_setting("server", server_hostname.value)
set_setting("port", server_port.value)
return
end if
end if
end while
end sub
sub ShowSignInSelect()
port = CreateObject("roMessagePort")
screen = CreateObject("roSGScreen")
screen.setMessagePort(port)
scene = screen.CreateScene("ConfigScene")
screen.show()
scene.findNode("prompt").text = "Sign In"
config = scene.findNode("configOptions")
items = [
{"field": "username", "label": "Username", "type": "string"},
{"field": "password", "label": "Password", "type": "password"}
]
config.callfunc("setData", items)
button = scene.findNode("submit")
button.observeField("buttonSelected", port)
config = scene.findNode("configOptions")
username = config.content.getChild(0)
password = config.content.getChild(1)
2019-03-04 22:59:31 -06:00
while(true)
msg = wait(0, port)
if type(msg) = "roSGScreenEvent" and msg.isScreenClosed()
2019-03-04 22:59:31 -06:00
return
else if type(msg) = "roSGNodeEvent"
node = msg.getNode()
if node = "submit"
get_token(username.value, password.value)
if get_setting("active_user") <> invalid
return
end if
print "Login attempt failed..."
end if
2019-03-04 22:59:31 -06:00
end if
end while
end sub
2019-01-30 22:56:15 -06:00
sub ShowLibrarySelect()
port = CreateObject("roMessagePort")
screen = CreateObject("roSGScreen")
screen.setMessagePort(port)
scene = screen.CreateScene("Library")
screen.show()
library = scene.findNode("LibrarySelect")
libs = LibraryList()
library.libList = libs
library.observeField("itemSelected", port)
while(true)
msg = wait(0, port)
if type(msg) = "roSGScreenEvent" and msg.isScreenClosed() then
exit while
else if itemSelectedQ(msg)
2019-03-04 22:59:31 -06:00
target = getMsgRowTarget(msg)
if target.libraryType = "movies"
ShowMovieOptions(target.libraryID)
else
print "Library type is not yet implemented"
2019-03-04 22:59:31 -06:00
end if
end if
end while
end sub
2019-03-04 22:59:31 -06:00
sub ShowMovieOptions(library_id)
port = CreateObject("roMessagePort")
screen = CreateObject("roSGScreen")
screen.setMessagePort(port)
scene = screen.CreateScene("Movies")
screen.show()
options = scene.findNode("MovieSelect")
options_list = ItemList(library_id)
options.movieData = options_list
options.observeField("itemSelected", port)
while true
msg = wait(0, port)
if type(msg) = "roSGScreenEvent" and msg.isScreenClosed() then
return
else if itemSelectedQ(msg)
2019-03-04 22:59:31 -06:00
target = getMsgRowTarget(msg)
showVideoPlayer(target.movieID)
end if
end while
end sub
sub showVideoPlayer(id)
port = CreateObject("roMessagePort")
screen = CreateObject("roSGScreen")
screen.setMessagePort(port)
2019-03-04 22:59:31 -06:00
scene = screen.CreateScene("Scene")
screen.show()
VideoPlayer(scene, id)
while true
msg = wait(0, port)
if type(msg) = "roSGScreenEvent" and msg.isScreenClosed() then
return
end if
end while
end sub
2019-03-04 22:59:31 -06:00
sub itemSelectedQ(msg) as boolean
' "Q" stands for "Question mark" since itemSelected? wasn't acceptable
' Probably needs a better name, but unique for now
return type(msg) = "roSGNodeEvent" and msg.getField() = "itemSelected"
end sub
sub getMsgRowTarget(msg) as object
node = msg.getRoSGNode()
coords = node.rowItemSelected
target = node.content.getChild(coords[0]).getChild(coords[1])
return target
2019-02-10 14:47:24 -06:00
end sub