From: Neal H. Walfield Date: Mon, 5 Sep 2011 12:03:43 +0000 (+0200) Subject: If an instance of FeedingIt is running, send it to the front and quit. X-Git-Url: https://vcs.maemo.org/git/?a=commitdiff_plain;h=74b0dc2ace136e0524fe6a25a733d0dd0a5e0b3b;p=feedingit If an instance of FeedingIt is running, send it to the front and quit. - Grab org.maemo.feedingit exclusively (don't queue). - If we fail to get it, invoke org.maemo.feedingit.GrabFocus. - Implement org.maemo.feedingit.GrabFocus to bring the application to the front. --- diff --git a/src/FeedingIt.py b/src/FeedingIt.py index da6c0f4..68fb7db 100644 --- a/src/FeedingIt.py +++ b/src/FeedingIt.py @@ -1462,6 +1462,9 @@ class FeedingIt: status = "No unread items" return status + def grabFocus(self): + self.window.present() + if __name__ == "__main__": mainthread.init () debugging.init(dot_directory=".feedingit", program_name="feedingit") diff --git a/src/feedingitdbus.py b/src/feedingitdbus.py index 145f569..77869b7 100644 --- a/src/feedingitdbus.py +++ b/src/feedingitdbus.py @@ -2,6 +2,7 @@ # # Copyright (c) 2007-2008 INdT. +# Copyright (c) 2011 Neal H. Walfield # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation, either version 3 of the License, or @@ -25,11 +26,29 @@ import dbus import dbus.service +import sys +import logging +logger = logging.getLogger(__name__) class ServerObject(dbus.service.Object): def __init__(self, app): # Here the service name - bus_name = dbus.service.BusName('org.maemo.feedingit',bus=dbus.SessionBus()) + bus = dbus.SessionBus() + try: + bus_name = dbus.service.BusName( + 'org.maemo.feedingit', bus=bus, do_not_queue=True) + except dbus.NameExistsException: + try: + logger.info("FeedingIt appears to already be running. " + + "Sending other instance to front.") + + proxy = bus.get_object('org.maemo.feedingit', + '/org/maemo/feedingit') + iface = dbus.Interface(proxy, 'org.maemo.feedingit') + iface.GrabFocus() + finally: + sys.exit(0) + # Here the object path dbus.service.Object.__init__(self, bus_name, '/org/maemo/feedingit') self.app = app @@ -55,3 +74,9 @@ class ServerObject(dbus.service.Object): #self.app.buttonFeedClicked(None, self.app, None, key) self.app.openArticle(key, id) return "Done" + + @dbus.service.method('org.maemo.feedingit') + def GrabFocus(self): + self.app.grabFocus() + return "Done" +