← Back to team overview

cairo-dock-team team mailing list archive

[Merge] lp:~eduardo-mucelli/cairo-dock-plug-ins-extras/WebSearch into lp:cairo-dock-plug-ins-extras

 

Eduardo Mucelli R. Oliveira has proposed merging lp:~eduardo-mucelli/cairo-dock-plug-ins-extras/WebSearch into lp:cairo-dock-plug-ins-extras.

Requested reviews:
  Cairo-Dock Team (cairo-dock-team)


WebSearch now fetch results from Digg. Changing the thumb download directory handling.
-- 
https://code.launchpad.net/~eduardo-mucelli/cairo-dock-plug-ins-extras/WebSearch/+merge/26352
Your team Cairo-Dock Team is requested to review the proposed merge of lp:~eduardo-mucelli/cairo-dock-plug-ins-extras/WebSearch into lp:cairo-dock-plug-ins-extras.
=== modified file 'WebSearch/Changelog.txt'
--- WebSearch/Changelog.txt	2010-05-23 23:23:52 +0000
+++ WebSearch/Changelog.txt	2010-05-28 23:42:26 +0000
@@ -1,3 +1,4 @@
+1.3.0: (May/28/2010): WebSearch now fetch results from Digg. Changing the thumb download directory handling.
 1.2.1: (May/23/2010): Working around a bug in Ruby-dbus to construct list of sub-icons which description contains encoded characters.
 1.2.0: (May/21/2010): WebSearch now fetch results from Twitter. Fixing a bug that I introduced in the code refactoring, forget that some engines use page, and some use offset. Modularizing the engines. Shortening the description the same way as the url because some tweets are very long. Engine class now uses a neat way for lazy-loading and engine instantiation.
 1.1.0: (May/17/2010): WebSearch now fetch results from ImageShack. Sub-menu is using icons to a better engine indication.

=== modified file 'WebSearch/WebSearch'
--- WebSearch/WebSearch	2010-05-23 23:23:52 +0000
+++ WebSearch/WebSearch	2010-05-28 23:42:26 +0000
@@ -244,12 +244,13 @@
 			offset = self.page_of_displayed_links * self.number_of_displayed_links		# the position of the first link in the self.engine.links array
 			if self.engine.links.size <= offset											# user already scrolled by the fetched links, fetch more
 				inform_start_of_waiting_process
-				self.engine.links = case self.engine.name								# receive the fetched links
-					# some engines use the concept of offset which is the first index of an interval of links/images to be shown
-					# but there is those that use a sequential page (1,2,3, ...) which has an amount of links/images, etc
-					when "Google", "Bing", "Yahoo", "Webshots", "Wikipedia"; self.engine.retrieve_links(self.query, offset)
-					when "Teoma","Youtube","Flickr","ImageShack","Twitter"; self.engine.retrieve_links(self.query, self.page_of_displayed_links + 1)
-				end
+                # some engines use the concept of offset which is the first index of an interval of links/images to be shown
+				# but there is those that use a sequential page (1,2,3, ...) which has an amount of links/images, etc
+                if Engines.paginated_by_page?(self.engine.name)                         # see ./lib/Engines.rb
+                    self.engine.links = self.engine.retrieve_links(self.query, self.page_of_displayed_links + 1)
+                else																	# paginated by offset
+                    self.engine.links = self.engine.retrieve_links(self.query, offset)
+                end
 				inform_end_of_waiting_process
 		    end
 			self.page_of_displayed_links += 1											# sequential page identification, lets go to the next

=== modified file 'WebSearch/WebSearch.conf'
--- WebSearch/WebSearch.conf	2010-05-23 23:23:52 +0000
+++ WebSearch/WebSearch.conf	2010-05-28 23:42:26 +0000
@@ -1,4 +1,4 @@
-#!en;1.2.1
+#!en;1.3.0
 
 #[gtk-about]
 [Icon]
@@ -83,7 +83,7 @@
 #[gtk-preferences]
 [Configuration]
 
-#l[Google;Bing;Yahoo!;Teoma;Youtube;Webshots;Flickr;Wikipedia;ImageShack;Twitter] Search engine :
+#l[Google;Bing;Yahoo!;Teoma;Youtube;Webshots;Flickr;Wikipedia;ImageShack;Twitter;Digg] Search engine :
 engine = 0
 #i[5;10] Maximum number of results shown :
 #{in sub-icons.}
@@ -92,6 +92,6 @@
 show current page = true
 #b Show the description of the result instead of its URL in the sub-icons ?
 show description instead url = true
-#b Enable thumbnail preview for Youtube, Webshots, Flickr, and ImageShack searches ?
+#b Enable thumbnail preview for Youtube, Webshots, Flickr, ImageShack, Twitter, and Digg searches ?
 #{for slow connections, disable will result in significantly faster fetching.}
 show thumbnail preview = true

