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 [image setScalesWhenResized:YES];
119 [image setSize:NSMakeSize(110, 110)];
120 /*if (size.width > 110 && size.width > size.height) {
121 [image setSize:NSMakeSize(110, (size.width / size.height) * 110)];
122 } else if (size.height > 110 && size.height > size.width) {
123 [image setSize:NSMakeSize((size.height / size.width) * 110, 110)];
125 } else if ( source == ITMTRemoteLibrarySource ) {
126 image = [NSImage imageNamed:@"Library"];
127 } else if ( source == ITMTRemoteCDSource ) {
128 image = [NSImage imageNamed:@"CD"];
129 } else if ( source == ITMTRemoteRadioSource ) {
130 image = [NSImage imageNamed:@"Radio"];
131 } else if ( source == ITMTRemoteiPodSource ) {
132 image = [NSImage imageNamed:@"iPod"];
133 } else if ( source == ITMTRemoteGenericDeviceSource ) {
134 image = [NSImage imageNamed:@"MP3Player"];
135 } else if ( source == ITMTRemoteSharedLibrarySource ) {
136 image = [NSImage imageNamed:@"Library"];
139 [_window setImage:image];
142 text = [text stringByAppendingString:[@"\n" stringByAppendingString:album]];
145 text = [text stringByAppendingString:[@"\n" stringByAppendingString:artist]];
148 text = [text stringByAppendingString:[@"\n" stringByAppendingString:time]];
151 text = [text stringByAppendingString:[@"\n" stringByAppendingString:track]];
155 NSString *ratingString = [NSString string];
156 NSString *emptyChar = [NSString stringWithUTF8String:"☆"];
157 NSString *fullChar = [NSString stringWithUTF8String:"★"];
160 for ( i = 1; i < 6; i++ ) {
163 ratingString = [ratingString stringByAppendingString:fullChar];
165 ratingString = [ratingString stringByAppendingString:emptyChar];
169 text = [text stringByAppendingString:[@"\n" stringByAppendingString:ratingString]];
173 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
174 [_window buildTextWindowWithString:text];
175 [_window appear:self];
178 - (void)showUpcomingSongsWindowWithTitles:(NSArray *)titleStrings
180 // NSString *bull = [NSString stringWithUTF8String:"‣ "];
181 NSString *bull = [NSString stringWithUTF8String:"♪ "];
182 NSString *end = [@"\n" stringByAppendingString:bull];
183 [_window setImage:[NSImage imageNamed:@"Upcoming"]];
184 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
185 [_window buildTextWindowWithString:[bull stringByAppendingString:[titleStrings componentsJoinedByString:end]]];
186 [_window appear:self];
189 - (void)showVolumeWindowWithLevel:(float)level
191 [_window setImage:[NSImage imageNamed:@"Volume"]];
192 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
193 [_window buildMeterWindowWithCharacter:[NSString stringWithUTF8String:"▊"]
196 active:( ceil(level * 100) / 10 )];
197 [_window appear:self];
200 - (void)showRatingWindowWithRating:(float)rating
202 [_window setImage:[NSImage imageNamed:@"Rating"]];
203 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
204 [_window buildMeterWindowWithCharacter:[NSString stringWithUTF8String:"★"]
207 active:( ceil(rating * 100) / 20 )];
208 [_window appear:self];
211 - (void)showShuffleWindow:(BOOL)shuffle
213 [_window setImage:[NSImage imageNamed:@"Shuffle"]];
214 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
215 [_window buildTextWindowWithString:( shuffle ? @"Shuffle On" : @"Shuffle Off")];
216 [_window appear:self];
219 - (void)showRepeatWindowWithMode:(StatusWindowRepeatMode)mode
221 NSString *string = nil;
223 if ( mode == StatusWindowRepeatNone ) {
224 string = @"Repeat Off";
225 } else if ( mode == StatusWindowRepeatGroup ) {
226 string = @"Repeat Playlist";
227 } else if ( mode == StatusWindowRepeatTrack ) {
228 string = @"Repeat One Track";
231 [_window setImage:[NSImage imageNamed:@"Repeat"]];
232 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
233 [_window buildTextWindowWithString:string];
234 [_window appear:self];
237 - (void)showSetupQueryWindow
239 NSString *message = @"Would you like MenuTunes to launch\nautomatically at startup?";
241 [_window setImage:[NSImage imageNamed:@"Setup"]];
242 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
243 [_window buildDialogWindowWithMessage:message
244 defaultButton:@"Launch at Startup"
245 alternateButton:@"Launch Manually"
246 target:[PreferencesController sharedPrefs]
247 defaultAction:@selector(autoLaunchOK)
248 alternateAction:@selector(autoLaunchCancel)];
250 [_window appear:self];
251 [_window setLocked:YES];
255 - (void)showRegistrationQueryWindow
257 NSString *message = @"Your 7-day unlimited trial period has elapsed.\nYou must register to continue using MenuTunes.";
259 [_window setImage:[NSImage imageNamed:@"Register"]];
260 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
261 [_window buildDialogWindowWithMessage:message
262 defaultButton:@"Register Now"
263 alternateButton:@"Quit MenuTunes"
264 target:[MainController sharedController]
265 defaultAction:@selector(registerNowOK)
266 alternateAction:@selector(registerNowCancel)];
268 [_window appear:self];
269 [_window setLocked:YES];
272 - (void)showReconnectQueryWindow
274 NSString *message = @"The selected shared player is available again.\nWould you like to reconnect to it?.";
276 [_window setImage:[NSImage imageNamed:@"Register"]];
277 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
278 [_window buildDialogWindowWithMessage:message
279 defaultButton:@"Reconnect"
280 alternateButton:@"Ignore"
281 target:[MainController sharedController]
282 defaultAction:@selector(reconnect)
283 alternateAction:@selector(cancelReconnect)];
285 [_window appear:self];
286 [_window setLocked:YES];
289 - (void)showPreferencesUpdateWindow
291 NSString *message = @"The new features in this version of MenuTunes\nrequire you to reconfigure your preferences.";
293 [_window setImage:[NSImage imageNamed:@"Setup"]];
294 [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
295 [_window buildDialogWindowWithMessage:message
296 defaultButton:@"Show Preferences"
297 alternateButton:@"OK"
298 target:[MainController sharedController]
299 defaultAction:@selector(showPreferencesAndClose)
300 alternateAction:@selector(cancelReconnect)];
302 [_window appear:self];
303 [_window setLocked:YES];