[Tkabber-dev] r523 - trunk/plugins/green

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Thu Aug 23 13:30:52 MSK 2012


Author: sergei
Date: 2012-08-23 13:30:52 +0400 (Thu, 23 Aug 2012)
New Revision: 523

Modified:
   trunk/plugins/green/green.tcl
Log:
  * green.tcl: Added preliminary support for DBus sleeping and resuming events.
  * green:tcl: Switched to loginconf_hist array for the stored login credentials
    instead of parsing loginconf* arrays which may be inconsistent at the time
    of relogin.


Modified: trunk/plugins/green/green.tcl
===================================================================
--- trunk/plugins/green/green.tcl	2012-08-21 16:22:01 UTC (rev 522)
+++ trunk/plugins/green/green.tcl	2012-08-23 09:30:52 UTC (rev 523)
@@ -20,6 +20,18 @@
 
 		winpm bind PBT_APMSUSPEND [namespace current]::on_suspend
 		winpm bind PBT_APMRESUMESUSPEND [namespace current]::on_resume
+	} else {
+		if {![catch { package require dbus-tcl }]} {
+			if {![catch { dbus connect system } bus]} {
+				dbus filter $bus add -type signal
+				dbus listen $bus /org/freedesktop/UPower \
+						 org.freedesktop.UPower.Sleeping \
+						 [namespace current]::on_suspend
+				dbus listen $bus /org/freedesktop/UPower \
+						 org.freedesktop.UPower.Resuming \
+						 [namespace current]::on_resume
+			}
+		}
 	}
 
 	variable active [list]
@@ -44,23 +56,16 @@
 		-group Green
 }
 
-proc green::on_suspend {} {
-	variable options
+proc green::on_suspend {args} {
+	# Logout all connections, even those which aren't fully logged in
+	variable active [connections 1]
 
-	set connids [connections]
-	if {[llength $connids] == 0} return
-
-	variable active [list]
-	foreach connid $connids {
-		if {$options(resume_sessions)} {
-			set jid [connection_bare_jid $connid]
-			lappend active $jid
-		}
-		logout $connid
+	foreach xlib $active {
+		logout $xlib
 	}
 }
 
-proc green::on_resume {} {
+proc green::on_resume {args} {
 	variable options
 	variable active
 
@@ -73,37 +78,16 @@
 
 proc green::do_resume {} {
 	variable active
+	global loginconf_hist
 
-	set lcs [lsearch -all -inline -regexp [info vars ::*] ::loginconf\\d+]
-	if {[llength $lcs] == 0} {
-		upvar 0 ::loginconf lc
-		set jid $lc(user)@$lc(server)
-		if {[lsearch -exact $active $jid] >= 0 && ![jid_connected $jid]} {
-			login [array get ::loginconf]
+	foreach xlib $active {
+		if {[info exists loginconf_hist($xlib)] && ![xlib_connected $xlib]} {
+			login $loginconf_hist($xlib)
 		}
-	} else {
-		foreach vlc $lcs {
-			upvar 0 $vlc lc
-			if {![info exists lc(user)]
-					|| ![info exists lc(server)]} continue
-			set jid $lc(user)@$lc(server)
-			foreach saved $active {
-				if {[string equal $saved $jid] && ![jid_connected $jid]} {
-					login [concat [array get ::loginconf] [array get lc]]
-				}
-			}
-		}
 	}
 }
 
-proc green::jid_connected jid {
-	set ref [::xmpp::jid::stripResource $jid]
-	foreach connid [connections] {
-		set cjid [connection_bare_jid $connid]
-		if {[string equal $ref $cjid]} {
-			return 1
-		}
-	}
-	return 0
+proc green::xlib_connected {xlib} {
+	expr {[lsearch -exact [connections] $xlib] >= 0}
 }
 



More information about the Tkabber-dev mailing list