D-Bus object; only allow a single instance running (bug 62)
Add support for D-Bus to gPodder, and allow only one instance running (the second invocation sends a D-Bus message to the running instance to show the window and then exits).
This commit is contained in:
parent
043309cec4
commit
ac5e804ab0
4 changed files with 39 additions and 4 deletions
1
README
1
README
|
@ -33,6 +33,7 @@
|
|||
* python-gtk2 (minimum 2.6, but >= 2.12 recommended)
|
||||
* python-glade2
|
||||
* python-feedparser
|
||||
* python-dbus
|
||||
|
||||
Additional dependencies for iPod synchronization support:
|
||||
|
||||
|
|
18
bin/gpodder
18
bin/gpodder
|
@ -42,6 +42,9 @@ import os.path
|
|||
import locale
|
||||
import gettext
|
||||
|
||||
import dbus
|
||||
import dbus.glib
|
||||
|
||||
from optparse import OptionParser
|
||||
|
||||
try:
|
||||
|
@ -125,6 +128,15 @@ def main( argv = sys.argv):
|
|||
from gpodder.liblogger import enable_verbose
|
||||
enable_verbose()
|
||||
|
||||
# Try to find an already-running instance of gPodder
|
||||
session_bus = dbus.SessionBus()
|
||||
try:
|
||||
remote_object = session_bus.get_object(gpodder.dbus_bus_name, gpodder.dbus_gui_object_path)
|
||||
from gpodder.liblogger import log
|
||||
log('Found gPodder GUI instance already running')
|
||||
except dbus.exceptions.DBusException:
|
||||
remote_object = None
|
||||
|
||||
from gpodder import console
|
||||
if options.list:
|
||||
console.list_channels()
|
||||
|
@ -140,8 +152,11 @@ def main( argv = sys.argv):
|
|||
console.del_channel( options.delete)
|
||||
elif options.stats:
|
||||
console.sync_stats()
|
||||
elif remote_object is not None:
|
||||
# An instance of GUI is already running
|
||||
remote_object.show_gui_window(dbus_interface=gpodder.dbus_interface)
|
||||
else:
|
||||
#default run gui
|
||||
# gPodder is not yet running - create new instance
|
||||
from gpodder import gui
|
||||
from gpodder.SimpleGladeApp import bindtextdomain
|
||||
import gtk.glade
|
||||
|
@ -166,7 +181,6 @@ def main( argv = sys.argv):
|
|||
gui.app_version = __version__
|
||||
gui.main()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit( main())
|
||||
|
||||
|
|
|
@ -26,3 +26,8 @@ user_agent = 'gPodder'
|
|||
# Are we running in GUI, Maemo or console mode?
|
||||
interface = CLI
|
||||
|
||||
# D-Bus specific interface names
|
||||
dbus_bus_name = 'org.godder'
|
||||
dbus_gui_object_path = '/gui'
|
||||
dbus_interface = 'org.gpodder.interface'
|
||||
|
||||
|
|
|
@ -30,6 +30,10 @@ import time
|
|||
import urllib
|
||||
import urllib2
|
||||
import datetime
|
||||
import dbus
|
||||
import dbus.service
|
||||
import dbus.mainloop
|
||||
import dbus.glib
|
||||
|
||||
from xml.sax import saxutils
|
||||
|
||||
|
@ -340,9 +344,13 @@ class GladeWidget(SimpleGladeApp.SimpleGladeApp):
|
|||
return (result, folder)
|
||||
|
||||
|
||||
class gPodder(GladeWidget):
|
||||
class gPodder(GladeWidget, dbus.service.Object):
|
||||
finger_friendly_widgets = ['btnCancelFeedUpdate', 'label2', 'labelDownloads', 'itemQuit', 'menuPodcasts', 'advanced1', 'menuChannels', 'menuHelp']
|
||||
ENTER_URL_TEXT = _('Enter podcast URL...')
|
||||
|
||||
def __init__(self, bus_name):
|
||||
dbus.service.Object.__init__(self, object_path=gpodder.dbus_gui_object_path, bus_name=bus_name)
|
||||
GladeWidget.__init__(self)
|
||||
|
||||
def new(self):
|
||||
if gpodder.interface == gpodder.MAEMO:
|
||||
|
@ -3015,6 +3023,10 @@ class gPodder(GladeWidget):
|
|||
else:
|
||||
self.label2.set_text(_('Podcasts'))
|
||||
|
||||
@dbus.service.method(gpodder.dbus_interface)
|
||||
def show_gui_window(self):
|
||||
self.gPodder.present()
|
||||
|
||||
class gPodderChannel(GladeWidget):
|
||||
finger_friendly_widgets = ['btn_website', 'btnOK', 'channel_description', 'label19', 'label37', 'label31']
|
||||
|
||||
|
@ -4559,7 +4571,10 @@ def main():
|
|||
gobject.threads_init()
|
||||
gtk.window_set_default_icon_name( 'gpodder')
|
||||
|
||||
gPodder().run()
|
||||
session_bus = dbus.SessionBus(mainloop=dbus.glib.DBusGMainLoop())
|
||||
bus_name = dbus.service.BusName(gpodder.dbus_bus_name, bus=session_bus)
|
||||
gp = gPodder(bus_name)
|
||||
gp.run()
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue