# $Id$
namespace eval ::logger {
variable logdir ~/.tkabber-logs
if {![file exists $logdir]} {
file mkdir $logdir
}
}
proc ::logger::log_file {chatid} {
variable logdir
regsub -all @|/ $chatid _ filename
return ${logdir}/$filename
}
proc ::logger::log_message {chatid from type body x} {
if {$type == "chat" && [resource_from_jid $chatid] != ""} {
set chatid [node_and_server_from_jid $chatid]
}
set logfile [log_file $chatid]
set nick [chat::get_nick $from $type]
set fd [open $logfile a]
fconfigure $fd -encoding utf-8
puts $fd "<${nick}> $body"
close $fd
}
plugins::add_hook draw_message_hook ::logger::log_message 15
set menuhistidx [expr [.jidpopupmenu index "Edit groups"] + 1]
.jidpopupmenu insert $menuhistidx command -label "Show history" \
-command {logger::show_log $curuser}
proc ::logger::winid {name} {
regsub -all \\. $name | allowed_name
return .log_$allowed_name
}
proc ::logger::show_log {jid} {
global font
set logfile [log_file $jid]
if {[file exists $logfile]} {
set lw [winid $jid]
puts $lw
if {[winfo exists $lw]} {
focus -force $lw
return
}
Dialog $lw -title "Histroy for $jid" -modal none
$lw add -text OK -command [list destroy $lw]
set lf [$lw getframe]
text $lf.log -yscrollcommand [list $lf.scroll set] \
-font $font -wrap word
scrollbar $lf.scroll -command [list $lf.log yview]
pack $lf.scroll -side right -fill y -expand yes
pack $lf.log -side left -expand yes -fill both
set fd [open $logfile r]
fconfigure $fd -encoding utf-8
$lf.log insert 0.0 [read $fd]
close $fd
$lf.log configure -state disabled
$lw draw
} else {
}
}