← 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 Rezende 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 keeps a history of recently searched terms.
-- 
https://code.launchpad.net/~eduardo-mucelli/cairo-dock-plug-ins-extras/WebSearch/+merge/29808
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.
=== added file 'WebSearch/.history'
=== modified file 'WebSearch/Changelog.txt'
--- WebSearch/Changelog.txt	2010-06-29 12:45:12 +0000
+++ WebSearch/Changelog.txt	2010-07-13 16:09:39 +0000
@@ -1,3 +1,4 @@
+1.4.0: (July/13/2010: WebSearch now keeps a history of recently searched terms.
 1.3.1: (June/29/2010: URL encoding was not being done. Fixed it.
 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.

=== modified file 'WebSearch/WebSearch'
--- WebSearch/WebSearch	2010-05-28 23:39:57 +0000
+++ WebSearch/WebSearch	2010-07-13 16:09:39 +0000
@@ -71,8 +71,9 @@
 	class Applet
 
 		require './lib/Engine.rb'
+		require './lib/History.rb'
 
-		attr_accessor 	:engine, :engines, :query,
+		attr_accessor 	:engine, :engines, :query, :history,
 						:number_of_fetched_links, :number_of_displayed_links, :page_of_displayed_links,
 						:show_current_page, :show_description_instead_url, :show_thumbnail_preview,
 						:scroll_engine_index
@@ -81,7 +82,8 @@
 
 		def initialize applet, sub_icons
 			self.query = ""
-			self.engines = Engines::List												# ./lib/Engines.rb
+			self.engines = Engines.list												    # ./lib/Engines.rb
+            self.history = History.entries                                              # ./lib/History.rb
 			self.engine = Engine.new
 			self.scroll_engine_index = 0												# current index when scrolling through search engines
 			@icon = applet
@@ -136,34 +138,61 @@
 				action_on_middle_click_sub_icon sub_icon_id
 			end
 		end
-
+        
+        # Building context menu
 		def action_on_build_menu
-			item = {}
-			items = []
+			begin
+				@icon.AddMenuItems(build_menu_for_engines)
+                @icon.AddMenuItems(build_menu_for_history)
+			rescue NoMethodError														# Cairo-Dock < 2.1.4-0beta0
+				WebSearch.log "AddMenuItems method is not available"
+				@icon.PopulateMenu(self.engines)
+			end
+		end
+
+        def build_menu_for_engines
+            items = []
 			self.engines.each_with_index do |engine, i|									# each property must do be string and never use Symbol
+			    item = {}
 				item['type'] = 0
 				item['label'] = engine
 				item['menu'] = 1
 				item['id'] = i
 				item['icon'] = File.expand_path("./images/data/#{engine}.png")
 				items.push item
-				item = {}
-			end	
-			begin
-				@icon.AddMenuItems(items)
-			rescue NoMethodError														# Cairo-Dock < 2.1.4-0beta0
-				WebSearch.log "AddMenuItems method is not available"
-				@icon.PopulateMenu(self.engines)
 			end
-		end
+            items
+        end
+
+        def build_menu_for_history
+            # The engines' index (id) of the WebSearch sub-menu ranges from 0 to self.engines.size-1 consequently, the first id of
+            # the history menu is the self.engines.size. Even if the number of engines change, the self.engine size will keep track of it
+            history_sub_menu_index = self.engines.size
+            history_sub_menu_icon = File.expand_path("./images/data/history.png")
+            history_sub_menu = [{'type' => 1, 'label' => 'History', 'menu' => 0, 'id' => history_sub_menu_index, 'icon' => history_sub_menu_icon}]
+            history_sub_menu_entry_index = history_sub_menu_index                       # subsequent indexes are used in the history entries
+            self.history.each do |entry|                                                # construct the history sub-menu entries
+                item = {}
+                item['type'] = 0
+				item['label'] = entry.chop
+				item['menu'] = history_sub_menu_index
+                history_sub_menu_entry_index += 1
+				item['id'] = history_sub_menu_entry_index
+                item['icon'] = history_sub_menu_icon
+				history_sub_menu.push item
+            end
+            history_sub_menu
+        end
 
 		def ask_for_search_query
-			@icon.AskText("Search for:", "#{self.query}")
+			@icon.AskText("Search for:", "#{self.query}")                               # the value in the text field is the previous used term
 		end
 
 		def action_on_answer answer
 			unless answer.empty?
 				reset_search_settings unless self.query.empty?
+                History.save_new_entry answer                                           # append (if necessary) the query term in the history file
+                self.history = History.entries                                          # refresh local entries of the historyu
 				self.query = answer
 				begin
 					self.engine = self.engine.connect									# only when the fetch is imminent the engine connection occurs
@@ -206,9 +235,20 @@
 			end
 		end
 
-		# Changing the search engine by context menu
-		def action_on_menu_select param
-			switch_search_engine param
+        # There is a sequential index in the context menu and it is divided in two sections
+        #   Section I - Indexes for search engines ranging from 0 to self.engines.size - 1
+        #   Section II - Indexes for history terms' entries ranging from self.engines.size + 1 to max number of entries in the history (NumberOfEntries see ./lib/History.rb)
+        #   Note - The index self.engines.size is the one used to place the "History" label actually creating the sub-menu. See first lines in  build_menu_for_history method
+        # This method treats both the selection of search engine, as trigger a search with a term coming from the history
+		def action_on_menu_select selected_menu_index
+            # an index that came from a click in one of the engines from WebSearch sub-menu
+            if selected_menu_index < self.engines.size
+    			switch_search_engine selected_menu_index
+            else    # user can be only clicked on the History sub-menu
+                # shift the history menu ids to make them range from 0 to self.history-1 (History.entries from ./lib/History.rb)
+                history_entry_term = self.history[selected_menu_index - self.engines.size - 1]
+                action_on_answer history_entry_term
+            end
 		end
 
 		def action_on_reload_module config_has_changed
@@ -220,7 +260,7 @@
 			if self.query.empty?														# before the first query it is possible scroll through engines
 				if scroll_up
 					switch_search_engine self.scroll_engine_index +=1					# drawback: user scrolls a lot for up/down and this variable
-				else																	# gets a value far from (0..self.engines.length-1) limits.
+				else																	# gets a value far from (0..self.engines.size-1) limits.
 					switch_search_engine self.scroll_engine_index -=1					# user need to scroll back a lot to get in these limits again
 				end
 			else																		# later the first query scroll through the resulting pages
@@ -234,7 +274,7 @@
 
 		def switch_search_engine index
 			index = 0 if index < 0														# keep the lower limit
-			index = self.engines.length - 1 if index > self.engines.length - 1			# keep the upper limit
+			index = self.engines.size - 1 if index > self.engines.size - 1			# keep the upper limit
 			self.engine.name = self.engines.at(index)
 			reset_search_settings														# clean the previous search when choosing a new one
 			inform_current_search_engine												# inform in the bottom of the icon what is the new engine

=== modified file 'WebSearch/WebSearch.conf'
--- WebSearch/WebSearch.conf	2010-06-29 12:45:12 +0000
+++ WebSearch/WebSearch.conf	2010-07-13 16:09:39 +0000
@@ -1,4 +1,4 @@
-#!en;1.3.1
+#!en;1.4.0
 
 #[gtk-about]
 [Icon]

=== modified file 'WebSearch/auto-load.conf'
--- WebSearch/auto-load.conf	2010-06-29 12:45:12 +0000
+++ WebSearch/auto-load.conf	2010-07-13 16:09:39 +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.3.1
+version = 1.4.0

=== added file 'WebSearch/images/data/history.png'
Binary files WebSearch/images/data/history.png	1970-01-01 00:00:00 +0000 and WebSearch/images/data/history.png	2010-07-13 16:09:39 +0000 differ
=== modified file 'WebSearch/lib/Bing.rb'
--- WebSearch/lib/Bing.rb	2010-06-29 12:45:12 +0000
+++ WebSearch/lib/Bing.rb	2010-07-13 16:09:39 +0000
@@ -1,3 +1,9 @@
+# This is a part of the external WebSearch applet for Cairo-Dock
+# Author: Eduardo Mucelli Rezende Oliveira
+# E-mail: edumucelli@xxxxxxxxx or eduardom@xxxxxxxxxxx
+#
+# This module fetch results from Bing - www.bing.com
+
 class Bing < Engine
 
 	def initialize

=== modified file 'WebSearch/lib/Digg.rb'
--- WebSearch/lib/Digg.rb	2010-06-29 12:45:12 +0000
+++ WebSearch/lib/Digg.rb	2010-07-13 16:09:39 +0000
@@ -1,3 +1,9 @@
+# This is a part of the external WebSearch applet for Cairo-Dock
+# Author: Eduardo Mucelli Rezende Oliveira
+# E-mail: edumucelli@xxxxxxxxx or eduardom@xxxxxxxxxxx
+#
+# This module fetch results from Digg, including thumbnails - www.digg.com
+
 class Digg < Engine
 
 	def initialize

=== modified file 'WebSearch/lib/Engine.rb'
--- WebSearch/lib/Engine.rb	2010-05-28 23:39:57 +0000
+++ WebSearch/lib/Engine.rb	2010-07-13 16:09:39 +0000
@@ -1,4 +1,11 @@
-class Engine 																			# Factory + Inheritance
+# This is a part of the external WebSearch applet for Cairo-Dock
+# Author: Eduardo Mucelli Rezende Oliveira
+# E-mail: edumucelli@xxxxxxxxx or eduardom@xxxxxxxxxxx
+#
+# This module acts as a Factory + Inheritance
+# It connects the WebSearch to the right search engine module
+
+class Engine
 
 	require './lib/Engines.rb'
 	require './lib/Link.rb'

=== modified file 'WebSearch/lib/Engines.rb'
--- WebSearch/lib/Engines.rb	2010-05-28 23:39:57 +0000
+++ WebSearch/lib/Engines.rb	2010-07-13 16:09:39 +0000
@@ -1,3 +1,10 @@
+# This is a part of the external WebSearch applet for Cairo-Dock
+# Author: Eduardo Mucelli Rezende Oliveira
+# E-mail: edumucelli@xxxxxxxxx or eduardom@xxxxxxxxxxx
+#
+# This module organizes the available search engines
+# New engines must be added here and verify its pagination type
+
 module Engines
 	
 	GOOGLE = "Google"
@@ -13,25 +20,29 @@
 	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]
+	@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]
+    @PaginatedByPage = [TEOMA, YOUTUBE, FLICKR, IMAGESHACK, TWITTER, DIGG]
 #	PaginatedByOffset = [GOOGLE, BING, YAHOO, WEBSHOTS, WIKIPEDIA]
 
