If an instance of FeedingIt is running, send it to the front and quit.
authorNeal H. Walfield <neal@walfield.org>
Mon, 5 Sep 2011 12:03:43 +0000 (14:03 +0200)
committerNeal H. Walfield <neal@walfield.org>
Mon, 5 Sep 2011 12:03:43 +0000 (14:03 +0200)
 - 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.

src/FeedingIt.py
src/feedingitdbus.py

index da6c0f4..68fb7db 100644 (file)
@@ -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")
index 145f569..77869b7 100644 (file)
@@ -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
 
 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"
+