webif/webif/lib/browse.class

186 lines
4.0 KiB
Tcl

require system.class plugin
if {![exists -command class]} { package require oo }
class dir {}
class browse {}
proc _addicon {img {hover ""} {class va}} {
set icon "<img src=$img class=\"$class\" height=21"
if {$hover ne ""} {
append icon " alt=\"$hover\" title=\"$hover\""
}
append icon ">"
return $icon
}
proc {dir expiry} {dir {data {}}} {
if {[llength $data] > 1} {
set fd [open "$dir/.autoexpire" w]
puts $fd "$data(days):$data(type):$data(keep):$data(keepnew):"
$fd close
return {}
}
set ret { days "" type 0 keep "" keepnew 0 }
catch {
set fd [open "$dir/.autoexpire"]
lassign [split [string trim [read $fd]] ":"] \
ret(days) ret(type) ret(keep) ret(keepnew)
$fd close
} msg
return $ret
}
proc {dir iconset} {dir} {
set icons {}
set attrs {}
set autoshrinkr 0
if {[file exists "$dir/.autoshrinkR"]} {
set autoshrinkr 1
lappend icons [_addicon "/img/compressr.png" \
"Recursive Auto-shrink"]
lappend attrs "autoshrinkR=1"
}
set autoshrink 0
if {!$autoshrinkr && [file exists "$dir/.autoshrink"]} {
set autoshrink 1
lappend icons [_addicon "/img/compress.png" "Auto-shrink"]
lappend attrs "autoshrink=1"
}
set autodedup 0
if {[file exists "$dir/.autodedup"]} {
set autodedup 1
lappend icons [_addicon "/img/dedup.png" "Auto-dedup"]
lappend attrs "autodedup=1"
}
set autodecryptr 0
if {[file exists "$dir/.autodecryptR"]} {
set autodecryptr 1
lappend icons [_addicon "/img/decryptr.png" \
"Recursive Auto-decrypt"]
lappend attrs "autodecryptR=1"
}
set autodecrypt 0
if {!$autodecryptr && [file exists "$dir/.autodecrypt"]} {
set autodecrypt 1
lappend icons [_addicon "/img/decrypt.png" "Auto-decrypt"]
lappend attrs "autodecrypt=1"
}
set autompg 0
if {[file exists "$dir/.autompg"]} {
set autompg 1
lappend icons [_addicon "/img/mpg.png" "Auto-MPG Extract"]
lappend attrs "autompg=1"
}
set automp3 0
if {[file exists "$dir/.automp3"]} {
set automp3 1
lappend icons [_addicon "/img/mp3.png" "Auto-Audio Extract"]
lappend attrs "automp3=1"
}
set autoexpire 0
if {[file exists "$dir/.autoexpire"]} {
set autoexpire 1
lappend icons [_addicon "/img/clock.png" "Auto-Expire"]
lappend attrs "autoexpire=1"
}
set tvdb 0
if {[file exists "$dir/.tvdbseriesid"]} {
set tvdb 1
lappend icons [_addicon "/img/tvdb-sm.png" "TheTVDB"]
lappend attrs "tvdb=1"
}
eval_plugins diriconset
return [list $icons $attrs]
}
proc {ts iconset} {ts} {
set icons {}
set attrs {}
# HD / SD
if {[$ts flag Radio]} {
lappend icons [_addicon "/img/radio.png" "Radio Programme"]
} else {
if {[$ts get definition] eq "HD"} {
set def HD
set img "172_1_00_HD"
} else {
set def SD
set img "172_1_26_SD"
}
lappend icons [_addicon "/images/$img.png"]
lappend attrs "def=$def"
}
# Locked
set locked 0
if {[$ts flag "Locked"] > 0} {
set locked 1
lappend icons [_addicon "/images/178_1_00_Icon_Lock.png" \
"Locked"]
}
lappend attrs "locked=$locked"
# Encrypted
set encd 0
if {[$ts flag "Encrypted"] > 0} {
set encd 1
lappend icons [_addicon "/images/749_1_26_Video_Encryption.png"\
""]
}
lappend attrs "encd=$encd"
# Encrypted on disk
set odencd 1
if {![$ts flag "ODEncrypted"]} {
set odencd 0
lappend icons [_addicon "/img/Decrypted.png" "Decrypted"]
}
lappend attrs "odencd=$odencd"
# Guidance
if {[$ts flag "Guidance"] > 0} {
lappend icons [_addicon "/img/Guidance_purple.png"]
}
if {[$ts flag "GGuidance"] > 0} {
lappend icons [_addicon "/img/Guidance_blue.png"]
}
# Shrunk
set shrunk 0
if {[$ts flag Shrunk]} {
set shrunk 1
lappend icons [_addicon "/img/compress.png" "Shrunk"]
}
lappend attrs "shrunk=$shrunk"
lappend attrs "bx=[$ts get bookmarks]"
eval_plugins tsiconset
return [list $icons $attrs]
}
# Breadcrumb path
proc {browse breadcrumb} {dir} {
set stub ""
foreach part [split $dir /] {
if {$stub eq "/"} { set name $part } else { set name "/$part" }
append stub $name
puts "<a class=breadcrumb href=\"/go/browse?dir=[cgi_quote_url $stub]\">$name</a>"
}
}