Lyrics: support for loading stored lyrics.
[nephilim.git] / nephilim / plugins / Filebrowser.py
blobf88c0f57934a19f5323d57c987623060dfa51729
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
20 import os
22 from ..plugin import Plugin
24 class Filebrowser(Plugin):
25 o = None
26 def _load(self):
27 self.o = wgFilebrowser(self)
29 def _unload(self):
30 self.o = None
32 def getInfo(self):
33 return 'A file browser that allows adding files not in collection.'
35 def _get_dock_widget(self):
36 return self._create_dock(self.o)
38 class wgFilebrowser(QtGui.QWidget):
39 view = None
40 model = None
41 path = None
42 plugin = None
44 def __init__(self, plugin):
45 QtGui.QWidget.__init__(self)
46 self.plugin = plugin
48 self.model = QtGui.QDirModel()
49 self.model.setFilter(QtCore.QDir.AllDirs|QtCore.QDir.AllEntries)
50 self.model.setSorting(QtCore.QDir.DirsFirst)
52 self.view = QtGui.QListView()
53 self.view.setModel(self.model)
54 self.view.setRootIndex(self.model.index(os.path.expanduser('~')))
55 self.view.setSelectionMode(QtGui.QTreeWidget.ExtendedSelection)
56 self.connect(self.view, QtCore.SIGNAL('activated(const QModelIndex&)'), self.item_activated)
58 self.path = QtGui.QLineEdit(self.model.filePath(self.view.rootIndex()))
59 self.connect(self.path, QtCore.SIGNAL('returnPressed()'), self.path_changed)
61 self.setLayout(QtGui.QVBoxLayout())
62 self.layout().setSpacing(0)
63 self.layout().setMargin(0)
64 self.layout().addWidget(self.path)
65 self.layout().addWidget(self.view)
67 def item_activated(self, index):
68 if self.model.hasChildren(index):
69 self.view.setRootIndex(index)
70 self.path.setText(self.model.filePath(index))
71 else:
72 if not 'file://' in self.plugin.mpclient().urlhandlers():
73 self.set_status('file:// handler not available. Connect via unix domain sockets.')
74 return
75 paths = []
76 for index in self.view.selectedIndexes():
77 paths.append(u'file://' + unicode(self.model.filePath(index)))
78 self.plugin.mpclient().add(paths)
80 def path_changed(self):
81 if os.path.isdir(self.path.text()):
82 self.view.setRootIndex(self.model.index(self.path.text()))