1 #import "StatusWindowController.h"
2 #import "StatusWindow.h"
3 #import "PreferencesController.h"
4 #import "MainController.h"
6 #import <ITKit/ITWindowEffect.h>
7 #import <ITKit/ITCutWindowEffect.h>
8 #import <ITKit/ITDissolveWindowEffect.h>
9 #import <ITKit/ITSlideHorizontallyWindowEffect.h>
10 #import <ITKit/ITSlideVerticallyWindowEffect.h>
11 #import <ITKit/ITPivotWindowEffect.h>
14 static StatusWindowController *sharedController;
17 @implementation StatusWindowController
20 + (StatusWindowController *)sharedController
22 if ( ! sharedController ) {
23 sharedController = [[StatusWindowController alloc] init];
26 return sharedController;
32 if ( ( self = [super init] ) ) {
40 ITWindowEffect *entryEffect;
41 ITWindowEffect *exitEffect;
43 _window = [[StatusWindow sharedWindow] retain];
44 df = [[NSUserDefaults standardUserDefaults] retain];
46 exitDelay = [df floatForKey:@"statusWindowVanishDelay"];
47 entryTag = [df integerForKey:@"statusWindowAppearanceEffect"];
48 exitTag = [df integerForKey:@"statusWindowVanishEffect"];
49 entrySpeed = [df floatForKey:@"statusWindowAppearanceSpeed"];
50 exitSpeed = [df floatForKey:@"statusWindowVanishSpeed"];
52 [_window setExitMode:ITTransientStatusWindowExitAfterDelay];
53 [_window setExitDelay:(exitDelay ? exitDelay : 4.0)];
55 if ( entryTag == 2101 ) {
56 entryEffect = [[[ITDissolveWindowEffect alloc] initWithWindow:_window] autorelease];
57 } else if ( entryTag == 2102 ) {
58 entryEffect = [[[ITSlideVerticallyWindowEffect alloc] initWithWindow:_window] autorelease];
59 } else if ( entryTag == 2103 ) {
60 entryEffect = [[[ITSlideHorizontallyWindowEffect alloc] initWithWindow:_window] autorelease];
61 } else if ( entryTag == 2104 ) {
62 entryEffect = [[[ITPivotWindowEffect alloc] initWithWindow:_window] autorelease];
64 entryEffect = [[[ITCutWindowEffect alloc] initWithWindow:_window] autorelease];
67 [_window setEntryEffect:entryEffect];
69 if ( exitTag == 2100 ) {
70 exitEffect = [[[ITCutWindowEffect alloc] initWithWindow:_window] autorelease];
71 } else if ( exitTag == 2102 ) {
72 exitEffect = [[[ITSlideVerticallyWindowEffect alloc] initWithWindow:_window] autorelease];
73 } else if ( exitTag == 2103 ) {
74 exitEffect = [[[ITSlideHorizontallyWindowEffect alloc] initWithWindow:_window] autorelease];
75 } else if ( exitTag == 2104 ) {
76 exitEffect = [[[ITPivotWindowEffect alloc] initWithWindow:_window] autorelease];
78 exitEffect = [[[ITDissolveWindowEffect alloc] initWithWindow:_window] autorelease];
81 [_window setExitEffect:exitEffect];
83 [[_window entryEffect] setEffectTime:(entrySpeed ? entrySpeed : 0.8)];
84 [[_window exitEffect] setEffectTime:(exitSpeed ? exitSpeed : 0.8)];
98 ITHorizontalWindowPosition horizontalPosition = [[NSUserDefaults standardUserDefaults] integerForKey:@"statusWindowHorizontalPosition"];
99 ITVerticalWindowPosition verticalPosition = [[NSUserDefaults standardUserDefaults] integerForKey:@"statusWindowVerticalPosition"];
100 [_window setHorizontalPosition:horizontalPosition];
101 [_window setVerticalPosition:verticalPosition];
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]];
162 [_window buildTextWindowWithString:text];
163 [_window appear:self];
166 - (void)showUpcomingSongsWindowWithTitles:(NSArray *)titleStrings
168 // NSString *bull = [NSString stringWithUTF8String:"‣ "];
169 NSString *bull = [NSString stringWithUTF8String:"♪ "];
170 NSString *end = [@"\n" stringByAppendingString:bull];
171 [_window setImage:[NSImage imageNamed:@"Upcoming"]];
172 [_window buildTextWindowWithString:[bull stringByAppendingString:[titleStrings componentsJoinedByString:end]]];
173 [_window appear:self];
176 - (void)showVolumeWindowWithLevel:(float)level
178 [_window setImage:[NSImage imageNamed:@"Volume"]];
179 [_window buildMeterWindowWithCharacter:[NSString stringWithUTF8String:"▊"]
182 active:( ceil(level * 100) / 10 )];
183 [_window appear:self];
186 - (void)showRatingWindowWithRating:(float)rating
188 [_window setImage:[NSImage imageNamed:@"Rating"]];
189 [_window buildMeterWindowWithCharacter:[NSString stringWithUTF8String:"★"]
192 active:( ceil(rating * 100) / 20 )];
193 [_window appear:self];
196 - (void)showShuffleWindow:(BOOL)shuffle
198 [_window setImage:[NSImage imageNamed:@"Shuffle"]];
199 [_window buildTextWindowWithString:( shuffle ? @"Shuffle On" : @"Shuffle Off")];
200 [_window appear:self];
203 - (void)showRepeatWindowWithMode:(StatusWindowRepeatMode)mode
205 NSString *string = nil;
207 if ( mode == StatusWindowRepeatNone ) {
208 string = @"Repeat Off";
209 } else if ( mode == StatusWindowRepeatGroup ) {
210 string = @"Repeat Playlist";
211 } else if ( mode == StatusWindowRepeatTrack ) {
212 string = @"Repeat One Track";
215 [_window setImage:[NSImage imageNamed:@"Repeat"]];
216 [_window buildTextWindowWithString:string];
217 [_window appear:self];
220 - (void)showSetupQueryWindow
222 NSString *message = @"Would you like MenuTunes to launch\nautomatically at startup?";
224 [_window setImage:[NSImage imageNamed:@"Setup"]];
225 [_window buildDialogWindowWithMessage:message
226 defaultButton:@"Launch at Startup"
227 alternateButton:@"Launch Manually"
228 target:[PreferencesController sharedPrefs]
229 defaultAction:@selector(autoLaunchOK)
230 alternateAction:@selector(autoLaunchCancel)];
232 [_window appear:self];
233 [_window setLocked:YES];
237 - (void)showRegistrationQueryWindow
239 NSString *message = @"Your 7-day unlimited trial period has elapsed.\nYou must register to continue using MenuTunes.";
241 [_window setImage:[NSImage imageNamed:@"Register"]];
242 [_window buildDialogWindowWithMessage:message
243 defaultButton:@"Register Now"
244 alternateButton:@"Quit MenuTunes"
245 target:[MainController sharedController]
246 defaultAction:@selector(registerNowOK)
247 alternateAction:@selector(registerNowCancel)];
249 [_window appear:self];
250 [_window setLocked:YES];
253 - (void)showReconnectQueryWindow
255 NSString *message = @"The selected shared player is available again.\nWould you like to reconnect to it?.";
257 [_window setImage:[NSImage imageNamed:@"Register"]];
258 [_window buildDialogWindowWithMessage:message
259 defaultButton:@"Reconnect"
260 alternateButton:@"Ignore"
261 target:[MainController sharedController]
262 defaultAction:@selector(reconnect)
263 alternateAction:@selector(cancelReconnect)];
265 [_window appear:self];
266 [_window setLocked:YES];