[Tkabber-dev] r94 - in trunk/plugins: . urlcmd urlcmd/msgs

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Thu Feb 7 03:00:10 MSK 2008


Author: kostix
Date: 2008-02-07 03:00:09 +0300 (Thu, 07 Feb 2008)
New Revision: 94

Added:
   trunk/plugins/urlcmd/
   trunk/plugins/urlcmd/AUTHORS
   trunk/plugins/urlcmd/INSTALL
   trunk/plugins/urlcmd/README
   trunk/plugins/urlcmd/VERSION
   trunk/plugins/urlcmd/license.terms
   trunk/plugins/urlcmd/msgs/
   trunk/plugins/urlcmd/msgs/ru.msg
   trunk/plugins/urlcmd/urlcmd.tcl
Log:
Added new Tkabber plugin -- "urlcmd" by Gebb.
This plugin provides two new IRC-style commands -- "/listurls"
and "/browseurl" which allow to list URLs precent in the current
chat window and open a web browser on any of them, using its number.


Added: trunk/plugins/urlcmd/AUTHORS
===================================================================
--- trunk/plugins/urlcmd/AUTHORS	                        (rev 0)
+++ trunk/plugins/urlcmd/AUTHORS	2008-02-07 00:00:09 UTC (rev 94)
@@ -0,0 +1,2 @@
+Gebb
+Konstantin Khomoutov <flatworm at users.sourceforge.com>


Property changes on: trunk/plugins/urlcmd/AUTHORS
___________________________________________________________________
Name: svn:eol-style
   + native

Added: trunk/plugins/urlcmd/INSTALL
===================================================================
--- trunk/plugins/urlcmd/INSTALL	                        (rev 0)
+++ trunk/plugins/urlcmd/INSTALL	2008-02-07 00:00:09 UTC (rev 94)
@@ -0,0 +1,9 @@
+As usually, copy this directory to the ~/.tkabber/plugins directory
+so that you get a hierarchy like this:
+  ~/.tkabber/plugins
+  ~/.tkabber/plugins/urlcmd/
+  ~/.tkabber/plugins/urlcmd/urlcmd.tcl
+
+Restart Tkabber to get the plugin loaded.
+Consult the README file for the details about using this plugin.
+


Property changes on: trunk/plugins/urlcmd/INSTALL
___________________________________________________________________
Name: svn:eol-style
   + native

Added: trunk/plugins/urlcmd/README
===================================================================
--- trunk/plugins/urlcmd/README	                        (rev 0)
+++ trunk/plugins/urlcmd/README	2008-02-07 00:00:09 UTC (rev 94)
@@ -0,0 +1,42 @@
+"URL command" chat plugin for Tkabber.
+
+I. The idea.
+
+This plugin provides two additional "IRC-style chat commands",
+which are  specially formatted chat messages, recognized as
+commands to Tkabber. They are parsed and executed, then  their
+text is thrown away (examples of standard chat commands are:
+/clear, /nick, /ban, /leave, etc).
+
+Provided commands are:
+* /listurls shows the list of all URLs contained in the text of
+  the current chat window;
+* /browseurl opens an URL with the specified number in the
+  browser.
+
+II. Usage.
+
+The syntax of the commands is:
+
+/listurls
+
+/browseurl ?n?
+
+The argument surrounded by question marks is optional.  The n
+argument of the /browseurl command specifies the zero-based
+index of the URL  to browse. If it is omitted, the last (i.e.
+sent most recently) URL present in the chat window is opened.
+
+III. Examples:
+
+Show the list of all URLs present in the current chat window:
+/listurls
+
+Open the first url in the list:
+/browseurl 1
+
+Open the URL that was sent to the current chat most recently: 
+/browseurl 
+
+
+vim:et:ts=4:sw=4:tw=64


Property changes on: trunk/plugins/urlcmd/README
___________________________________________________________________
Name: svn:eol-style
   + native

Added: trunk/plugins/urlcmd/VERSION
===================================================================
--- trunk/plugins/urlcmd/VERSION	                        (rev 0)
+++ trunk/plugins/urlcmd/VERSION	2008-02-07 00:00:09 UTC (rev 94)
@@ -0,0 +1 @@
+1.0, 5-February-2007


Property changes on: trunk/plugins/urlcmd/VERSION
___________________________________________________________________
Name: svn:eol-style
   + native

Added: trunk/plugins/urlcmd/license.terms
===================================================================
--- trunk/plugins/urlcmd/license.terms	                        (rev 0)
+++ trunk/plugins/urlcmd/license.terms	2008-02-07 00:00:09 UTC (rev 94)
@@ -0,0 +1,19 @@
+Copyright (c) 2008 Konstantin Khomoutov <flatworm at users.sourceforge.net>, Gebb
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the "Software"),
+to deal in the Software without restriction, including without limitation
+the rights to use, copy, modify, merge, publish, distribute, sublicense,
+and/or sell copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.


Property changes on: trunk/plugins/urlcmd/license.terms
___________________________________________________________________
Name: svn:eol-style
   + native

