From 788ccd60d30830ef1da240f78b5d1cf5f97e97d4 Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Fri, 16 May 2008 00:25:09 +0000 Subject: [PATCH] #948 - when processing the blocklist, don't block the gui (Leopard-only) --- macosx/BlocklistDownloader.m | 49 +++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/macosx/BlocklistDownloader.m b/macosx/BlocklistDownloader.m index 0e1a93bd7..7d400b9c4 100644 --- a/macosx/BlocklistDownloader.m +++ b/macosx/BlocklistDownloader.m @@ -34,6 +34,7 @@ - (id) initWithPrefsController: (PrefsController *) prefsController; - (void) startDownload; +- (void) finishDownloadSuccess; - (void) updateProcessString; - (void) failureSheetClosed: (NSAlert *) alert returnCode: (int) code contextInfo: (void *) info; @@ -108,28 +109,10 @@ - (void) downloadDidFinish: (NSURLDownload *) download { - //change to indeterminate while processing - [fProgressBar setIndeterminate: YES]; - [fProgressBar startAnimation: self]; - - [fTextField setStringValue: [NSLocalizedString(@"Processing blocklist", "Blocklist -> message") stringByAppendingEllipsis]]; - [fButton setEnabled: NO]; - [fStatusWindow display]; //force window to be updated - - //process data - tr_blocklistSetContent([fPrefsController handle], [DESTINATION UTF8String]); - - //delete downloaded file if ([NSApp isOnLeopardOrBetter]) - [[NSFileManager defaultManager] removeItemAtPath: DESTINATION error: NULL]; + [self performSelectorInBackground: @selector(finishDownloadSuccess) withObject: nil]; else - [[NSFileManager defaultManager] removeFileAtPath: DESTINATION handler: nil]; - - [fPrefsController updateBlocklistFields]; - - [NSApp endSheet: fStatusWindow]; - [fStatusWindow orderOut: self]; - [self release]; + [self finishDownloadSuccess]; } @end @@ -159,6 +142,32 @@ [fDownload setDestination: DESTINATION allowOverwrite: YES]; } +- (void) finishDownloadSuccess +{ + //change to indeterminate while processing + [fProgressBar setIndeterminate: YES]; + [fProgressBar startAnimation: self]; + + [fTextField setStringValue: [NSLocalizedString(@"Processing blocklist", "Blocklist -> message") stringByAppendingEllipsis]]; + [fButton setEnabled: NO]; + [fStatusWindow display]; //force window to be updated + + //process data + tr_blocklistSetContent([fPrefsController handle], [DESTINATION UTF8String]); + + //delete downloaded file + if ([NSApp isOnLeopardOrBetter]) + [[NSFileManager defaultManager] removeItemAtPath: DESTINATION error: NULL]; + else + [[NSFileManager defaultManager] removeFileAtPath: DESTINATION handler: nil]; + + [fPrefsController updateBlocklistFields]; + + [NSApp endSheet: fStatusWindow]; + [fStatusWindow orderOut: self]; + [self release]; +} + - (void) updateProcessString { NSString * string = NSLocalizedString(@"Downloading blocklist", "Blocklist -> message");