# LJ's Utilities module. # # Based very heavily on other parts of TiVoWeb! # # LJ @ http://www.tivocommunity.com/ # # 29Dec02 11:48 v1.0 Slotfree module. # 30Dec02 17:30 v2.0 New search code; return icon with conflict details. # 30Dec02 22:38 v2.1 Show conflict.png instead of broken link for conflicts. # 30Dec02 23:20 v2.2 Shorter tooltips! # 31Dec02 13:26 v2.3 Show four different icons for conflicts. # 01Jan03 17:24 v2.4 Different icon for a free slot; ignore suggestions when deciding if a slot is free; remove alt text. proc slotfree {seconds duration chan} { global db global images global tzoffset set slotstartdate [expr $seconds / 86400] set slotstarttime [expr $seconds - ($slotstartdate * 86400)] set slotenddate [expr ($seconds + $duration) / 86400] set slotendtime [expr ($seconds + $duration) - ($slotenddate * 86400)] set foundearlierrec 0 set foundlaterrec 0 set slotfull 0 set reason "" set recs [mfs scan "/Recording/Active" -start "4:[expr $slotstartdate - 1]:" -count 2] scan [lindex [lindex $recs 1] 1] "%d:%d:%d:%d" dummy recstartdate recstarttime recfsid set lasttest [lindex [lindex $recs 0] 1] while { [expr ($recstartdate * 86400) + $recstarttime] < $seconds } { set recs [mfs scan "/Recording/Active" -start "[lindex [lindex $recs 1] 1]" -count 2] if { [llength $recs] < 2 } { break } scan [lindex [lindex $recs 1] 1] "%d:%d:%d:%d" dummy recstartdate recstarttime recfsid set lasttest [lindex [lindex $recs 0] 1] set foundearlierrec 1 } while { $lasttest != "" } { set recs [mfs scan "/Recording/Active" -start $lasttest -count 2] set lasttest [lindex [lindex $recs 1] 1] scan [lindex [lindex $recs 0] 1] "%d:%d:%d:%d" dummy recstartdate recstarttime recfsid if { $recstartdate > $slotenddate } { set foundlaterrec 1 break } if { ($recstartdate == $slotenddate) && ($recstarttime >= $slotendtime) } { set foundlaterrec 1 break } set rec [db $db openid $recfsid] set rectype [dbobj $rec get SelectionType] if { $rectype == 6 } { continue } set startpad [dbobj $rec get StartPadding] set endpad [dbobj $rec get EndPadding] set showing [dbobj $rec get Showing] set recdur [dbobj $showing get Duration] set recend [expr ($recstartdate * 86400) + $recstarttime + $startpad + $endpad + $recdur] set recenddate [expr $recend / 86400] set recendtime [expr $recend - ($recenddate * 86400)] if { $recenddate < $slotstartdate } { set foundearlierrec 1 continue } if { ($recenddate == $slotstartdate) && ($recendtime <= $slotstarttime) } { set foundearlierrec 1 continue } incr slotfull 1 set recstartsecs [expr ($recstartdate * 86400) + $recstarttime + $tzoffset] if {$::uktivo} { set starttimestr [clock format $recstartsecs -format "%H:%M"] } else { set starttimestr [clock format $recstartsecs -format "%l:%M %P"] } set recendsecs [expr $recend + $tzoffset] if {$::uktivo} { set endtimestr [clock format $recendsecs -format "%H:%M"] } else { set endtimestr [clock format $recendsecs -format "%l:%M %P"] } set station [dbobj $showing get Station] set recchannel [dbobj $station get CallSign] set program [dbobj $showing get Program] set recseries [dbobj $program get Title] set reason "$reason$starttimestr-$endtimestr $recchannel: $recseries. " } set reason [string trimright $reason] regsub -all {\{} $reason "" reason regsub -all {\}} $reason "" reason if { $slotfull > 0 } { return "[img "title=\"$slotfull scheduled: $reason\"" "conflict[expr {$slotfull > 4 ? "4" : "$slotfull"}].png"]" } else { if { ($foundlaterrec == 1) || ([llength $recs] != 2) } { return "[img "title=\"No recordings currently scheduled in this slot.\"" "slotfree.png"]" } else { return "[img "title=\"Slot may be free ;) Send LJ this error message: E$foundearlierrec$foundlaterrec:$recstartdate:$recstarttime:$slotenddate:$slotendtime\"" "slotfree.png"]" } } }