Checking in improvements to the effect availability heuristic.
[MenuTunes.git] / PreferencesController.m
index a17c1b3..96fcfea 100755 (executable)
@@ -10,6 +10,8 @@
 #import <arpa/inet.h>
 #import <openssl/sha.h>
 
+#import <ITFoundation/ITFoundation.h>
+
 #import <ITKit/ITHotKeyCenter.h>
 #import <ITKit/ITKeyCombo.h>
 #import <ITKit/ITKeyComboPanel.h>
@@ -17,6 +19,7 @@
 #import <ITKit/ITKeyBroadcaster.h>
 
 #import <ITKit/ITTSWBackgroundView.h>
+#import <ITKit/ITWindowEffect.h>
 #import <ITKit/ITCutWindowEffect.h>
 #import <ITKit/ITDissolveWindowEffect.h>
 #import <ITKit/ITSlideHorizontallyWindowEffect.h>
@@ -378,42 +381,19 @@ static PreferencesController *prefs = nil;
     } else if ( [sender tag] == 2020) {
         // update screen selection
     } else if ( [sender tag] == 2030) {
-        int effectTag = [[sender selectedItem] tag];
+        Class selectedClass = [[sender selectedItem] representedObject];
         float time = ([df floatForKey:@"statusWindowAppearanceSpeed"] ? [df floatForKey:@"statusWindowAppearanceSpeed"] : 0.8);
-        [df setInteger:effectTag forKey:@"statusWindowAppearanceEffect"];
-
-        if ( effectTag == 2100 ) {
-            [sw setEntryEffect:[[[ITCutWindowEffect alloc] initWithWindow:sw] autorelease]];
-        } else if ( effectTag == 2101 ) {
-            [sw setEntryEffect:[[[ITDissolveWindowEffect alloc] initWithWindow:sw] autorelease]];
-        } else if ( effectTag == 2102 ) {
-            [sw setEntryEffect:[[[ITSlideVerticallyWindowEffect alloc] initWithWindow:sw] autorelease]];
-        } else if ( effectTag == 2103 ) {
-            [sw setEntryEffect:[[[ITSlideHorizontallyWindowEffect alloc] initWithWindow:sw] autorelease]];
-        } else if ( effectTag == 2104 ) {
-            [sw setEntryEffect:[[[ITPivotWindowEffect alloc] initWithWindow:sw] autorelease]];
-        }
+        [df setObject:NSStringFromClass(selectedClass) forKey:@"statusWindowAppearanceEffect"];
 
+        [sw setEntryEffect:[[[selectedClass alloc] initWithWindow:sw] autorelease]];
         [[sw entryEffect] setEffectTime:time];
         
     } else if ( [sender tag] == 2040) {
-        int effectTag = [[sender selectedItem] tag];
+        Class selectedClass = [[sender selectedItem] representedObject];
         float time = ([df floatForKey:@"statusWindowVanishSpeed"] ? [df floatForKey:@"statusWindowVanishSpeed"] : 0.8);
+        [df setObject:NSStringFromClass(selectedClass) forKey:@"statusWindowVanishEffect"];
         
-        [df setInteger:[[sender selectedItem] tag] forKey:@"statusWindowVanishEffect"];
-        
-        if ( effectTag == 2100 ) {
-            [sw setExitEffect:[[[ITCutWindowEffect alloc] initWithWindow:sw] autorelease]];
-        } else if ( effectTag == 2101 ) {
-            [sw setExitEffect:[[[ITDissolveWindowEffect alloc] initWithWindow:sw] autorelease]];
-        } else if ( effectTag == 2102 ) {
-            [sw setExitEffect:[[[ITSlideVerticallyWindowEffect alloc] initWithWindow:sw] autorelease]];
-        } else if ( effectTag == 2103 ) {
-            [sw setExitEffect:[[[ITSlideHorizontallyWindowEffect alloc] initWithWindow:sw] autorelease]];
-        } else if ( effectTag == 2104 ) {
-            [sw setExitEffect:[[[ITPivotWindowEffect alloc] initWithWindow:sw] autorelease]];
-        }
-
+        [sw setExitEffect:[[[selectedClass alloc] initWithWindow:sw] autorelease]];
         [[sw exitEffect] setEffectTime:time];
 
     } else if ( [sender tag] == 2050) {
@@ -510,13 +490,13 @@ static PreferencesController *prefs = nil;
         nil] forKey:@"menu"];
 
     [df setInteger:5 forKey:@"SongsInAdvance"];
