From 36eccb71228e7214b2f1bb3f9d40e3c9e4c2355b Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Sun, 15 Aug 2010 15:07:44 +0200 Subject: [PATCH] Removed the "all files are refs" error message and made the "no files, can't scan" message quicker. That's because when scanning iPhoto libraries with big libraries, the GUI would hang because these checks would involve loading the whole library. --- cocoa/me/ResultWindow.m | 2 -- cocoa/pe/ResultWindow.m | 2 -- cocoa/se/ResultWindow.m | 2 -- core/app.py | 9 +-------- core/app_cocoa.py | 2 -- core/directories.py | 7 +++++++ core_pe/app_cocoa.py | 9 +++++++++ qt/base/main_window.py | 5 +---- 8 files changed, 18 insertions(+), 20 deletions(-) diff --git a/cocoa/me/ResultWindow.m b/cocoa/me/ResultWindow.m index 7f8a5b26..21cf5c39 100644 --- a/cocoa/me/ResultWindow.m +++ b/cocoa/me/ResultWindow.m @@ -69,8 +69,6 @@ http://www.hardcoded.net/licenses/hs_license [_py setMixFileKind:[ud objectForKey:@"mixFileKind"]]; [_py setMatchSimilarWords:[ud objectForKey:@"matchSimilarWords"]]; NSInteger r = n2i([py doScan]); - if (r == 1) - [Dialogs showMessage:@"You cannot make a duplicate scan with only reference directories."]; if (r == 3) { [Dialogs showMessage:@"The selected directories contain no scannable file."]; diff --git a/cocoa/pe/ResultWindow.m b/cocoa/pe/ResultWindow.m index 87500cd8..888cddd2 100644 --- a/cocoa/pe/ResultWindow.m +++ b/cocoa/pe/ResultWindow.m @@ -65,8 +65,6 @@ http://www.hardcoded.net/licenses/hs_license int r = n2i([py doScan]); if (r != 0) [[ProgressController mainProgressController] hide]; - if (r == 1) - [Dialogs showMessage:@"You cannot make a duplicate scan with only reference directories."]; if (r == 3) { [Dialogs showMessage:@"The selected directories contain no scannable file."]; diff --git a/cocoa/se/ResultWindow.m b/cocoa/se/ResultWindow.m index 0a74b815..16da92de 100644 --- a/cocoa/se/ResultWindow.m +++ b/cocoa/se/ResultWindow.m @@ -59,8 +59,6 @@ http://www.hardcoded.net/licenses/hs_license int r = n2i([py doScan]); if (r != 0) [[ProgressController mainProgressController] hide]; - if (r == 1) - [Dialogs showMessage:@"You cannot make a duplicate scan with only reference directories."]; if (r == 3) { [Dialogs showMessage:@"The selected directories contain no scannable file."]; diff --git a/core/app.py b/core/app.py index 4e1277af..206840a0 100644 --- a/core/app.py +++ b/core/app.py @@ -33,9 +33,6 @@ JOB_DELETE = 'job_delete' class NoScannableFileError(Exception): pass -class AllFilesAreRefError(Exception): - pass - class DupeGuru(RegistrableApplication, Broadcaster): DEMO_LIMIT_DESC = "In the demo version, only 10 duplicates per session can be sent to the recycle bin, moved or copied." @@ -347,12 +344,8 @@ class DupeGuru(RegistrableApplication, Broadcaster): logging.info('Scanning %d files' % len(files)) self.results.groups = self.scanner.GetDupeGroups(files, j) - files = self.directories.get_files() - first_file = first(files) - if first_file is None: + if not self.directories.has_any_file(): raise NoScannableFileError() - if first_file.is_ref and all(f.is_ref for f in files): - raise AllFilesAreRefError() self.results.groups = [] self._start_job(JOB_SCAN, do) diff --git a/core/app_cocoa.py b/core/app_cocoa.py index 3ef49c3d..4807ffb6 100644 --- a/core/app_cocoa.py +++ b/core/app_cocoa.py @@ -76,6 +76,4 @@ class DupeGuru(app.DupeGuru): return 0 except app.NoScannableFileError: return 3 - except app.AllFilesAreRefError: - return 1 diff --git a/core/directories.py b/core/directories.py index 19365409..4524558a 100644 --- a/core/directories.py +++ b/core/directories.py @@ -124,6 +124,13 @@ class Directories(object): else: return STATE_NORMAL + def has_any_file(self): + try: + next(self.get_files()) + return True + except StopIteration: + return False + def load_from_file(self, infile): try: root = ET.parse(infile).getroot() diff --git a/core_pe/app_cocoa.py b/core_pe/app_cocoa.py index 375c79b4..39c78046 100644 --- a/core_pe/app_cocoa.py +++ b/core_pe/app_cocoa.py @@ -122,6 +122,15 @@ class Directories(directories.Directories): else: directories.Directories.add_path(self, path) + def has_any_file(self): + # If we don't do that, it causes a hangup in the GUI when we click Start Scanning because + # checking if there's any file to scan involves reading the whole library. If we have the + # iPhoto library, we assume we have at least one file. + if any(path == Path('iPhoto Library') for path in self._dirs): + return True + else: + return directories.Directories.has_any_file(self) + class DupeGuruPE(app_cocoa.DupeGuru): def __init__(self): diff --git a/qt/base/main_window.py b/qt/base/main_window.py index 5399d2bb..922c48d8 100644 --- a/qt/base/main_window.py +++ b/qt/base/main_window.py @@ -14,7 +14,7 @@ from PyQt4.QtGui import (QMainWindow, QMenu, QPixmap, QIcon, QToolButton, QLabel from hsutil.misc import nonone -from core.app import NoScannableFileError, AllFilesAreRefError +from core.app import NoScannableFileError from . import dg_rc from .main_window_ui import Ui_MainWindow @@ -271,9 +271,6 @@ class MainWindow(QMainWindow, Ui_MainWindow): msg = "The selected directories contain no scannable file." QMessageBox.warning(self, title, msg) self.app.show_directories() - except AllFilesAreRefError: - msg = "You cannot make a duplicate scan with only reference directories." - QMessageBox.warning(self, title, msg) def showHelpTriggered(self): self.app.show_help()