[Tkabber-dev] r1912 - branches/webbrowser-mod/tkabber/plugins/general

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Tue Feb 2 14:32:59 MSK 2010


Author: kostix
Date: 2010-02-02 14:32:59 +0300 (Tue, 02 Feb 2010)
New Revision: 1912

Modified:
   branches/webbrowser-mod/tkabber/plugins/general/webbrowser.tcl
Log:
Work in progress


Modified: branches/webbrowser-mod/tkabber/plugins/general/webbrowser.tcl
===================================================================
--- branches/webbrowser-mod/tkabber/plugins/general/webbrowser.tcl	2010-02-01 21:07:43 UTC (rev 1911)
+++ branches/webbrowser-mod/tkabber/plugins/general/webbrowser.tcl	2010-02-02 11:32:59 UTC (rev 1912)
@@ -34,6 +34,7 @@
     variable webbrowser
 
     if {[info exists webbrowser] && $webbrowser != ""} {
+	# TODO check what ExpandBrowserSpec returns is a proper list
 	eval exec [ExpandBrowserSpec $webbrowser $url] &
     } else {
 	switch -- $tcl_platform(platform) {
@@ -61,7 +62,7 @@
     for {set i 0} {$i < $len} {incr i} {
 	binary scan $utf8_url @${i}c sym
 	set sym [expr {$sym & 0xFF}]
-	if {$sym >= 128 || $sym <= 32} {
+	if {$sym >= 127 || $sym <= 32} {
 	    append encoded_url [format "%%%02X" $sym]
 	} else {
 	    append encoded_url [binary format c $sym]
@@ -75,17 +76,20 @@
 }
 
 proc webbrowser::MacOSOpenURL {url} {
-    exec open [list $url]
+    exec open $url
 }
 
+# TODO supposedly we should map " to \" and \ to \\ in $app and $url
+# before passing them to AppleScript.
+# But the whole idea of supporting prehistoric Macs seems questionable.
 proc webbrowser::MacintoshOpenURL {url} {
     global env
 
     upvar 0 env(BROWSER) envSpec
     set app [expr {
 	[info exists envSpec] && $envSpec != ""
-	? $envSpec
-	: "Browse the Internet"}]
+	    ? $envSpec
+	    : "Browse the Internet"}]
     exec AppleScript execute \
 	"tell application \"$app\"\nopen url \"$url\"\nend tell\n" &
 }
@@ -113,7 +117,7 @@
 proc webbrowser::PosixRunSensibleBrowser {url} {
     set proc [FindExecutable sensible-browser]
     if {$proc != ""} {
-	exec $proc $url &
+	RunCommandAsync $prog [list $url]
 	return 1
     } else {
 	return 0
@@ -193,39 +197,44 @@
     lindex [auto_execok $filename] 0
 }
 
+# RunCommandAsync returns immediately;
+# any error, if any, will be shown in the future using ShowFailure.
 proc webbrowser::RunCommandAsync {args} {
     variable cmdout
     set fd [open "| $args 2>@1"]
-    fconfigure $fd -buffering line
-    fileevent $fd readable [list [namespace current]::ReadCmdLine $fd $args]
+    fconfigure $fd -blocking no
+    fileevent $fd readable [list [namespace current]::ReadCmdOutput $fd $args]
     set cmdout($fd) ""
 }
 
-proc webbrowser::ReadCmdLine {fd cmd} {
+proc webbrowser::ReadCmdOutput {fd cmd} {
     variable cmdout
     upvar 0 cmdout($fd) out
 
-    if {[gets $fd line] < 0} {
+    append out [read $fd]
+    if {[eof $fd]} {
+	fconfigure $fd -blocking yes
 	set code [catch {close $fd} res]
 	if {$code != 0} {
-	    append msg $out $res
+	    append msg $out \n $res
 	    unset out
-	    return -code $code -errorcode $::errorCode -errorInfo $::errorInfo $msg
+	    ShowFailure $msg
 	}
 	unset out
-	puts OK
-    } else {
-	append out $line \n
     }
 }
 
-proc webbrowser::PosixShowFailure {} {
+proc webbrowser::ShowFailure {msg} {
     MessageDlg .browse_err -aspect 50000 -icon info \
-	-message [::msgcat::mc "Please define environment variable BROWSER"] \
+	-message $msg \
 	-type user \
 	-buttons ok -default 0 -cancel 0
 }
 
+proc webbrowser::PosixShowFailure {} {
+    ShowFailure [::msgcat::mc "Please define environment variable BROWSER"]
+}
+
 proc browseurlX {url} {
         default {
             if {![info exists env(BROWSER)]} {



More information about the Tkabber-dev mailing list