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;
117 NSSize oldSize, newSize;
119 [image setScalesWhenResized:YES];
120 oldSize = [image size];
121 if (oldSize.width > oldSize.height) newSize = NSMakeSize(110,oldSize.height * (110.0f / oldSize.width));
122 else newSize = NSMakeSize(oldSize.width * (110.0f / oldSize.height),110);
123 [image setSize:newSize];
124 } else if ( source == ITMTRemoteLibrarySource ) {
125 image = [NSImage imageNamed:@"Library"];
126 } else if ( source == ITMTRemoteCDSource ) {
127 image = [NSImage imageNamed:@"CD"];
128 } else if ( source == ITMTRemoteRadioSource ) {
129 image = [NSImage imageNamed:@"Radio"];
130 } else if ( source == ITMTRemoteiPodSource ) {
131 image = [NSImage imageNamed:@"iPod"];
132 } else if ( source == ITMTRemoteGenericDeviceSource ) {
133 image = [NSImage imageNamed:@"MP3Player"];
134 } else if ( source == ITMTRemoteSharedLibrarySource ) {
135 image = [NSImage imageNamed:@"Library"];
138 [_window setImage:image];
141 text = [text stringByAppendingString:[@"\n" stringByAppendingString:album]];
144 text = [text stringByAppendingString:[@"\n" stringByAppendingString:artist]];
147 text = [text stringByAppendingString:[@"\n" stringByAppendingString:time]];
150 text = [text stringByAppendingString:[@"\n" stringByAppendingString:track]];
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]];
172 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
173 [_window buildTextWindowWithString:text];
174 [_window appear:self];
177 - (void)showUpcomingSongsWindowWithTitles:(NSArray *)titleStrings
179 // NSString *bull = [NSString stringWithUTF8String:"‣ "];
180 NSString *bull = [NSString stringWithUTF8String:"♪ "];
181 NSString *end = [@"\n" stringByAppendingString:bull];
182 [_window setImage:[NSImage imageNamed:@"Upcoming"]];
183 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
184 [_window buildTextWindowWithString:[bull stringByAppendingString:[titleStrings componentsJoinedByString:end]]];
185 [_window appear:self];
188 - (void)showVolumeWindowWithLevel:(float)level
190 [_window setImage:[NSImage imageNamed:@"Volume"]];
191 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
192 [_window buildMeterWindowWithCharacter:[NSString stringWithUTF8String:"▊"]
195 active:( ceil(level * 100) / 10 )];
196 [_window appear:self];
199 - (void)showRatingWindowWithRating:(float)rating
201 [_window setImage:[NSImage imageNamed:@"Rating"]];
202 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
203 [_window buildMeterWindowWithCharacter:[NSString stringWithUTF8String:"★"]
206 active:( ceil(rating * 100) / 20 )];
207 [_window appear:self];
210 - (void)showShuffleWindow:(BOOL)shuffle
212 [_window setImage:[NSImage imageNamed:@"Shuffle"]];
213 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
214 [_window buildTextWindowWithString:( shuffle ? @"Shuffle On" : @"Shuffle Off")];
215 [_window appear:self];
218 - (void)showRepeatWindowWithMode:(StatusWindowRepeatMode)mode
220 NSString *string = nil;
222 if ( mode == StatusWindowRepeatNone ) {
223 string = @"Repeat Off";
224 } else if ( mode == StatusWindowRepeatGroup ) {
225 string = @"Repeat Playlist";
226 } else if ( mode == StatusWindowRepeatTrack ) {
227 string = @"Repeat One Track";
230 [_window setImage:[NSImage imageNamed:@"Repeat"]];
231 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
232 [_window buildTextWindowWithString:string];
233 [_window appear:self];
236 - (void)showSetupQueryWindow
238 NSString *message = @"Would you like MenuTunes to launch\nautomatically at startup?";
240 [_window setImage:[NSImage imageNamed:@"Setup"]];
241 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
242 [_window buildDialogWindowWithMessage:message
243 defaultButton:@"Launch at Startup"
244 alternateButton:@"Launch Manually"
245 target:[PreferencesController sharedPrefs]
246 defaultAction:@selector(autoLaunchOK)
247 alternateAction:@selector(autoLaunchCancel)];
249 [_window appear:self];
250 [_window setLocked:YES];
254 - (void)showRegistrationQueryWindow
256 NSString *message = @"Your 7-day unlimited trial period has elapsed.\nYou must register to continue using MenuTunes.";
258 [_window setImage:[NSImage imageNamed:@"Register"]];
259 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
260 [_window buildDialogWindowWithMessage:message
261 defaultButton:@"Register Now"
262 alternateButton:@"Quit MenuTunes"
263 target:[MainController sharedController]
264 defaultAction:@selector(registerNowOK)
265 alternateAction:@selector(registerNowCancel)];
267 [_window appear:self];
268 [_window setLocked:YES];
271 - (void)showReconnectQueryWindow
273 NSString *message = @"The selected shared player is available again.\nWould you like to reconnect to it?.";
275 [_window setImage:[NSImage imageNamed:@"Setup"]];
276 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
277 [_window buildDialogWindowWithMessage:message
278 defaultButton:@"Reconnect"
279 alternateButton:@"Ignore"
280 target:[MainController sharedController]
281 defaultAction:@selector(reconnect)
282 alternateAction:@selector(cancelReconnect)];
284 [_window appear:self];
285 [_window setLocked:YES];
288 - (void)showPreferencesUpdateWindow
290 NSString *message = @"The new features in this version of MenuTunes\nrequire you to reconfigure your preferences.";
292 [_window setImage:[NSImage imageNamed:@"Setup"]];
293 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
294 [_window buildDialogWindowWithMessage:message
295 defaultButton:@"Show Preferences"
296 alternateButton:@"OK"
297 target:[MainController sharedController]
298 defaultAction:@selector(showPreferencesAndClose)
299 alternateAction:@selector(cancelReconnect)];
301 [_window appear:self];
302 [_window setLocked:YES];