+    def self.list
+        @List
+    end
+
 	def self.exists? (engine)
-		List.include? engine
+		@List.include? engine
 	end
 
 	def self.at (index)
-		List.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)
+        @PaginatedByPage.include?(engine)
     end
 
 #	def self.paginated_by_offset?(engine)

=== modified file 'WebSearch/lib/Flickr.rb'
--- WebSearch/lib/Flickr.rb	2010-06-29 12:45:12 +0000
+++ WebSearch/lib/Flickr.rb	2010-07-13 16:09:39 +0000
@@ -1,3 +1,9 @@
+# This is a part of the external WebSearch applet for Cairo-Dock
+# Author: Eduardo Mucelli Rezende Oliveira
+# E-mail: edumucelli@xxxxxxxxx or eduardom@xxxxxxxxxxx
+#
+# This module fetch results from Flickr, including thumbnails - www.flickr.com
+
 class Flickr < Engine
 	
 	def initialize

=== modified file 'WebSearch/lib/Google.rb'
--- WebSearch/lib/Google.rb	2010-06-29 12:45:12 +0000
+++ WebSearch/lib/Google.rb	2010-07-13 16:09:39 +0000
@@ -1,3 +1,8 @@
+# This is a part of the external WebSearch applet for Cairo-Dock
+# Author: Eduardo Mucelli Rezende Oliveira
+# E-mail: edumucelli@xxxxxxxxx or eduardom@xxxxxxxxxxx
+#
+# This module fetch results from Google - www.google.com
 class Google < Engine
 
 	#attr_accessor :name, :stats, :links, :base_url, :query_url, :number_of_fetched_links