=== modified file 'WebSearch/auto-load.conf'
--- WebSearch/auto-load.conf	2010-05-23 23:23:52 +0000
+++ WebSearch/auto-load.conf	2010-05-28 23:42:26 +0000
@@ -10,4 +10,4 @@
 category = 2
 
 # Version of the applet; change it everytime you change something in the config file. Don't forget to update the version both in this file and in the config file.
-version = 1.2.1
+version = 1.3.0

=== removed directory 'WebSearch/images'
=== removed directory 'WebSearch/images/data'
=== removed file 'WebSearch/images/data/Bing.png'
Binary files WebSearch/images/data/Bing.png	2010-05-18 13:47:51 +0000 and WebSearch/images/data/Bing.png	1970-01-01 00:00:00 +0000 differ
=== removed file 'WebSearch/images/data/Flickr.png'
Binary files WebSearch/images/data/Flickr.png	2010-05-23 23:23:52 +0000 and WebSearch/images/data/Flickr.png	1970-01-01 00:00:00 +0000 differ
=== removed file 'WebSearch/images/data/Google.png'
Binary files WebSearch/images/data/Google.png	2010-05-23 23:23:52 +0000 and WebSearch/images/data/Google.png	1970-01-01 00:00:00 +0000 differ
=== removed file 'WebSearch/images/data/ImageShack.png'
Binary files WebSearch/images/data/ImageShack.png	2010-05-18 13:47:51 +0000 and WebSearch/images/data/ImageShack.png	1970-01-01 00:00:00 +0000 differ
=== removed file 'WebSearch/images/data/Teoma.png'
Binary files WebSearch/images/data/Teoma.png	2010-05-18 13:47:51 +0000 and WebSearch/images/data/Teoma.png	1970-01-01 00:00:00 +0000 differ
=== removed file 'WebSearch/images/data/Twitter.png'
Binary files WebSearch/images/data/Twitter.png	2010-05-23 23:23:52 +0000 and WebSearch/images/data/Twitter.png	1970-01-01 00:00:00 +0000 differ
=== removed file 'WebSearch/images/data/Webshots.png'
Binary files WebSearch/images/data/Webshots.png	2010-05-23 23:23:52 +0000 and WebSearch/images/data/Webshots.png	1970-01-01 00:00:00 +0000 differ
=== removed file 'WebSearch/images/data/Wikipedia.png'
Binary files WebSearch/images/data/Wikipedia.png	2010-05-23 23:23:52 +0000 and WebSearch/images/data/Wikipedia.png	1970-01-01 00:00:00 +0000 differ
=== removed file 'WebSearch/images/data/Yahoo.png'
Binary files WebSearch/images/data/Yahoo.png	2010-05-23 23:23:52 +0000 and WebSearch/images/data/Yahoo.png	1970-01-01 00:00:00 +0000 differ
=== removed file 'WebSearch/images/data/Youtube.png'
Binary files WebSearch/images/data/Youtube.png	2010-05-18 13:47:51 +0000 and WebSearch/images/data/Youtube.png	1970-01-01 00:00:00 +0000 differ
=== removed directory 'WebSearch/images/flickr'
=== removed directory 'WebSearch/images/imageshack'
=== removed directory 'WebSearch/images/twitter'
=== removed directory 'WebSearch/images/webshots'
=== removed directory 'WebSearch/images/youtube'
=== modified file 'WebSearch/lib/Engine.rb'
--- WebSearch/lib/Engine.rb	2010-05-23 23:23:52 +0000
+++ WebSearch/lib/Engine.rb	2010-05-28 23:42:26 +0000
@@ -1,8 +1,8 @@
 class Engine 																			# Factory + Inheritance
 
+	require './lib/Engines.rb'
 	require './lib/Link.rb'
 	require './lib/Exceptions.rb'
-	require './lib/Engines.rb'
 
 	attr_accessor :name, :stats, :links, :base_url, :query_url
 

=== modified file 'WebSearch/lib/Engines.rb'
--- WebSearch/lib/Engines.rb	2010-05-22 02:13:02 +0000
+++ WebSearch/lib/Engines.rb	2010-05-28 23:42:26 +0000
@@ -10,7 +10,15 @@
 	FLICKR = "Flickr"
 	IMAGESHACK = "ImageShack"
 	TWITTER = "Twitter"
