Make opening a browser window a top-level function.
authorNeal H. Walfield <neal@walfield.org>
Sun, 27 Nov 2011 16:35:50 +0000 (17:35 +0100)
committerNeal H. Walfield <neal@walfield.org>
Sun, 27 Nov 2011 17:00:58 +0000 (18:00 +0100)
src/FeedingIt.py

index b143b0b..6672c46 100644 (file)
@@ -149,6 +149,28 @@ def notify(message):
         get_iface()
         doit()
 
+def open_in_browser(link):
+    bus = dbus.SessionBus()
+    b_proxy = bus.get_object("com.nokia.osso_browser",
+                             "/com/nokia/osso_browser/request")
+    b_iface = dbus.Interface(b_proxy, 'com.nokia.osso_browser')
+
+    notify("Opening %s" % link)
+
+    # We open the link asynchronously: if the web browser is not
+    # already running, this can take a while.
+    def error_handler():
+        """
+        Something went wrong opening the URL.
+        """
+        def e(exception):
+            notify("Error opening %s: %s" % (link, str(exception)))
+        return e
+
+    b_iface.open_new_window(link,
+                            reply_handler=lambda *args: None,
+                            error_handler=error_handler())
+
 ##
 # Removes HTML or XML character references and entities from a text string.
 #
@@ -804,26 +826,7 @@ class DisplayArticle(hildon.StackableWindow):
         if link == None:
             link = self.currentUrl
 
-        bus = dbus.SessionBus()
-        b_proxy = bus.get_object("com.nokia.osso_browser",
-                                 "/com/nokia/osso_browser/request")
-        b_iface = dbus.Interface(b_proxy, 'com.nokia.osso_browser')
-
-        notify("Opening %s" % link)
-
-        # We open the link asynchronously: if the web browser is not
-        # already running, this can take a while.
-        def error_handler():
-            """
-            Something went wrong opening the URL.
-            """
-            def e(exception):
-                notify("Error opening %s: %s" % (link, str(exception)))
-            return e
-
-        b_iface.open_new_window(link,
-                                reply_handler=lambda *args: None,
-                                error_handler=error_handler())
+        open_in_browser(link)
 
 class DisplayFeed(hildon.StackableWindow):
     def __init__(self, listing, config):