summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2013-04-25 09:36:35 +0200
committerAnton Khirnov <anton@khirnov.net>2013-04-25 10:11:29 +0200
commit9fbc47d89b6f696cce2d68caf4509c7d1f222bfe (patch)
tree3bbe7d775a4723b7e4addf98818e1647d3c35d5e
parent360ad0cf82395ff42dde4bea31bbd13b7d417163 (diff)
mpclient: cache the database locally.
-rw-r--r--nephilim/mpclient.py20
-rw-r--r--nephilim/plugins/Library.py2
2 files changed, 14 insertions, 8 deletions
diff --git a/nephilim/mpclient.py b/nephilim/mpclient.py
index 46dd324..2a454c5 100644
--- a/nephilim/mpclient.py
+++ b/nephilim/mpclient.py
@@ -116,6 +116,12 @@ class MPClient(QtCore.QObject):
status = None
"""A Song object representing current song."""
cur_song = None
+ """
+ A dictionary of Song objects representing all songs currently in the database,
+ indexed by their paths.
+ Changes when db_updated() signal is emitted.
+ """
+ db = None
# SIGNALS
connect_changed = Signal(bool)
@@ -158,6 +164,7 @@ class MPClient(QtCore.QObject):
self._commands = []
self.status = MPDStatus()
self.cur_song = Song()
+ self.db = {}
self.outputs = []
self.urlhandlers = []
@@ -249,12 +256,6 @@ class MPClient(QtCore.QObject):
self._command('shuffle')
## database ##
- def database(self, callback):
- """
- Request database information from MPD. Callback will be called with an
- iterator over all Songs in the database as the argument.
- """
- self._command('listallinfo', callback = lambda data: callback(self._parse_songs(data)))
def update_database(self):
"""
Initiates a database update.
@@ -488,7 +489,7 @@ class MPClient(QtCore.QObject):
'options' in subsystems):
self._command('status', callback = self._update_status)
if 'database' in subsystems:
- self.db_updated.emit()
+ self._command('listallinfo', callback = lambda data: self._update_db(self._parse_songs(data)))
if 'sticker' in subsystems:
self.sticker_changed.emit()
if 'update' in subsystems:
@@ -558,6 +559,11 @@ class MPClient(QtCore.QObject):
else:
self.songpos_changed.emit(self.cur_song)
+ def _update_db(self, songs):
+ for song in songs:
+ self.db[song['file']] = song
+ self.db_updated.emit()
+
def _update_playcount(self, song):
if not 'file' in song or os.path.isabs(song['file']):
return
diff --git a/nephilim/plugins/Library.py b/nephilim/plugins/Library.py
index 3ff6242..3aa49f9 100644
--- a/nephilim/plugins/Library.py
+++ b/nephilim/plugins/Library.py
@@ -99,7 +99,7 @@ class LibraryWidget(QtGui.QWidget):
def fill_library(self):
self.logger.info('Refreshing library.')
- self.plugin.mpclient.database(lambda songs: self.library_model.fill(songs, self.foldings.currentText().split('/')))
+ self.library_model.fill(self.plugin.mpclient.db.values(), self.foldings.currentText().split('/'))
@Slot(unicode)
def filter_library(self, text):