[Tkabber-dev] r76 - in trunk/plugins: . green

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Tue Oct 23 21:44:54 MSD 2007


Author: kostix
Date: 2007-10-23 21:44:54 +0400 (Tue, 23 Oct 2007)
New Revision: 76

Added:
   trunk/plugins/green/
   trunk/plugins/green/AUTHORS
   trunk/plugins/green/INSTALL
   trunk/plugins/green/green.tcl
   trunk/plugins/green/license.terms
Log:
green: Added new plugin providing handling of Windows power management
 events with the help of the tkwinpm Tcl extension (http://tkwinpm.googlecode.com).


Added: trunk/plugins/green/AUTHORS
===================================================================
--- trunk/plugins/green/AUTHORS	                        (rev 0)
+++ trunk/plugins/green/AUTHORS	2007-10-23 17:44:54 UTC (rev 76)
@@ -0,0 +1 @@
+Konstantin Khomoutov <flatworm at users.sourceforge.com>


Property changes on: trunk/plugins/green/AUTHORS
___________________________________________________________________
Name: svn:eol-style
   + native

Added: trunk/plugins/green/INSTALL
===================================================================
--- trunk/plugins/green/INSTALL	                        (rev 0)
+++ trunk/plugins/green/INSTALL	2007-10-23 17:44:54 UTC (rev 76)
@@ -0,0 +1,13 @@
+Install tkwinpm Tcl extension which can be found at
+http://tkwinpm.googlecode.com.
+
+As usually, copy this directory under the ~/.tkabber/plugins directory
+so that you get a hierarchy like this:
+  ~/.tkabber/plugins
+  ~/.tkabber/plugins/green/
+  ~/.tkabber/plugins/green/green.tcl
+
+Restart Tkabber, to get the plugin loaded.
+Visit the Cutsomize->Plugins->Green group of settings.
+Consult the README file for the details about using this plugin.
+


Property changes on: trunk/plugins/green/INSTALL
___________________________________________________________________
Name: svn:eol-style
   + native

Added: trunk/plugins/green/green.tcl
===================================================================
--- trunk/plugins/green/green.tcl	                        (rev 0)
+++ trunk/plugins/green/green.tcl	2007-10-23 17:44:54 UTC (rev 76)
@@ -0,0 +1,94 @@
+# $Id$
+# "Green" -- Tkabber plugin which allows Tkabber to properly
+# handle changes in the Windows power state (disconnection on
+# suspend and (possibly) re-connection on resume).
+# REQUIRES tkwinpm Tcl extension: http://tkwinpm.googlecode.com
+# Written by Konstantin Khomoutov <flatworm at users.sourceforge.net>
+# See README for usage guidelines.
+# See license.terms for details about distribution.
+
+namespace eval green {
+	if {[catch { package require winpm }]} {
+		global errorInfo
+		puts stderr "Power management support is unavailable:\
+			failed to load \"winpm\" package.\
+			The error was:\n\
+			$errorInfo"
+		return
+	}
+
+	variable active [list]
+	variable options
+
+	custom::defgroup Green \
+		[::msgcat::mc "Power management support (for Windows)."] \
+		-group Plugins
+
+	custom::defvar options(resume_sessions) 1 \
+		[::msgcat::mc "Attempt to resume the sessions that were active\
+			when the system has been suspended."] \
+		-type boolean \
+		-group Green
+
+	custom::defvar options(resume_delay) 10 \
+		[::msgcat::mc "Number of seconds to wait before attempting\
+			to re-establish the sessions that were active.\
+			This may be useful to allow the network connection(s)\
+			to come up."] \
+		-type integer \
+		-group Green
+
+	winpm bind PBT_APMSUSPEND [namespace current]::on_suspend
+	winpm bind PBT_APMRESUMESUSPEND [namespace current]::on_resume
+}
+
+proc green::on_suspend {} {
+	variable options
+
+	set connids [jlib::connections]
+	if {[llength $connids] == 0} return
+
+	variable active [list]
+	foreach connid $connids {
+		if {$options(resume_sessions)} {
+			set jid [jlib::connection_bare_jid $connid]
+			lappend active $jid
+		}
+		logout $connid
+	}
+}
+
+proc green::on_resume {} {
+	variable options
+	if {!$options(resume_sessions)} return
+
+	variable active
+	if {[llength $active] == 0} return
+
+	after 0 [namespace current]::do_resume
+}
+
+proc green::do_resume {} {
+	variable options
+	variable active
+
+	after [expr {$options(resume_delay) * 1000}]
+
+	set lcs [lsearch -all -inline -regexp [info vars ::*] ::loginconf\\d+]
+	if {[llength $lcs] == 0} {
+		login [array get ::loginconf]
+	} 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]} {
+					login [concat [array get ::loginconf] [array get lc]]
+				}
+			}
+		}
+	}
+}
+


Property changes on: trunk/plugins/green/green.tcl
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: trunk/plugins/green/license.terms
===================================================================
--- trunk/plugins/green/license.terms	                        (rev 0)
+++ trunk/plugins/green/license.terms	2007-10-23 17:44:54 UTC (rev 76)
@@ -0,0 +1,19 @@
+Copyright (c) 2007 Konstantin Khomoutov <flatworm at users.sourceforge.net>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the "Software"),
+to deal in the Software without restriction, including without limitation
+the rights to use, copy, modify, merge, publish, distribute, sublicense,
+and/or sell copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.


Property changes on: trunk/plugins/green/license.terms
___________________________________________________________________
Name: svn:eol-style
   + native



More information about the Tkabber-dev mailing list