-	List = [GOOGLE, BING, YAHOO, TEOMA, WIKIPEDIA, YOUTUBE, WEBSHOTS, FLICKR, IMAGESHACK, TWITTER]
+	DIGG = "Digg"
+	
+	# All the engines. Help to create the list of strings controlled by mouse scroll to be shown in the icon
+	List = [GOOGLE, BING, YAHOO, TEOMA, WIKIPEDIA, YOUTUBE, WEBSHOTS, FLICKR, IMAGESHACK, TWITTER, DIGG]
+    
+    # some engines use the concept of offset which is the first index of an interval of links/images to be shown
+	# but there is those that use a sequential page (1,2,3, ...) which has an amount of links/images, etc
+    PaginatedByPage = [TEOMA, YOUTUBE, FLICKR, IMAGESHACK, TWITTER, DIGG]
+#	PaginatedByOffset = [GOOGLE, BING, YAHOO, WEBSHOTS, WIKIPEDIA]
 
 	def self.exists? (engine)
 		List.include? engine
@@ -19,4 +27,14 @@
 	def self.at (index)
 		List.at index
 	end
+
+    # since there is just pagination by page or offset, only one of the following
+    # methods would solve, but for readability I choose write both
+    def self.paginated_by_page?(engine)
+        PaginatedByPage.include?(engine)
+    end
+
+#	def self.paginated_by_offset?(engine)
+#		PaginatedByOffset.include?(engine)
+#	end
 end

=== modified file 'WebSearch/lib/Flickr.rb'
--- WebSearch/lib/Flickr.rb	2010-05-22 02:13:02 +0000
+++ WebSearch/lib/Flickr.rb	2010-05-28 23:42:26 +0000
@@ -15,7 +15,7 @@
 			url = res['href']
 			description = res['title']
 			thumb_url = res.at("img")['src']
-			self.links << ThumbnailedLink.new("#{self.base_url}#{url}", description, thumb_url)
+			self.links << ThumbnailedLink.new("#{self.base_url}#{url}", description, thumb_url, self.name)
 		end
 		self.links
 	end

=== modified file 'WebSearch/lib/ImageShack.rb'
--- WebSearch/lib/ImageShack.rb	2010-05-22 02:13:02 +0000
+++ WebSearch/lib/ImageShack.rb	2010-05-28 23:42:26 +0000
@@ -7,12 +7,13 @@
 		super
 	end
 
+    # ImageShack does not provide image description
 	def retrieve_links(query, page = 1)
 		imageshack = Nokogiri::HTML.parse(open("#{self.query_url}#{query}&page=#{page}"))
 		(imageshack/"a[@class='search_result']").each do |res|
 			url = res['href']
 			thumb_url = res.at("img")['src']
-			self.links << ThumbnailedLink.new(url, "", thumb_url)
+			self.links << ThumbnailedLink.new(url, "", thumb_url, self.name)
 		end
 		self.links
 	end

=== modified file 'WebSearch/lib/Link.rb'
--- WebSearch/lib/Link.rb	2010-05-23 23:23:52 +0000
+++ WebSearch/lib/Link.rb	2010-05-28 23:42:26 +0000
@@ -12,16 +12,7 @@
 	end
 
 	def to_utf8
-		# Strings like "OpenSUSE のインス" generate encoding "OpenSUSE \343\201\256\343\202\244\343\203"
-		# If this is passed to ruby-dbus as a string parameter of any method, the error described bellow occurs
-		# Martin Vidner was contacted by me about it
-		# --
-		#/usr/local/lib/site_ruby/1.8/dbus/bus.rb:432:in `read_nonblock': end of file reached (EOFError)
-		#	from /usr/local/lib/site_ruby/1.8/dbus/bus.rb:432:in `update_buffer'
-		#	from /usr/local/lib/site_ruby/1.8/dbus/bus.rb:478:in `wait_for_message'
-		#	from /usr/local/lib/site_ruby/1.8/dbus/bus.rb:492:in `send_sync'
-		#	from (eval):22:in `AddSubIcons'
-		Iconv.iconv('ascii//ignore//translit', 'utf-8', self).to_s
+		Iconv.iconv('ascii//ignore//translit', 'utf-8', self).to_s						# what cannot be translitered in UTF-8, must be ignored
 	end
 end
 
@@ -29,9 +20,9 @@
 	attr_accessor :url, :description, :id, :icon, :shortened_url
 	@@next_id = 0																		# sequential id "static"
 
-	def initialize (url = "", description = "", icon = File.expand_path("./icon"))
+	def initialize (url, description, icon = File.expand_path("./icon"))
 		self.url = url
-		self.description = description.shorten.to_utf8									# description shortened by default
+		self.description = description.shorten.to_utf8									# Dbus parameters must to be string encoded in UTF-8
 		self.id = @@next_id += 1
 		self.icon = icon
 		self.shortened_url = url.shorten
@@ -43,34 +34,27 @@
 end
 
 class ThumbnailedLink < Link															# a nice refactoring with the old YoutubeLink class
-	attr_accessor :image_id, :thumb_url, :thumb_path, :downloaded_thumb
+	attr_accessor :image_id, :thumb_url, :downloaded_thumb, :engine
 	@@next_image_id = 0
 
