summaryrefslogtreecommitdiff
path: root/nephilim/plugins/Songinfo.py
blob: 6334d67c3c99823d4c24d178579c742656124d4e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#
#    Copyright (C) 2009 Anton Khirnov <wyskas@gmail.com>
#
#    Nephilim is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    Nephilim is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with Nephilim.  If not, see <http://www.gnu.org/licenses/>.
#

from PyQt4 import QtGui, QtCore

from ..plugin import Plugin

class Songinfo(Plugin):
    o = None
    def _load(self):
        self.o = SonginfoWidget(self)

    def _unload(self):
        self.o = None

    def info(self):
        return 'Provides information about a song.'

    def _get_dock_widget(self):
        return self._create_dock(self.o)

class SonginfoWidget(QtGui.QWidget):
    plugin = None
    labels = {}

    def __init__(self, plugin):
        QtGui.QWidget.__init__(self)
        self.plugin = plugin

        self.setLayout(QtGui.QVBoxLayout())

        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])

        self.plugin.mpclient.song_changed.connect(self.on_song_change)

    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))))