1 #import "StatusWindowController.h"
2 #import "StatusWindow.h"
3 #import "PreferencesController.h"
4 #import "MainController.h"
6 #import <ITKit/ITTSWBackgroundView.h>
7 #import <ITKit/ITWindowEffect.h>
8 #import <ITKit/ITCutWindowEffect.h>
9 #import <ITKit/ITDissolveWindowEffect.h>
10 #import <ITKit/ITSlideHorizontallyWindowEffect.h>
11 #import <ITKit/ITSlideVerticallyWindowEffect.h>
12 #import <ITKit/ITPivotWindowEffect.h>
14 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] ) ) {
36 NSArray *classList = [ITWindowEffect effectClasses];
42 ITWindowEffect *entryEffect;
43 ITWindowEffect *exitEffect;
45 _window = [[StatusWindow sharedWindow] retain];
46 df = [[NSUserDefaults standardUserDefaults] retain];
48 exitDelay = [df floatForKey:@"statusWindowVanishDelay"];
49 entryClass = [df stringForKey:@"statusWindowAppearanceEffect"];
50 exitClass = [df stringForKey:@"statusWindowVanishEffect"];
51 entrySpeed = [df floatForKey:@"statusWindowAppearanceSpeed"];
52 exitSpeed = [df floatForKey:@"statusWindowVanishSpeed"];
54 [_window setExitMode:ITTransientStatusWindowExitAfterDelay];
55 [_window setExitDelay:(exitDelay ? exitDelay : 4.0)];
57 [_window setHorizontalPosition:[df integerForKey:@"statusWindowHorizontalPosition"]];
58 [_window setVerticalPosition:[df integerForKey:@"statusWindowVerticalPosition"]];
60 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
62 if ( [classList containsObject:NSClassFromString(entryClass)] ) {
63 entryEffect = [[[NSClassFromString(entryClass) alloc] initWithWindow:_window] autorelease];
65 entryEffect = [[[ITCutWindowEffect alloc] initWithWindow:_window] autorelease];
68 if ( [classList containsObject:NSClassFromString(exitClass)] ) {
69 exitEffect = [[[NSClassFromString(exitClass) alloc] initWithWindow:_window] autorelease];
71 exitEffect = [[[ITDissolveWindowEffect alloc] initWithWindow:_window] autorelease];
74 [_window setEntryEffect:entryEffect];
75 [_window setExitEffect:exitEffect];
77 [[_window entryEffect] setEffectTime:(entrySpeed ? entrySpeed : 0.8)];
78 [[_window exitEffect] setEffectTime:(exitSpeed ? exitSpeed : 0.8)];
80 [(ITTSWBackgroundView *)[_window contentView]setBackgroundMode:
81 (ITTSWBackgroundMode)[df integerForKey:@"statusWindowBackgroundMode"]];
83 colorData = [df dataForKey:@"statusWindowBackgroundColor"];
86 [(ITTSWBackgroundView *)[_window contentView] setBackgroundColor:
87 (NSColor *)[NSUnarchiver unarchiveObjectWithData:colorData]];
89 [(ITTSWBackgroundView *)[_window contentView] setBackgroundColor:[NSColor blueColor]];
102 - (void)showSongInfoWindowWithSource:(ITMTRemotePlayerSource)source
103 title: (NSString *)title
104 album: (NSString *)album
105 artist: (NSString *)artist
106 composer: (NSString *)composer
107 time: (NSString *)time // FLOW: Should probably be NSDate or something.
108 track: (NSString *)track
110 playCount: (int)playCount
111 image: (NSImage *)art
113 NSImage *image = nil;
114 NSString *text = title;
118 } else if ( source == ITMTRemoteLibrarySource ) {
119 image = [NSImage imageNamed:@"Library"];
120 } else if ( source == ITMTRemoteCDSource ) {
121 image = [NSImage imageNamed:@"CD"];
122 } else if ( source == ITMTRemoteRadioSource ) {
123 image = [NSImage imageNamed:@"Radio"];
124 } else if ( source == ITMTRemoteiPodSource ) {
125 image = [NSImage imageNamed:@"iPod"];
126 } else if ( source == ITMTRemoteGenericDeviceSource ) {
127 image = [NSImage imageNamed:@"MP3Player"];
128 } else if ( source == ITMTRemoteSharedLibrarySource ) {
129 image = [NSImage imageNamed:@"Library"];
132 [_window setImage:image];
135 text = [text stringByAppendingString:[@"\n" stringByAppendingString:album]];
138 text = [text stringByAppendingString:[@"\n" stringByAppendingString:artist]];
141 text = [text stringByAppendingString:[@"\n" stringByAppendingString:composer]];
144 text = [text stringByAppendingString:[@"\n" stringByAppendingString:time]];
147 text = [text stringByAppendingString:[@"\n" stringByAppendingString:track]];
149 if (playCount > -1) {
150 text = [text stringByAppendingString:[NSString stringWithFormat:@"\nPlay Count: %i", playCount]];
154 NSString *ratingString = [NSString string];
155 NSString *emptyChar = [NSString stringWithUTF8String:"☆"];
156 NSString *fullChar = [NSString stringWithUTF8String:"★"];
159 for ( i = 1; i < 6; i++ ) {
162 ratingString = [ratingString stringByAppendingString:fullChar];
164 ratingString = [ratingString stringByAppendingString:emptyChar];
168 text = [text stringByAppendingString:[@"\n" stringByAppendingString:ratingString]];
171 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
172 [_window buildTextWindowWithString:text];
173 [_window appear:self];
176 - (void)showUpcomingSongsWindowWithTitles:(NSArray *)titleStrings
178 // NSString *bull = [NSString stringWithUTF8String:"‣ "];
179 NSString *bull = [NSString stringWithUTF8String:"♪ "];
180 NSString *end = [@"\n" stringByAppendingString:bull];
181 [_window setImage:[NSImage imageNamed:@"Upcoming"]];
182 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
183 [_window buildTextWindowWithString:[bull stringByAppendingString:[titleStrings componentsJoinedByString:end]]];
184 [_window appear:self];
187 - (void)showVolumeWindowWithLevel:(float)level
189 [_window setImage:[NSImage imageNamed:@"Volume"]];
190 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
191 [_window buildMeterWindowWithCharacter:[NSString stringWithUTF8String:"▊"]
194 active:( ceil(level * 100) / 10 )];
195 [_window appear:self];
198 - (void)showRatingWindowWithRating:(float)rating
200 [_window setImage:[NSImage imageNamed:@"Rating"]];
201 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
202 [_window buildMeterWindowWithCharacter:[NSString stringWithUTF8String:"★"]
205 active:( ceil(rating * 100) / 20 )];
206 [_window appear:self];
209 - (void)showShuffleWindow:(BOOL)shuffle
211 [_window setImage:[NSImage imageNamed:@"Shuffle"]];
212 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
213 [_window buildTextWindowWithString:( shuffle ? @"Shuffle On" : @"Shuffle Off")];
214 [_window appear:self];
217 - (void)showRepeatWindowWithMode:(StatusWindowRepeatMode)mode
219 NSString *string = nil;
221 if ( mode == StatusWindowRepeatNone ) {
222 string = @"Repeat Off";
223 } else if ( mode == StatusWindowRepeatGroup ) {
224 string = @"Repeat Playlist";
225 } else if ( mode == StatusWindowRepeatTrack ) {
226 string = @"Repeat One Track";
229 [_window setImage:[NSImage imageNamed:@"Repeat"]];
230 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
231 [_window buildTextWindowWithString:string];
232 [_window appear:self];
235 - (void)showSetupQueryWindow
237 NSString *message = @"Would you like MenuTunes to launch\nautomatically at startup?";
239 [_window setImage:[NSImage imageNamed:@"Setup"]];
240 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
241 [_window buildDialogWindowWithMessage:message
242 defaultButton:@"Launch at Startup"
243 alternateButton:@"Launch Manually"
244 target:[PreferencesController sharedPrefs]
245 defaultAction:@selector(autoLaunchOK)
246 alternateAction:@selector(autoLaunchCancel)];
248 [_window appear:self];
249 [_window setLocked:YES];
253 - (void)showRegistrationQueryWindow
255 NSString *message = @"Your 7-day unlimited trial period has elapsed.\nYou must register to continue using MenuTunes.";
257 [_window setImage:[NSImage imageNamed:@"Register"]];
258 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
259 [_window buildDialogWindowWithMessage:message
260 defaultButton:@"Register Now"
261 alternateButton:@"Quit MenuTunes"
262 target:[MainController sharedController]
263 defaultAction:@selector(registerNowOK)
264 alternateAction:@selector(registerNowCancel)];
266 [_window appear:self];
267 [_window setLocked:YES];
270 - (void)showReconnectQueryWindow
272 NSString *message = @"The selected shared player is available again.\nWould you like to reconnect to it?";
273 [_window setLocked:NO];
274 [_window setImage:[NSImage imageNamed:@"Setup"]];
275 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
276 [_window buildDialogWindowWithMessage:message
277 defaultButton:@"Reconnect"
278 alternateButton:@"Ignore"
279 target:[MainController sharedController]
280 defaultAction:@selector(reconnect)
281 alternateAction:@selector(cancelReconnect)];
283 [_window appear:self];
284 [_window setLocked:YES];
287 - (void)showNetworkErrorQueryWindow
289 NSString *message = @"The remote MenuTunes server is unreachable.\nMenuTunes will revert back to the local player.";
291 [_window setImage:[NSImage imageNamed:@"Setup"]];
292 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
293 [_window buildDialogWindowWithMessage:message
294 defaultButton:@" OK "
296 target:[MainController sharedController]
297 defaultAction:@selector(cancelReconnect)
298 alternateAction:nil];
300 [_window appear:self];
301 [_window setLocked:YES];
304 - (void)showPreferencesUpdateWindow
306 NSString *message = @"The new features in this version of MenuTunes\nrequire you to reconfigure your preferences.";
308 [_window setImage:[NSImage imageNamed:@"Setup"]];
309 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
310 [_window buildDialogWindowWithMessage:message
311 defaultButton:@"Show Preferences"
312 alternateButton:@"OK"
313 target:[MainController sharedController]
314 defaultAction:@selector(showPreferencesAndClose)
315 alternateAction:@selector(cancelReconnect)];
317 [_window appear:self];
318 [_window setLocked:YES];