[Tkabber-dev] r404 - in trunk/plugins/vimage: . pixmaps

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Mon Sep 27 16:03:10 MSD 2010


Author: Rejjin
Date: 2010-09-27 16:03:10 +0400 (Mon, 27 Sep 2010)
New Revision: 404

Added:
   trunk/plugins/vimage/pixmaps/error.gif
   trunk/plugins/vimage/pixmaps/large.gif
   trunk/plugins/vimage/pixmaps/normal.gif
   trunk/plugins/vimage/pixmaps/process.gif
   trunk/plugins/vimage/pixmaps/stop.gif
Removed:
   trunk/plugins/vimage/pixmaps/big.gif
   trunk/plugins/vimage/pixmaps/none.gif
Modified:
   trunk/plugins/vimage/README
   trunk/plugins/vimage/vimage.tcl
Log:
+++ opportunities
  If the option options (use_progressbar), then when 
  loading images added download status indicator. 
  Left of the indicator button is added to cancel the download.
  The right of the image references are status indicators.
  If the indicator shows a weight - then click on her image reload 
  no limit on the maximum size. If the indicator shows the thumbs 
  down - then click on the indicator image reloads. If the indicator 
  shows the image icon, then click on the indicator opens a 
  downloaded image.

+++ options 
options(use_progressbar):
  Add progressbar and cancel button.

+++ Fixed:
  - bad automatically url download
  - Error with save image
  - Con't show image, if disabled options(auto_show_image)
  - ...

Modified: trunk/plugins/vimage/README
===================================================================
--- trunk/plugins/vimage/README	2010-09-27 10:23:33 UTC (rev 403)
+++ trunk/plugins/vimage/README	2010-09-27 12:03:10 UTC (rev 404)
@@ -2,6 +2,7 @@
 
 
 Usage.
+	+++ Old version
 	This plugin created in order not to run once more browser 
 	to view images. If the plugin is configured accordingly, the 
 	image will be automatically downloaded when a new message 
@@ -19,7 +20,16 @@
 	out image.
 	If you send a link to the image you have already 
 	downloaded, the download will not be repeated.
-
+	+++ Current version
+	If the option options (use_progressbar), then when 
+	loading images added download status indicator. 
+	Left of the indicator button is added to cancel the download.
+	The right of the image references are status indicators.
+	If the indicator shows a weight - then click on her image reload 
+	no limit on the maximum size. If the indicator shows the thumbs 
+	down - then click on the indicator image reloads. If the indicator 
+	shows the image icon, then click on the indicator opens a 
+	downloaded image.
 	
 Setting (Plugins::Vimage options).
 
@@ -31,15 +41,6 @@
 	options(auto_show_image):
 		This option enable automatically opens a window viewing
 		pictures after the download.
-		
-	options(use_colors):
-		if this option is enabled, the link works with this plugin 
-		change color of their background.
-		Downloading - a gray background.
-		Download the picture contains an error - red background.
-		Image exceeds the limit - red background.
-		Download image does not contain 
-		errors and do not exceed the limit - green background.
 
 	options(activate_tkabber):
 		Activates the window Tkabber after download ending.
@@ -47,6 +48,10 @@
 	options(max_size):
 		Limits the maximum size of content (picture).
 		Value indicated in kb.
+	
+	+++ Current version
+	options(use_progressbar):
+		Add progressbar and cancel button.
 		
 	The following options may be absent in some 
 	implementations of Tk!
@@ -57,13 +62,10 @@
 		
 	options(toolwindow):
 		New style box of window with image.
-
 	
 TODO.
 
-	1) Integration of images in the chat.
-	2) Show progressbar of status download images.
-	3) Accurate and rapid mutations both size images.
+	1) Accurate and rapid mutations both size images.
 	
 	
 AUTHOR.

Deleted: trunk/plugins/vimage/pixmaps/big.gif
===================================================================
(Binary files differ)

Added: trunk/plugins/vimage/pixmaps/error.gif
===================================================================
(Binary files differ)


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

Added: trunk/plugins/vimage/pixmaps/large.gif
===================================================================
(Binary files differ)


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

