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 [[text mutableString] appendFormat:@"\n%@", time];
157 //text = [text stringByAppendingString:[@"\n" stringByAppendingString:time]];
160 [[text mutableString] appendFormat:@"\n%@", track];
161 //text = [text stringByAppendingString:[@"\n" stringByAppendingString:track]];
163 if (playCount > -1) {
164 [[text mutableString] appendFormat:@"\n%@: %i", NSLocalizedString(@"playCount", @"Play Count"), playCount];
165 //text = [text stringByAppendingString:[NSString stringWithFormat:@"\n%@: %i", NSLocalizedString(@"playCount", @"Play Count"), playCount]];
169 NSString *ratingString = [NSString string];
170 NSString *emptyChar = [NSString stringWithUTF8String:"☆"];
171 NSString *fullChar = [NSString stringWithUTF8String:"★"];
172 int i, start = [[text mutableString] length], size = 18;
174 for ( i = 1; i < 6; i++ ) {
177 ratingString = [ratingString stringByAppendingString:fullChar];
179 ratingString = [ratingString stringByAppendingString:emptyChar];
183 [[text mutableString] appendFormat:@"\n%@", ratingString];
184 if ([_window sizing] == ITTransientStatusWindowSmall) {
185 size /= SMALL_DIVISOR;
186 } else if ([_window sizing] == ITTransientStatusWindowMini) {
187 size /= MINI_DIVISOR;
189 [text setAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[NSFont fontWithName:@"AppleGothic" size:size], NSFontAttributeName, nil, nil] range:NSMakeRange(start + 1, 5)];
190 //text = [text stringByAppendingString:[@"\n" stringByAppendingString:ratingString]];
193 [_window buildTextWindowWithString:text];
194 [_window appear:self];
197 - (void)showUpcomingSongsWindowWithTitles:(NSArray *)titleStrings
199 // NSString *bull = [NSString stringWithUTF8String:"‣ "];
200 NSString *bull = [NSString stringWithUTF8String:"♪ "];
201 NSString *end = [@"\n" stringByAppendingString:bull];
202 [_window setImage:[NSImage imageNamed:@"Upcoming"]];
203 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
204 [_window buildTextWindowWithString:[bull stringByAppendingString:[titleStrings componentsJoinedByString:end]]];
205 [_window appear:self];
208 - (void)showVolumeWindowWithLevel:(float)level
210 [_window setImage:[NSImage imageNamed:@"Volume"]];
211 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
212 [_window buildMeterWindowWithCharacter:[NSString stringWithUTF8String:"▊"]
215 active:( ceil(level * 100) / 10 )];
216 [_window appear:self];
219 - (void)showRatingWindowWithRating:(float)rating
221 [_window setImage:[NSImage imageNamed:@"Rating"]];
222 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
223 [_window buildMeterWindowWithCharacter:[NSString stringWithUTF8String:"★"]
226 active:( ceil(rating * 100) / 20 )];
227 [_window appear:self];
230 - (void)showShuffleWindow:(BOOL)shuffle
232 [_window setImage:[NSImage imageNamed:@"Shuffle"]];
233 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
234 [_window buildTextWindowWithString:( shuffle ? NSLocalizedString(@"shuffleOn", @"Shuffle On") : NSLocalizedString(@"shuffleOff", @"Shuffle Off"))];
235 [_window appear:self];
238 - (void)showRepeatWindowWithMode:(StatusWindowRepeatMode)mode
240 NSString *string = nil;
242 if ( mode == StatusWindowRepeatNone ) {
243 string = NSLocalizedString(@"repeatOff", @"Repeat Off");
244 } else if ( mode == StatusWindowRepeatGroup ) {
245 string = NSLocalizedString(@"repeatPlaylist", @"Repeat Playlist");
246 } else if ( mode == StatusWindowRepeatTrack ) {
247 string = NSLocalizedString(@"repeatOneTrack", @"Repeat One Track");;
250 [_window setImage:[NSImage imageNamed:@"Repeat"]];
251 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
252 [_window buildTextWindowWithString:string];
253 [_window appear:self];
256 - (void)showSetupQueryWindow
258 NSString *message = NSLocalizedString(@"autolaunch_msg", @"Would you like MenuTunes to launch\nautomatically at startup?");
260 [_window setImage:[NSImage imageNamed:@"Setup"]];
261 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
262 [_window buildDialogWindowWithMessage:message
263 defaultButton:NSLocalizedString(@"launch_at_startup", @"Launch at Startup")
264 alternateButton:NSLocalizedString(@"launch_manually", @"Launch Manually")
265 target:[PreferencesController sharedPrefs]
266 defaultAction:@selector(autoLaunchOK)
267 alternateAction:@selector(autoLaunchCancel)];
269 [_window appear:self];
270 [_window setLocked:YES];
274 - (void)showRegistrationQueryWindow
276 NSString *message = NSLocalizedString(@"trialexpired_msg", @"Your 7-day unlimited trial period has elapsed.\nYou must register to continue using MenuTunes.");
278 [_window setImage:[NSImage imageNamed:@"Register"]];
279 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
280 [_window buildDialogWindowWithMessage:message
281 defaultButton:NSLocalizedString(@"registernow", @"Register Now")
282 alternateButton:NSLocalizedString(@"quitmenutunes", @"Quit MenuTunes")
283 target:[MainController sharedController]
284 defaultAction:@selector(registerNowOK)
285 alternateAction:@selector(registerNowCancel)];
287 [_window appear:self];
288 [_window setLocked:YES];
291 - (void)showReconnectQueryWindow
293 NSString *message = NSLocalizedString(@"sharedplayeravailable_msg", @"The selected shared player is available again.\nWould you like to reconnect to it?");
294 [_window setLocked:NO];
295 [_window setImage:[NSImage imageNamed:@"Setup"]];
296 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
297 [_window buildDialogWindowWithMessage:message
298 defaultButton:NSLocalizedString(@"reconnect", @"Reconnect")
299 alternateButton:NSLocalizedString(@"ignore", @"Ignore")
300 target:[MainController sharedController]
301 defaultAction:@selector(reconnect)
302 alternateAction:@selector(cancelReconnect)];
304 [_window appear:self];
305 [_window setLocked:YES];
308 - (void)showNetworkErrorQueryWindow
310 NSString *message = NSLocalizedString(@"sharedplayerunreachable_msg", @"The remote MenuTunes server is unreachable.\nMenuTunes will revert back to the local player.");
312 [_window setImage:[NSImage imageNamed:@"Setup"]];
313 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
314 [_window buildDialogWindowWithMessage:message
315 defaultButton:@" OK "
317 target:[MainController sharedController]
318 defaultAction:@selector(cancelReconnect)
319 alternateAction:nil];
321 [_window appear:self];
322 [_window setLocked:YES];
325 - (void)showPreferencesUpdateWindow
327 NSString *message = NSLocalizedString(@"reconfigureprefs_msg", @"The new features in this version of MenuTunes\nrequire you to reconfigure your preferences.");
329 [_window setImage:[NSImage imageNamed:@"Setup"]];
330 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
331 [_window buildDialogWindowWithMessage:message
332 defaultButton:NSLocalizedString(@"showpreferences", @"Show Preferences")
333 alternateButton:@"OK"
334 target:[MainController sharedController]
335 defaultAction:@selector(showPreferencesAndClose)
336 alternateAction:@selector(cancelReconnect)];
338 [_window appear:self];
339 [_window setLocked:YES];
342 - (void)showDebugModeEnabledWindow
344 [_window setImage:[NSImage imageNamed:@"Setup"]];
345 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
346 [_window buildDialogWindowWithMessage:NSLocalizedString(@"debugmodeenabled", @"Debug Mode Enabled")
349 target:[MainController sharedController]
350 defaultAction:@selector(cancelReconnect)
351 alternateAction:nil];
352 [_window appear:self];
353 [_window setLocked:YES];