Added a reset prefs status window for when the user first upgrades to 1.2
[MenuTunes.git] / StatusWindowController.m
1 #import "StatusWindowController.h"
2 #import "StatusWindow.h"
3 #import "PreferencesController.h"
4 #import "MainController.h"
5
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>
13
14
15 static StatusWindowController *sharedController;
16
17
18 @implementation StatusWindowController
19
20
21 + (StatusWindowController *)sharedController
22 {
23     if ( ! sharedController ) {
24         sharedController = [[StatusWindowController alloc] init];
25     }
26     
27     return sharedController;
28 }
29
30
31 - (id)init
32 {
33     if ( ( self = [super init] ) ) {
34         
35         float exitDelay;
36         NSString *entryClass;
37         NSString *exitClass;
38         NSArray  *classList = [ITWindowEffect effectClasses];
39         float entrySpeed;
40         float exitSpeed;
41         
42         NSData *colorData;
43         
44         ITWindowEffect *entryEffect;
45         ITWindowEffect *exitEffect;
46         
47         _window = [[StatusWindow sharedWindow] retain];
48         df = [[NSUserDefaults standardUserDefaults] retain];
49         
50         exitDelay  = [df floatForKey:@"statusWindowVanishDelay"];
51         entryClass = [df stringForKey:@"statusWindowAppearanceEffect"];
52         exitClass  = [df stringForKey:@"statusWindowVanishEffect"];
53         entrySpeed = [df floatForKey:@"statusWindowAppearanceSpeed"];
54         exitSpeed  = [df floatForKey:@"statusWindowVanishSpeed"];
55         
56         [_window setExitMode:ITTransientStatusWindowExitAfterDelay];
57         [_window setExitDelay:(exitDelay ? exitDelay : 4.0)];
58         
59         [_window setHorizontalPosition:[df integerForKey:@"statusWindowHorizontalPosition"]];
60         [_window setVerticalPosition:[df integerForKey:@"statusWindowVerticalPosition"]];
61         
62         [_window setSizing:(StatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
63         
64         if ( [classList containsObject:NSClassFromString(entryClass)] ) {
65             entryEffect = [[[NSClassFromString(entryClass) alloc] initWithWindow:_window] autorelease];
66         } else {
67             entryEffect = [[[ITCutWindowEffect alloc] initWithWindow:_window] autorelease];
68         }
69         
70         if ( [classList containsObject:NSClassFromString(exitClass)] ) {
71             exitEffect = [[[NSClassFromString(exitClass) alloc] initWithWindow:_window] autorelease];
72         } else {
73             exitEffect = [[[ITDissolveWindowEffect alloc] initWithWindow:_window] autorelease];
74         }
75         
76         [_window setEntryEffect:entryEffect];
77         [_window setExitEffect:exitEffect];
78         
79         [[_window entryEffect] setEffectTime:(entrySpeed ? entrySpeed : 0.8)];
80         [[_window exitEffect]  setEffectTime:(exitSpeed  ? exitSpeed  : 0.8)];
81         
82         [(ITTSWBackgroundView *)[_window contentView]setBackgroundMode:
83             (ITTSWBackgroundMode)[df integerForKey:@"statusWindowBackgroundMode"]];
84         
85         colorData = [df dataForKey:@"statusWindowBackgroundColor"];
86         
87         if ( colorData ) {
88             [(ITTSWBackgroundView *)[_window contentView] setBackgroundColor:
89                 (NSColor *)[NSUnarchiver unarchiveObjectWithData:colorData]];
90         } else {
91             [(ITTSWBackgroundView *)[_window contentView] setBackgroundColor:[NSColor blueColor]];
92         }
93     }
94     
95     return self;
96 }
97
98 - (void)dealloc
99 {
100     [_window release];
101     [super dealloc];
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     
163     [_window setSizing:(StatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
164     [_window buildTextWindowWithString:text];
165     [_window appear:self];
166 }
167
168 - (void)showUpcomingSongsWindowWithTitles:(NSArray *)titleStrings
169 {
170 //  NSString *bull = [NSString stringWithUTF8String:"‣ "];
171     NSString *bull = [NSString stringWithUTF8String:"♪ "];
172     NSString *end  = [@"\n" stringByAppendingString:bull];
173     [_window setImage:[NSImage imageNamed:@"Upcoming"]];
174     [_window setSizing:(StatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
175     [_window buildTextWindowWithString:[bull stringByAppendingString:[titleStrings componentsJoinedByString:end]]];
176     [_window appear:self];
177 }
178
179 - (void)showVolumeWindowWithLevel:(float)level
180 {
181     [_window setImage:[NSImage imageNamed:@"Volume"]];
182     [_window setSizing:(StatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
183     [_window buildMeterWindowWithCharacter:[NSString stringWithUTF8String:"▊"]
184                                       size:18
185                                      count:10
186                                     active:( ceil(level * 100) / 10 )];
187     [_window appear:self];
188 }
189
190 - (void)showRatingWindowWithRating:(float)rating
191 {
192     [_window setImage:[NSImage imageNamed:@"Rating"]];
193     [_window setSizing:(StatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
194     [_window buildMeterWindowWithCharacter:[NSString stringWithUTF8String:"★"]
195                                       size:48
196                                      count:5
197                                     active:( ceil(rating * 100) / 20 )];
198     [_window appear:self];
199 }
200
201 - (void)showShuffleWindow:(BOOL)shuffle
202 {
203     [_window setImage:[NSImage imageNamed:@"Shuffle"]];
204     [_window setSizing:(StatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
205     [_window buildTextWindowWithString:( shuffle ? @"Shuffle On" : @"Shuffle Off")];
206     [_window appear:self];
207 }
208
209 - (void)showRepeatWindowWithMode:(StatusWindowRepeatMode)mode
210 {
211     NSString *string = nil;
212     
213     if ( mode == StatusWindowRepeatNone ) {
214         string = @"Repeat Off";
215     } else if ( mode == StatusWindowRepeatGroup ) {
216         string = @"Repeat Playlist";
217     } else if ( mode == StatusWindowRepeatTrack ) {
218         string = @"Repeat One Track";
219     }
220     
221     [_window setImage:[NSImage imageNamed:@"Repeat"]];
222     [_window setSizing:(StatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
223     [_window buildTextWindowWithString:string];
224     [_window appear:self];
225 }
226
227 - (void)showSetupQueryWindow
228 {
229     NSString *message = @"Would you like MenuTunes to launch\nautomatically at startup?";
230
231     [_window setImage:[NSImage imageNamed:@"Setup"]];
232     [_window setSizing:(StatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
233     [_window buildDialogWindowWithMessage:message
234                             defaultButton:@"Launch at Startup"
235                           alternateButton:@"Launch Manually"
236                                    target:[PreferencesController sharedPrefs]
237                             defaultAction:@selector(autoLaunchOK)
238                           alternateAction:@selector(autoLaunchCancel)];
239
240     [_window appear:self];
241     [_window setLocked:YES];
242 }
243
244
245 - (void)showRegistrationQueryWindow
246 {
247     NSString *message = @"Your 7-day unlimited trial period has elapsed.\nYou must register to continue using MenuTunes.";
248
249     [_window setImage:[NSImage imageNamed:@"Register"]];
250     [_window setSizing:(StatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
251     [_window buildDialogWindowWithMessage:message
252                             defaultButton:@"Register Now"
253                           alternateButton:@"Quit MenuTunes"
254                                    target:[MainController sharedController]
255                             defaultAction:@selector(registerNowOK)
256                           alternateAction:@selector(registerNowCancel)];
257
258     [_window appear:self];
259     [_window setLocked:YES];
260 }
261
262 - (void)showReconnectQueryWindow
263 {
264     NSString *message = @"The selected shared player is available again.\nWould you like to reconnect to it?.";
265
266     [_window setImage:[NSImage imageNamed:@"Register"]];
267     [_window setSizing:(StatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
268     [_window buildDialogWindowWithMessage:message
269                             defaultButton:@"Reconnect"
270                           alternateButton:@"Ignore"
271                                    target:[MainController sharedController]
272                             defaultAction:@selector(reconnect)
273                           alternateAction:@selector(cancelReconnect)];
274
275     [_window appear:self];
276     [_window setLocked:YES];
277 }
278
279 - (void)showPreferencesUpdateWindow
280 {
281     NSString *message = @"The new features in this version of MenuTunes\nrequire you to reconfigure your preferences.";
282
283     [_window setImage:[NSImage imageNamed:@"Setup"]];
284     [_window setSizing:(StatusWindowSizing)[df integerForKey:@"statusWindowSizing"]];
285     [_window buildDialogWindowWithMessage:message
286                             defaultButton:@"Show Preferences"
287                           alternateButton:@"OK"
288                                    target:[MainController sharedController]
289                             defaultAction:@selector(showPreferencesAndClose)
290                           alternateAction:@selector(cancelReconnect)];
291
292     [_window appear:self];
293     [_window setLocked:YES];
294 }
295
296 @end