Plugin

This plugin shows last two changes of status in user_popup_info and last 10 lines of log when open chat window:

Sorry my tcl isn't good (my english too :P). Maybe someone can rewrite this plugin to more pretty version.

# Wersja: $Id: tkszary.tcl,v 1.8 2005/12/05 18:57:16 szary Exp $
#
# Plugin do tkabbera
# Funkcje ktore dzieki niemu uzyskamy:
# - 10 ostatnich linijek rozmowy przy nowootwartych oknach
# - W dymku przy kontakcie widac jego ostatnie 2 statusy i czasy po ktorych nastapily zmiany 

if {![info exists ::szary] || $::szary == ""} {return}

namespace eval ::szary {
	array set statusy {}

}

# User name (/home/$user/.tkabber/logs/) 
set user "szary"

# To taka prymitywna funkcja zapisujaca text do pliku
# przydatna do sprawdzania zawartosci zmiennych
proc ::szary::debager {text} {
	set plik [open "/tmp/tk.dbg" a]
	puts $plik $text
	close $plik

}

# Change info about last statuses
proc ::szary::presence_notify {connid from type x opts} {
	variable statusy
	set jid [node_and_server_from_jid $from]
	set status ""
    	set show ""
    	foreach {attr val} $opts {
	    	switch -- $attr {
			-status   {set status $val}
	    		-show     {set show   $val}
		}
    	}

	if {[catch { set tmp $statusy($jid,status) }]} {
	    	set statusy($jid,status) ""
    	}

    	if {[catch { set tmp $statusy($jid,oldstatus) }]} {
		set statusy($jid,oldstatus) ""
    	}
    	if {[catch { set tmp $statusy($jid,old2status) }]} {
		set statusy($jid,old2status) ""
	}

	catch {set statusy($jid,olddata) $statusy($jid,data)}
	set statusy($jid,data)  [clock seconds]
	set statusy($jid,old2status) $statusy($jid,oldstatus)
	set statusy($jid,oldstatus) $statusy($jid,status)	
	set nowystatus "$type $status"
	set statusy($jid,status) "$nowystatus"

}

# Show last statuses
proc ::szary::add_user_popup_info {infovar connid jid} {
	variable statusy
	upvar 0 $infovar info
	set jid [node_and_server_from_jid $jid]
        if {[catch { set tmp $statusy($jid,status) }]} {
		set statusy($jid,status) ""
	}
	if {[catch { set tmp $statusy($jid,oldstatus) }]} {
		set statusy($jid,oldstatus) ""
	}
	if {[catch { set tmp $statusy($jid,old2status) }]} {
		set statusy($jid,old2status) ""
	}

    
	if {[catch { set wartosc [expr [clock seconds] - $statusy($jid,data) ] }] } {
		set roznica "0"
	} else {
		set roznica [clock format $wartosc -format "%T" -gmt "-1"]
	}
	catch {append info  [format "\n\tOstatnia zmiana statusu: %s (%s)" [clock format $statusy($jid,data) 
					-format "%Y-%m-%d %T" -gmt false] $roznica]}

	if { "$statusy($jid,oldstatus)" != ""  && "$statusy($jid,oldstatus)" != "$statusy($jid,status)"} {
		catch {append info  [format "\n\tOstatni status: %s" $statusy($jid,oldstatus)]}
		catch {append info [format "\n\t\tpo: %s " [clock format [expr $statusy($jid,data) 
				- $statusy($jid,olddata) ] -format "%T" -gmt "-1"]  ] }
		if {"$statusy($jid,old2status)"!= ""} {
			append info " z $statusy($jid,old2status)"
		}
	} 
}

# Show last 10 lines of log in chat window
proc ::szary::open_chat {chatid type} {
	global user
	set jid [node_and_server_from_jid $chatid]
	regsub -all {[@/|*+?]} [lindex $jid 1] _ nazwapliku
	set ilosc 0
	set linii 0
	set iw [chat::chat_win $chatid]
	set plik_t [open "|grep timestamp /home/$user/.tkabber/logs/$nazwapliku | tail -n 10 | head -n 1 | cut -c 11-25" r]
	set linia_t [gets $plik_t]
	close $plik_t
	set plik [open "|grep -A500 $linia_t /home/$user/.tkabber/logs/$nazwapliku" r]
	set mynick ""
	set l ""
	fconfigure $plik -encoding utf-8
	set tresc [read $plik]
	close $plik
	foreach vars $tresc {
		array unset tmp
		array set tmp $vars
		set l ""
		if {[info exist tmp(timestamp)]} {
			set seconds [clock scan $tmp(timestamp) -gmt 0]
			append l [clock format $seconds -format {[%Y-%m-%d %X]}]
		}
		if {[info exists tmp(nick)] && $tmp(nick) != ""} {
			if {[string equal $tmp(nick) $mynick]} {
				set tag me
			} else {
				set tag they
			}
			if {[info exists tmp(body)] && [regsub {^/me } $tmp(body) {} body]} {
				append l "*$tmp(nick) $body" 
				unset tmp(body)
			} else {
				append l "<$tmp(nick)>" 
			}
			set servertag ""
		} else {
			append l "---" server_lab
			set servertag server
		}
		if {[info exists tmp(body)]} {
			append l " $tmp(body)" $servertag
		}
		chat::add_message $chatid "alamakota" error "$l"  {}
	}





}


# Wywolania funkcji
hook::add roster_user_popup_info_hook ::szary::add_user_popup_info 80
hook::add open_chat_post_hook ::szary::open_chat 80
hook::add client_presence_hook ::szary::presence_notify 100
Syndicate content