OMG HUEG COMMIT!!! IT SI LIEK AN XBOX, BECAUES IT SI SO HUEG!! ALL STATUS WINDOW...
[MenuTunes.git] / StatusWindowController.m
1 #import "StatusWindowController.h"
2 #import "StatusWindow.h"
3 #import "PreferencesController.h"
4
5 #import <ITKit/ITWindowEffect.h>
6 #import <ITKit/ITCutWindowEffect.h>
7 #import <ITKit/ITDissolveWindowEffect.h>
8 #import <ITKit/ITSlideHorizontallyWindowEffect.h>
9 #import <ITKit/ITSlideVerticallyWindowEffect.h>
10 #import <ITKit/ITPivotWindowEffect.h>
11
12
13 static StatusWindowController *sharedController;
14
15
16 @implementation StatusWindowController
17
18
19 + (StatusWindowController *)sharedController
20 {
21     if ( ! sharedController ) {
22         sharedController = [[StatusWindowController alloc] init];
23     }
24     
25     return sharedController;
26 }
27
28
29 - (id)init
30 {
31     if ( ( self = [super init] ) ) {
32     
33         float exitDelay;
34         int entryTag;
35         int exitTag;
36         float entrySpeed;
37         float exitSpeed;
38         
39         ITWindowEffect *entryEffect;
40         ITWindowEffect *exitEffect;
41
42         _window = [[StatusWindow sharedWindow] retain];
43         df = [[NSUserDefaults standardUserDefaults] retain];
44
45         exitDelay  = [df floatForKey:@"statusWindowVanishDelay"];
46         entryTag   = [df integerForKey:@"statusWindowAppearanceEffect"];
47         exitTag    = [df integerForKey:@"statusWindowVanishEffect"];
48         entrySpeed = [df floatForKey:@"statusWindowAppearanceSpeed"];
49         exitSpeed  = [df floatForKey:@"statusWindowVanishSpeed"];
50
51         [_window setExitMode:ITTransientStatusWindowExitAfterDelay];
52         [_window setExitDelay:(exitDelay ? exitDelay : 4.0)];
53
54         if ( entryTag == 2101 ) {
55             entryEffect = [[[ITDissolveWindowEffect alloc] initWithWindow:_window] autorelease];
56         } else if ( entryTag == 2102 ) {
57             entryEffect = [[[ITSlideVerticallyWindowEffect alloc] initWithWindow:_window] autorelease];
58         } else if ( entryTag == 2103 ) {
59             entryEffect = [[[ITSlideHorizontallyWindowEffect alloc] initWithWindow:_window] autorelease];
60         } else if ( entryTag == 2104 ) {
61             entryEffect = [[[ITPivotWindowEffect alloc] initWithWindow:_window] autorelease];
62         } else {
63             entryEffect = [[[ITCutWindowEffect alloc] initWithWindow:_window] autorelease];
64         }
65
66         [_window setEntryEffect:entryEffect];
67
68         if ( exitTag == 2100 ) {
69             exitEffect = [[[ITCutWindowEffect alloc] initWithWindow:_window] autorelease];
70         } else if ( exitTag == 2102 ) {
71             exitEffect = [[[ITSlideVerticallyWindowEffect alloc] initWithWindow:_window] autorelease];
72         } else if ( exitTag == 2103 ) {
73             exitEffect = [[[ITSlideHorizontallyWindowEffect alloc] initWithWindow:_window] autorelease];
74         } else if ( exitTag == 2104 ) {
75             exitEffect = [[[ITPivotWindowEffect alloc] initWithWindow:_window] autorelease];
76         } else {
77             exitEffect = [[[ITDissolveWindowEffect alloc] initWithWindow:_window] autorelease];
78         }
79
80         [_window setExitEffect:exitEffect];
81
82         [[_window entryEffect] setEffectTime:(entrySpeed ? entrySpeed : 0.8)];
83         [[_window exitEffect]  setEffectTime:(exitSpeed  ? exitSpeed  : 0.8)];
84     }
85     
86     return self;
87 }
88
89 - (void)dealloc
90 {
91     [_window release];
92     [super dealloc];
93 }
94
95 - (void)showSongInfoWindowWithSource:(ITMTRemotePlayerSource)source
96                                title:            (NSString *)title
97                                album:            (NSString *)album
98                               artist:            (NSString *)artist
99                                 time:            (NSString *)time  // FLOW: Should probably be NSDate or something.
100                                track:            (NSString *)track
101                               rating:                   (int)rating
102 {
103     NSImage  *image = nil;
104     NSString *text  = title;
105     
106     if ( source == ITMTRemoteLibrarySource ) {
107         image = [NSImage imageNamed:@"Library"];
108     } else if ( source == ITMTRemoteCDSource ) {
109         image = [NSImage imageNamed:@"CD"];
110     } else if ( source == ITMTRemoteRadioSource ) {
111         image = [NSImage imageNamed:@"Radio"];
112     } else if ( source == ITMTRemoteiPodSource ) {
113         image = [NSImage imageNamed:@"iPod"];
114     } else if ( source == ITMTRemoteGenericDeviceSource ) {
115         image = [NSImage imageNamed:@"MP3Player"];
116     } else if ( source == ITMTRemoteSharedLibrarySource ) {
117         image = [NSImage imageNamed:@"Library"];
118     }
119
120     [_window setImage:image];
121
122     if ( album ) {
123         text = [text stringByAppendingString:[@"\n" stringByAppendingString:album]];
124     }
125     if ( artist ) {
126         text = [text stringByAppendingString:[@"\n" stringByAppendingString:artist]];
127     }
128     if ( time ) {
129         text = [text stringByAppendingString:[@"\n" stringByAppendingString:time]];
130     }
131     if ( track ) {
132         text = [text stringByAppendingString:[@"\n" stringByAppendingString:track]];
133     }
134     if ( rating > -1 ) {
135
136         NSString *ratingString = [NSString string];
137         NSString *emptyChar    = [NSString stringWithUTF8String:"☆"];
138         NSString *fullChar     = [NSString stringWithUTF8String:"★"];
139         int       i;
140         
141         for ( i = 1; i < 6; i++ ) {
142                 
143             if ( rating >= i ) {
144                 ratingString = [ratingString stringByAppendingString:fullChar];
145             } else {
146                 ratingString = [ratingString stringByAppendingString:emptyChar];
147             }
148         }
149     
150         text = [text stringByAppendingString:[@"\n" stringByAppendingString:ratingString]];
151     }
152     
153     [_window buildTextWindowWithString:text];
154     [_window appear:self];
155 }
156
157 - (void)showUpcomingSongsWindowWithTitles:(NSArray *)titleStrings
158 {
159 //  NSString *bull = [NSString stringWithUTF8String:"‣ "];
160     NSString *bull = [NSString stringWithUTF8String:"♪ "];
161     NSString *end  = [@"\n" stringByAppendingString:bull];
162     [_window setImage:[NSImage imageNamed:@"Upcoming"]];
163     [_window buildTextWindowWithString:[bull stringByAppendingString:[titleStrings componentsJoinedByString:end]]];
164     [_window appear:self];
165 }
166
167 - (void)showVolumeWindowWithLevel:(float)level
168 {
169     [_window setImage:[NSImage imageNamed:@"Volume"]];
170     [_window buildMeterWindowWithCharacter:[NSString stringWithUTF8String:"▊"]
171                                       size:18
172                                      count:10
173                                     active:( ceil(level * 100) / 10 )];
174     [_window appear:self];
175 }
176
177 - (void)showRatingWindowWithRating:(float)rating
178 {
179     [_window setImage:[NSImage imageNamed:@"Rating"]];
180     [_window buildMeterWindowWithCharacter:[NSString stringWithUTF8String:"★"]
181                                       size:48
182                                      count:5
183                                     active:( ceil(rating * 100) / 20 )];
184     [_window appear:self];
185 }
186
187 - (void)showShuffleWindow:(BOOL)shuffle
188 {
189     [_window setImage:[NSImage imageNamed:@"Shuffle"]];
190     [_window buildTextWindowWithString:( shuffle ? @"Shuffle On" : @"Shuffle Off")];
191     [_window appear:self];
192 }
193
194 - (void)showRepeatWindowWithMode:(StatusWindowRepeatMode)mode
195 {
196     NSString *string = nil;
197     
198     if ( mode == StatusWindowRepeatNone ) {
199         string = @"Repeat Off";
200     } else if ( mode == StatusWindowRepeatGroup ) {
201         string = @"Repeat Playlist";
202     } else if ( mode == StatusWindowRepeatTrack ) {
203         string = @"Repeat One Track";
204     }
205     
206     [_window setImage:[NSImage imageNamed:@"Repeat"]];
207     [_window buildTextWindowWithString:string];
208     [_window appear:self];
209 }
210
211 - (void)showSetupQueryWindow
212 {
213     NSString *message = @"Would you like MenuTunes to launch\nautomatically at startup?";
214
215     [_window setImage:[NSImage imageNamed:@"Setup"]];
216     [_window buildDialogWindowWithMessage:message
217                             defaultButton:@"Launch at Startup"
218                           alternateButton:@"Launch Manually"
219                                    target:[PreferencesController sharedPrefs]
220                             defaultAction:@selector(autoLaunchOK)
221                           alternateAction:@selector(autoLaunchCancel)];
222
223     [_window appear:self];
224     [_window setLocked:YES];
225 }
226
227
228 @end