2009-08-05 08:59:46 +00:00
|
|
|
/*
|
2013-04-28 10:35:51 -04:00
|
|
|
Copyright 2013 Hardcoded Software (http://www.hardcoded.net)
|
2009-08-05 08:59:46 +00:00
|
|
|
|
2010-09-30 12:17:41 +02:00
|
|
|
This software is licensed under the "BSD" License as described in the "LICENSE" file,
|
2009-08-05 08:59:46 +00:00
|
|
|
which should be included with this package. The terms are also available at
|
2010-09-30 12:17:41 +02:00
|
|
|
http://www.hardcoded.net/licenses/bsd_license
|
2009-08-05 08:59:46 +00:00
|
|
|
*/
|
|
|
|
|
2012-07-27 18:30:34 -04:00
|
|
|
#import "AppDelegateBase.h"
|
2009-06-01 09:55:11 +00:00
|
|
|
#import "ProgressController.h"
|
2010-09-29 16:49:50 +02:00
|
|
|
#import "HSFairwareReminder.h"
|
2012-05-28 14:45:13 -04:00
|
|
|
#import "HSPyUtil.h"
|
2009-06-01 09:55:11 +00:00
|
|
|
#import "Consts.h"
|
2011-01-13 16:20:03 +01:00
|
|
|
#import "Dialogs.h"
|
2012-07-31 10:27:36 -04:00
|
|
|
#import "Utils.h"
|
2011-09-23 09:14:16 -04:00
|
|
|
#import "ValueTransformers.h"
|
2012-07-27 15:21:35 -04:00
|
|
|
#import "PreferencesPanel_UI.h"
|
2009-06-01 09:55:11 +00:00
|
|
|
|
|
|
|
@implementation AppDelegateBase
|
2012-07-27 18:30:34 -04:00
|
|
|
|
|
|
|
@synthesize recentResultsMenu;
|
|
|
|
@synthesize columnsMenu;
|
|
|
|
@synthesize updater;
|
|
|
|
|
2012-07-31 10:27:36 -04:00
|
|
|
+ (NSDictionary *)defaultPreferences
|
|
|
|
{
|
|
|
|
NSMutableDictionary *d = [NSMutableDictionary dictionary];
|
|
|
|
[d setObject:i2n(1) forKey:@"recreatePathType"];
|
|
|
|
[d setObject:i2n(11) forKey:TableFontSize];
|
|
|
|
[d setObject:b2n(YES) forKey:@"mixFileKind"];
|
|
|
|
[d setObject:b2n(NO) forKey:@"useRegexpFilter"];
|
|
|
|
[d setObject:b2n(NO) forKey:@"ignoreHardlinkMatches"];
|
|
|
|
[d setObject:b2n(NO) forKey:@"removeEmptyFolders"];
|
|
|
|
[d setObject:b2n(NO) forKey:@"DebugMode"];
|
|
|
|
[d setObject:@"" forKey:@"CustomCommand"];
|
|
|
|
[d setObject:[NSArray array] forKey:@"recentDirectories"];
|
|
|
|
[d setObject:[NSArray array] forKey:@"columnsOrder"];
|
|
|
|
[d setObject:[NSDictionary dictionary] forKey:@"columnsWidth"];
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
2011-09-23 09:14:16 -04:00
|
|
|
+ (void)initialize
|
|
|
|
{
|
|
|
|
HSVTAdd *vt = [[[HSVTAdd alloc] initWithValue:4] autorelease];
|
|
|
|
[NSValueTransformer setValueTransformer:vt forName:@"vtRowHeightOffset"];
|
2012-07-31 10:27:36 -04:00
|
|
|
NSDictionary *d = [self defaultPreferences];
|
|
|
|
[[NSUserDefaultsController sharedUserDefaultsController] setInitialValues:d];
|
|
|
|
[[NSUserDefaults standardUserDefaults] registerDefaults:d];
|
2011-09-23 09:14:16 -04:00
|
|
|
}
|
|
|
|
|
2012-07-27 18:30:34 -04:00
|
|
|
- (id)init
|
2011-01-13 16:20:03 +01:00
|
|
|
{
|
2012-07-27 18:30:34 -04:00
|
|
|
self = [super init];
|
2012-01-13 14:43:43 -05:00
|
|
|
model = [[PyDupeGuru alloc] init];
|
2012-01-13 17:02:41 -05:00
|
|
|
[model bindCallback:createCallback(@"DupeGuruView", self)];
|
2012-07-27 18:30:34 -04:00
|
|
|
[self setUpdater:[SUUpdater sharedUpdater]];
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)finalizeInit
|
|
|
|
{
|
|
|
|
// We can only finalize initialization once the main menu has been created, which cannot happen
|
|
|
|
// before AppDelegate is created.
|
2011-01-23 12:47:21 +01:00
|
|
|
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
|
|
|
|
/* Because the pref pane is lazily loaded, we have to manually do the update check if the
|
|
|
|
preference is set.
|
|
|
|
*/
|
|
|
|
if ([ud boolForKey:@"SUEnableAutomaticChecks"]) {
|
|
|
|
[[SUUpdater sharedUpdater] checkForUpdatesInBackground];
|
|
|
|
}
|
2011-01-13 16:20:03 +01:00
|
|
|
_recentResults = [[HSRecentFiles alloc] initWithName:@"recentResults" menu:recentResultsMenu];
|
|
|
|
[_recentResults setDelegate:self];
|
2011-01-15 12:08:10 +01:00
|
|
|
_resultWindow = [self createResultWindow];
|
|
|
|
_directoryPanel = [self createDirectoryPanel];
|
2012-03-13 14:27:08 -04:00
|
|
|
_detailsPanel = [self createDetailsPanel];
|
2012-03-14 12:47:21 -04:00
|
|
|
_ignoreListDialog = [[IgnoreListDialog alloc] initWithPyRef:[model ignoreListDialog]];
|
2011-01-15 12:08:10 +01:00
|
|
|
_aboutBox = nil; // Lazily loaded
|
|
|
|
_preferencesPanel = nil; // Lazily loaded
|
2011-01-14 14:41:43 +01:00
|
|
|
[[[self directoryPanel] window] makeKeyAndOrderFront:self];
|
2011-01-13 16:20:03 +01:00
|
|
|
}
|
|
|
|
|
2011-01-14 13:56:50 +01:00
|
|
|
/* Virtual */
|
|
|
|
|
2012-01-13 14:43:43 -05:00
|
|
|
- (PyDupeGuru *)model
|
|
|
|
{
|
|
|
|
return model;
|
|
|
|
}
|
2011-01-14 13:56:50 +01:00
|
|
|
|
|
|
|
- (ResultWindowBase *)createResultWindow
|
|
|
|
{
|
|
|
|
return nil; // must be overriden by all editions
|
|
|
|
}
|
|
|
|
|
|
|
|
- (DirectoryPanel *)createDirectoryPanel
|
|
|
|
{
|
|
|
|
return [[DirectoryPanel alloc] initWithParentApp:self];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (DetailsPanel *)createDetailsPanel
|
|
|
|
{
|
2012-01-13 15:25:34 -05:00
|
|
|
return [[DetailsPanel alloc] initWithPyRef:[model detailsPanel]];
|
2011-01-14 13:56:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *)homepageURL
|
|
|
|
{
|
|
|
|
return @""; // must be overriden by all editions
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Public */
|
|
|
|
- (ResultWindowBase *)resultWindow
|
|
|
|
{
|
|
|
|
return _resultWindow;
|
|
|
|
}
|
|
|
|
|
2010-02-05 17:05:00 +01:00
|
|
|
- (DirectoryPanel *)directoryPanel
|
|
|
|
{
|
|
|
|
return _directoryPanel;
|
|
|
|
}
|
|
|
|
|
2010-02-05 17:15:45 +01:00
|
|
|
- (DetailsPanel *)detailsPanel
|
|
|
|
{
|
|
|
|
return _detailsPanel;
|
|
|
|
}
|
2009-10-30 14:40:17 +00:00
|
|
|
|
2011-01-13 16:20:03 +01:00
|
|
|
- (HSRecentFiles *)recentResults
|
2010-02-05 16:51:00 +01:00
|
|
|
{
|
2011-01-13 16:20:03 +01:00
|
|
|
return _recentResults;
|
|
|
|
}
|
|
|
|
|
2011-01-14 13:56:50 +01:00
|
|
|
/* Actions */
|
2012-07-27 18:30:34 -04:00
|
|
|
- (void)loadResults
|
2010-12-30 13:00:44 +01:00
|
|
|
{
|
2011-01-14 15:34:10 +01:00
|
|
|
NSOpenPanel *op = [NSOpenPanel openPanel];
|
|
|
|
[op setCanChooseFiles:YES];
|
|
|
|
[op setCanChooseDirectories:NO];
|
|
|
|
[op setCanCreateDirectories:NO];
|
|
|
|
[op setAllowsMultipleSelection:NO];
|
|
|
|
[op setAllowedFileTypes:[NSArray arrayWithObject:@"dupeguru"]];
|
2012-08-01 16:34:12 -04:00
|
|
|
[op setTitle:NSLocalizedString(@"Select a results file to load", @"")];
|
2011-01-14 15:34:10 +01:00
|
|
|
if ([op runModal] == NSOKButton) {
|
|
|
|
NSString *filename = [[op filenames] objectAtIndex:0];
|
2012-01-13 14:43:43 -05:00
|
|
|
[model loadResultsFrom:filename];
|
2011-01-14 15:34:10 +01:00
|
|
|
[[self recentResults] addFile:filename];
|
2010-12-30 13:00:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-27 18:30:34 -04:00
|
|
|
- (void)openWebsite
|
2011-01-12 17:30:57 +01:00
|
|
|
{
|
2011-01-13 16:20:03 +01:00
|
|
|
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:[self homepageURL]]];
|
2011-01-12 17:30:57 +01:00
|
|
|
}
|
|
|
|
|
2012-07-27 18:30:34 -04:00
|
|
|
- (void)openHelp
|
2011-01-12 17:30:57 +01:00
|
|
|
{
|
|
|
|
NSBundle *b = [NSBundle mainBundle];
|
|
|
|
NSString *p = [b pathForResource:@"index" ofType:@"html" inDirectory:@"help"];
|
|
|
|
NSURL *u = [NSURL fileURLWithPath:p];
|
|
|
|
[[NSWorkspace sharedWorkspace] openURL:u];
|
|
|
|
}
|
|
|
|
|
2012-07-27 18:30:34 -04:00
|
|
|
- (void)showAboutBox
|
2011-01-14 15:34:10 +01:00
|
|
|
{
|
|
|
|
if (_aboutBox == nil) {
|
2013-03-24 18:53:41 -04:00
|
|
|
_aboutBox = [[HSFairwareAboutBox alloc] initWithApp:model];
|
2011-01-14 15:34:10 +01:00
|
|
|
}
|
2012-07-27 18:30:34 -04:00
|
|
|
[[_aboutBox window] makeKeyAndOrderFront:nil];
|
2011-01-14 15:34:10 +01:00
|
|
|
}
|
|
|
|
|
2012-07-27 18:30:34 -04:00
|
|
|
- (void)showDirectoryWindow
|
2011-01-14 15:34:10 +01:00
|
|
|
{
|
|
|
|
[[[self directoryPanel] window] makeKeyAndOrderFront:nil];
|
|
|
|
}
|
|
|
|
|
2012-07-27 18:30:34 -04:00
|
|
|
- (void)showPreferencesPanel
|
2011-01-14 14:06:54 +01:00
|
|
|
{
|
|
|
|
if (_preferencesPanel == nil) {
|
2012-07-27 15:21:35 -04:00
|
|
|
_preferencesPanel = [[NSWindowController alloc] initWithWindow:createPreferencesPanel_UI(nil)];
|
2011-01-14 14:06:54 +01:00
|
|
|
}
|
2012-07-27 18:30:34 -04:00
|
|
|
[_preferencesPanel showWindow:nil];
|
2011-01-14 14:06:54 +01:00
|
|
|
}
|
|
|
|
|
2012-07-27 18:30:34 -04:00
|
|
|
- (void)showResultWindow
|
2011-01-14 14:41:43 +01:00
|
|
|
{
|
2011-01-14 15:34:10 +01:00
|
|
|
[[[self resultWindow] window] makeKeyAndOrderFront:nil];
|
2011-01-14 14:41:43 +01:00
|
|
|
}
|
|
|
|
|
2012-07-27 18:30:34 -04:00
|
|
|
- (void)showIgnoreList
|
2012-03-14 12:47:21 -04:00
|
|
|
{
|
|
|
|
[model showIgnoreList];
|
|
|
|
}
|
|
|
|
|
2012-07-27 18:30:34 -04:00
|
|
|
- (void)startScanning
|
2011-01-13 16:20:03 +01:00
|
|
|
{
|
2012-07-29 11:16:04 -04:00
|
|
|
[[self resultWindow] startDuplicateScan];
|
2011-01-13 16:20:03 +01:00
|
|
|
}
|
|
|
|
|
2011-01-14 15:34:10 +01:00
|
|
|
|
2009-10-30 14:40:17 +00:00
|
|
|
/* Delegate */
|
|
|
|
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
|
|
|
|
{
|
2012-01-13 14:43:43 -05:00
|
|
|
[[ProgressController mainProgressController] setWorker:model];
|
|
|
|
[model initialRegistrationSetup];
|
|
|
|
[model loadSession];
|
2009-10-30 14:40:17 +00:00
|
|
|
}
|
2010-02-05 16:31:09 +01:00
|
|
|
|
|
|
|
- (void)applicationWillBecomeActive:(NSNotification *)aNotification
|
|
|
|
{
|
2011-01-14 14:41:43 +01:00
|
|
|
if (![[[self directoryPanel] window] isVisible]) {
|
|
|
|
[[self directoryPanel] showWindow:NSApp];
|
|
|
|
}
|
2010-02-05 16:31:09 +01:00
|
|
|
}
|
|
|
|
|
2011-01-13 16:20:03 +01:00
|
|
|
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
|
|
|
|
{
|
2012-01-13 14:43:43 -05:00
|
|
|
if ([model resultsAreModified]) {
|
2012-08-01 16:34:12 -04:00
|
|
|
NSString *msg = NSLocalizedString(@"You have unsaved results, do you really want to quit?", @"");
|
2011-01-13 16:20:03 +01:00
|
|
|
if ([Dialogs askYesNo:msg] == NSAlertSecondButtonReturn) { // NO
|
|
|
|
return NSTerminateCancel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NSTerminateNow;
|
|
|
|
}
|
|
|
|
|
2010-02-05 16:31:09 +01:00
|
|
|
- (void)applicationWillTerminate:(NSNotification *)aNotification
|
|
|
|
{
|
|
|
|
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
|
|
|
|
NSInteger sc = [ud integerForKey:@"sessionCountSinceLastIgnorePurge"];
|
2011-01-13 16:20:03 +01:00
|
|
|
if (sc >= 10) {
|
2010-02-05 16:31:09 +01:00
|
|
|
sc = -1;
|
2012-01-13 14:43:43 -05:00
|
|
|
[model purgeIgnoreList];
|
2010-02-05 16:31:09 +01:00
|
|
|
}
|
|
|
|
sc++;
|
2012-01-13 14:43:43 -05:00
|
|
|
[model saveSession];
|
2010-02-05 16:31:09 +01:00
|
|
|
[ud setInteger:sc forKey:@"sessionCountSinceLastIgnorePurge"];
|
|
|
|
// NSApplication does not release nib instances objects, we must do it manually
|
|
|
|
// Well, it isn't needed because the memory is freed anyway (we are quitting the application
|
2011-01-13 16:20:03 +01:00
|
|
|
// But I need to release HSRecentFiles so it saves the user defaults
|
|
|
|
[_directoryPanel release];
|
|
|
|
[_recentResults release];
|
2010-02-05 16:31:09 +01:00
|
|
|
}
|
|
|
|
|
2011-01-13 16:20:03 +01:00
|
|
|
- (void)recentFileClicked:(NSString *)path
|
2010-02-05 16:51:00 +01:00
|
|
|
{
|
2012-01-13 14:43:43 -05:00
|
|
|
[model loadResultsFrom:path];
|
2010-02-05 16:51:00 +01:00
|
|
|
}
|
2011-03-05 13:03:23 +01:00
|
|
|
|
2011-09-21 15:24:26 -04:00
|
|
|
|
|
|
|
/* model --> view */
|
2011-09-22 10:35:17 -04:00
|
|
|
- (void)showMessage:(NSString *)msg
|
|
|
|
{
|
|
|
|
[Dialogs showMessage:msg];
|
|
|
|
}
|
2011-09-24 16:21:20 -04:00
|
|
|
|
2012-03-09 11:34:08 -05:00
|
|
|
- (BOOL)askYesNoWithPrompt:(NSString *)prompt
|
|
|
|
{
|
|
|
|
return [Dialogs askYesNo:prompt] == NSAlertFirstButtonReturn;
|
|
|
|
}
|
|
|
|
|
2012-03-09 13:47:28 -05:00
|
|
|
- (void)showProblemDialog
|
|
|
|
{
|
|
|
|
[[self resultWindow] showProblemDialog];
|
|
|
|
}
|
|
|
|
|
2011-09-24 16:21:20 -04:00
|
|
|
- (void)setupAsRegistered
|
|
|
|
{
|
|
|
|
// Nothing to do.
|
|
|
|
}
|
|
|
|
|
2011-09-26 11:54:17 -04:00
|
|
|
- (void)showDemoNagWithPrompt:(NSString *)prompt
|
|
|
|
{
|
2012-01-13 14:43:43 -05:00
|
|
|
[HSFairwareReminder showDemoNagWithApp:[self model] prompt:prompt];
|
2011-09-24 16:21:20 -04:00
|
|
|
}
|
2012-03-10 14:32:56 -05:00
|
|
|
|
|
|
|
- (NSString *)selectDestFolderWithPrompt:(NSString *)prompt
|
|
|
|
{
|
|
|
|
NSOpenPanel *op = [NSOpenPanel openPanel];
|
|
|
|
[op setCanChooseFiles:NO];
|
|
|
|
[op setCanChooseDirectories:YES];
|
|
|
|
[op setCanCreateDirectories:YES];
|
|
|
|
[op setAllowsMultipleSelection:NO];
|
|
|
|
[op setTitle:prompt];
|
|
|
|
if ([op runModal] == NSOKButton) {
|
|
|
|
return [[op filenames] objectAtIndex:0];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-31 16:46:51 -04:00
|
|
|
- (NSString *)selectDestFileWithPrompt:(NSString *)prompt extension:(NSString *)extension
|
|
|
|
{
|
|
|
|
NSSavePanel *sp = [NSSavePanel savePanel];
|
|
|
|
[sp setCanCreateDirectories:YES];
|
|
|
|
[sp setAllowedFileTypes:[NSArray arrayWithObject:extension]];
|
|
|
|
[sp setTitle:prompt];
|
|
|
|
if ([sp runModal] == NSOKButton) {
|
|
|
|
return [sp filename];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-01 09:55:11 +00:00
|
|
|
@end
|