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 class PlaylistSongItem(QtGui
.QTreeWidgetItem
):
51 def __init__(self
, id):
52 QtGui
.QTreeWidgetItem
.__init
__(self
)
55 def __init__(self
, plugin
):
56 QtGui
.QWidget
.__init
__(self
)
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
):
70 def __init__(self
, plugin
):
71 QtGui
.QTreeWidget
.__init
__(self
)
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)
93 columns
= self
.plugin
.settings
.value(self
.plugin
.name
+ '/columns').toStringList()
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
):
104 for item
in self
.selectedItems():
107 self
.plugin
.mpclient
.delete(ids
)
109 QtGui
.QTreeWidget
.keyPressEvent(self
, event
)
111 def fill_playlist(self
):