Fixed my dorkiness with making unneeded helper methods in
[MenuTunes.git] / StatusWindowController.m
1 #import "StatusWindowController.h"
2 #import "StatusWindow.h"
3 #import "PreferencesController.h"
4 #import "MainController.h"
5
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>
12
13
14 static StatusWindowController *sharedController;
15
16
17 @implementation StatusWindowController
18
19
20 + (StatusWindowController *)sharedController
21 {
22     if ( ! sharedController ) {
23         sharedController = [[StatusWindowController alloc] init];
24     }
25     
26     return sharedController;
27 }
28
29
30 - (id)init
31 {
32     if ( ( self = [super init] ) ) {
33     
34         float exitDelay;
35         int entryTag;
36         int exitTag;
37         float entrySpeed;
38         float exitSpeed;
39         
40         ITWindowEffect *entryEffect;
41         ITWindowEffect *exitEffect;
42
43         _window = [[StatusWindow sharedWindow] retain];
44         df = [[NSUserDefaults standardUserDefaults] retain];
45
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"];
51
52         [_window setExitMode:ITTransientStatusWindowExitAfterDelay];
53         [_window setExitDelay:(exitDelay ? exitDelay : 4.0)];
54
55         [_window setHorizontalPosition:[df integerForKey:@"statusWindowHorizontalPosition"]];
56         [_window setVerticalPosition:[df integerForKey:@"statusWindowVerticalPosition"]];
57
58         if ( entryTag == 2101 ) {
59             entryEffect = [[[ITDissolveWindowEffect alloc] initWithWindow:_window] autorelease];
60         } else if ( entryTag == 2102 ) {
61             entryEffect = [[[ITSlideVerticallyWindowEffect alloc] initWithWindow:_window] autorelease];
62         } else if ( entryTag == 2103 ) {
63             entryEffect = [[[ITSlideHorizontallyWindowEffect alloc] initWithWindow:_window] autorelease];
64         } else if ( entryTag == 2104 ) {
65             entryEffect = [[[ITPivotWindowEffect alloc] initWithWindow:_window] autorelease];
66         } else {
67             entryEffect = [[[ITCutWindowEffect alloc] initWithWindow:_window] autorelease];
68         }
69
70         [_window setEntryEffect:entryEffect];
71
72         if ( exitTag == 2100 ) {
73             exitEffect = [[[ITCutWindowEffect alloc] initWithWindow:_window] autorelease];
74         } else if ( exitTag == 2102 ) {
75             exitEffect = [[[ITSlideVerticallyWindowEffect alloc] initWithWindow:_window] autorelease];
76         } else if ( exitTag == 2103 ) {
77             exitEffect = [[[ITSlideHorizontallyWindowEffect alloc] initWithWindow:_window] autorelease];
78         } else if ( exitTag == 2104 ) {
79             exitEffect = [[[ITPivotWindowEffect alloc] initWithWindow:_window] autorelease];
80         } else {
81             exitEffect = [[[ITDissolveWindowEffect alloc] initWithWindow:_window] autorelease];
82         }
83
84         [_window setExitEffect:exitEffect];
85
86         [[_window entryEffect] setEffectTime:(entrySpeed ? entrySpeed : 0.8)];
87         [[_window exitEffect]  setEffectTime:(exitSpeed  ? exitSpeed  : 0.8)];
88     }
89     
90     return self;
91 }
92
93 - (void)dealloc
94 {
95     [_window release];
96     [super dealloc];
97 }
98
99 - (void)showSongInfoWindowWithSource:(ITMTRemotePlayerSource)source
100                                title:            (NSString *)title
101                                album:            (NSString *)album
102                               artist:            (NSString *)artist
103                                 time:            (NSString *)time  // FLOW: Should probably be NSDate or something.
104                                track:            (NSString *)track
105                               rating:                   (int)rating
106 {
107     NSImage  *image = nil;
108     NSString *text  = title;
109     
110     if ( source == ITMTRemoteLibrarySource ) {
111         image = [NSImage imageNamed:@"Library"];
112     } else if ( source == ITMTRemoteCDSource ) {
113         image = [NSImage imageNamed:@"CD"];
114     } else if ( source == ITMTRemoteRadioSource ) {
115         image = [NSImage imageNamed:@"Radio"];
116     } else if ( source == ITMTRemoteiPodSource ) {
117         image = [NSImage imageNamed:@"iPod"];
118     } else if ( source == ITMTRemoteGenericDeviceSource ) {
119         image = [NSImage imageNamed:@"MP3Player"];
120     } else if ( source == ITMTRemoteSharedLibrarySource ) {
121         image = [NSImage imageNamed:@"Library"];
122     }
123
124     [_window setImage:image];
125
126     if ( album ) {
127         text = [text stringByAppendingString:[@"\n" stringByAppendingString:album]];
128     }
129     if ( artist ) {
130         text = [text stringByAppendingString:[@"\n" stringByAppendingString:artist]];
131     }
132     if ( time ) {
133         text = [text stringByAppendingString:[@"\n" stringByAppendingString:time]];
134     }
135     if ( track ) {
136         text = [text stringByAppendingString:[@"\n" stringByAppendingString:track]];
137     }
138     if ( rating > -1 ) {
139
140         NSString *ratingString = [NSString string];
141         NSString *emptyChar    = [NSString stringWithUTF8String:"☆"];
142         NSString *fullChar     = [NSString stringWithUTF8String:"★"];
143         int       i;
144         
145         for ( i = 1; i < 6; i++ ) {
146                 
147             if ( rating >= i ) {
148                 ratingString = [ratingString stringByAppendingString:fullChar];
149             } else {
150                 ratingString = [ratingString stringByAppendingString:emptyChar];
151             }
152         }
153     
154         text = [text stringByAppendingString:[@"\n" stringByAppendingString:ratingString]];
155     }
156     
157     [_window buildTextWindowWithString:text];
158     [_window appear:self];
159 }
160
161 - (void)showUpcomingSongsWindowWithTitles:(NSArray *)titleStrings
162 {
163 //  NSString *bull = [NSString stringWithUTF8String:"‣ "];
164     NSString *bull = [NSString stringWithUTF8String:"♪ "];
165     NSString *end  = [@"\n" stringByAppendingString:bull];
166     [_window setImage:[NSImage imageNamed:@"Upcoming"]];
167     [_window buildTextWindowWithString:[bull stringByAppendingString:[titleStrings componentsJoinedByString:end]]];
168     [_window appear:self];
169 }
170
171 - (void)showVolumeWindowWithLevel:(float)level
172 {
173     [_window setImage:[NSImage imageNamed:@"Volume"]];
174     [_window buildMeterWindowWithCharacter:[NSString stringWithUTF8String:"▊"]
175                                       size:18
176                                      count:10
177                                     active:( ceil(level * 100) / 10 )];
178     [_window appear:self];
179 }
180
181 - (void)showRatingWindowWithRating:(float)rating
182 {
183     [_window setImage:[NSImage imageNamed:@"Rating"]];
184     [_window buildMeterWindowWithCharacter:[NSString stringWithUTF8String:"★"]
185                                       size:48
186                                      count:5
187                                     active:( ceil(rating * 100) / 20 )];
188     [_window appear:self];
189 }
190
191 - (void)showShuffleWindow:(BOOL)shuffle
192 {
193     [_window setImage:[NSImage imageNamed:@"Shuffle"]];
194     [_window buildTextWindowWithString:( shuffle ? @"Shuffle On" : @"Shuffle Off")];
195     [_window appear:self];
196 }
197
198 - (void)showRepeatWindowWithMode:(StatusWindowRepeatMode)mode
199 {
200     NSString *string = nil;
201     
202     if ( mode == StatusWindowRepeatNone ) {
203         string = @"Repeat Off";
204     } else if ( mode == StatusWindowRepeatGroup ) {
205         string = @"Repeat Playlist";
206     } else if ( mode == StatusWindowRepeatTrack ) {
207         string = @"Repeat One Track";
208     }
209     
210     [_window setImage:[NSImage imageNamed:@"Repeat"]];
211     [_window buildTextWindowWithString:string];
212     [_window appear:self];
213 }
214
215 - (void)showSetupQueryWindow
216 {
217     NSString *message = @"Would you like MenuTunes to launch\nautomatically at startup?";
218
219     [_window setImage:[NSImage imageNamed:@"Setup"]];
220     [_window buildDialogWindowWithMessage:message
221                             defaultButton:@"Launch at Startup"
222                           alternateButton:@"Launch Manually"
223                                    target:[PreferencesController sharedPrefs]
224                             defaultAction:@selector(autoLaunchOK)
225                           alternateAction:@selector(autoLaunchCancel)];
226
227     [_window appear:self];
228     [_window setLocked:YES];
229 }
230
231
232 - (void)showRegistrationQueryWindow
233 {
234     NSString *message = @"Your 7-day unlimited trial period has elapsed.\nYou must register to continue using MenuTunes.";
235
236     [_window setImage:[NSImage imageNamed:@"Register"]];
237     [_window buildDialogWindowWithMessage:message
238                             defaultButton:@"Register Now"
239                           alternateButton:@"Quit MenuTunes"
240                                    target:[MainController sharedController]
241                             defaultAction:@selector(registerNowOK)
242                           alternateAction:@selector(registerNowCancel)];
243
244     [_window appear:self];
245     [_window setLocked:YES];
246 }
247
248 - (void)showReconnectQueryWindow
249 {
250     NSString *message = @"The selected shared player is available again.\nWould you like to reconnect to it?.";
251
252     [_window setImage:[NSImage imageNamed:@"Register"]];
253     [_window buildDialogWindowWithMessage:message
254                             defaultButton:@"Reconnect"
255                           alternateButton:@"Ignore"
256                                    target:[MainController sharedController]
257                             defaultAction:@selector(reconnect)
258                           alternateAction:@selector(cancelReconnect)];
259
260     [_window appear:self];
261     [_window setLocked:YES];
262 }
263
264 @end