Pushed job_finished logic down from GUI layers to the core.

This commit is contained in:
Virgil Dupras 2012-03-09 13:47:28 -05:00
parent 5fb7742cf4
commit ef0a66f794
6 changed files with 50 additions and 60 deletions

View File

@ -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.

View File

@ -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

View File

@ -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.")];

View File

@ -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()

View File

@ -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):

View File

@ -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()