3
ROOT_NAME = 'org.freedesktop.DBus'
4
ROOT_PATH = '/org/freedesktop/DBus'
6
class DBusBase(songretriever.MusicHandler):
7
'''Handler for music players that use D-Bus'''
9
def __init__(self, main_window, iface_name, iface_path):
10
songretriever.MusicHandler.__init__(self, main_window)
12
self.iface_name = iface_name
13
self.iface_path = iface_path
17
dbus_version = getattr(dbus, 'version', (0, 0, 0))
18
if dbus_version >= (0, 41, 0) and dbus_version < (0, 80, 0):
21
elif dbus_version >= (0, 80, 0):
22
from dbus.mainloop.glib import DBusGMainLoop
23
DBusGMainLoop(set_as_default = True)
26
print 'python-dbus is too old, please update'
28
except dbus.DBusException, error:
29
print 'Unable to use D-Bus: %s' % str(error)
31
# dbus session, this is set in reconnect.
33
# dbus interface set in reconnect.
36
self.root = dbus.SessionBus().get_object(ROOT_NAME, ROOT_PATH)
39
'''method to attemp a reconnection, via dbus, this is only
40
called if the bus object is not initialized'''
41
''' You don't need to override this'''
42
self.bus = self.module.SessionBus()
44
self.iface = self.bus.get_object(self.iface_name, self.iface_path)
46
except self.module.DBusException, error:
48
print 'D-Bus error: %s' % str(error)
52
'''Returns a True if the player is running'''
53
''' You don't need to override this'''
54
if self.is_name_active(self.iface_name):
55
if self.iface is None:
63
'''Returns True if a song is being played'''
64
''' This MUST be overriden'''
67
def get_current_song(self):
68
'''Returns the current song in the correct format'''
69
''' This MUST be overriden'''
72
def is_name_active(self, name):
73
'''return True if the name is active on dbus'''
74
''' You don't need to override this'''
75
return bool(self.root.NameHasOwner(name))