1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
|
# $Id: openurl.tcl 1954 2010-11-11 13:00:36Z sergei $
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" \
mozilla-firefox "Mozilla Firefox" \
mozilla-firebird "Mozilla Firebird" \
mozilla "Mozilla" \
netscape "Netscape" \
iexplore "Internet Explorer" \
opera "Opera" \
chrome "Google Chrome" \
lynx "Lynx" \
links "Links" \
elinks "Elinks" \
dillo "Dillo"]
custom::defgroup Plugins [::msgcat::mc "Plugins options."] \
-group Tkabber
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::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 -
mozilla -
netscape {
if {[catch {eval exec $brpath -remote \"openURL($url, new-tab)\"}]} {
exec $brpath $url &
}
}
galeon {
exec $brpath --new-tab $url &
}
opera {
exec $brpath -newpage $url &
}
links -
elinks -
lynx {
exec x-terminal-emulator -e $brpath $url &
}
default {
exec $brpath $url &
}
}
}
proc openurl::add_chat_win_popup_menu {m chatwin X Y x y} {
variable options
set tags [$chatwin tag names "@$x,$y"]
if {[lsearch -glob $tags href_*] < 0} return
set url [::plugins::urls::encode_url [::plugins::urls::get_url $chatwin $x $y]]
if {$options(submenu)} {
set mb [menu $m.openurl -tearoff 0]
foreach {brname brdesc} $options(browsers) {
if {[llength [set e [auto_execok $brname]]] > 0} {
$mb add command \
-label $brdesc \
-command [list [namespace current]::open_url \
$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 {
foreach {brname brdesc} $options(browsers) {
if {[llength [set e [auto_execok $brname]]] > 0} {
$m add command \
-label [::msgcat::mc "Open URL with %s" $brdesc] \
-command [list [namespace current]::open_url \
$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]
}
}
}
}
# vim:ts=8:sw=4:sts=4:noet
|