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)];
96 - (void)showSongInfoWindowWithSource:(ITMTRemotePlayerSource)source
97 title: (NSString *)title
98 album: (NSString *)album
99 artist: (NSString *)artist
100 time: (NSString *)time // FLOW: Should probably be NSDate or something.
101 track: (NSString *)track
104 NSImage *image = nil;
105 NSString *text = title;
107 if ( source == ITMTRemoteLibrarySource ) {
108 image = [NSImage imageNamed:@"Library"];
109 } else if ( source == ITMTRemoteCDSource ) {
110 image = [NSImage imageNamed:@"CD"];
111 } else if ( source == ITMTRemoteRadioSource ) {
112 image = [NSImage imageNamed:@"Radio"];
113 } else if ( source == ITMTRemoteiPodSource ) {
114 image = [NSImage imageNamed:@"iPod"];
115 } else if ( source == ITMTRemoteGenericDeviceSource ) {
116 image = [NSImage imageNamed:@"MP3Player"];
117 } else if ( source == ITMTRemoteSharedLibrarySource ) {
118 image = [NSImage imageNamed:@"Library"];
121 [_window setImage:image];
124 text = [text stringByAppendingString:[@"\n" stringByAppendingString:album]];
127 text = [text stringByAppendingString:[@"\n" stringByAppendingString:artist]];
130 text = [text stringByAppendingString:[@"\n" stringByAppendingString:time]];
133 text = [text stringByAppendingString:[@"\n" stringByAppendingString:track]];
137 NSString *ratingString = [NSString string];
138 NSString *emptyChar = [NSString stringWithUTF8String:"☆"];
139 NSString *fullChar = [NSString stringWithUTF8String:"★"];
142 for ( i = 1; i < 6; i++ ) {
145 ratingString = [ratingString stringByAppendingString:fullChar];
147 ratingString = [ratingString stringByAppendingString:emptyChar];
151 text = [text stringByAppendingString:[@"\n" stringByAppendingString:ratingString]];
154 [_window buildTextWindowWithString:text];
155 [_window appear:self];
158 - (void)showUpcomingSongsWindowWithTitles:(NSArray *)titleStrings
160 // NSString *bull = [NSString stringWithUTF8String:"‣ "];
161 NSString *bull = [NSString stringWithUTF8String:"♪ "];
162 NSString *end = [@"\n" stringByAppendingString:bull];
163 [_window setImage:[NSImage imageNamed:@"Upcoming"]];
164 [_window buildTextWindowWithString:[bull stringByAppendingString:[titleStrings componentsJoinedByString:end]]];
165 [_window appear:self];
168 - (void)showVolumeWindowWithLevel:(float)level
170 [_window setImage:[NSImage imageNamed:@"Volume"]];
171 [_window buildMeterWindowWithCharacter:[NSString stringWithUTF8String:"▊"]
174 active:( ceil(level * 100) / 10 )];
175 [_window appear:self];
178 - (void)showRatingWindowWithRating:(float)rating
180 [_window setImage:[NSImage imageNamed:@"Rating"]];
181 [_window buildMeterWindowWithCharacter:[NSString stringWithUTF8String:"★"]
184 active:( ceil(rating * 100) / 20 )];
185 [_window appear:self];
188 - (void)showShuffleWindow:(BOOL)shuffle
190 [_window setImage:[NSImage imageNamed:@"Shuffle"]];
191 [_window buildTextWindowWithString:( shuffle ? @"Shuffle On" : @"Shuffle Off")];
192 [_window appear:self];
195 - (void)showRepeatWindowWithMode:(StatusWindowRepeatMode)mode
197 NSString *string = nil;
199 if ( mode == StatusWindowRepeatNone ) {
200 string = @"Repeat Off";
201 } else if ( mode == StatusWindowRepeatGroup ) {
202 string = @"Repeat Playlist";
203 } else if ( mode == StatusWindowRepeatTrack ) {
204 string = @"Repeat One Track";
207 [_window setImage:[NSImage imageNamed:@"Repeat"]];
208 [_window buildTextWindowWithString:string];
209 [_window appear:self];
212 - (void)showSetupQueryWindow
214 NSString *message = @"Would you like MenuTunes to launch\nautomatically at startup?";
216 [_window setImage:[NSImage imageNamed:@"Setup"]];
217 [_window buildDialogWindowWithMessage:message
218 defaultButton:@"Launch at Startup"
219 alternateButton:@"Launch Manually"
220 target:[PreferencesController sharedPrefs]
221 defaultAction:@selector(autoLaunchOK)
222 alternateAction:@selector(autoLaunchCancel)];
224 [_window appear:self];
225 [_window setLocked:YES];
229 - (void)showRegistrationQueryWindow
231 NSString *message = @"Your 7-day unlimited trial period has elapsed.\nYou must register to continue using MenuTunes.";
233 [_window setImage:[NSImage imageNamed:@"Register"]];
234 [_window buildDialogWindowWithMessage:message
235 defaultButton:@"Register Now"
236 alternateButton:@"Quit MenuPrefs"
237 target:[MainController sharedController]
238 defaultAction:@selector(registerNowOK)
239 alternateAction:@selector(registerNowCancel)];
241 [_window appear:self];
242 [_window setLocked:YES];