summaryrefslogtreecommitdiff
path: root/nephilim/mpclient.py
diff options
context:
space:
mode:
authorAnton Khirnov <wyskas@gmail.com>2009-05-18 20:15:53 +0200
committerAnton Khirnov <wyskas@gmail.com>2009-05-18 20:15:53 +0200
commit78482a6cec42aabd8735a71277ce3e2c78ab8b9a (patch)
treecfba8f1150fd40e1b287e00d8ecfc0e7b3a7cc6c /nephilim/mpclient.py
parent4be456af9a3dc999b65b66fb1db925ec169610be (diff)
mpclient: use stats cmd to query db update.
Diffstat (limited to 'nephilim/mpclient.py')
-rw-r--r--nephilim/mpclient.py37
1 files changed, 24 insertions, 13 deletions
diff --git a/nephilim/mpclient.py b/nephilim/mpclient.py
index 9b1a948..de7e81f 100644
--- a/nephilim/mpclient.py
+++ b/nephilim/mpclient.py
@@ -32,11 +32,13 @@ class MPClient(QtCore.QObject):
_status = {'volume' : 0, 'repeat' : 0, 'random' : 0,
'songid' : 0, 'playlist' : 0, 'playlistlength' : 0,
'time' : 0, 'length' : 0, 'xfade' : 0,
- 'updatings_db' : 0,'state' : 'stop', 'single' : 0,
+ 'state' : 'stop', 'single' : 0,
'consume' : 0}
_commands = None
- _timer_id = None
+ _timer_id = None #for querying status changes
+ _db_timer_id = None #for querying db updates
+ _db_update = None #time of last db update
_retr_mutex = QtCore.QMutex()
@@ -82,8 +84,8 @@ class MPClient(QtCore.QObject):
self.emit(QtCore.SIGNAL('connected'))
self.logger.info('Successfully connected to MPD.')
- self.timerEvent(None)
- self._timer_id = self.startTimer(500)
+ self._timer_id = self.startTimer(500)
+ self._db_timer_id = self.startTimer(10000)
return True
def disconnect_mpd(self):
"""Disconnect from MPD."""
@@ -101,6 +103,9 @@ class MPClient(QtCore.QObject):
if self._timer_id:
self.killTimer(self._timer_id)
self._timer_id = None
+ if self._db_timer_id:
+ self.killTimer(self._db_timer_id)
+ self._db_timer_id = None
self._status = dict(MPClient._status)
self._cur_song = None
self._cur_lib = []
@@ -192,6 +197,9 @@ class MPClient(QtCore.QObject):
def commands(self):
"""List all currently available MPD commands."""
return self._commands
+ def stats(self):
+ """Get MPD statistics."""
+ return self._retrieve(self._client.stats)
def repeat(self, val):
"""Set repeat playlist to val (True/False)."""
@@ -234,7 +242,7 @@ class MPClient(QtCore.QObject):
def play(self, id = None):
"""Play song with ID id or next song if id is None."""
- self.logger.info('Starting playback %s.'%('of id %d'%id if id else ''))
+ self.logger.info('Starting playback %s.'%('of id %s'%(id) if id else ''))
if not self._check_command_ok('play'):
return
if id:
@@ -309,6 +317,7 @@ class MPClient(QtCore.QObject):
self.logger.error('Error adding files: %s.'%e)
self._update_playlist()
if self._status['state'] == 'stop' and ret:
+ print ret
self.play(ret[0])
def move(self, source, target):
"""Move the songs in playlist. Takes a list of source ids and one target position."""
@@ -377,8 +386,6 @@ class MPClient(QtCore.QObject):
ret['length'] = 0
ret['time'] = 0
- if not 'updatings_db' in ret:
- ret['updatings_db'] = 0
if not 'songid' in ret:
ret['songid'] = -1
@@ -392,6 +399,16 @@ class MPClient(QtCore.QObject):
def timerEvent(self, event):
"""Check for changes since last check."""
+ if event.timerId == self._db_timer_id:
+ #timer for monitoring db changes
+ db_update = self.stats()['db_update']
+ if db_update > self._db_update:
+ self.logger.info('Database updated.')
+ self._db_update = db_update
+ self.emit(QtCore.SIGNAL('db_updated'))
+ return
+
+
old_status = self._status
self._status = self._update_status()
@@ -427,9 +444,3 @@ class MPClient(QtCore.QObject):
if self._status['playlist'] != old_status['playlist']:
self._update_playlist()
self.emit(QtCore.SIGNAL('playlist_changed'))
-
- if self._status['updatings_db'] and not old_status['updatings_db']:
- self.emit(QtCore.SIGNAL('update_started'))
- if not self._status['updatings_db'] and old_status['updatings_db']:
- self._update_lib()
- self.emit(QtCore.SIGNAL('update_finished'))