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

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Mon Oct 11 04:49:27 MSD 2010


Author: kostix
Date: 2010-10-11 04:49:26 +0400 (Mon, 11 Oct 2010)
New Revision: 1942

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-10-03 06:01:22 UTC (rev 1941)
+++ branches/webbrowser-mod/tkabber/plugins/general/webbrowser.tcl	2010-10-11 00:49:26 UTC (rev 1942)
@@ -26,7 +26,7 @@
 proc webbrowser::browseURL {url} {
     set_status $url
     after idle [list after 0 [list \
-	[namespace current]::openURL [EncodeURL $url]]]
+	[namespace current]::openURL [EncodeURL $url]]\; set_status ""]
 }
 
 proc webbrowser::openURL {url} {
@@ -34,7 +34,6 @@
     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) {
@@ -167,23 +166,20 @@
 #     http://www.python.org/doc/2.5/lib/module-webbrowser.html
 #     http://catb.org/~esr/BROWSER/
 #     http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=172436
-# TODO handling BROWSER is more complicated: if the spec does not
-# contain %s, we must append $url as the sole argument.
-# Possibly the same semantics should be specified for the
-# ::plugins::options(webbrowser) variable and the code to
-# handle specs from BROWSER and fallback defaults unified.
 proc webbrowser::ExpandBrowserCommand {cmdLine url} {
     set cmd [list]
+    set seen_tokens 0
     foreach parts [regexp -all -inline {\S+} $text] {
-	lappend cmd [string map [list %% % %c : %s $url] $part]
+	set chunk [string map [list %% % %c : %s \x00] $part]
+	incr seen_tokens [regsub -all \x00 $chunk $url chunk]
+	lappend cmd $chunk
     }
+    if {$seen_tokens == 0} {
+	lappend cmd $url
+    }
     set cmd
 }
 
-# TODO Why don't we treat fallback browser specs in the same way
-# as those from BROWSER? Seems like they differ only by the fact
-# fallback specs are already lists while specs coming from
-# the user environment should be first split at whitespace.
 proc webbrowser::ExpandBrowserSpec {spec url} {
     set map [list %s $url]
     set out [list]
@@ -219,8 +215,9 @@
 	    append msg $out \n $res
 	    unset out
 	    ShowFailure $msg
+	} else {
+	    unset out
 	}
-	unset out
     }
 }
 
@@ -235,13 +232,26 @@
     ShowFailure [::msgcat::mc "Please define environment variable BROWSER"]
 }
 
-proc browseurlX {url} {
-        default {
-            if {![info exists env(BROWSER)]} {
-	}
-    }
+# TODO handling BROWSER is more complicated: ESR's example
+# uses escaped double quotes which hints a string extracted
+# from the BROWSER variable should be invoked via `/bin/sh -c`
+# aftet substitution. Possibly we should go the same way and
+# do this:
+# 1) Do not split extracted string into chunks to make it proper list,
+#    process it as a whole.
+# 2) Append the contents of env(SHELL), if present, of /bin/sh, if not,
+#    before the string, followed by "-c", like this:
+#    set cmd "/bin/sh -c $str"
+# 3) Use this as a command for [exec] or [open].
+#
+# TODO ShowFailure should probably show some header, like "opening URL failes"
+# and also show the command which failed so that the user could tweak their setup.
+#
+# TODO do we need fallback browser mechanics at all?
+#
+# TODO consider changin the way webbrowser is defined: it would be more
+# sensible for people if it used the "shell" semantics rather than Tcl's.
+# Also what if we would append the URL to that command if no %s tokens
+# were replaced?
 
-    set_status ""
-}
-
 # vim:ts=8:sw=4:sts=4:noet



More information about the Tkabber-dev mailing list