X-Git-Url: http://git.ithinksw.org/MenuTunes.git/blobdiff_plain/9c8f6e1b9b0b947d898a3d9bae3acb3999879791..955343cfbfebf6b68b127629d9b6a76f80ba023a:/MainController.m diff --git a/MainController.m b/MainController.m index edd1e78..b695d80 100755 --- a/MainController.m +++ b/MainController.m @@ -4,6 +4,7 @@ #import #import #import +#import "StatusWindow.h" #import "StatusWindowController.h" #import "StatusItemHack.h" @@ -40,6 +41,7 @@ static MainController *sharedController; menuController = [[MenuController alloc] init]; df = [[NSUserDefaults standardUserDefaults] retain]; timerUpdating = NO; + blinged = NO; } return self; } @@ -51,9 +53,6 @@ static MainController *sharedController; SetITDebugMode(YES); } - bling = [[MTBlingController alloc] init]; - blingDate = nil; - currentRemote = [self loadRemote]; [currentRemote begin]; @@ -79,6 +78,14 @@ static MainController *sharedController; initWithStatusBar:[NSStatusBar systemStatusBar] withLength:NSSquareStatusItemLength]; + bling = [[MTBlingController alloc] init]; + [self blingTime]; + registerTimer = [[NSTimer scheduledTimerWithTimeInterval:10.0 + target:self + selector:@selector(blingTime) + userInfo:nil + repeats:YES] retain]; + if ([currentRemote playerRunningState] == ITMTRemotePlayerRunning) { [self applicationLaunched:nil]; } else { @@ -148,21 +155,64 @@ static MainController *sharedController; [pool release]; }*/ +- (void)setBlingTime:(NSDate*)date +{ + NSMutableDictionary *globalPrefs; + [df synchronize]; + globalPrefs = [[df persistentDomainForName:@".GlobalPreferences"] mutableCopy]; + if (date) { + [globalPrefs setObject:date forKey:@"ITMTTrialStart"]; + } else { + [globalPrefs removeObjectForKey:@"ITMTTrialStart"]; + } + [df setPersistentDomain:globalPrefs forName:@".GlobalPreferences"]; + [df synchronize]; + [globalPrefs release]; +} + +- (NSDate*)getBlingTime +{ + [df synchronize]; + return [[df persistentDomainForName:@".GlobalPreferences"] objectForKey:@"ITMTTrialStart"]; +} + - (void)blingTime { NSDate *now = [NSDate date]; - if ( (! blingDate) || ([now timeIntervalSinceDate:blingDate] >= 86400) ) { - [bling showPanelIfNeeded]; - [blingDate autorelease]; - blingDate = [now retain]; + if (![self blingBling]) { + if ( (! [self getBlingTime] ) || ([now timeIntervalSinceDate:[self getBlingTime]] < 0) ) { + [self setBlingTime:now]; + } + if ( ([now timeIntervalSinceDate:[self getBlingTime]] >= 604800) && (blinged != YES) ) { + blinged = YES; + [statusItem setEnabled:NO]; + [self clearHotKeys]; + if ([refreshTimer isValid]) { + [refreshTimer invalidate]; + } + [statusWindowController showRegistrationQueryWindow]; + } + } else { + if (blinged) { + [statusItem setEnabled:YES]; + [self setupHotKeys]; + if (![refreshTimer isValid]) { + [refreshTimer release]; + refreshTimer = refreshTimer = [[NSTimer scheduledTimerWithTimeInterval:0.5 + target:self + selector:@selector(timerUpdate) + userInfo:nil + repeats:YES] retain]; + } + blinged = NO; + } + [self setBlingTime:nil]; } } - (void)blingNow { [bling showPanel]; - [blingDate autorelease]; - blingDate = [[NSDate date] retain]; } - (BOOL)blingBling @@ -710,7 +760,7 @@ static MainController *sharedController; [[StatusWindow sharedWindow] vanish:self]; [[StatusWindow sharedWindow] setIgnoresMouseEvents:YES]; - [NSApp terminate]; + [NSApp terminate:self]; } @@ -745,6 +795,9 @@ static MainController *sharedController; [refreshTimer invalidate]; [refreshTimer release]; refreshTimer = nil; + [registerTimer invalidate]; + [registerTimer release]; + registerTimer = nil; [self clearHotKeys]; playerRunningState = ITMTRemotePlayerNotRunning; }