Moving registerDefaults to the preferences controller where it belongs. Some other...
authorMatthew Judy <mjudy@ithinksw.com>
Wed, 9 Apr 2003 23:33:45 +0000 (23:33 +0000)
committerMatthew Judy <mjudy@ithinksw.com>
Wed, 9 Apr 2003 23:33:45 +0000 (23:33 +0000)
OldMainController.h
OldMainController.m
PreferencesController.h
PreferencesController.m

index e8901bf..85b4c54 100755 (executable)
@@ -64,7 +64,6 @@
 - (void)applicationLaunched:(NSNotification *)note;
 - (void)applicationTerminated:(NSNotification *)note;
 
-- (void)registerDefaults;
 - (void)rebuildMenu;
 
 - (void)clearHotKeys;
index aec922d..7ce374c 100755 (executable)
@@ -48,6 +48,7 @@
 
 - (void)applicationDidFinishLaunching:(NSNotification *)note
 {
+    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
     currentRemote = [self loadRemote];
     [currentRemote begin];
     
             selector:@selector(applicationLaunched:)
             name:NSWorkspaceDidLaunchApplicationNotification
             object:nil];
-    
-    [self registerDefaults];
+
+    if ( ! [defaults objectForKey:@"menu"] ) {  // If this is nil, defaults have never been registered.
+        [[PreferencesController sharedPrefs] registerDefaults];
+    }
     
     statusItem = [[ITStatusItem alloc]
             initWithStatusBar:[NSStatusBar systemStatusBar]
 #pragma mark INSTANCE METHODS
 /*************************************************************************/
 
-- (void)registerDefaults
-{
-    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
-    if (![defaults objectForKey:@"menu"]) {
-        BOOL found = NO;
-        NSMutableDictionary *loginwindow;
-        NSMutableArray *loginarray;
-        int i;
-        
-        [defaults setObject:
-            [NSArray arrayWithObjects:
-                @"Play/Pause",
-                @"Next Track",
-                @"Previous Track",
-                @"Fast Forward",
-                @"Rewind",
-                @"<separator>",
-                @"Upcoming Songs",
-                @"Playlists",
-                @"Song Rating",
-                @"<separator>",
-                @"PreferencesÉ",
-                @"Quit",
-                @"<separator>",
-                @"Current Track Info",
-                nil] forKey:@"menu"];
-        
-        [defaults synchronize];
-        loginwindow = [[defaults persistentDomainForName:@"loginwindow"] mutableCopy];
-        loginarray = [loginwindow objectForKey:@"AutoLaunchedApplicationDictionary"];
-        
-        for (i = 0; i < [loginarray count]; i++) {
-            NSDictionary *tempDict = [loginarray objectAtIndex:i];
-            if ([[[tempDict objectForKey:@"Path"] lastPathComponent] isEqualToString:
-                [[[NSBundle mainBundle] bundlePath] lastPathComponent]]) {
-                found = YES;
-            }
-        }
-        
-        //
-        //This is teh sux
-        //We must fix it so it is no longer suxy
-        if (!found) {
-            if (NSRunInformationalAlertPanel(@"Auto-launch MenuTunes", @"Would you like MenuTunes to automatically launch at login?", @"Yes", @"No", nil) == NSOKButton) {
-                AEDesc scriptDesc, resultDesc;
-                NSString *script = [NSString stringWithFormat:@"tell application \"System Events\"\nmake new login item at end of login items with properties {path:\"%@\", kind:\"APPLICATION\"}\nend tell", [[NSBundle mainBundle] bundlePath]];
-                ComponentInstance asComponent = OpenDefaultComponent(kOSAComponentType, kAppleScriptSubtype);
-                
-                AECreateDesc(typeChar, [script cString], [script cStringLength], 
-            &scriptDesc);
-                
-                OSADoScript(asComponent, &scriptDesc, kOSANullScript, typeChar, kOSAModeCanInteract, &resultDesc);
-                
-                AEDisposeDesc(&scriptDesc);
-                AEDisposeDesc(&resultDesc);
-                
-                CloseComponent(asComponent);
-            }
-        }
-    }
-    
-    if (![defaults integerForKey:@"SongsInAdvance"])
-    {
-        [defaults setInteger:5 forKey:@"SongsInAdvance"];
-    }
-    
-    if (![defaults objectForKey:@"showName"]) {
-        [defaults setBool:YES forKey:@"showName"];
-    }
-    
-    if (![defaults objectForKey:@"showArtist"]) {
-        [defaults setBool:YES forKey:@"showArtist"];
-    }
-    
-    if (![defaults objectForKey:@"showAlbum"]) {
-        [defaults setBool:NO forKey:@"showAlbum"];
-    }
-    
-    if (![defaults objectForKey:@"showTime"]) {
-        [defaults setBool:NO forKey:@"showTime"];
-    }
-}
-
 - (void)startTimerInNewThread
 {
     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
index 9cc25cb..60fc875 100755 (executable)
@@ -57,6 +57,7 @@
 - (void)setController:(id)object;
 
 - (IBAction)showPrefsWindow:(id)sender;
+- (void)registerDefaults;
 
 - (IBAction)cancelHotKey:(id)sender;
 - (IBAction)clearHotKey:(id)sender;
index 113f883..217afb4 100755 (executable)
@@ -61,10 +61,8 @@ static PreferencesController *prefs = nil;
 
 - (void)setController:(id)object
 {
-NSLog(@"foo");
     [controller autorelease];
     controller = [object retain];
-NSLog(@"bar");
 }
 
 
@@ -73,7 +71,6 @@ NSLog(@"bar");
 #pragma mark INSTANCE METHODS
 /*************************************************************************/
 
-
 - (IBAction)showPrefsWindow:(id)sender
 {
     if (! window) {  // If window does not exist yet, then the nib hasn't been loaded.
@@ -180,6 +177,72 @@ NSLog(@"bar");
     [controller clearHotKeys];
 }
 
+- (void)registerDefaults
+{
+    BOOL found = NO;
+    NSMutableDictionary *loginWindow;
+    NSMutableArray *loginArray;
+    NSEnumerator *loginEnum;
+    id anItem;
+
+    [df setObject:[NSArray arrayWithObjects:
+        @"Play/Pause",
+        @"Next Track",
+        @"Previous Track",
+        @"Fast Forward",
+        @"Rewind",
+        @"<separator>",
+        @"Upcoming Songs",
+        @"Playlists",
+        @"Song Rating",
+        @"<separator>",
+        @"PreferencesÉ",
+        @"Quit",
+        @"<separator>",
+        @"Current Track Info",
+        nil] forKey:@"menu"];
+
+    [df setInteger:5 forKey:@"SongsInAdvance"];
+    [df setBool:YES forKey:@"showName"];
+    [df setBool:YES forKey:@"showArtist"];
+    [df setBool:NO forKey:@"showAlbum"];
+    [df setBool:NO forKey:@"showTime"];
+
+    [df synchronize];
+    
+    loginWindow = [[df persistentDomainForName:@"loginwindow"] mutableCopy];
+    loginArray = [loginWindow objectForKey:@"AutoLaunchedApplicationDictionary"];
+    loginEnum = [loginArray objectEnumerator];
+
+    while ( (anItem = [loginEnum nextObject]) ) {
+        if ( [[[anItem objectForKey:@"Path"] lastPathComponent] isEqualToString:[[[NSBundle mainBundle] bundlePath] lastPathComponent]] ) {
+            found = YES;
+        }
+    }
+
+    [loginWindow release];
+    
+    // This is teh sux
+    // We must fix it so it is no longer suxy
+    if (!found) {
+        if (NSRunInformationalAlertPanel(@"Auto-launch MenuTunes", @"Would you like MenuTunes to automatically launch at login?", @"Yes", @"No", nil) == NSOKButton) {
+            AEDesc scriptDesc, resultDesc;
+            NSString *script = [NSString stringWithFormat:@"tell application \"System Events\"\nmake new login item at end of login items with properties {path:\"%@\", kind:\"APPLICATION\"}\nend tell", [[NSBundle mainBundle] bundlePath]];
+            ComponentInstance asComponent = OpenDefaultComponent(kOSAComponentType, kAppleScriptSubtype);
+
+            AECreateDesc(typeChar, [script cString], [script cStringLength],
+                         &scriptDesc);
+
+            OSADoScript(asComponent, &scriptDesc, kOSANullScript, typeChar, kOSAModeCanInteract, &resultDesc);
+
+            AEDisposeDesc(&scriptDesc);
+            AEDisposeDesc(&resultDesc);
+
+            CloseComponent(asComponent);
+        }
+    }
+}
+
 - (IBAction)cancelHotKey:(id)sender
 {
     [[NSNotificationCenter defaultCenter] removeObserver:self];