-    // [df setBool:YES forKey:@"showName"];  // Song info will always show song title.
+//  [df setBool:YES forKey:@"showName"];  // Song info will always show song title.
     [df setBool:YES forKey:@"showArtist"];
     [df setBool:NO forKey:@"showAlbum"];
     [df setBool:NO forKey:@"showTime"];
 
-    [df setInteger:2100 forKey:@"statusWindowAppearanceEffect"];
-    [df setInteger:2101 forKey:@"statusWindowVanishEffect"];
+    [df setObject:@"ITCutWindowEffect" forKey:@"statusWindowAppearanceEffect"];
+    [df setObject:@"ITDissolveWindowEffect" forKey:@"statusWindowVanishEffect"];
     [df setFloat:0.8 forKey:@"statusWindowAppearanceSpeed"];
     [df setFloat:0.8 forKey:@"statusWindowVanishSpeed"];
     [df setFloat:4.0 forKey:@"statusWindowVanishDelay"];
@@ -731,10 +711,13 @@ static PreferencesController *prefs = nil;
 - (void)setupUI
 {
     NSMutableDictionary *loginwindow;
-    NSMutableArray *loginarray;
-    NSEnumerator *loginEnum, *keyArrayEnum;
-    NSString *serverName;
-    NSData *colorData;
+    NSMutableArray      *loginarray;
+    NSEnumerator   *loginEnum;
+    NSEnumerator   *keyArrayEnum;
+    NSString       *serverName;
+    NSData         *colorData;
+    NSArray        *effectClasses = [ITWindowEffect effectClasses];
+    NSEnumerator   *effectEnum = [effectClasses objectEnumerator];
     int selectedBGStyle;
     id anItem;
     
@@ -784,14 +767,36 @@ static PreferencesController *prefs = nil;
     // Setup the positioning controls
     
     // Setup effects controls
-    [appearanceEffectPopup selectItem:[appearanceEffectPopup itemAtIndex:[appearanceEffectPopup indexOfItemWithTag:[df integerForKey:@"statusWindowAppearanceEffect"]]]];
-    [vanishEffectPopup     selectItem:[vanishEffectPopup     itemAtIndex:[vanishEffectPopup     indexOfItemWithTag:[df integerForKey:@"statusWindowVanishEffect"]]]];
+    // Populate the effects popups
+    [appearanceEffectPopup removeItemAtIndex:0];
+    [vanishEffectPopup     removeItemAtIndex:0];
+    
+    while ( (anItem = [effectEnum nextObject]) ) {
+        [appearanceEffectPopup addItemWithTitle:[anItem effectName]];
+        [vanishEffectPopup     addItemWithTitle:[anItem effectName]];
+        [[appearanceEffectPopup lastItem] setRepresentedObject:anItem];
+        [[vanishEffectPopup     lastItem] setRepresentedObject:anItem];
+    }
+    
+    // Attempt to find the pref'd effect in the list.
+    // If it's not there, use cut/dissolve.
+    if ( [effectClasses containsObject:NSClassFromString([df stringForKey:@"statusWindowAppearanceEffect"])] ) {
+        [appearanceEffectPopup selectItemAtIndex:[effectClasses indexOfObject:NSClassFromString([df stringForKey:@"statusWindowAppearanceEffect"])]];
+    } else {
+        [appearanceEffectPopup selectItemAtIndex:[effectClasses indexOfObject:NSClassFromString(@"ITCutWindowEffect")]];
+    }
+    
+    if ( [effectClasses containsObject:NSClassFromString([df stringForKey:@"statusWindowVanishEffect"])] ) {
+        [vanishEffectPopup selectItemAtIndex:[effectClasses indexOfObject:NSClassFromString([df stringForKey:@"statusWindowVanishEffect"])]];
+    } else {
+        [vanishEffectPopup selectItemAtIndex:[effectClasses indexOfObject:NSClassFromString(@"ITCutWindowEffect")]];
+    }
+    
     [appearanceSpeedSlider setFloatValue:-([df floatForKey:@"statusWindowAppearanceSpeed"])];
     [vanishSpeedSlider     setFloatValue:-([df floatForKey:@"statusWindowVanishSpeed"])];
     [vanishDelaySlider     setFloatValue:[df floatForKey:@"statusWindowVanishDelay"]];
 
     // Setup General Controls
-    
     selectedBGStyle = [df integerForKey:@"statusWindowBackgroundMode"];
     [backgroundStylePopup selectItem:[backgroundStylePopup itemAtIndex:[backgroundStylePopup indexOfItemWithTag:selectedBGStyle]]];