From ef0a66f794c6b4fd0e802a058853fd8a65bf2a8c Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Fri, 9 Mar 2012 13:47:28 -0500 Subject: [PATCH] Pushed job_finished logic down from GUI layers to the core. --- cocoa/base/AppDelegate.m | 5 +++++ cocoa/base/ResultWindow.h | 4 +--- cocoa/base/ResultWindow.m | 42 +++++---------------------------------- cocoa/inter/app.py | 15 +++++++++++--- core/app.py | 23 +++++++++++++++++++-- qt/base/app.py | 21 ++++++-------------- 6 files changed, 50 insertions(+), 60 deletions(-) diff --git a/cocoa/base/AppDelegate.m b/cocoa/base/AppDelegate.m index 15c2f352..dec5e0df 100644 --- a/cocoa/base/AppDelegate.m +++ b/cocoa/base/AppDelegate.m @@ -218,6 +218,11 @@ http://www.hardcoded.net/licenses/bsd_license return [Dialogs askYesNo:prompt] == NSAlertFirstButtonReturn; } +- (void)showProblemDialog +{ + [[self resultWindow] showProblemDialog]; +} + - (void)setupAsRegistered { // Nothing to do. diff --git a/cocoa/base/ResultWindow.h b/cocoa/base/ResultWindow.h index 4e0f4455..b9992021 100644 --- a/cocoa/base/ResultWindow.h +++ b/cocoa/base/ResultWindow.h @@ -42,6 +42,7 @@ http://www.hardcoded.net/licenses/bsd_license - (void)fillColumnsMenu; - (void)sendMarkedToTrash:(BOOL)hardlinkDeleted; - (void)updateOptionSegments; +- (void)showProblemDialog; /* Actions */ - (IBAction)clearIgnoreList:(id)sender; @@ -74,7 +75,4 @@ http://www.hardcoded.net/licenses/bsd_license - (IBAction)toggleDetailsPanel:(id)sender; - (IBAction)togglePowerMarker:(id)sender; - (IBAction)toggleQuicklookPanel:(id)sender; - -/* Notifications */ -- (void)jobCompleted:(NSNotification *)aNotification; @end diff --git a/cocoa/base/ResultWindow.m b/cocoa/base/ResultWindow.m index 984b7da1..9f439c24 100644 --- a/cocoa/base/ResultWindow.m +++ b/cocoa/base/ResultWindow.m @@ -32,7 +32,6 @@ http://www.hardcoded.net/licenses/bsd_license [matches setTarget:self]; [matches setDoubleAction:@selector(openClicked:)]; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(jobCompleted:) name:JobCompletedNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(jobStarted:) name:JobStarted object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(jobInProgress:) name:JobInProgress object:nil]; return self; @@ -104,6 +103,11 @@ http://www.hardcoded.net/licenses/bsd_license [optionsSwitch setSelected:[table deltaValuesMode] forSegment:2]; } +- (void)showProblemDialog +{ + [problemDialog showWindow:self]; +} + /* Actions */ - (IBAction)clearIgnoreList:(id)sender { @@ -377,42 +381,6 @@ http://www.hardcoded.net/licenses/bsd_license previewPanel = nil; } -/* Notifications */ -- (void)jobCompleted:(NSNotification *)aNotification -{ - id lastAction = [[ProgressController mainProgressController] jobId]; - if ([lastAction isEqualTo:jobCopy]) { - if ([model scanWasProblematic]) { - [problemDialog showWindow:self]; - } - else { - [Dialogs showMessage:TR(@"All marked files were copied sucessfully.")]; - } - } - else if ([lastAction isEqualTo:jobMove]) { - if ([model scanWasProblematic]) { - [problemDialog showWindow:self]; - } - else { - [Dialogs showMessage:TR(@"All marked files were moved sucessfully.")]; - } - } - else if ([lastAction isEqualTo:jobDelete]) { - if ([model scanWasProblematic]) { - [problemDialog showWindow:self]; - } - else { - [Dialogs showMessage:TR(@"All marked files were sucessfully sent to Trash.")]; - } - } - else if ([lastAction isEqualTo:jobScan]) { - NSInteger rowCount = [[table model] numberOfRows]; - if (rowCount == 0) { - [Dialogs showMessage:TR(@"No duplicates found.")]; - } - } -} - - (void)jobInProgress:(NSNotification *)aNotification { [Dialogs showMessage:TR(@"A previous action is still hanging in there. You can't start a new one yet. Wait a few seconds, then try again.")]; diff --git a/cocoa/inter/app.py b/cocoa/inter/app.py index fd2e4372..66bc8e48 100644 --- a/cocoa/inter/app.py +++ b/cocoa/inter/app.py @@ -21,6 +21,7 @@ JOBID2TITLE = { class DupeGuruView(FairwareView): def askYesNoWithPrompt_(self, prompt: str) -> bool: pass + def showProblemDialog(self): pass class PyDupeGuruBase(PyFairware): FOLLOW_PROTOCOLS = ['Worker'] @@ -128,9 +129,6 @@ class PyDupeGuruBase(PyFairware): def getMarkCount(self) -> int: return self.model.results.mark_count - def scanWasProblematic(self) -> bool: - return bool(self.model.results.problems) - def resultsAreModified(self) -> bool: return self.model.results.is_modified @@ -197,3 +195,14 @@ class PyDupeGuruBase(PyFairware): def ask_yes_no(self, prompt): return self.callback.askYesNoWithPrompt_(prompt) + @dontwrap + def show_results_window(self): + # Not needed yet because our progress dialog is shown as a sheet of the results window, + # which causes it to be already visible when the scan/load ends. + # XXX Make progress sheet be a child of the folder selection window. + pass + + @dontwrap + def show_problem_dialog(self): + self.callback.showProblemDialog() + diff --git a/core/app.py b/core/app.py index c9d0b639..0e8ed179 100644 --- a/core/app.py +++ b/core/app.py @@ -81,6 +81,8 @@ class DupeGuru(RegistrableApplication, Broadcaster): # reveal_path(path) # start_job(jobid, func, args=()) ( func(j, *args) ) # ask_yes_no(prompt) --> bool + # show_results_window() + # show_problem_dialog() # in fairware prompts, we don't mention the edition, it's too long. PROMPT_NAME = "dupeGuru" @@ -174,12 +176,29 @@ class DupeGuru(RegistrableApplication, Broadcaster): # Must be called by subclasses when they detect that an async job is completed. If an # exception was raised during the job, `exc` will be set. Return True when the error was # handled. If we return False when exc is set, a the exception will be re-raised. + if exc is not None: + return False # We don't handle any exception in here if jobid == JobType.Scan: self._results_changed() - elif jobid in {JobType.Load, JobType.Move, JobType.Delete}: + if not self.results.groups: + self.view.show_message(tr("No duplicates found.")) + else: + self.view.show_results_window() + if jobid in {JobType.Load, JobType.Move, JobType.Delete}: self._results_changed() + if jobid == JobType.Load: + self.view.show_results_window() if jobid in {JobType.Copy, JobType.Move, JobType.Delete}: - self.notify('problems_changed') + if self.results.problems: + self.notify('problems_changed') + self.view.show_problem_dialog() + else: + msg = { + JobType.Copy: tr("All marked files were copied sucessfully."), + JobType.Move: tr("All marked files were moved sucessfully."), + JobType.Delete: tr("All marked files were sucessfully sent to Trash."), + }[jobid] + self.view.show_message(msg) @staticmethod def _remove_hardlink_dupes(files): diff --git a/qt/base/app.py b/qt/base/app.py index 4c85424a..b3a8c2e2 100644 --- a/qt/base/app.py +++ b/qt/base/app.py @@ -203,21 +203,6 @@ class DupeGuru(QObject): result = self.model._job_completed(jobid, self._progress.last_error) if not result: self._progress.reraise_if_error() - if jobid in {JobType.Move, JobType.Copy, JobType.Delete}: - if self.model.results.problems: - self.problemDialog.show() - else: - msg = tr("All files were processed successfully.") - QMessageBox.information(self.resultWindow, tr("Operation Complete"), msg) - elif jobid == JobType.Scan: - if not self.model.results.groups: - title = tr("Scan complete") - msg = tr("No duplicates found.") - QMessageBox.information(self.resultWindow, title, msg) - else: - self.showResultsWindow() - elif jobid == JobType.Load: - self.showResultsWindow() def openDebugLogTriggered(self): debugLogPath = op.join(self.model.appdata, 'debug.log') @@ -294,3 +279,9 @@ class DupeGuru(QObject): url = QUrl(url) QDesktopServices.openUrl(url) + def show_results_window(self): + self.showResultsWindow() + + def show_problem_dialog(self): + self.problemDialog.show() +