# Copyright (c) 2001,2002 Mike Baker (mbm@linux.com) if {$::version > 3} {continue} #return any key that seems to be a menu #I'd love to use arrays here but they'd alpha sort proc findmenus { path tree } { set ret "" if { $path != "" } { set newpath "$path." } else { set newpath "" } while {[llength $tree] > 0} { set item [lindex $tree 0] if { $item != "fromContext"} { if { $item == "nItem"} { return $path } set newtree [lindex $tree 1] set newret [findmenus "$newpath$item" $newtree] if { $newret != ""} { if {[regexp -nocase image $newret] != 1 && $newret != "context.pExplicitListM"} { lappend ret $newret } elseif { $::screen_images ==0} { set ret "$newret $ret" } } } set tree [lrange $tree 2 end] } return $ret } proc GetVal { path } { global mwStateG set path [split $path "."] set ret $mwStateG while {[llength $path] > 0} { array set tree $ret if {[catch {set ret $tree([lindex $path 0])}]} { return } set path [lrange $path 1 end] } return $ret } proc dumpmenu { chan menus } { if {$menus == ""} return set i 0 set rows 0 foreach column $menus { array set column$i "[GetVal $column]" eval set tmp \$column$i\(nItem) if {$tmp > $rows} { set rows $tmp } incr i } set columns $i set current $column0(iCurrent) set tmp [GetVal dialog.arrow.iSelected] if {$tmp != ""} { set current $tmp } set top 0 set tmp [GetVal context.iTopChoiceM] if {$tmp != ""} { set top $tmp } set tmp [GetVal dialog.arrow.iSelected] if {$tmp != ""} { set current $tmp } if {$current < $top} { set current $top } if { [lindex $menus end] == "context.pSystemValuesM" } { set link 0 } else { set link 1 } puts $chan "" for {set row $top} {$row < $rows} {incr row} { set move [expr $row - $current] puts $chan "" for {set column 0} {$column < $columns} {incr column} { catch {eval "array set col \$column$column\($row)"} if {[info exists col(string)] && $col(string) != ""} { regsub -all "<\[0-9\]+>" $col(string) " " col(string) if { $link } { puts $chan "" } else { puts $chan "" } } else { puts $chan "" } catch {unset col} } puts $chan "" } puts $chan "
[html_link "/screen/?move=$move" $col(string)]$col(string) 
" } proc do_move {move} { global mwStateG set f [open /tmp/mwstate r] set mwStateG [read $f] close $f set iTop -999 set nVisible 999 set iBottom 999 set iCurrent 0 set target [expr $iCurrent + $move] set nItemMax 1000 set try {context.pListCtrlM context.pTextListCtrlM context.pRightCtrlM context.pGuideM.pList1CtrlM context.pTitleListCtrlM context.pWeekdayListM} foreach item $try { if { [GetVal $item.fPage] == "true"} { set iTop [GetVal $item.iTop] set nItemMax [GetVal $item.nItemMax] set nVisible [GetVal $item.nVisible] if { $nItemMax < $nVisible } { set nVisible $nItemMax } set iBottom [expr $iTop + $nVisible - 1] set iCurrent [GetVal $item.iCurrent] set target [expr $iCurrent + $move] break; } } while { $iCurrent != $target} { # figure out what happens on a page up if { $target < $iCurrent } { if { $iCurrent != $iTop } { set nCurrent $iTop set nBottom $nCurrent set nTop [expr $nBottom - $nVisible + 1] } else { set nBottom $iCurrent set nTop [expr $nBottom - $nVisible + 1] set nCurrent $nTop } if { $nTop < 0 } { set nTop 0 set nBottom [expr $nTop + $nVisible - 1] if { $nCurrent != $nTop } { set nCurrent $nBottom } } #if it's closer then do it, even if we end up overshooting the target if { abs($nCurrent - $target) < ($iCurrent - $target)} { SendKeyAndWait surfup set iTop $nTop set iBottom $nBottom set iCurrent $nCurrent } else { SendKeyAndWait up incr iCurrent -1 } } else { ;# $target > $iCurrent # figure out what happens on a page down if { $iCurrent != $iBottom } { set nCurrent $iBottom set nTop $nCurrent set nBottom [expr $nTop + $nVisible - 1] } else { set nTop $iCurrent set nBottom [expr $nTop + $nVisible - 1] set nCurrent $nBottom } if { $nBottom >= $nItemMax } { set nBottom [expr $nItemMax - 1] set nTop [expr $nBottom - $nVisible + 1] if { $nCurrent != $nBottom } { set nCurrent $nTop } } #if it's closer then do it, even if we end up overshooting the target if { abs($target - $nCurrent) < ($target - $iCurrent) } { SendKeyAndWait surfdown set iTop $nTop set iBottom $nBottom set iCurrent $nCurrent } else { SendKeyAndWait down incr iCurrent 1 } } } SendKeyAndWait select } proc action_screen {chan path env} { global mwStateG set move "none" if {![info exists evrc(tivo)]} { global evrc evmw eventSerialNumberG verboseSendKeyG source $::tcl_library/tv/sendkey.tcl # disable keyname echoing to controling tty set ::verboseSendKeyG 0 } eval $env if {$move == "back"} { SendKeyAndWait left } elseif {$move == "tivo"} { SendKeyAndWait tivo } elseif {$move != "none"} { do_move $move } set mtime [file mtime "/tmp/mwstate"] SendKeyAndWait dumpState set i 0; while {[file mtime "/tmp/mwstate"] == $mtime && $i < 50000} { incr i; after 100; update } after 100 ;# wait for pending writes set f [open /tmp/mwstate r] set mwStateG [read $f] regsub -all "\"" $mwStateG "\\\"" mwStateG close $f puts $chan [html_start "Screen Monitor"] if { [GetVal dialog] != "" } { puts $chan "

[GetVal dialog.header.pTextM]

" set val [GetVal dialog.desc.pTextM] regsub -all "<\[0-9\]+>" $val " " val puts $chan "
$val

" } else { set try {context.title context.pTitleTextCtrlM.pTextM context.pTextCtrlM.pTextM context.pBannerWidgetM.title context.pTitleTextM.pTextM context.pPageTitleCtrlM.pTextM } puts $chan "

" foreach item $try { set val [GetVal $item] if { $val != "" } { puts $chan $val break; } } puts $chan "

" set title [GetVal context.pPrognameTextM.pTextM] if { $title != "" } { puts $chan "

$title

" } set instr "[GetVal context.pInstructionsCtrlM.pTextM][GetVal context.pDetailsTextM.pTextM]" if { $instr != "" } { regsub -all "\n" $instr "
" instr regsub -all "\xc2\x8f" $instr "*" instr regsub -all "\xc2\x90" $instr " 1\/2" instr puts $chan "
$instr

" } set left [GetVal context.pExtraLeftM.pTextM] set right [GetVal context.pExtraRightM.pTextM] if { $left != "" || $right != "" } { regsub -all "\n" $left "
" left regsub -all "\n" $right "
" right puts $chan "

" puts $chan "

$left
" puts $chan "
$right
" } } set menus [strim [findmenus "" $mwStateG]] #puts "MENUS: $menus" dumpmenu $chan [strim $menus] puts $chan [html_link "/screen/?move=tivo" "TiVo"] puts $chan [html_link "/screen/?move=back" "back"] puts $chan [html_link "/screen" "refresh"] puts $chan [html_end] set mwStateG "" } set f [open "/tmp/mwstate" "w"] close $f if {![info exists ::screen_images]} { set ::screen_images 0 } set p_event 0 set evtnum 0 set mwStateG "" register_module "screen" "Screen" "View and control your TiVo's screen"