Added: trunk/plugins/urlcmd/msgs/ru.msg
===================================================================
--- trunk/plugins/urlcmd/msgs/ru.msg	                        (rev 0)
+++ trunk/plugins/urlcmd/msgs/ru.msg	2008-02-07 00:00:09 UTC (rev 94)
@@ -0,0 +1,13 @@
+# urlcmd.tcl -- Russian message catalog
+# Translated by Gebb
+
+::msgcat::mcset ru "No URLs were found." \
+	"Нет ссылок."
+::msgcat::mcset ru "Invalid URL index. Index must be an integer number." \
+	"Недопустимый номер ссылки. Номер должен быть целым числом."
+::msgcat::mcset ru "URL index was out of range. Valid range is from 0 to %s inclusively." \
+	"Номер ссылки — вне диапазона. Допустимый диапазон — от 0 до %s включительно."
+::msgcat::mcset ru "Available URL list" \
+	"Список ссылок"
+
+# vim:fenc=utf-8


Property changes on: trunk/plugins/urlcmd/msgs/ru.msg
___________________________________________________________________
Name: svn:eol-style
   + native

Added: trunk/plugins/urlcmd/urlcmd.tcl
===================================================================
--- trunk/plugins/urlcmd/urlcmd.tcl	                        (rev 0)
+++ trunk/plugins/urlcmd/urlcmd.tcl	2008-02-07 00:00:09 UTC (rev 94)
@@ -0,0 +1,130 @@
+# "URL commands" -- a Tkabber chat plugin.
+# Provides two IRC-style chat commands that allow the
+# user to view the list of URLs present in the current 
+# chat window and open them in the browser.
+# Plugin implementation by
+#    Gebb
+# Original idea and main code by
+#    Konstantin Khomoutov <flatworm at users.sourceforge.net>
+#
+# Usage:
+# /listurls
+#    Shows the list of URLs in the chat window.
+#
+# /browseurl ?n?
+#    Opens the n-th URL in the browser. Omit the argument 
+#    to open the last URL in the list.
+
+package require msgcat
+
+namespace eval urlcmd {
+	::msgcat::mcload [file join [file dirname [info script]] msgs]
+
+	hook::add generate_completions_hook \
+		[namespace current]::command_comps
+	hook::add chat_send_message_hook \
+		[namespace current]::handle_command 16
+}
+
+proc urlcmd::command_comps {chatid compsvar wordstart line} {
+	upvar 0 $compsvar comps
+    
+	if {!$wordstart} {
+		lappend comps {/listurls } {/browseurl }
+	}
+}
+
+proc urlcmd::handle_command {chatid user body type} {
+	
+	# Detect the command.
+	if {[string match {/listurls*} $body]} {
+		set cmd /listurls
+	} elseif {[string match {/browseurl*} $body]} {
+		set cmd /browseurl
+	} else return
+
+	# Get the URL list.
+	set urls [geturls $chatid]
+
+	# If the list was requested, show it and exit.
+	if {[string equal $cmd "/listurls"]} {
+		if {[llength $urls] == 0} {
+			show error $chatid [::msgcat::mc "No URLs were found."]
+		} else {
+			listurls $urls $chatid
+		}
+		return stop
+	}
+
+	# If we got here, the command is definitely /browseurl.
+	set maxindex [expr {[llength $urls] - 1}]
+	if {$maxindex < 0} {
+		# Nothing to show: URL list is empty.
+		show error $chatid [::msgcat::mc "No URLs were found."]
+		return stop
+	}
+	
+	# Ignore everything but the first line.
+	set firstline [lindex [split $body \n] 0]
+	# Get the command argument (URL index).
+	set uindex [string trim [string range $firstline [string length $cmd] end]]
+	
+	# Validate the URL index.	
+	if {$uindex == ""} {
+		set uindex end 
+	} elseif {![string is integer $uindex]} {
+		show error $chatid [::msgcat::mc "Invalid URL index.\
+			Index must be an integer number."]
+		return stop
+	} elseif {$uindex > $maxindex || $uindex < 0 } {
+		set errmsg [::msgcat::mc "URL index was\
+			out of range. Valid range is from 0\
+			to %s inclusively." $maxindex]
+		show error $chatid $errmsg
+		return stop
+	}
+	
+	# Everything is OK, navigate to the requested URL.
+	browseurl [lindex $urls $uindex]
+	# We're done, stop processing hook handlers.
+	return stop
+}
+
+# Returns a list of URLs present
+# in the $chatid window.
+#
+proc urlcmd::geturls chatid {
+	set cw [chat::chat_win $chatid]
+	set out [list]
+	
+	foreach {a b} [$cw tag ranges url] {
+		set u [$cw get $a $b]
+		# Do not add existing URLs.
+		if { ![info exists urls($u)] } {
+			set urls($u) 1
+			lappend out $u
+		}
+	}
+	set out
+}
+
+# Shows the specified list of URLs
+# in the $chatid window.
+#
+proc urlcmd::listurls {urls chatid} {
+	set ix 0
+	show info $chatid \n[::msgcat::mc "Available URL list"]
+	foreach url $urls {
+		show info $chatid "$ix: $url"
+		incr ix
+	}
+}
+
+# $type should be either "info" or "error"
+proc urlcmd::show {type chatid msg} {
+	set jid [chat::get_jid $chatid]
+	set cw [chat::chat_win $chatid]
+
+	chat::add_message $chatid $jid $type $msg {}
+}
+


Property changes on: trunk/plugins/urlcmd/urlcmd.tcl
___________________________________________________________________
Name: svn:eol-style
   + native



More information about the Tkabber-dev mailing list