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
):
25 info
= 'Shows the playlist.'
31 DEFAULTS
= {'columns': ['track', 'title', 'artist',
32 'date', 'album', 'length']}
35 self
.o
= PlaylistWidget(self
)
40 def _get_dock_widget(self
):
41 return self
._create
_dock
(self
.o
)
43 class PlaylistWidget(QtGui
.QWidget
):
47 def __init__(self
, plugin
):
48 QtGui
.QWidget
.__init
__(self
)
51 self
.playlist
= self
.Playlist(self
.plugin
)
53 self
.setLayout(QtGui
.QVBoxLayout())
54 self
.layout().setSpacing(0)
55 self
.layout().setMargin(0)
56 self
.layout().addWidget(self
.playlist
)
59 class Playlist(QtGui
.QTreeWidget
):
63 def __init__(self
, plugin
):
64 QtGui
.QTreeWidget
.__init
__(self
)
67 self
.setSelectionMode(QtGui
.QTreeWidget
.ExtendedSelection
)
68 self
.setAlternatingRowColors(True)
69 self
.setRootIsDecorated(False)
70 columns
= self
.plugin
.settings
.value(self
.plugin
.name
+ '/columns').toStringList()
71 self
.setColumnCount(len(columns
))
72 self
.setHeaderLabels(columns
)
73 self
.header().restoreState(self
.plugin
.settings
.value(self
.plugin
.name
+ '/header_state').toByteArray())
74 self
.itemActivated
.connect(self
._song
_activated
)
75 self
.header().geometriesChanged
.connect(self
._save
_state
)
77 self
.plugin
.mpclient
.playlist_changed
.connect(self
.fill
)
79 def _save_state(self
):
80 self
.plugin
.settings
.setValue(self
.plugin
.name
+ '/header_state', QVariant(self
.header().saveState()))
82 def _song_activated(self
, item
):
83 self
.plugin
.mpclient
.play(item
.data(0, QtCore
.Qt
.UserRole
).toPyObject().id())
86 columns
= self
.plugin
.settings
.value(self
.plugin
.name
+ '/columns').toStringList()
88 for song
in self
.plugin
.mpclient
.playlist():
89 item
= QtGui
.QTreeWidgetItem()
90 for i
in range(len(columns
)):
91 item
.setText(i
, unicode(song
.tag(str(columns
[i
]))))
92 item
.setData(0, QtCore
.Qt
.UserRole
, QVariant(song
))
93 self
.addTopLevelItem(item
)
95 def keyPressEvent(self
, event
):
96 if event
.matches(QtGui
.QKeySequence
.Delete
):
98 for item
in self
.selectedItems():
99 ids
.append(item
.data(0, QtCore
.Qt
.UserRole
).toPyObject().id())
101 self
.plugin
.mpclient
.delete(ids
)
103 QtGui
.QTreeWidget
.keyPressEvent(self
, event
)
105 def fill_playlist(self
):