2 # Copyright (C) 2009 Anton Khirnov <wyskas@gmail.com>
4 # Nephilim is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
9 # Nephilim is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with Nephilim. If not, see <http://www.gnu.org/licenses/>.
18 from PyQt4
import QtGui
, QtCore
20 from ..plugin
import Plugin
22 class Songinfo(Plugin
):
24 info
= 'Displays song metadata provided by MPD.'
31 def __init__(self
, parent
, mpclient
, name
):
32 Plugin
.__init
__(self
, parent
, mpclient
, name
)
37 self
.o
= SonginfoWidget(self
)
38 self
.mpclient
.song_changed
.connect(self
.refresh
)
39 self
.mpclient
.connect_changed
.connect(self
.__update
_tagtypes
)
42 self
.mpclient
.song_changed
.disconnect(self
.refresh
)
43 self
.mpclient
.connect_changed
.disconnect(self
.__update
_tagtypes
)
46 def __update_tagtypes(self
):
47 self
.__tags
= self
.mpclient
.tagtypes()
48 self
.o
.set_tagtypes(self
.__tags
)
50 def _get_dock_widget(self
):
51 return self
._create
_dock
(self
.o
)
54 self
.logger
.info('Refreshing.')
56 song
= self
.mpclient
.current_song()
58 for tag
in self
.__tags
:
59 metadata
[tag
] = song
.tag(tag
, '') if song
else ''
60 self
.o
.set_metadata(metadata
)
62 class SonginfoWidget(QtGui
.QWidget
):
66 def __init__(self
, plugin
):
67 QtGui
.QWidget
.__init
__(self
)
70 self
.setLayout(QtGui
.QGridLayout())
72 def set_tagtypes(self
, tagtypes
):
73 """Setup labels for each tagtype in the list."""
74 for i
in range(self
.layout().rowCount()):
75 it
= self
.layout().itemAtPosition(i
, 0)
76 it1
= self
.layout().itemAtPosition(i
, 1)
78 self
.layout().removeItem(it
)
79 it
.widget().setParent(None)
81 self
.layout().removeItem(it1
)
82 it1
.widget().setParent(None)
86 label
= QtGui
.QLabel('<b>%s</b>'%tag
.title()) #TODO sort known tags
87 label1
= QtGui
.QLabel() # tag value will go here
88 label1
.setTextInteractionFlags(QtCore
.Qt
.TextSelectableByMouse
)
89 label
.setWordWrap(True)
90 label1
.setWordWrap(True)
91 self
.layout().addWidget(label
, len(self
.__labels
), 0, QtCore
.Qt
.AlignRight
)
92 self
.layout().addWidget(label1
, len(self
.__labels
), 1)
93 self
.__labels
[tag
] = label1
95 def set_metadata(self
, metadata
):
96 """Set displayed metadata, which is provided in a dict of { tag : value }."""
98 self
.__labels
[tag
].setText(unicode(metadata
[tag
]))