From ad3114c56bf298c1b76861805ae1c9a649138289 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Sat, 15 Jan 2011 11:38:59 +0100 Subject: [PATCH] Cleaned ResultWindow's code up. --- cocoa/base/ResultWindow.h | 7 +++- cocoa/base/ResultWindow.m | 37 ++++++++++++++--- cocoa/me/ResultWindow.h | 1 - cocoa/me/ResultWindow.m | 68 +++++++++++++------------------ cocoa/pe/ResultWindow.m | 79 ++++++++++++++++------------------- cocoa/se/ResultWindow.h | 7 +--- cocoa/se/ResultWindow.m | 86 ++++++++++++++++----------------------- 7 files changed, 138 insertions(+), 147 deletions(-) diff --git a/cocoa/base/ResultWindow.h b/cocoa/base/ResultWindow.h index 4117595f..5df1b4c3 100644 --- a/cocoa/base/ResultWindow.h +++ b/cocoa/base/ResultWindow.h @@ -32,12 +32,17 @@ http://www.hardcoded.net/licenses/bsd_license ProblemDialog *problemDialog; } - (id)initWithParentApp:(AppDelegateBase *)app; + +/* Virtual */ +- (void)initResultColumns; +- (void)setScanOptions; +- (NSString *)getScanErrorMessageForCode:(NSInteger)errorCode; + /* Helpers */ - (void)fillColumnsMenu; - (NSTableColumn *)getColumnForIdentifier:(NSInteger)aIdentifier title:(NSString *)aTitle width:(NSInteger)aWidth refCol:(NSTableColumn *)aColumn; - (NSArray *)getColumnsOrder; - (NSDictionary *)getColumnsWidth; -- (void)initResultColumns; - (void)restoreColumnsPosition:(NSArray *)aColumnsOrder widths:(NSDictionary *)aColumnsWidth; - (void)sendMarkedToTrash:(BOOL)hardlinkDeleted; - (void)updateOptionSegments; diff --git a/cocoa/base/ResultWindow.m b/cocoa/base/ResultWindow.m index f62010d6..73f056dd 100644 --- a/cocoa/base/ResultWindow.m +++ b/cocoa/base/ResultWindow.m @@ -44,6 +44,26 @@ http://www.hardcoded.net/licenses/bsd_license [super dealloc]; } +/* Virtual */ +- (void)initResultColumns +{ +} + +- (void)setScanOptions +{ +} + +- (NSString *)getScanErrorMessageForCode:(NSInteger)errorCode +{ + if (errorCode == 0) { + return nil; + } + if (errorCode == 3) { + return @"The selected directories contain no scannable file."; + } + return @"Unknown Error."; +} + /* Helpers */ - (void)fillColumnsMenu { @@ -96,11 +116,6 @@ http://www.hardcoded.net/licenses/bsd_license return result; } -- (void)initResultColumns -{ - // Virtual -} - - (void)restoreColumnsPosition:(NSArray *)aColumnsOrder widths:(NSDictionary *)aColumnsWidth { for (NSMenuItem *mi in [columnsMenu itemArray]) { @@ -344,7 +359,17 @@ http://www.hardcoded.net/licenses/bsd_license - (IBAction)startDuplicateScan:(id)sender { - // Virtual + if ([py resultsAreModified]) { + if ([Dialogs askYesNo:@"You have unsaved results, do you really want to continue?"] == NSAlertSecondButtonReturn) // NO + return; + } + [self setScanOptions]; + NSInteger r = n2i([py doScan]); + NSString *errorMsg = [self getScanErrorMessageForCode:r]; + if (errorMsg != nil) { + [[ProgressController mainProgressController] hide]; + [Dialogs showMessage:errorMsg]; + } } - (IBAction)switchSelected:(id)sender diff --git a/cocoa/me/ResultWindow.h b/cocoa/me/ResultWindow.h index b3f666aa..e29e6c0c 100644 --- a/cocoa/me/ResultWindow.h +++ b/cocoa/me/ResultWindow.h @@ -8,7 +8,6 @@ http://www.hardcoded.net/licenses/bsd_license #import #import "../base/ResultWindow.h" -#import "DirectoryPanel.h" @interface ResultWindow : ResultWindowBase {} - (IBAction)removeDeadTracks:(id)sender; diff --git a/cocoa/me/ResultWindow.m b/cocoa/me/ResultWindow.m index 14b55206..0290fc85 100644 --- a/cocoa/me/ResultWindow.m +++ b/cocoa/me/ResultWindow.m @@ -7,10 +7,9 @@ http://www.hardcoded.net/licenses/bsd_license */ #import "ResultWindow.h" -#import "../../cocoalib/Dialogs.h" -#import "../../cocoalib/ProgressController.h" -#import "../../cocoalib/Utils.h" -#import "AppDelegate.h" +#import "Dialogs.h" +#import "Utils.h" +#import "PyDupeGuru.h" #import "Consts.h" @implementation ResultWindow @@ -24,37 +23,8 @@ http://www.hardcoded.net/licenses/bsd_license return self; } -/* Actions */ -- (IBAction)removeDeadTracks:(id)sender +- (void)setScanOptions { - [(PyDupeGuru *)py scanDeadTracks]; -} - -- (IBAction)resetColumnsToDefault:(id)sender -{ - NSMutableArray *columnsOrder = [NSMutableArray array]; - [columnsOrder addObject:@"0"]; - [columnsOrder addObject:@"2"]; - [columnsOrder addObject:@"3"]; - [columnsOrder addObject:@"4"]; - [columnsOrder addObject:@"6"]; - [columnsOrder addObject:@"15"]; - NSMutableDictionary *columnsWidth = [NSMutableDictionary dictionary]; - [columnsWidth setObject:i2n(235) forKey:@"0"]; - [columnsWidth setObject:i2n(63) forKey:@"2"]; - [columnsWidth setObject:i2n(50) forKey:@"3"]; - [columnsWidth setObject:i2n(50) forKey:@"4"]; - [columnsWidth setObject:i2n(40) forKey:@"6"]; - [columnsWidth setObject:i2n(57) forKey:@"15"]; - [self restoreColumnsPosition:columnsOrder widths:columnsWidth]; -} - -- (IBAction)startDuplicateScan:(id)sender -{ - if ([py resultsAreModified]) { - if ([Dialogs askYesNo:@"You have unsaved results, do you really want to continue?"] == NSAlertSecondButtonReturn) // NO - return; - } NSUserDefaults *ud = [NSUserDefaults standardUserDefaults]; PyDupeGuru *_py = (PyDupeGuru *)py; [_py setScanType:[ud objectForKey:@"scanType"]]; @@ -69,13 +39,8 @@ http://www.hardcoded.net/licenses/bsd_license [_py setMixFileKind:n2b([ud objectForKey:@"mixFileKind"])]; [_py setIgnoreHardlinkMatches:n2b([ud objectForKey:@"ignoreHardlinkMatches"])]; [_py setMatchSimilarWords:[ud objectForKey:@"matchSimilarWords"]]; - NSInteger r = n2i([py doScan]); - if (r == 3) { - [Dialogs showMessage:@"The selected directories contain no scannable file."]; - } } -/* Public */ - (void)initResultColumns { NSTableColumn *refCol = [matches tableColumnWithIdentifier:@"0"]; @@ -106,6 +71,31 @@ http://www.hardcoded.net/licenses/bsd_license [_resultColumns addObject:[self getColumnForIdentifier:17 title:@"Dupe Count" width:80 refCol:refCol]]; } +/* Actions */ +- (IBAction)removeDeadTracks:(id)sender +{ + [(PyDupeGuru *)py scanDeadTracks]; +} + +- (IBAction)resetColumnsToDefault:(id)sender +{ + NSMutableArray *columnsOrder = [NSMutableArray array]; + [columnsOrder addObject:@"0"]; + [columnsOrder addObject:@"2"]; + [columnsOrder addObject:@"3"]; + [columnsOrder addObject:@"4"]; + [columnsOrder addObject:@"6"]; + [columnsOrder addObject:@"15"]; + NSMutableDictionary *columnsWidth = [NSMutableDictionary dictionary]; + [columnsWidth setObject:i2n(235) forKey:@"0"]; + [columnsWidth setObject:i2n(63) forKey:@"2"]; + [columnsWidth setObject:i2n(50) forKey:@"3"]; + [columnsWidth setObject:i2n(50) forKey:@"4"]; + [columnsWidth setObject:i2n(40) forKey:@"6"]; + [columnsWidth setObject:i2n(57) forKey:@"15"]; + [self restoreColumnsPosition:columnsOrder widths:columnsWidth]; +} + /* Notifications */ - (void)jobCompleted:(NSNotification *)aNotification { diff --git a/cocoa/pe/ResultWindow.m b/cocoa/pe/ResultWindow.m index 74578df6..8f815a58 100644 --- a/cocoa/pe/ResultWindow.m +++ b/cocoa/pe/ResultWindow.m @@ -8,10 +8,8 @@ http://www.hardcoded.net/licenses/bsd_license #import "ResultWindow.h" #import "Dialogs.h" -#import "ProgressController.h" #import "Utils.h" -#import "AppDelegate.h" -#import "Consts.h" +#import "PyDupeGuru.h" @implementation ResultWindow /* Override */ @@ -24,6 +22,40 @@ http://www.hardcoded.net/licenses/bsd_license return self; } +- (void)initResultColumns +{ + NSTableColumn *refCol = [matches tableColumnWithIdentifier:@"0"]; + _resultColumns = [[NSMutableArray alloc] init]; + [_resultColumns addObject:[matches tableColumnWithIdentifier:@"0"]]; // File Name + [_resultColumns addObject:[self getColumnForIdentifier:1 title:@"Directory" width:120 refCol:refCol]]; + NSTableColumn *sizeCol = [self getColumnForIdentifier:2 title:@"Size (KB)" width:63 refCol:refCol]; + [[sizeCol dataCell] setAlignment:NSRightTextAlignment]; + [_resultColumns addObject:sizeCol]; + [_resultColumns addObject:[self getColumnForIdentifier:3 title:@"Kind" width:40 refCol:refCol]]; + [_resultColumns addObject:[self getColumnForIdentifier:4 title:@"Dimensions" width:80 refCol:refCol]]; + [_resultColumns addObject:[self getColumnForIdentifier:5 title:@"Modification" width:120 refCol:refCol]]; + [_resultColumns addObject:[self getColumnForIdentifier:6 title:@"Match %" width:58 refCol:refCol]]; + [_resultColumns addObject:[self getColumnForIdentifier:7 title:@"Dupe Count" width:80 refCol:refCol]]; +} + +- (void)setScanOptions +{ + NSUserDefaults *ud = [NSUserDefaults standardUserDefaults]; + PyDupeGuru *_py = (PyDupeGuru *)py; + [_py setMinMatchPercentage:[ud objectForKey:@"minMatchPercentage"]]; + [_py setMixFileKind:n2b([ud objectForKey:@"mixFileKind"])]; + [_py setIgnoreHardlinkMatches:n2b([ud objectForKey:@"ignoreHardlinkMatches"])]; + [_py setMatchScaled:[ud objectForKey:@"matchScaled"]]; +} + +- (NSString *)getScanErrorMessageForCode:(NSInteger)errorCode +{ + if (errorCode == 4) { + return @"The iPhoto application couldn't be found."; + } + return [super getScanErrorMessageForCode:errorCode]; +} + /* Actions */ - (IBAction)clearPictureCache:(id)sender { @@ -48,45 +80,4 @@ http://www.hardcoded.net/licenses/bsd_license [columnsWidth setObject:i2n(58) forKey:@"6"]; [self restoreColumnsPosition:columnsOrder widths:columnsWidth]; } - -- (IBAction)startDuplicateScan:(id)sender -{ - if ([py resultsAreModified]) { - if ([Dialogs askYesNo:@"You have unsaved results, do you really want to continue?"] == NSAlertSecondButtonReturn) // NO - return; - } - NSUserDefaults *ud = [NSUserDefaults standardUserDefaults]; - PyDupeGuru *_py = (PyDupeGuru *)py; - [_py setMinMatchPercentage:[ud objectForKey:@"minMatchPercentage"]]; - [_py setMixFileKind:n2b([ud objectForKey:@"mixFileKind"])]; - [_py setIgnoreHardlinkMatches:n2b([ud objectForKey:@"ignoreHardlinkMatches"])]; - [_py setMatchScaled:[ud objectForKey:@"matchScaled"]]; - int r = n2i([py doScan]); - if (r != 0) { - [[ProgressController mainProgressController] hide]; - } - if (r == 3) { - [Dialogs showMessage:@"The selected directories contain no scannable file."]; - } - if (r == 4) { - [Dialogs showMessage:@"The iPhoto application couldn't be found."]; - } -} - -/* Public */ -- (void)initResultColumns -{ - NSTableColumn *refCol = [matches tableColumnWithIdentifier:@"0"]; - _resultColumns = [[NSMutableArray alloc] init]; - [_resultColumns addObject:[matches tableColumnWithIdentifier:@"0"]]; // File Name - [_resultColumns addObject:[self getColumnForIdentifier:1 title:@"Directory" width:120 refCol:refCol]]; - NSTableColumn *sizeCol = [self getColumnForIdentifier:2 title:@"Size (KB)" width:63 refCol:refCol]; - [[sizeCol dataCell] setAlignment:NSRightTextAlignment]; - [_resultColumns addObject:sizeCol]; - [_resultColumns addObject:[self getColumnForIdentifier:3 title:@"Kind" width:40 refCol:refCol]]; - [_resultColumns addObject:[self getColumnForIdentifier:4 title:@"Dimensions" width:80 refCol:refCol]]; - [_resultColumns addObject:[self getColumnForIdentifier:5 title:@"Modification" width:120 refCol:refCol]]; - [_resultColumns addObject:[self getColumnForIdentifier:6 title:@"Match %" width:58 refCol:refCol]]; - [_resultColumns addObject:[self getColumnForIdentifier:7 title:@"Dupe Count" width:80 refCol:refCol]]; -} @end \ No newline at end of file diff --git a/cocoa/se/ResultWindow.h b/cocoa/se/ResultWindow.h index 6e975180..f16c2e56 100644 --- a/cocoa/se/ResultWindow.h +++ b/cocoa/se/ResultWindow.h @@ -8,11 +8,6 @@ http://www.hardcoded.net/licenses/bsd_license #import #import "../base/ResultWindow.h" -#import "DirectoryPanel.h" -@interface ResultWindow : ResultWindowBase -{ - NSString *_lastAction; -} -- (IBAction)resetColumnsToDefault:(id)sender; +@interface ResultWindow : ResultWindowBase {} @end diff --git a/cocoa/se/ResultWindow.m b/cocoa/se/ResultWindow.m index 8f6f036c..43097f82 100644 --- a/cocoa/se/ResultWindow.m +++ b/cocoa/se/ResultWindow.m @@ -7,20 +7,49 @@ http://www.hardcoded.net/licenses/bsd_license */ #import "ResultWindow.h" -#import "../../cocoalib/Dialogs.h" -#import "../../cocoalib/ProgressController.h" -#import "../../cocoalib/Utils.h" -#import "AppDelegate.h" -#import "Consts.h" +#import "Utils.h" +#import "PyDupeGuru.h" @implementation ResultWindow /* Override */ -- (void)awakeFromNib +- (id)initWithParentApp:(AppDelegateBase *)aApp; { - [super awakeFromNib]; + self = [super initWithParentApp:aApp]; NSMutableIndexSet *deltaColumns = [NSMutableIndexSet indexSetWithIndex:2]; [deltaColumns addIndex:4]; [table setDeltaColumns:deltaColumns]; + return self; +} + +- (void)initResultColumns +{ + NSTableColumn *refCol = [matches tableColumnWithIdentifier:@"0"]; + _resultColumns = [[NSMutableArray alloc] init]; + [_resultColumns addObject:[matches tableColumnWithIdentifier:@"0"]]; // File Name + [_resultColumns addObject:[self getColumnForIdentifier:1 title:@"Directory" width:120 refCol:refCol]]; + NSTableColumn *sizeCol = [self getColumnForIdentifier:2 title:@"Size (KB)" width:63 refCol:refCol]; + [[sizeCol dataCell] setAlignment:NSRightTextAlignment]; + [_resultColumns addObject:sizeCol]; + [_resultColumns addObject:[self getColumnForIdentifier:3 title:@"Kind" width:40 refCol:refCol]]; + [_resultColumns addObject:[self getColumnForIdentifier:4 title:@"Modification" width:120 refCol:refCol]]; + [_resultColumns addObject:[self getColumnForIdentifier:5 title:@"Match %" width:60 refCol:refCol]]; + [_resultColumns addObject:[self getColumnForIdentifier:6 title:@"Words Used" width:120 refCol:refCol]]; + [_resultColumns addObject:[self getColumnForIdentifier:7 title:@"Dupe Count" width:80 refCol:refCol]]; +} + +- (void)setScanOptions +{ + NSUserDefaults *ud = [NSUserDefaults standardUserDefaults]; + PyDupeGuru *_py = (PyDupeGuru *)py; + [_py setScanType:[ud objectForKey:@"scanType"]]; + [_py setMinMatchPercentage:[ud objectForKey:@"minMatchPercentage"]]; + [_py setWordWeighting:[ud objectForKey:@"wordWeighting"]]; + [_py setMixFileKind:n2b([ud objectForKey:@"mixFileKind"])]; + [_py setIgnoreHardlinkMatches:n2b([ud objectForKey:@"ignoreHardlinkMatches"])]; + [_py setMatchSimilarWords:[ud objectForKey:@"matchSimilarWords"]]; + int smallFileThreshold = [ud integerForKey:@"smallFileThreshold"]; // In KB + int sizeThreshold = [ud boolForKey:@"ignoreSmallFiles"] ? smallFileThreshold * 1024 : 0; // The py side wants bytes + [_py setSizeThreshold:sizeThreshold]; } /* Actions */ @@ -38,47 +67,4 @@ http://www.hardcoded.net/licenses/bsd_license [columnsWidth setObject:i2n(60) forKey:@"5"]; [self restoreColumnsPosition:columnsOrder widths:columnsWidth]; } - -- (IBAction)startDuplicateScan:(id)sender -{ - if ([py resultsAreModified]) { - if ([Dialogs askYesNo:@"You have unsaved results, do you really want to continue?"] == NSAlertSecondButtonReturn) // NO - return; - } - NSUserDefaults *ud = [NSUserDefaults standardUserDefaults]; - PyDupeGuru *_py = (PyDupeGuru *)py; - [_py setScanType:[ud objectForKey:@"scanType"]]; - [_py setMinMatchPercentage:[ud objectForKey:@"minMatchPercentage"]]; - [_py setWordWeighting:[ud objectForKey:@"wordWeighting"]]; - [_py setMixFileKind:n2b([ud objectForKey:@"mixFileKind"])]; - [_py setIgnoreHardlinkMatches:n2b([ud objectForKey:@"ignoreHardlinkMatches"])]; - [_py setMatchSimilarWords:[ud objectForKey:@"matchSimilarWords"]]; - int smallFileThreshold = [ud integerForKey:@"smallFileThreshold"]; // In KB - int sizeThreshold = [ud boolForKey:@"ignoreSmallFiles"] ? smallFileThreshold * 1024 : 0; // The py side wants bytes - [_py setSizeThreshold:sizeThreshold]; - int r = n2i([py doScan]); - if (r != 0) - [[ProgressController mainProgressController] hide]; - if (r == 3) { - [Dialogs showMessage:@"The selected directories contain no scannable file."]; - } - -} - -/* Public */ -- (void)initResultColumns -{ - NSTableColumn *refCol = [matches tableColumnWithIdentifier:@"0"]; - _resultColumns = [[NSMutableArray alloc] init]; - [_resultColumns addObject:[matches tableColumnWithIdentifier:@"0"]]; // File Name - [_resultColumns addObject:[self getColumnForIdentifier:1 title:@"Directory" width:120 refCol:refCol]]; - NSTableColumn *sizeCol = [self getColumnForIdentifier:2 title:@"Size (KB)" width:63 refCol:refCol]; - [[sizeCol dataCell] setAlignment:NSRightTextAlignment]; - [_resultColumns addObject:sizeCol]; - [_resultColumns addObject:[self getColumnForIdentifier:3 title:@"Kind" width:40 refCol:refCol]]; - [_resultColumns addObject:[self getColumnForIdentifier:4 title:@"Modification" width:120 refCol:refCol]]; - [_resultColumns addObject:[self getColumnForIdentifier:5 title:@"Match %" width:60 refCol:refCol]]; - [_resultColumns addObject:[self getColumnForIdentifier:6 title:@"Words Used" width:120 refCol:refCol]]; - [_resultColumns addObject:[self getColumnForIdentifier:7 title:@"Dupe Count" width:80 refCol:refCol]]; -} @end