Deleted: trunk/plugins/vimage/pixmaps/none.gif
===================================================================
(Binary files differ)

Added: trunk/plugins/vimage/pixmaps/normal.gif
===================================================================
(Binary files differ)


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

Added: trunk/plugins/vimage/pixmaps/process.gif
===================================================================
(Binary files differ)


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

Added: trunk/plugins/vimage/pixmaps/stop.gif
===================================================================
(Binary files differ)


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

Modified: trunk/plugins/vimage/vimage.tcl
===================================================================
--- trunk/plugins/vimage/vimage.tcl	2010-09-27 10:23:33 UTC (rev 403)
+++ trunk/plugins/vimage/vimage.tcl	2010-09-27 12:03:10 UTC (rev 404)
@@ -18,12 +18,12 @@
 	}	
 
 #	+++	( Default images )
-	image create photo LARGE \
-	-file [file join $script_dir pixmaps big.gif]
-		
-	image create photo ERROR \
-	-file [file join $script_dir pixmaps none.gif]
+	foreach name {large normal process error stop} {
+		image create photo plugins/vimage/$name \
+		-file [file join $script_dir pixmaps ${name}.gif]
+	}
 	
+	
 	if {![::plugins::is_registered vimage]} {
 		::plugins::register vimage \
               -namespace [namespace current] \
@@ -58,16 +58,14 @@
 	return
 	}
 	
