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 DEFAULTS
= {'columns': ['track', 'title', 'artist',
26 'date', 'album', 'length']}
29 self
.o
= PlaylistWidget(self
)
34 return "The playlist showing the songs that will be played."
36 def _get_dock_widget(self
):
37 return self
._create
_dock
(self
.o
)
39 class PlaylistWidget(QtGui
.QWidget
):
43 def __init__(self
, plugin
):
44 QtGui
.QWidget
.__init
__(self
)
47 self
.playlist
= self
.Playlist(self
.plugin
)
49 self
.setLayout(QtGui
.QVBoxLayout())
50 self
.layout().setSpacing(0)
51 self
.layout().setMargin(0)
52 self
.layout().addWidget(self
.playlist
)
55 class Playlist(QtGui
.QTreeWidget
):
59 def __init__(self
, plugin
):
60 QtGui
.QTreeWidget
.__init
__(self
)
63 self
.setSelectionMode(QtGui
.QTreeWidget
.ExtendedSelection
)
64 self
.setAlternatingRowColors(True)
65 self
.setRootIsDecorated(False)
66 columns
= self
.plugin
.settings
.value(self
.plugin
.name
+ '/columns').toStringList()
67 self
.setColumnCount(len(columns
))
68 self
.setHeaderLabels(columns
)
69 self
.header().restoreState(self
.plugin
.settings
.value(self
.plugin
.name
+ '/header_state').toByteArray())
70 self
.connect(self
, QtCore
.SIGNAL('itemActivated(QTreeWidgetItem*, int)'), self
._song
_activated
)
71 self
.connect(self
.header(), QtCore
.SIGNAL('geometriesChanged()'), self
._save
_state
)
73 self
.connect(self
.plugin
.mpclient
, QtCore
.SIGNAL('playlist_changed'), self
.fill
)
74 self
.connect(self
.plugin
.mpclient
, QtCore
.SIGNAL('disconnected'), self
.fill
)
76 def _save_state(self
):
77 self
.plugin
.settings
.setValue(self
.plugin
.name
+ '/header_state', QVariant(self
.header().saveState()))
79 def _song_activated(self
, item
):
80 self
.plugin
.mpclient
.play(item
.data(0, QtCore
.Qt
.UserRole
).toPyObject().id())
83 columns
= self
.plugin
.settings
.value(self
.plugin
.name
+ '/columns').toStringList()
85 for song
in self
.plugin
.mpclient
.playlist():
86 item
= QtGui
.QTreeWidgetItem()
87 for i
in range(len(columns
)):
88 item
.setText(i
, unicode(song
.tag(str(columns
[i
]))))
89 item
.setData(0, QtCore
.Qt
.UserRole
, QVariant(song
))
90 self
.addTopLevelItem(item
)
92 def keyPressEvent(self
, event
):
93 if event
.matches(QtGui
.QKeySequence
.Delete
):
95 for item
in self
.selectedItems():
96 ids
.append(item
.data(0, QtCore
.Qt
.UserRole
).toPyObject().id())
98 self
.plugin
.mpclient
.delete(ids
)
100 QtGui
.QTreeWidget
.keyPressEvent(self
, event
)
102 def fill_playlist(self
):