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] ) ) {
41 ITWindowEffect *entryEffect;
42 ITWindowEffect *exitEffect;
44 _window = [[StatusWindow sharedWindow] retain];
45 df = [[NSUserDefaults standardUserDefaults] retain];
47 exitDelay = [df floatForKey:@"statusWindowVanishDelay"];
48 entryTag = [df integerForKey:@"statusWindowAppearanceEffect"];
49 exitTag = [df integerForKey:@"statusWindowVanishEffect"];
50 entrySpeed = [df floatForKey:@"statusWindowAppearanceSpeed"];
51 exitSpeed = [df floatForKey:@"statusWindowVanishSpeed"];
53 [_window setExitMode:ITTransientStatusWindowExitAfterDelay];
54 [_window setExitDelay:(exitDelay ? exitDelay : 4.0)];
56 [_window setHorizontalPosition:[df integerForKey:@"statusWindowHorizontalPosition"]];
57 [_window setVerticalPosition:[df integerForKey:@"statusWindowVerticalPosition"]];
59 if ( entryTag == 2101 ) {
60 entryEffect = [[[ITDissolveWindowEffect alloc] initWithWindow:_window] autorelease];
61 } else if ( entryTag == 2102 ) {
62 entryEffect = [[[ITSlideVerticallyWindowEffect alloc] initWithWindow:_window] autorelease];
63 } else if ( entryTag == 2103 ) {
64 entryEffect = [[[ITSlideHorizontallyWindowEffect alloc] initWithWindow:_window] autorelease];
65 } else if ( entryTag == 2104 ) {
66 entryEffect = [[[ITPivotWindowEffect alloc] initWithWindow:_window] autorelease];
68 entryEffect = [[[ITCutWindowEffect alloc] initWithWindow:_window] autorelease];
71 [_window setEntryEffect:entryEffect];
73 if ( exitTag == 2100 ) {
74 exitEffect = [[[ITCutWindowEffect alloc] initWithWindow:_window] autorelease];
75 } else if ( exitTag == 2102 ) {
76 exitEffect = [[[ITSlideVerticallyWindowEffect alloc] initWithWindow:_window] autorelease];
77 } else if ( exitTag == 2103 ) {
78 exitEffect = [[[ITSlideHorizontallyWindowEffect alloc] initWithWindow:_window] autorelease];
79 } else if ( exitTag == 2104 ) {
80 exitEffect = [[[ITPivotWindowEffect alloc] initWithWindow:_window] autorelease];
82 exitEffect = [[[ITDissolveWindowEffect alloc] initWithWindow:_window] autorelease];
85 [_window setExitEffect:exitEffect];
87 [[_window entryEffect] setEffectTime:(entrySpeed ? entrySpeed : 0.8)];
88 [[_window exitEffect] setEffectTime:(exitSpeed ? exitSpeed : 0.8)];
90 [(ITTSWBackgroundView *)[_window contentView]setBackgroundMode:
91 (ITTSWBackgroundMode)[df integerForKey:@"statusWindowBackgroundMode"]];
93 [(ITTSWBackgroundView *)[_window contentView]setBackgroundColor:
94 (NSColor *)[NSUnarchiver unarchiveObjectWithData:[df dataForKey:@"statusWindowBackgroundColor"]]];
106 - (void)showSongInfoWindowWithSource:(ITMTRemotePlayerSource)source
107 title: (NSString *)title
108 album: (NSString *)album
109 artist: (NSString *)artist
110 time: (NSString *)time // FLOW: Should probably be NSDate or something.
111 track: (NSString *)track
114 NSImage *image = nil;
115 NSString *text = title;
117 if ( source == ITMTRemoteLibrarySource ) {
118 image = [NSImage imageNamed:@"Library"];
119 } else if ( source == ITMTRemoteCDSource ) {
120 image = [NSImage imageNamed:@"CD"];
121 } else if ( source == ITMTRemoteRadioSource ) {
122 image = [NSImage imageNamed:@"Radio"];
123 } else if ( source == ITMTRemoteiPodSource ) {
124 image = [NSImage imageNamed:@"iPod"];
125 } else if ( source == ITMTRemoteGenericDeviceSource ) {
126 image = [NSImage imageNamed:@"MP3Player"];
127 } else if ( source == ITMTRemoteSharedLibrarySource ) {
128 image = [NSImage imageNamed:@"Library"];
131 [_window setImage:image];
134 text = [text stringByAppendingString:[@"\n" stringByAppendingString:album]];
137 text = [text stringByAppendingString:[@"\n" stringByAppendingString:artist]];
140 text = [text stringByAppendingString:[@"\n" stringByAppendingString:time]];
143 text = [text stringByAppendingString:[@"\n" stringByAppendingString:track]];
147 NSString *ratingString = [NSString string];
148 NSString *emptyChar = [NSString stringWithUTF8String:"☆"];
149 NSString *fullChar = [NSString stringWithUTF8String:"★"];
152 for ( i = 1; i < 6; i++ ) {
155 ratingString = [ratingString stringByAppendingString:fullChar];
157 ratingString = [ratingString stringByAppendingString:emptyChar];
161 text = [text stringByAppendingString:[@"\n" stringByAppendingString:ratingString]];
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 buildTextWindowWithString:[bull stringByAppendingString:[titleStrings componentsJoinedByString:end]]];
175 [_window appear:self];
178 - (void)showVolumeWindowWithLevel:(float)level
180 [_window setImage:[NSImage imageNamed:@"Volume"]];
181 [_window buildMeterWindowWithCharacter:[NSString stringWithUTF8String:"▊"]
184 active:( ceil(level * 100) / 10 )];
185 [_window appear:self];
188 - (void)showRatingWindowWithRating:(float)rating
190 [_window setImage:[NSImage imageNamed:@"Rating"]];
191 [_window buildMeterWindowWithCharacter:[NSString stringWithUTF8String:"★"]
194 active:( ceil(rating * 100) / 20 )];
195 [_window appear:self];
198 - (void)showShuffleWindow:(BOOL)shuffle
200 [_window setImage:[NSImage imageNamed:@"Shuffle"]];
201 [_window buildTextWindowWithString:( shuffle ? @"Shuffle On" : @"Shuffle Off")];
202 [_window appear:self];
205 - (void)showRepeatWindowWithMode:(StatusWindowRepeatMode)mode
207 NSString *string = nil;
209 if ( mode == StatusWindowRepeatNone ) {
210 string = @"Repeat Off";
211 } else if ( mode == StatusWindowRepeatGroup ) {
212 string = @"Repeat Playlist";
213 } else if ( mode == StatusWindowRepeatTrack ) {
214 string = @"Repeat One Track";
217 [_window setImage:[NSImage imageNamed:@"Repeat"]];
218 [_window buildTextWindowWithString:string];
219 [_window appear:self];
222 - (void)showSetupQueryWindow
224 NSString *message = @"Would you like MenuTunes to launch\nautomatically at startup?";
226 [_window setImage:[NSImage imageNamed:@"Setup"]];
227 [_window buildDialogWindowWithMessage:message
228 defaultButton:@"Launch at Startup"
229 alternateButton:@"Launch Manually"
230 target:[PreferencesController sharedPrefs]
231 defaultAction:@selector(autoLaunchOK)
232 alternateAction:@selector(autoLaunchCancel)];
234 [_window appear:self];
235 [_window setLocked:YES];
239 - (void)showRegistrationQueryWindow
241 NSString *message = @"Your 7-day unlimited trial period has elapsed.\nYou must register to continue using MenuTunes.";
243 [_window setImage:[NSImage imageNamed:@"Register"]];
244 [_window buildDialogWindowWithMessage:message
245 defaultButton:@"Register Now"
246 alternateButton:@"Quit MenuTunes"
247 target:[MainController sharedController]
248 defaultAction:@selector(registerNowOK)
249 alternateAction:@selector(registerNowCancel)];
251 [_window appear:self];
252 [_window setLocked:YES];
255 - (void)showReconnectQueryWindow
257 NSString *message = @"The selected shared player is available again.\nWould you like to reconnect to it?.";
259 [_window setImage:[NSImage imageNamed:@"Register"]];
260 [_window buildDialogWindowWithMessage:message
261 defaultButton:@"Reconnect"
262 alternateButton:@"Ignore"
263 target:[MainController sharedController]
264 defaultAction:@selector(reconnect)
265 alternateAction:@selector(cancelReconnect)];
267 [_window appear:self];
268 [_window setLocked:YES];