summaryrefslogtreecommitdiff
path: root/nephilim/plugins/Filebrowser.py
blob: 0a2908dec06f35462767e6b055299ca727589648 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from PyQt4 import QtGui, QtCore
from PyQt4.QtCore import QVariant
import os

from ..clPlugin import Plugin
from ..misc     import ORGNAME, APPNAME

class pluginFilebrowser(Plugin):
    view  = None
    model = None

    def __init__(self, winMain):
        Plugin.__init__(self, winMain, 'Filebrowser')

    def _load(self):
        self.model = QtGui.QDirModel()
        self.model.setFilter(QtCore.QDir.AllDirs|QtCore.QDir.AllEntries)
        self.model.setSorting(QtCore.QDir.DirsFirst)

        self.view  = QtGui.QListView()
        self.view.setModel(self.model)
        self.view.setRootIndex(self.model.index(os.path.expanduser('~')))
        self.view.setSelectionMode(QtGui.QTreeWidget.ExtendedSelection)
        self.view.connect(self.view, QtCore.SIGNAL('activated(const QModelIndex&)'), self.item_activated)

    def _unload(self):
        self.view  = None
        self.model = None

    def getInfo(self):
        return 'A file browser that allows adding files not in collection.'

    def _getDockWidget(self):
        return self._createDock(self.view)

    def item_activated(self, index):
        if self.model.hasChildren(index):
            self.view.setRootIndex(index)
        else:
            if not 'file://' in self.mpclient.urlhandlers():
                self.setStatus('file:// handler not available. Connect via unix domain sockets.')
                return
            paths = []
            for index in self.view.selectedIndexes():
                paths.append(u'file://' + self.model.filePath(index))
            self.mpclient.addToPlaylist(paths)