[#188 state:fixed] Instead of showing a crash report on iTunes communication problems, show a friendlier message.

This commit is contained in:
Virgil Dupras 2012-03-09 11:34:08 -05:00
parent 22de2d803a
commit 5fb7742cf4
5 changed files with 27 additions and 26 deletions

View File

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

View File

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

View File

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

View File

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

View File

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