2009-06-01 09:55:11 +00:00
|
|
|
# Created By: Virgil Dupras
|
|
|
|
# Created On: 2009-04-25
|
2010-01-01 20:11:34 +00:00
|
|
|
# Copyright 2010 Hardcoded Software (http://www.hardcoded.net)
|
2009-08-05 08:59:46 +00:00
|
|
|
#
|
|
|
|
# This software is licensed under the "HS" License as described in the "LICENSE" file,
|
|
|
|
# which should be included with this package. The terms are also available at
|
|
|
|
# http://www.hardcoded.net/licenses/hs_license
|
2009-06-01 09:55:11 +00:00
|
|
|
|
|
|
|
from PyQt4.QtCore import SIGNAL, Qt
|
|
|
|
from PyQt4.QtGui import QDialog, QFileDialog, QHeaderView
|
|
|
|
|
2009-10-14 13:29:46 +00:00
|
|
|
from . import platform
|
|
|
|
from .directories_dialog_ui import Ui_DirectoriesDialog
|
|
|
|
from .directories_model import DirectoriesModel, DirectoriesDelegate
|
2009-06-01 09:55:11 +00:00
|
|
|
|
|
|
|
class DirectoriesDialog(QDialog, Ui_DirectoriesDialog):
|
|
|
|
def __init__(self, parent, app):
|
|
|
|
flags = Qt.CustomizeWindowHint | Qt.WindowTitleHint | Qt.WindowSystemMenuHint
|
|
|
|
QDialog.__init__(self, parent, flags)
|
|
|
|
self.app = app
|
2009-10-14 13:29:46 +00:00
|
|
|
self.lastAddedFolder = platform.INITIAL_FOLDER_IN_DIALOGS
|
2009-06-01 09:55:11 +00:00
|
|
|
self._setupUi()
|
|
|
|
self._updateRemoveButton()
|
|
|
|
|
|
|
|
self.connect(self.doneButton, SIGNAL('clicked()'), self.doneButtonClicked)
|
|
|
|
self.connect(self.addButton, SIGNAL('clicked()'), self.addButtonClicked)
|
|
|
|
self.connect(self.removeButton, SIGNAL('clicked()'), self.removeButtonClicked)
|
|
|
|
self.connect(self.treeView.selectionModel(), SIGNAL('selectionChanged(QItemSelection,QItemSelection)'), self.selectionChanged)
|
|
|
|
|
|
|
|
def _setupUi(self):
|
|
|
|
self.setupUi(self)
|
|
|
|
# Stuff that can't be done in the Designer
|
|
|
|
self.directoriesModel = DirectoriesModel(self.app)
|
|
|
|
self.directoriesDelegate = DirectoriesDelegate()
|
|
|
|
self.treeView.setItemDelegate(self.directoriesDelegate)
|
|
|
|
self.treeView.setModel(self.directoriesModel)
|
|
|
|
|
|
|
|
header = self.treeView.header()
|
|
|
|
header.setStretchLastSection(False)
|
|
|
|
header.setResizeMode(0, QHeaderView.Stretch)
|
|
|
|
header.setResizeMode(1, QHeaderView.Fixed)
|
|
|
|
header.resizeSection(1, 100)
|
|
|
|
|
|
|
|
def _updateRemoveButton(self):
|
|
|
|
indexes = self.treeView.selectedIndexes()
|
|
|
|
if not indexes:
|
|
|
|
self.removeButton.setEnabled(False)
|
|
|
|
return
|
|
|
|
self.removeButton.setEnabled(True)
|
|
|
|
index = indexes[0]
|
|
|
|
node = index.internalPointer()
|
|
|
|
# label = 'Remove' if node.parent is None else 'Exclude'
|
|
|
|
|
|
|
|
def addButtonClicked(self):
|
2010-08-11 14:39:06 +00:00
|
|
|
title = "Select a directory to add to the scanning list"
|
2009-06-01 09:55:11 +00:00
|
|
|
flags = QFileDialog.ShowDirsOnly
|
2010-08-11 14:39:06 +00:00
|
|
|
dirpath = str(QFileDialog.getExistingDirectory(self, title, self.lastAddedFolder, flags))
|
2009-06-01 09:55:11 +00:00
|
|
|
if not dirpath:
|
|
|
|
return
|
2009-10-14 13:29:46 +00:00
|
|
|
self.lastAddedFolder = dirpath
|
2009-06-07 07:11:52 +00:00
|
|
|
self.app.add_directory(dirpath)
|
2009-06-01 09:55:11 +00:00
|
|
|
|
|
|
|
def doneButtonClicked(self):
|
|
|
|
self.hide()
|
|
|
|
|
|
|
|
def removeButtonClicked(self):
|
|
|
|
indexes = self.treeView.selectedIndexes()
|
|
|
|
if not indexes:
|
|
|
|
return
|
|
|
|
index = indexes[0]
|
|
|
|
node = index.internalPointer()
|
|
|
|
if node.parent is None:
|
|
|
|
row = index.row()
|
2010-02-07 15:00:58 +00:00
|
|
|
self.app.remove_directory(row)
|
2009-06-01 09:55:11 +00:00
|
|
|
|
|
|
|
def selectionChanged(self, selected, deselected):
|
|
|
|
self._updateRemoveButton()
|
|
|
|
|