1 #import "StatusWindowController.h"
2 #import "StatusWindow.h"
3 #import "PreferencesController.h"
5 #import <ITKit/ITWindowEffect.h>
6 #import <ITKit/ITCutWindowEffect.h>
7 #import <ITKit/ITDissolveWindowEffect.h>
8 #import <ITKit/ITSlideHorizontallyWindowEffect.h>
9 #import <ITKit/ITSlideVerticallyWindowEffect.h>
10 #import <ITKit/ITPivotWindowEffect.h>
13 static StatusWindowController *sharedController;
16 @implementation StatusWindowController
19 + (StatusWindowController *)sharedController
21 if ( ! sharedController ) {
22 sharedController = [[StatusWindowController alloc] init];
25 return sharedController;
31 if ( ( self = [super init] ) ) {
39 ITWindowEffect *entryEffect;
40 ITWindowEffect *exitEffect;
42 _window = [[StatusWindow sharedWindow] retain];
43 df = [[NSUserDefaults standardUserDefaults] retain];
45 exitDelay = [df floatForKey:@"statusWindowVanishDelay"];
46 entryTag = [df integerForKey:@"statusWindowAppearanceEffect"];
47 exitTag = [df integerForKey:@"statusWindowVanishEffect"];
48 entrySpeed = [df floatForKey:@"statusWindowAppearanceSpeed"];
49 exitSpeed = [df floatForKey:@"statusWindowVanishSpeed"];
51 [_window setExitMode:ITTransientStatusWindowExitAfterDelay];
52 [_window setExitDelay:(exitDelay ? exitDelay : 4.0)];
54 if ( entryTag == 2101 ) {
55 entryEffect = [[[ITDissolveWindowEffect alloc] initWithWindow:_window] autorelease];
56 } else if ( entryTag == 2102 ) {
57 entryEffect = [[[ITSlideVerticallyWindowEffect alloc] initWithWindow:_window] autorelease];
58 } else if ( entryTag == 2103 ) {
59 entryEffect = [[[ITSlideHorizontallyWindowEffect alloc] initWithWindow:_window] autorelease];
60 } else if ( entryTag == 2104 ) {
61 entryEffect = [[[ITPivotWindowEffect alloc] initWithWindow:_window] autorelease];
63 entryEffect = [[[ITCutWindowEffect alloc] initWithWindow:_window] autorelease];
66 [_window setEntryEffect:entryEffect];
68 if ( exitTag == 2100 ) {
69 exitEffect = [[[ITCutWindowEffect alloc] initWithWindow:_window] autorelease];
70 } else if ( exitTag == 2102 ) {
71 exitEffect = [[[ITSlideVerticallyWindowEffect alloc] initWithWindow:_window] autorelease];
72 } else if ( exitTag == 2103 ) {
73 exitEffect = [[[ITSlideHorizontallyWindowEffect alloc] initWithWindow:_window] autorelease];
74 } else if ( exitTag == 2104 ) {
75 exitEffect = [[[ITPivotWindowEffect alloc] initWithWindow:_window] autorelease];
77 exitEffect = [[[ITDissolveWindowEffect alloc] initWithWindow:_window] autorelease];
80 [_window setExitEffect:exitEffect];
82 [[_window entryEffect] setEffectTime:(entrySpeed ? entrySpeed : 0.8)];
83 [[_window exitEffect] setEffectTime:(exitSpeed ? exitSpeed : 0.8)];
95 - (void)showSongInfoWindowWithSource:(ITMTRemotePlayerSource)source
96 title: (NSString *)title
97 album: (NSString *)album
98 artist: (NSString *)artist
99 time: (NSString *)time // FLOW: Should probably be NSDate or something.
100 track: (NSString *)track
103 NSImage *image = nil;
104 NSString *text = title;
106 if ( source == ITMTRemoteLibrarySource ) {
107 image = [NSImage imageNamed:@"Library"];
108 } else if ( source == ITMTRemoteCDSource ) {
109 image = [NSImage imageNamed:@"CD"];
110 } else if ( source == ITMTRemoteRadioSource ) {
111 image = [NSImage imageNamed:@"Radio"];
112 } else if ( source == ITMTRemoteiPodSource ) {
113 image = [NSImage imageNamed:@"iPod"];
114 } else if ( source == ITMTRemoteGenericDeviceSource ) {
115 image = [NSImage imageNamed:@"MP3Player"];
116 } else if ( source == ITMTRemoteSharedLibrarySource ) {
117 image = [NSImage imageNamed:@"Library"];
120 [_window setImage:image];
123 text = [text stringByAppendingString:[@"\n" stringByAppendingString:album]];
126 text = [text stringByAppendingString:[@"\n" stringByAppendingString:artist]];
129 text = [text stringByAppendingString:[@"\n" stringByAppendingString:time]];
132 text = [text stringByAppendingString:[@"\n" stringByAppendingString:track]];
136 NSString *ratingString = [NSString string];
137 NSString *emptyChar = [NSString stringWithUTF8String:"☆"];
138 NSString *fullChar = [NSString stringWithUTF8String:"★"];
141 for ( i = 1; i < 6; i++ ) {
144 ratingString = [ratingString stringByAppendingString:fullChar];
146 ratingString = [ratingString stringByAppendingString:emptyChar];
150 text = [text stringByAppendingString:[@"\n" stringByAppendingString:ratingString]];
153 [_window buildTextWindowWithString:text];
154 [_window appear:self];
157 - (void)showUpcomingSongsWindowWithTitles:(NSArray *)titleStrings
159 // NSString *bull = [NSString stringWithUTF8String:"‣ "];
160 NSString *bull = [NSString stringWithUTF8String:"♪ "];
161 NSString *end = [@"\n" stringByAppendingString:bull];
162 [_window setImage:[NSImage imageNamed:@"Upcoming"]];
163 [_window buildTextWindowWithString:[bull stringByAppendingString:[titleStrings componentsJoinedByString:end]]];
164 [_window appear:self];
167 - (void)showVolumeWindowWithLevel:(float)level
169 [_window setImage:[NSImage imageNamed:@"Volume"]];
170 [_window buildMeterWindowWithCharacter:[NSString stringWithUTF8String:"▊"]
173 active:( ceil(level * 100) / 10 )];
174 [_window appear:self];
177 - (void)showRatingWindowWithRating:(float)rating
179 [_window setImage:[NSImage imageNamed:@"Rating"]];
180 [_window buildMeterWindowWithCharacter:[NSString stringWithUTF8String:"★"]
183 active:( ceil(rating * 100) / 20 )];
184 [_window appear:self];
187 - (void)showShuffleWindow:(BOOL)shuffle
189 [_window setImage:[NSImage imageNamed:@"Shuffle"]];
190 [_window buildTextWindowWithString:( shuffle ? @"Shuffle On" : @"Shuffle Off")];
191 [_window appear:self];
194 - (void)showRepeatWindowWithMode:(StatusWindowRepeatMode)mode
196 NSString *string = nil;
198 if ( mode == StatusWindowRepeatNone ) {
199 string = @"Repeat Off";
200 } else if ( mode == StatusWindowRepeatGroup ) {
201 string = @"Repeat Playlist";
202 } else if ( mode == StatusWindowRepeatTrack ) {
203 string = @"Repeat One Track";
206 [_window setImage:[NSImage imageNamed:@"Repeat"]];
207 [_window buildTextWindowWithString:string];
208 [_window appear:self];
211 - (void)showSetupQueryWindow
213 NSString *message = @"Would you like MenuTunes to launch\nautomatically at startup?";
215 [_window setImage:[NSImage imageNamed:@"Setup"]];
216 [_window buildDialogWindowWithMessage:message
217 defaultButton:@"Launch at Startup"
218 alternateButton:@"Launch Manually"
219 target:[PreferencesController sharedPrefs]
220 defaultAction:@selector(autoLaunchOK)
221 alternateAction:@selector(autoLaunchCancel)];
223 [_window appear:self];
224 [_window setLocked:YES];