summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Khirnov <wyskas@gmail.com>2009-09-12 20:15:06 +0200
committerAnton Khirnov <wyskas@gmail.com>2009-09-12 20:15:06 +0200
commit530265c9aeb58f8b0120675a90d8ee94638e775c (patch)
tree4c955692a5288abf8128e108f41b0b096fde88d2
parentbe7260ad246f033479b0a5e4a84bc94ac2dba604 (diff)
Playlist: allow dropping items from library.
-rw-r--r--nephilim/mpclient.py8
-rw-r--r--nephilim/plugins/Playlist.py23
2 files changed, 28 insertions, 3 deletions
diff --git a/nephilim/mpclient.py b/nephilim/mpclient.py
index b2e2116..328394f 100644
--- a/nephilim/mpclient.py
+++ b/nephilim/mpclient.py
@@ -319,7 +319,7 @@ class MPClient(QtCore.QObject):
if not self.__check_command_ok('clear'):
return
self._client.clear()
- def add(self, paths):
+ def add(self, paths, pos = -1):
"""Add all files in paths to the current playlist."""
if not self.__check_command_ok('addid'):
return
@@ -328,7 +328,11 @@ class MPClient(QtCore.QObject):
try:
for path in paths:
self.logger.info('Adding %s to playlist'%path)
- self._client.addid(path.encode('utf-8'))
+ if pos < 0:
+ self._client.addid(path.encode('utf-8'))
+ else:
+ self._client.addid(path.encode('utf-8'), pos)
+ pos += 1
ret = list(self._client.command_list_end())
except mpd.CommandError, e:
self.logger.error('Error adding files: %s.'%e)
diff --git a/nephilim/plugins/Playlist.py b/nephilim/plugins/Playlist.py
index 1e1bedb..b6266cc 100644
--- a/nephilim/plugins/Playlist.py
+++ b/nephilim/plugins/Playlist.py
@@ -19,6 +19,7 @@ from PyQt4 import QtGui, QtCore
from PyQt4.QtCore import QVariant
from ..plugin import Plugin
+from ..common import MIMETYPES
class Playlist(Plugin):
# public, const
@@ -77,13 +78,19 @@ class PlaylistWidget(QtGui.QWidget):
self.setSelectionMode(QtGui.QTreeWidget.ExtendedSelection)
self.setAlternatingRowColors(True)
self.setRootIsDecorated(False)
+
+ # drag&drop
+ self.viewport().setAcceptDrops(True)
+ self.setDropIndicatorShown(True)
+ self.setDragDropMode(QtGui.QAbstractItemView.DropOnly)
+
columns = self.plugin.settings.value(self.plugin.name + '/columns').toStringList()
self.setColumnCount(len(columns))
self.setHeaderLabels(columns)
self.header().restoreState(self.plugin.settings.value(self.plugin.name + '/header_state').toByteArray())
+
self.itemActivated.connect(self._song_activated)
self.header().geometriesChanged.connect(self._save_state)
-
self.plugin.mpclient.playlist_changed.connect(self.fill)
def _save_state(self):
@@ -111,5 +118,19 @@ class PlaylistWidget(QtGui.QWidget):
else:
QtGui.QTreeWidget.keyPressEvent(self, event)
+ def dropMimeData(self, parent, index, data, action):
+ if data.hasFormat(MIMETYPES['songs']):
+ if parent:
+ index = self.indexOfTopLevelItem(parent)
+ self.plugin.mpclient.add(data.songs(), index)
+ return True
+ return False
+
+ def supportedDropActions(self):
+ return QtCore.Qt.CopyAction | QtCore.Qt.MoveAction
+
+ def mimeTypes(self):
+ return [MIMETYPES['songs'], MIMETYPES['plistsongs']]
+
def fill_playlist(self):
self.playlist.fill()