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];
39 NSArray *screens = [NSScreen screens];
44 ITWindowEffect *entryEffect;
45 ITWindowEffect *exitEffect;
47 _currentType = StatusWindowNoType;
49 _window = [[StatusWindow sharedWindow] retain];
50 df = [[NSUserDefaults standardUserDefaults] retain];
52 exitDelay = [df floatForKey:@"statusWindowVanishDelay"];
53 entryClass = [df stringForKey:@"statusWindowAppearanceEffect"];
54 exitClass = [df stringForKey:@"statusWindowVanishEffect"];
55 entrySpeed = [df floatForKey:@"statusWindowAppearanceSpeed"];
56 exitSpeed = [df floatForKey:@"statusWindowVanishSpeed"];
58 screenIndex = [df integerForKey:@"statusWindowScreenIndex"];
59 if (screenIndex >= [screens count]) {
62 [_window setScreen:[screens objectAtIndex:screenIndex]];
64 [_window setExitMode:ITTransientStatusWindowExitAfterDelay];
65 [_window setExitDelay:(exitDelay ? exitDelay : 4.0)];
67 [_window setHorizontalPosition:[df integerForKey:@"statusWindowHorizontalPosition"]];
68 [_window setVerticalPosition:[df integerForKey:@"statusWindowVerticalPosition"]];
70 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
72 if ( [classList containsObject:NSClassFromString(entryClass)] ) {
73 entryEffect = [[[NSClassFromString(entryClass) alloc] initWithWindow:_window] autorelease];
75 entryEffect = [[[ITCutWindowEffect alloc] initWithWindow:_window] autorelease];
78 if ( [classList containsObject:NSClassFromString(exitClass)] ) {
79 exitEffect = [[[NSClassFromString(exitClass) alloc] initWithWindow:_window] autorelease];
81 exitEffect = [[[ITDissolveWindowEffect alloc] initWithWindow:_window] autorelease];
84 [_window setEntryEffect:entryEffect];
85 [_window setExitEffect:exitEffect];
87 [[_window entryEffect] setEffectTime:(entrySpeed ? entrySpeed : 0.8)];
88 [[_window exitEffect] setEffectTime:(exitSpeed ? exitSpeed : 0.8)];
90 [(ITTSWBackgroundView *)[_window contentView]setBackgroundMode:
91 (ITTSWBackgroundMode)[df integerForKey:@"statusWindowBackgroundMode"]];
93 colorData = [df dataForKey:@"statusWindowBackgroundColor"];
96 [(ITTSWBackgroundView *)[_window contentView] setBackgroundColor:
97 (NSColor *)[NSUnarchiver unarchiveObjectWithData:colorData]];
99 [(ITTSWBackgroundView *)[_window contentView] setBackgroundColor:[NSColor blueColor]];
102 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(screenParametersChanged:) name:NSApplicationDidChangeScreenParametersNotification object:nil];
110 [[NSNotificationCenter defaultCenter] removeObserver:self];
116 - (void)screenParametersChanged:(NSNotification *)notification
118 NSArray *screens = [NSScreen screens];
119 int screenIndex = [df integerForKey:@"statusWindowScreenIndex"];
121 if (screenIndex >= [screens count]) {
124 [_window setScreen:[screens objectAtIndex:screenIndex]];
127 - (void)showSongInfoWindowWithSource:(ITMTRemotePlayerSource)source
128 title: (NSString *)title
129 album: (NSString *)album
130 artist: (NSString *)artist
131 composer: (NSString *)composer
132 time: (NSString *)time // FLOW: Should probably be NSDate or something.
133 track: (NSString *)track
135 playCount: (int)playCount
136 image: (NSImage *)art
138 NSImage *image = nil;
139 NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:title];
143 } else if ( source == ITMTRemoteLibrarySource ) {
144 image = [NSImage imageNamed:@"Library"];
145 } else if ( source == ITMTRemoteCDSource ) {
146 image = [NSImage imageNamed:@"CD"];
147 } else if ( source == ITMTRemoteRadioSource ) {
148 image = [NSImage imageNamed:@"Radio"];
149 } else if ( source == ITMTRemoteiPodSource ) {
150 image = [NSImage imageNamed:@"iPod"];
151 } else if ( source == ITMTRemoteGenericDeviceSource ) {
152 image = [NSImage imageNamed:@"MP3Player"];
153 } else if ( source == ITMTRemoteSharedLibrarySource ) {
154 image = [NSImage imageNamed:@"Library"];
157 [_window setImage:image];
158 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
161 [[text mutableString] appendFormat:@"\n%@", album];
162 //text = [text stringByAppendingString:[@"\n" stringByAppendingString:album]];
165 [[text mutableString] appendFormat:@"\n%@", artist];
166 //text = [text stringByAppendingString:[@"\n" stringByAppendingString:artist]];
169 [[text mutableString] appendFormat:@"\n%@", composer];
170 //text = [text stringByAppendingString:[@"\n" stringByAppendingString:composer]];
173 _timeRange = NSMakeRange([[text mutableString] length] + 1, [time length]);
174 [[text mutableString] appendFormat:@"\n%@", time];
175 //text = [text stringByAppendingString:[@"\n" stringByAppendingString:time]];
178 [[text mutableString] appendFormat:@"\n%@", track];
179 //text = [text stringByAppendingString:[@"\n" stringByAppendingString:track]];
181 if (playCount > -1) {
182 [[text mutableString] appendFormat:@"\n%@: %i", NSLocalizedString(@"playCount", @"Play Count"), playCount];
183 //text = [text stringByAppendingString:[NSString stringWithFormat:@"\n%@: %i", NSLocalizedString(@"playCount", @"Play Count"), playCount]];
187 NSString *ratingString = [NSString string];
188 NSString *emptyChar = [NSString stringWithUTF8String:"☆"];
189 NSString *fullChar = [NSString stringWithUTF8String:"★"];
190 int i, start = [[text mutableString] length], size = 18;
192 for ( i = 1; i < 6; i++ ) {
195 ratingString = [ratingString stringByAppendingString:fullChar];
197 ratingString = [ratingString stringByAppendingString:emptyChar];
201 [[text mutableString] appendFormat:@"\n%@", ratingString];
202 if ([_window sizing] == ITTransientStatusWindowSmall) {
203 size /= SMALL_DIVISOR;
204 } else if ([_window sizing] == ITTransientStatusWindowMini) {
205 size /= MINI_DIVISOR;
207 [text setAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[NSFont fontWithName:@"AppleGothic" size:size], NSFontAttributeName, nil, nil] range:NSMakeRange(start + 1, 5)];
208 //text = [text stringByAppendingString:[@"\n" stringByAppendingString:ratingString]];
211 _currentType = StatusWindowTrackInfoType;
212 [_window buildTextWindowWithString:text];
213 [_window appear:self];
217 - (void)showAlbumArtWindowWithImage:(NSImage *)image
220 _currentType = StatusWindowAlbumArtType;
221 [_window setImage:[NSImage imageNamed:@"Library"]];
222 [_window buildImageWindowWithImage:image];
223 [_window appear:self];
227 - (void)showAlbumArtWindowWithErrorText:(NSString *)string
229 if (string && [string length] > 0) {
230 _currentType = StatusWindowAlbumArtType;
231 [_window buildTextWindowWithString:string];
232 [_window appear:self];
236 - (void)showUpcomingSongsWindowWithTitles:(NSArray *)titleStrings
238 // NSString *bull = [NSString stringWithUTF8String:"‣ "];
239 NSString *bull = [NSString stringWithUTF8String:"♪ "];
240 NSString *end = [@"\n" stringByAppendingString:bull];
241 [_window setImage:[NSImage imageNamed:@"Upcoming"]];
242 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
243 [_window buildTextWindowWithString:[bull stringByAppendingString:[titleStrings componentsJoinedByString:end]]];
244 _currentType = StatusWindowUpcomingSongsType;
245 [_window appear:self];
248 - (void)showVolumeWindowWithLevel:(float)level
250 [_window setImage:[NSImage imageNamed:@"Volume"]];
251 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
252 [_window buildMeterWindowWithCharacter:[NSString stringWithUTF8String:"▊"]
255 active:( ceil(level * 100) / 10 )];
256 _currentType = StatusWindowVolumeType;
257 [_window appear:self];
260 - (void)showRatingWindowWithRating:(float)rating
262 [_window setImage:[NSImage imageNamed:@"Rating"]];
263 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
264 [_window buildMeterWindowWithCharacter:[NSString stringWithUTF8String:"★"]
267 active:( ceil(rating * 100) / 20 )];
268 _currentType = StatusWindowRatingType;
269 [_window appear:self];
272 - (void)showShuffleWindow:(BOOL)shuffle
274 [_window setImage:[NSImage imageNamed:@"Shuffle"]];
275 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
276 [_window buildTextWindowWithString:( shuffle ? NSLocalizedString(@"shuffleOn", @"Shuffle On") : NSLocalizedString(@"shuffleOff", @"Shuffle Off"))];
277 _currentType = StatusWindowRatingType;
278 [_window appear:self];
281 - (void)showRepeatWindowWithMode:(StatusWindowRepeatMode)mode
283 NSString *string = nil;
285 if ( mode == StatusWindowRepeatNone ) {
286 string = NSLocalizedString(@"repeatOff", @"Repeat Off");
287 } else if ( mode == StatusWindowRepeatGroup ) {
288 string = NSLocalizedString(@"repeatPlaylist", @"Repeat Playlist");
289 } else if ( mode == StatusWindowRepeatTrack ) {
290 string = NSLocalizedString(@"repeatOneTrack", @"Repeat One Track");;
293 [_window setImage:[NSImage imageNamed:@"Repeat"]];
294 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
295 [_window buildTextWindowWithString:string];
296 _currentType = StatusWindowRepeatType;
297 [_window appear:self];
300 - (void)showSongShufflabilityWindow:(BOOL)shufflable
302 [_window setImage:[NSImage imageNamed:@"Shuffle"]];
303 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
304 [_window buildTextWindowWithString:( !shufflable ? NSLocalizedString(@"shufflableOn", @"Current Song Skipped When Shuffling") : NSLocalizedString(@"shufflableOff", @"Current Song Not Skipped When Shuffling"))];
305 _currentType = StatusWindowShufflabilityType;
306 [_window appear:self];
309 - (void)showSetupQueryWindow
311 NSString *message = NSLocalizedString(@"autolaunch_msg", @"Would you like MenuTunes to launch\nautomatically at startup?");
313 [_window setImage:[NSImage imageNamed:@"Setup"]];
314 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
315 [_window buildDialogWindowWithMessage:message
316 defaultButton:NSLocalizedString(@"launch_at_startup", @"Launch at Startup")
317 alternateButton:NSLocalizedString(@"launch_manually", @"Launch Manually")
318 target:[PreferencesController sharedPrefs]
319 defaultAction:@selector(autoLaunchOK)
320 alternateAction:@selector(autoLaunchCancel)];
322 _currentType = StatusWindowSetupType;
323 [_window appear:self];
324 [_window setLocked:YES];
327 - (void)showReconnectQueryWindow
329 NSString *message = NSLocalizedString(@"sharedplayeravailable_msg", @"The selected shared player is available again.\nWould you like to reconnect to it?");
330 [_window setLocked:NO];
331 [_window setImage:[NSImage imageNamed:@"Setup"]];
332 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
333 [_window buildDialogWindowWithMessage:message
334 defaultButton:NSLocalizedString(@"reconnect", @"Reconnect")
335 alternateButton:NSLocalizedString(@"ignore", @"Ignore")
336 target:[MainController sharedController]
337 defaultAction:@selector(reconnect)
338 alternateAction:@selector(cancelReconnect)];
340 _currentType = StatusWindowNetworkType;
341 [_window appear:self];
342 [_window setLocked:YES];
345 - (void)showNetworkErrorQueryWindow
347 NSString *message = NSLocalizedString(@"sharedplayerunreachable_msg", @"The remote MenuTunes server is unreachable.\nMenuTunes will revert back to the local player.");
349 [_window setImage:[NSImage imageNamed:@"Setup"]];
350 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
351 [_window buildDialogWindowWithMessage:message
352 defaultButton:@" OK "
354 target:[MainController sharedController]
355 defaultAction:@selector(cancelReconnect)
356 alternateAction:nil];
358 _currentType = StatusWindowNetworkType;
359 [_window appear:self];
360 [_window setLocked:YES];
363 - (void)showPreferencesUpdateWindow
365 NSString *message = NSLocalizedString(@"reconfigureprefs_msg", @"The new features in this version of MenuTunes\nrequire you to reconfigure your preferences.");
367 [_window setImage:[NSImage imageNamed:@"Setup"]];
368 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
369 [_window buildDialogWindowWithMessage:message
370 defaultButton:NSLocalizedString(@"showpreferences", @"Show Preferences")
371 alternateButton:@"OK"
372 target:[MainController sharedController]
373 defaultAction:@selector(showPreferencesAndClose)
374 alternateAction:@selector(cancelReconnect)];
376 _currentType = StatusWindowPreferencesType;
377 [_window appear:self];
378 [_window setLocked:YES];
381 - (void)showDebugModeEnabledWindow
383 [_window setImage:[NSImage imageNamed:@"Setup"]];
384 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
385 [_window buildDialogWindowWithMessage:NSLocalizedString(@"debugmodeenabled", @"Debug Mode Enabled")
388 target:[MainController sharedController]
389 defaultAction:@selector(cancelReconnect)
390 alternateAction:nil];
392 _currentType = StatusWindowDebugType;
393 [_window appear:self];
394 [_window setLocked:YES];
397 - (StatusWindowType)currentStatusWindowType
402 - (void)updateTime:(NSString *)time
404 if (time && [time length]) {
405 [_window updateTime:time range:_timeRange];