From: Neal H. Walfield Date: Sun, 4 Sep 2011 11:19:51 +0000 (+0200) Subject: Open external links asynchronously. X-Git-Url: https://vcs.maemo.org/git/?a=commitdiff_plain;h=f20b9080c94c4bdcb6995c5d2662b14d748898b6;p=feedingit Open external links asynchronously. --- diff --git a/src/FeedingIt.py b/src/FeedingIt.py index a48251f..84d223a 100644 --- a/src/FeedingIt.py +++ b/src/FeedingIt.py @@ -127,6 +127,30 @@ FEED_TEMPLATE_UNREAD = '\n'.join((head, active_sub)) ENTRY_TEMPLATE = entry_head ENTRY_TEMPLATE_UNREAD = entry_active_head +notification_iface = None +def notify(message): + def get_iface(): + global notification_iface + + bus = dbus.SessionBus() + proxy = bus.get_object('org.freedesktop.Notifications', + '/org/freedesktop/Notifications') + notification_iface \ + = dbus.Interface(proxy, 'org.freedesktop.Notifications') + + def doit(): + notification_iface.SystemNoteInfoprint("FeedingIt: " + message) + + if notification_iface is None: + get_iface() + + try: + doit() + except dbus.DBusException: + # Rebind the name and try again. + get_iface() + doit() + ## # Removes HTML or XML character references and entities from a text string. # @@ -708,14 +732,29 @@ class DisplayArticle(hildon.StackableWindow): self.set_for_removal = True def open_in_browser(self, object, link=None): - import dbus - bus = dbus.SessionBus() - proxy = bus.get_object("com.nokia.osso_browser", "/com/nokia/osso_browser/request") - iface = dbus.Interface(proxy, 'com.nokia.osso_browser') if link == None: - iface.open_new_window(self.currentUrl) - else: - iface.open_new_window(link) + 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()) class DisplayFeed(hildon.StackableWindow): def __init__(self, listing, feed, title, key, config):