[Tkabber-dev] r376 - in trunk/plugins: . vimage vimage/images vimage/msgs

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Tue Aug 31 22:59:02 MSD 2010


Author: Rejjin
Date: 2010-08-31 22:59:02 +0400 (Tue, 31 Aug 2010)
New Revision: 376

Added:
   trunk/plugins/vimage/
   trunk/plugins/vimage/images/
   trunk/plugins/vimage/images/big.gif
   trunk/plugins/vimage/images/none.gif
   trunk/plugins/vimage/msgs/
   trunk/plugins/vimage/msgs/ru.msg
   trunk/plugins/vimage/readme.ru
   trunk/plugins/vimage/vimage.tcl
Log:
Version - alpha. Please see to readme.ru

Added: trunk/plugins/vimage/images/big.gif
===================================================================
(Binary files differ)


Property changes on: trunk/plugins/vimage/images/big.gif
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Added: trunk/plugins/vimage/images/none.gif
===================================================================
(Binary files differ)


Property changes on: trunk/plugins/vimage/images/none.gif
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Added: trunk/plugins/vimage/msgs/ru.msg
===================================================================
--- trunk/plugins/vimage/msgs/ru.msg	                        (rev 0)
+++ trunk/plugins/vimage/msgs/ru.msg	2010-08-31 18:59:02 UTC (rev 376)
@@ -0,0 +1,24 @@
+::msgcat::mcset ru "Whether the vimage plugin is loaded." "Загружает/выгружает плагин Vimage"
+::msgcat::mcset ru "Vimage options" "Опции плагина Vimage"
+::msgcat::mcset ru "Download image when a new message" "Автоматически скачивать изображение, если его ссылка находится в теле сообщения"
+::msgcat::mcset ru "Automatic show downloaded images" "Автоматически открывать изображение по завершении скачивания."
+::msgcat::mcset ru "Show images from history" "Загружать изображения истории"
+::msgcat::mcset ru "Max size of image (kb)." "Максимальный размер изображения (kb)"
+::msgcat::mcset ru "Downloaded urls - background color" "Цвет фона ссылок на скачанные изображения"
+::msgcat::mcset ru "Process urls - background color" "Цвет фона ссылок скачивающихся изображений"
+::msgcat::mcset ru "Vimage - view" "Vimage - просмотр"
+::msgcat::mcset ru "Compulsory viewing" "Принудительный просмотр"
+::msgcat::mcset ru "Show" "Показать"
+::msgcat::mcset ru "Reload" "Перезагрузить"
+::msgcat::mcset ru "Save" "Сохранить"
+::msgcat::mcset ru "Back" "Назад"
+::msgcat::mcset ru "Zoom" "Увеличение"
+::msgcat::mcset ru "Zoom in" "Приблизить"
+::msgcat::mcset ru "Zoom out" "Отдалить"
+::msgcat::mcset ru "Tools" "Инструменты"
+::msgcat::mcset ru "Flip LR" "Развернуть слева направо"
+::msgcat::mcset ru "Flip TB" "Развернуть сверху вниз"
+::msgcat::mcset ru "Flip both" "Развернуть"
+::msgcat::mcset ru "Unsaved" "Не сохранено"
+::msgcat::mcset ru "Saved to %s" "Сохранено в %s"
+::msgcat::mcset ru "Saved" "Сохранено"
\ No newline at end of file

