Initial hookup of the new positioning into MT. The corner effects work,
[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         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];
63         } else {
64             entryEffect = [[[ITCutWindowEffect alloc] initWithWindow:_window] autorelease];
65         }
66
67         [_window setEntryEffect:entryEffect];
68
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];
77         } else {
78             exitEffect = [[[ITDissolveWindowEffect alloc] initWithWindow:_window] autorelease];
79         }
80
81         [_window setExitEffect:exitEffect];
82
83         [[_window entryEffect] setEffectTime:(entrySpeed ? entrySpeed : 0.8)];
84         [[_window exitEffect]  setEffectTime:(exitSpeed  ? exitSpeed  : 0.8)];
85     }
86     
87     return self;
88 }
89
90 - (void)dealloc
91 {
92     [_window release];
93     [super dealloc];
94 }
95
96 - (void)readDefaults
97 {
98     ITHorizontalWindowPosition horizontalPosition = [[NSUserDefaults standardUserDefaults] integerForKey:@"statusWindowHorizontalPosition"];
99     ITVerticalWindowPosition verticalPosition = [[NSUserDefaults standardUserDefaults] integerForKey:@"statusWindowVerticalPosition"];
100     [_window setHorizontalPosition:horizontalPosition];
101     [_window setVerticalPosition:verticalPosition];
102 }
103
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
110                               rating:                   (int)rating
111 {
112     NSImage  *image = nil;
113     NSString *text  = title;
114     
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"];
127     }
128
129     [_window setImage:image];
130
131     if ( album ) {
132         text = [text stringByAppendingString:[@"\n" stringByAppendingString:album]];
133     }
134     if ( artist ) {
135         text = [text stringByAppendingString:[@"\n" stringByAppendingString:artist]];
136     }
137     if ( time ) {
138         text = [text stringByAppendingString:[@"\n" stringByAppendingString:time]];
139     }
140     if ( track ) {
141         text = [text stringByAppendingString:[@"\n" stringByAppendingString:track]];
142     }
143     if ( rating > -1 ) {
144
145         NSString *ratingString = [NSString string];
146         NSString *emptyChar    = [NSString stringWithUTF8String:"☆"];
147         NSString *fullChar     = [NSString stringWithUTF8String:"★"];
148         int       i;
149         
150         for ( i = 1; i < 6; i++ ) {
151                 
152             if ( rating >= i ) {
153                 ratingString = [ratingString stringByAppendingString:fullChar];
154             } else {
155                 ratingString = [ratingString stringByAppendingString:emptyChar];
156             }
157         }
158     
159         text = [text stringByAppendingString:[@"\n" stringByAppendingString:ratingString]];
160     }
161     
162     [_window buildTextWindowWithString:text];
163     [_window appear:self];
164 }
165
166 - (void)showUpcomingSongsWindowWithTitles:(NSArray *)titleStrings
167 {
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];
174 }
175
176 - (void)showVolumeWindowWithLevel:(float)level
177 {
178     [_window setImage:[NSImage imageNamed:@"Volume"]];
179     [_window buildMeterWindowWithCharacter:[NSString stringWithUTF8String:"▊"]
180                                       size:18
181                                      count:10
182                                     active:( ceil(level * 100) / 10 )];
183     [_window appear:self];
184 }
185
186 - (void)showRatingWindowWithRating:(float)rating
187 {
188     [_window setImage:[NSImage imageNamed:@"Rating"]];
189     [_window buildMeterWindowWithCharacter:[NSString stringWithUTF8String:"★"]
190                                       size:48
191                                      count:5
192                                     active:( ceil(rating * 100) / 20 )];
193     [_window appear:self];
194 }
195
196 - (void)showShuffleWindow:(BOOL)shuffle
197 {
198     [_window setImage:[NSImage imageNamed:@"Shuffle"]];
199     [_window buildTextWindowWithString:( shuffle ? @"Shuffle On" : @"Shuffle Off")];
200     [_window appear:self];
201 }
202
203 - (void)showRepeatWindowWithMode:(StatusWindowRepeatMode)mode
204 {
205     NSString *string = nil;
206     
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";
213     }
214     
215     [_window setImage:[NSImage imageNamed:@"Repeat"]];
216     [_window buildTextWindowWithString:string];
217     [_window appear:self];
218 }
219
220 - (void)showSetupQueryWindow
221 {
222     NSString *message = @"Would you like MenuTunes to launch\nautomatically at startup?";
223
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)];
231
232     [_window appear:self];
233     [_window setLocked:YES];
234 }
235
236
237 - (void)showRegistrationQueryWindow
238 {
239     NSString *message = @"Your 7-day unlimited trial period has elapsed.\nYou must register to continue using MenuTunes.";
240
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)];
248
249     [_window appear:self];
250     [_window setLocked:YES];
251 }
252
253 - (void)showReconnectQueryWindow
254 {
255     NSString *message = @"The selected shared player is available again.\nWould you like to reconnect to it?.";
256
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)];
264
265     [_window appear:self];
266     [_window setLocked:YES];
267 }
268
269 @end