2023-10-03 16:11:25 +00:00
|
|
|
import "pkg:/source/utils/misc.bs"
|
|
|
|
import "pkg:/source/utils/config.bs"
|
2023-05-03 21:21:04 +00:00
|
|
|
|
2022-02-06 15:37:02 +00:00
|
|
|
sub init()
|
2022-11-19 14:29:57 +00:00
|
|
|
m.top.optionsAvailable = true
|
2022-02-13 20:53:30 +00:00
|
|
|
m.top.overhangVisible = false
|
2022-11-19 14:29:57 +00:00
|
|
|
m.slideshowTimer = m.top.findNode("slideshowTimer")
|
|
|
|
m.slideshowTimer.observeField("fire", "nextSlide")
|
|
|
|
m.status = m.top.findNode("status")
|
|
|
|
m.textBackground = m.top.findNode("background")
|
|
|
|
m.statusTimer = m.top.findNode("statusTimer")
|
|
|
|
m.statusTimer.observeField("fire", "statusUpdate")
|
2023-06-01 12:43:27 +00:00
|
|
|
m.slideshow = m.global.session.user.settings["photos.slideshow"]
|
|
|
|
m.random = m.global.session.user.settings["photos.random"]
|
2022-11-19 20:39:45 +00:00
|
|
|
|
|
|
|
m.showStatusAnimation = m.top.findNode("showStatusAnimation")
|
|
|
|
m.hideStatusAnimation = m.top.findNode("hideStatusAnimation")
|
|
|
|
|
2022-11-19 05:57:40 +00:00
|
|
|
itemContentChanged()
|
2022-02-06 15:37:02 +00:00
|
|
|
end sub
|
|
|
|
|
|
|
|
sub itemContentChanged()
|
2022-11-19 05:57:40 +00:00
|
|
|
if isValidToContinue(m.top.itemIndex)
|
|
|
|
m.LoadLibrariesTask = createObject("roSGNode", "LoadPhotoTask")
|
2023-11-13 14:16:00 +00:00
|
|
|
if isValid(m.top.itemsNode)
|
|
|
|
if isValid(m.top.itemsNode.content)
|
|
|
|
m.LoadLibrariesTask.itemNodeContent = m.top.itemsNode.content.getChild(m.top.itemIndex)
|
|
|
|
else if isValidAndNotEmpty(m.top.itemsNode.id)
|
|
|
|
m.LoadLibrariesTask.itemNodeContent = m.top.itemsNode
|
|
|
|
end if
|
|
|
|
else if isValid(m.top.itemsArray)
|
|
|
|
itemContent = m.top.itemsArray[m.top.itemIndex]
|
|
|
|
m.LoadLibrariesTask.itemArrayContent = itemContent
|
|
|
|
else
|
|
|
|
return
|
|
|
|
end if
|
|
|
|
|
2022-11-19 05:57:40 +00:00
|
|
|
m.LoadLibrariesTask.observeField("results", "onPhotoLoaded")
|
|
|
|
m.LoadLibrariesTask.control = "RUN"
|
|
|
|
end if
|
2022-02-06 15:37:02 +00:00
|
|
|
end sub
|
|
|
|
|
|
|
|
sub onPhotoLoaded()
|
2023-11-22 22:08:37 +00:00
|
|
|
stopLoadingSpinner()
|
2022-02-06 15:37:02 +00:00
|
|
|
if m.LoadLibrariesTask.results <> invalid
|
|
|
|
photo = m.top.findNode("photo")
|
|
|
|
photo.uri = m.LoadLibrariesTask.results
|
2022-11-19 14:29:57 +00:00
|
|
|
|
2023-06-24 14:16:27 +00:00
|
|
|
if m.slideshow = true or m.random = true
|
2022-12-02 13:26:47 +00:00
|
|
|
' user has requested either a slideshow or random...
|
2022-11-19 14:29:57 +00:00
|
|
|
m.slideshowTimer.control = "start"
|
|
|
|
end if
|
2022-02-06 15:37:02 +00:00
|
|
|
else
|
|
|
|
'Show user error here (for example if it's not a supported image type)
|
2022-02-06 17:12:32 +00:00
|
|
|
message_dialog("This image type is not supported.")
|
2022-02-06 15:37:02 +00:00
|
|
|
end if
|
|
|
|
end sub
|
2022-11-19 05:57:40 +00:00
|
|
|
|
2022-11-19 14:29:57 +00:00
|
|
|
sub nextSlide()
|
|
|
|
m.slideshowTimer.control = "stop"
|
2022-11-19 20:17:35 +00:00
|
|
|
|
2023-06-24 14:16:27 +00:00
|
|
|
if m.slideshow = true
|
2022-11-19 20:17:35 +00:00
|
|
|
if isValidToContinue(m.top.itemIndex + 1)
|
|
|
|
m.top.itemIndex++
|
|
|
|
m.slideshowTimer.control = "start"
|
|
|
|
end if
|
2023-06-24 14:16:27 +00:00
|
|
|
else if m.random = true
|
2023-11-13 14:16:00 +00:00
|
|
|
index = invalid
|
|
|
|
|
|
|
|
if isValid(m.top.itemsNode)
|
|
|
|
if isValidAndNotEmpty(m.top.itemsNode.content)
|
|
|
|
index = rnd(m.top.itemsNode.content.getChildCount() - 1)
|
2023-11-14 21:45:07 +00:00
|
|
|
else
|
|
|
|
' we're dealing with a single photo
|
|
|
|
return
|
2023-11-13 14:16:00 +00:00
|
|
|
end if
|
|
|
|
else if isValid(m.top.itemsArray)
|
2023-11-14 21:45:07 +00:00
|
|
|
if m.top.itemsArray.count() > 0
|
2023-11-13 14:16:00 +00:00
|
|
|
index = rnd(m.top.itemsArray.count() - 1)
|
|
|
|
end if
|
|
|
|
end if
|
|
|
|
|
2023-11-14 21:45:07 +00:00
|
|
|
if isValid(index) and isValidToContinue(index)
|
2022-11-19 20:17:35 +00:00
|
|
|
m.top.itemIndex = index
|
|
|
|
m.slideshowTimer.control = "start"
|
|
|
|
end if
|
2022-11-19 14:29:57 +00:00
|
|
|
end if
|
|
|
|
end sub
|
|
|
|
|
|
|
|
sub statusUpdate()
|
|
|
|
m.statusTimer.control = "stop"
|
2022-11-19 20:39:45 +00:00
|
|
|
m.hideStatusAnimation.control = "start"
|
2022-11-19 14:29:57 +00:00
|
|
|
end sub
|
|
|
|
|
2023-11-13 22:57:01 +00:00
|
|
|
' JFScreen hook.
|
|
|
|
' Used to ensure tasks are stopped
|
|
|
|
sub OnScreenHidden()
|
|
|
|
m.slideshowTimer.control = "stop"
|
|
|
|
m.statusTimer.control = "stop"
|
|
|
|
end sub
|
|
|
|
|
2023-11-14 16:57:00 +00:00
|
|
|
' isSlideshow component field has changed
|
|
|
|
sub isSlideshowChanged()
|
|
|
|
m.slideshow = m.top.isSlideshow
|
|
|
|
end sub
|
|
|
|
|
2023-11-14 21:45:07 +00:00
|
|
|
' isRandom component field has changed
|
|
|
|
sub isRandomChanged()
|
|
|
|
m.random = m.top.isRandom
|
|
|
|
end sub
|
|
|
|
|
2022-11-19 05:57:40 +00:00
|
|
|
function onKeyEvent(key as string, press as boolean) as boolean
|
|
|
|
if not press then return false
|
|
|
|
|
|
|
|
if key = "right"
|
|
|
|
if isValidToContinue(m.top.itemIndex + 1)
|
2022-11-19 14:29:57 +00:00
|
|
|
m.slideshowTimer.control = "stop"
|
2022-11-19 05:57:40 +00:00
|
|
|
m.top.itemIndex++
|
|
|
|
end if
|
|
|
|
return true
|
|
|
|
end if
|
|
|
|
|
|
|
|
if key = "left"
|
|
|
|
if isValidToContinue(m.top.itemIndex - 1)
|
2022-11-19 14:29:57 +00:00
|
|
|
m.slideshowTimer.control = "stop"
|
2022-11-19 05:57:40 +00:00
|
|
|
m.top.itemIndex--
|
|
|
|
end if
|
|
|
|
return true
|
|
|
|
end if
|
|
|
|
|
2022-11-19 14:29:57 +00:00
|
|
|
if key = "play"
|
|
|
|
if m.slideshowTimer.control = "start"
|
|
|
|
' stop the slideshow if the user hits "pause"
|
|
|
|
m.slideshowTimer.control = "stop"
|
|
|
|
m.status.text = tr("Slideshow Paused")
|
2022-11-19 20:39:45 +00:00
|
|
|
if m.textBackground.opacity = 0
|
|
|
|
m.showStatusAnimation.control = "start"
|
|
|
|
end if
|
2022-11-19 14:29:57 +00:00
|
|
|
m.statusTimer.control = "start"
|
|
|
|
else
|
|
|
|
' start the slideshow if the user hits "play"
|
|
|
|
m.status.text = tr("Slideshow Resumed")
|
2022-11-19 20:39:45 +00:00
|
|
|
if m.textBackground.opacity = 0
|
|
|
|
m.showStatusAnimation.control = "start"
|
|
|
|
end if
|
2023-06-24 14:16:27 +00:00
|
|
|
m.slideshow = true
|
2022-11-19 14:29:57 +00:00
|
|
|
m.statusTimer.control = "start"
|
|
|
|
m.slideshowTimer.control = "start"
|
|
|
|
end if
|
|
|
|
return true
|
|
|
|
end if
|
|
|
|
|
|
|
|
if key = "options"
|
2022-12-02 13:26:47 +00:00
|
|
|
' Options (random etc) is done on itemGrid
|
2022-11-19 14:29:57 +00:00
|
|
|
return true
|
|
|
|
end if
|
|
|
|
|
2022-11-19 05:57:40 +00:00
|
|
|
return false
|
|
|
|
end function
|
|
|
|
|
|
|
|
function isValidToContinue(index as integer)
|
2023-11-13 14:16:00 +00:00
|
|
|
if isValid(m.top.itemsNode)
|
|
|
|
if isValidAndNotEmpty(m.top.itemsNode.content)
|
|
|
|
if index >= 0 and index < m.top.itemsNode.content.getChildCount()
|
|
|
|
return true
|
|
|
|
end if
|
|
|
|
else if isValidAndNotEmpty(m.top.itemsNode) and index = 0
|
|
|
|
return true
|
|
|
|
end if
|
|
|
|
else if isValidAndNotEmpty(m.top.itemsArray)
|
|
|
|
if index >= 0 and index < m.top.itemsArray.count()
|
2022-11-19 05:57:40 +00:00
|
|
|
return true
|
|
|
|
end if
|
|
|
|
end if
|
|
|
|
|
|
|
|
return false
|
|
|
|
end function
|