=== added file 'WebSearch/lib/History.rb'
--- WebSearch/lib/History.rb	1970-01-01 00:00:00 +0000
+++ WebSearch/lib/History.rb	2010-07-13 16:09:39 +0000
@@ -0,0 +1,35 @@
+# This is a part of the external WebSearch applet for Cairo-Dock
+# Author: Eduardo Mucelli Rezende Oliveira
+# E-mail: edumucelli@xxxxxxxxx or eduardom@xxxxxxxxxxx
+#
+# This module deals with the History file that is used to compose
+# the context menu "History"
+
+module History
+    
+    @Entries = []
+    NumberOfEntries = 10
+    @file = '.history'
+
+    # Return and fill the list of history terms
+    def self.entries
+        # it is important to bring a reversed list in which the most recent search term appears on the top (first) of the list 
+        @Entries = IO.readlines(@file).reverse.first(NumberOfEntries)
+    end
+
+    # Save (if necessary) the new entry in the history file
+    def self.save_new_entry (entry)
+        unless @Entries.include? entry                                                  # if doest not existe yet ...
+            File.open(@file, 'a') {|file| file.puts entry}                              # append the new entry at the end of the file
+        end
+    end
+
+    def self.empty?
+        @Entries.empty?
+    end
+
+    def self.clear
+        File.delete(@file)
+        File.open(@file, 'w')
+    end
+end

=== modified file 'WebSearch/lib/ImageShack.rb'
--- WebSearch/lib/ImageShack.rb	2010-06-29 12:45:12 +0000
+++ WebSearch/lib/ImageShack.rb	2010-07-13 16:09:39 +0000
@@ -1,3 +1,9 @@
+# This is a part of the external WebSearch applet for Cairo-Dock
+# Author: Eduardo Mucelli Rezende Oliveira
+# E-mail: edumucelli@xxxxxxxxx or eduardom@xxxxxxxxxxx
+#
+# This module fetch results from ImageShack, including thumbnails - www.imageshack.us
+
 class ImageShack < Engine
 
 	def initialize