-	if { $options(active_is_message) == 0 } {
-	return
-	}
-	
-	set map [format {[http://][^\s]+\.(%s)} $extensions]
+	set map [format {http://[^\s]+\.(%s)} $extensions]
 	set matched [regexp -inline -nocase -all -- $map $body]
 	set chatwin [chat::chat_win $chatid]
 	
-	foreach { url ext } $matched {
-		after 0 [list [namespace current]::image_process $url $chatwin]
+	if { $options(active_is_message) } {
+		foreach { url ext } $matched {
+			after 0 [list [namespace current]::image_process $url $chatwin]
+		}
 	}
 }
 
@@ -102,15 +100,22 @@
 
 proc vimage::image_get { url chatwin } {
 	variable images
+	variable options
 	
 	set ns [namespace current]
 	change_state_url $url $chatwin process
 	
-	set token [http::geturl $url -binary 0 \
+	if {[catch {set token [http::geturl $url -binary 0 \
 		-command [list ${ns}::image_get_end $chatwin $url] \
 		-blocksize 1024 \
 		-progress [list ${ns}::image_get_process $chatwin $url]]
-		
+	}]} {
+		set images($url,full) error
+		return
+	}
+	
+	set options(_download) 1
+	
 	http::wait $token
 }
 
@@ -121,7 +126,7 @@
 	set images($url,data) [http::data $token]
 	del_progressbar
 	http::cleanup $token
-	change_state_url $url $chatwin end
+	change_state_url $url $chatwin normal
 }
 
 
@@ -132,9 +137,15 @@
 	progressbar [namespace current]::progress $total
 	set [namespace current]::progress $current
 	
+	if {!$options(_download)} {
+		set images($url,full) error
+		del_progressbar
+		http::reset $token
+	}
+	
 	set max_size [expr {$options(max_size)*1024}]
-	if { $current > $max_size || $total > $max_size} {
-		set images($url,full) LARGE
+	if { $current > $max_size || $total > $max_size } {
+		set images($url,full) large
 		del_progressbar
 		http::reset $token
 	}
@@ -147,19 +158,31 @@
 	variable images
 	variable options
 	
-	if { [info exist images($url,full)] == 0 } {
+	if { ![info exist images($url,full)] } {
 		set images($url,data) [base64::encode $images($url,data)]
 		if { [catch {set images($url,full) [image create photo -data $images($url,data)]}] } {
-			set images($url,full) ERROR
+			set images($url,full) error
 			change_state_url $url $chatwin error
+			return
 		}
-	} elseif { $images($url,full) eq "ERROR" || $images($url,full) eq "LARGE" } {
+		if { $options(auto_show_image) } {
+			image_full_show $url
+		}
+		return
+	}
+	
+	if { $images($url,full) eq "error" } {
 		change_state_url $url $chatwin error
+		return
 	}
 	
-	if { $options(auto_show_image) } {
-		image_full_show $chatwin $url
+	if { $images($url,full) eq "large" } {
+		change_state_url $url $chatwin large
+		return
 	}
+	
+	change_state_url $url $chatwin normal
+	image_full_show $url
 }
 
 proc vimage::image_scale { im xfactor { yfactor 0 } } {
@@ -190,30 +213,37 @@
 proc vimage::change_state_url { url chatwin type } {
 	variable options
 	
-	if { $options(use_colors) == 0 } {
-		return
+	foreach {start end} [$chatwin tag ranges "uri $url"] {
+		if {[lsearch -exact [$chatwin tag names $start] vimage-$url/$end] < 0} {
+			$chatwin image create $end -image plugins/vimage/$type -padx 3
+			$chatwin tag add vimage-$url/$end $start $end
+			$chatwin tag add vimage-icon-$url/$end $end
+			$chatwin tag bind vimage-icon-$url/$end <1> \
+			[list [namespace current]::on_click_icon $url $chatwin]
+		} else {
+			$chatwin image configure $end -image plugins/vimage/$type
+		}
 	}
+}
+
+proc vimage::on_click_icon { url chatwin } {
+	variable images
 	
-	switch -- $type {
-		process {
-			$chatwin tag configure "uri $url" \
-				-background $options(color-process)
+	if {[info exist images($url,full)]} {
+		switch -- $images($url,full) {
+			large {image_comp_process $url $chatwin}
+			error {image_process $url $chatwin reload}
+			default {image_full_show $url}
 		}
-		end {
-			$chatwin tag configure "uri $url" \
-				-background $options(color-end)
-		}
-		error {
-			$chatwin tag configure "uri $url" \
-				-background $options(color-error)
-		}
+	} else {
+		image_process $url $chatwin
 	}
 }
 
 #################################################
 ######################## view image
 
-proc vimage::image_full_show { w url } {
+proc vimage::image_full_show { url } {
 	variable images
 	variable options
 	
@@ -344,7 +374,7 @@
    
 	set fileid [open $filename "WRONLY CREAT"]
 	fconfigure $fileid -translation binary
-	puts $fileid -nonewline [base64::decode $images($url,data)]
+	puts $fileid [base64::decode $images($url,data)]
 	close $fileid
 }
 
@@ -376,11 +406,15 @@
 			-type normal
 	}
 	
-	pack $win.prb -padx 2
+	button $win.cancel -image plugins/vimage/stop -relief flat \
+	-command [list set [namespace current]::options(_download) 0]
+		
+	pack $win.cancel $win.prb -padx 2 -side left
 }
 
 proc vimage::del_progressbar { } {
-	catch { destroy .mainframe.status.prgf.prb }
+	catch { destroy .mainframe.status.prgf.prb \
+	.mainframe.status.prgf.cancel }
 }
 
 #################################################
@@ -435,24 +469,4 @@
 	custom::defvar options(max_size) 50 \
 	[::msgcat::mc "Maximum size of content (kb)."] \
 	-type string -group Vimage	
-	
-	 custom::defgroup "Vimage colors" \
-	[::msgcat::mc "Vimage colors options"] \
-	-group Vimage	
-	
-	custom::defvar options(use_colors) 1 \
-	[::msgcat::mc "Use color-shemes for image urls."] \
-	-type boolean -group "Vimage colors"
-
-	custom::defvar options(color-process) {#7f7f7f} \
-	[::msgcat::mc "Background color of downloading urls."] \
-	-type string -group "Vimage colors"	
-	
-	custom::defvar options(color-end) {#00ff00} \
-	[::msgcat::mc "Background color of downloaded urls."] \
-	-type string -group "Vimage colors"	
-	
-	custom::defvar options(color-error) {#ff0000} \
-	[::msgcat::mc "Background color of don't downloaded urls. (with error)"] \
-	-type string -group "Vimage colors"	
 }
\ No newline at end of file



More information about the Tkabber-dev mailing list