-	def initialize(url = "", description = "", thumb_url = "")
+	def initialize(url, description, thumb_url, engine)
 		super(url, description)
 		self.thumb_url = thumb_url
 		self.image_id = @@next_image_id += 1
-		self.thumb_path = define_thumbnail_path
+        self.engine = engine                                                            # just to define the output directory
 		self.downloaded_thumb = false													# keep track of which thumbs were downloaded
 	end
 
 	def download_thumbnail																# remember that is being threaded outside
 		# download thumb quietly (q), name it (O) '#{image_id}.jpg' and take it to the directory named as engine
-		IO.popen("wget -q '#{self.thumb_url}' -O #{self.thumb_path}") do |io|			# important enclose url in single quotes cuz there is '&'
+        thumb_path = "./images/#{self.engine}/#{self.image_id}.jpg"                     # search engine name == directory name
+		IO.popen("wget -q '#{self.thumb_url}' -O #{thumb_path}") do |io|			    # important enclose url in single quotes cuz there is '&'
 			IO.select([io], nil, nil, 0.5)												# non-blocking download through the pipe
 		end
 		self.downloaded_thumb = true
-		self.icon = File.expand_path(self.thumb_path)
+		self.icon = File.expand_path(thumb_path)
 	end
 
-	# Thumbnail path composed by the search engine and image id
-	# Extract from the thumb_url the what is the search engine using the the core of the url
-	def define_thumbnail_path
-		directories = %w(youtube webshots flickr imageshack twitter)					# search engine name == directory name
-		directory = directories.detect {|d| self.url.include?(d)}						# search for engines names in url
-		"./images/#{directory}/#{self.image_id}.jpg"
-	end	
-
 	def downloaded_thumb?
 		self.downloaded_thumb
 	end

=== modified file 'WebSearch/lib/Twitter.rb'
--- WebSearch/lib/Twitter.rb	2010-05-22 02:13:02 +0000
+++ WebSearch/lib/Twitter.rb	2010-05-28 23:42:26 +0000
@@ -10,13 +10,16 @@
 	# thumb_url, e.g., http://a1.twimg.com/profile_images/768793556/n12430139_39051956_3639_normal.jpg ; twitter does not change the original pic name
 	# description, e.g, Dusty, I hope you literally kill Miguel Cairo with your words after today. #RedsFAIL
 	def retrieve_links(query, page = 1)
-		twitter = Nokogiri::HTML.parse(open("#{self.query_url}#{query}&page=#{page}"))
+		search = "#{self.query_url}#{query}&page=#{page}"
+		WebSearch.log search
+		twitter = Nokogiri::HTML.parse(open(search))
 		(twitter/"div[@id='results']/ul").each do |res|
 			(res/"li").each do |raw_result|
 				thumb_url = raw_result.at("div[@class='avatar']/a/img")['src']							# the thumb of the avatar which tweeted
 				description = raw_result.at("div[@class='msg']/span[@class^='msgtxt']").inner_text		# the tweet text
 				url = raw_result.at("div[@class='info']/a[@class='lit']")['href']						# url of the tweet
-				self.links << ThumbnailedLink.new(url, description, thumb_url)
+				WebSearch.log "#{url} #{thumb_url} #{description}"
+				self.links << ThumbnailedLink.new(url, description, thumb_url, self.name)
 			end
 		end
 		self.links

=== modified file 'WebSearch/lib/Webshots.rb'
--- WebSearch/lib/Webshots.rb	2010-05-22 02:13:02 +0000
+++ WebSearch/lib/Webshots.rb	2010-05-28 23:42:26 +0000
@@ -16,7 +16,7 @@
 			url = res['href']
 			description = res['title']
 			thumb_url = res.at("img[@class='searchListItemImg']")['src']
-			self.links << ThumbnailedLink.new(url, description, thumb_url)
+			self.links << ThumbnailedLink.new(url, description, thumb_url, self.name)
 		end
 		self.links
 	end

=== modified file 'WebSearch/lib/Youtube.rb'
--- WebSearch/lib/Youtube.rb	2010-05-22 02:13:02 +0000
+++ WebSearch/lib/Youtube.rb	2010-05-28 23:42:26 +0000
@@ -17,7 +17,7 @@
 			description = res.inner_text
 			video_id = url.split('=').last												# /watch?v=WwojCsQ3Fa8 => WwojCsQ3Fa8 => video_id
 			thumb_url = "http://i4.ytimg.com/vi/#{video_id}/default.jpg";
-			self.links << ThumbnailedLink.new("#{self.base_url}#{url}", description, thumb_url)
+			self.links << ThumbnailedLink.new("#{self.base_url}#{url}", description, thumb_url, self.name)
 		end
 		self.links
 	end