deskbar-applet r2559 - in trunk: . deskbar/core deskbar/handlers/actions



Author: sebp
Date: Mon Feb  9 17:46:24 2009
New Revision: 2559
URL: http://svn.gnome.org/viewvc/deskbar-applet?rev=2559&view=rev

Log:
* deskbar/core/Utils.py:
Added uri_has_default_handler function
    
* deskbar/handlers/actions/ShowUrlAction.py:
Check if there's an default application to open the url in is_valid

Modified:
   trunk/ChangeLog
   trunk/deskbar/core/Utils.py
   trunk/deskbar/handlers/actions/ShowUrlAction.py

Modified: trunk/deskbar/core/Utils.py
==============================================================================
--- trunk/deskbar/core/Utils.py	(original)
+++ trunk/deskbar/core/Utils.py	Mon Feb  9 17:46:24 2009
@@ -209,7 +209,7 @@
     if appinfo != None:
         appinfo.launch([gfile], None)
     else:
-        LOGGER.error("Could not detect default application for %s", uri.get_uri())
+        LOGGER.error("Could not detect default application for %s", gfile.get_uri())
 
 def launch_default_for_uri_and_scheme(uri_string):
     """
@@ -224,7 +224,23 @@
     if appinfo != None:
         appinfo.launch_uris([uri_string], None)
     else:
-        LOGGER.error("Could not detect default application for %s", uri.get_uri())
+        LOGGER.error("Could not detect default application for %s", gfile.get_uri())
+        
+def uri_has_default_handler(uri_string):
+    """
+    Returns True if there's a default application
+    to open the specified URI
+    @type uri_string: str 
+    """
+    gfile = gio.File(uri=uri_string)
+    try:
+        appinfo = gfile.query_default_handler(None)
+    except Exception, e:
+        LOGGER.error("Error retrieving default application for %s: %s",
+                     gfile.get_uri(), str(e))
+        return False
+    
+    return (appinfo != None)
     
 def url_show_file(url, escape=True):
     """

Modified: trunk/deskbar/handlers/actions/ShowUrlAction.py
==============================================================================
--- trunk/deskbar/handlers/actions/ShowUrlAction.py	(original)
+++ trunk/deskbar/handlers/actions/ShowUrlAction.py	Mon Feb  9 17:46:24 2009
@@ -1,6 +1,6 @@
 import deskbar.interfaces.Action
 from gettext import gettext as _
-from deskbar.core.Utils import url_show
+from deskbar.core.Utils import url_show, uri_has_default_handler
 import cgi
 
 class ShowUrlAction(deskbar.interfaces.Action):
@@ -28,4 +28,7 @@
         url_show(self._url)
         
     def get_tooltip(self, text=None):
-        return cgi.escape(self._url)
\ No newline at end of file
+        return cgi.escape(self._url)
+    
+    def is_valid(self):
+        return uri_has_default_handler(self._url)
\ No newline at end of file



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