Added: trunk/plugins/vimage/readme.ru
===================================================================
--- trunk/plugins/vimage/readme.ru	                        (rev 0)
+++ trunk/plugins/vimage/readme.ru	2010-08-31 18:59:02 UTC (rev 376)
@@ -0,0 +1,14 @@
+Âåðñèÿ - alpha. (âûëîæåí â êà÷åñòâå ïðèìåðà ôóíêöèîíàëüíîñòè, õîòÿ è ìîæíî íîðìàëüíî èñïîëüçîâàòü âûñòàâèâ îòïöèè:
+options(auto_show_image) 0
+options(shadow_download_image) 0
+)
+
+Îñíîâíûå ïðîáëåìû:
+ - Ñêà÷èâàíèå èçîáðàæåíèé è èõ îòîáðàæåíèå íà÷èíàÿ ñ ñàìîé çàãðóçêè Tkabber. 
+ - Ïðîáëåìû ñ îòîáðàæåíèåì ñêà÷àííûõ èçîáðàæåíèé (îøèáêè ñêà÷èâàíèÿ, ïðîáëåìà http).
+ - Òðåáóåòñÿ ìîäèôèêàöèÿ regexp (ïàðñèíã url'îâ)
+ - Ðàáîòà íàä àíãëèéñêèì è ðóññêèì ÿçûêàìè
+ 
+Âîçìîæíîñòè:
+Ïëàãèí óìååò çàãðóæàòüñÿ/âûãðóæàòñÿ äèíàìè÷åñêè. Åñëè ñòîèò îïöèÿ {shadow_download_image 1}, òî ïðè ïîÿâëåíèè íîâîãî ñîîáùåíèÿ, è íàéäåííîé â í¸ì ññûëêè íà èçîáðàæåíèå, ýòî èçîáðàæåíèå íà÷èíàåò ñêà÷èâàòñÿ. Äàëåå, åñëè ñòîèò îïöèÿ {options(auto_show_image) 1}, òî èçîáðàæåíèå àâòîìàòè÷åñêè ïîÿâèòñÿ íà ýêðàíå. Åñëè íåò, òî ññûëêà îæèäàåò ñîáûòèÿ "ñðåäíÿÿ êíîïêà ìûøè", ëèáî êëèê, ïî ñîîòâåòñòâóþùåìó ìåíþ, ïî íàæàòèè íà ïðàâóþ êíîïêó ìûøè. Åñëè ïîÿâèëîñü èçîáðàæåíèå "Image is too large", òî âû ìîæåòå íàæàòü ïðàâóþ êíîïêó ìûøè ==> "Ïðèíóäèòåëüíûé ïðîñìîòð", îïöèÿ max_size ïðè ýòîì íå ó÷èòûâåòñÿ. Åñëè èçîáðàæåíèå îòîáðàæàåòñÿ íåâåðíî (îøèáêè http), òî âû ìîæåòå íàæàòü ïðàâóþ êíîïêó ìûøè ==> "Ïåðåçàãðóçèòü". Ýôôåêò "Ïðàâàÿ êíîïêà ìûøè ==> Ïîêàçàòü" àíàëîãè÷åí ñðåäíåé êíîïêå ìûøè. Íà ïîÿâèâøåìñÿ îêíå ñ èçîáðàæåíèåì âû ìîæåòå íàæàòü ïðàâóþ êíîïêó, è â ìåíþ âûáðàòü "Ñîõðàíèòü" - ñîõðàíèòü ëîêàëüíî íà äèñê, "Íàçàä" - ñêðûòü èçîáðàæåíèå "Óâåëè÷åíèå - Ïðèáëèçèòü/Îòäàëèòü" - óâåëè÷èâàåò èëè óìåíüøàåò èçîáðàæåíèå.  "Èíñòðóìåíòû âû ìîæåòå ïîâåðíóòü èçîáðàæåíèå." Âî âðåìÿ ñêà÷èâàíèÿ èçîáðàæåíèÿ, ôîí ññûëîê ñòàíîâÿòñÿ îðàíæåâîãî öâåòà, ïî-îêîí÷àíèè - êðàñíîãî (îïöèîíàëüíî).
+  
\ No newline at end of file

Added: trunk/plugins/vimage/vimage.tcl
===================================================================
--- trunk/plugins/vimage/vimage.tcl	                        (rev 0)
+++ trunk/plugins/vimage/vimage.tcl	2010-08-31 18:59:02 UTC (rev 376)
@@ -0,0 +1,328 @@
+namespace eval vimage {
+	variable options
+	
+	::msgcat::mcload [file join [file dirname [info script] ] msgs]
+	
+	set options(extensions) {gif|pixmap}
+	if { [catch { package require Img } ] == 0 } {
+		append options(extensions) {|bmp|ico|jpeg|jpg|pcx|}
+		append options(extensions) {png|ppm|postscript|sgi|sun|}
+		append options(extensions) {tga|tiff|xbm|xpm}
+	}	
+
+	image create photo Big -file \
+		[file join [file dirname [info script] ] images big.gif]
+		
+	image create photo None -file \
+		[file join [file dirname [info script] ] images none.gif]
+	
+	if {![::plugins::is_registered vimage]} {
+		::plugins::register vimage \
+              -namespace [namespace current] \
+              -source [info script] \
+              -description [::msgcat::mc "Whether the vimage plugin is loaded."] \
+              -loadcommand [namespace code load] \
+              -unloadcommand [namespace code unload]
+		return
+    }
+	
+	custom::defgroup Plugins [::msgcat::mc "Plugins options."] -group Tkabber	
+    custom::defgroup Vimage [::msgcat::mc "Vimage options"] -group Plugins	
+		
+	custom::defvar options(shadow_download_image) 1 \
+		[::msgcat::mc "Download image when a new message"] \
+		-group Vimage -type boolean
+		
+	custom::defvar options(auto_show_image) 1 \
+		[::msgcat::mc "Automatic show downloaded images"] \
+		-group Vimage -type boolean
+		
+	custom::defvar options(show_images_from_history) 0 \
+		[::msgcat::mc "Show images from history"] \
+		-group Vimage -type boolean
+		
+	custom::defvar options(max_size) 50 \
+			[::msgcat::mc "Max size of image (kb)."] \
+			-type string -group Vimage	
+		
+	custom::defvar options(background_active_urls) red \
+			[::msgcat::mc "Downloaded urls - background color"] \
+			-type string -group Vimage	
+			
+	custom::defvar options(background_process_urls) yellow \
+			[::msgcat::mc "Process urls - background color"] \
+			-type string -group Vimage	
+}
+
+# # # # # # # # # # # # # # # # # # # # # # # # 
+proc vimage::load {} {
+	hook::add draw_message_post_hook \
+			[namespace current]::drawMessage 50
+	hook::add chat_win_popup_menu_hook \
+			[namespace current]::add_view_button 1
+}
+
+proc vimage::unload {} {
+	hook::remove draw_message_post_hook \
+			[namespace current]::drawMessage 50
+	hook::remove chat_win_popup_menu_hook \
+			[namespace current]::add_view_button 1
+		
+}
+# # # # # # # # # # # # # # # # # # # # # # # # 
+
+
+proc vimage::drawMessage { chatid from type body extras } {
+	variable options
+	
+	if { $options(show_images_from_history) == 0 && [lindex [lindex $extras 4] 2] ne {}} {
+		return -code break
+	}
+	
+	set chatwin [chat::chat_win $chatid]
+	
+	foreach url [regexp -inline -all [format {https*://[^\s]+[%s]} $options(extensions)] $body] {
+		if { $options(shadow_download_image) } {
+			puts $url
+			after 0 [list [namespace current]::imageProcess $url $chatwin]
+		}
+	}
+}
+
+proc vimage::imageProcess { url w } {
+	variable images
+	variable options
+	
+	if { [info exist images($url,data)] == 0 && \
+		$options(shadow_download_image) } {
+			imageGet $url
+			imageCreate $w $url
+	} else {
+			imageCreate $w $url
+	}
+}
+
+proc vimage::imageReload { url w } {
+	variable images
+	
+	array unset images $url,*
+	imageProcess $url $w
+}
+
+proc vimage::imageGet { url } {
+	variable images
+	
+	if { [catch {
+		set token [http::geturl $url -binary 1 \
+			-command [list [namespace current]::imageGetEnd $url] \
+			-blocksize 1000 \
+			-progress [list [namespace current]::imageGetProcess $url] \
+			-timeout 10000]
+		http::wait $token
+	}]} {
+		return [set images($url,full) None]
+	}	
+}
+
+proc vimage::imageGetEnd { url token } {
+	variable images
+	
+	set images($url,data) [http::data $token]
+	http::cleanup $token
+}
+
+proc vimage::imageGetProcess { url token total current } {
+	variable options
+	variable images
+	
+	puts $current
+	
+	if { [expr { round($current / 1024) }] > $options(max_size) || \
+		[expr { round($total / 1024) }] > $options(max_size)} {
+			set images($url,full) Big
+			return [http::reset $token]
+	}
+}
+
+proc vimage::imageCreate { w url } {
+	variable images
+	variable options
+	
+	if { [info exist images($url,full)] == 0 } {
+		if {[catch {set images($url,full) [image create photo -data $images($url,data)]}]} {
+			set images($url,full) None
+		}
+	}
+	
+	$w tag bind "uri $url" <2> [list [namespace current]::imageFullShow $w $url]
+	
+	changeColor $w $url
+	imageUpdate $w $url
+	
+	if { $options(auto_show_image) } {
+		imageFullShow $w $url
+	}
+}
+
+proc vimage::imageUpdate { w url } {
+	if { [winfo exist .fullshow] } { 
+		imageFullShow $w $url
+	}
+}
+
+proc vimage::changeColor { w url } {
+	variable options
+	$w tag configure "uri $url" -background $options(background_active_urls)
+}
+
+proc vimage::changeColorProcess { w url } {
+	variable options
+	$w tag configure "uri $url" -background $options(background_process_urls)
+}
+ 
+proc vimage::imageScale { im xfactor { yfactor 0 } } {
+	set mode -subsample
+	if { abs($xfactor) < 1 } {
+		set xfactor [expr { round(1./$xfactor) }]
+	} elseif { $xfactor >= 0 && $yfactor >= 0 } {
+		set mode -zoom
+	}
+	
+	if { $yfactor == 0 } {
+		set yfactor $xfactor
+	}
+	
+		set dest [image create photo]
+		$dest copy $im
+		$im blank
+		$im copy $dest -shrink $mode $xfactor $yfactor
+		image delete $dest
+}
+
+proc vimage::imageFullShow { w url } {
+	variable images
+	
+	if { [winfo exist .fullshow] } { 
+		destroy .fullshow 
+	}
+
+	toplevel .fullshow
+	
+	wm attributes .fullshow -topmost 1
+	wm attributes .fullshow -toolwindow 1
+	
+	wm title .fullshow [::msgcat::mc "Vimage - view"]
+	wm resizable .fullshow 0 0
+	
+	label .fullshow.image -image $images($url,full)
+	pack .fullshow.image
+	
+	bind .fullshow <1> [list destroy .fullshow]
+	bind .fullshow <3> [list [namespace current]::popup_menu %W %X %Y $images($url,full) $url]
+}
+
+proc vimage::add_view_button { m chatwin X Y x y } {
+	variable options
+	
+	set tags [$chatwin tag names "@$x,$y"]	
+    set idx [lsearch $tags href_*]
+	set idx1 [lsearch $tags uri*]
+	
+	 if { $idx < 0 } {
+		return
+	}
+	
+    if { $idx1 >= 0 } {
+		set url [lindex [lindex $tags $idx1] 1]
+    } else {
+		lassign [$w tag prevrange url "@$x,$y"] a b
+		set url [$w get $a $b]
+    }
+	
+	if { [lsearch -nocase -regexp [file extension $url] $options(extensions)] < 0 } {
+		return -code break
+	}
+	
+	$m add command \
+		-label [::msgcat::mc "Show"] \
+		-command [list [namespace current]::imageProcess $url $chatwin]
+	$m add command \
+		-label [::msgcat::mc "Reload"] \
+		-command [list [namespace current]::imageReload $url $chatwin]
+	$m add command \
+		-label [::msgcat::mc "Compulsory viewing"] \
+		-command [list [namespace current]::imageCompProcess $url $chatwin]
+	$m add separator
+}
+
+proc vimage::imageCompProcess { url w } {
+	variable options
+	variable images
+	
+	set options_max_size_old $options(max_size)
+	set options(max_size) 2000
+	
+	array unset images $url,*
+	imageProcess $url $w
+	
+	set options(max_size) $options_max_size_old
+}
+
+proc vimage::popup_menu { W X Y img url } {
+
+    set m .zomm_popup
+	
+    if {[winfo exists $m]} {
+		destroy $m
+    }
+
+    menu $m -tearoff 0
+	
+	$m add command -label [::msgcat::mc "Save"] \
+			-command [list [namespace current]::imageSave $url]
+	$m add command -label [::msgcat::mc "Back"] \
+			-command [list event generate .fullshow <1>]
+	$m add separator
+	$m add cascade -label  [::msgcat::mc "Zoom"] \
+			-menu [menu $m.zoom -tearoff 0]	
+	$m.zoom add command -label [::msgcat::mc "Zoom in"] \
+			-command [list [namespace current]::imageScale $img 2]
+	$m.zoom add command -label [::msgcat::mc "Zoom out"] \
+			-command [list [namespace current]::imageScale $img 0.5]		
+
+	$m add cascade -label  [::msgcat::mc "Tools"] \
+			-menu [menu $m.tools -tearoff 0]	
+	$m.tools add command -label [::msgcat::mc "Flip LR"] \
+			-command [list [namespace current]::imageScale $img -1 1]
+	$m.tools add command -label [::msgcat::mc "Flip TB"] \
+			-command [list [namespace current]::imageScale $img 1 -1]
+	$m.tools add command -label [::msgcat::mc "Flip both"] \
+			-command [list [namespace current]::imageScale $img -1 -1]
+    
+    tk_popup $m $X $Y
+}
+
+proc vimage::imageSave { url } {
+	variable options
+	variable images
+
+	event generate .fullshow <1>
+	
+	set filename [tk_getSaveFile -initialfile [file tail $url] \
+		-filetypes [list [list [string toupper [file extension $url]] \
+		[file extension $url]]]]
+	
+	
+	if { $filename eq {} } { 
+		return [tk_messageBox -message [::msgcat::mc "Unsaved"] \
+			-title [::msgcat::mc "Unsaved"]]
+	}
+   
+	set fileid [open $filename "WRONLY CREAT"]
+	fconfigure $fileid -translation binary
+	puts $fileid $images($url,data)
+	close $fileid
+	
+	tk_messageBox -message [::msgcat::mc "Saved to %s" $filename] \
+		-title [::msgcat::mc "Saved"]
+}
\ No newline at end of file



More information about the Tkabber-dev mailing list