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] ) ) {
43 ITWindowEffect *entryEffect;
44 ITWindowEffect *exitEffect;
46 _window = [[StatusWindow sharedWindow] retain];
47 df = [[NSUserDefaults standardUserDefaults] retain];
49 exitDelay = [df floatForKey:@"statusWindowVanishDelay"];
50 entryTag = [df integerForKey:@"statusWindowAppearanceEffect"];
51 exitTag = [df integerForKey:@"statusWindowVanishEffect"];
52 entrySpeed = [df floatForKey:@"statusWindowAppearanceSpeed"];
53 exitSpeed = [df floatForKey:@"statusWindowVanishSpeed"];
55 [_window setExitMode:ITTransientStatusWindowExitAfterDelay];
56 [_window setExitDelay:(exitDelay ? exitDelay : 4.0)];
58 [_window setHorizontalPosition:[df integerForKey:@"statusWindowHorizontalPosition"]];
59 [_window setVerticalPosition:[df integerForKey:@"statusWindowVerticalPosition"]];
61 [_window setSizing:(StatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
63 if ( entryTag == 2101 ) {
64 entryEffect = [[[ITDissolveWindowEffect alloc] initWithWindow:_window] autorelease];
65 } else if ( entryTag == 2102 ) {
66 entryEffect = [[[ITSlideVerticallyWindowEffect alloc] initWithWindow:_window] autorelease];
67 } else if ( entryTag == 2103 ) {
68 entryEffect = [[[ITSlideHorizontallyWindowEffect alloc] initWithWindow:_window] autorelease];
69 } else if ( entryTag == 2104 ) {
70 entryEffect = [[[ITPivotWindowEffect alloc] initWithWindow:_window] autorelease];
72 entryEffect = [[[ITCutWindowEffect alloc] initWithWindow:_window] autorelease];
75 [_window setEntryEffect:entryEffect];
77 if ( exitTag == 2100 ) {
78 exitEffect = [[[ITCutWindowEffect alloc] initWithWindow:_window] autorelease];
79 } else if ( exitTag == 2102 ) {
80 exitEffect = [[[ITSlideVerticallyWindowEffect alloc] initWithWindow:_window] autorelease];
81 } else if ( exitTag == 2103 ) {
82 exitEffect = [[[ITSlideHorizontallyWindowEffect alloc] initWithWindow:_window] autorelease];
83 } else if ( exitTag == 2104 ) {
84 exitEffect = [[[ITPivotWindowEffect alloc] initWithWindow:_window] autorelease];
86 exitEffect = [[[ITDissolveWindowEffect alloc] initWithWindow:_window] autorelease];
89 [_window setExitEffect:exitEffect];
91 [[_window entryEffect] setEffectTime:(entrySpeed ? entrySpeed : 0.8)];
92 [[_window exitEffect] setEffectTime:(exitSpeed ? exitSpeed : 0.8)];
94 [(ITTSWBackgroundView *)[_window contentView]setBackgroundMode:
95 (ITTSWBackgroundMode)[df integerForKey:@"statusWindowBackgroundMode"]];
97 colorData = [df dataForKey:@"statusWindowBackgroundColor"];
100 [(ITTSWBackgroundView *)[_window contentView] setBackgroundColor:
101 (NSColor *)[NSUnarchiver unarchiveObjectWithData:colorData]];
103 [(ITTSWBackgroundView *)[_window contentView] setBackgroundColor:[NSColor blueColor]];
116 - (void)showSongInfoWindowWithSource:(ITMTRemotePlayerSource)source
117 title: (NSString *)title
118 album: (NSString *)album
119 artist: (NSString *)artist
120 time: (NSString *)time // FLOW: Should probably be NSDate or something.
121 track: (NSString *)track
124 NSImage *image = nil;
125 NSString *text = title;
127 if ( source == ITMTRemoteLibrarySource ) {
128 image = [NSImage imageNamed:@"Library"];
129 } else if ( source == ITMTRemoteCDSource ) {
130 image = [NSImage imageNamed:@"CD"];
131 } else if ( source == ITMTRemoteRadioSource ) {
132 image = [NSImage imageNamed:@"Radio"];
133 } else if ( source == ITMTRemoteiPodSource ) {
134 image = [NSImage imageNamed:@"iPod"];
135 } else if ( source == ITMTRemoteGenericDeviceSource ) {
136 image = [NSImage imageNamed:@"MP3Player"];
137 } else if ( source == ITMTRemoteSharedLibrarySource ) {
138 image = [NSImage imageNamed:@"Library"];
141 [_window setImage:image];
144 text = [text stringByAppendingString:[@"\n" stringByAppendingString:album]];
147 text = [text stringByAppendingString:[@"\n" stringByAppendingString:artist]];
150 text = [text stringByAppendingString:[@"\n" stringByAppendingString:time]];
153 text = [text stringByAppendingString:[@"\n" stringByAppendingString:track]];
157 NSString *ratingString = [NSString string];
158 NSString *emptyChar = [NSString stringWithUTF8String:"☆"];
159 NSString *fullChar = [NSString stringWithUTF8String:"★"];
162 for ( i = 1; i < 6; i++ ) {
165 ratingString = [ratingString stringByAppendingString:fullChar];
167 ratingString = [ratingString stringByAppendingString:emptyChar];
171 text = [text stringByAppendingString:[@"\n" stringByAppendingString:ratingString]];
175 [_window setSizing:(StatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
176 [_window buildTextWindowWithString:text];
177 [_window appear:self];
180 - (void)showUpcomingSongsWindowWithTitles:(NSArray *)titleStrings
182 // NSString *bull = [NSString stringWithUTF8String:"‣ "];
183 NSString *bull = [NSString stringWithUTF8String:"♪ "];
184 NSString *end = [@"\n" stringByAppendingString:bull];
185 [_window setImage:[NSImage imageNamed:@"Upcoming"]];
186 [_window setSizing:(StatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
187 [_window buildTextWindowWithString:[bull stringByAppendingString:[titleStrings componentsJoinedByString:end]]];
188 [_window appear:self];
191 - (void)showVolumeWindowWithLevel:(float)level
193 [_window setImage:[NSImage imageNamed:@"Volume"]];
194 [_window setSizing:(StatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
195 [_window buildMeterWindowWithCharacter:[NSString stringWithUTF8String:"▊"]
198 active:( ceil(level * 100) / 10 )];
199 [_window appear:self];
202 - (void)showRatingWindowWithRating:(float)rating
204 [_window setImage:[NSImage imageNamed:@"Rating"]];
205 [_window setSizing:(StatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
206 [_window buildMeterWindowWithCharacter:[NSString stringWithUTF8String:"★"]
209 active:( ceil(rating * 100) / 20 )];
210 [_window appear:self];
213 - (void)showShuffleWindow:(BOOL)shuffle
215 [_window setImage:[NSImage imageNamed:@"Shuffle"]];
216 [_window setSizing:(StatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
217 [_window buildTextWindowWithString:( shuffle ? @"Shuffle On" : @"Shuffle Off")];
218 [_window appear:self];
221 - (void)showRepeatWindowWithMode:(StatusWindowRepeatMode)mode
223 NSString *string = nil;
225 if ( mode == StatusWindowRepeatNone ) {
226 string = @"Repeat Off";
227 } else if ( mode == StatusWindowRepeatGroup ) {
228 string = @"Repeat Playlist";
229 } else if ( mode == StatusWindowRepeatTrack ) {
230 string = @"Repeat One Track";
233 [_window setImage:[NSImage imageNamed:@"Repeat"]];
234 [_window setSizing:(StatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
235 [_window buildTextWindowWithString:string];
236 [_window appear:self];
239 - (void)showSetupQueryWindow
241 NSString *message = @"Would you like MenuTunes to launch\nautomatically at startup?";
243 [_window setImage:[NSImage imageNamed:@"Setup"]];
244 [_window setSizing:(StatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
245 [_window buildDialogWindowWithMessage:message
246 defaultButton:@"Launch at Startup"
247 alternateButton:@"Launch Manually"
248 target:[PreferencesController sharedPrefs]
249 defaultAction:@selector(autoLaunchOK)
250 alternateAction:@selector(autoLaunchCancel)];
252 [_window appear:self];
253 [_window setLocked:YES];
257 - (void)showRegistrationQueryWindow
259 NSString *message = @"Your 7-day unlimited trial period has elapsed.\nYou must register to continue using MenuTunes.";
261 [_window setImage:[NSImage imageNamed:@"Register"]];
262 [_window setSizing:(StatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
263 [_window buildDialogWindowWithMessage:message
264 defaultButton:@"Register Now"
265 alternateButton:@"Quit MenuTunes"
266 target:[MainController sharedController]
267 defaultAction:@selector(registerNowOK)
268 alternateAction:@selector(registerNowCancel)];
270 [_window appear:self];
271 [_window setLocked:YES];
274 - (void)showReconnectQueryWindow
276 NSString *message = @"The selected shared player is available again.\nWould you like to reconnect to it?.";
278 [_window setImage:[NSImage imageNamed:@"Register"]];
279 [_window setSizing:(StatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
280 [_window buildDialogWindowWithMessage:message
281 defaultButton:@"Reconnect"
282 alternateButton:@"Ignore"
283 target:[MainController sharedController]
284 defaultAction:@selector(reconnect)
285 alternateAction:@selector(cancelReconnect)];
287 [_window appear:self];
288 [_window setLocked:YES];