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:(StatusWindowSizing)[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
112 NSImage *image = nil;
113 NSString *text = title;
115 if ( source == ITMTRemoteLibrarySource ) {
116 image = [NSImage imageNamed:@"Library"];
117 } else if ( source == ITMTRemoteCDSource ) {
118 image = [NSImage imageNamed:@"CD"];
119 } else if ( source == ITMTRemoteRadioSource ) {
120 image = [NSImage imageNamed:@"Radio"];
121 } else if ( source == ITMTRemoteiPodSource ) {
122 image = [NSImage imageNamed:@"iPod"];
123 } else if ( source == ITMTRemoteGenericDeviceSource ) {
124 image = [NSImage imageNamed:@"MP3Player"];
125 } else if ( source == ITMTRemoteSharedLibrarySource ) {
126 image = [NSImage imageNamed:@"Library"];
129 [_window setImage:image];
132 text = [text stringByAppendingString:[@"\n" stringByAppendingString:album]];
135 text = [text stringByAppendingString:[@"\n" stringByAppendingString:artist]];
138 text = [text stringByAppendingString:[@"\n" stringByAppendingString:time]];
141 text = [text stringByAppendingString:[@"\n" stringByAppendingString:track]];
145 NSString *ratingString = [NSString string];
146 NSString *emptyChar = [NSString stringWithUTF8String:"☆"];
147 NSString *fullChar = [NSString stringWithUTF8String:"★"];
150 for ( i = 1; i < 6; i++ ) {
153 ratingString = [ratingString stringByAppendingString:fullChar];
155 ratingString = [ratingString stringByAppendingString:emptyChar];
159 text = [text stringByAppendingString:[@"\n" stringByAppendingString:ratingString]];
163 [_window setSizing:(StatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
164 [_window buildTextWindowWithString:text];
165 [_window appear:self];
168 - (void)showUpcomingSongsWindowWithTitles:(NSArray *)titleStrings
170 // NSString *bull = [NSString stringWithUTF8String:"‣ "];
171 NSString *bull = [NSString stringWithUTF8String:"♪ "];
172 NSString *end = [@"\n" stringByAppendingString:bull];
173 [_window setImage:[NSImage imageNamed:@"Upcoming"]];
174 [_window setSizing:(StatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
175 [_window buildTextWindowWithString:[bull stringByAppendingString:[titleStrings componentsJoinedByString:end]]];
176 [_window appear:self];
179 - (void)showVolumeWindowWithLevel:(float)level
181 [_window setImage:[NSImage imageNamed:@"Volume"]];
182 [_window setSizing:(StatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
183 [_window buildMeterWindowWithCharacter:[NSString stringWithUTF8String:"▊"]
186 active:( ceil(level * 100) / 10 )];
187 [_window appear:self];
190 - (void)showRatingWindowWithRating:(float)rating
192 [_window setImage:[NSImage imageNamed:@"Rating"]];
193 [_window setSizing:(StatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
194 [_window buildMeterWindowWithCharacter:[NSString stringWithUTF8String:"★"]
197 active:( ceil(rating * 100) / 20 )];
198 [_window appear:self];
201 - (void)showShuffleWindow:(BOOL)shuffle
203 [_window setImage:[NSImage imageNamed:@"Shuffle"]];
204 [_window setSizing:(StatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
205 [_window buildTextWindowWithString:( shuffle ? @"Shuffle On" : @"Shuffle Off")];
206 [_window appear:self];
209 - (void)showRepeatWindowWithMode:(StatusWindowRepeatMode)mode
211 NSString *string = nil;
213 if ( mode == StatusWindowRepeatNone ) {
214 string = @"Repeat Off";
215 } else if ( mode == StatusWindowRepeatGroup ) {
216 string = @"Repeat Playlist";
217 } else if ( mode == StatusWindowRepeatTrack ) {
218 string = @"Repeat One Track";
221 [_window setImage:[NSImage imageNamed:@"Repeat"]];
222 [_window setSizing:(StatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
223 [_window buildTextWindowWithString:string];
224 [_window appear:self];
227 - (void)showSetupQueryWindow
229 NSString *message = @"Would you like MenuTunes to launch\nautomatically at startup?";
231 [_window setImage:[NSImage imageNamed:@"Setup"]];
232 [_window setSizing:(StatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
233 [_window buildDialogWindowWithMessage:message
234 defaultButton:@"Launch at Startup"
235 alternateButton:@"Launch Manually"
236 target:[PreferencesController sharedPrefs]
237 defaultAction:@selector(autoLaunchOK)
238 alternateAction:@selector(autoLaunchCancel)];
240 [_window appear:self];
241 [_window setLocked:YES];
245 - (void)showRegistrationQueryWindow
247 NSString *message = @"Your 7-day unlimited trial period has elapsed.\nYou must register to continue using MenuTunes.";
249 [_window setImage:[NSImage imageNamed:@"Register"]];
250 [_window setSizing:(StatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
251 [_window buildDialogWindowWithMessage:message
252 defaultButton:@"Register Now"
253 alternateButton:@"Quit MenuTunes"
254 target:[MainController sharedController]
255 defaultAction:@selector(registerNowOK)
256 alternateAction:@selector(registerNowCancel)];
258 [_window appear:self];
259 [_window setLocked:YES];
262 - (void)showReconnectQueryWindow
264 NSString *message = @"The selected shared player is available again.\nWould you like to reconnect to it?.";
266 [_window setImage:[NSImage imageNamed:@"Register"]];
267 [_window setSizing:(StatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
268 [_window buildDialogWindowWithMessage:message
269 defaultButton:@"Reconnect"
270 alternateButton:@"Ignore"
271 target:[MainController sharedController]
272 defaultAction:@selector(reconnect)
273 alternateAction:@selector(cancelReconnect)];
275 [_window appear:self];
276 [_window setLocked:YES];
279 - (void)showPreferencesUpdateWindow
281 NSString *message = @"The new features in this version of MenuTunes\nrequire you to reconfigure your preferences.";
283 [_window setImage:[NSImage imageNamed:@"Setup"]];
284 [_window setSizing:(StatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
285 [_window buildDialogWindowWithMessage:message
286 defaultButton:@"Show Preferences"
287 alternateButton:@"OK"
288 target:[MainController sharedController]
289 defaultAction:@selector(showPreferencesAndClose)
290 alternateAction:@selector(cancelReconnect)];
292 [_window appear:self];
293 [_window setLocked:YES];