~ubuntu-branches/ubuntu/oneiric/emesene/oneiric-proposed

« back to all changes in this revision

Viewing changes to emesene/plugins/music/DBusBase.py

  • Committer: Bazaar Package Importer
  • Author(s): Devid Antonio Filoni
  • Date: 2011-03-19 13:47:22 UTC
  • mfrom: (1.1.10 upstream) (5.2.9 sid)
  • Revision ID: james.westby@ubuntu.com-20110319134722-5yjs8aa0xbcbze37
Tags: 2.0~git20110319+dfsg-1
* Set myself as maintainer.
* New upstream git revision, tarball generated removing non-free dlls dir.
* Remove debian/watch, debian/emesene.xpm, debian/install files.
* Update debian/README.source file.
* Remove 21_svn2451_fix_avatar and 20_dont_build_own_libmimic patches.
* debian/control: modify python to python (>= 2.5) in Build-Depends field.
* debian/control: remove python-libmimic from Recommends field.
* debian/control: modify python-gtk2 (>= 2.10) to python-gtk2 (>= 2.12) in
  Depends field.
* debian/control: add python-appindicator and python-xmpp to Recommends
  field.
* debian/control: add python-papyon (>= 0.5.4) and python-webkit to Depends
  field.
* debian/control: update Description field.
* debian/control: add python-setuptools to Build-Depends field.
* debian/control: move python-dbus and python-notify to Depends field.
* Update debian/copyright file.
* Update debian/links file.
* debian/menu: update description field.
* Bump Standards-Version to 3.9.1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
import songretriever
2
 
 
3
 
ROOT_NAME = 'org.freedesktop.DBus'
4
 
ROOT_PATH = '/org/freedesktop/DBus'
5
 
 
6
 
class DBusBase(songretriever.MusicHandler):
7
 
    '''Handler for music players that use D-Bus'''
8
 
 
9
 
    def __init__(self, main_window, iface_name, iface_path):
10
 
        songretriever.MusicHandler.__init__(self, main_window)
11
 
        
12
 
        self.iface_name = iface_name
13
 
        self.iface_path = iface_path
14
 
 
15
 
        try:
16
 
            import dbus
17
 
            dbus_version = getattr(dbus, 'version', (0, 0, 0))
18
 
            if dbus_version >= (0, 41, 0) and dbus_version < (0, 80, 0):
19
 
                dbus.SessionBus()
20
 
                import dbus.glib
21
 
            elif dbus_version >= (0, 80, 0):
22
 
                from dbus.mainloop.glib import DBusGMainLoop
23
 
                DBusGMainLoop(set_as_default = True)
24
 
                dbus.SessionBus()
25
 
            else:
26
 
                print 'python-dbus is too old, please update'
27
 
                raise
28
 
        except dbus.DBusException, error:
29
 
            print 'Unable to use D-Bus: %s' % str(error)
30
 
 
31
 
        # dbus session, this is set in reconnect.
32
 
        self.bus = None
33
 
        # dbus interface set in reconnect.
34
 
        self.iface = None
35
 
        self.module = dbus
36
 
        self.root = dbus.SessionBus().get_object(ROOT_NAME, ROOT_PATH)
37
 
 
38
 
    def reconnect(self):
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()
43
 
        try:
44
 
            self.iface = self.bus.get_object(self.iface_name, self.iface_path)
45
 
            return True
46
 
        except self.module.DBusException, error:
47
 
            self.iface = None
48
 
            print 'D-Bus error: %s' % str(error)
49
 
            return False
50
 
 
51
 
    def is_running(self):
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:
56
 
                self.reconnect()
57
 
            return True
58
 
        else:
59
 
            self.iface = None
60
 
            return False
61
 
 
62
 
    def is_playing(self):
63
 
        '''Returns True if a song is being played'''
64
 
        ''' This MUST be overriden'''
65
 
        return False
66
 
 
67
 
    def get_current_song(self):
68
 
        '''Returns the current song in the correct format'''
69
 
        ''' This MUST be overriden'''
70
 
        return False
71
 
 
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))
76