[js] pool for benshee player only if it is installed

fix mpris track change
This commit is contained in:
Yann Leboulanger 2007-12-12 20:50:34 +00:00
parent d2d92e7de3
commit aa41133f63
1 changed files with 24 additions and 15 deletions

View File

@ -18,6 +18,7 @@
## You should have received a copy of the GNU General Public License ## You should have received a copy of the GNU General Public License
## along with Gajim. If not, see <http://www.gnu.org/licenses/>. ## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
## ##
import os
import gobject import gobject
if __name__ == '__main__': if __name__ == '__main__':
# install _() func before importing dbus_support # install _() func before importing dbus_support
@ -54,7 +55,7 @@ class MusicTrackListener(gobject.GObject):
## MPRIS ## MPRIS
bus.add_signal_receiver(self._mpris_music_track_change_cb, 'TrackChange', bus.add_signal_receiver(self._mpris_music_track_change_cb, 'TrackChange',
'org.freedesktop.MediaPlayer') 'org.freedesktop.MediaPlayer')
bus.add_signal_receiver(self._player_playing_changed_cb, 'StatusChange', bus.add_signal_receiver(self._mpris_playing_changed_cb, 'StatusChange',
'org.freedesktop.MediaPlayer') 'org.freedesktop.MediaPlayer')
@ -77,20 +78,24 @@ class MusicTrackListener(gobject.GObject):
'playingSongPropertyChanged', 'org.gnome.Rhythmbox.Player') 'playingSongPropertyChanged', 'org.gnome.Rhythmbox.Player')
## Banshee ## Banshee
banshee_bus = dbus.SessionBus() # Banshee sucks because it only supports polling.
dubus = banshee_bus.get_object('org.freedesktop.DBus', # Thus, we only register this is we are very sure that it's
'/org/freedesktop/dbus') # installed.
self.dubus_methods = dbus.Interface(dubus, 'org.freedesktop.DBus') if os.name == 'posix' and os.system('which banshee >/dev/null 2>&1') == 0:
self.current_banshee_title = '' banshee_bus = dbus.SessionBus()
self.banshee_paused_before = False dubus = banshee_bus.get_object('org.freedesktop.DBus',
self.banshee_is_here = False '/org/freedesktop/dbus')
gobject.timeout_add(10000, self._check_if_banshee_bus) self.dubus_methods = dbus.Interface(dubus, 'org.freedesktop.DBus')
if self.dubus_methods.NameHasOwner('org.gnome.Banshee'): self.current_banshee_title = ''
self._get_banshee_bus() self.banshee_paused_before = False
self.banshee_is_here = True self.banshee_is_here = False
# Otherwise, it opens Banshee! gobject.timeout_add(10000, self._check_if_banshee_bus)
self.banshee_props ={} if self.dubus_methods.NameHasOwner('org.gnome.Banshee'):
gobject.timeout_add(1000, self._banshee_check_track_status) self._get_banshee_bus()
self.banshee_is_here = True
# Otherwise, it opens Banshee!
self.banshee_props ={}
gobject.timeout_add(1000, self._banshee_check_track_status)
def _check_if_banshee_bus(self): def _check_if_banshee_bus(self):
if self.dubus_methods.NameHasOwner('org.gnome.Banshee'): if self.dubus_methods.NameHasOwner('org.gnome.Banshee'):
@ -131,6 +136,10 @@ class MusicTrackListener(gobject.GObject):
info.duration = int(song['length']) info.duration = int(song['length'])
return info return info
def _mpris_playing_changed_cb(self, playing):
if playing == 2:
self.emit('music-track-changed', None)
def _mpris_music_track_change_cb(self, arg): def _mpris_music_track_change_cb(self, arg):
info = self._mpris_properties_extract(arg) info = self._mpris_properties_extract(arg)
self.emit('music-track-changed', info) self.emit('music-track-changed', info)