summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Khirnov <wyskas@gmail.com>2009-08-23 20:37:03 +0200
committerAnton Khirnov <wyskas@gmail.com>2009-08-23 20:37:03 +0200
commit405db9d29530a063475e183a0609d67fc59fe3ac (patch)
tree80be99b09e93db856299563d8f68ce51abea64d6
parente15061c283aea38ee6fffba4e81663550586c6fe (diff)
Songinfo: rewrite to use all metadata from MPD.
-rw-r--r--nephilim/mpclient.py2
-rw-r--r--nephilim/plugins/Songinfo.py75
2 files changed, 57 insertions, 20 deletions
diff --git a/nephilim/mpclient.py b/nephilim/mpclient.py
index a1298b1..35be3f5 100644
--- a/nephilim/mpclient.py
+++ b/nephilim/mpclient.py
@@ -211,7 +211,7 @@ class MPClient(QtCore.QObject):
if not self.__check_command_ok('tagtypes'):
return []
- return self._retrieve(self._client.tagtypes)
+ return map(str.lower, self._retrieve(self._client.tagtypes) + ['file'])
def commands(self):
"""List all currently available MPD commands."""
return self._commands
diff --git a/nephilim/plugins/Songinfo.py b/nephilim/plugins/Songinfo.py
index 960f179..44de8be 100644
--- a/nephilim/plugins/Songinfo.py
+++ b/nephilim/plugins/Songinfo.py
@@ -24,38 +24,75 @@ class Songinfo(Plugin):
info = 'Displays song metadata provided by MPD.'
# public, read-only
- o = None
+ o = None
+ tags = None
+
+ #### public ####
+ def __init__(self, parent, mpclient, name):
+ Plugin.__init__(self, parent, mpclient, name)
+
+ self.__tags = []
+
def _load(self):
self.o = SonginfoWidget(self)
+ self.mpclient.song_changed.connect(self.refresh)
+ self.mpclient.connect_changed.connect(self.__update_tagtypes)
def _unload(self):
+ self.mpclient.song_changed.disconnect(self.refresh)
+ self.mpclient.connect_changed.disconnect(self.__update_tagtypes)
self.o = None
+ def __update_tagtypes(self):
+ self.__tags = self.mpclient.tagtypes()
+ self.o.set_tagtypes(self.__tags)
+
def _get_dock_widget(self):
return self._create_dock(self.o)
+ def refresh(self):
+ self.logger.info('Refreshing.')
+ metadata = {}
+ song = self.mpclient.current_song()
+
+ for tag in self.__tags:
+ metadata[tag] = song.tag(tag, '') if song else ''
+ self.o.set_metadata(metadata)
+
class SonginfoWidget(QtGui.QWidget):
- plugin = None
- labels = {}
+ plugin = None
+ __labels = None
def __init__(self, plugin):
QtGui.QWidget.__init__(self)
- self.plugin = plugin
-
- self.setLayout(QtGui.QVBoxLayout())
+ self.plugin = plugin
+ self.__labels = {}
+ self.setLayout(QtGui.QGridLayout())
- for item in 'track', 'title', 'album', 'disc', 'artist', 'composer', 'date', 'genre', 'file':
- self.labels[item] = QtGui.QLabel('<b>%s</b>:'%item)
- self.labels[item].setWordWrap(True)
- self.layout().addWidget(self.labels[item])
+ def set_tagtypes(self, tagtypes):
+ """Setup labels for each tagtype in the list."""
+ for i in range(self.layout().rowCount()):
+ it = self.layout().itemAtPosition(i, 0)
+ it1 = self.layout().itemAtPosition(i, 1)
+ if it:
+ self.layout().removeItem(it)
+ it.widget().setParent(None)
+ if it1:
+ self.layout().removeItem(it1)
+ it1.widget().setParent(None)
+ self.__labels = {}
- self.plugin.mpclient.song_changed.connect(self.on_song_change)
+ for tag in tagtypes:
+ label = QtGui.QLabel('<b>%s</b>'%tag.title()) #TODO sort known tags
+ label1 = QtGui.QLabel() # tag value will go here
+ label1.setTextInteractionFlags(QtCore.Qt.TextSelectableByMouse)
+ label.setWordWrap(True)
+ label1.setWordWrap(True)
+ self.layout().addWidget(label, len(self.__labels), 0, QtCore.Qt.AlignRight)
+ self.layout().addWidget(label1, len(self.__labels), 1)
+ self.__labels[tag] = label1
- def on_song_change(self):
- song = self.plugin.mpclient.current_song()
- if not song:
- for item in self.labels:
- self.labels[item].setText('<b>%s</b>:'%item)
- else:
- for item in self.labels:
- self.labels[item].setText('<b>%s</b>: %s'%(item, unicode(song.tag(item))))
+ def set_metadata(self, metadata):
+ """Set displayed metadata, which is provided in a dict of { tag : value }."""
+ for tag in metadata:
+ self.__labels[tag].setText(unicode(metadata[tag]))