Implementing Registration checks and final touches.
[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)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
102                               rating:                   (int)rating
103 {
104     NSImage  *image = nil;
105     NSString *text  = title;
106     
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"];
119     }
120
121     [_window setImage:image];
122
123     if ( album ) {
124         text = [text stringByAppendingString:[@"\n" stringByAppendingString:album]];
125     }
126     if ( artist ) {
127         text = [text stringByAppendingString:[@"\n" stringByAppendingString:artist]];
128     }
129     if ( time ) {
130         text = [text stringByAppendingString:[@"\n" stringByAppendingString:time]];
131     }
132     if ( track ) {
133         text = [text stringByAppendingString:[@"\n" stringByAppendingString:track]];
134     }
135     if ( rating > -1 ) {
136
137         NSString *ratingString = [NSString string];
138         NSString *emptyChar    = [NSString stringWithUTF8String:"☆"];
139         NSString *fullChar     = [NSString stringWithUTF8String:"★"];
140         int       i;
141         
142         for ( i = 1; i < 6; i++ ) {
143                 
144             if ( rating >= i ) {
145                 ratingString = [ratingString stringByAppendingString:fullChar];
146             } else {
147                 ratingString = [ratingString stringByAppendingString:emptyChar];
148             }
149         }
150     
151         text = [text stringByAppendingString:[@"\n" stringByAppendingString:ratingString]];
152     }
153     
154     [_window buildTextWindowWithString:text];
155     [_window appear:self];
156 }
157
158 - (void)showUpcomingSongsWindowWithTitles:(NSArray *)titleStrings
159 {
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];
166 }
167
168 - (void)showVolumeWindowWithLevel:(float)level
169 {
170     [_window setImage:[NSImage imageNamed:@"Volume"]];
171     [_window buildMeterWindowWithCharacter:[NSString stringWithUTF8String:"▊"]
172                                       size:18
173                                      count:10
174                                     active:( ceil(level * 100) / 10 )];
175     [_window appear:self];
176 }
177
178 - (void)showRatingWindowWithRating:(float)rating
179 {
180     [_window setImage:[NSImage imageNamed:@"Rating"]];
181     [_window buildMeterWindowWithCharacter:[NSString stringWithUTF8String:"★"]
182                                       size:48
183                                      count:5
184                                     active:( ceil(rating * 100) / 20 )];
185     [_window appear:self];
186 }
187
188 - (void)showShuffleWindow:(BOOL)shuffle
189 {
190     [_window setImage:[NSImage imageNamed:@"Shuffle"]];
191     [_window buildTextWindowWithString:( shuffle ? @"Shuffle On" : @"Shuffle Off")];
192     [_window appear:self];
193 }
194
195 - (void)showRepeatWindowWithMode:(StatusWindowRepeatMode)mode
196 {
197     NSString *string = nil;
198     
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";
205     }
206     
207     [_window setImage:[NSImage imageNamed:@"Repeat"]];
208     [_window buildTextWindowWithString:string];
209     [_window appear:self];
210 }
211
212 - (void)showSetupQueryWindow
213 {
214     NSString *message = @"Would you like MenuTunes to launch\nautomatically at startup?";
215
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)];
223
224     [_window appear:self];
225     [_window setLocked:YES];
226 }
227
228
229 - (void)showRegistrationQueryWindow
230 {
231     NSString *message = @"Your 7-day unlimited trial period has elapsed.\nYou must register to continue using MenuTunes.";
232
233     [_window setImage:[NSImage imageNamed:@"Register"]];
234     [_window buildDialogWindowWithMessage:message
235                             defaultButton:@"Register Now"
236                           alternateButton:@"Quit MenuTunes"
237                                    target:[MainController sharedController]
238                             defaultAction:@selector(registerNowOK)
239                           alternateAction:@selector(registerNowCancel)];
240
241     [_window appear:self];
242     [_window setLocked:YES];
243 }
244
245
246 @end