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 _window = [[StatusWindow sharedWindow] retain];
48 df = [[NSUserDefaults standardUserDefaults] retain];
50 exitDelay = [df floatForKey:@"statusWindowVanishDelay"];
51 entryClass = [df stringForKey:@"statusWindowAppearanceEffect"];
52 exitClass = [df stringForKey:@"statusWindowVanishEffect"];
53 entrySpeed = [df floatForKey:@"statusWindowAppearanceSpeed"];
54 exitSpeed = [df floatForKey:@"statusWindowVanishSpeed"];
56 screenIndex = [df integerForKey:@"statusWindowScreenIndex"];
57 if (screenIndex >= [screens count]) {
60 [_window setScreen:[screens objectAtIndex:screenIndex]];
62 [_window setExitMode:ITTransientStatusWindowExitAfterDelay];
63 [_window setExitDelay:(exitDelay ? exitDelay : 4.0)];
65 [_window setHorizontalPosition:[df integerForKey:@"statusWindowHorizontalPosition"]];
66 [_window setVerticalPosition:[df integerForKey:@"statusWindowVerticalPosition"]];
68 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
70 if ( [classList containsObject:NSClassFromString(entryClass)] ) {
71 entryEffect = [[[NSClassFromString(entryClass) alloc] initWithWindow:_window] autorelease];
73 entryEffect = [[[ITCutWindowEffect alloc] initWithWindow:_window] autorelease];
76 if ( [classList containsObject:NSClassFromString(exitClass)] ) {
77 exitEffect = [[[NSClassFromString(exitClass) alloc] initWithWindow:_window] autorelease];
79 exitEffect = [[[ITDissolveWindowEffect alloc] initWithWindow:_window] autorelease];
82 [_window setEntryEffect:entryEffect];
83 [_window setExitEffect:exitEffect];
85 [[_window entryEffect] setEffectTime:(entrySpeed ? entrySpeed : 0.8)];
86 [[_window exitEffect] setEffectTime:(exitSpeed ? exitSpeed : 0.8)];
88 [(ITTSWBackgroundView *)[_window contentView]setBackgroundMode:
89 (ITTSWBackgroundMode)[df integerForKey:@"statusWindowBackgroundMode"]];
91 colorData = [df dataForKey:@"statusWindowBackgroundColor"];
94 [(ITTSWBackgroundView *)[_window contentView] setBackgroundColor:
95 (NSColor *)[NSUnarchiver unarchiveObjectWithData:colorData]];
97 [(ITTSWBackgroundView *)[_window contentView] setBackgroundColor:[NSColor blueColor]];
110 - (void)showSongInfoWindowWithSource:(ITMTRemotePlayerSource)source
111 title: (NSString *)title
112 album: (NSString *)album
113 artist: (NSString *)artist
114 composer: (NSString *)composer
115 time: (NSString *)time // FLOW: Should probably be NSDate or something.
116 track: (NSString *)track
118 playCount: (int)playCount
119 image: (NSImage *)art
121 NSImage *image = nil;
122 NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:title];
126 } else if ( source == ITMTRemoteLibrarySource ) {
127 image = [NSImage imageNamed:@"Library"];
128 } else if ( source == ITMTRemoteCDSource ) {
129 image = [NSImage imageNamed:@"CD"];
130 } else if ( source == ITMTRemoteRadioSource ) {
131 image = [NSImage imageNamed:@"Radio"];
132 } else if ( source == ITMTRemoteiPodSource ) {
133 image = [NSImage imageNamed:@"iPod"];
134 } else if ( source == ITMTRemoteGenericDeviceSource ) {
135 image = [NSImage imageNamed:@"MP3Player"];
136 } else if ( source == ITMTRemoteSharedLibrarySource ) {
137 image = [NSImage imageNamed:@"Library"];
140 [_window setImage:image];
141 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
144 [[text mutableString] appendFormat:@"\n%@", album];
145 //text = [text stringByAppendingString:[@"\n" stringByAppendingString:album]];
148 [[text mutableString] appendFormat:@"\n%@", artist];
149 //text = [text stringByAppendingString:[@"\n" stringByAppendingString:artist]];
152 [[text mutableString] appendFormat:@"\n%@", composer];
153 //text = [text stringByAppendingString:[@"\n" stringByAppendingString:composer]];
156 _timeRange = NSMakeRange([[text mutableString] length] + 1, [time length]);
157 [[text mutableString] appendFormat:@"\n%@", time];
158 //text = [text stringByAppendingString:[@"\n" stringByAppendingString:time]];
161 [[text mutableString] appendFormat:@"\n%@", track];
162 //text = [text stringByAppendingString:[@"\n" stringByAppendingString:track]];
164 if (playCount > -1) {
165 [[text mutableString] appendFormat:@"\n%@: %i", NSLocalizedString(@"playCount", @"Play Count"), playCount];
166 //text = [text stringByAppendingString:[NSString stringWithFormat:@"\n%@: %i", NSLocalizedString(@"playCount", @"Play Count"), playCount]];
170 NSString *ratingString = [NSString string];
171 NSString *emptyChar = [NSString stringWithUTF8String:"☆"];
172 NSString *fullChar = [NSString stringWithUTF8String:"★"];
173 int i, start = [[text mutableString] length], size = 18;
175 for ( i = 1; i < 6; i++ ) {
178 ratingString = [ratingString stringByAppendingString:fullChar];
180 ratingString = [ratingString stringByAppendingString:emptyChar];
184 [[text mutableString] appendFormat:@"\n%@", ratingString];
185 if ([_window sizing] == ITTransientStatusWindowSmall) {
186 size /= SMALL_DIVISOR;
187 } else if ([_window sizing] == ITTransientStatusWindowMini) {
188 size /= MINI_DIVISOR;
190 [text setAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[NSFont fontWithName:@"AppleGothic" size:size], NSFontAttributeName, nil, nil] range:NSMakeRange(start + 1, 5)];
191 //text = [text stringByAppendingString:[@"\n" stringByAppendingString:ratingString]];
194 [_window buildTextWindowWithString:text];
195 [_window appear:self];
198 - (void)showUpcomingSongsWindowWithTitles:(NSArray *)titleStrings
200 // NSString *bull = [NSString stringWithUTF8String:"‣ "];
201 NSString *bull = [NSString stringWithUTF8String:"♪ "];
202 NSString *end = [@"\n" stringByAppendingString:bull];
203 [_window setImage:[NSImage imageNamed:@"Upcoming"]];
204 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
205 [_window buildTextWindowWithString:[bull stringByAppendingString:[titleStrings componentsJoinedByString:end]]];
206 [_window appear:self];
209 - (void)showVolumeWindowWithLevel:(float)level
211 [_window setImage:[NSImage imageNamed:@"Volume"]];
212 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
213 [_window buildMeterWindowWithCharacter:[NSString stringWithUTF8String:"▊"]
216 active:( ceil(level * 100) / 10 )];
217 [_window appear:self];
220 - (void)showRatingWindowWithRating:(float)rating
222 [_window setImage:[NSImage imageNamed:@"Rating"]];
223 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
224 [_window buildMeterWindowWithCharacter:[NSString stringWithUTF8String:"★"]
227 active:( ceil(rating * 100) / 20 )];
228 [_window appear:self];
231 - (void)showShuffleWindow:(BOOL)shuffle
233 [_window setImage:[NSImage imageNamed:@"Shuffle"]];
234 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
235 [_window buildTextWindowWithString:( shuffle ? NSLocalizedString(@"shuffleOn", @"Shuffle On") : NSLocalizedString(@"shuffleOff", @"Shuffle Off"))];
236 [_window appear:self];
239 - (void)showRepeatWindowWithMode:(StatusWindowRepeatMode)mode
241 NSString *string = nil;
243 if ( mode == StatusWindowRepeatNone ) {
244 string = NSLocalizedString(@"repeatOff", @"Repeat Off");
245 } else if ( mode == StatusWindowRepeatGroup ) {
246 string = NSLocalizedString(@"repeatPlaylist", @"Repeat Playlist");
247 } else if ( mode == StatusWindowRepeatTrack ) {
248 string = NSLocalizedString(@"repeatOneTrack", @"Repeat One Track");;
251 [_window setImage:[NSImage imageNamed:@"Repeat"]];
252 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
253 [_window buildTextWindowWithString:string];
254 [_window appear:self];
257 - (void)showSongShufflabilityWindow:(BOOL)shufflable
259 [_window setImage:[NSImage imageNamed:@"Shuffle"]];
260 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
261 [_window buildTextWindowWithString:( !shufflable ? NSLocalizedString(@"shufflableOn", @"Current Song Skipped When Shuffling") : NSLocalizedString(@"shufflableOff", @"Current Song Not Skipped When Shuffling"))];
262 [_window appear:self];
265 - (void)showSetupQueryWindow
267 NSString *message = NSLocalizedString(@"autolaunch_msg", @"Would you like MenuTunes to launch\nautomatically at startup?");
269 [_window setImage:[NSImage imageNamed:@"Setup"]];
270 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
271 [_window buildDialogWindowWithMessage:message
272 defaultButton:NSLocalizedString(@"launch_at_startup", @"Launch at Startup")
273 alternateButton:NSLocalizedString(@"launch_manually", @"Launch Manually")
274 target:[PreferencesController sharedPrefs]
275 defaultAction:@selector(autoLaunchOK)
276 alternateAction:@selector(autoLaunchCancel)];
278 [_window appear:self];
279 [_window setLocked:YES];
283 - (void)showRegistrationQueryWindow
285 NSString *message = NSLocalizedString(@"trialexpired_msg", @"Your 7-day unlimited trial period has elapsed.\nYou must register to continue using MenuTunes.");
287 [_window setImage:[NSImage imageNamed:@"Register"]];
288 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
289 [_window buildDialogWindowWithMessage:message
290 defaultButton:NSLocalizedString(@"registernow", @"Register Now")
291 alternateButton:NSLocalizedString(@"quitmenutunes", @"Quit MenuTunes")
292 target:[MainController sharedController]
293 defaultAction:@selector(registerNowOK)
294 alternateAction:@selector(registerNowCancel)];
296 [_window appear:self];
297 [_window setLocked:YES];
300 - (void)showReconnectQueryWindow
302 NSString *message = NSLocalizedString(@"sharedplayeravailable_msg", @"The selected shared player is available again.\nWould you like to reconnect to it?");
303 [_window setLocked:NO];
304 [_window setImage:[NSImage imageNamed:@"Setup"]];
305 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
306 [_window buildDialogWindowWithMessage:message
307 defaultButton:NSLocalizedString(@"reconnect", @"Reconnect")
308 alternateButton:NSLocalizedString(@"ignore", @"Ignore")
309 target:[MainController sharedController]
310 defaultAction:@selector(reconnect)
311 alternateAction:@selector(cancelReconnect)];
313 [_window appear:self];
314 [_window setLocked:YES];
317 - (void)showNetworkErrorQueryWindow
319 NSString *message = NSLocalizedString(@"sharedplayerunreachable_msg", @"The remote MenuTunes server is unreachable.\nMenuTunes will revert back to the local player.");
321 [_window setImage:[NSImage imageNamed:@"Setup"]];
322 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
323 [_window buildDialogWindowWithMessage:message
324 defaultButton:@" OK "
326 target:[MainController sharedController]
327 defaultAction:@selector(cancelReconnect)
328 alternateAction:nil];
330 [_window appear:self];
331 [_window setLocked:YES];
334 - (void)showPreferencesUpdateWindow
336 NSString *message = NSLocalizedString(@"reconfigureprefs_msg", @"The new features in this version of MenuTunes\nrequire you to reconfigure your preferences.");
338 [_window setImage:[NSImage imageNamed:@"Setup"]];
339 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
340 [_window buildDialogWindowWithMessage:message
341 defaultButton:NSLocalizedString(@"showpreferences", @"Show Preferences")
342 alternateButton:@"OK"
343 target:[MainController sharedController]
344 defaultAction:@selector(showPreferencesAndClose)
345 alternateAction:@selector(cancelReconnect)];
347 [_window appear:self];
348 [_window setLocked:YES];
351 - (void)showDebugModeEnabledWindow
353 [_window setImage:[NSImage imageNamed:@"Setup"]];
354 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
355 [_window buildDialogWindowWithMessage:NSLocalizedString(@"debugmodeenabled", @"Debug Mode Enabled")
358 target:[MainController sharedController]
359 defaultAction:@selector(cancelReconnect)
360 alternateAction:nil];
361 [_window appear:self];
362 [_window setLocked:YES];
365 - (void)updateTime:(NSString *)time
367 if (time && [time length]) {
368 [_window updateTime:time range:_timeRange];