diff --git a/cocoa/base/AppDelegate.m b/cocoa/base/AppDelegate.m index 4911a8eb..15c2f352 100644 --- a/cocoa/base/AppDelegate.m +++ b/cocoa/base/AppDelegate.m @@ -213,6 +213,11 @@ http://www.hardcoded.net/licenses/bsd_license [Dialogs showMessage:msg]; } +- (BOOL)askYesNoWithPrompt:(NSString *)prompt +{ + return [Dialogs askYesNo:prompt] == NSAlertFirstButtonReturn; +} + - (void)setupAsRegistered { // Nothing to do. diff --git a/cocoa/inter/app.py b/cocoa/inter/app.py index d04a4244..fd2e4372 100644 --- a/cocoa/inter/app.py +++ b/cocoa/inter/app.py @@ -20,7 +20,7 @@ JOBID2TITLE = { } class DupeGuruView(FairwareView): - pass + def askYesNoWithPrompt_(self, prompt: str) -> bool: pass class PyDupeGuruBase(PyFairware): FOLLOW_PROTOCOLS = ['Worker'] @@ -193,3 +193,7 @@ class PyDupeGuruBase(PyFairware): ud = {'desc': JOBID2TITLE[jobid], 'jobid':jobid} proxy.postNotification_userInfo_('JobStarted', ud) + @dontwrap + def ask_yes_no(self, prompt): + return self.callback.askYesNoWithPrompt_(prompt) + diff --git a/cocoa/inter/app_me.py b/cocoa/inter/app_me.py index ec46701b..7842062c 100644 --- a/cocoa/inter/app_me.py +++ b/cocoa/inter/app_me.py @@ -171,6 +171,22 @@ class DupeGuruME(DupeGuruBase): return ITunesSong(path) return DupeGuruBase._create_file(self, path) + def _job_completed(self, jobid, exc): + if (jobid in {JobType.RemoveDeadTracks, JobType.ScanDeadTracks}) and (exc is not None): + msg = tr("There were communication problems with iTunes. The operation couldn't be completed.") + self.view.show_message(msg) + return True + if jobid == JobType.ScanDeadTracks: + dead_tracks_count = len(self.dead_tracks) + if dead_tracks_count > 0: + msg = tr("Your iTunes Library contains %d dead tracks ready to be removed. Continue?") + if self.view.ask_yes_no(msg % dead_tracks_count): + self.remove_dead_tracks() + else: + msg = tr("You have no dead tracks in your iTunes Library") + self.view.show_message(msg) + DupeGuruBase._job_completed(self, jobid, exc) + def copy_or_move(self, dupe, copy, destination, dest_type): if isinstance(dupe, ITunesSong): copy = True @@ -221,16 +237,9 @@ class PyDupeGuru(PyDupeGuruBase): def __init__(self): self._init(DupeGuruME) - def removeDeadTracks(self): - self.model.remove_dead_tracks() - def scanDeadTracks(self): self.model.scan_dead_tracks() - #---Information - def deadTrackCount(self) -> int: - return len(self.model.dead_tracks) - #---Properties def setMinMatchPercentage_(self, percentage: int): self.model.scanner.min_match_percentage = percentage diff --git a/cocoa/me/ResultWindow.m b/cocoa/me/ResultWindow.m index 715091f4..45b82ace 100644 --- a/cocoa/me/ResultWindow.m +++ b/cocoa/me/ResultWindow.m @@ -74,22 +74,4 @@ http://www.hardcoded.net/licenses/bsd_license { [model scanDeadTracks]; } - -/* Notifications */ -- (void)jobCompleted:(NSNotification *)aNotification -{ - [super jobCompleted:aNotification]; - id lastAction = [[ProgressController mainProgressController] jobId]; - if ([lastAction isEqualTo:jobScanDeadTracks]) { - NSInteger deadTrackCount = [model deadTrackCount]; - if (deadTrackCount > 0) { - NSString *msg = TR(@"Your iTunes Library contains %d dead tracks ready to be removed. Continue?"); - if ([Dialogs askYesNo:[NSString stringWithFormat:msg,deadTrackCount]] == NSAlertFirstButtonReturn) - [model removeDeadTracks]; - } - else { - [Dialogs showMessage:TR(@"You have no dead tracks in your iTunes Library")]; - } - } -} @end diff --git a/core/app.py b/core/app.py index 5299097c..c9d0b639 100644 --- a/core/app.py +++ b/core/app.py @@ -80,6 +80,7 @@ class DupeGuru(RegistrableApplication, Broadcaster): # open_path(path) # reveal_path(path) # start_job(jobid, func, args=()) ( func(j, *args) ) + # ask_yes_no(prompt) --> bool # in fairware prompts, we don't mention the edition, it's too long. PROMPT_NAME = "dupeGuru"