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
|
|
|
#
|
2010-09-30 10:17:41 +00:00
|
|
|
# This software is licensed under the "BSD" License as described in the "LICENSE" file,
|
2009-08-05 08:59:46 +00:00
|
|
|
# which should be included with this package. The terms are also available at
|
2010-09-30 10:17:41 +00:00
|
|
|
# http://www.hardcoded.net/licenses/bsd_license
|
2009-06-01 09:55:11 +00:00
|
|
|
|
2011-01-15 15:29:35 +00:00
|
|
|
from PyQt4.QtCore import QSize, QRect
|
|
|
|
from PyQt4.QtGui import (QWidget, QFileDialog, QHeaderView, QVBoxLayout, QHBoxLayout, QTreeView,
|
|
|
|
QAbstractItemView, QSpacerItem, QSizePolicy, QPushButton, QApplication, QMessageBox, QMainWindow,
|
|
|
|
QMenuBar, QMenu)
|
|
|
|
|
|
|
|
from core.app import NoScannableFileError
|
2009-06-01 09:55:11 +00:00
|
|
|
|
2009-10-14 13:29:46 +00:00
|
|
|
from . import platform
|
|
|
|
from .directories_model import DirectoriesModel, DirectoriesDelegate
|
2011-01-15 15:29:35 +00:00
|
|
|
from .util import createActions
|
2009-06-01 09:55:11 +00:00
|
|
|
|
2011-01-15 15:29:35 +00:00
|
|
|
class DirectoriesDialog(QMainWindow):
|
2009-06-01 09:55:11 +00:00
|
|
|
def __init__(self, parent, app):
|
2011-01-15 15:29:35 +00:00
|
|
|
QMainWindow.__init__(self, None)
|
2009-06-01 09:55:11 +00:00
|
|
|
self.app = app
|
2009-10-14 13:29:46 +00:00
|
|
|
self.lastAddedFolder = platform.INITIAL_FOLDER_IN_DIALOGS
|
2010-10-04 13:29:00 +00:00
|
|
|
self.directoriesModel = DirectoriesModel(self.app)
|
|
|
|
self.directoriesDelegate = DirectoriesDelegate()
|
2009-06-01 09:55:11 +00:00
|
|
|
self._setupUi()
|
|
|
|
self._updateRemoveButton()
|
|
|
|
|
2011-01-15 15:29:35 +00:00
|
|
|
self.scanButton.clicked.connect(self.scanButtonClicked)
|
|
|
|
self.addButton.clicked.connect(self.addButtonClicked)
|
|
|
|
self.removeButton.clicked.connect(self.removeButtonClicked)
|
|
|
|
self.treeView.selectionModel().selectionChanged.connect(self.selectionChanged)
|
2010-08-15 10:27:15 +00:00
|
|
|
self.app.willSavePrefs.connect(self.appWillSavePrefs)
|
2009-06-01 09:55:11 +00:00
|
|
|
|
2011-01-15 15:29:35 +00:00
|
|
|
def _setupActions(self):
|
|
|
|
# (name, shortcut, icon, desc, func)
|
|
|
|
ACTIONS = [
|
|
|
|
('actionLoadResults', 'Ctrl+L', '', "Load Results...", self.loadResultsTriggered),
|
|
|
|
('actionShowResultsWindow', '', '', "Results Window", self.app.showResultsWindow),
|
|
|
|
]
|
|
|
|
createActions(ACTIONS, self)
|
|
|
|
|
|
|
|
def _setupMenu(self):
|
|
|
|
self.menubar = QMenuBar(self)
|
|
|
|
self.menubar.setGeometry(QRect(0, 0, 42, 22))
|
|
|
|
self.menuFile = QMenu(self.menubar)
|
|
|
|
self.menuFile.setTitle("File")
|
|
|
|
self.menuView = QMenu(self.menubar)
|
|
|
|
self.menuView.setTitle("View")
|
|
|
|
self.menuHelp = QMenu(self.menubar)
|
|
|
|
self.menuHelp.setTitle("Help")
|
|
|
|
self.menuLoadRecent = QMenu(self.menuFile)
|
|
|
|
self.menuLoadRecent.setTitle("Load Recent Results")
|
|
|
|
self.setMenuBar(self.menubar)
|
|
|
|
|
|
|
|
self.menuFile.addAction(self.actionLoadResults)
|
|
|
|
self.menuFile.addAction(self.menuLoadRecent.menuAction())
|
|
|
|
self.menuFile.addSeparator()
|
|
|
|
self.menuFile.addAction(self.app.actionQuit)
|
|
|
|
self.menuView.addAction(self.app.actionPreferences)
|
|
|
|
self.menuView.addAction(self.actionShowResultsWindow)
|
|
|
|
self.menuHelp.addAction(self.app.actionShowHelp)
|
|
|
|
self.menuHelp.addAction(self.app.actionRegister)
|
|
|
|
self.menuHelp.addAction(self.app.actionCheckForUpdate)
|
|
|
|
self.menuHelp.addAction(self.app.actionOpenDebugLog)
|
|
|
|
self.menuHelp.addAction(self.app.actionAbout)
|
|
|
|
|
|
|
|
self.menubar.addAction(self.menuFile.menuAction())
|
|
|
|
self.menubar.addAction(self.menuView.menuAction())
|
|
|
|
self.menubar.addAction(self.menuHelp.menuAction())
|
|
|
|
|
2009-06-01 09:55:11 +00:00
|
|
|
def _setupUi(self):
|
2011-01-15 15:29:35 +00:00
|
|
|
self.setWindowTitle(self.app.NAME)
|
2010-10-04 13:29:00 +00:00
|
|
|
self.resize(420, 338)
|
2011-01-15 15:29:35 +00:00
|
|
|
self.centralwidget = QWidget(self)
|
|
|
|
self.verticalLayout = QVBoxLayout(self.centralwidget)
|
|
|
|
self.treeView = QTreeView(self.centralwidget)
|
2009-06-01 09:55:11 +00:00
|
|
|
self.treeView.setItemDelegate(self.directoriesDelegate)
|
|
|
|
self.treeView.setModel(self.directoriesModel)
|
2010-10-04 13:29:00 +00:00
|
|
|
self.treeView.setAcceptDrops(True)
|
2011-01-15 15:29:35 +00:00
|
|
|
triggers = QAbstractItemView.DoubleClicked|QAbstractItemView.EditKeyPressed\
|
|
|
|
|QAbstractItemView.SelectedClicked
|
|
|
|
self.treeView.setEditTriggers(triggers)
|
2010-10-04 13:29:00 +00:00
|
|
|
self.treeView.setDragDropOverwriteMode(True)
|
|
|
|
self.treeView.setDragDropMode(QAbstractItemView.DropOnly)
|
|
|
|
self.treeView.setUniformRowHeights(True)
|
2009-06-01 09:55:11 +00:00
|
|
|
header = self.treeView.header()
|
|
|
|
header.setStretchLastSection(False)
|
|
|
|
header.setResizeMode(0, QHeaderView.Stretch)
|
|
|
|
header.setResizeMode(1, QHeaderView.Fixed)
|
|
|
|
header.resizeSection(1, 100)
|
2010-10-04 13:29:00 +00:00
|
|
|
self.verticalLayout.addWidget(self.treeView)
|
|
|
|
self.horizontalLayout = QHBoxLayout()
|
|
|
|
spacerItem = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
|
|
|
|
self.horizontalLayout.addItem(spacerItem)
|
2011-01-15 15:29:35 +00:00
|
|
|
self.removeButton = QPushButton(self.centralwidget)
|
2010-10-04 13:29:00 +00:00
|
|
|
self.removeButton.setText("Remove")
|
|
|
|
self.removeButton.setShortcut("Del")
|
|
|
|
self.removeButton.setMinimumSize(QSize(91, 0))
|
|
|
|
self.removeButton.setMaximumSize(QSize(16777215, 32))
|
|
|
|
self.horizontalLayout.addWidget(self.removeButton)
|
2011-01-15 15:29:35 +00:00
|
|
|
self.addButton = QPushButton(self.centralwidget)
|
2010-10-04 13:29:00 +00:00
|
|
|
self.addButton.setText("Add")
|
|
|
|
self.addButton.setMinimumSize(QSize(91, 0))
|
|
|
|
self.addButton.setMaximumSize(QSize(16777215, 32))
|
|
|
|
self.horizontalLayout.addWidget(self.addButton)
|
|
|
|
spacerItem1 = QSpacerItem(40, 20, QSizePolicy.Fixed, QSizePolicy.Minimum)
|
|
|
|
self.horizontalLayout.addItem(spacerItem1)
|
2011-01-15 15:29:35 +00:00
|
|
|
self.scanButton = QPushButton(self.centralwidget)
|
|
|
|
self.scanButton.setText("Scan")
|
2010-10-04 13:29:00 +00:00
|
|
|
sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
|
|
|
|
sizePolicy.setHorizontalStretch(0)
|
|
|
|
sizePolicy.setVerticalStretch(0)
|
2011-01-15 15:29:35 +00:00
|
|
|
sizePolicy.setHeightForWidth(self.scanButton.sizePolicy().hasHeightForWidth())
|
|
|
|
self.scanButton.setSizePolicy(sizePolicy)
|
|
|
|
self.scanButton.setMinimumSize(QSize(91, 0))
|
|
|
|
self.scanButton.setMaximumSize(QSize(16777215, 32))
|
|
|
|
self.scanButton.setDefault(True)
|
|
|
|
self.horizontalLayout.addWidget(self.scanButton)
|
2010-10-04 13:29:00 +00:00
|
|
|
self.verticalLayout.addLayout(self.horizontalLayout)
|
2011-01-15 15:29:35 +00:00
|
|
|
self.setCentralWidget(self.centralwidget)
|
|
|
|
|
|
|
|
self._setupActions()
|
|
|
|
self._setupMenu()
|
2010-10-04 13:29:00 +00:00
|
|
|
|
2010-08-15 10:27:15 +00:00
|
|
|
if self.app.prefs.directoriesWindowRect is not None:
|
|
|
|
self.setGeometry(self.app.prefs.directoriesWindowRect)
|
2009-06-01 09:55:11 +00:00
|
|
|
|
|
|
|
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'
|
|
|
|
|
2011-01-15 15:29:35 +00:00
|
|
|
#--- QWidget overrides
|
|
|
|
def closeEvent(self, event):
|
|
|
|
event.accept()
|
|
|
|
if self.app.results.is_modified:
|
|
|
|
title = "Unsaved results"
|
|
|
|
msg = "You have unsaved results, do you really want to quit?"
|
|
|
|
if not self.app.confirm(title, msg):
|
|
|
|
event.ignore()
|
|
|
|
if event.isAccepted():
|
|
|
|
QApplication.quit()
|
|
|
|
|
2010-08-15 10:27:15 +00:00
|
|
|
#--- Events
|
2009-06-01 09:55:11 +00:00
|
|
|
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
|
|
|
|
2010-08-15 10:27:15 +00:00
|
|
|
def appWillSavePrefs(self):
|
|
|
|
self.app.prefs.directoriesWindowRect = self.geometry()
|
|
|
|
|
2011-01-15 15:29:35 +00:00
|
|
|
def loadResultsTriggered(self):
|
|
|
|
title = "Select a results file to load"
|
|
|
|
files = "dupeGuru Results (*.dupeguru)"
|
|
|
|
destination = QFileDialog.getOpenFileName(self, title, '', files)
|
|
|
|
if destination:
|
|
|
|
self.app.load_from(destination)
|
|
|
|
self.app.recentResults.insertItem(destination)
|
2009-06-01 09:55:11 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
2011-01-15 15:29:35 +00:00
|
|
|
def scanButtonClicked(self):
|
|
|
|
title = "Start a new scan"
|
|
|
|
if len(self.app.results.groups) > 0:
|
|
|
|
msg = "Are you sure you want to start a new duplicate scan?"
|
|
|
|
if not self.app.confirm(title, msg):
|
|
|
|
return
|
|
|
|
try:
|
|
|
|
self.app.start_scanning()
|
|
|
|
except NoScannableFileError:
|
|
|
|
msg = "The selected directories contain no scannable file."
|
|
|
|
QMessageBox.warning(self, title, msg)
|
|
|
|
|
2009-06-01 09:55:11 +00:00
|
|
|
def selectionChanged(self, selected, deselected):
|
|
|
|
self._updateRemoveButton()
|
|
|
|
|
2010-10-04 13:29:00 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
import sys
|
|
|
|
from ..testapp import TestApp
|
|
|
|
app = QApplication([])
|
|
|
|
dgapp = TestApp()
|
|
|
|
dialog = DirectoriesDialog(None, dgapp)
|
|
|
|
dialog.show()
|
|
|
|
sys.exit(app.exec_())
|