AlbumCover: use Nephilim logo when there's no cover.
[nephilim.git] / nephilim / plugins / Playlist.py
blobd8147bcf4c5d817876fc23349ab7f360ca2f8078
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
19 from PyQt4.QtCore import QVariant
21 from ..plugin import Plugin
23 class Playlist(Plugin):
24 # public, const
25 info = 'Shows the playlist.'
27 # public, read-only
28 o = None
30 # private
31 DEFAULTS = {'columns': ['track', 'title', 'artist',
32 'date', 'album', 'length']}
34 def _load(self):
35 self.o = PlaylistWidget(self)
37 def _unload(self):
38 self.o = None
40 def _get_dock_widget(self):
41 return self._create_dock(self.o)
43 class PlaylistWidget(QtGui.QWidget):
44 plugin = None
45 playlist = None
47 class PlaylistSongItem(QtGui.QTreeWidgetItem):
48 # public
49 id = -1
51 def __init__(self, id):
52 QtGui.QTreeWidgetItem.__init__(self)
53 self.id = id
55 def __init__(self, plugin):
56 QtGui.QWidget.__init__(self)
57 self.plugin = plugin
59 self.playlist = self.Playlist(self.plugin)
61 self.setLayout(QtGui.QVBoxLayout())
62 self.layout().setSpacing(0)
63 self.layout().setMargin(0)
64 self.layout().addWidget(self.playlist)
66 class Playlist(QtGui.QTreeWidget):
67 song = None
68 plugin = None
70 def __init__(self, plugin):
71 QtGui.QTreeWidget.__init__(self)
72 self.plugin = plugin
74 self.setSelectionMode(QtGui.QTreeWidget.ExtendedSelection)
75 self.setAlternatingRowColors(True)
76 self.setRootIsDecorated(False)
77 columns = self.plugin.settings.value(self.plugin.name + '/columns').toStringList()
78 self.setColumnCount(len(columns))
79 self.setHeaderLabels(columns)
80 self.header().restoreState(self.plugin.settings.value(self.plugin.name + '/header_state').toByteArray())
81 self.itemActivated.connect(self._song_activated)
82 self.header().geometriesChanged.connect(self._save_state)
84 self.plugin.mpclient.playlist_changed.connect(self.fill)
86 def _save_state(self):
87 self.plugin.settings.setValue(self.plugin.name + '/header_state', QVariant(self.header().saveState()))
89 def _song_activated(self, item):
90 self.plugin.mpclient.play(item.id)
92 def fill(self):
93 columns = self.plugin.settings.value(self.plugin.name + '/columns').toStringList()
94 self.clear()
95 for song in self.plugin.mpclient.playlistinfo():
96 item = PlaylistWidget.PlaylistSongItem(song['id'])
97 for i in range(len(columns)):
98 item.setText(i, unicode(song[str(columns[i])]))
99 self.addTopLevelItem(item)
101 def keyPressEvent(self, event):
102 if event.matches(QtGui.QKeySequence.Delete):
103 ids = []
104 for item in self.selectedItems():
105 ids.append(item.id)
107 self.plugin.mpclient.delete(ids)
108 else:
109 QtGui.QTreeWidget.keyPressEvent(self, event)
111 def fill_playlist(self):
112 self.playlist.fill()