[Tkabber-dev] r2126 - in trunk/tkabber-plugins: . otr

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Fri Jan 31 18:54:21 MSK 2014


Author: sergei
Date: 2014-01-31 18:54:21 +0400 (Fri, 31 Jan 2014)
New Revision: 2126

Modified:
   trunk/tkabber-plugins/ChangeLog
   trunk/tkabber-plugins/otr/otr.tcl
Log:
	* otr/otr.tcl: Toggle the OTR message state on clicking OTR button in
	  a chat tab.


Modified: trunk/tkabber-plugins/ChangeLog
===================================================================
--- trunk/tkabber-plugins/ChangeLog	2014-01-31 07:52:43 UTC (rev 2125)
+++ trunk/tkabber-plugins/ChangeLog	2014-01-31 14:54:21 UTC (rev 2126)
@@ -5,6 +5,9 @@
 
 	* README: Added short description for floatingcontact and otr plugins.
 
+	* otr/otr.tcl: Toggle the OTR message state on clicking OTR button in
+	  a chat tab.
+
 2014-01-30  Sergei Golovan <sgolovan at nes.ru>
 
 	* otr/key.tcl: Fixed typo in error message.

Modified: trunk/tkabber-plugins/otr/otr.tcl
===================================================================
--- trunk/tkabber-plugins/otr/otr.tcl	2014-01-31 07:52:43 UTC (rev 2125)
+++ trunk/tkabber-plugins/otr/otr.tcl	2014-01-31 14:54:21 UTC (rev 2126)
@@ -504,6 +504,14 @@
     ::otr::finishConversation $ctx($xlib,$jid)
 }
 
+proc otr::toggle_session {xlib jid type} {
+    if {[msgstate:index $xlib $jid] == 0} {
+	request_session $xlib $jid $type
+    } else {
+	finish_session $xlib $jid $type
+    }
+}
+
 #############################################################################
 
 proc otr::peer_jid {xlib jid} {
@@ -1172,10 +1180,13 @@
 		 -height 24 \
 		 -width 24 \
 		 -relief link \
-		 -bd $::tk_borderwidth]
+		 -bd $::tk_borderwidth \
+		 -state [msgstate:enabled $xlib $jid] \
+		 -command [namespace code [list toggle_session $xlib $jid ""]]]
     msgstate:trace \
 	"$b configure -image \[[namespace current]::msgstate:icon [list $xlib] [list $jid]\] \
-		      -helptext \[[namespace current]::msgstate:helptext [list $xlib] [list $jid]\]" \
+		      -helptext \[[namespace current]::msgstate:helptext [list $xlib] [list $jid]\] \
+		      -state \[[namespace current]::msgstate:enabled [list $xlib] [list $jid]\]" \
 	$xlib $jid
 
     pack $bbox -side left -fill x -padx 2m -pady 2m
@@ -1198,11 +1209,14 @@
 	   -relief flat \
            -image [msgstate:icon $xlib $jid] \
            -helptype balloon \
-           -helptext [msgstate:helptext $xlib $jid]
+           -helptext [msgstate:helptext $xlib $jid] \
+	   -state [msgstate:enabled $xlib $jid] \
+	   -command [namespace code [list toggle_session $xlib $jid $type]]
 
     msgstate:trace "$cw.status.otrmsgstate configure \
 		-image \[[namespace current]::msgstate:icon [list $xlib] [list $jid]\] \
-		-helptext \[[namespace current]::msgstate:helptext [list $xlib] [list $jid]\]" \
+		-helptext \[[namespace current]::msgstate:helptext [list $xlib] [list $jid]\] \
+		-state \[[namespace current]::msgstate:enabled [list $xlib] [list $jid]\]" \
         $xlib $jid
     pack $cw.status.otrmsgstate -side left -before $cw.status.mb
 }
@@ -1269,8 +1283,36 @@
     return 0
 }
 
+proc otr::msgstate:enabled {xlib jid} {
+    if {[lsearch -exact [connections] $xlib] < 0
+	    || [::xmpp::jid::equal [my_jid $xlib $jid] $jid]
+	    || ![once_only $xlib $jid]} {
+	return disabled
+    } else {
+	return normal
+    }
+}
+
 ###############################################################################
 
+proc otr::enable_disable_buttons {xlib} {
+    variable ctx
+
+    foreach chatid [chat::opened $xlib] {
+	set jid [chat::get_jid $chatid]
+	if {[info exists ctx(msgstate,$xlib,$jid)]} {
+	    on_msgstate_change $xlib $jid $ctx(msgstate,$xlib,$jid)
+	} else {
+	    on_msgstate_change $xlib $jid MSGSTATE_PLAINTEXT
+	}
+    }
+}
+
+hook::add connected_hook [namespace current]::otr::enable_disable_buttons
+hook::add disconnected_hook [namespace current]::otr::enable_disable_buttons
+
+###############################################################################
+
 proc otr::user_popup_info {infovar xlib jid} {
     variable ctx
 
@@ -1406,7 +1448,7 @@
 	}
     }
 
-    if {[lsearch -exact [connections] $xlib] >= 0} {
+    if {![info exists state] && [lsearch -exact [connections] $xlib] >= 0} {
 	set state normal
     } else {
 	set state disabled



More information about the Tkabber-dev mailing list