1 #import "StatusWindowController.h"
2 #import "StatusWindow.h"
3 #import "PreferencesController.h"
4 #import "MainController.h"
6 #import <ITKit/ITWindowEffect.h>
7 #import <ITKit/ITCutWindowEffect.h>
8 #import <ITKit/ITDissolveWindowEffect.h>
9 #import <ITKit/ITSlideHorizontallyWindowEffect.h>
10 #import <ITKit/ITSlideVerticallyWindowEffect.h>
11 #import <ITKit/ITPivotWindowEffect.h>
14 static StatusWindowController *sharedController;
17 @implementation StatusWindowController
20 + (StatusWindowController *)sharedController
22 if ( ! sharedController ) {
23 sharedController = [[StatusWindowController alloc] init];
26 return sharedController;
32 if ( ( self = [super init] ) ) {
40 ITWindowEffect *entryEffect;
41 ITWindowEffect *exitEffect;
43 _window = [[StatusWindow sharedWindow] retain];
44 df = [[NSUserDefaults standardUserDefaults] retain];
46 exitDelay = [df floatForKey:@"statusWindowVanishDelay"];
47 entryTag = [df integerForKey:@"statusWindowAppearanceEffect"];
48 exitTag = [df integerForKey:@"statusWindowVanishEffect"];
49 entrySpeed = [df floatForKey:@"statusWindowAppearanceSpeed"];
50 exitSpeed = [df floatForKey:@"statusWindowVanishSpeed"];
52 [_window setExitMode:ITTransientStatusWindowExitAfterDelay];
53 [_window setExitDelay:(exitDelay ? exitDelay : 4.0)];
55 [_window setHorizontalPosition:[df integerForKey:@"statusWindowHorizontalPosition"]];
56 [_window setVerticalPosition:[df integerForKey:@"statusWindowVerticalPosition"]];
58 if ( entryTag == 2101 ) {
59 entryEffect = [[[ITDissolveWindowEffect alloc] initWithWindow:_window] autorelease];
60 } else if ( entryTag == 2102 ) {
61 entryEffect = [[[ITSlideVerticallyWindowEffect alloc] initWithWindow:_window] autorelease];
62 } else if ( entryTag == 2103 ) {
63 entryEffect = [[[ITSlideHorizontallyWindowEffect alloc] initWithWindow:_window] autorelease];
64 } else if ( entryTag == 2104 ) {
65 entryEffect = [[[ITPivotWindowEffect alloc] initWithWindow:_window] autorelease];
67 entryEffect = [[[ITCutWindowEffect alloc] initWithWindow:_window] autorelease];
70 [_window setEntryEffect:entryEffect];
72 if ( exitTag == 2100 ) {
73 exitEffect = [[[ITCutWindowEffect alloc] initWithWindow:_window] autorelease];
74 } else if ( exitTag == 2102 ) {
75 exitEffect = [[[ITSlideVerticallyWindowEffect alloc] initWithWindow:_window] autorelease];
76 } else if ( exitTag == 2103 ) {
77 exitEffect = [[[ITSlideHorizontallyWindowEffect alloc] initWithWindow:_window] autorelease];
78 } else if ( exitTag == 2104 ) {
79 exitEffect = [[[ITPivotWindowEffect alloc] initWithWindow:_window] autorelease];
81 exitEffect = [[[ITDissolveWindowEffect alloc] initWithWindow:_window] autorelease];
84 [_window setExitEffect:exitEffect];
86 [[_window entryEffect] setEffectTime:(entrySpeed ? entrySpeed : 0.8)];
87 [[_window exitEffect] setEffectTime:(exitSpeed ? exitSpeed : 0.8)];
99 - (void)showSongInfoWindowWithSource:(ITMTRemotePlayerSource)source
100 title: (NSString *)title
101 album: (NSString *)album
102 artist: (NSString *)artist
103 time: (NSString *)time // FLOW: Should probably be NSDate or something.
104 track: (NSString *)track
107 NSImage *image = nil;
108 NSString *text = title;
110 if ( source == ITMTRemoteLibrarySource ) {
111 image = [NSImage imageNamed:@"Library"];
112 } else if ( source == ITMTRemoteCDSource ) {
113 image = [NSImage imageNamed:@"CD"];
114 } else if ( source == ITMTRemoteRadioSource ) {
115 image = [NSImage imageNamed:@"Radio"];
116 } else if ( source == ITMTRemoteiPodSource ) {
117 image = [NSImage imageNamed:@"iPod"];
118 } else if ( source == ITMTRemoteGenericDeviceSource ) {
119 image = [NSImage imageNamed:@"MP3Player"];
120 } else if ( source == ITMTRemoteSharedLibrarySource ) {
121 image = [NSImage imageNamed:@"Library"];
124 [_window setImage:image];
127 text = [text stringByAppendingString:[@"\n" stringByAppendingString:album]];
130 text = [text stringByAppendingString:[@"\n" stringByAppendingString:artist]];
133 text = [text stringByAppendingString:[@"\n" stringByAppendingString:time]];
136 text = [text stringByAppendingString:[@"\n" stringByAppendingString:track]];
140 NSString *ratingString = [NSString string];
141 NSString *emptyChar = [NSString stringWithUTF8String:"☆"];
142 NSString *fullChar = [NSString stringWithUTF8String:"★"];
145 for ( i = 1; i < 6; i++ ) {
148 ratingString = [ratingString stringByAppendingString:fullChar];
150 ratingString = [ratingString stringByAppendingString:emptyChar];
154 text = [text stringByAppendingString:[@"\n" stringByAppendingString:ratingString]];
157 [_window buildTextWindowWithString:text];
158 [_window appear:self];
161 - (void)showUpcomingSongsWindowWithTitles:(NSArray *)titleStrings
163 // NSString *bull = [NSString stringWithUTF8String:"‣ "];
164 NSString *bull = [NSString stringWithUTF8String:"♪ "];
165 NSString *end = [@"\n" stringByAppendingString:bull];
166 [_window setImage:[NSImage imageNamed:@"Upcoming"]];
167 [_window buildTextWindowWithString:[bull stringByAppendingString:[titleStrings componentsJoinedByString:end]]];
168 [_window appear:self];
171 - (void)showVolumeWindowWithLevel:(float)level
173 [_window setImage:[NSImage imageNamed:@"Volume"]];
174 [_window buildMeterWindowWithCharacter:[NSString stringWithUTF8String:"▊"]
177 active:( ceil(level * 100) / 10 )];
178 [_window appear:self];
181 - (void)showRatingWindowWithRating:(float)rating
183 [_window setImage:[NSImage imageNamed:@"Rating"]];
184 [_window buildMeterWindowWithCharacter:[NSString stringWithUTF8String:"★"]
187 active:( ceil(rating * 100) / 20 )];
188 [_window appear:self];
191 - (void)showShuffleWindow:(BOOL)shuffle
193 [_window setImage:[NSImage imageNamed:@"Shuffle"]];
194 [_window buildTextWindowWithString:( shuffle ? @"Shuffle On" : @"Shuffle Off")];
195 [_window appear:self];
198 - (void)showRepeatWindowWithMode:(StatusWindowRepeatMode)mode
200 NSString *string = nil;
202 if ( mode == StatusWindowRepeatNone ) {
203 string = @"Repeat Off";
204 } else if ( mode == StatusWindowRepeatGroup ) {
205 string = @"Repeat Playlist";
206 } else if ( mode == StatusWindowRepeatTrack ) {
207 string = @"Repeat One Track";
210 [_window setImage:[NSImage imageNamed:@"Repeat"]];
211 [_window buildTextWindowWithString:string];
212 [_window appear:self];
215 - (void)showSetupQueryWindow
217 NSString *message = @"Would you like MenuTunes to launch\nautomatically at startup?";
219 [_window setImage:[NSImage imageNamed:@"Setup"]];
220 [_window buildDialogWindowWithMessage:message
221 defaultButton:@"Launch at Startup"
222 alternateButton:@"Launch Manually"
223 target:[PreferencesController sharedPrefs]
224 defaultAction:@selector(autoLaunchOK)
225 alternateAction:@selector(autoLaunchCancel)];
227 [_window appear:self];
228 [_window setLocked:YES];
232 - (void)showRegistrationQueryWindow
234 NSString *message = @"Your 7-day unlimited trial period has elapsed.\nYou must register to continue using MenuTunes.";
236 [_window setImage:[NSImage imageNamed:@"Register"]];
237 [_window buildDialogWindowWithMessage:message
238 defaultButton:@"Register Now"
239 alternateButton:@"Quit MenuTunes"
240 target:[MainController sharedController]
241 defaultAction:@selector(registerNowOK)
242 alternateAction:@selector(registerNowCancel)];
244 [_window appear:self];
245 [_window setLocked:YES];
248 - (void)showReconnectQueryWindow
250 NSString *message = @"The selected shared player is available again.\nWould you like to reconnect to it?.";
252 [_window setImage:[NSImage imageNamed:@"Register"]];
253 [_window buildDialogWindowWithMessage:message
254 defaultButton:@"Reconnect"
255 alternateButton:@"Ignore"
256 target:[MainController sharedController]
257 defaultAction:@selector(reconnect)
258 alternateAction:@selector(cancelReconnect)];
260 [_window appear:self];
261 [_window setLocked:YES];