2009-08-05 08:59:46 +00:00
|
|
|
/*
|
2011-04-12 08:04:01 +00:00
|
|
|
Copyright 2011 Hardcoded Software (http://www.hardcoded.net)
|
2009-08-05 08:59:46 +00:00
|
|
|
|
2010-09-30 10:17:41 +00: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 10:17:41 +00:00
|
|
|
http://www.hardcoded.net/licenses/bsd_license
|
2009-08-05 08:59:46 +00:00
|
|
|
*/
|
|
|
|
|
2009-06-01 09:55:11 +00:00
|
|
|
#import "AppDelegate.h"
|
|
|
|
#import "ProgressController.h"
|
2010-09-29 14:49:50 +00:00
|
|
|
#import "HSFairwareReminder.h"
|
2009-06-01 09:55:11 +00:00
|
|
|
#import "Utils.h"
|
|
|
|
#import "Consts.h"
|
2011-01-13 15:20:03 +00:00
|
|
|
#import "Dialogs.h"
|
2011-09-23 13:14:16 +00:00
|
|
|
#import "ValueTransformers.h"
|
2010-02-05 15:51:00 +00:00
|
|
|
#import <Sparkle/SUUpdater.h>
|
2009-06-01 09:55:11 +00:00
|
|
|
|
|
|
|
@implementation AppDelegateBase
|
2011-09-23 13:14:16 +00:00
|
|
|
+ (void)initialize
|
|
|
|
{
|
|
|
|
HSVTAdd *vt = [[[HSVTAdd alloc] initWithValue:4] autorelease];
|
|
|
|
[NSValueTransformer setValueTransformer:vt forName:@"vtRowHeightOffset"];
|
|
|
|
}
|
|
|
|
|
2011-01-13 15:20:03 +00:00
|
|
|
- (void)awakeFromNib
|
|
|
|
{
|
2012-01-13 19:43:43 +00:00
|
|
|
model = [[PyDupeGuru alloc] init];
|
2012-01-13 22:02:41 +00:00
|
|
|
[model bindCallback:createCallback(@"DupeGuruView", self)];
|
2011-01-23 11:47:21 +00: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 15:20:03 +00:00
|
|
|
_recentResults = [[HSRecentFiles alloc] initWithName:@"recentResults" menu:recentResultsMenu];
|
|
|
|
[_recentResults setDelegate:self];
|
2011-01-15 11:08:10 +00:00
|
|
|
_resultWindow = [self createResultWindow];
|
|
|
|
_directoryPanel = [self createDirectoryPanel];
|
|
|
|
_detailsPanel = nil; // Lazily loaded
|
|
|
|
_aboutBox = nil; // Lazily loaded
|
|
|
|
_preferencesPanel = nil; // Lazily loaded
|
2011-01-14 13:41:43 +00:00
|
|
|
[[[self directoryPanel] window] makeKeyAndOrderFront:self];
|
2011-01-13 15:20:03 +00:00
|
|
|
}
|
|
|
|
|
2011-01-14 12:56:50 +00:00
|
|
|
/* Virtual */
|
|
|
|
|
2012-01-13 19:43:43 +00:00
|
|
|
- (PyDupeGuru *)model
|
|
|
|
{
|
|
|
|
return model;
|
|
|
|
}
|
2011-01-14 12:56:50 +00:00
|
|
|
|
|
|
|
- (ResultWindowBase *)createResultWindow
|
|
|
|
{
|
|
|
|
return nil; // must be overriden by all editions
|
|
|
|
}
|
|
|
|
|
|
|
|
- (DirectoryPanel *)createDirectoryPanel
|
|
|
|
{
|
|
|
|
return [[DirectoryPanel alloc] initWithParentApp:self];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (DetailsPanel *)createDetailsPanel
|
|
|
|
{
|
2012-01-13 20:25:34 +00:00
|
|
|
return [[DetailsPanel alloc] initWithPyRef:[model detailsPanel]];
|
2011-01-14 12:56:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *)homepageURL
|
|
|
|
{
|
|
|
|
return @""; // must be overriden by all editions
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Public */
|
|
|
|
- (ResultWindowBase *)resultWindow
|
|
|
|
{
|
|
|
|
return _resultWindow;
|
|
|
|
}
|
|
|
|
|
2010-02-05 16:05:00 +00:00
|
|
|
- (DirectoryPanel *)directoryPanel
|
|
|
|
{
|
|
|
|
return _directoryPanel;
|
|
|
|
}
|
|
|
|
|
2010-02-05 16:15:45 +00:00
|
|
|
- (DetailsPanel *)detailsPanel
|
|
|
|
{
|
|
|
|
if (!_detailsPanel)
|
2011-01-14 12:56:50 +00:00
|
|
|
_detailsPanel = [self createDetailsPanel];
|
2010-02-05 16:15:45 +00:00
|
|
|
return _detailsPanel;
|
|
|
|
}
|
2009-10-30 14:40:17 +00:00
|
|
|
|
2011-01-13 15:20:03 +00:00
|
|
|
- (HSRecentFiles *)recentResults
|
2010-02-05 15:51:00 +00:00
|
|
|
{
|
2011-01-13 15:20:03 +00:00
|
|
|
return _recentResults;
|
|
|
|
}
|
|
|
|
|
2011-01-14 12:56:50 +00:00
|
|
|
- (NSMenu *)columnsMenu { return columnsMenu; }
|
2010-02-05 15:51:00 +00:00
|
|
|
|
2011-01-14 12:56:50 +00:00
|
|
|
/* Actions */
|
2011-01-14 14:34:10 +00:00
|
|
|
- (IBAction)loadResults:(id)sender
|
2010-12-30 12:00:44 +00:00
|
|
|
{
|
2011-01-14 14:34:10 +00:00
|
|
|
NSOpenPanel *op = [NSOpenPanel openPanel];
|
|
|
|
[op setCanChooseFiles:YES];
|
|
|
|
[op setCanChooseDirectories:NO];
|
|
|
|
[op setCanCreateDirectories:NO];
|
|
|
|
[op setAllowsMultipleSelection:NO];
|
|
|
|
[op setAllowedFileTypes:[NSArray arrayWithObject:@"dupeguru"]];
|
2011-11-04 17:10:11 +00:00
|
|
|
[op setTitle:TR(@"Select a results file to load")];
|
2011-01-14 14:34:10 +00:00
|
|
|
if ([op runModal] == NSOKButton) {
|
|
|
|
NSString *filename = [[op filenames] objectAtIndex:0];
|
2012-01-13 19:43:43 +00:00
|
|
|
[model loadResultsFrom:filename];
|
2011-01-14 14:34:10 +00:00
|
|
|
[[self recentResults] addFile:filename];
|
2010-12-30 12:00:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-12 16:30:57 +00:00
|
|
|
- (IBAction)openWebsite:(id)sender
|
|
|
|
{
|
2011-01-13 15:20:03 +00:00
|
|
|
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:[self homepageURL]]];
|
2011-01-12 16:30:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)openHelp:(id)sender
|
|
|
|
{
|
|
|
|
NSBundle *b = [NSBundle mainBundle];
|
|
|
|
NSString *p = [b pathForResource:@"index" ofType:@"html" inDirectory:@"help"];
|
|
|
|
NSURL *u = [NSURL fileURLWithPath:p];
|
|
|
|
[[NSWorkspace sharedWorkspace] openURL:u];
|
|
|
|
}
|
|
|
|
|
2011-01-14 14:34:10 +00:00
|
|
|
- (IBAction)showAboutBox:(id)sender
|
|
|
|
{
|
|
|
|
if (_aboutBox == nil) {
|
2012-01-13 19:43:43 +00:00
|
|
|
_aboutBox = [[HSAboutBox alloc] initWithApp:model];
|
2011-01-14 14:34:10 +00:00
|
|
|
}
|
|
|
|
[[_aboutBox window] makeKeyAndOrderFront:sender];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)showDirectoryWindow:(id)sender
|
|
|
|
{
|
|
|
|
[[[self directoryPanel] window] makeKeyAndOrderFront:nil];
|
|
|
|
}
|
|
|
|
|
2011-01-14 13:06:54 +00:00
|
|
|
- (IBAction)showPreferencesPanel:(id)sender
|
|
|
|
{
|
|
|
|
if (_preferencesPanel == nil) {
|
|
|
|
_preferencesPanel = [[NSWindowController alloc] initWithWindowNibName:@"Preferences"];
|
|
|
|
}
|
|
|
|
[_preferencesPanel showWindow:sender];
|
|
|
|
}
|
|
|
|
|
2011-01-14 14:34:10 +00:00
|
|
|
- (IBAction)showResultWindow:(id)sender
|
2011-01-14 13:41:43 +00:00
|
|
|
{
|
2011-01-14 14:34:10 +00:00
|
|
|
[[[self resultWindow] window] makeKeyAndOrderFront:nil];
|
2011-01-14 13:41:43 +00:00
|
|
|
}
|
|
|
|
|
2011-01-14 14:34:10 +00:00
|
|
|
- (IBAction)startScanning:(id)sender
|
2011-01-13 15:20:03 +00:00
|
|
|
{
|
2011-01-14 14:34:10 +00:00
|
|
|
[[self resultWindow] startDuplicateScan:sender];
|
2011-01-13 15:20:03 +00:00
|
|
|
}
|
|
|
|
|
2011-01-14 14:34:10 +00:00
|
|
|
|
2009-10-30 14:40:17 +00:00
|
|
|
/* Delegate */
|
|
|
|
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
|
|
|
|
{
|
2012-01-13 19:43:43 +00:00
|
|
|
[[ProgressController mainProgressController] setWorker:model];
|
|
|
|
[model initialRegistrationSetup];
|
|
|
|
[model loadSession];
|
2009-10-30 14:40:17 +00:00
|
|
|
}
|
2010-02-05 15:31:09 +00:00
|
|
|
|
|
|
|
- (void)applicationWillBecomeActive:(NSNotification *)aNotification
|
|
|
|
{
|
2011-01-14 13:41:43 +00:00
|
|
|
if (![[[self directoryPanel] window] isVisible]) {
|
|
|
|
[[self directoryPanel] showWindow:NSApp];
|
|
|
|
}
|
2010-02-05 15:31:09 +00:00
|
|
|
}
|
|
|
|
|
2011-01-13 15:20:03 +00:00
|
|
|
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
|
|
|
|
{
|
2012-01-13 19:43:43 +00:00
|
|
|
if ([model resultsAreModified]) {
|
2011-11-04 17:10:11 +00:00
|
|
|
NSString *msg = TR(@"You have unsaved results, do you really want to quit?");
|
2011-01-13 15:20:03 +00:00
|
|
|
if ([Dialogs askYesNo:msg] == NSAlertSecondButtonReturn) { // NO
|
|
|
|
return NSTerminateCancel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NSTerminateNow;
|
|
|
|
}
|
|
|
|
|
2010-02-05 15:31:09 +00:00
|
|
|
- (void)applicationWillTerminate:(NSNotification *)aNotification
|
|
|
|
{
|
|
|
|
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
|
|
|
|
NSInteger sc = [ud integerForKey:@"sessionCountSinceLastIgnorePurge"];
|
2011-01-13 15:20:03 +00:00
|
|
|
if (sc >= 10) {
|
2010-02-05 15:31:09 +00:00
|
|
|
sc = -1;
|
2012-01-13 19:43:43 +00:00
|
|
|
[model purgeIgnoreList];
|
2010-02-05 15:31:09 +00:00
|
|
|
}
|
|
|
|
sc++;
|
2012-01-13 19:43:43 +00:00
|
|
|
[model saveSession];
|
2010-02-05 15:31:09 +00: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 15:20:03 +00:00
|
|
|
// But I need to release HSRecentFiles so it saves the user defaults
|
|
|
|
[_directoryPanel release];
|
|
|
|
[_recentResults release];
|
2010-02-05 15:31:09 +00:00
|
|
|
}
|
|
|
|
|
2011-01-13 15:20:03 +00:00
|
|
|
- (void)recentFileClicked:(NSString *)path
|
2010-02-05 15:51:00 +00:00
|
|
|
{
|
2012-01-13 19:43:43 +00:00
|
|
|
[model loadResultsFrom:path];
|
2010-02-05 15:51:00 +00:00
|
|
|
}
|
2011-03-05 12:03:23 +00:00
|
|
|
|
2011-09-21 19:24:26 +00:00
|
|
|
|
|
|
|
/* model --> view */
|
2011-09-22 14:35:17 +00:00
|
|
|
- (void)showMessage:(NSString *)msg
|
|
|
|
{
|
|
|
|
[Dialogs showMessage:msg];
|
|
|
|
}
|
2011-09-24 20:21:20 +00:00
|
|
|
|
2012-03-09 16:34:08 +00:00
|
|
|
- (BOOL)askYesNoWithPrompt:(NSString *)prompt
|
|
|
|
{
|
|
|
|
return [Dialogs askYesNo:prompt] == NSAlertFirstButtonReturn;
|
|
|
|
}
|
|
|
|
|
2011-09-24 20:21:20 +00:00
|
|
|
- (void)setupAsRegistered
|
|
|
|
{
|
|
|
|
// Nothing to do.
|
|
|
|
}
|
|
|
|
|
2011-09-26 15:54:17 +00:00
|
|
|
- (void)showFairwareNagWithPrompt:(NSString *)prompt
|
2011-09-24 20:21:20 +00:00
|
|
|
{
|
2012-01-13 19:43:43 +00:00
|
|
|
[HSFairwareReminder showFairwareNagWithApp:[self model] prompt:prompt];
|
2011-09-26 15:54:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)showDemoNagWithPrompt:(NSString *)prompt
|
|
|
|
{
|
2012-01-13 19:43:43 +00:00
|
|
|
[HSFairwareReminder showDemoNagWithApp:[self model] prompt:prompt];
|
2011-09-24 20:21:20 +00:00
|
|
|
}
|
2009-06-01 09:55:11 +00:00
|
|
|
@end
|