[Tkabber-dev] r1574 - branches/dynamic-chats/tkabber

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Wed Oct 22 22:30:19 MSD 2008


Author: kostix
Date: 2008-10-22 22:30:19 +0400 (Wed, 22 Oct 2008)
New Revision: 1574

Modified:
   branches/dynamic-chats/tkabber/chats.tcl
Log:
tkabber/chats.tcl: First stab at the concept of chat IDs
 not statically bound to JIDs.


Modified: branches/dynamic-chats/tkabber/chats.tcl
===================================================================
--- branches/dynamic-chats/tkabber/chats.tcl	2008-10-22 17:48:16 UTC (rev 1573)
+++ branches/dynamic-chats/tkabber/chats.tcl	2008-10-22 18:30:19 UTC (rev 1574)
@@ -14,6 +14,7 @@
 
 namespace eval chat {
     set enrichid 0
+    set nchats 0
     custom::defgroup Chat [::msgcat::mc "Chat options."] -group Tkabber
     custom::defvar options(smart_scroll) 0 \
 	[::msgcat::mc "Enable chat window autoscroll only when last message is shown."] \
@@ -162,16 +163,43 @@
     expr {[info exists chat_id($winid)] ? $chat_id($winid) : ""}
 }
 
+proc chat::mkchatid {xlib jid} {
+    variable nchats
+    variable chats
+
+    set chatid chatid$nchats
+    incr nchats
+
+    set chats(jid,$chatid)  $jid
+    set chats(xlib,$chatid) $xlib
+    set chats(chatid,[list $xlib $jid]) $chatid
+
+    return $chatid
+}
+
+proc chat::forget_chatid {chatid} {
+    variable chats
+
+    upvar 0 chats(jid,$chatid) jid
+    upvar 0 chats(xlib,$chatid) xlib
+
+    unset chats(chatid,[list $xlib $jid]) jid xlib
+}
+
 proc chat::chatid {xlib jid} {
-    return [list $xlib $jid]
+    variable chats
+    upvar 0 chats(chatid,[list $xlib $jid]) chatid
+    expr {[info exists chatid] ? $chatid : ""}
 }
 
 proc chat::get_xlib {chatid} {
-    return [lindex $chatid 0]
+    variable chats
+    return chats(xlib,$chatid)
 }
 
 proc chat::get_jid {chatid} {
-    return [lindex $chatid 1]
+    variable chats
+    return chats(jid,$chatid)
 }
 
 ###############################################################################
@@ -387,7 +415,7 @@
     set xlib [get_xlib $chatid]
     set jid [get_jid $chatid]
     set jid [::xmpp::jid::normalize $jid]
-    set chatid [chatid $xlib $jid]
+    set chatid [mkchatid $xlib $jid]
 
     set cw [winid $chatid]
 



More information about the Tkabber-dev mailing list