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>
15 static StatusWindowController *sharedController;
18 @implementation StatusWindowController
21 + (StatusWindowController *)sharedController
23 if ( ! sharedController ) {
24 sharedController = [[StatusWindowController alloc] init];
27 return sharedController;
33 if ( ( self = [super init] ) ) {
38 NSArray *classList = [ITWindowEffect effectClasses];
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 [_window setExitMode:ITTransientStatusWindowExitAfterDelay];
57 [_window setExitDelay:(exitDelay ? exitDelay : 4.0)];
59 [_window setHorizontalPosition:[df integerForKey:@"statusWindowHorizontalPosition"]];
60 [_window setVerticalPosition:[df integerForKey:@"statusWindowVerticalPosition"]];
62 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
64 if ( [classList containsObject:NSClassFromString(entryClass)] ) {
65 entryEffect = [[[NSClassFromString(entryClass) alloc] initWithWindow:_window] autorelease];
67 entryEffect = [[[ITCutWindowEffect alloc] initWithWindow:_window] autorelease];
70 if ( [classList containsObject:NSClassFromString(exitClass)] ) {
71 exitEffect = [[[NSClassFromString(exitClass) alloc] initWithWindow:_window] autorelease];
73 exitEffect = [[[ITDissolveWindowEffect alloc] initWithWindow:_window] autorelease];
76 [_window setEntryEffect:entryEffect];
77 [_window setExitEffect:exitEffect];
79 [[_window entryEffect] setEffectTime:(entrySpeed ? entrySpeed : 0.8)];
80 [[_window exitEffect] setEffectTime:(exitSpeed ? exitSpeed : 0.8)];
82 [(ITTSWBackgroundView *)[_window contentView]setBackgroundMode:
83 (ITTSWBackgroundMode)[df integerForKey:@"statusWindowBackgroundMode"]];
85 colorData = [df dataForKey:@"statusWindowBackgroundColor"];
88 [(ITTSWBackgroundView *)[_window contentView] setBackgroundColor:
89 (NSColor *)[NSUnarchiver unarchiveObjectWithData:colorData]];
91 [(ITTSWBackgroundView *)[_window contentView] setBackgroundColor:[NSColor blueColor]];
104 - (void)showSongInfoWindowWithSource:(ITMTRemotePlayerSource)source
105 title: (NSString *)title
106 album: (NSString *)album
107 artist: (NSString *)artist
108 time: (NSString *)time // FLOW: Should probably be NSDate or something.
109 track: (NSString *)track
111 image: (NSImage *)art
113 NSImage *image = nil;
114 NSString *text = title;
118 [[NSGraphicsContext currentContext] setImageInterpolation:NSImageInterpolationLow];
119 [image setScalesWhenResized:YES];
120 [image setSize:NSMakeSize(110, 110)];
121 /*if (size.width > 110 && size.width > size.height) {
122 [image setSize:NSMakeSize(110, (size.width / size.height) * 110)];
123 } else if (size.height > 110 && size.height > size.width) {
124 [image setSize:NSMakeSize((size.height / size.width) * 110, 110)];
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];
143 text = [text stringByAppendingString:[@"\n" stringByAppendingString:album]];
146 text = [text stringByAppendingString:[@"\n" stringByAppendingString:artist]];
149 text = [text stringByAppendingString:[@"\n" stringByAppendingString:time]];
152 text = [text stringByAppendingString:[@"\n" stringByAppendingString:track]];
156 NSString *ratingString = [NSString string];
157 NSString *emptyChar = [NSString stringWithUTF8String:"☆"];
158 NSString *fullChar = [NSString stringWithUTF8String:"★"];
161 for ( i = 1; i < 6; i++ ) {
164 ratingString = [ratingString stringByAppendingString:fullChar];
166 ratingString = [ratingString stringByAppendingString:emptyChar];
170 text = [text stringByAppendingString:[@"\n" stringByAppendingString:ratingString]];
174 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
175 [_window buildTextWindowWithString:text];
176 [_window appear:self];
179 - (void)showUpcomingSongsWindowWithTitles:(NSArray *)titleStrings
181 // NSString *bull = [NSString stringWithUTF8String:"‣ "];
182 NSString *bull = [NSString stringWithUTF8String:"♪ "];
183 NSString *end = [@"\n" stringByAppendingString:bull];
184 [_window setImage:[NSImage imageNamed:@"Upcoming"]];
185 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
186 [_window buildTextWindowWithString:[bull stringByAppendingString:[titleStrings componentsJoinedByString:end]]];
187 [_window appear:self];
190 - (void)showVolumeWindowWithLevel:(float)level
192 [_window setImage:[NSImage imageNamed:@"Volume"]];
193 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
194 [_window buildMeterWindowWithCharacter:[NSString stringWithUTF8String:"▊"]
197 active:( ceil(level * 100) / 10 )];
198 [_window appear:self];
201 - (void)showRatingWindowWithRating:(float)rating
203 [_window setImage:[NSImage imageNamed:@"Rating"]];
204 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
205 [_window buildMeterWindowWithCharacter:[NSString stringWithUTF8String:"★"]
208 active:( ceil(rating * 100) / 20 )];
209 [_window appear:self];
212 - (void)showShuffleWindow:(BOOL)shuffle
214 [_window setImage:[NSImage imageNamed:@"Shuffle"]];
215 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
216 [_window buildTextWindowWithString:( shuffle ? @"Shuffle On" : @"Shuffle Off")];
217 [_window appear:self];
220 - (void)showRepeatWindowWithMode:(StatusWindowRepeatMode)mode
222 NSString *string = nil;
224 if ( mode == StatusWindowRepeatNone ) {
225 string = @"Repeat Off";
226 } else if ( mode == StatusWindowRepeatGroup ) {
227 string = @"Repeat Playlist";
228 } else if ( mode == StatusWindowRepeatTrack ) {
229 string = @"Repeat One Track";
232 [_window setImage:[NSImage imageNamed:@"Repeat"]];
233 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
234 [_window buildTextWindowWithString:string];
235 [_window appear:self];
238 - (void)showSetupQueryWindow
240 NSString *message = @"Would you like MenuTunes to launch\nautomatically at startup?";
242 [_window setImage:[NSImage imageNamed:@"Setup"]];
243 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
244 [_window buildDialogWindowWithMessage:message
245 defaultButton:@"Launch at Startup"
246 alternateButton:@"Launch Manually"
247 target:[PreferencesController sharedPrefs]
248 defaultAction:@selector(autoLaunchOK)
249 alternateAction:@selector(autoLaunchCancel)];
251 [_window appear:self];
252 [_window setLocked:YES];
256 - (void)showRegistrationQueryWindow
258 NSString *message = @"Your 7-day unlimited trial period has elapsed.\nYou must register to continue using MenuTunes.";
260 [_window setImage:[NSImage imageNamed:@"Register"]];
261 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
262 [_window buildDialogWindowWithMessage:message
263 defaultButton:@"Register Now"
264 alternateButton:@"Quit MenuTunes"
265 target:[MainController sharedController]
266 defaultAction:@selector(registerNowOK)
267 alternateAction:@selector(registerNowCancel)];
269 [_window appear:self];
270 [_window setLocked:YES];
273 - (void)showReconnectQueryWindow
275 NSString *message = @"The selected shared player is available again.\nWould you like to reconnect to it?.";
277 [_window setImage:[NSImage imageNamed:@"Register"]];
278 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
279 [_window buildDialogWindowWithMessage:message
280 defaultButton:@"Reconnect"
281 alternateButton:@"Ignore"
282 target:[MainController sharedController]
283 defaultAction:@selector(reconnect)
284 alternateAction:@selector(cancelReconnect)];
286 [_window appear:self];
287 [_window setLocked:YES];
290 - (void)showPreferencesUpdateWindow
292 NSString *message = @"The new features in this version of MenuTunes\nrequire you to reconfigure your preferences.";
294 [_window setImage:[NSImage imageNamed:@"Setup"]];
295 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
296 [_window buildDialogWindowWithMessage:message
297 defaultButton:@"Show Preferences"
298 alternateButton:@"OK"
299 target:[MainController sharedController]
300 defaultAction:@selector(showPreferencesAndClose)
301 alternateAction:@selector(cancelReconnect)];
303 [_window appear:self];
304 [_window setLocked:YES];