deskbar-applet r2530 - in trunk: . deskbar/handlers



Author: sebp
Date: Thu Jan 22 17:47:49 2009
New Revision: 2530
URL: http://svn.gnome.org/viewvc/deskbar-applet?rev=2530&view=rev

Log:
Fixed bug #419211: Web search in new a browser window
    
Add match to view the search results in the browser.
Assign priority to Google matches.


Modified:
   trunk/ChangeLog
   trunk/deskbar/handlers/googlesearch.py
   trunk/deskbar/handlers/yahoo.py

Modified: trunk/deskbar/handlers/googlesearch.py
==============================================================================
--- trunk/deskbar/handlers/googlesearch.py	(original)
+++ trunk/deskbar/handlers/googlesearch.py	Thu Jan 22 17:47:49 2009
@@ -163,9 +163,14 @@
         LOGGER.debug("Returning Google answer for: %s", qstring)
         
         if not 'Error' in results:
-            for result in results:
-                matches.append( GoogleMatch(result) )
-            self._emit_query_ready(qstring, matches)
+            num_results = len(results)
+            for i, result in enumerate(results):
+                print result
+                prio = self.get_priority() + num_results - i
+                matches.append(GoogleMatch(result, priority=prio))
+            
+        matches.append(GoogleSearchForMatch(qstring, priority=self.get_priority()))    
+        self._emit_query_ready(qstring, matches)
 
     def has_config(self):
         return True
@@ -214,6 +219,34 @@
         return self.url
         
 
+class SearchWithGoogleAction(ShowUrlAction):
+    """
+    Open the Google search page with results
+    for the given query
+    """
+    
+    BASE_URL = "http://www.google.com/search?%s";
+    
+    def __init__(self, term):
+        url = self.BASE_URL % urllib.urlencode({'q': term})
+        ShowUrlAction.__init__(self, term, url)
+
+    def get_verb(self):
+        return _("Search <b>Google</b> for <i>%(name)s</i>")
+
+class GoogleSearchForMatch(deskbar.interfaces.Match):
+    """
+    Search Google for the given query
+    """
+    
+    def __init__(self, term=None, **args):
+        deskbar.interfaces.Match.__init__ (self, category="web", icon="google.png", **args)
+        self._term = term
+        self.add_action( SearchWithGoogleAction(self._term) )
+    
+    def get_hash(self):
+        return "google:"+self._term
+
 class GoogleConfigDialog(gtk.Dialog):
     """
     

Modified: trunk/deskbar/handlers/yahoo.py
==============================================================================
--- trunk/deskbar/handlers/yahoo.py	(original)
+++ trunk/deskbar/handlers/yahoo.py	Thu Jan 22 17:47:49 2009
@@ -209,6 +209,8 @@
                                       summary=result_summary,
                                       priority=result_prio))
             
+        matches.append(YahooSearchForMatch(qstring, priority=self.get_priority()))
+            
         LOGGER.debug("Returning yahoo answer for: %s", qstring)
         self._emit_query_ready(qstring, matches)
         
@@ -316,7 +318,7 @@
         self.add_action( SearchWithYahooAction(self._term) )
     
     def get_hash(self):
-        return self._term
+        return "yahoo:"+self._term
        
 class YahooSuggestHandler(deskbar.interfaces.Module):
     



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]