#import <arpa/inet.h>
#import <openssl/sha.h>
+#import <ITFoundation/ITFoundation.h>
+
#import <ITKit/ITHotKeyCenter.h>
#import <ITKit/ITKeyCombo.h>
#import <ITKit/ITKeyComboPanel.h>
#import <ITKit/ITKeyBroadcaster.h>
#import <ITKit/ITTSWBackgroundView.h>
+#import <ITKit/ITWindowEffect.h>
#import <ITKit/ITCutWindowEffect.h>
#import <ITKit/ITDissolveWindowEffect.h>
#import <ITKit/ITSlideHorizontallyWindowEffect.h>
- (void)setupCustomizationTables;
- (void)setupMenuItems;
- (void)setupUI;
+- (void)setStatusWindowEntryEffect:(Class)effectClass;
+- (void)setStatusWindowExitEffect:(Class)effectClass;
- (void)setCustomColor:(NSColor *)color updateWell:(BOOL)update;
+- (void)repopulateEffectPopupsForVerticalPosition:(ITVerticalWindowPosition)vPos horizontalPosition:(ITHorizontalWindowPosition)hPos;
+- (BOOL)effect:(Class)effectClass supportsVerticalPosition:(ITVerticalWindowPosition)vPos withHorizontalPosition:(ITHorizontalWindowPosition)hPos;
- (IBAction)changeMenus:(id)sender;
- (void)setLaunchesAtLogin:(BOOL)flag;
@end
if ( (self = [super init]) ) {
ITDebugLog(@"Preferences initialized.");
df = [[NSUserDefaults standardUserDefaults] retain];
+
+ effectClasses = [[ITWindowEffect effectClasses] retain];
+
hotKeysArray = [[NSArray alloc] initWithObjects:@"PlayPause",
@"NextTrack",
@"PrevTrack",
{
StatusWindow *sw = [StatusWindow sharedWindow];
ITDebugLog(@"Changing status window setting of tag %i", [sender tag]);
+
if ( [sender tag] == 2010) {
+
+ BOOL entryEffectValid = YES;
+ BOOL exitEffectValid = YES;
+
[df setInteger:[sender selectedRow] forKey:@"statusWindowVerticalPosition"];
[df setInteger:[sender selectedColumn] forKey:@"statusWindowHorizontalPosition"];
- [sw setHorizontalPosition:[sender selectedColumn]];
[sw setVerticalPosition:[sender selectedRow]];
- // update the window's position here
+ [sw setHorizontalPosition:[sender selectedColumn]];
+
+ // Enable/disable the items in the popups.
+ [self repopulateEffectPopupsForVerticalPosition:[sw verticalPosition]
+ horizontalPosition:[sw horizontalPosition]];
+
+ // Make sure the effects support the new position.
+ entryEffectValid = ( [self effect:[[sw entryEffect] class]
+ supportsVerticalPosition:[sw verticalPosition]
+ withHorizontalPosition:[sw horizontalPosition]] );
+ exitEffectValid = ( [self effect:[[sw exitEffect] class]
+ supportsVerticalPosition:[sw verticalPosition]
+ withHorizontalPosition:[sw horizontalPosition]] );
+
+ if ( ! entryEffectValid ) {
+ [appearanceEffectPopup selectItemAtIndex:[[appearanceEffectPopup menu] indexOfItemWithRepresentedObject:NSClassFromString(@"ITCutWindowEffect")]];
+ [self setStatusWindowEntryEffect:NSClassFromString(@"ITCutWindowEffect")];
+ } else {
+ [appearanceEffectPopup selectItemAtIndex:[[appearanceEffectPopup menu] indexOfItemWithRepresentedObject:[[sw entryEffect] class]]];
+ }
+
+ if ( ! exitEffectValid ) {
+ [vanishEffectPopup selectItemAtIndex:[[vanishEffectPopup menu] indexOfItemWithRepresentedObject:NSClassFromString(@"ITDissolveWindowEffect")]];
+ [self setStatusWindowExitEffect:NSClassFromString(@"ITDissolveWindowEffect")];
+ } else {
+ [vanishEffectPopup selectItemAtIndex:[[vanishEffectPopup menu] indexOfItemWithRepresentedObject:[[sw exitEffect] class]]];
+ }
+
+ [(MainController *)controller showCurrentTrackInfo];
+
} else if ( [sender tag] == 2020) {
- // update screen selection
+
+ // Update screen selection.
+
} else if ( [sender tag] == 2030) {
- int effectTag = [[sender selectedItem] tag];
- 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]];
- }
-
- [[sw entryEffect] setEffectTime:time];
+
+ [self setStatusWindowEntryEffect:[[sender selectedItem] representedObject]];
} else if ( [sender tag] == 2040) {
- int effectTag = [[sender selectedItem] tag];
- float time = ([df floatForKey:@"statusWindowVanishSpeed"] ? [df floatForKey:@"statusWindowVanishSpeed"] : 0.8);
-
- [df setInteger:[[sender selectedItem] tag] forKey:@"statusWindowVanishEffect"];
+
+ [self setStatusWindowExitEffect:[[sender selectedItem] representedObject]];
- 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 exitEffect] setEffectTime:time];
-
} else if ( [sender tag] == 2050) {
- float newTime = (-([sender floatValue]));
+ float newTime = ( -([sender floatValue]) );
[df setFloat:newTime forKey:@"statusWindowAppearanceSpeed"];
[[sw entryEffect] setEffectTime:newTime];
} else if ( [sender tag] == 2060) {
- float newTime = (-([sender floatValue]));
+ float newTime = ( -([sender floatValue]) );
[df setFloat:newTime forKey:@"statusWindowVanishSpeed"];
[[sw exitEffect] setEffectTime:newTime];
} else if ( [sender tag] == 2070) {
[self setCustomColor:[NSColor colorWithCalibratedWhite:0.15 alpha:0.70] updateWell:YES];
}
+ } else if ( [sender tag] == 2095) {
+ [df setInteger:[sender indexOfSelectedItem] forKey:@"statusWindowSizing"];
+ [(MainController *)controller showCurrentTrackInfo];
}
[df synchronize];
}
-- (void)setCustomColor:(NSColor *)color updateWell:(BOOL)update
-{
- [(ITTSWBackgroundView *)[[StatusWindow sharedWindow] contentView] setBackgroundColor:color];
- [df setObject:[NSArchiver archivedDataWithRootObject:color] forKey:@"statusWindowBackgroundColor"];
-
- if ( update ) {
- [backgroundColorWell setColor:color];
- }
-}
-
- (void)registerDefaults
{
BOOL found = NO;
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"];
+ [df setInteger:(int)ITWindowPositionBottom forKey:@"statusWindowVerticalPosition"];
+ [df setInteger:(int)ITWindowPositionLeft forKey:@"statusWindowHorizontalPosition"];
[df setBool:YES forKey:@"showSongInfoOnChange"];
-
+
+ [df setObject:[NSArchiver archivedDataWithRootObject:[NSColor blueColor]] forKey:@"statusWindowBackgroundColor"];
+
[df synchronize];
loginWindow = [[df persistentDomainForName:@"loginwindow"] mutableCopy];
- (void)setupUI
{
NSMutableDictionary *loginwindow;
- NSMutableArray *loginarray;
- NSEnumerator *loginEnum, *keyArrayEnum;
- NSString *serverName;
+ NSMutableArray *loginarray;
+ NSEnumerator *loginEnum;
+ NSEnumerator *keyArrayEnum;
+ NSString *serverName;
+ NSData *colorData;
int selectedBGStyle;
id anItem;
[launchPlayerAtLaunchCheckbox setState:[df boolForKey:@"LaunchPlayerWithMT"] ? NSOnState : NSOffState];
// Setup the positioning controls
+ [positionMatrix selectCellAtRow:[df integerForKey:@"statusWindowVerticalPosition"]
+ column:[df integerForKey:@"statusWindowHorizontalPosition"]];
// Setup effects controls
- [appearanceEffectPopup selectItem:[appearanceEffectPopup itemAtIndex:[appearanceEffectPopup indexOfItemWithTag:[df integerForKey:@"statusWindowAppearanceEffect"]]]];
- [vanishEffectPopup selectItem:[vanishEffectPopup itemAtIndex:[vanishEffectPopup indexOfItemWithTag:[df integerForKey:@"statusWindowVanishEffect"]]]];
- [appearanceSpeedSlider setFloatValue:-([df floatForKey:@"statusWindowAppearanceSpeed"])];
- [vanishSpeedSlider setFloatValue:-([df floatForKey:@"statusWindowVanishSpeed"])];
+ // Populate the effects popups
+ [appearanceEffectPopup setAutoenablesItems:NO];
+ [vanishEffectPopup setAutoenablesItems:NO];
+ [self repopulateEffectPopupsForVerticalPosition:[df integerForKey:@"statusWindowVerticalPosition"]
+ horizontalPosition:[df integerForKey:@"statusWindowHorizontalPosition"]];
+
+ // 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]]];
[backgroundColorPopup setEnabled:NO];
}
- [backgroundColorWell setColor:(NSColor *)[NSUnarchiver unarchiveObjectWithData:[df dataForKey:@"statusWindowBackgroundColor"]]];
+ colorData = [df dataForKey:@"statusWindowBackgroundColor"];
+
+ if ( colorData ) {
+ [backgroundColorWell setColor:(NSColor *)[NSUnarchiver unarchiveObjectWithData:colorData]];
+ } else {
+ [backgroundColorWell setColor:[NSColor blueColor]];
+ }
+
[showOnChangeCheckbox setState:([df boolForKey:@"showSongInfoOnChange"] ? NSOnState : NSOffState)];
+
+ [windowSizingPopup selectItem:[windowSizingPopup itemAtIndex:[windowSizingPopup indexOfItemWithTag:[df integerForKey:@"statusWindowSizing"]]]];
// Setup the sharing controls
if ([df boolForKey:@"enableSharing"]) {
}
}
+- (void)setStatusWindowEntryEffect:(Class)effectClass
+{
+ StatusWindow *sw = [StatusWindow sharedWindow];
+
+ float time = ([df floatForKey:@"statusWindowAppearanceSpeed"] ? [df floatForKey:@"statusWindowAppearanceSpeed"] : 0.8);
+ [df setObject:NSStringFromClass(effectClass) forKey:@"statusWindowAppearanceEffect"];
+
+ [sw setEntryEffect:[[[effectClass alloc] initWithWindow:sw] autorelease]];
+ [[sw entryEffect] setEffectTime:time];
+}
+
+- (void)setStatusWindowExitEffect:(Class)effectClass
+{
+ StatusWindow *sw = [StatusWindow sharedWindow];
+
+ float time = ([df floatForKey:@"statusWindowVanishSpeed"] ? [df floatForKey:@"statusWindowVanishSpeed"] : 0.8);
+ [df setObject:NSStringFromClass(effectClass) forKey:@"statusWindowVanishEffect"];
+
+ [sw setExitEffect:[[[effectClass alloc] initWithWindow:sw] autorelease]];
+ [[sw exitEffect] setEffectTime:time];
+}
+
+- (void)setCustomColor:(NSColor *)color updateWell:(BOOL)update
+{
+ [(ITTSWBackgroundView *)[[StatusWindow sharedWindow] contentView] setBackgroundColor:color];
+ [df setObject:[NSArchiver archivedDataWithRootObject:color] forKey:@"statusWindowBackgroundColor"];
+
+ if ( update ) {
+ [backgroundColorWell setColor:color];
+ }
+}
+
+- (void)repopulateEffectPopupsForVerticalPosition:(ITVerticalWindowPosition)vPos horizontalPosition:(ITHorizontalWindowPosition)hPos
+{
+ NSEnumerator *effectEnum = [effectClasses objectEnumerator];
+ id anItem;
+
+ [appearanceEffectPopup removeAllItems];
+ [vanishEffectPopup removeAllItems];
+
+ while ( (anItem = [effectEnum nextObject]) ) {
+ [appearanceEffectPopup addItemWithTitle:[anItem effectName]];
+ [vanishEffectPopup addItemWithTitle:[anItem effectName]];
+
+ [[appearanceEffectPopup lastItem] setRepresentedObject:anItem];
+ [[vanishEffectPopup lastItem] setRepresentedObject:anItem];
+
+ if ( [self effect:anItem supportsVerticalPosition:vPos withHorizontalPosition:hPos] ) {
+ [[appearanceEffectPopup lastItem] setEnabled:YES];
+ [[vanishEffectPopup lastItem] setEnabled:YES];
+ } else {
+ [[appearanceEffectPopup lastItem] setEnabled:NO];
+ [[vanishEffectPopup lastItem] setEnabled:NO];
+ }
+ }
+
+}
+
+- (BOOL)effect:(Class)effectClass supportsVerticalPosition:(ITVerticalWindowPosition)vPos withHorizontalPosition:(ITHorizontalWindowPosition)hPos
+{
+ BOOL valid = NO;
+
+ if ( vPos == ITWindowPositionTop ) {
+ if ( hPos == ITWindowPositionLeft ) {
+ valid = ( [[[[effectClass supportedPositions] objectForKey:@"Top"] objectForKey:@"Left"] boolValue] ) ;
+ } else if ( hPos == ITWindowPositionCenter ) {
+ valid = ( [[[[effectClass supportedPositions] objectForKey:@"Top"] objectForKey:@"Center"] boolValue] );
+ } else if ( hPos == ITWindowPositionRight ) {
+ valid = ( [[[[effectClass supportedPositions] objectForKey:@"Top"] objectForKey:@"Right"] boolValue] );
+ }
+ } else if ( vPos == ITWindowPositionMiddle ) {
+ if ( hPos == ITWindowPositionLeft ) {
+ valid = ( [[[[effectClass supportedPositions] objectForKey:@"Middle"] objectForKey:@"Left"] boolValue] );
+ } else if ( hPos == ITWindowPositionCenter ) {
+ valid = ( [[[[effectClass supportedPositions] objectForKey:@"Middle"] objectForKey:@"Center"] boolValue] );
+ } else if ( hPos == ITWindowPositionRight ) {
+ valid = ( [[[[effectClass supportedPositions] objectForKey:@"Middle"] objectForKey:@"Right"] boolValue] );
+ }
+ } else if ( vPos == ITWindowPositionBottom ) {
+ if ( hPos == ITWindowPositionLeft ) {
+ valid = ( [[[[effectClass supportedPositions] objectForKey:@"Bottom"] objectForKey:@"Left"] boolValue] );
+ } else if ( hPos == ITWindowPositionCenter ) {
+ valid = ( [[[[effectClass supportedPositions] objectForKey:@"Bottom"] objectForKey:@"Center"] boolValue] );
+ } else if ( hPos == ITWindowPositionRight ) {
+ valid = ( [[[[effectClass supportedPositions] objectForKey:@"Bottom"] objectForKey:@"Right"] boolValue] );
+ }
+ }
+
+ return valid;
+}
+
- (IBAction)changeMenus:(id)sender
{
ITDebugLog(@"Synchronizing menus");
{
[hotKeysArray release];
[hotKeysDictionary release];
+ [effectClasses release];
[menuTableView setDataSource:nil];
[allTableView setDataSource:nil];
[controller release];