[Tkabber-dev] r1621 - trunk/tkabber

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Sun Dec 14 18:09:55 MSK 2008


Author: sergei
Date: 2008-12-14 18:09:54 +0300 (Sun, 14 Dec 2008)
New Revision: 1621

Modified:
   trunk/tkabber/ChangeLog
   trunk/tkabber/login.tcl
Log:
	* login.tcl: Since logout can be called before a connection is
	  authenticated then an additional flag is added to connections list.
	  It indicates if the connection is active and needs running
	  disconnected_hook on logout.


Modified: trunk/tkabber/ChangeLog
===================================================================
--- trunk/tkabber/ChangeLog	2008-12-10 12:33:50 UTC (rev 1620)
+++ trunk/tkabber/ChangeLog	2008-12-14 15:09:54 UTC (rev 1621)
@@ -1,3 +1,10 @@
+2008-12-14  Sergei Golovan  <sgolovan at nes.ru>
+
+	* login.tcl: Since logout can be called before a connection is
+	  authenticated then an additional flag is added to connections list.
+	  It indicates if the connection is active and needs running
+	  disconnected_hook on logout.
+
 2008-12-10  Sergei Golovan  <sgolovan at nes.ru>
 
 	* plugins/general/autoaway.tcl: Start timer at Tkabber start and

Modified: trunk/tkabber/login.tcl
===================================================================
--- trunk/tkabber/login.tcl	2008-12-10 12:33:50 UTC (rev 1620)
+++ trunk/tkabber/login.tcl	2008-12-14 15:09:54 UTC (rev 1621)
@@ -227,28 +227,37 @@
     set connections {}
 }
 
-proc connections {} {
+proc connections {{all 0}} {
     global connections
 
-    return $connections
+    set res {}
+    foreach c $connections {
+	if {$all || [lindex $c 1]} {
+	    lappend res [lindex $c 0]
+	}
+    }
+    return $res
 }
 
-proc add_to_connection {xlib} {
+proc add_to_connection {active xlib} {
     global connections
 
-    set idx [lsearch -exact $connections $xlib]
-    if {$idx < 0} {
-	lappend connections $xlib
-    }
+    set idx [lsearch -exact $connections [list $xlib 0]]
+    set connections [lreplace $connections $idx $idx]
+    set idx [lsearch -exact $connections [list $xlib 1]]
+    set connections [lreplace $connections $idx $idx]
+    lappend connections [list $xlib $active]
 }
 
-hook::add connected_hook add_to_connection 1
+hook::add connected_hook [list add_to_connection 1] 1
 
 proc remove_from_connection {xlib} {
     global connections
 
-    set idx [lsearch -exact $connections $xlib]
+    set idx [lsearch -exact $connections [list $xlib 0]]
     set connections [lreplace $connections $idx $idx]
+    set idx [lsearch -exact $connections [list $xlib 1]]
+    set connections [lreplace $connections $idx $idx]
 }
 
 hook::add disconnected_hook remove_from_connection 1
@@ -316,6 +325,7 @@
     }
 
     debugmsg login "Starting login"
+    set_status [::msgcat::mc "Connecting to %s" $lc(server)]
     if {[catch {login_connect $logindata} xlib] > 0} {
 	# Nasty thing has happened.
 	# $xlib contains error message here.
@@ -344,6 +354,7 @@
 	return
     }
     # OK, connected.
+    add_to_connection 0 $xlib
     debugmsg login "Connect successful ($jid) $xlib"
     set login_after_time 7500
     login_login $xlib $logindata
@@ -712,7 +723,7 @@
 	    unset login_after_id($jid)
 	}
 
-	foreach xlib [connections] {
+	foreach xlib [connections 1] {
 	    disconnected $xlib
 	}
     } else {
@@ -746,7 +757,10 @@
 proc disconnected {xlib} {
     remove_from_login_after_id $xlib
 
-    if {[lsearch -exact [connections] $xlib] < 0} return
+    if {[lsearch -exact [connections] $xlib] < 0} {
+	::xmpp::disconnect $xlib
+	return
+    }
 
     hook::run disconnected_hook $xlib
 }
@@ -801,16 +815,13 @@
 				       [error_to_string $xml]] \
 		-type user -buttons {ok} -default 0 -cancel 0
 	}
-	# Connection isn't authenticated here, so disconnecting without
-	# a logout.
-	remove_from_login_after_id $xlib
-	::xmpp::disconnect $xlib
+
+	logout $xlib
     }
 }
 
 proc recv_register_result {xlib logindata res xml} {
-    remove_from_login_after_id $xlib
-    ::xmpp::disconnect $xlib
+    logout $xlib
 
     if {$res == "ok"} {
 	login $logindata



More information about the Tkabber-dev mailing list