[Tkabber-dev] r1721 - in trunk/tkabber-plugins: . openurl

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Fri Mar 13 19:09:43 MSK 2009


Author: sergei
Date: 2009-03-13 19:09:43 +0300 (Fri, 13 Mar 2009)
New Revision: 1721

Modified:
   trunk/tkabber-plugins/ChangeLog
   trunk/tkabber-plugins/openurl/openurl.tcl
Log:
	* openurl/openurl.tcl: Made plugin unloadable. Also, added a few
	  browsers and a custom browser (thanks to Serge Yudin).


Modified: trunk/tkabber-plugins/ChangeLog
===================================================================
--- trunk/tkabber-plugins/ChangeLog	2009-03-13 14:52:04 UTC (rev 1720)
+++ trunk/tkabber-plugins/ChangeLog	2009-03-13 16:09:43 UTC (rev 1721)
@@ -3,6 +3,9 @@
 	* whiteboard/svgrender.tcl, whiteboard/whiteboard.tcl: Fixed cid: URI
 	  usage.
 
+	* openurl/openurl.tcl: Made plugin unloadable. Also, added a few
+	  browsers and a custom browser (thanks to Serge Yudin).
+
 2009-03-12  Sergei Golovan <sgolovan at nes.ru>
 
 	* whiteboard/svgrender.tcl, whiteboard/whiteboard.tcl: Switched to

Modified: trunk/tkabber-plugins/openurl/openurl.tcl
===================================================================
--- trunk/tkabber-plugins/openurl/openurl.tcl	2009-03-13 14:52:04 UTC (rev 1720)
+++ trunk/tkabber-plugins/openurl/openurl.tcl	2009-03-13 16:09:43 UTC (rev 1721)
@@ -3,10 +3,20 @@
 package require msgcat
 
 namespace eval openurl {
-
     ::msgcat::mcload [file join [file dirname [info script]] msgs]
 
+    if {![::plugins::is_registered openurl]} {
+	::plugins::register openurl \
+			    -namespace [namespace current] \
+			    -source [info script] \
+			    -description [::msgcat::mc "Whether the Open URL plugin is loaded."] \
+			    -loadcommand [namespace code load] \
+			    -unloadcommand [namespace code unload]
+	return
+    }
+
     set options(browsers) [list \
+	iceweasel "Iceweasel" \
 	firefox "Firefox" \
 	galeon "Galeon" \
 	konqueror "Konqueror" \
@@ -18,22 +28,50 @@
 	opera "Opera" \
 	lynx "Lynx" \
 	links "Links" \
-	elinks "Elinks"]
+	elinks "Elinks" \
+	dillo "Dillo"]
 
-    custom::defgroup Plugins [::msgcat::mc "Plugins options."] -group Tkabber
+    custom::defgroup Plugins [::msgcat::mc "Plugins options."] \
+	-group Tkabber
 
-    custom::defgroup {Open URL} [::msgcat::mc "Open URL plugin options."] -group Plugins
+    custom::defgroup {Open URL} [::msgcat::mc "Open URL plugin options."] \
+	-group Plugins
 
     custom::defvar options(submenu) 1 \
 	[::msgcat::mc "Use submenu for browsers list."] \
 	-group {Open URL} \
 	-type boolean
+
+    custom::defvar options(custom_browser) "" \
+        [::msgcat::mc "User defined browser\
+		       name.\n\nExamples:\n  HV3\n  Google Chrome"] \
+    -group {Open URL} \
+    -type string
+
+    custom::defvar options(path_to_custom_browser) "" \
+        [::msgcat::mc "A binary name or a full path to user defined browser. Use\
+	its full path if can't be autodetected.\n\nExample:\n  ~/bin/hv3/hv3-linux"] \
+    -group {Open URL} \
+    -type string
 }
 
-proc openurl::open_url {brname brpath command} {
-    set url [::plugins::urls::encode_url [eval $command]]
+proc openurl::load {} {
+    hook::add chat_win_popup_menu_hook \
+	      [namespace current]::add_chat_win_popup_menu 5
+}
 
+proc openurl::unload {} {
+    variable options
+
+    hook::remove chat_win_popup_menu_hook \
+		 [namespace current]::add_chat_win_popup_menu 5
+
+    catch {unset options(browsers)}
+}
+
+proc openurl::open_url {brname brpath url} {
     switch -- $brname {
+	iceweasel -
 	firefox -
 	mozilla-firefox -
 	mozilla-firebird -
@@ -63,20 +101,7 @@
 proc openurl::add_chat_win_popup_menu {m chatwin X Y x y} {
     variable options
 
-    set tags [$chatwin tag names "@$x,$y"]
-    set idx1 [lsearch $tags url]
-    set idx2 [lsearch $tags xep]
-    switch -glob -- [expr {$idx1 >= 0}]/[expr {$idx2 >= 0}] {
-	0/0 {
-	    return
-	}
-	1/* {
-	    set command [list ::plugins::urls::get_url $chatwin $x $y]
-	}
-	default {
-	    set command [list ::plugins::xeps::get_xep $chatwin $x $y]
-	}
-    }
+    set url [::plugins::urls::encode_url [::plugins::urls::get_url $chatwin $x $y]]
 
     if {$options(submenu)} {
 	set mb [menu $m.openurl -tearoff 0]
@@ -86,9 +111,18 @@
 		$mb add command \
 		    -label $brdesc \
 		    -command [list [namespace current]::open_url \
-				   $brname [lindex $e 0] $command]
+				   $brname [lindex $e 0] $url]
 	    }
 	}
+	if {$options(custom_browser) != "" && $options(path_to_custom_browser) != ""} {
+	    set brname $options(path_to_custom_browser)
+	    if {[llength [set e [auto_execok $brname]]] > 0} {
+		$mb add command \
+		    -label $options(custom_browser) \
+		    -command [list [namespace current]::open_url \
+				   $brname [lindex $e 0] $url]
+	    }
+	}
 
 	$m add cascade -label [::msgcat::mc "Open URL with"] -menu $mb
     } else {
@@ -97,14 +131,19 @@
 		$m add command \
 		   -label [::msgcat::mc "Open URL with %s" $brdesc] \
 		   -command [list [namespace current]::open_url \
-				  $brname [lindex $e 0] $command]
+				  $brname [lindex $e 0] $url]
 	    }
 	}
-
+        if {$options(custom_browser) != "" && $options(path_to_custom_browser) != ""} {
+	    set brname $options(path_to_custom_browser)
+	    if {[llength [set e [auto_execok $brname]]] > 0} {
+                $m add command \
+                   -label [::msgcat::mc "Open URL with %s" $options(custom_browser)] \
+		   -command [list [namespace current]::open_url \
+				  $brname [lindex $e 0] $url]
+	    }
+        }
     }
 }
 
-hook::add chat_win_popup_menu_hook \
-    [namespace current]::openurl::add_chat_win_popup_menu 5
-
 # vim:ts=8:sw=4:sts=4:noet



More information about the Tkabber-dev mailing list