=== modified file 'WebSearch/lib/Link.rb'
--- WebSearch/lib/Link.rb	2010-05-28 23:39:57 +0000
+++ WebSearch/lib/Link.rb	2010-07-13 16:09:39 +0000
@@ -1,3 +1,11 @@
+# This is a part of the external WebSearch applet for Cairo-Dock
+# Author: Eduardo Mucelli Rezende Oliveira
+# E-mail: edumucelli@xxxxxxxxx or eduardom@xxxxxxxxxxx
+#
+# This module makes the Link abstraction with two classes,
+# I - Link, links that does not have related thumb image
+# II - ThumnailedLink, links from sites which have thumbnail also deals with thumb download 
+
 class String
 
 	require 'iconv'

=== modified file 'WebSearch/lib/Teoma.rb'
--- WebSearch/lib/Teoma.rb	2010-06-29 12:45:12 +0000
+++ WebSearch/lib/Teoma.rb	2010-07-13 16:09:39 +0000
@@ -1,3 +1,9 @@
+# This is a part of the external WebSearch applet for Cairo-Dock
+# Author: Eduardo Mucelli Rezende Oliveira
+# E-mail: edumucelli@xxxxxxxxx or eduardom@xxxxxxxxxxx
+#
+# This module fetch results from Teoma - www.teoma.com
+
 class Teoma < Engine
 
 	def initialize

=== modified file 'WebSearch/lib/Twitter.rb'
--- WebSearch/lib/Twitter.rb	2010-06-29 12:45:12 +0000
+++ WebSearch/lib/Twitter.rb	2010-07-13 16:09:39 +0000
@@ -1,3 +1,9 @@
+# This is a part of the external WebSearch applet for Cairo-Dock
+# Author: Eduardo Mucelli Rezende Oliveira
+# E-mail: edumucelli@xxxxxxxxx or eduardom@xxxxxxxxxxx
+#
+# This module fetch results from Twitter, including thumbnails - www.twitter.com
+
 class Twitter < Engine
 
 	def initialize

=== modified file 'WebSearch/lib/Webshots.rb'
--- WebSearch/lib/Webshots.rb	2010-06-29 12:45:12 +0000
+++ WebSearch/lib/Webshots.rb	2010-07-13 16:09:39 +0000
@@ -1,3 +1,9 @@
+# This is a part of the external WebSearch applet for Cairo-Dock
+# Author: Eduardo Mucelli Rezende Oliveira
+# E-mail: edumucelli@xxxxxxxxx or eduardom@xxxxxxxxxxx
+#
+# This module fetch results from Webshots, including thumbnails - www.webshots.com
+
 class Webshots < Engine
 	
 	def initialize

=== modified file 'WebSearch/lib/Wikipedia.rb'
--- WebSearch/lib/Wikipedia.rb	2010-06-29 12:45:12 +0000
+++ WebSearch/lib/Wikipedia.rb	2010-07-13 16:09:39 +0000
@@ -1,3 +1,9 @@
+# This is a part of the external WebSearch applet for Cairo-Dock
+# Author: Eduardo Mucelli Rezende Oliveira
+# E-mail: edumucelli@xxxxxxxxx or eduardom@xxxxxxxxxxx
+#
+# This module fetch results from Wikipedia - en.wikipedia.org
+
 class Wikipedia < Engine
 
 	attr_accessor :number_of_fetched_links

=== modified file 'WebSearch/lib/Yahoo.rb'
--- WebSearch/lib/Yahoo.rb	2010-06-29 12:45:12 +0000
+++ WebSearch/lib/Yahoo.rb	2010-07-13 16:09:39 +0000
@@ -1,3 +1,9 @@
+# This is a part of the external WebSearch applet for Cairo-Dock
+# Author: Eduardo Mucelli Rezende Oliveira
+# E-mail: edumucelli@xxxxxxxxx or eduardom@xxxxxxxxxxx
+#
+# This module fetch results from Yahoo! - www.yahoo.com
+
 class Yahoo < Engine
 
 	def initialize

=== modified file 'WebSearch/lib/Youtube.rb'
--- WebSearch/lib/Youtube.rb	2010-06-29 12:45:12 +0000
+++ WebSearch/lib/Youtube.rb	2010-07-13 16:09:39 +0000
@@ -1,3 +1,9 @@
+# This is a part of the external WebSearch applet for Cairo-Dock
+# Author: Eduardo Mucelli Rezende Oliveira
+# E-mail: edumucelli@xxxxxxxxx or eduardom@xxxxxxxxxxx
+#
+# This module fetch results from Youtube, including thumbnails - www.youtube.com
+
 class Youtube < Engine
 	
 	def initialize


Follow ups