2009-08-05 08:59:46 +00:00
|
|
|
/*
|
2010-01-01 20:11:34 +00:00
|
|
|
Copyright 2010 Hardcoded Software (http://www.hardcoded.net)
|
2009-08-05 08:59:46 +00:00
|
|
|
|
|
|
|
This software is licensed under the "HS" License as described in the "LICENSE" file,
|
|
|
|
which should be included with this package. The terms are also available at
|
|
|
|
http://www.hardcoded.net/licenses/hs_license
|
|
|
|
*/
|
|
|
|
|
2009-06-01 09:55:11 +00:00
|
|
|
#import "AppDelegate.h"
|
|
|
|
#import "ProgressController.h"
|
|
|
|
#import "RegistrationInterface.h"
|
|
|
|
#import "Utils.h"
|
|
|
|
#import "Consts.h"
|
2010-02-05 15:51:00 +00:00
|
|
|
#import <Sparkle/SUUpdater.h>
|
2009-06-01 09:55:11 +00:00
|
|
|
|
|
|
|
@implementation AppDelegateBase
|
|
|
|
- (IBAction)unlockApp:(id)sender
|
|
|
|
{
|
|
|
|
if ([[self py] isRegistered])
|
|
|
|
return;
|
2010-01-13 08:30:10 +00:00
|
|
|
RegistrationInterface *ri = [[RegistrationInterface alloc] initWithApp:[self py]];
|
2009-06-01 09:55:11 +00:00
|
|
|
if ([ri enterCode] == NSOKButton)
|
|
|
|
{
|
2010-01-13 08:30:10 +00:00
|
|
|
NSString *menuTitle = [NSString stringWithFormat:@"Thanks for buying %@!",[py appName]];
|
2009-06-01 09:55:11 +00:00
|
|
|
[unlockMenuItem setTitle:menuTitle];
|
|
|
|
}
|
|
|
|
[ri release];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (PyDupeGuruBase *)py { return py; }
|
|
|
|
- (RecentDirectories *)recentDirectories { return recentDirectories; }
|
2010-02-05 15:51:00 +00:00
|
|
|
- (DirectoryPanelBase *)directoryPanel {return nil; } // Virtual
|
2009-11-02 15:16:34 +00:00
|
|
|
- (DetailsPanelBase *)detailsPanel { return nil; } // Virtual
|
2009-10-30 14:40:17 +00:00
|
|
|
|
2010-02-05 15:51:00 +00:00
|
|
|
- (void)saveResults
|
|
|
|
{
|
|
|
|
if (_savedResults) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
[py saveIgnoreList];
|
|
|
|
[py saveResults];
|
|
|
|
_savedResults = YES;
|
|
|
|
}
|
|
|
|
|
2009-10-30 14:40:17 +00:00
|
|
|
/* Delegate */
|
|
|
|
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
|
|
|
|
{
|
|
|
|
[[ProgressController mainProgressController] setWorker:py];
|
|
|
|
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
|
|
|
|
//Restore Columns
|
|
|
|
NSArray *columnsOrder = [ud arrayForKey:@"columnsOrder"];
|
|
|
|
NSDictionary *columnsWidth = [ud dictionaryForKey:@"columnsWidth"];
|
|
|
|
if ([columnsOrder count])
|
|
|
|
[result restoreColumnsPosition:columnsOrder widths:columnsWidth];
|
|
|
|
else
|
|
|
|
[result resetColumnsToDefault:nil];
|
|
|
|
//Reg stuff
|
2010-01-13 08:30:10 +00:00
|
|
|
if ([RegistrationInterface showNagWithApp:[self py]])
|
|
|
|
[unlockMenuItem setTitle:[NSString stringWithFormat:@"Thanks for buying %@!",[py appName]]];
|
2009-10-30 14:40:17 +00:00
|
|
|
//Restore results
|
|
|
|
[py loadIgnoreList];
|
|
|
|
[py loadResults];
|
2010-02-05 15:51:00 +00:00
|
|
|
_savedResults = NO;
|
2009-10-30 14:40:17 +00:00
|
|
|
}
|
2010-02-05 15:31:09 +00:00
|
|
|
|
|
|
|
- (void)applicationWillBecomeActive:(NSNotification *)aNotification
|
|
|
|
{
|
|
|
|
if (![[result window] isVisible])
|
|
|
|
[result showWindow:NSApp];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)applicationWillTerminate:(NSNotification *)aNotification
|
|
|
|
{
|
|
|
|
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
|
|
|
|
[ud setObject: [result getColumnsOrder] forKey:@"columnsOrder"];
|
|
|
|
[ud setObject: [result getColumnsWidth] forKey:@"columnsWidth"];
|
2010-02-05 15:51:00 +00:00
|
|
|
[self saveResults];
|
2010-02-05 15:31:09 +00:00
|
|
|
NSInteger sc = [ud integerForKey:@"sessionCountSinceLastIgnorePurge"];
|
|
|
|
if (sc >= 10)
|
|
|
|
{
|
|
|
|
sc = -1;
|
|
|
|
[py purgeIgnoreList];
|
|
|
|
}
|
|
|
|
sc++;
|
|
|
|
[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
|
|
|
|
// But I need to release RecentDirectories so it saves the user defaults
|
|
|
|
[recentDirectories release];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)recentDirecoryClicked:(NSString *)directory
|
|
|
|
{
|
|
|
|
[[self directoryPanel] addDirectory:directory];
|
|
|
|
}
|
2010-02-05 15:51:00 +00:00
|
|
|
|
|
|
|
/* SUUpdater delegate */
|
|
|
|
|
|
|
|
- (BOOL)updater:(SUUpdater *)updater shouldPostponeRelaunchForUpdate:(SUAppcastItem *)update untilInvoking:(NSInvocation *)invocation;
|
|
|
|
{
|
|
|
|
/* If results aren't saved now, we might get a weird utf-8 lookup error when saving later.
|
|
|
|
**/
|
|
|
|
[self saveResults];
|
|
|
|
return NO;
|
|
|
|
}
|
2009-06-01 09:55:11 +00:00
|
|
|
@end
|